diff --git a/src/it/projects/MSHADE-374_testJarArtifactSet/api/pom.xml b/src/it/projects/MSHADE-374_testJarArtifactSet/api/pom.xml new file mode 100644 index 00000000..b0242680 --- /dev/null +++ b/src/it/projects/MSHADE-374_testJarArtifactSet/api/pom.xml @@ -0,0 +1,32 @@ + + + + + + 4.0.0 + + org.apache.maven.its.shade.stj + mshade-374-parent + 1.0 + + mshade-374-api + diff --git a/src/it/projects/MSHADE-374_testJarArtifactSet/api/src/main/java/Api.java b/src/it/projects/MSHADE-374_testJarArtifactSet/api/src/main/java/Api.java new file mode 100644 index 00000000..b1a0ba74 --- /dev/null +++ b/src/it/projects/MSHADE-374_testJarArtifactSet/api/src/main/java/Api.java @@ -0,0 +1,22 @@ +/* + * 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. + */ + +public class Api +{ +} diff --git a/src/it/projects/MSHADE-374_testJarArtifactSet/api/src/main/resources/api-resource.txt b/src/it/projects/MSHADE-374_testJarArtifactSet/api/src/main/resources/api-resource.txt new file mode 100644 index 00000000..13a83393 --- /dev/null +++ b/src/it/projects/MSHADE-374_testJarArtifactSet/api/src/main/resources/api-resource.txt @@ -0,0 +1,16 @@ +# 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. diff --git a/src/it/projects/MSHADE-374_testJarArtifactSet/api/src/test/java/ApiTest.java b/src/it/projects/MSHADE-374_testJarArtifactSet/api/src/test/java/ApiTest.java new file mode 100644 index 00000000..2e2eaab2 --- /dev/null +++ b/src/it/projects/MSHADE-374_testJarArtifactSet/api/src/test/java/ApiTest.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. + */ + +public class ApiTest +{ + public static void main(String[] args) { + new Api(); + } +} diff --git a/src/it/projects/MSHADE-374_testJarArtifactSet/api/src/test/resources/api-test-resource.txt b/src/it/projects/MSHADE-374_testJarArtifactSet/api/src/test/resources/api-test-resource.txt new file mode 100644 index 00000000..13a83393 --- /dev/null +++ b/src/it/projects/MSHADE-374_testJarArtifactSet/api/src/test/resources/api-test-resource.txt @@ -0,0 +1,16 @@ +# 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. diff --git a/src/it/projects/MSHADE-374_testJarArtifactSet/impl/pom.xml b/src/it/projects/MSHADE-374_testJarArtifactSet/impl/pom.xml new file mode 100644 index 00000000..c126e6c2 --- /dev/null +++ b/src/it/projects/MSHADE-374_testJarArtifactSet/impl/pom.xml @@ -0,0 +1,43 @@ + + + + + + 4.0.0 + + org.apache.maven.its.shade.stj + mshade-374-parent + 1.0 + + mshade-374-impl + + + org.apache.maven.its.shade.stj + mshade-374-api + + + org.apache.maven.its.shade.stj + mshade-374-api + test-jar + + + diff --git a/src/it/projects/MSHADE-374_testJarArtifactSet/impl/src/main/java/Impl.java b/src/it/projects/MSHADE-374_testJarArtifactSet/impl/src/main/java/Impl.java new file mode 100644 index 00000000..737fb97c --- /dev/null +++ b/src/it/projects/MSHADE-374_testJarArtifactSet/impl/src/main/java/Impl.java @@ -0,0 +1,22 @@ +/* + * 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. + */ + +public class Impl extends Api +{ +} diff --git a/src/it/projects/MSHADE-374_testJarArtifactSet/impl/src/main/resources/impl-resource.txt b/src/it/projects/MSHADE-374_testJarArtifactSet/impl/src/main/resources/impl-resource.txt new file mode 100644 index 00000000..13a83393 --- /dev/null +++ b/src/it/projects/MSHADE-374_testJarArtifactSet/impl/src/main/resources/impl-resource.txt @@ -0,0 +1,16 @@ +# 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. diff --git a/src/it/projects/MSHADE-374_testJarArtifactSet/impl/src/test/java/ImplTest.java b/src/it/projects/MSHADE-374_testJarArtifactSet/impl/src/test/java/ImplTest.java new file mode 100644 index 00000000..f335ad5c --- /dev/null +++ b/src/it/projects/MSHADE-374_testJarArtifactSet/impl/src/test/java/ImplTest.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. + */ + +public class ImplTest extends ApiTest +{ + public static void main(String[] args) { + new Impl(); + } +} diff --git a/src/it/projects/MSHADE-374_testJarArtifactSet/impl/src/test/resources/impl-test-resource.txt b/src/it/projects/MSHADE-374_testJarArtifactSet/impl/src/test/resources/impl-test-resource.txt new file mode 100644 index 00000000..13a83393 --- /dev/null +++ b/src/it/projects/MSHADE-374_testJarArtifactSet/impl/src/test/resources/impl-test-resource.txt @@ -0,0 +1,16 @@ +# 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. diff --git a/src/it/projects/MSHADE-374_testJarArtifactSet/pom.xml b/src/it/projects/MSHADE-374_testJarArtifactSet/pom.xml new file mode 100644 index 00000000..d4a6e085 --- /dev/null +++ b/src/it/projects/MSHADE-374_testJarArtifactSet/pom.xml @@ -0,0 +1,77 @@ + + + + + + 4.0.0 + org.apache.maven.its.shade.stj + mshade-374-parent + pom + 1.0 + + api + impl + uber + + + + + org.apache.maven.its.shade.stj + mshade-374-api + 1.0 + + + org.apache.maven.its.shade.stj + mshade-374-api + 1.0 + test-jar + test + + + org.apache.maven.its.shade.stj + mshade-374-impl + 1.0 + + + org.apache.maven.its.shade.stj + mshade-374-impl + 1.0 + test-jar + test + + + + + + + maven-jar-plugin + + + + test-jar + + + + + + + diff --git a/src/it/projects/MSHADE-374_testJarArtifactSet/uber/pom.xml b/src/it/projects/MSHADE-374_testJarArtifactSet/uber/pom.xml new file mode 100644 index 00000000..573127a4 --- /dev/null +++ b/src/it/projects/MSHADE-374_testJarArtifactSet/uber/pom.xml @@ -0,0 +1,79 @@ + + + + + + 4.0.0 + + org.apache.maven.its.shade.stj + mshade-374-parent + 1.0 + + mshade-374-uber + + + org.apache.maven.its.shade.stj + mshade-374-api + + + org.apache.maven.its.shade.stj + mshade-374-api + test-jar + + + org.apache.maven.its.shade.stj + mshade-374-impl + + + org.apache.maven.its.shade.stj + mshade-374-impl + test-jar + + + + + + maven-shade-plugin + @project.version@ + + + + shade + + + true + + + org.apache.maven.its.shade.stj:mshade-374-impl:* + org.apache.maven.its.shade.stj:mshade-374-api:* + + + org.apache.maven.its.shade.stj:mshade-374-impl:*:tests + + + + + + + + + diff --git a/src/it/projects/MSHADE-374_testJarArtifactSet/verify.groovy b/src/it/projects/MSHADE-374_testJarArtifactSet/verify.groovy new file mode 100644 index 00000000..bf96066a --- /dev/null +++ b/src/it/projects/MSHADE-374_testJarArtifactSet/verify.groovy @@ -0,0 +1,53 @@ +/* + * 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. + */ + +def jarFile = new java.util.jar.JarFile( new File( basedir, "uber/target/mshade-374-uber-1.0.jar" ) ) +try +{ + // modified to get an exception + assert null != jarFile.getJarEntry( "Api.class" ) + assert null != jarFile.getJarEntry( "api-resource.txt" ) + assert null != jarFile.getJarEntry( "Impl.class" ) + assert null != jarFile.getJarEntry( "impl-resource.txt" ) + assert null == jarFile.getJarEntry( "ApiTest.class" ) + assert null == jarFile.getJarEntry( "api-test-resource.txt" ) + assert null == jarFile.getJarEntry( "ImplTest.class" ) + assert null == jarFile.getJarEntry( "impl-test-resource.txt" ) +} +finally +{ + jarFile.close() +} + +def testJarFile = new java.util.jar.JarFile( new File( basedir, "uber/target/mshade-374-uber-1.0-tests.jar" ) ) +try +{ + assert null == testJarFile.getJarEntry( "Api.class" ) + assert null == testJarFile.getJarEntry( "api-resource.txt" ) + assert null == testJarFile.getJarEntry( "Impl.class" ) + assert null == testJarFile.getJarEntry( "impl-resource.txt" ) + assert null != testJarFile.getJarEntry( "ApiTest.class" ) + assert null != testJarFile.getJarEntry( "api-test-resource.txt" ) + assert null == testJarFile.getJarEntry( "ImplTest.class" ) + assert null == testJarFile.getJarEntry( "impl-test-resource.txt" ) +} +finally +{ + testJarFile.close() +} diff --git a/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java b/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java index 312c76ae..479f4425 100644 --- a/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java +++ b/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java @@ -518,7 +518,7 @@ public void execute() throws MojoExecutionException { // Now add our extra resources try { - List filters = getFilters(); + List filters = getFilters(artifactSelector); List relocators = getRelocators(); @@ -773,33 +773,45 @@ private void processArtifactSelectors( artifactIds.add(getId(artifact)); if (createSourcesJar) { - File file = resolveArtifactForClassifier(artifact, "sources"); - if (file != null) { - if (file.length() > 0) { - sourceArtifacts.add(file); - } else { - emptySourceArtifacts.add(artifact.getArtifactId()); + ArtifactId sourcesArtifactId = + new ArtifactId(artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), "sources"); + if (artifactSelector.isSelected(sourcesArtifactId)) { + File file = resolveArtifactForClassifier(artifact, "sources"); + if (file != null) { + if (file.length() > 0) { + sourceArtifacts.add(file); + } else { + emptySourceArtifacts.add(artifact.getArtifactId()); + } } } } if (shadeTestJar) { - File file = resolveArtifactForClassifier(artifact, "tests"); - if (file != null) { - if (file.length() > 0) { - testArtifacts.add(file); - } else { - emptyTestArtifacts.add(artifact.getId()); + ArtifactId testArtifactId = + new ArtifactId(artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), "tests"); + if (artifactSelector.isSelected(testArtifactId)) { + File file = resolveArtifactForClassifier(artifact, "tests"); + if (file != null) { + if (file.length() > 0) { + testArtifacts.add(file); + } else { + emptyTestArtifacts.add(artifact.getId()); + } } } } if (createTestSourcesJar) { - File file = resolveArtifactForClassifier(artifact, "test-sources"); - if (file != null) { - testSourceArtifacts.add(file); - } else { - emptyTestSourceArtifacts.add(artifact.getId()); + ArtifactId testSourcesArtifactId = new ArtifactId( + artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), "test-sources"); + if (artifactSelector.isSelected(testSourcesArtifactId)) { + File file = resolveArtifactForClassifier(artifact, "test-sources"); + if (file != null) { + testSourceArtifacts.add(file); + } else { + emptyTestSourceArtifacts.add(artifact.getId()); + } } } } @@ -868,6 +880,27 @@ private void copyFiles(File source, File target) throws IOException { } } + private org.eclipse.aether.artifact.Artifact resolveArtifactForClassifier2(Artifact artifact, String classifier) { + Artifact toResolve = new DefaultArtifact( + artifact.getGroupId(), + artifact.getArtifactId(), + artifact.getVersionRange() == null + ? VersionRange.createFromVersion(artifact.getVersion()) + : artifact.getVersionRange(), + artifact.getScope(), + artifact.getType(), + classifier, + artifact.getArtifactHandler(), + artifact.isOptional()); + try { + org.eclipse.aether.artifact.Artifact resolved = resolveArtifact(RepositoryUtils.toArtifact(toResolve)); + return resolved; + } catch (ArtifactResolutionException e) { + getLog().warn("Could not get " + classifier + " for " + artifact); + return null; + } + } + private File resolveArtifactForClassifier(Artifact artifact, String classifier) { Artifact toResolve = new DefaultArtifact( artifact.getGroupId(), @@ -930,6 +963,10 @@ private List getResourceTransformers() throws MojoExecution } private List getFilters() throws MojoExecutionException { + return getFilters(null); + } + + private List getFilters(ArtifactSelector artifactSelector) throws MojoExecutionException { List filters = new ArrayList<>(); List simpleFilters = new ArrayList<>(); @@ -939,7 +976,9 @@ private List getFilters() throws MojoExecutionException { artifacts.put(project.getArtifact(), new ArtifactId(project.getArtifact())); for (Artifact artifact : project.getArtifacts()) { - artifacts.put(artifact, new ArtifactId(artifact)); + if (artifactSelector == null || artifactSelector.isSelected(artifact)) { + artifacts.put(artifact, new ArtifactId(artifact)); + } } for (ArchiveFilter filter : this.filters) { @@ -954,16 +993,24 @@ private List getFilters() throws MojoExecutionException { jars.add(artifact.getFile()); if (createSourcesJar) { - File file = resolveArtifactForClassifier(artifact, "sources"); - if (file != null) { - jars.add(file); + ArtifactId testSourcesArtifactId = new ArtifactId( + artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), "sources"); + if (artifactSelector == null || artifactSelector.isSelected(testSourcesArtifactId)) { + File file = resolveArtifactForClassifier(artifact, "sources"); + if (file != null) { + jars.add(file); + } } } if (shadeTestJar) { - File file = resolveArtifactForClassifier(artifact, "tests"); - if (file != null) { - jars.add(file); + ArtifactId testSourcesArtifactId = new ArtifactId( + artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), "tests"); + if (artifactSelector == null || artifactSelector.isSelected(testSourcesArtifactId)) { + File file = resolveArtifactForClassifier(artifact, "tests"); + if (file != null) { + jars.add(file); + } } } }