Skip to content

Commit

Permalink
[MINSTALL-143] Remove a lot of checksum related dead code and comment…
Browse files Browse the repository at this point in the history
…ed out tests (#8)

* clean up warnings
* remove checksum code that was commented out
  • Loading branch information
elharo committed Jun 12, 2020
1 parent eeb5480 commit da439e2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 139 deletions.
Expand Up @@ -21,7 +21,6 @@

import java.io.File;
import java.io.Reader;
import java.util.Map;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Model;
Expand All @@ -32,9 +31,7 @@
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;
Expand Down Expand Up @@ -66,11 +63,6 @@ public void setUp()
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()
Expand Down Expand Up @@ -166,29 +158,18 @@ public void testInstallFileWithGeneratePom()
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() );
}

Expand Down Expand Up @@ -253,7 +234,7 @@ public void testInstallFileWithPomAsPackaging()
assertEquals( 4, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
}

public void testInstallFileWithChecksum()
public void testInstallFile()
throws Exception
{
File testPom =
Expand All @@ -267,30 +248,15 @@ public void testInstallFileWithChecksum()

assignValuesForParameter( mojo );

// boolean createChecksum = (Boolean) getVariableValueFromObject( mojo, "createChecksum" );
//
// assertTrue( createChecksum );

mojo.execute();

String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
artifactId + "-" + version;

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() );
}

Expand Down
Expand Up @@ -58,14 +58,7 @@ public void setUp()
{
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()
Expand Down Expand Up @@ -250,7 +243,7 @@ public void testInstallIfPackagingIsPom()
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" );
Expand All @@ -270,10 +263,6 @@ public void testBasicInstallAndCreateChecksumIsTrue()

artifact = (InstallArtifactStub) project.getArtifact();

// boolean createChecksum = (Boolean) getVariableValueFromObject( mojo, "createChecksum" );
//
// assertTrue( createChecksum );

artifact.setFile( file );

mojo.execute();
Expand Down Expand Up @@ -302,31 +291,11 @@ public void testBasicInstallAndCreateChecksumIsTrue()
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() );
}

Expand Down
63 changes: 0 additions & 63 deletions src/test/java/org/apache/maven/plugins/install/Utils.java

This file was deleted.

0 comments on commit da439e2

Please sign in to comment.