diff --git a/pom.xml b/pom.xml
index cb10a847..4cb6dc7a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -276,6 +276,9 @@
install
+
+ spi/pom.xml
+
${https.protocols}
diff --git a/src/it/spi-shade/invoker.properties b/src/it/spi-shade/invoker.properties
new file mode 100644
index 00000000..bdf5c615
--- /dev/null
+++ b/src/it/spi-shade/invoker.properties
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals=clean package
diff --git a/src/it/spi-shade/pom.xml b/src/it/spi-shade/pom.xml
new file mode 100644
index 00000000..6a1d70a6
--- /dev/null
+++ b/src/it/spi-shade/pom.xml
@@ -0,0 +1,77 @@
+
+
+
+
+
+ 4.0.0
+
+
+ org.apache.maven.plugins.shade.its
+ shade-parent
+ 1.0
+ ../setup-parent
+
+
+ spi-shade
+ 1.0-SNAPSHOT
+
+ IT :: SPI :: Shade
+
+
+ 1.7
+ 1.7
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ @project.version@
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ @project.version@
+ tests
+
+
+ ${project.groupId}
+ spi
+ ${project.version}
+
+
+
+
+ create-shaded-artifact
+ package
+
+ shade
+
+
+ false
+
+
+
+
+
+
+
diff --git a/src/it/spi-shade/verify.groovy b/src/it/spi-shade/verify.groovy
new file mode 100644
index 00000000..febbe05a
--- /dev/null
+++ b/src/it/spi-shade/verify.groovy
@@ -0,0 +1,31 @@
+import java.util.jar.JarFile
+
+/*
+ * 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.
+ */
+shade = new File(basedir, 'target/spi-shade-1.0-SNAPSHOT.jar')
+assert shade.exists();
+
+jar = new JarFile(shade)
+entry = jar.getEntry('org.apache.maven.plugins.shade.it.spi.CustomTransformer')
+assert entry != null
+stream = jar.getInputStream(entry)
+assert stream.text == 'executed'
+jar.close()
+
+return true;
\ No newline at end of file
diff --git a/src/it/spi/invoker.properties b/src/it/spi/invoker.properties
new file mode 100644
index 00000000..24178d35
--- /dev/null
+++ b/src/it/spi/invoker.properties
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals=clean install
diff --git a/src/it/spi/pom.xml b/src/it/spi/pom.xml
new file mode 100644
index 00000000..8f1bf775
--- /dev/null
+++ b/src/it/spi/pom.xml
@@ -0,0 +1,52 @@
+
+
+
+
+
+ 4.0.0
+
+
+ org.apache.maven.plugins.shade.its
+ shade-parent
+ 1.0
+ ../setup-parent
+
+
+ spi
+ 1.0-SNAPSHOT
+
+ IT :: SPI
+
+
+ 1.7
+ 1.7
+
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+
+ 3.2.1
+ provided
+
+
+
diff --git a/src/it/spi/src/main/java/org/apache/maven/plugins/shade/it/spi/CustomTransformer.java b/src/it/spi/src/main/java/org/apache/maven/plugins/shade/it/spi/CustomTransformer.java
new file mode 100644
index 00000000..566227cc
--- /dev/null
+++ b/src/it/spi/src/main/java/org/apache/maven/plugins/shade/it/spi/CustomTransformer.java
@@ -0,0 +1,51 @@
+/**
+ * Copyright (C) 2006-2018 Talend Inc. - www.talend.com
+ *
+ * Licensed 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.
+ */
+package org.apache.maven.plugins.shade.it.spi;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+
+import org.apache.maven.plugins.shade.relocation.Relocator;
+import org.apache.maven.plugins.shade.resource.ResourceTransformer;
+
+public class CustomTransformer implements ResourceTransformer {
+ @Override
+ public boolean canTransformResource( final String s ) {
+ return false;
+ }
+
+ @Override
+ public void processResource( final String s, final InputStream inputStream,
+ final List list ) throws IOException {
+ // no-op
+ }
+
+ @Override
+ public boolean hasTransformedResource() {
+ return true;
+ }
+
+ @Override
+ public void modifyOutputStream( final JarOutputStream jarOutputStream ) throws IOException {
+ jarOutputStream.putNextEntry( new JarEntry( CustomTransformer.class.getName() ) );
+ jarOutputStream.write( "executed".getBytes( StandardCharsets.UTF_8 ) );
+ jarOutputStream.closeEntry();
+ }
+}
diff --git a/src/it/spi/src/main/resources/META-INF/services/org.apache.maven.plugins.shade.resource.ResourceTransformer b/src/it/spi/src/main/resources/META-INF/services/org.apache.maven.plugins.shade.resource.ResourceTransformer
new file mode 100644
index 00000000..15ff9128
--- /dev/null
+++ b/src/it/spi/src/main/resources/META-INF/services/org.apache.maven.plugins.shade.resource.ResourceTransformer
@@ -0,0 +1,14 @@
+# Copyright (C) 2006-2018 Talend Inc. - www.talend.com
+#
+# Licensed 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.
+org.apache.maven.plugins.shade.it.spi.CustomTransformer
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 6b8d24a6..974504a3 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
@@ -40,7 +40,9 @@
import org.apache.maven.plugins.shade.pom.PomWriter;
import org.apache.maven.plugins.shade.relocation.Relocator;
import org.apache.maven.plugins.shade.relocation.SimpleRelocator;
+import org.apache.maven.plugins.shade.resource.ManifestResourceTransformer;
import org.apache.maven.plugins.shade.resource.ResourceTransformer;
+import org.apache.maven.plugins.shade.resource.ServicesResourceTransformer;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
@@ -76,8 +78,10 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.ServiceLoader;
import java.util.Set;
/**
@@ -762,12 +766,54 @@ private List getRelocators()
private List getResourceTransformers()
{
- if ( transformers == null )
+ final List transformers;
+ if ( this.transformers == null )
+ {
+ transformers = getDefaultResourceTransformers();
+ }
+ else
+ {
+ transformers = new ArrayList<>( Arrays.asList( this.transformers ) );
+ }
+
+ for ( final ResourceTransformer transformer : ServiceLoader.load( ResourceTransformer.class ) )
+ {
+ transformers.add( transformer );
+ }
+
+ return transformers;
+ }
+
+ private List getDefaultResourceTransformers()
+ {
+ final List transformers = new LinkedList<>();
+ if ( missTransformer( ServicesResourceTransformer.class ) )
{
- return Collections.emptyList();
+ getLog().debug( "Adding ServicesResourceTransformer transformer" );
+ transformers.add( new ServicesResourceTransformer() );
}
+ if ( missTransformer( ManifestResourceTransformer.class ) )
+ {
+ getLog().debug( "Adding ManifestResourceTransformer transformer" );
+ transformers.add( new ManifestResourceTransformer() );
+ }
+ return transformers;
+ }
- return Arrays.asList( transformers );
+ private boolean missTransformer( final Class> type )
+ {
+ if ( transformers == null )
+ {
+ return true;
+ }
+ for ( final ResourceTransformer transformer : transformers )
+ {
+ if ( type.isInstance( transformer ) )
+ {
+ return false;
+ }
+ }
+ return true;
}
private List getFilters()
@@ -778,39 +824,13 @@ private List getFilters()
if ( this.filters != null && this.filters.length > 0 )
{
- Map artifacts = new HashMap();
-
- artifacts.put( project.getArtifact(), new ArtifactId( project.getArtifact() ) );
-
- for ( Artifact artifact : project.getArtifacts() )
- {
- artifacts.put( artifact, new ArtifactId( artifact ) );
- }
+ Map artifacts = getArtifactIds();
for ( ArchiveFilter filter : this.filters )
{
ArtifactId pattern = new ArtifactId( filter.getArtifact() );
- Set jars = new HashSet();
-
- for ( Map.Entry entry : artifacts.entrySet() )
- {
- if ( entry.getValue().matches( pattern ) )
- {
- Artifact artifact = entry.getKey();
-
- jars.add( artifact.getFile() );
-
- if ( createSourcesJar )
- {
- File file = resolveArtifactSources( artifact );
- if ( file != null )
- {
- jars.add( file );
- }
- }
- }
- }
+ Set jars = getMatchingJars( artifacts, pattern );
if ( jars.isEmpty() )
{
@@ -822,6 +842,28 @@ private List getFilters()
simpleFilters.add( new SimpleFilter( jars, filter.getIncludes(), filter.getExcludes() ) );
}
}
+ else if ( this.filters == null )
+ {
+ getLog().debug( "Adding META-INF/*.SF, META-INF/*.DSA and META-INF/*.RSA exclusions" );
+
+ Map artifacts = getArtifactIds();
+ simpleFilters.add( new SimpleFilter(
+ getMatchingJars( artifacts , new ArtifactId( "*:*" ) ),
+ Collections.emptySet(),
+ new HashSet<>( Arrays.asList( "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA" ) ) ) );
+ }
+ for ( final Filter filter : ServiceLoader.load( Filter.class ) )
+ {
+ if ( SimpleFilter.class.isInstance( filter ) )
+ {
+ simpleFilters.add ( SimpleFilter.class.cast( filter ) );
+ }
+ else
+ {
+ filters.add( filter );
+ }
+ }
+
filters.addAll( simpleFilters );
@@ -842,6 +884,44 @@ private List getFilters()
return filters;
}
+ private Set getMatchingJars( final Map artifacts, final ArtifactId pattern )
+ {
+ final Set jars = new HashSet();
+
+ for ( final Map.Entry entry : artifacts.entrySet() )
+ {
+ if ( entry.getValue().matches( pattern ) )
+ {
+ final Artifact artifact = entry.getKey();
+
+ jars.add( artifact.getFile() );
+
+ if ( createSourcesJar )
+ {
+ final File file = resolveArtifactSources( artifact );
+ if ( file != null )
+ {
+ jars.add( file );
+ }
+ }
+ }
+ }
+ return jars;
+ }
+
+ private Map getArtifactIds()
+ {
+ final Map artifacts = new HashMap();
+
+ artifacts.put( project.getArtifact(), new ArtifactId( project.getArtifact() ) );
+
+ for ( final Artifact artifact : project.getArtifacts() )
+ {
+ artifacts.put( artifact, new ArtifactId( artifact ) );
+ }
+ return artifacts;
+ }
+
private File shadedArtifactFileWithClassifier()
{
Artifact artifact = project.getArtifact();
diff --git a/src/site/apt/examples/implicit-configuration.apt.vm b/src/site/apt/examples/implicit-configuration.apt.vm
new file mode 100644
index 00000000..e4f69964
--- /dev/null
+++ b/src/site/apt/examples/implicit-configuration.apt.vm
@@ -0,0 +1,68 @@
+ ------
+ Maven Shade Plugin and implicit configuration
+ ------
+ Romain Manni-Bucau
+ ------
+ 2018-12-19
+ ------
+
+~~ 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.
+
+Auto-registered configuration elements
+
+ For framework and libraries writers it can be neat to skip to their user some registration.
+ This is why some extension points are supported.
+
+ Assuming your configuration is the following one and that my-extension is a module implementing
+ a <<>> or <<>>:
+
++-----
+
+ ...
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ ${project.version}
+
+
+ org.foo.bar
+ my-extension
+ 1.0
+
+
+
+
+ package
+
+ shade
+
+
+
+
+
+
+ ...
+
++-----
+
+ Then if you register through Java <<> mecanism your <<>> / <<>>
+ then Maven Shade Plugin will automatically add them to the configuration even if not references into
+ <<>> or <<>>. This way, if your extension does not have any configuration it will
+ be active just adding the plugin dependency.
diff --git a/src/site/apt/index.apt.vm b/src/site/apt/index.apt.vm
index fb5e8662..62bc1a03 100644
--- a/src/site/apt/index.apt.vm
+++ b/src/site/apt/index.apt.vm
@@ -75,4 +75,6 @@ ${project.name}
* {{{./examples/resource-transformers.html}Resource Transformers}}
+ * {{{./examples/implicit-configuration.html}Implicit Configuration}}
+
[]
diff --git a/src/site/site.xml b/src/site/site.xml
index cba65de0..a991b5a0 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -65,6 +65,7 @@ under the License.
+