Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper fix for #44 #94

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -451,22 +451,46 @@
<version>3.2.0</version>
<configuration>
<debug>true</debug>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<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>
<dependencies>
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 @@ -46,7 +46,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 @@ -350,19 +350,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 @@ -390,6 +379,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 @@ -501,9 +501,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 @@ -578,13 +575,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();

//
// Private helpers
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,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 @@ -339,8 +339,8 @@ protected List<String> getClasspath() throws MojoExecutionException {
* {@inheritDoc}
*/
@Override
protected void addGeneratedSourcesToProjectSourceRoot() {
getProject().addCompileSourceRoot(FileSystemUtilities.getCanonicalPath(getOutputDirectory()));
protected void updateProject() {
getProject().addCompileSourceRoot(getOutputDirectory().getAbsolutePath());
}

/**
Expand Down