You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2020/06/12 18:47:24 UTC

[maven-install-plugin] branch master updated: [MINSTALL-143] Remove a lot of checksum related dead code and commented out tests (#8)

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

elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-install-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new da439e2  [MINSTALL-143] Remove a lot of checksum related dead code and commented out tests  (#8)
da439e2 is described below

commit da439e29cd752841aa04a56e17cfff89b89a32e7
Author: Elliotte Rusty Harold <el...@users.noreply.github.com>
AuthorDate: Fri Jun 12 14:47:07 2020 -0400

    [MINSTALL-143] Remove a lot of checksum related dead code and commented out tests  (#8)
    
    * clean up warnings
    * remove checksum code that was commented out
---
 .../maven/plugins/install/InstallFileMojoTest.java | 54 ++++---------------
 .../maven/plugins/install/InstallMojoTest.java     | 33 +-----------
 .../org/apache/maven/plugins/install/Utils.java    | 63 ----------------------
 3 files changed, 11 insertions(+), 139 deletions(-)

diff --git a/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java b/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java
index f915047..8b3b070 100644
--- a/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java
@@ -21,7 +21,6 @@ package org.apache.maven.plugins.install;
 
 import java.io.File;
 import java.io.Reader;
-import java.util.Map;
 
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Model;
@@ -32,9 +31,7 @@ import org.apache.maven.project.DefaultProjectBuildingRequest;
 import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.shared.utils.ReaderFactory;
 import org.apache.maven.shared.utils.io.FileUtils;
-import org.apache.maven.shared.utils.io.IOUtil;
 import org.sonatype.aether.impl.internal.EnhancedLocalRepositoryManager;
-import org.sonatype.aether.util.ChecksumUtils;
 import org.sonatype.aether.util.DefaultRepositorySystemSession;
 
 import static org.mockito.Mockito.mock;
@@ -66,11 +63,6 @@ public class InstallFileMojoTest
         super.setUp();
 
         FileUtils.deleteDirectory( new File( getBasedir() + "/" + LOCAL_REPO ) );
-        
-//        LegacySupport legacySupport = lookup( LegacySupport.class );
-//        RepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
-//        MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
-//        legacySupport.setSession( new MavenSession( getContainer(), repositorySession, executionRequest, null ) );
     }
 
     public void testInstallFileTestEnvironment()
@@ -166,29 +158,18 @@ public class InstallFileMojoTest
         File installedPom = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
             artifactId + "-" + version + "." + "pom" );
 
-        Model model;
+        try ( Reader reader = ReaderFactory.newXmlReader( installedPom ) ) {
+            Model model = new MavenXpp3Reader().read( reader );
 
-        Reader reader = null;
-        try
-        {
-            reader = ReaderFactory.newXmlReader( installedPom );
-            model = new MavenXpp3Reader().read( reader );
-            reader.close();
-            reader = null;
-        }
-        finally
-        {
-            IOUtil.close( reader );
+            assertEquals( "4.0.0", model.getModelVersion() );
+    
+            assertEquals( (String) getVariableValueFromObject( mojo, "groupId" ), model.getGroupId() );
+    
+            assertEquals( artifactId, model.getArtifactId() );
+    
+            assertEquals( version, model.getVersion() );
         }
 
-        assertEquals( "4.0.0", model.getModelVersion() );
-
-        assertEquals( (String) getVariableValueFromObject( mojo, "groupId" ), model.getGroupId() );
-
-        assertEquals( artifactId, model.getArtifactId() );
-
-        assertEquals( version, model.getVersion() );
-
         assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
     }
 
@@ -253,7 +234,7 @@ public class InstallFileMojoTest
         assertEquals( 4, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
     }
 
-    public void testInstallFileWithChecksum()
+    public void testInstallFile()
         throws Exception
     {
         File testPom =
@@ -267,10 +248,6 @@ public class InstallFileMojoTest
 
         assignValuesForParameter( mojo );
 
-//        boolean createChecksum = (Boolean) getVariableValueFromObject( mojo, "createChecksum" );
-//
-//        assertTrue( createChecksum );
-
         mojo.execute();
 
         String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
@@ -278,19 +255,8 @@ public class InstallFileMojoTest
         
         File installedArtifact = new File( localPath + "." + "jar" );
         
-        //get the actual checksum of the artifact
-//        Map<String, Object> csums = ChecksumUtils.calc( file, Utils.CHECKSUM_ALGORITHMS );
-//        for (Map.Entry<String, Object> csum : csums.entrySet()) {
-//            Object actualSum = csum.getValue();
-//            File sum = new File( localPath + ".jar." + csum.getKey().toLowerCase().replace( "-", "" ) );
-//            assertTrue( sum.exists() );
-//            String generatedSum = FileUtils.fileRead( sum, "UTF-8" );
-//            assertEquals( actualSum, generatedSum );
-//        }
-
         assertTrue( installedArtifact.exists() );
         
-//        assertEquals( 9, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
         assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
     }
 
diff --git a/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java b/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
index e211a18..63ac6fa 100644
--- a/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
@@ -58,14 +58,7 @@ public class InstallMojoTest
     {
         super.setUp();
 
-        System.out.println( ">>>Cleaning local repo " + getBasedir() + "/" + LOCAL_REPO + "..." );
-
         FileUtils.deleteDirectory( new File( getBasedir() + "/" + LOCAL_REPO ) );
-        
-//        LegacySupport legacySupport = lookup( LegacySupport.class );
-//        RepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
-//        MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
-//        legacySupport.setSession( new MavenSession( getContainer(), repositorySession, executionRequest, null ) );
     }
 
     public void testInstallTestEnvironment()
@@ -250,7 +243,7 @@ public class InstallMojoTest
         assertEquals( 4, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
     }
 
-    public void testBasicInstallAndCreateChecksumIsTrue()
+    public void testBasicInstallAndCreate()
         throws Exception
     {
         File testPom = new File( getBasedir(), "target/test-classes/unit/basic-install-checksum/plugin-config.xml" );
@@ -270,10 +263,6 @@ public class InstallMojoTest
 
         artifact = (InstallArtifactStub) project.getArtifact();
 
-//        boolean createChecksum = (Boolean) getVariableValueFromObject( mojo, "createChecksum" );
-//
-//        assertTrue( createChecksum );
-
         artifact.setFile( file );
 
         mojo.execute();
@@ -302,31 +291,11 @@ public class InstallMojoTest
         String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" +
                         artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion();
         
-        //get the actual checksum of the pom
-//        Map<String, Object> csums = ChecksumUtils.calc( pom, Utils.CHECKSUM_ALGORITHMS );
-//        for (Map.Entry<String, Object> csum : csums.entrySet()) {
-//            Object actualPomSum = csum.getValue();
-//            File pomSum = new File( localPath + ".pom." + csum.getKey().toLowerCase().replace( "-", "" ) );
-//            assertTrue( pomSum.exists() );
-//            String generatedPomSum = FileUtils.fileRead( pomSum, "UTF-8" );
-//            assertEquals( actualPomSum, generatedPomSum );
-//        }
-
-        //get the actual checksum of the artifact
-//        csums = ChecksumUtils.calc( file, Utils.CHECKSUM_ALGORITHMS );
-//        for (Map.Entry<String, Object> csum : csums.entrySet()) {
-//            Object actualSum = csum.getValue();
-//            File sum = new File( localPath + "." + packaging + "." + csum.getKey().toLowerCase().replace( "-", "" ) );
-//            assertTrue( sum.exists() );
-//            String generatedSum = FileUtils.fileRead( sum, "UTF-8" );
-//            assertEquals( actualSum, generatedSum );
-//        }
 
         File installedArtifact = new File( localPath + "." + packaging );
 
         assertTrue( installedArtifact.exists() );
         
-//        assertEquals( 9, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
         assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
     }
 
diff --git a/src/test/java/org/apache/maven/plugins/install/Utils.java b/src/test/java/org/apache/maven/plugins/install/Utils.java
deleted file mode 100644
index 33c262c..0000000
--- a/src/test/java/org/apache/maven/plugins/install/Utils.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package org.apache.maven.plugins.install;
-
-/*
- * 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
- */
-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 );
-            }
-        }
-    }
-
-}