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-787] Add optional buildEnvironment information to the manifest #3

Merged
merged 1 commit into from
Feb 1, 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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public class ManifestConfiguration
*/
private String classpathPrefix = "";

/**
* Add build environment information about Maven, JDK, and OS.
*
* @since 3.4.0
*/
private boolean addBuildEnvironmentEntries;

/**
* Add default implementation entries if this is an extension specification.
*
Expand Down Expand Up @@ -100,6 +107,14 @@ public boolean isAddClasspath()
return addClasspath;
}

/**
* @return {@link #addBuildEnvironmentEntries}
*/
public boolean isAddBuildEnvironmentEntries()
{
return addBuildEnvironmentEntries;
}

/**
* @return {@link #addDefaultImplementationEntries}
*/
Expand Down Expand Up @@ -132,6 +147,14 @@ public void setAddClasspath( boolean addClasspath )
this.addClasspath = addClasspath;
}

/**
* @param addBuildEnvironmentEntries add build environment information true/false.
*/
public void setAddBuildEnvironmentEntries( boolean addBuildEnvironmentEntries )
{
this.addBuildEnvironmentEntries = addBuildEnvironmentEntries;
}

/**
* @param addDefaultImplementationEntries true to add default implementations false otherwise.
*/
Expand Down Expand Up @@ -250,7 +273,7 @@ public String getCustomClasspathLayout()
* </ol>
* <br>
* <b>NOTE:</b> If you specify a layout type of 'custom' you MUST set this layout expression.
* You can take a look at
* You can take a look at
* <ol>
* <li>{@link MavenArchiver#SIMPLE_LAYOUT}</li>
* <li>{@link MavenArchiver#SIMPLE_LAYOUT_NONUNIQUE}</li>
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/apache/maven/archiver/MavenArchiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ protected Manifest getManifest( MavenSession session, MavenProject project, Mani

addCustomEntries( m, entries, config );

if ( config.isAddBuildEnvironmentEntries() )
{
handleBuildEnvironmentEntries( session, m, entries );
}

if ( config.isAddClasspath() )
{
StringBuilder classpath = new StringBuilder();
Expand Down Expand Up @@ -672,6 +677,17 @@ private void addCreatedByEntry( MavenSession session, Manifest m, Map<String, St
addManifestAttribute( m, entries, "Created-By", createdBy );
}

private void handleBuildEnvironmentEntries( MavenSession session, Manifest m, Map<String, String> entries )
throws ManifestException
{
addManifestAttribute( m, entries, "Build-Tool",
session != null ? session.getSystemProperties().getProperty( "maven.build.version" ) : "Apache Maven" );
addManifestAttribute( m, entries, "Build-Jdk", String.format( "%s (%s)", System.getProperty( "java.version" ),
System.getProperty( "java.vendor" ) ) );
addManifestAttribute( m, entries, "Build-Os", String.format( "%s (%s; %s)", System.getProperty( "os.name" ),
System.getProperty( "os.version" ), System.getProperty( "os.arch" ) ) );
}

private Artifact findArtifactWithFile( Set<Artifact> artifacts, File file )
{
for ( Artifact artifact : artifacts )
Expand Down
4 changes: 2 additions & 2 deletions src/site/apt/examples/manifest.apt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Created-By: Apache Maven ${maven.version}
Build-Jdk: ${java.version}
+-----+

<<Note:>> The <<<Build-Jdk>>> does not take toolchains configuration into account. It is the same
JDK version as running the Maven instance.
<<Note:>> The <<<Build-Jdk>>> does not take toolchains configuration into account. It is the same
JDK version as running the Maven instance.

* Adding Implementation And Specification Details

Expand Down
20 changes: 16 additions & 4 deletions src/site/xdoc/index.xml.vm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
&lt;addClasspath/&gt;
&lt;addDefaultImplementationEntries/&gt;
&lt;addDefaultSpecificationEntries/&gt;
&lt;addBuildEnvironmentEntries/&gt;
&lt;addExtensions/&gt;
&lt;classpathLayoutType/&gt;
&lt;classpathPrefix/&gt;
Expand Down Expand Up @@ -197,8 +198,7 @@
<source>
Implementation-Title: \${project.name}
Implementation-Version: \${project.version}
Implementation-Vendor: \${project.organization.name}
</source>
Implementation-Vendor: \${project.organization.name}</source>
The default value is <code>false</code>.
</td>
<td>boolean</td>
Expand All @@ -211,13 +211,25 @@ Implementation-Vendor: \${project.organization.name}
<source>
Specification-Title: \${project.name}
Specification-Version: \${project.artifact.selectedVersion.majorVersion}.\${project.artifact.selectedVersion.minorVersion}
Specification-Vendor: \${project.organization.name}
</source>
Specification-Vendor: \${project.organization.name}</source>
The default value is <code>false</code>.
</td>
<td>boolean</td>
<td>2.1</td>
</tr>
<tr>
<td>addBuildEnvironmentEntries</td>
<td>
If the manifest will contain these entries:
<source>
Build-Tool: ${maven.build.version}
Build-Jdk: ${java.version} (${java.vendor})
Build-Os: ${os.name} (${os.version}; (${os.arch})</source>
The default value is <code>false</code>.
</td>
<td>boolean</td>
<td>3.4.0</td>
</tr>
<tr>
<td>addExtensions</td>
<td>
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ public void testManifestEntries()
config.setForced( true );
config.getManifest().setAddDefaultImplementationEntries( true );
config.getManifest().setAddDefaultSpecificationEntries( true );
config.getManifest().setAddBuildEnvironmentEntries( true );

Map<String, String> manifestEntries = new HashMap<String, String>();
manifestEntries.put( "foo", "bar" );
Expand All @@ -541,6 +542,14 @@ public void testManifestEntries()

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

assertEquals( session.getSystemProperties().get( "maven.build.version" ),
manifest.get( new Attributes.Name( "Build-Tool" ) ) );
assertEquals( String.format( "%s (%s)", System.getProperty( "java.version" ),
System.getProperty( "java.vendor" )), manifest.get( new Attributes.Name( "Build-Jdk" ) ) );
assertEquals( String.format( "%s (%s; %s)", System.getProperty( "os.name" ),
System.getProperty( "os.version" ), System.getProperty( "os.arch" )),
manifest.get( new Attributes.Name( "Build-Os" ) ) );

assertEquals( "archiver test", manifest.get( Attributes.Name.SPECIFICATION_TITLE ) );
assertEquals( "0.1", manifest.get( Attributes.Name.SPECIFICATION_VERSION ) );
assertEquals( "Apache", manifest.get( Attributes.Name.SPECIFICATION_VENDOR ) );
Expand Down Expand Up @@ -1410,6 +1419,8 @@ private MavenSession getDummySession()
{
Properties systemProperties = new Properties();
systemProperties.put( "maven.version", "3.0.4" );
systemProperties.put( "maven.build.version",
"Apache Maven 3.0.4 (3ad2b6794a8293a8ca6c1590708fb5d3fc795c49; 2012-01-17T08:39:41Z)" );

return getDummySession( systemProperties );
}
Expand Down