jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r1868945 - in /jackrabbit/commons/filevault-package-maven-plugin/trunk: ./ src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ src/test/java/org/apache/jackrabbit/filevault/maven/packaging/ src/test/java/org/apache/jackrabbit/fil...
Date Fri, 25 Oct 2019 16:07:41 GMT
Author: kwin
Date: Fri Oct 25 16:07:41 2019
New Revision: 1868945

URL: http://svn.apache.org/viewvc?rev=1868945&view=rev
Log:
JCRVLT-387 support reproducible builds

Modified:
    jackrabbit/commons/filevault-package-maven-plugin/trunk/pom.xml
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/VaultMojo.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojoTest.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/DefaultProjectIT.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/generate-metadata-multimodule/expected-log-lines.txt
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/manifest-generation/simple/expected-manifest.txt

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/pom.xml?rev=1868945&r1=1868944&r2=1868945&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/pom.xml (original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/pom.xml Fri Oct 25 16:07:41 2019
@@ -353,17 +353,17 @@
         <dependency>
             <groupId>org.apache.maven</groupId>
             <artifactId>maven-archiver</artifactId>
-            <version>3.4.0</version>
+            <version>3.5.0</version>
         </dependency>
         <dependency>
             <groupId>org.codehaus.plexus</groupId>
             <artifactId>plexus-archiver</artifactId>
-            <version>4.1.0</version>
+            <version>4.2.0</version>
         </dependency>
         <dependency>
             <groupId>org.codehaus.plexus</groupId>
             <artifactId>plexus-utils</artifactId>
-            <version>3.0.22</version>
+            <version>3.3.0</version>
         </dependency>
         <dependency>
             <groupId>commons-lang</groupId>

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java?rev=1868945&r1=1868944&r2=1868945&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java
(original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java
Fri Oct 25 16:07:41 2019
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.filevault.
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -130,7 +131,7 @@ public class GenerateMetadataMojo extend
             property = "vault.group",
             defaultValue="${project.groupId}",
             required = true)
-    private String group;
+     String group;
 
     /**
      * The name of the content package
@@ -139,7 +140,7 @@ public class GenerateMetadataMojo extend
             property = "vault.name",
             defaultValue="${project.artifactId}",
             required = true)
-    private String name;
+    String name;
 
     /**
      * The version of the content package.
@@ -148,7 +149,7 @@ public class GenerateMetadataMojo extend
             property = "vault.version",
             defaultValue = "${project.version}",
             required = true)
-    private String version;
+    String version;
 
     /**
      * Defines the content of the filter.xml file
@@ -493,17 +494,23 @@ public class GenerateMetadataMojo extend
                 FileUtils.copyFile(thumbnailImage, new File(vaultDefinitionFolder, "thumbnail.png"));
             }
 
-            // generate manifest file
-            MavenArchiver mavenArchiver = new MavenArchiver();
-            Manifest manifest = mavenArchiver.getManifest(session, project, getMavenArchiveConfiguration(vaultProperties,
dependenciesString, dependenciesLocations));
-            try (OutputStream out = new FileOutputStream(getGeneratedManifestFile())) {
-                manifest.write(out);
-            }
+            writeManifest(getGeneratedManifestFile(), dependenciesString, dependenciesLocations,
vaultProperties);
         } catch (IOException | ManifestException | DependencyResolutionRequiredException
| ConfigurationException e) {
             throw new MojoExecutionException(e.toString(), e);
         }
         buildContext.refresh(vaultDir);
     }
+
+    void writeManifest(File file, String dependenciesString, String dependenciesLocations,
final Properties vaultProperties)
+            throws ManifestException, DependencyResolutionRequiredException, IOException,
FileNotFoundException {
+        // generate manifest file
+        MavenArchiver mavenArchiver = new MavenArchiver();
+        mavenArchiver.setCreatedBy("Apache Jackrabbit FileVault - Package Maven Plugin",
"org.apache.jackrabbit", "filevault-package-maven-plugin");
+        Manifest manifest = mavenArchiver.getManifest(session, project, getMavenArchiveConfiguration(vaultProperties,
dependenciesString, dependenciesLocations));
+        try (OutputStream out = new FileOutputStream(file)) {
+            manifest.write(out);
+        }
+    }
     
     /**
      * Computes the package filters.

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/VaultMojo.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/VaultMojo.java?rev=1868945&r1=1868944&r2=1868945&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/VaultMojo.java
(original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/VaultMojo.java
Fri Oct 25 16:07:41 2019
@@ -126,6 +126,15 @@ public class VaultMojo extends AbstractS
      */
     private Map<File, File> protectedFiles = new HashMap<>();
 
+
+    /**
+     * Timestamp for reproducible archive entries.
+     *
+     * @since 1.1.0
+     */
+    @Parameter( defaultValue = "${project.build.outputTimestamp}" )
+    private String outputTimestamp;
+
     /**
      * Creates a {@link FileSet} for the archiver
      * @param directory the directory
@@ -283,6 +292,7 @@ public class VaultMojo extends AbstractS
             MavenArchiver mavenArchiver = new MavenArchiver();
             mavenArchiver.setArchiver(contentPackageArchiver);
             mavenArchiver.setOutputFile(finalFile);
+            mavenArchiver.configureReproducible(outputTimestamp);
             mavenArchiver.createArchive(null, project, getMavenArchiveConfiguration(getGeneratedManifestFile()));
 
             // set the file for the project's artifact and ensure the

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojoTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojoTest.java?rev=1868945&r1=1868944&r2=1868945&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojoTest.java
(original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojoTest.java
Fri Oct 25 16:07:41 2019
@@ -18,15 +18,28 @@ package org.apache.jackrabbit.filevault.
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+import java.util.Properties;
 import java.util.jar.Attributes;
 import java.util.jar.Manifest;
 import java.util.regex.Pattern;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
 import org.apache.jackrabbit.vault.fs.config.ConfigurationException;
 import org.apache.jackrabbit.vault.fs.filter.DefaultPathFilter;
+import org.apache.jackrabbit.vault.packaging.PackageType;
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.archiver.jar.ManifestException;
 import org.junit.Assert;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class GenerateMetadataMojoTest {
@@ -68,6 +81,38 @@ public class GenerateMetadataMojoTest {
         Assert.assertEquals(expectedPathFilter, GenerateMetadataMojo.getPathFilterSetForEmbeddedFile("/etc/packages/some/weird/group/name-1.0.zip",
true));
     }
 
+    @Test
+    public void testWriteManifest() throws FileNotFoundException, ManifestException, DependencyResolutionRequiredException,
IOException {
+        GenerateMetadataMojo mojo = new GenerateMetadataMojo();
+        mojo.name = "mypackage";
+        mojo.group = "mygroup";
+        mojo.version = "1.4";
+        mojo.packageType = PackageType.APPLICATION;
+        mojo.project = new MavenProject();
+        Properties vaultProperties = new Properties();
+        File outputFile = File.createTempFile("filevault-test-", null);
+        String expectedManifest = 
+           "Manifest-Version: 1.0\r\n" + 
+           "Implementation-Title: empty-project\r\n" + 
+           "Content-Package-Roots: \r\n" + 
+           "Implementation-Version: 0\r\n" + 
+           "Content-Package-Dependencies: somegroup:dependency:1.0\r\n" + 
+           "Build-Jdk-Spec: 1.8\r\n" + 
+           "Content-Package-Type: application\r\n" + 
+           "Created-By: Apache Jackrabbit FileVault - Package Maven Plugin\r\n" + 
+           "Content-Package-Id: mygroup:mypackage:1.4\r\n" + 
+           "Content-Package-Description: \r\n" + 
+           "\r\n";
+        try {
+            mojo.writeManifest(outputFile, "somegroup:dependency:1.0", null, vaultProperties);
+            try (Reader reader = new InputStreamReader(new FileInputStream(outputFile), StandardCharsets.UTF_8))
{
+                Assert.assertEquals(expectedManifest, IOUtils.toString(reader));
+            }
+        } finally {
+            outputFile.delete();
+        }
+    }
+
     private void assertEscapedValueWorksInManifest(String value) throws IOException {
         String escapedValue = GenerateMetadataMojo.escapeManifestValue(value);
         Manifest manifest = new Manifest();

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/DefaultProjectIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/DefaultProjectIT.java?rev=1868945&r1=1868944&r2=1868945&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/DefaultProjectIT.java
(original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/DefaultProjectIT.java
Fri Oct 25 16:07:41 2019
@@ -19,12 +19,19 @@ package org.apache.jackrabbit.filevault.
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
 
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.security.DigestInputStream;
+import java.security.MessageDigest;
 import java.util.Calendar;
 
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.output.NullOutputStream;
 import org.apache.jackrabbit.util.ISO8601;
 import org.apache.maven.it.VerificationException;
 import org.hamcrest.number.OrderingComparison;
+import org.junit.Assert;
 import org.junit.Test;
 
 public class DefaultProjectIT {
@@ -54,6 +61,28 @@ public class DefaultProjectIT {
     }
 
     @Test
+    public void generic_project_is_reproducible() throws Exception {
+        ProjectBuilder builder = verify("generic");
+        // MD5
+        MessageDigest md = MessageDigest.getInstance("MD5");
+        try (InputStream is = new FileInputStream(builder.getTestPackageFile());
+             DigestInputStream dis = new DigestInputStream(is, md)) 
+        {
+            IOUtils.copy(dis, new NullOutputStream());
+        }
+        byte[] digest1 = md.digest();
+        builder = verify("generic");
+        // MD5
+        md = MessageDigest.getInstance("MD5");
+        try (InputStream is = new FileInputStream(builder.getTestPackageFile());
+             DigestInputStream dis = new DigestInputStream(is, md)) {
+            IOUtils.copy(dis, new NullOutputStream());
+        }
+        byte[] digest2 = md.digest();
+        Assert.assertArrayEquals(digest1, digest2);
+    }
+ 
+    @Test
     public void generic_project_package_with_metainf_contains_correct_files() throws Exception
{
         verify("generic-with-metainf");
     }

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/generate-metadata-multimodule/expected-log-lines.txt
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/generate-metadata-multimodule/expected-log-lines.txt?rev=1868945&r1=1868944&r2=1868945&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/generate-metadata-multimodule/expected-log-lines.txt
(original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/generate-metadata-multimodule/expected-log-lines.txt
Fri Oct 25 16:07:41 2019
@@ -1 +1 @@
-[INFO] No explicit version range given for dependency 'Dependency{group='test', groupId='org.apache.jackrabbit.filevault',
name='package-plugin-test-pkg-sub1', artifactId='package-plugin-test-pkg-sub1', version='null'}'.
Using default version range derived from the Maven dependency
\ No newline at end of file
+[WARNING] ValidationViolation: "jackrabbit-filter: Filter root's ancestor '/apps/bundles/install'
is not covered by any of the specified dependencies nor a valid root.", filePath=target/vault-work/META-INF/vault/filter.xml
\ No newline at end of file

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/manifest-generation/simple/expected-manifest.txt
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/manifest-generation/simple/expected-manifest.txt?rev=1868945&r1=1868944&r2=1868945&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/manifest-generation/simple/expected-manifest.txt
(original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/resources/test-projects/manifest-generation/simple/expected-manifest.txt
Fri Oct 25 16:07:41 2019
@@ -1,3 +1,4 @@
+Content-Package-Dependencies-Locations:apache/jackrabbit:test.content.package:1.0.4=maven:com.apache.jackrabbit.filevault:test.content.package:1.0.0:zip,apache/jackrabbit:test.content.package:1.0.4=maven:com.apache.jackrabbit.filevault:test.content.package:1.0.0:zip
 Content-Package-Dependencies:apache/jackrabbit:test.content.package:0.1,apache/jackrabbit:test.content.package:1.0.4
 Content-Package-Description:This is an Example Project to verify that manifest generation
is correct.
 Content-Package-Id:my/test/group:package-plugin-test-pkg:1.0.0-SNAPSHOT



Mime
View raw message