Skip to content

Commit

Permalink
Proper fix for #44
Browse files Browse the repository at this point in the history
  • Loading branch information
veithen committed Sep 19, 2017
1 parent 2691c82 commit f5817a4
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 32 deletions.
36 changes: 30 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -367,23 +367,47 @@
<artifactId>maven-invoker-plugin</artifactId>
<configuration>
<debug>true</debug>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<!--<preBuildHookScript>setup</preBuildHookScript>-->
<postBuildHookScript>verify</postBuildHookScript>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<settingsFile>src/it/settings.xml</settingsFile>
<goals>
<goal>clean</goal>
<goal>test-compile</goal>
</goals>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<id>install</id>
<goals>
<goal>install</goal>
</goals>
</execution>
<execution>
<id>run-clean-test-compile</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<goals>
<goal>clean</goal>
<goal>test-compile</goal>
</goals>
</configuration>
</execution>
<execution>
<!-- Execute selected projects a second time without clean to catch problems like #44 -->
<id>run-test-compile</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
<!-- Reuse the cloned directories produced by the previous execution -->
<projectsDirectory>${project.build.directory}/it</projectsDirectory>
<pomIncludes>
<pomInclude>xjc-test/pom.xml</pomInclude>
</pomIncludes>
<goals>
<goal>test-compile</goal>
</goals>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion src/it/xjc-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<version>3.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
Expand Down
25 changes: 25 additions & 0 deletions src/it/xjc-test/src/test/java/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import com.example.myschema.AddressType;

public class Test {
public AddressType createAddress() {
return new AddressType();
}
}
22 changes: 9 additions & 13 deletions src/main/java/org/codehaus/mojo/jaxb2/AbstractJaxbMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,19 +270,8 @@ public final void execute() throws MojoExecutionException, MojoFailureException
log.info("No changes detected in schema or binding files - skipping JAXB generation.");
}

// 4) If the output directories exist, add them to the MavenProject's source directories
if(getOutputDirectory().exists() && getOutputDirectory().isDirectory()) {

final String canonicalPathToOutputDirectory = FileSystemUtilities.getCanonicalPath(getOutputDirectory());

if(log.isDebugEnabled()) {
log.debug("Adding existing JAXB outputDirectory [" + canonicalPathToOutputDirectory
+ "] to Maven's sources.");
}

// Add the output Directory.
getProject().addCompileSourceRoot(canonicalPathToOutputDirectory);
}
// 4) Update the project always.
updateProject();
}

/**
Expand Down Expand Up @@ -310,6 +299,13 @@ public final void execute() throws MojoExecutionException, MojoFailureException
*/
protected abstract boolean performExecution() throws MojoExecutionException, MojoFailureException;

/**
* Update the Maven project if necessary. This method will be called if {@code !shouldExecutionBeSkipped()}
* (even if {@link #performExecution()} is skipped).
*/
protected void updateProject() {
}

/**
* Override this method to acquire a List holding all URLs to the sources which this
* AbstractJaxbMojo should use to produce its output (XSDs files for AbstractXsdGeneratorMojos and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,6 @@ protected boolean performExecution() throws MojoExecutionException, MojoFailureE
}
}

// Add the generated source root to the project, enabling tooling and other plugins to see them.
addGeneratedSourcesToProjectSourceRoot();

// Copy all source XSDs to the resulting artifact?
if (xsdPathWithinArtifact != null) {

Expand Down Expand Up @@ -507,13 +504,6 @@ protected boolean performExecution() throws MojoExecutionException, MojoFailureE
*/
protected abstract List<File> getSourceXJBs();

/**
* Adds any directories containing the generated XJC classes to the appropriate Project compilation sources;
* either {@code TestCompileSourceRoot} or {@code CompileSourceRoot} depending on the exact Mojo implementation
* of this AbstractJavaGeneratorMojo.
*/
protected abstract void addGeneratedSourcesToProjectSourceRoot();

/**
* Adds the supplied Resource to the project using the appropriate scope (i.e. resource or testResource)
* depending on the exact implementation of this AbstractJavaGeneratorMojo.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ protected List<String> getClasspath() throws MojoExecutionException {
* {@inheritDoc}
*/
@Override
protected void addGeneratedSourcesToProjectSourceRoot() {
protected void updateProject() {
getProject().addTestCompileSourceRoot(getOutputDirectory().getAbsolutePath());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ protected List<String> getClasspath() throws MojoExecutionException {
* {@inheritDoc}
*/
@Override
protected void addGeneratedSourcesToProjectSourceRoot() {
protected void updateProject() {
getProject().addCompileSourceRoot(getOutputDirectory().getAbsolutePath());
}

Expand Down

0 comments on commit f5817a4

Please sign in to comment.