Skip to content

Commit

Permalink
Add option to omit "Created-By" manifest entry (#110)
Browse files Browse the repository at this point in the history
This closes #110
  • Loading branch information
michael-o committed Dec 26, 2018
1 parent d89af3b commit 05e241f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
16 changes: 15 additions & 1 deletion src/main/java/org/codehaus/plexus/archiver/jar/JarArchiver.java
Expand Up @@ -144,6 +144,11 @@ public class JarArchiver
*/
private ArrayList<String> indexJars;

/**
* Creates a minimal default manifest with {@code Manifest-Version: 1.0} only.
*/
private boolean minimalDefaultManifest = false;

/**
* constructor
*/
Expand All @@ -166,6 +171,15 @@ public void setIndex( boolean flag )
index = flag;
}

/**
* Set whether the default manifest is minimal, thus having only {@code Manifest-Version: 1.0} in it.
*
* @param minimalDefaultManifest true to create minimal default manifest
*/
public void setMinimalDefaultManifest( boolean minimalDefaultManifest ) {
this.minimalDefaultManifest = minimalDefaultManifest;
}

@SuppressWarnings(
{
"JavaDoc", "UnusedDeclaration"
Expand Down Expand Up @@ -331,7 +345,7 @@ protected boolean hasVirtualFiles()
protected Manifest createManifest()
throws ArchiverException
{
Manifest finalManifest = Manifest.getDefaultManifest();
Manifest finalManifest = Manifest.getDefaultManifest( minimalDefaultManifest );

if ( ( manifest == null ) && ( manifestFile != null ) )
{
Expand Down
36 changes: 26 additions & 10 deletions src/main/java/org/codehaus/plexus/archiver/jar/Manifest.java
Expand Up @@ -755,31 +755,47 @@ public Iterator<String> iterator()
/**
* Construct a manifest from Ant's default manifest file.
*
* @param minimalDefaultManifest
* indicates whether a minimal manifest will be created, thus having only
* {@code Manifest-Version: 1.0} in it.
*
* @return the default manifest.
*
* @throws ArchiverException if there is a problem loading the
* default manifest
* @throws ArchiverException
* if there is a problem loading the default manifest
*/
public static Manifest getDefaultManifest()
public static Manifest getDefaultManifest( boolean minimalDefaultManifest )
throws ArchiverException
{
final Manifest defaultManifest = new Manifest();
defaultManifest.getMainAttributes().putValue( "Manifest-Version", "1.0" );

String createdBy = "Plexus Archiver";
if ( !minimalDefaultManifest )
{
String createdBy = "Plexus Archiver";

final String plexusArchiverVersion = JdkManifestFactory.getArchiverVersion();
final String plexusArchiverVersion = JdkManifestFactory.getArchiverVersion();

if ( plexusArchiverVersion != null )
{
createdBy += " " + plexusArchiverVersion;
}
if ( plexusArchiverVersion != null )
{
createdBy += " " + plexusArchiverVersion;
}

defaultManifest.getMainAttributes().putValue( "Created-By", createdBy );
defaultManifest.getMainAttributes().putValue( "Created-By", createdBy );
}

return defaultManifest;
}

/**
* @see #getDefaultManifest(boolean)
*/
public static Manifest getDefaultManifest()
throws ArchiverException
{
return getDefaultManifest( false );
}

/**
* Construct an empty manifest
*/
Expand Down
Expand Up @@ -220,6 +220,11 @@ public void testGetDefaultManifest()
assertEquals( 2, mainAttributes.size() );
assertTrue( mainAttributes.containsKey( new java.util.jar.Attributes.Name( "Manifest-Version" ) ) );
assertTrue( mainAttributes.containsKey( new java.util.jar.Attributes.Name( "Created-By" ) ) );

mf = Manifest.getDefaultManifest( true );
mainAttributes = mf.getMainAttributes();
assertEquals( 1, mainAttributes.size() );
assertTrue( mainAttributes.containsKey( new java.util.jar.Attributes.Name( "Manifest-Version" ) ) );
}

public void checkMultiLineAttribute( String in, String expected )
Expand Down

0 comments on commit 05e241f

Please sign in to comment.