Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MSHARED-799] Change "Created-By" manifest entry value to be reproducible #4

Merged
merged 1 commit into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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