This is an automated email from the ASF dual-hosted git repository. olamy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-assembly-plugin.git
The following commit(s) were added to refs/heads/master by this push: new 6f86188d [MASSEMBLY-1030] Manifest entries from archive configuration are not added in final MANIFEST (#205) 6f86188d is described below commit 6f86188d097f58453c7fcf662c02c691020877d1 Author: Olivier Lamy <ol...@apache.org> AuthorDate: Sun May 12 13:17:31 2024 +0200 [MASSEMBLY-1030] Manifest entries from archive configuration are not added in final MANIFEST (#205) * [MASSEMBLY-1030] Manifest entries from archive configuration are not added in final MANIFEST Signed-off-by: Olivier Lamy <ol...@apache.org> * force war plugin version to get it working with more recent Java version Signed-off-by: Olivier Lamy <ol...@apache.org> --------- Signed-off-by: Olivier Lamy <ol...@apache.org> --- src/it/it-project-parent/pom.xml | 5 ++ .../pom.xml | 86 ++++++++++++++++++++++ .../src/main/assembly/web-bundle.xml | 40 ++++++++++ .../src/main/java/test/App.java | 33 +++++++++ .../src/main/webapp/WEB-INF/web.xml | 27 +++++++ .../src/main/webapp/index.jsp | 20 +++++ .../verify.bsh | 39 ++++++++++ .../archive/ManifestCreationFinalizer.java | 10 +++ 8 files changed, 260 insertions(+) diff --git a/src/it/it-project-parent/pom.xml b/src/it/it-project-parent/pom.xml index 511da0d6..37af8699 100644 --- a/src/it/it-project-parent/pom.xml +++ b/src/it/it-project-parent/pom.xml @@ -79,6 +79,11 @@ under the License. <artifactId>maven-surefire-plugin</artifactId> <version>@version.maven-surefire@</version> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-war-plugin</artifactId> + <version>3.4.0</version> + </plugin> </plugins> </pluginManagement> </build> diff --git a/src/it/projects/mojo-configuration/manifest-with-customEntry-manifest-file/pom.xml b/src/it/projects/mojo-configuration/manifest-with-customEntry-manifest-file/pom.xml new file mode 100644 index 00000000..d446ff21 --- /dev/null +++ b/src/it/projects/mojo-configuration/manifest-with-customEntry-manifest-file/pom.xml @@ -0,0 +1,86 @@ +<?xml version='1.0'?> +<!-- +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 xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd' xmlns='http://maven.apache.org/POM/4.0.0'> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.maven.plugin.assembly.test</groupId> + <artifactId>it-project-parent</artifactId> + <version>1</version> + </parent> + + <groupId>test</groupId> + <artifactId>manifest-with-customEntry-manifest-file</artifactId> + <packaging>war</packaging> + <version>1</version> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <version>5.1.9</version> + <extensions>true</extensions> + <configuration> + <supportedProjectTypes> + <supportedProjectType>war</supportedProjectType> + </supportedProjectTypes> + <instructions> + <Import-Package>jakarta.servlet.jsp.*;version="[3,4)",org.eclipse.jetty.*;version="[$(version;===;1.0),$(version;==+;1.0))",*</Import-Package> + <Export-Package>!org.example.*</Export-Package> + <Web-ContextPath>/ee10-demo-jsp</Web-ContextPath> + <Bundle-ClassPath>.,WEB-INF/classes</Bundle-ClassPath> + </instructions> + </configuration> + <executions> + <execution> + <goals> + <goal>manifest</goal> + </goals> + <phase>process-classes</phase> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <executions> + <execution> + <id>assembly</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <descriptors> + <descriptor>src/main/assembly/web-bundle.xml</descriptor> + </descriptors> + <archive> + <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> + <manifestEntries> + <foo>beer</foo> + </manifestEntries> + </archive> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> + diff --git a/src/it/projects/mojo-configuration/manifest-with-customEntry-manifest-file/src/main/assembly/web-bundle.xml b/src/it/projects/mojo-configuration/manifest-with-customEntry-manifest-file/src/main/assembly/web-bundle.xml new file mode 100644 index 00000000..41660b10 --- /dev/null +++ b/src/it/projects/mojo-configuration/manifest-with-customEntry-manifest-file/src/main/assembly/web-bundle.xml @@ -0,0 +1,40 @@ +<?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. +--> + +<assembly> + <id>webbundle</id> + <formats> + <format>jar</format> + </formats> + <includeBaseDirectory>false</includeBaseDirectory> + <fileSets> + <fileSet> + <directory>${basedir}/${project.build.directory}/${project.build.finalName}/</directory> + <outputDirectory></outputDirectory> + <includes> + <include>**/*.*</include> + </includes> + <excludes> + <exclude>WEB-INF/lib/**</exclude> + </excludes> + </fileSet> + </fileSets> +</assembly> diff --git a/src/it/projects/mojo-configuration/manifest-with-customEntry-manifest-file/src/main/java/test/App.java b/src/it/projects/mojo-configuration/manifest-with-customEntry-manifest-file/src/main/java/test/App.java new file mode 100644 index 00000000..d0442f33 --- /dev/null +++ b/src/it/projects/mojo-configuration/manifest-with-customEntry-manifest-file/src/main/java/test/App.java @@ -0,0 +1,33 @@ +package test; + +/* + * 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. + */ + + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/src/it/projects/mojo-configuration/manifest-with-customEntry-manifest-file/src/main/webapp/WEB-INF/web.xml b/src/it/projects/mojo-configuration/manifest-with-customEntry-manifest-file/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..0a242ab8 --- /dev/null +++ b/src/it/projects/mojo-configuration/manifest-with-customEntry-manifest-file/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,27 @@ +<?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. +--> + +<web-app> + + <display-name>foo WebApp</display-name> + + +</web-app> diff --git a/src/it/projects/mojo-configuration/manifest-with-customEntry-manifest-file/src/main/webapp/index.jsp b/src/it/projects/mojo-configuration/manifest-with-customEntry-manifest-file/src/main/webapp/index.jsp new file mode 100644 index 00000000..a2594328 --- /dev/null +++ b/src/it/projects/mojo-configuration/manifest-with-customEntry-manifest-file/src/main/webapp/index.jsp @@ -0,0 +1,20 @@ +<!-- +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. +--> + +nothing to see here \ No newline at end of file diff --git a/src/it/projects/mojo-configuration/manifest-with-customEntry-manifest-file/verify.bsh b/src/it/projects/mojo-configuration/manifest-with-customEntry-manifest-file/verify.bsh new file mode 100644 index 00000000..f36f0d8f --- /dev/null +++ b/src/it/projects/mojo-configuration/manifest-with-customEntry-manifest-file/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.*; +import java.util.*; +import java.net.*; + +File file = new File( basedir, "target/manifest-with-customEntry-manifest-file-1-webbundle.jar" ); + +System.out.println( "file: " + file + " exists? " + file.exists() ); + +JarFile jarFile = new JarFile( file ); + +Manifest mf = jarFile.getManifest(); + +Attributes attrs = mf.getMainAttributes(); + +String foo = (String) attrs.get( new Attributes.Name( "foo" ) ); + +System.out.println( "Got foo: " + mode ); + +return "beer".equals( foo ); diff --git a/src/main/java/org/apache/maven/plugins/assembly/archive/ManifestCreationFinalizer.java b/src/main/java/org/apache/maven/plugins/assembly/archive/ManifestCreationFinalizer.java index 98383bbc..a0f37621 100644 --- a/src/main/java/org/apache/maven/plugins/assembly/archive/ManifestCreationFinalizer.java +++ b/src/main/java/org/apache/maven/plugins/assembly/archive/ManifestCreationFinalizer.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.Collections; import java.util.List; +import java.util.Map; import org.apache.maven.archiver.MavenArchiveConfiguration; import org.apache.maven.archiver.MavenArchiver; @@ -84,6 +85,15 @@ public class ManifestCreationFinalizer extends AbstractArchiveFinalizer { manifest = mavenArchiver.getManifest(session, project, archiveConfiguration); } + if (manifest != null + && !archiveConfiguration.getManifestEntries().isEmpty()) { + for (Map.Entry<String, String> entry : + archiveConfiguration.getManifestEntries().entrySet()) { + manifest.getMainSection() + .addConfiguredAttribute(new Manifest.Attribute(entry.getKey(), entry.getValue())); + } + } + if ((manifest != null) && (archiver instanceof JarArchiver)) { final JarArchiver jarArchiver = (JarArchiver) archiver; jarArchiver.addConfiguredManifest(manifest);