Skip to content

Commit

Permalink
[MSHARED-799] Change "Created-By" manifest entry value to be reproduc…
Browse files Browse the repository at this point in the history
…ible

The test method testCreatedByManifestEntryWithoutMavenVersion() has been
dropped because its function is coverted by two other tests as well.

This closes #4
  • Loading branch information
michael-o committed Feb 4, 2019
1 parent 93f5ba1 commit 7041fca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 33 deletions.
23 changes: 16 additions & 7 deletions src/main/java/org/apache/maven/archiver/MavenArchiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.codehaus.plexus.interpolation.RecursionInterceptor;
import org.codehaus.plexus.interpolation.StringSearchInterpolator;
import org.codehaus.plexus.interpolation.ValueSource;
import org.apache.maven.shared.utils.PropertyUtils;
import org.apache.maven.shared.utils.StringUtils;

import javax.lang.model.SourceVersion;
Expand Down Expand Up @@ -610,6 +611,8 @@ public void createArchive( MavenSession session, MavenProject project,
// Create the manifest
// ----------------------------------------------------------------------

archiver.setMinimalDefaultManifest( true );

File manifestFile = archiveConfiguration.getManifestFile();

if ( manifestFile != null )
Expand Down Expand Up @@ -665,14 +668,11 @@ public void createArchive( MavenSession session, MavenProject project,
private void addCreatedByEntry( MavenSession session, Manifest m, Map<String, String> entries )
throws ManifestException
{
String createdBy = "Apache Maven";
if ( session != null ) // can be null due to API backwards compatibility
String createdBy = "Maven Archiver";
String archiverVersion = getArchiverVersion();
if ( archiverVersion != null )
{
String mavenVersion = session.getSystemProperties().getProperty( "maven.version" );
if ( mavenVersion != null )
{
createdBy += " " + mavenVersion;
}
createdBy += " " + archiverVersion;
}
addManifestAttribute( m, entries, "Created-By", createdBy );
}
Expand Down Expand Up @@ -703,4 +703,13 @@ private Artifact findArtifactWithFile( Set<Artifact> artifacts, File file )
}
return null;
}

private static String getArchiverVersion()
{
final Properties properties = PropertyUtils.loadOptionalProperties( MavenArchiver.class.getResourceAsStream(
"/META-INF/maven/org.apache.maven/maven-archiver/pom.properties" ) );

return properties.getProperty( "version" );
}

}
30 changes: 4 additions & 26 deletions src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,8 @@ public void testDeprecatedCreateArchiveAPI()
assertTrue( jarFile.exists() );
Attributes manifest = getJarFileManifest( jarFile ).getMainAttributes();

assertEquals( "Apache Maven", manifest.get( new Attributes.Name( "Created-By" ) ) ); // no version number
// no version number
assertEquals( "Maven Archiver", manifest.get( new Attributes.Name( "Created-By" ) ) );

assertEquals( "archiver test", manifest.get( Attributes.Name.SPECIFICATION_TITLE ) );
assertEquals( "0.1", manifest.get( Attributes.Name.SPECIFICATION_VERSION ) );
Expand Down Expand Up @@ -540,7 +541,8 @@ public void testManifestEntries()
final Manifest jarFileManifest = getJarFileManifest( jarFile );
Attributes manifest = jarFileManifest.getMainAttributes();

assertEquals( "Apache Maven 3.0.4", manifest.get( new Attributes.Name( "Created-By" ) ) );
// no version number
assertEquals( "Maven Archiver", manifest.get( new Attributes.Name( "Created-By" ) ) );

assertEquals( session.getSystemProperties().get( "maven.build.version" ),
manifest.get( new Attributes.Name( "Build-Tool" ) ) );
Expand Down Expand Up @@ -602,30 +604,6 @@ public void testManifestWithInvalidAutomaticModuleNameThrowsOnCreateArchive()
}
}

@Test
public void testCreatedByManifestEntryWithoutMavenVersion()
throws Exception
{
File jarFile = new File( "target/test/dummy.jar" );
JarArchiver jarArchiver = getCleanJarArchiver( jarFile );

MavenArchiver archiver = getMavenArchiver( jarArchiver );

MavenSession session = getDummySessionWithoutMavenVersion();
MavenProject project = getDummyProject();

MavenArchiveConfiguration config = new MavenArchiveConfiguration();
config.setForced( true );

archiver.createArchive( session, project, config );
assertTrue( jarFile.exists() );

final Manifest manifest = getJarFileManifest( jarFile );
Map<Object, Object> entries = manifest.getMainAttributes();

assertEquals( "Apache Maven", entries.get( new Attributes.Name( "Created-By" ) ) );
}

/*
* Test to make sure that manifest sections are present in the manifest prior to the archive has been created.
*/
Expand Down

0 comments on commit 7041fca

Please sign in to comment.