diff --git a/maven-plugin/plugin-core/src/main/java/org/jvnet/jaxb/maven/RawXJC2Mojo.java b/maven-plugin/plugin-core/src/main/java/org/jvnet/jaxb/maven/RawXJC2Mojo.java index c675cab1b..55dfd2ebf 100644 --- a/maven-plugin/plugin-core/src/main/java/org/jvnet/jaxb/maven/RawXJC2Mojo.java +++ b/maven-plugin/plugin-core/src/main/java/org/jvnet/jaxb/maven/RawXJC2Mojo.java @@ -791,13 +791,14 @@ protected void logConfiguration() throws MojoExecutionException { getLog().info("dependsURIs (resolved):" + getDependsURIs()); } - private void collectBindingUrisFromDependencies(List bindingUris) throws MojoExecutionException { + void collectBindingUrisFromDependencies(List bindingUris) throws MojoExecutionException { @SuppressWarnings("unchecked") final Collection projectArtifacts = getProject().getArtifacts(); final List compileScopeArtifacts = new ArrayList(projectArtifacts.size()); - final ArtifactFilter filter = new ScopeArtifactFilter(DefaultArtifact.SCOPE_COMPILE); + final ArtifactFilter scopeFilter = new ScopeArtifactFilter(DefaultArtifact.SCOPE_COMPILE); + final ArtifactFilter typeFilter = new TypeArtifactFilter("pom"); for (Artifact artifact : projectArtifacts) { - if (filter.include(artifact)) { + if (scopeFilter.include(artifact) && !typeFilter.include(artifact)) { compileScopeArtifacts.add(artifact); } } diff --git a/maven-plugin/plugin-core/src/test/java/org/jvnet/jaxb/maven/RawXJC2MojoTest.java b/maven-plugin/plugin-core/src/test/java/org/jvnet/jaxb/maven/RawXJC2MojoTest.java index 5d2c62679..8b4cd5b23 100644 --- a/maven-plugin/plugin-core/src/test/java/org/jvnet/jaxb/maven/RawXJC2MojoTest.java +++ b/maven-plugin/plugin-core/src/test/java/org/jvnet/jaxb/maven/RawXJC2MojoTest.java @@ -1,6 +1,9 @@ package org.jvnet.jaxb.maven; +import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.testing.stubs.ArtifactStub; +import org.apache.maven.project.MavenProject; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -15,7 +18,9 @@ import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; @@ -43,6 +48,62 @@ public void createJarFile() throws Exception { } } + @Test + public void collectBindingUrisFromDependencies() throws Exception { + List bindings = new ArrayList<>(); + + final RawXJC2Mojo mojo = new RawXJC2Mojo() { + + @Override + public MavenProject getProject() { + MavenProject project = new MavenProject() { + @Override + public Set getArtifacts() { + Set artifacts = new HashSet<>(); + ArtifactStub stubJar = new ArtifactStub(); + stubJar.setArtifactId("test"); + stubJar.setScope("compile"); + stubJar.setType("jar"); + stubJar.setFile(testJarFile); + artifacts.add(stubJar); + + ArtifactStub stubProvided = new ArtifactStub(); + stubProvided.setArtifactId("test-provided"); + stubProvided.setScope("provided"); + stubProvided.setType("jar"); + artifacts.add(stubJar); + + ArtifactStub stubPom = new ArtifactStub(); + stubPom.setArtifactId("test-pom"); + stubPom.setScope("compile"); + stubPom.setType("pom"); + artifacts.add(stubPom); + return artifacts; + } + }; + return project; + } + + @Override + protected IOptionsFactory getOptionsFactory() { + throw new UnsupportedOperationException(); + } + + @Override + public void doExecute(Void options) throws MojoExecutionException { + throw new UnsupportedOperationException(); + } + }; + + mojo.collectBindingUrisFromDependencies(bindings); + + assertEquals(2, bindings.size()); + assertEquals(URI.create("jar:" + testJarFile.toURI() + "!/dir/nested.xjb"), bindings.get(0)); + assertEquals(URI.create("jar:" + testJarFile.toURI() + "!/root.xjb"), bindings.get(1)); + assertEquals("nested binding", readContent(bindings.get(0))); + assertEquals("root binding", readContent(bindings.get(1))); + } + @Test public void collectsBindingUrisFromArtifact() throws Exception { List bindings = new ArrayList<>(); diff --git a/maven-plugin/tests/jt-194/pom.xml b/maven-plugin/tests/jt-194/pom.xml new file mode 100644 index 000000000..126e9f934 --- /dev/null +++ b/maven-plugin/tests/jt-194/pom.xml @@ -0,0 +1,51 @@ + + 4.0.0 + jaxb-maven-plugin-tests-194 + + org.jvnet.jaxb + jaxb-maven-plugin-tests + 2.0.4-SNAPSHOT + + jar + JAXB Tools :: Maven Plugin :: Test [JAXB-TOOLS 194] + + This project tests pom artifacts filtering that may cause scanDependenciesForBindings fails on dependency of type pom. + + + + org.apache.commons + commons-lang3 + 3.12.0 + pom + provided + + + org.glassfish.jaxb + jaxb-runtime + + + org.jvnet.jaxb + jaxb-maven-plugin-testing + test + + + + + + org.jvnet.jaxb + jaxb-maven-plugin + + + generate + + generate + + + true + + + + + + + diff --git a/maven-plugin/tests/jt-194/src/main/resources/purchaseorder.xjb b/maven-plugin/tests/jt-194/src/main/resources/purchaseorder.xjb new file mode 100644 index 000000000..433eecc7a --- /dev/null +++ b/maven-plugin/tests/jt-194/src/main/resources/purchaseorder.xjb @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/maven-plugin/tests/jt-194/src/main/resources/purchaseorder.xsd b/maven-plugin/tests/jt-194/src/main/resources/purchaseorder.xsd new file mode 100644 index 000000000..18b9fe116 --- /dev/null +++ b/maven-plugin/tests/jt-194/src/main/resources/purchaseorder.xsd @@ -0,0 +1,66 @@ + + + + + Purchase order schema for Example.com. + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/maven-plugin/tests/pom.xml b/maven-plugin/tests/pom.xml index 119ba9288..38cf1510c 100644 --- a/maven-plugin/tests/pom.xml +++ b/maven-plugin/tests/pom.xml @@ -53,6 +53,7 @@ gh-issue-58 java-9 jt-250 + jt-194