-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MSHADE-36] Support for injecting the dependency-reduced-pom.xml into…
… the final shaded jar
- Loading branch information
1 parent
57d78de
commit 6fd4581
Showing
6 changed files
with
297 additions
and
5 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/it/MSHADE-36-inject-dep-reduced-pom-in-final/invoker.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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. | ||
|
||
invoker.goals = clean package | ||
invoker.java.version = 1.8+ |
100 changes: 100 additions & 0 deletions
100
src/it/MSHADE-36-inject-dep-reduced-pom-in-final/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
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. | ||
--> | ||
|
||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.apache.maven.plugins.shade.its</groupId> | ||
<artifactId>shade-parent</artifactId> | ||
<version>1.0</version> | ||
<relativePath>../setup-parent</relativePath> | ||
</parent> | ||
|
||
<groupId>org.apache.maven.its.shade.drp</groupId> | ||
<artifactId>test</artifactId> | ||
<version>1.0</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>MSHADE-36</name> | ||
<description> | ||
Test to see that the dependency-reduced-pom.xml is injected into the final jar instead of the normal pom.xml | ||
</description> | ||
|
||
<properties> | ||
<maven.compiler.source>1.4</maven.compiler.source> | ||
<maven.compiler.target>1.4</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>3.8.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.codehaus.plexus</groupId> | ||
<artifactId>plexus-utils</artifactId> | ||
<version>1.4.1</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>@project.version@</version> | ||
<executions> | ||
<execution> | ||
<id>attach-shade</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<minimizeJar>true</minimizeJar> | ||
<createDependencyReducedPom>true</createDependencyReducedPom> | ||
<useDependencyReducedPomInJar>true</useDependencyReducedPomInJar> | ||
<relocations> | ||
<relocation> | ||
<pattern>org.codehaus.plexus</pattern> | ||
<shadedPattern>nl.example.shaded.org.codehaus.plexus</shadedPattern> | ||
</relocation> | ||
</relocations> | ||
<artifactSet> | ||
<includes> | ||
<include>junit:junit</include> | ||
<include>org.codehaus.plexus:plexus-utils</include> | ||
</includes> | ||
</artifactSet> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
33 changes: 33 additions & 0 deletions
33
src/it/MSHADE-36-inject-dep-reduced-pom-in-final/src/main/java/nl/example/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package nl.example; | ||
|
||
import org.codehaus.plexus.util.StringUtils; | ||
|
||
public class Main | ||
{ | ||
public static void main( String[] args ) { | ||
System.out.println( "Hello World!" + ( isEmpty("foo") ? " is empty!" : " -- ") ); | ||
} | ||
|
||
public static boolean isEmpty( String input ) { | ||
return StringUtils.isEmpty( input ); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/it/MSHADE-36-inject-dep-reduced-pom-in-final/verify.bsh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* 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 java.io.*; | ||
import java.util.jar.*; | ||
import java.util.Arrays; | ||
import org.codehaus.plexus.util.*; | ||
|
||
String[] wanted = | ||
{ | ||
"nl/example/Main.class", | ||
"junit/swingui/icons/error.gif", | ||
"nl/example/shaded/org/codehaus/plexus/util/StringUtils.class", | ||
}; | ||
|
||
String[] unwanted = | ||
{ | ||
"junit/swingui/TestRunner.class", | ||
"org/codehaus/plexus/util/StringUtils.class", | ||
}; | ||
|
||
JarFile jarFile = new JarFile( new File( basedir, "target/test-1.0.jar" ) ); | ||
|
||
for ( String path : wanted ) | ||
{ | ||
if ( jarFile.getEntry( path ) == null ) | ||
{ | ||
throw new IllegalStateException( "wanted path is missing: " + path ); | ||
} | ||
} | ||
|
||
for ( String path : unwanted ) | ||
{ | ||
if ( jarFile.getEntry( path ) != null ) | ||
{ | ||
throw new IllegalStateException( "unwanted path is present: " + path ); | ||
} | ||
} | ||
|
||
JarEntry jarEntry = jarFile.getEntry( "META-INF/maven/org.apache.maven.its.shade.drp/test/pom.xml" ); | ||
String pomFile = IOUtil.toString( jarFile.getInputStream( jarEntry ), "UTF-8" ); | ||
|
||
if ( pomFile.contains( "<groupId>org.codehaus.plexus</groupId>" ) ) { | ||
throw new IllegalStateException( "The pom.xml still contains a reference to the org.codehaus.plexus dependency"); | ||
} | ||
|
||
jarFile.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/org/apache/maven/plugins/shade/resource/UseDependencyReducedPomXml.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.apache.maven.plugins.shade.resource; | ||
|
||
/* | ||
* 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 org.apache.maven.project.MavenProject; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
* Manually creates the resource processors needed to remove the original pom.xml and inject | ||
* the dependency-reduced-pom.xml in it's place in the shaded JAR. | ||
*/ | ||
public class UseDependencyReducedPomXml | ||
{ | ||
public static List<ResourceTransformer> createPomXmlReplaceTransformers( | ||
MavenProject project, | ||
File dependencyReducedPomLocation | ||
) | ||
{ | ||
String pomXmlInFinalJarFilename = | ||
"META-INF/maven/" + project.getGroupId() + "/" + project.getArtifactId() + "/pom.xml"; | ||
|
||
DontIncludeResourceTransformer removePomXML = new DontIncludeResourceTransformer(); | ||
removePomXML.resource = pomXmlInFinalJarFilename; | ||
|
||
IncludeResourceTransformer insertDependencyReducedPomXML = new IncludeResourceTransformer(); | ||
insertDependencyReducedPomXML.file = dependencyReducedPomLocation; | ||
insertDependencyReducedPomXML.resource = pomXmlInFinalJarFilename; | ||
|
||
return Arrays.asList( | ||
removePomXML, | ||
insertDependencyReducedPomXML | ||
); | ||
} | ||
} |