You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2018/06/30 18:23:44 UTC

[maven-deploy-plugin] 04/04: [MSHARED-695] - WIP - Move checksum generation from install to deploy o stat of IT's. to check for checksums.

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

khmarbaise pushed a commit to branch MSHARED-695
in repository https://gitbox.apache.org/repos/asf/maven-deploy-plugin.git

commit 6c3df7de981c44345ad580d8cc1ac6069a0ca95e
Author: Karl Heinz Marbaise <kh...@apache.org>
AuthorDate: Sat May 12 14:59:12 2018 +0200

    [MSHARED-695] - WIP - Move checksum generation from install to deploy
     o stat of IT's. to check for checksums.
---
 pom.xml                                            |  1 +
 src/it/attach-jar-checksum-release/pom.xml         | 89 ++++++++++++++++++++++
 src/it/attach-jar-checksum-release/setup.bsh       | 29 +++++++
 src/it/attach-jar-checksum-release/verify.groovy   | 63 +++++++++++++++
 src/it/attach-jar-checksum-snapshot/pom.xml        | 89 ++++++++++++++++++++++
 src/it/attach-jar-checksum-snapshot/setup.bsh      | 29 +++++++
 src/it/attach-jar-checksum-snapshot/verify.groovy  | 66 ++++++++++++++++
 .../org/apache/maven/plugins/deploy/Utils.java     | 64 ++++++++++++++++
 8 files changed, 430 insertions(+)

diff --git a/pom.xml b/pom.xml
index 521b56f..aa28e45 100644
--- a/pom.xml
+++ b/pom.xml
@@ -185,6 +185,7 @@ under the License.
                 <postBuildHookScript>verify</postBuildHookScript>
                 <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
                 <settingsFile>src/it/settings.xml</settingsFile>
+                <addTestClassPath>true</addTestClassPath>
                 <goals>
                   <goal>deploy</goal>
                 </goals>
diff --git a/src/it/attach-jar-checksum-release/pom.xml b/src/it/attach-jar-checksum-release/pom.xml
new file mode 100644
index 0000000..d0e28b0
--- /dev/null
+++ b/src/it/attach-jar-checksum-release/pom.xml
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.deploy.ajc</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0</version>
+  <packaging>jar</packaging>
+
+  <description>
+    This test has been moved from maven-install-plugin to maven-deploy-plugin.
+    Tests the installation of a simple snapshot JAR with an attached artifact and checksums
+  </description>
+
+  <properties>
+    <maven.test.skip>true</maven.test.skip>
+  </properties>
+  <distributionManagement>
+    <repository>
+      <id>it</id>
+      <url>file:///${basedir}/target/repo</url>
+    </repository>
+  </distributionManagement>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.0.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-deploy-plugin</artifactId>
+        <version>@project.version@</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <version>2.1</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>2.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-source-plugin</artifactId>
+        <version>2.0.4</version>
+        <executions>
+          <execution>
+            <id>attach-sources</id>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.3.1</version>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/attach-jar-checksum-release/setup.bsh b/src/it/attach-jar-checksum-release/setup.bsh
new file mode 100644
index 0000000..9c52da8
--- /dev/null
+++ b/src/it/attach-jar-checksum-release/setup.bsh
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.*;
+import java.util.*;
+
+import org.codehaus.plexus.util.*;
+
+File file = new File( localRepositoryPath, "org/apache/maven/its/install/ajc" );
+System.out.println( "Deleting " + file );
+FileUtils.deleteDirectory( file );
+
+return true;
diff --git a/src/it/attach-jar-checksum-release/verify.groovy b/src/it/attach-jar-checksum-release/verify.groovy
new file mode 100644
index 0000000..9a7376b
--- /dev/null
+++ b/src/it/attach-jar-checksum-release/verify.groovy
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.*;
+import java.util.*;
+
+import org.apache.maven.plugins.deploy.Utils;
+
+def paths =
+[
+    "org/apache/maven/its/deploy/ajc/test/1.0/test-1.0.pom",
+    "org/apache/maven/its/deploy/ajc/test/1.0/test-1.0.pom.md5",
+    "org/apache/maven/its/deploy/ajc/test/1.0/test-1.0.pom.sha1",
+    "org/apache/maven/its/deploy/ajc/test/1.0/test-1.0.jar",
+    "org/apache/maven/its/deploy/ajc/test/1.0/test-1.0.jar.md5",
+    "org/apache/maven/its/deploy/ajc/test/1.0/test-1.0.jar.sha1",
+    "org/apache/maven/its/deploy/ajc/test/1.0/test-1.0-sources.jar",
+    "org/apache/maven/its/deploy/ajc/test/1.0/test-1.0-sources.jar.md5",
+    "org/apache/maven/its/deploy/ajc/test/1.0/test-1.0-sources.jar.sha1",
+    "org/apache/maven/its/deploy/ajc/test/maven-metadata.xml",
+    "org/apache/maven/its/deploy/ajc/test/maven-metadata.xml.md5",
+    "org/apache/maven/its/deploy/ajc/test/maven-metadata.xml.sha1",
+]
+
+def cksumToCheckPaths = [
+    "org/apache/maven/its/deploy/ajc/test/1.0/test-1.0.pom",
+    "org/apache/maven/its/deploy/ajc/test/1.0/test-1.0.jar",
+    "org/apache/maven/its/deploy/ajc/test/1.0/test-1.0-sources.jar"
+]
+
+def repository = new File (basedir, "target/repo" )
+paths.each { path ->
+    //File file = new File( localRepositoryPath, path );
+    File file = new File( repository, path );
+    println "Checking for existence of ${file}"
+    if ( !file.isFile() )
+    {
+        throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() );
+    }
+    if ( cksumToCheckPaths.contains( path ) )
+    {    
+        println "Verifying ${file}"
+        Utils.verifyChecksum( file );
+    }
+}
+
+return true;
diff --git a/src/it/attach-jar-checksum-snapshot/pom.xml b/src/it/attach-jar-checksum-snapshot/pom.xml
new file mode 100644
index 0000000..c81cc24
--- /dev/null
+++ b/src/it/attach-jar-checksum-snapshot/pom.xml
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.deploy.ajc</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <description>
+    This test has been moved from maven-install-plugin to maven-deploy-plugin.
+    Tests the installation of a simple snapshot JAR with an attached artifact and checksums
+  </description>
+
+  <properties>
+    <maven.test.skip>true</maven.test.skip>
+  </properties>
+  <distributionManagement>
+    <repository>
+      <id>it</id>
+      <url>file:///${basedir}/target/repo</url>
+    </repository>
+  </distributionManagement>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.0.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-deploy-plugin</artifactId>
+        <version>@project.version@</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <version>2.1</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>2.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-source-plugin</artifactId>
+        <version>2.0.4</version>
+        <executions>
+          <execution>
+            <id>attach-sources</id>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.3.1</version>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/attach-jar-checksum-snapshot/setup.bsh b/src/it/attach-jar-checksum-snapshot/setup.bsh
new file mode 100644
index 0000000..9c52da8
--- /dev/null
+++ b/src/it/attach-jar-checksum-snapshot/setup.bsh
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.*;
+import java.util.*;
+
+import org.codehaus.plexus.util.*;
+
+File file = new File( localRepositoryPath, "org/apache/maven/its/install/ajc" );
+System.out.println( "Deleting " + file );
+FileUtils.deleteDirectory( file );
+
+return true;
diff --git a/src/it/attach-jar-checksum-snapshot/verify.groovy b/src/it/attach-jar-checksum-snapshot/verify.groovy
new file mode 100644
index 0000000..b533981
--- /dev/null
+++ b/src/it/attach-jar-checksum-snapshot/verify.groovy
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.*;
+import java.util.*;
+
+import org.apache.maven.plugins.deploy.Utils;
+
+def paths =
+[
+    "org/apache/maven/its/deploy/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.pom",
+    "org/apache/maven/its/deploy/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.pom.md5",
+    "org/apache/maven/its/deploy/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.pom.sha1",
+    "org/apache/maven/its/deploy/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.jar",
+    "org/apache/maven/its/deploy/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.jar.md5",
+    "org/apache/maven/its/deploy/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.jar.sha1",
+    "org/apache/maven/its/deploy/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT-sources.jar",
+    "org/apache/maven/its/deploy/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT-sources.jar.md5",
+    "org/apache/maven/its/deploy/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT-sources.jar.sha1",
+    "org/apache/maven/its/deploy/ajc/test/maven-metadata.xml",
+    "org/apache/maven/its/deploy/ajc/test/maven-metadata.xml.md5",
+    "org/apache/maven/its/deploy/ajc/test/maven-metadata.xml.sha1",
+]
+
+def cksumToCheckPaths = [
+    "org/apache/maven/its/deploy/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.pom",
+    "org/apache/maven/its/deploy/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.jar",
+    "org/apache/maven/its/deploy/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT-sources.jar"
+]
+
+def buildLog = new File ( basedir, "build.log")
+
+
+def repository = new File (basedir, "target/repo" )
+paths.each { path ->
+    //File file = new File( localRepositoryPath, path );
+    File file = new File( repository, path );
+    println "Checking for existence of ${file}"
+    if ( !file.isFile() )
+    {
+        throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() );
+    }
+    if ( cksumToCheckPaths.contains( path ) )
+    {    
+        println "Verifying ${file}"
+        Utils.verifyChecksum( file );
+    }
+}
+
+return true;
diff --git a/src/test/java/org/apache/maven/plugins/deploy/Utils.java b/src/test/java/org/apache/maven/plugins/deploy/Utils.java
new file mode 100644
index 0000000..09949a6
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/deploy/Utils.java
@@ -0,0 +1,64 @@
+package org.apache.maven.plugins.deploy;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.sonatype.aether.util.ChecksumUtils;
+
+/**
+ * A utility class to assist testing.
+ *
+ * @author Benjamin Bentmann
+ * @version $Id$
+ */
+public class Utils
+{
+
+    public static final List<String> CHECKSUM_ALGORITHMS = Arrays.asList( "MD5", "SHA-1" );
+
+    /**
+     * Verifies the checksum files in the local repo for the given file.
+     *
+     * @param file The file to verify its checksum with, must not be <code>null</code>.
+     * @throws MojoExecutionException In case the checksums were incorrect.
+     * @throws IOException If the files couldn't be read.
+     */
+    public static void verifyChecksum( File file )
+        throws MojoExecutionException, IOException
+    {
+        Map<String, Object> checksums = ChecksumUtils.calc( file, CHECKSUM_ALGORITHMS );
+        for ( Map.Entry<String, Object> entry : checksums.entrySet() )
+        {
+            File cksumFile = new File( file + "." + entry.getKey().toLowerCase().replace( "-", "" ) );
+            String actualChecksum = ChecksumUtils.read( cksumFile );
+            if ( !actualChecksum.equals( entry.getValue() ) )
+            {
+                throw new MojoExecutionException( "Incorrect " + entry.getKey() + " checksum for file: " + file );
+            }
+        }
+    }
+
+}