From 676dfc1c096836dd4b18620b4292081ccf028745 Mon Sep 17 00:00:00 2001 From: Andreas Veithen Date: Tue, 19 Sep 2017 21:31:49 +0100 Subject: [PATCH] Proper fix for #44 --- pom.xml | 36 +++++++++++++++---- src/it/xjc-test/pom.xml | 2 +- src/it/xjc-test/src/test/java/Test.java | 25 +++++++++++++ .../codehaus/mojo/jaxb2/AbstractJaxbMojo.java | 22 +++++------- .../AbstractJavaGeneratorMojo.java | 10 ------ .../jaxb2/javageneration/TestXjcMojo.java | 2 +- .../mojo/jaxb2/javageneration/XjcMojo.java | 4 +-- 7 files changed, 68 insertions(+), 33 deletions(-) create mode 100644 src/it/xjc-test/src/test/java/Test.java diff --git a/pom.xml b/pom.xml index 2ac0d780..a4a605c4 100644 --- a/pom.xml +++ b/pom.xml @@ -451,22 +451,46 @@ 3.2.0 true - ${project.build.directory}/it verify ${project.build.directory}/local-repo src/it/settings.xml - - clean - test-compile - - integration-test + install install + + + + run-clean-test-compile + + run + + + ${project.build.directory}/it + + clean + test-compile + + + + + + run-test-compile + run + + + ${project.build.directory}/it + + xjc-test/pom.xml + + + test-compile + + diff --git a/src/it/xjc-test/pom.xml b/src/it/xjc-test/pom.xml index 89789be6..e47ee940 100644 --- a/src/it/xjc-test/pom.xml +++ b/src/it/xjc-test/pom.xml @@ -46,7 +46,7 @@ org.apache.maven.plugins maven-compiler-plugin - 2.5.1 + 3.5.1 1.6 1.6 diff --git a/src/it/xjc-test/src/test/java/Test.java b/src/it/xjc-test/src/test/java/Test.java new file mode 100644 index 00000000..3990a585 --- /dev/null +++ b/src/it/xjc-test/src/test/java/Test.java @@ -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(); + } +} diff --git a/src/main/java/org/codehaus/mojo/jaxb2/AbstractJaxbMojo.java b/src/main/java/org/codehaus/mojo/jaxb2/AbstractJaxbMojo.java index 9f370409..bb684eeb 100644 --- a/src/main/java/org/codehaus/mojo/jaxb2/AbstractJaxbMojo.java +++ b/src/main/java/org/codehaus/mojo/jaxb2/AbstractJaxbMojo.java @@ -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(); } /** @@ -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 diff --git a/src/main/java/org/codehaus/mojo/jaxb2/javageneration/AbstractJavaGeneratorMojo.java b/src/main/java/org/codehaus/mojo/jaxb2/javageneration/AbstractJavaGeneratorMojo.java index f3a45452..62f249c6 100644 --- a/src/main/java/org/codehaus/mojo/jaxb2/javageneration/AbstractJavaGeneratorMojo.java +++ b/src/main/java/org/codehaus/mojo/jaxb2/javageneration/AbstractJavaGeneratorMojo.java @@ -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) { @@ -578,13 +575,6 @@ protected boolean performExecution() throws MojoExecutionException, MojoFailureE */ protected abstract List 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 // diff --git a/src/main/java/org/codehaus/mojo/jaxb2/javageneration/TestXjcMojo.java b/src/main/java/org/codehaus/mojo/jaxb2/javageneration/TestXjcMojo.java index 9869deb5..1b74fb66 100644 --- a/src/main/java/org/codehaus/mojo/jaxb2/javageneration/TestXjcMojo.java +++ b/src/main/java/org/codehaus/mojo/jaxb2/javageneration/TestXjcMojo.java @@ -328,7 +328,7 @@ protected List getClasspath() throws MojoExecutionException { * {@inheritDoc} */ @Override - protected void addGeneratedSourcesToProjectSourceRoot() { + protected void updateProject() { getProject().addTestCompileSourceRoot(getOutputDirectory().getAbsolutePath()); } diff --git a/src/main/java/org/codehaus/mojo/jaxb2/javageneration/XjcMojo.java b/src/main/java/org/codehaus/mojo/jaxb2/javageneration/XjcMojo.java index 7767a8e9..20aabbc4 100644 --- a/src/main/java/org/codehaus/mojo/jaxb2/javageneration/XjcMojo.java +++ b/src/main/java/org/codehaus/mojo/jaxb2/javageneration/XjcMojo.java @@ -339,8 +339,8 @@ protected List getClasspath() throws MojoExecutionException { * {@inheritDoc} */ @Override - protected void addGeneratedSourcesToProjectSourceRoot() { - getProject().addCompileSourceRoot(FileSystemUtilities.getCanonicalPath(getOutputDirectory())); + protected void updateProject() { + getProject().addCompileSourceRoot(getOutputDirectory().getAbsolutePath()); } /**