From 0bb64a478bbf795df8b69e2fe267ebdd8c8e6481 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Tue, 23 Aug 2005 07:31:04 +0000 Subject: [PATCH] PR: MNG-742 Submitted by: Timothy Bennett Reviewed by: Brett Porter allow addition of custom entries to the manifest git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@239374 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiver/MavenArchiveConfiguration.java | 24 +++++++++++++++ .../apache/maven/archiver/MavenArchiver.java | 30 ++++++++++++++----- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiveConfiguration.java b/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiveConfiguration.java index c0a1caae03..74b75cc7d4 100644 --- a/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiveConfiguration.java +++ b/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiveConfiguration.java @@ -17,6 +17,8 @@ package org.apache.maven.archiver; */ import java.io.File; +import java.util.HashMap; +import java.util.Map; /** * Capture common archive configuration. @@ -35,6 +37,8 @@ public class MavenArchiveConfiguration private ManifestConfiguration manifest; + private Map manifestEntries = new HashMap(); + public boolean isCompress() { return compress; @@ -78,4 +82,24 @@ public class MavenArchiveConfiguration { this.manifest = manifest; } + + public void addManifestEntry( Object key, Object value ) + { + manifestEntries.put( key, value ); + } + + public void addManifestEntries( Map map ) + { + manifestEntries.putAll( map ); + } + + public boolean isManifestEntriesEmpty() + { + return manifestEntries.isEmpty(); + } + + public Map getManifestEntries() + { + return manifestEntries; + } } diff --git a/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java b/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java index 770ac8bf7a..721133f7f8 100644 --- a/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java +++ b/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java @@ -32,6 +32,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.Set; @@ -42,7 +43,7 @@ import java.util.Set; public class MavenArchiver { private JarArchiver archiver = new JarArchiver(); - + private File archiveFile; /** @@ -59,12 +60,13 @@ public class MavenArchiver m.addConfiguredAttribute( buildAttr ); Manifest.Attribute createdAttr = new Manifest.Attribute( "Created-By", "Apache Maven" ); m.addConfiguredAttribute( createdAttr ); - + Artifact projectArtifact = project.getArtifact(); - + if ( projectArtifact.isSnapshot() ) { - Manifest.Attribute buildNumberAttr = new Manifest.Attribute( "Build-Number", "" + project.getSnapshotDeploymentBuildNumber() ); + Manifest.Attribute buildNumberAttr = new Manifest.Attribute( "Build-Number", "" + + project.getSnapshotDeploymentBuildNumber() ); m.addConfiguredAttribute( buildNumberAttr ); } @@ -222,16 +224,16 @@ public class MavenArchiver // top-level POM elements so that applications that wish to access // POM information without the use of maven tools can do so. // ---------------------------------------------------------------------- - + // we have to clone the project instance so we can write out the pom with the deployment version, // without impacting the main project instance... MavenProject workingProject = new MavenProject( project ); - + if ( workingProject.getArtifact().isSnapshot() ) { workingProject.setVersion( workingProject.getSnapshotDeploymentVersion() ); } - + String groupId = workingProject.getGroupId(); String artifactId = workingProject.getArtifactId(); @@ -275,6 +277,20 @@ public class MavenArchiver Manifest manifest = getManifest( workingProject, archiveConfiguration.getManifest() ); + // any custom manifest entries in the archive configuration manifest? + if ( !archiveConfiguration.isManifestEntriesEmpty() ) + { + Map entries = archiveConfiguration.getManifestEntries(); + Set keys = entries.keySet(); + for ( Iterator iter = keys.iterator(); iter.hasNext(); ) + { + String key = (String) iter.next(); + String value = (String) entries.get( key ); + Manifest.Attribute attr = new Manifest.Attribute( key, value ); + manifest.addConfiguredAttribute( attr ); + } + } + // Configure the jar archiver.addConfiguredManifest( manifest );