Skip to content

Commit 05e241f

Browse files
committed
Add option to omit "Created-By" manifest entry (#110)
This closes #110
1 parent d89af3b commit 05e241f

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed

src/main/java/org/codehaus/plexus/archiver/jar/JarArchiver.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ public class JarArchiver
144144
*/
145145
private ArrayList<String> indexJars;
146146

147+
/**
148+
* Creates a minimal default manifest with {@code Manifest-Version: 1.0} only.
149+
*/
150+
private boolean minimalDefaultManifest = false;
151+
147152
/**
148153
* constructor
149154
*/
@@ -166,6 +171,15 @@ public void setIndex( boolean flag )
166171
index = flag;
167172
}
168173

174+
/**
175+
* Set whether the default manifest is minimal, thus having only {@code Manifest-Version: 1.0} in it.
176+
*
177+
* @param minimalDefaultManifest true to create minimal default manifest
178+
*/
179+
public void setMinimalDefaultManifest( boolean minimalDefaultManifest ) {
180+
this.minimalDefaultManifest = minimalDefaultManifest;
181+
}
182+
169183
@SuppressWarnings(
170184
{
171185
"JavaDoc", "UnusedDeclaration"
@@ -331,7 +345,7 @@ protected boolean hasVirtualFiles()
331345
protected Manifest createManifest()
332346
throws ArchiverException
333347
{
334-
Manifest finalManifest = Manifest.getDefaultManifest();
348+
Manifest finalManifest = Manifest.getDefaultManifest( minimalDefaultManifest );
335349

336350
if ( ( manifest == null ) && ( manifestFile != null ) )
337351
{

src/main/java/org/codehaus/plexus/archiver/jar/Manifest.java

+26-10
Original file line numberDiff line numberDiff line change
@@ -755,31 +755,47 @@ public Iterator<String> iterator()
755755
/**
756756
* Construct a manifest from Ant's default manifest file.
757757
*
758+
* @param minimalDefaultManifest
759+
* indicates whether a minimal manifest will be created, thus having only
760+
* {@code Manifest-Version: 1.0} in it.
761+
*
758762
* @return the default manifest.
759763
*
760-
* @throws ArchiverException if there is a problem loading the
761-
* default manifest
764+
* @throws ArchiverException
765+
* if there is a problem loading the default manifest
762766
*/
763-
public static Manifest getDefaultManifest()
767+
public static Manifest getDefaultManifest( boolean minimalDefaultManifest )
764768
throws ArchiverException
765769
{
766770
final Manifest defaultManifest = new Manifest();
767771
defaultManifest.getMainAttributes().putValue( "Manifest-Version", "1.0" );
768772

769-
String createdBy = "Plexus Archiver";
773+
if ( !minimalDefaultManifest )
774+
{
775+
String createdBy = "Plexus Archiver";
770776

771-
final String plexusArchiverVersion = JdkManifestFactory.getArchiverVersion();
777+
final String plexusArchiverVersion = JdkManifestFactory.getArchiverVersion();
772778

773-
if ( plexusArchiverVersion != null )
774-
{
775-
createdBy += " " + plexusArchiverVersion;
776-
}
779+
if ( plexusArchiverVersion != null )
780+
{
781+
createdBy += " " + plexusArchiverVersion;
782+
}
777783

778-
defaultManifest.getMainAttributes().putValue( "Created-By", createdBy );
784+
defaultManifest.getMainAttributes().putValue( "Created-By", createdBy );
785+
}
779786

780787
return defaultManifest;
781788
}
782789

790+
/**
791+
* @see #getDefaultManifest(boolean)
792+
*/
793+
public static Manifest getDefaultManifest()
794+
throws ArchiverException
795+
{
796+
return getDefaultManifest( false );
797+
}
798+
783799
/**
784800
* Construct an empty manifest
785801
*/

src/test/java/org/codehaus/plexus/archiver/jar/ManifestTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ public void testGetDefaultManifest()
220220
assertEquals( 2, mainAttributes.size() );
221221
assertTrue( mainAttributes.containsKey( new java.util.jar.Attributes.Name( "Manifest-Version" ) ) );
222222
assertTrue( mainAttributes.containsKey( new java.util.jar.Attributes.Name( "Created-By" ) ) );
223+
224+
mf = Manifest.getDefaultManifest( true );
225+
mainAttributes = mf.getMainAttributes();
226+
assertEquals( 1, mainAttributes.size() );
227+
assertTrue( mainAttributes.containsKey( new java.util.jar.Attributes.Name( "Manifest-Version" ) ) );
223228
}
224229

225230
public void checkMultiLineAttribute( String in, String expected )

0 commit comments

Comments
 (0)