You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2018/12/26 00:13:39 UTC

[maven-archiver] branch MSHARED-787 updated (64e8b56 -> d708dc9)

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a change to branch MSHARED-787
in repository https://gitbox.apache.org/repos/asf/maven-archiver.git.


 discard 64e8b56  [MSHARED-787] Add optional buildEnvironment information to the manifest
     new d708dc9  [MSHARED-787] Add optional buildEnvironment information to the manifest

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (64e8b56)
            \
             N -- N -- N   refs/heads/MSHARED-787 (d708dc9)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pom.xml                                                    | 2 +-
 src/main/java/org/apache/maven/archiver/MavenArchiver.java | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)


[maven-archiver] 01/01: [MSHARED-787] Add optional buildEnvironment information to the manifest

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch MSHARED-787
in repository https://gitbox.apache.org/repos/asf/maven-archiver.git

commit d708dc920eee92ddd439dbfd3b3b3dd6b482a3a6
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Wed Dec 26 00:37:25 2018 +0100

    [MSHARED-787] Add optional buildEnvironment information to the manifest
---
 pom.xml                                            |  2 +-
 .../maven/archiver/ManifestConfiguration.java      | 25 +++++++++++++++++++++-
 .../org/apache/maven/archiver/MavenArchiver.java   | 22 +++++++++++++++----
 .../apache/maven/archiver/MavenArchiverTest.java   | 17 +++++++++++----
 4 files changed, 56 insertions(+), 10 deletions(-)

diff --git a/pom.xml b/pom.xml
index 10c81d4..a447146 100644
--- a/pom.xml
+++ b/pom.xml
@@ -93,7 +93,7 @@
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-archiver</artifactId>
-      <version>3.6.0</version>
+      <version>4.0.1-SNAPSHOT</version>
     </dependency>
     <!--
       ! plexus-archiver needs this, or else maven-artifact will
diff --git a/src/main/java/org/apache/maven/archiver/ManifestConfiguration.java b/src/main/java/org/apache/maven/archiver/ManifestConfiguration.java
index 7795c48..0f5e92a 100644
--- a/src/main/java/org/apache/maven/archiver/ManifestConfiguration.java
+++ b/src/main/java/org/apache/maven/archiver/ManifestConfiguration.java
@@ -57,6 +57,13 @@ public class ManifestConfiguration
     private String classpathPrefix = "";
 
     /**
+     * Add build environment information about Maven, JDK, and OS.
+     *
+     * @since 3.3.1
+     */
+    private boolean addBuildEnvironmentEntries;
+
+    /**
      * Add default implementation entries if this is an extension specification.
      *
      * @since 2.1
@@ -101,6 +108,14 @@ public class ManifestConfiguration
     }
 
     /**
+     * @return {@link #addBuildEnvironmentEntries}
+     */
+    public boolean isAddBuildEnvironmentEntries()
+    {
+        return addBuildEnvironmentEntries;
+    }
+
+    /**
      * @return {@link #addDefaultImplementationEntries}
      */
     public boolean isAddDefaultImplementationEntries()
@@ -133,6 +148,14 @@ public class ManifestConfiguration
     }
 
     /**
+     * @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.
      */
     public void setAddDefaultImplementationEntries( boolean addDefaultImplementationEntries )
@@ -250,7 +273,7 @@ public class ManifestConfiguration
      * </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>
diff --git a/src/main/java/org/apache/maven/archiver/MavenArchiver.java b/src/main/java/org/apache/maven/archiver/MavenArchiver.java
index f925a39..390f453 100644
--- a/src/main/java/org/apache/maven/archiver/MavenArchiver.java
+++ b/src/main/java/org/apache/maven/archiver/MavenArchiver.java
@@ -244,7 +244,10 @@ public class MavenArchiver
 
         // Added basic entries
         Manifest m = new Manifest();
-        addCreatedByEntry( session, m, entries );
+        if ( config.isAddBuildEnvironmentEntries() )
+        {
+            handleBuildEnvironmentEntries( session, m, entries );
+        }
 
         addCustomEntries( m, entries, config );
 
@@ -508,8 +511,6 @@ public class MavenArchiver
     private void addCustomEntries( Manifest m, Map<String, String> entries, ManifestConfiguration config )
         throws ManifestException
     {
-        addManifestAttribute( m, entries, "Build-Jdk", System.getProperty( "java.version" ) );
-
         /*
          * TODO: rethink this, it wasn't working Artifact projectArtifact = project.getArtifact(); if (
          * projectArtifact.isSnapshot() ) { Manifest.Attribute buildNumberAttr = new Manifest.Attribute( "Build-Number",
@@ -615,6 +616,9 @@ public class MavenArchiver
         Manifest manifest = getManifest( session, workingProject, archiveConfiguration );
 
         // Configure the jar
+
+        archiver.setMinimalDefaultManifest( true );
+
         archiver.addConfiguredManifest( manifest );
 
         archiver.setCompress( archiveConfiguration.isCompress() );
@@ -658,7 +662,7 @@ public class MavenArchiver
     }
 
     private void addCreatedByEntry( MavenSession session, Manifest m, Map<String, String> entries )
-        throws ManifestException
+    throws ManifestException
     {
         String createdBy = "Apache Maven";
         if ( session != null ) // can be null due to API backwards compatibility
@@ -672,6 +676,16 @@ public class MavenArchiver
         addManifestAttribute( m, entries, "Created-By", createdBy );
     }
 
+    private void handleBuildEnvironmentEntries( MavenSession session, Manifest m, Map<String, String> entries )
+        throws ManifestException
+    {
+        addCreatedByEntry( session, m, entries );
+        addManifestAttribute( m, entries, "Build-Jdk", String.format( "%s (%s)", System.getProperty( "java.version" ),
+            System.getProperty( "java.vm.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 )
diff --git a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
index f4a496b..68c1c95 100644
--- a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
+++ b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
@@ -482,6 +482,7 @@ public class MavenArchiverTest
         config.setForced( true );
         config.getManifest().setAddDefaultImplementationEntries( true );
         config.getManifest().setAddDefaultSpecificationEntries( true );
+        config.getManifest().setAddBuildEnvironmentEntries( true );
 
         // noinspection deprecation
         MavenSession session = getDummySessionWithoutMavenVersion();
@@ -490,6 +491,11 @@ public class MavenArchiverTest
         Attributes manifest = getJarFileManifest( jarFile ).getMainAttributes();
 
         assertEquals( "Apache Maven", manifest.get( new Attributes.Name( "Created-By" ) ) ); // no version number
+        assertEquals( String.format( "%s (%s)", System.getProperty( "java.version" ),
+            System.getProperty( "java.vm.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 ) );
@@ -498,8 +504,6 @@ public class MavenArchiverTest
         assertEquals( "archiver test", manifest.get( Attributes.Name.IMPLEMENTATION_TITLE ) );
         assertEquals( "0.1.1", manifest.get( Attributes.Name.IMPLEMENTATION_VERSION ) );
         assertEquals( "Apache", manifest.get( Attributes.Name.IMPLEMENTATION_VENDOR ) );
-
-        assertEquals( System.getProperty( "java.version" ), manifest.get( new Attributes.Name( "Build-Jdk" ) ) );
     }
 
     @Test
@@ -517,6 +521,7 @@ public class MavenArchiverTest
         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" );
@@ -539,6 +544,11 @@ public class MavenArchiverTest
         Attributes manifest = jarFileManifest.getMainAttributes();
 
         assertEquals( "Apache Maven 3.0.4", manifest.get( new Attributes.Name( "Created-By" ) ) );
+        assertEquals( String.format( "%s (%s)", System.getProperty( "java.version" ),
+            System.getProperty( "java.vm.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 ) );
@@ -554,8 +564,6 @@ public class MavenArchiverTest
         assertEquals( "olivier", manifest.get( new Attributes.Name( "first-name" ) ) );
         assertEquals( "org.apache.maven.archiver", manifest.getValue( "Automatic-Module-Name" ) );
 
-        assertEquals( System.getProperty( "java.version" ), manifest.get( new Attributes.Name( "Build-Jdk" ) ) );
-
         assertTrue( StringUtils.isEmpty( manifest.getValue( new Attributes.Name( "keyWithEmptyValue" ) ) ) );
         assertTrue( manifest.containsKey( new Attributes.Name( "keyWithEmptyValue" ) ) );
 
@@ -605,6 +613,7 @@ public class MavenArchiverTest
 
         MavenArchiveConfiguration config = new MavenArchiveConfiguration();
         config.setForced( true );
+        config.getManifest().setAddBuildEnvironmentEntries( true );
 
         archiver.createArchive( session, project, config );
         assertTrue( jarFile.exists() );