This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch MSHADE-478-p2
in repository https://gitbox.apache.org/repos/asf/maven-shade-plugin.git

commit 6f03602d54dfe14c93be914829b9a1e5df91eb76
Author: Tamas Cservenak <[email protected]>
AuthorDate: Mon May 27 16:14:26 2024 +0200

    [MSHADE-478] Extra JARs feature
    
    Ability to add "extra JARs" and still enjoy the full
    benefits of relocation, resource transformation, etc.
    
    ---
    
    https://issues.apache.org/jira/browse/MSHADE-478
---
 .../extrajar-missing-file/invoker.properties       | 18 ++++
 src/it/projects/extrajar-missing-file/pom.xml      | 72 ++++++++++++++++
 src/it/projects/extrajar/pom.xml                   | 95 ++++++++++++++++++++++
 src/it/projects/extrajar/verify.bsh                | 39 +++++++++
 .../apache/maven/plugins/shade/mojo/ShadeMojo.java | 21 +++++
 5 files changed, 245 insertions(+)

diff --git a/src/it/projects/extrajar-missing-file/invoker.properties 
b/src/it/projects/extrajar-missing-file/invoker.properties
new file mode 100644
index 0000000..f2a7dfb
--- /dev/null
+++ b/src/it/projects/extrajar-missing-file/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.buildResult = failure
diff --git a/src/it/projects/extrajar-missing-file/pom.xml 
b/src/it/projects/extrajar-missing-file/pom.xml
new file mode 100644
index 0000000..56ea580
--- /dev/null
+++ b/src/it/projects/extrajar-missing-file/pom.xml
@@ -0,0 +1,72 @@
+<?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>
+
+  <groupId>org.apache.maven.its.shade.extrajar</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0</version>
+  <packaging>jar</packaging>
+
+  <name>extrajar</name>
+  <description>
+    Test that asserts failure if specified extra jar is not a file.
+  </description>
+
+  <properties>
+    <slf4j.version>1.7.36</slf4j.version>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>${slf4j.version}</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <!-- See extrajar IT: removed m-dep-p:copy so the file is not there -->
+      <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>
+              <shadedArtifactAttached>true</shadedArtifactAttached>
+              <extraJars>
+                
<extraJar>${project.build.directory}/dependency/slf4j-simple.jar</extraJar>
+              </extraJars>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/it/projects/extrajar/pom.xml b/src/it/projects/extrajar/pom.xml
new file mode 100644
index 0000000..eff4a00
--- /dev/null
+++ b/src/it/projects/extrajar/pom.xml
@@ -0,0 +1,95 @@
+<?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>
+
+  <groupId>org.apache.maven.its.shade.extrajar</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0</version>
+  <packaging>jar</packaging>
+
+  <name>extrajar</name>
+  <description>
+    Test that asserts addition of extra-jars.
+  </description>
+
+  <properties>
+    <slf4j.version>1.7.36</slf4j.version>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>${slf4j.version}</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <version>3.6.1</version>
+        <executions>
+          <execution>
+            <id>copy-extra-jars</id>
+            <phase>package</phase>
+            <goals>
+              <goal>copy</goal>
+            </goals>
+            <configuration>
+              <stripVersion>true</stripVersion>
+              <artifactItems>
+                <artifactItem>
+                  <groupId>org.slf4j</groupId>
+                  <artifactId>slf4j-simple</artifactId>
+                  <version>${slf4j.version}</version>
+                </artifactItem>
+              </artifactItems>
+            </configuration>
+          </execution>
+        </executions>
+      </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>
+              <shadedArtifactAttached>true</shadedArtifactAttached>
+              <extraJars>
+                
<extraJar>${project.build.directory}/dependency/slf4j-simple.jar</extraJar>
+              </extraJars>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/it/projects/extrajar/verify.bsh 
b/src/it/projects/extrajar/verify.bsh
new file mode 100644
index 0000000..b7d1db3
--- /dev/null
+++ b/src/it/projects/extrajar/verify.bsh
@@ -0,0 +1,39 @@
+/*
+ * 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.*;
+
+String[] wanted =
+{
+    "org/slf4j/Logger.class",
+    "org/slf4j/impl/SimpleLogger.class"
+};
+
+JarFile jarFile = new JarFile( new File( basedir, "target/test-1.0-shaded.jar" 
) );
+
+for ( String path : wanted )
+{
+    if ( jarFile.getEntry( path ) == null )
+    {
+        throw new IllegalStateException( "wanted path is missing: " + path );
+    }
+}
+
+jarFile.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 48a39d9..497ba4a 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
@@ -393,6 +393,16 @@ public class ShadeMojo extends AbstractMojo {
     @Parameter(defaultValue = "false")
     private boolean skip;
 
+    /**
+     * Extra JAR files to process into shaded result. One can add here "extra 
JARs" to be processed into the resulting
+     * shaded JAR. The listed JAR files must exist. Extra JARs will be 
processed in same way as any other dependency
+     * (regarding relocation, filtering, resource transformers etc.).
+     *
+     * @since 3.6.0
+     */
+    @Parameter
+    private List<File> extraJars;
+
     @Inject
     private MavenProjectHelper projectHelper;
 
@@ -444,6 +454,17 @@ public class ShadeMojo extends AbstractMojo {
 
             artifacts.add(project.getArtifact().getFile());
 
+            if (extraJars != null && !extraJars.isEmpty()) {
+                for (File extraJar : extraJars) {
+                    if (!Files.isRegularFile(extraJar.toPath())) {
+                        createErrorOutput();
+                        throw new MojoExecutionException("Failed to create 
shaded artifact, "
+                                + "extra JAR artifact does not exist: " + 
extraJar);
+                    }
+                    artifacts.add(extraJar);
+                }
+            }
+
             if (createSourcesJar) {
                 File file = shadedSourcesArtifactFile();
                 if (file.isFile()) {

Reply via email to