Skip to content

Commit 3798e82

Browse files
Updated to stop failing creating 'Created-by' manifest entries,
when the version of the archiver cannot be determined. This closes #43
1 parent 3bff7dc commit 3798e82

File tree

2 files changed

+48
-29
lines changed

2 files changed

+48
-29
lines changed

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

+23-15
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,42 @@ class JdkManifestFactory
3333
public static java.util.jar.Manifest getDefaultManifest()
3434
throws ArchiverException
3535
{
36-
try
36+
final java.util.jar.Manifest defaultManifest = new java.util.jar.Manifest();
37+
defaultManifest.getMainAttributes().putValue( "Manifest-Version", "1.0" );
38+
39+
String createdBy = "Plexus Archiver";
40+
41+
final String plexusArchiverVersion = getArchiverVersion();
42+
43+
if ( plexusArchiverVersion != null )
3744
{
38-
final java.util.jar.Manifest defaultManifest = new java.util.jar.Manifest();
39-
defaultManifest.getMainAttributes().putValue( "Manifest-Version", "1.0" );
45+
createdBy += " " + plexusArchiverVersion;
46+
}
47+
48+
defaultManifest.getMainAttributes().putValue( "Created-By", createdBy );
49+
return defaultManifest;
50+
}
4051

41-
String createdBy = "Plexus Archiver";
52+
private static String getArchiverVersion()
53+
{
54+
String version = null;
4255

56+
try
57+
{
4358
final Properties properties = PropertyUtils.loadProperties( JdkManifestFactory.class.getResourceAsStream(
4459
"/META-INF/maven/org.codehaus.plexus/plexus-archiver/pom.properties" ) );
4560

4661
if ( properties != null )
4762
{
48-
String plexusArchiverVersion = properties.getProperty( "version" );
49-
if ( plexusArchiverVersion != null )
50-
{
51-
createdBy += " " + plexusArchiverVersion;
52-
}
63+
version = properties.getProperty( "version" );
5364
}
54-
55-
defaultManifest.getMainAttributes().putValue( "Created-By", createdBy );
56-
57-
return defaultManifest;
5865
}
5966
catch ( final IOException e )
6067
{
61-
throw new ArchiverException( "Failure reading default manifest.", e );
68+
version = null;
6269
}
70+
71+
return version;
6372
}
6473

6574
public static void merge( java.util.jar.Manifest target, java.util.jar.Manifest other, boolean overwriteMain )
@@ -113,5 +122,4 @@ public static void mergeAttributes( java.util.jar.Attributes target, java.util.j
113122
}
114123
}
115124

116-
117125
}

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

+25-14
Original file line numberDiff line numberDiff line change
@@ -735,32 +735,43 @@ public Iterator<String> iterator()
735735
public static Manifest getDefaultManifest()
736736
throws ArchiverException
737737
{
738-
try
738+
final Manifest defaultManifest = new Manifest();
739+
defaultManifest.getMainAttributes().putValue( "Manifest-Version", "1.0" );
740+
741+
String createdBy = "Plexus Archiver";
742+
743+
final String plexusArchiverVersion = getArchiverVersion();
744+
745+
if ( plexusArchiverVersion != null )
739746
{
740-
final Manifest defaultManifest = new Manifest();
741-
defaultManifest.getMainAttributes().putValue( "Manifest-Version", "1.0" );
747+
createdBy += " " + plexusArchiverVersion;
748+
}
749+
750+
defaultManifest.getMainAttributes().putValue( "Created-By", createdBy );
742751

743-
String createdBy = "Plexus Archiver";
752+
return defaultManifest;
753+
}
744754

745-
final Properties properties = PropertyUtils.loadProperties( Manifest.class.getResourceAsStream(
755+
private static String getArchiverVersion()
756+
{
757+
String version = null;
758+
759+
try
760+
{
761+
final Properties properties = PropertyUtils.loadProperties( JdkManifestFactory.class.getResourceAsStream(
746762
"/META-INF/maven/org.codehaus.plexus/plexus-archiver/pom.properties" ) );
747763

748764
if ( properties != null )
749765
{
750-
String plexusArchiverVersion = properties.getProperty( "version" );
751-
if ( plexusArchiverVersion != null )
752-
{
753-
createdBy += " " + plexusArchiverVersion;
754-
}
766+
version = properties.getProperty( "version" );
755767
}
756-
defaultManifest.getMainAttributes().putValue( "Created-By", createdBy );
757-
758-
return defaultManifest;
759768
}
760769
catch ( final IOException e )
761770
{
762-
throw new ArchiverException( "Failure reading default manifest.", e );
771+
version = null;
763772
}
773+
774+
return version;
764775
}
765776

766777
/**

0 commit comments

Comments
 (0)