Skip to content

Commit 93f5ba1

Browse files
committed
[MSHARED-787] Add optional buildEnvironment information to the manifest
This closes #3
1 parent 12a5885 commit 93f5ba1

File tree

5 files changed

+69
-7
lines changed

5 files changed

+69
-7
lines changed

src/main/java/org/apache/maven/archiver/ManifestConfiguration.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ public class ManifestConfiguration
5656
*/
5757
private String classpathPrefix = "";
5858

59+
/**
60+
* Add build environment information about Maven, JDK, and OS.
61+
*
62+
* @since 3.4.0
63+
*/
64+
private boolean addBuildEnvironmentEntries;
65+
5966
/**
6067
* Add default implementation entries if this is an extension specification.
6168
*
@@ -100,6 +107,14 @@ public boolean isAddClasspath()
100107
return addClasspath;
101108
}
102109

110+
/**
111+
* @return {@link #addBuildEnvironmentEntries}
112+
*/
113+
public boolean isAddBuildEnvironmentEntries()
114+
{
115+
return addBuildEnvironmentEntries;
116+
}
117+
103118
/**
104119
* @return {@link #addDefaultImplementationEntries}
105120
*/
@@ -132,6 +147,14 @@ public void setAddClasspath( boolean addClasspath )
132147
this.addClasspath = addClasspath;
133148
}
134149

150+
/**
151+
* @param addBuildEnvironmentEntries add build environment information true/false.
152+
*/
153+
public void setAddBuildEnvironmentEntries( boolean addBuildEnvironmentEntries )
154+
{
155+
this.addBuildEnvironmentEntries = addBuildEnvironmentEntries;
156+
}
157+
135158
/**
136159
* @param addDefaultImplementationEntries true to add default implementations false otherwise.
137160
*/
@@ -250,7 +273,7 @@ public String getCustomClasspathLayout()
250273
* </ol>
251274
* <br>
252275
* <b>NOTE:</b> If you specify a layout type of 'custom' you MUST set this layout expression.
253-
* You can take a look at
276+
* You can take a look at
254277
* <ol>
255278
* <li>{@link MavenArchiver#SIMPLE_LAYOUT}</li>
256279
* <li>{@link MavenArchiver#SIMPLE_LAYOUT_NONUNIQUE}</li>

src/main/java/org/apache/maven/archiver/MavenArchiver.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ protected Manifest getManifest( MavenSession session, MavenProject project, Mani
248248

249249
addCustomEntries( m, entries, config );
250250

251+
if ( config.isAddBuildEnvironmentEntries() )
252+
{
253+
handleBuildEnvironmentEntries( session, m, entries );
254+
}
255+
251256
if ( config.isAddClasspath() )
252257
{
253258
StringBuilder classpath = new StringBuilder();
@@ -672,6 +677,17 @@ private void addCreatedByEntry( MavenSession session, Manifest m, Map<String, St
672677
addManifestAttribute( m, entries, "Created-By", createdBy );
673678
}
674679

680+
private void handleBuildEnvironmentEntries( MavenSession session, Manifest m, Map<String, String> entries )
681+
throws ManifestException
682+
{
683+
addManifestAttribute( m, entries, "Build-Tool",
684+
session != null ? session.getSystemProperties().getProperty( "maven.build.version" ) : "Apache Maven" );
685+
addManifestAttribute( m, entries, "Build-Jdk", String.format( "%s (%s)", System.getProperty( "java.version" ),
686+
System.getProperty( "java.vendor" ) ) );
687+
addManifestAttribute( m, entries, "Build-Os", String.format( "%s (%s; %s)", System.getProperty( "os.name" ),
688+
System.getProperty( "os.version" ), System.getProperty( "os.arch" ) ) );
689+
}
690+
675691
private Artifact findArtifactWithFile( Set<Artifact> artifacts, File file )
676692
{
677693
for ( Artifact artifact : artifacts )

src/site/apt/examples/manifest.apt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ Created-By: Apache Maven ${maven.version}
3636
Build-Jdk: ${java.version}
3737
+-----+
3838

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

4242
* Adding Implementation And Specification Details
4343

src/site/xdoc/index.xml.vm

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
&lt;addClasspath/&gt;
4444
&lt;addDefaultImplementationEntries/&gt;
4545
&lt;addDefaultSpecificationEntries/&gt;
46+
&lt;addBuildEnvironmentEntries/&gt;
4647
&lt;addExtensions/&gt;
4748
&lt;classpathLayoutType/&gt;
4849
&lt;classpathPrefix/&gt;
@@ -197,8 +198,7 @@
197198
<source>
198199
Implementation-Title: \${project.name}
199200
Implementation-Version: \${project.version}
200-
Implementation-Vendor: \${project.organization.name}
201-
</source>
201+
Implementation-Vendor: \${project.organization.name}</source>
202202
The default value is <code>false</code>.
203203
</td>
204204
<td>boolean</td>
@@ -211,13 +211,25 @@ Implementation-Vendor: \${project.organization.name}
211211
<source>
212212
Specification-Title: \${project.name}
213213
Specification-Version: \${project.artifact.selectedVersion.majorVersion}.\${project.artifact.selectedVersion.minorVersion}
214-
Specification-Vendor: \${project.organization.name}
215-
</source>
214+
Specification-Vendor: \${project.organization.name}</source>
216215
The default value is <code>false</code>.
217216
</td>
218217
<td>boolean</td>
219218
<td>2.1</td>
220219
</tr>
220+
<tr>
221+
<td>addBuildEnvironmentEntries</td>
222+
<td>
223+
If the manifest will contain these entries:
224+
<source>
225+
Build-Tool: ${maven.build.version}
226+
Build-Jdk: ${java.version} (${java.vendor})
227+
Build-Os: ${os.name} (${os.version}; (${os.arch})</source>
228+
The default value is <code>false</code>.
229+
</td>
230+
<td>boolean</td>
231+
<td>3.4.0</td>
232+
</tr>
221233
<tr>
222234
<td>addExtensions</td>
223235
<td>

src/test/java/org/apache/maven/archiver/MavenArchiverTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ public void testManifestEntries()
518518
config.setForced( true );
519519
config.getManifest().setAddDefaultImplementationEntries( true );
520520
config.getManifest().setAddDefaultSpecificationEntries( true );
521+
config.getManifest().setAddBuildEnvironmentEntries( true );
521522

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

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

545+
assertEquals( session.getSystemProperties().get( "maven.build.version" ),
546+
manifest.get( new Attributes.Name( "Build-Tool" ) ) );
547+
assertEquals( String.format( "%s (%s)", System.getProperty( "java.version" ),
548+
System.getProperty( "java.vendor" )), manifest.get( new Attributes.Name( "Build-Jdk" ) ) );
549+
assertEquals( String.format( "%s (%s; %s)", System.getProperty( "os.name" ),
550+
System.getProperty( "os.version" ), System.getProperty( "os.arch" )),
551+
manifest.get( new Attributes.Name( "Build-Os" ) ) );
552+
544553
assertEquals( "archiver test", manifest.get( Attributes.Name.SPECIFICATION_TITLE ) );
545554
assertEquals( "0.1", manifest.get( Attributes.Name.SPECIFICATION_VERSION ) );
546555
assertEquals( "Apache", manifest.get( Attributes.Name.SPECIFICATION_VENDOR ) );
@@ -1410,6 +1419,8 @@ private MavenSession getDummySession()
14101419
{
14111420
Properties systemProperties = new Properties();
14121421
systemProperties.put( "maven.version", "3.0.4" );
1422+
systemProperties.put( "maven.build.version",
1423+
"Apache Maven 3.0.4 (3ad2b6794a8293a8ca6c1590708fb5d3fc795c49; 2012-01-17T08:39:41Z)" );
14131424

14141425
return getDummySession( systemProperties );
14151426
}

0 commit comments

Comments
 (0)