From 9b3a90c35c74a56803c671a9a49e048f125d86fc Mon Sep 17 00:00:00 2001
From: Elliotte Rusty Harold <elharo@users.noreply.github.com>
Date: Fri, 12 Jun 2020 14:47:07 -0400
Subject: [PATCH 1/4] [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
---
 .../plugins/install/InstallFileMojoTest.java  | 52 +++------------
 .../plugins/install/InstallMojoTest.java      | 33 +---------
 .../apache/maven/plugins/install/Utils.java   | 63 -------------------
 3 files changed, 11 insertions(+), 137 deletions(-)
 delete mode 100644 src/test/java/org/apache/maven/plugins/install/Utils.java

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..f0360c9 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;
@@ -66,11 +65,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 +160,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 +236,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 +250,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 +257,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 );
-            }
-        }
-    }
-
-}
-- 
2.36.0

