[maven-archiver] branch MSHARED-798 created (now cf2399a)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[maven-archiver] branch MSHARED-798 created (now cf2399a)

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

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


      at cf2399a  [MSHARED-798] Add defaultEntries option

This branch includes the following new commits:

     new cf2399a  [MSHARED-798] Add defaultEntries option

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.


Reply | Threaded
Open this post in threaded view
|

[maven-archiver] 01/01: [MSHARED-798] Add defaultEntries option

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

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

commit cf2399ae3e88cad426c98cfd782a33f7e8048420
Author: Michael Osipov <[hidden email]>
AuthorDate: Wed Feb 6 21:17:12 2019 +0100

    [MSHARED-798] Add defaultEntries option
---
 .../maven/archiver/ManifestConfiguration.java      | 24 +++++++++++++++++
 .../org/apache/maven/archiver/MavenArchiver.java   | 31 +++++++++++++---------
 src/site/xdoc/index.xml.vm                         | 13 +++++++++
 .../apache/maven/archiver/MavenArchiverTest.java   | 27 +++++++++++++++++++
 4 files changed, 82 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/apache/maven/archiver/ManifestConfiguration.java b/src/main/java/org/apache/maven/archiver/ManifestConfiguration.java
index 51078d1..ccfc621 100644
--- a/src/main/java/org/apache/maven/archiver/ManifestConfiguration.java
+++ b/src/main/java/org/apache/maven/archiver/ManifestConfiguration.java
@@ -57,6 +57,14 @@ public class ManifestConfiguration
     private String classpathPrefix = "";
 
     /**
+     * Add default, reproducible entries {@code Created-By} and {@code Build-Jdk-Spec}.
+     *
+     * @since 3.4.0
+     */
+    private boolean addDefaultEntries = true;
+
+
+    /**
      * Add build environment information about Maven, JDK, and OS.
      *
      * @since 3.4.0
@@ -108,6 +116,14 @@ public class ManifestConfiguration
     }
 
     /**
+     * @return {@link #addDefaultEntries}
+     */
+    public boolean isAddDefaultEntries()
+    {
+        return addDefaultEntries;
+    }
+
+    /**
      * @return {@link #addBuildEnvironmentEntries}
      */
     public boolean isAddBuildEnvironmentEntries()
@@ -148,6 +164,14 @@ public class ManifestConfiguration
     }
 
     /**
+     * @param addDefaultEntries add default entries true/false.
+     */
+    public void setAddDefaultEntries( boolean addDefaultEntries )
+    {
+        this.addDefaultEntries = addDefaultEntries;
+    }
+
+    /**
      * @param addBuildEnvironmentEntries add build environment information true/false.
      */
     public void setAddBuildEnvironmentEntries( boolean addBuildEnvironmentEntries )
diff --git a/src/main/java/org/apache/maven/archiver/MavenArchiver.java b/src/main/java/org/apache/maven/archiver/MavenArchiver.java
index 591a464..2922f6e 100644
--- a/src/main/java/org/apache/maven/archiver/MavenArchiver.java
+++ b/src/main/java/org/apache/maven/archiver/MavenArchiver.java
@@ -58,6 +58,8 @@ import java.util.jar.Attributes;
 public class MavenArchiver
 {
 
+    private static final String CREATED_BY = "Maven Archiver";
+
     /**
      * The simply layout.
      */
@@ -243,11 +245,13 @@ public class MavenArchiver
     {
         // TODO: Should we replace "map" with a copy? Note, that we modify it!
 
-        // Added basic entries
         Manifest m = new Manifest();
-        addCreatedByEntry( session, m, entries );
 
-        addCustomEntries( m, entries, config );
+        if ( config.isAddDefaultEntries() )
+        {
+            handleDefaultEntries( m, entries );
+        }
+
 
         if ( config.isAddBuildEnvironmentEntries() )
         {
@@ -393,6 +397,8 @@ public class MavenArchiver
             handleExtensions( project, entries, m );
         }
 
+        addCustomEntries( m, entries, config );
+
         return m;
     }
 
@@ -514,8 +520,6 @@ public class MavenArchiver
     private void addCustomEntries( Manifest m, Map<String, String> entries, ManifestConfiguration config )
         throws ManifestException
     {
-        addManifestAttribute( m, entries, "Build-Jdk-Spec", System.getProperty( "java.specification.version" ) );
-
         /*
          * TODO: rethink this, it wasn't working Artifact projectArtifact = project.getArtifact(); if (
          * projectArtifact.isSnapshot() ) { Manifest.Attribute buildNumberAttr = new Manifest.Attribute( "Build-Number",
@@ -665,16 +669,17 @@ public class MavenArchiver
         archiver.createArchive();
     }
 
-    private void addCreatedByEntry( MavenSession session, Manifest m, Map<String, String> entries )
+    private void handleDefaultEntries( Manifest m, Map<String, String> entries )
         throws ManifestException
     {
-        String createdBy = "Maven Archiver";
-        String archiverVersion = getArchiverVersion();
-        if ( archiverVersion != null )
-        {
-            createdBy += " " + archiverVersion;
-        }
-        addManifestAttribute( m, entries, "Created-By", createdBy );
+         String createdBy = CREATED_BY;
+         String archiverVersion = getArchiverVersion();
+         if ( archiverVersion != null )
+         {
+             createdBy += " " + archiverVersion;
+         }
+         addManifestAttribute( m, entries, "Created-By", createdBy );
+         addManifestAttribute( m, entries, "Build-Jdk-Spec", System.getProperty( "java.specification.version" ) );
     }
 
     private void handleBuildEnvironmentEntries( MavenSession session, Manifest m, Map<String, String> entries )
diff --git a/src/site/xdoc/index.xml.vm b/src/site/xdoc/index.xml.vm
index d7ce85f..68af2b9 100644
--- a/src/site/xdoc/index.xml.vm
+++ b/src/site/xdoc/index.xml.vm
@@ -41,6 +41,7 @@
   &lt;index/&gt;
   &lt;<a href="#class_manifest">manifest</a>&gt;
     &lt;addClasspath/&gt;
+    &lt;addDefaultEntries/&gt;
     &lt;addDefaultImplementationEntries/&gt;
     &lt;addDefaultSpecificationEntries/&gt;
     &lt;addBuildEnvironmentEntries/&gt;
@@ -192,6 +193,18 @@
             <td></td>
           </tr>
           <tr>
+            <td>addDefaultEntries</td>
+            <td>
+              If the manifest will contain these entries:
+              <source>
+Created-By: Maven Archiver ${maven-archiver.version}
+Build-Jdk-Spec: ${java.specification.version}</source>
+              The default value is <code>true</code>.
+            </td>
+            <td>boolean</td>
+            <td>3.4.0</td>
+          </tr>
+          <tr>
             <td>addDefaultImplementationEntries</td>
             <td>
               If the manifest will contain these entries:
diff --git a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
index 77b53df..6e0e81e 100644
--- a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
+++ b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
@@ -505,6 +505,33 @@ public class MavenArchiverTest
     }
 
     @Test
+    public void testMinimalManifestEntries()
+        throws Exception
+    {
+        File jarFile = new File( "target/test/dummy.jar" );
+        JarArchiver jarArchiver = getCleanJarArchiver( jarFile );
+
+        MavenArchiver archiver = getMavenArchiver( jarArchiver );
+
+        MavenSession session = getDummySession();
+        MavenProject project = getDummyProject();
+        MavenArchiveConfiguration config = new MavenArchiveConfiguration();
+        config.setForced( true );
+        config.getManifest().setAddDefaultEntries( false );
+
+        archiver.createArchive( session, project, config );
+        assertTrue( jarFile.exists() );
+
+        final Manifest jarFileManifest = getJarFileManifest( jarFile );
+        Attributes manifest = jarFileManifest.getMainAttributes();
+
+        assertEquals( 1, manifest.size() );
+        assertEquals( new Attributes.Name( "Manifest-Version" ), manifest.keySet().iterator().next() );
+        assertEquals( "1.0", manifest.getValue( "Manifest-Version" ) );
+    }
+
+
+    @Test
     public void testManifestEntries()
         throws Exception
     {