aboutsummaryrefslogtreecommitdiffstats
path: root/maven-repository-reports-standard
diff options
context:
space:
mode:
authorEdwin L. Punzalan <epunzalan@apache.org>2005-12-08 00:19:59 +0000
committerEdwin L. Punzalan <epunzalan@apache.org>2005-12-08 00:19:59 +0000
commit7edda879499a74053dce995ef12770792277613f (patch)
treec268fad32ff1f0094e361c502936b2722b1fbf76 /maven-repository-reports-standard
parent2b5e09d67986fa3996cf724639c029c0335c5b00 (diff)
downloadarchiva-7edda879499a74053dce995ef12770792277613f.tar.gz
archiva-7edda879499a74053dce995ef12770792277613f.zip
PR: MRM-17
Submitted by: Maria Odea Ching Patch is for testing checksum of artifact and metadata files located in remote repository git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@354916 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'maven-repository-reports-standard')
-rw-r--r--maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java86
-rw-r--r--maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java9
-rw-r--r--maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java119
-rw-r--r--maven-repository-reports-standard/src/test/repository/maven-metadata-repository.xml (renamed from maven-repository-reports-standard/src/test/repository/maven-metadata.xml)0
4 files changed, 169 insertions, 45 deletions
diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java
index af1b60844..d236531e6 100644
--- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java
+++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java
@@ -23,6 +23,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -47,6 +48,8 @@ public class ChecksumArtifactReporter
protected InputStream sha1InputStream;
+ private boolean isLocal = true;
+
/**
* Validate the checksum of the specified artifact.
* @param model
@@ -60,13 +63,23 @@ public class ChecksumArtifactReporter
System.out.println( " " );
System.out
.println( "===================================== +++++ PROCESS ARTIFACT +++++ ====================================" );
-
+
String artifactUrl = "";
- String repositoryUrl = repository.getUrl();
+ String repositoryUrl = "";
+
+ if ( !repository.getProtocol().equals( "file" ) )
+ {
+ isLocal = false;
+ repositoryUrl = repository.getUrl();
+ }
+ else
+ {
+ repositoryUrl = repository.getBasedir();
+ }
+
artifactUrl = repositoryUrl + artifact.getGroupId() + "/" + artifact.getArtifactId() + "/"
+ artifact.getBaseVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "."
+ artifact.getType();
- //System.out.println("ARTIFACT URL ------->>>> " + artifactUrl);
//check if checksum files exist
boolean md5Exists = getMD5File( artifactUrl );
@@ -107,9 +120,18 @@ public class ChecksumArtifactReporter
System.out
.println( "====================================== +++++ PROCESS METADATA +++++ ==============================" );
- String metadataUrl = "";
- String repositoryUrl = repository.getUrl();
- String filename = metadata.getRemoteFilename();
+ String metadataUrl = "", repositoryUrl = "", filename = "";
+ if ( !repository.getProtocol().equals( "file" ) )
+ {
+ isLocal = false;
+ repositoryUrl = repository.getUrl();
+ filename = metadata.getRemoteFilename();
+ }
+ else
+ {
+ repositoryUrl = repository.getBasedir();
+ filename = metadata.getLocalFilename( repository );
+ }
//version metadata
if ( metadata.storedInArtifactVersionDirectory() == true && metadata.storedInGroupDirectory() == false )
@@ -130,7 +152,6 @@ public class ChecksumArtifactReporter
//add the file name of the metadata
metadataUrl = metadataUrl + filename;
- //System.out.println( "METADATA URL -------> " + metadataUrl );
//check if checksum files exist
boolean md5Exists = getMD5File( metadataUrl );
@@ -171,7 +192,16 @@ public class ChecksumArtifactReporter
{
try
{
- md5InputStream = new FileInputStream( filename + ".md5" );
+ if ( isLocal )
+ {
+ md5InputStream = new FileInputStream( filename + ".md5" );
+ }
+ else
+ {
+ URL url = new URL( filename );
+ md5InputStream = url.openStream();
+ }
+
md5InputStream.close();
}
catch ( Exception e )
@@ -190,7 +220,15 @@ public class ChecksumArtifactReporter
{
try
{
- sha1InputStream = new FileInputStream( filename + ".sha1" );
+ if ( isLocal )
+ {
+ sha1InputStream = new FileInputStream( filename + ".sha1" );
+ }
+ else
+ {
+ URL url = new URL( filename );
+ sha1InputStream = url.openStream();
+ }
sha1InputStream.close();
}
catch ( Exception e )
@@ -223,9 +261,20 @@ public class ChecksumArtifactReporter
//read the md5 file
chk2 = new byte[chk1.length];
-
File f = new File( fileUrl + ext );
- InputStream is = new FileInputStream( f );
+ InputStream is = null;
+
+ //check whether the file is located locally or remotely
+ if ( isLocal )
+ {
+ is = new FileInputStream( f );
+ }
+ else
+ {
+ URL url = new URL( fileUrl + ext );
+ is = url.openStream();
+ }
+
char[] chars = new char[is.available()];
InputStreamReader isr = new InputStreamReader( is );
isr.read( chars );
@@ -237,7 +286,7 @@ public class ChecksumArtifactReporter
System.out.println( "-----" + algo + " Checksum value (CHK2 - content of CHECKSUM file) ::::: "
+ chk2Str );
- if ( chk2Str.equals( byteArrayToHexStr( chk1 ) ) )
+ if ( chk2Str.toUpperCase().equals( byteArrayToHexStr( chk1 ).toUpperCase() ) )
{
valid = true;
}
@@ -269,9 +318,20 @@ public class ChecksumArtifactReporter
throws FileNotFoundException, NoSuchAlgorithmException, IOException
{
- InputStream fis = new FileInputStream( filename );
+ InputStream fis = null;
byte[] buffer = new byte[1024];
+ //check whether file is located locally or remotely
+ if ( isLocal )
+ {
+ fis = new FileInputStream( filename );
+ }
+ else
+ {
+ URL url = new URL( filename );
+ fis = url.openStream();
+ }
+
MessageDigest complete = MessageDigest.getInstance( algo );
int numRead;
do
diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java
index 14b29f4b6..423192ff1 100644
--- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java
+++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java
@@ -48,7 +48,7 @@ public class AbstractChecksumArtifactReporterTest
protected static final String[] invalidArtifactChecksumJars = { "invalidArtifact-1.0" };
- protected static final String metadataChecksumFilename = "maven-metadata";
+ protected static final String metadataChecksumFilename = "maven-metadata-repository";
public AbstractChecksumArtifactReporterTest()
{
@@ -228,17 +228,10 @@ public class AbstractChecksumArtifactReporterTest
{
//create checksum for the metadata file..
String repoUrl = repository.getBasedir();
- //System.out.println("repoUrl ---->>> " + repoUrl);
-
- System.out.println( "REPO URL :::: " + repoUrl );
- // String[] split1 = repoUrl.split( "file:/" );
- // split1[1] = split1[1] + "/";
-
String url = repository.getBasedir() + "/" + filename + "." + type;
//boolean copied = copyFile( url, repoUrl + relativePath + filename + "." + type );
FileUtils.copyFile( new File( url ), new File( repoUrl + relativePath + filename + "." + type ) );
- //System.out.println( "META FILE COPIED ---->>> " + copied );
//Create md5 and sha-1 checksum files..
byte[] md5chk = createChecksum( repoUrl + relativePath + filename + "." + type, "MD5" );
diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java
index 940b3cd5d..f5c40ecd7 100644
--- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java
+++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java
@@ -47,6 +47,20 @@ public class ChecksumArtifactReporterTest
private MetadataReportProcessor metadataReportProcessor;
+ private static final String remoteRepoUrl = "http://public.planetmirror.com/pub/maven2/";
+
+ private static final String remoteArtifactGroup = "HTTPClient";
+
+ private static final String remoteArtifactId = "HTTPClient";
+
+ private static final String remoteArtifactVersion = "0.3-3";
+
+ private static final String remoteArtifactScope = "compile";
+
+ private static final String remoteArtifactType = "jar";
+
+ private static final String remoteRepoId = "remote-repo";
+
public ChecksumArtifactReporterTest()
{
@@ -75,7 +89,6 @@ public class ChecksumArtifactReporterTest
/**
* Test creation of artifact with checksum files.
- *
*/
public void testCreateChecksumFile()
{
@@ -89,7 +102,6 @@ public class ChecksumArtifactReporterTest
assertTrue( createMetadataFile( "INVALID" ) );
}
-
/**
* Test the ChecksumArtifactReporter when the checksum files are valid.
*/
@@ -101,18 +113,10 @@ public class ChecksumArtifactReporterTest
VersionRange version = VersionRange.createFromVersion( "1.0" );
Artifact artifact = new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "",
handler );
- ArtifactRepository repository = new DefaultArtifactRepository( "repository", System.getProperty( "basedir" )
- + "/src/test/repository/", new DefaultRepositoryLayout() );
-
- /* VersionRange version = VersionRange.createFromVersion("0.3-3");
- Artifact artifact = new DefaultArtifact("HTTPClient", "HTTPClient", version, "compile", "jar", "",
- handler);
- ArtifactRepository repository = new DefaultArtifactRepository("remote-repo", "http://www.ibiblio.org/maven2/",
- new DefaultRepositoryLayout());
- */
+ ArtifactRepository repository = new DefaultArtifactRepository( "repository", "file:/"
+ + System.getProperty( "basedir" ) + "/src/test/repository/", new DefaultRepositoryLayout() );
artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
-
Iterator iter = reporter.getArtifactSuccessIterator();
int ctr = 0;
while ( iter.hasNext() )
@@ -141,8 +145,8 @@ public class ChecksumArtifactReporterTest
VersionRange version = VersionRange.createFromVersion( "1.0" );
Artifact artifact = new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "",
handler );
- ArtifactRepository repository = new DefaultArtifactRepository( "repository", System.getProperty( "basedir" )
- + "/src/test/repository/", new DefaultRepositoryLayout() );
+ ArtifactRepository repository = new DefaultArtifactRepository( "repository", "file:/"
+ + System.getProperty( "basedir" ) + "/src/test/repository/", new DefaultRepositoryLayout() );
artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
@@ -162,14 +166,18 @@ public class ChecksumArtifactReporterTest
}
}
+ /**
+ * Test the valid checksum of a metadata file.
+ * The reporter should report 2 success validation.
+ */
public void testChecksumMetadataReporterSuccess()
{
try
{
ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
- ArtifactRepository repository = new DefaultArtifactRepository( "repository", System.getProperty( "basedir" )
- + "/src/test/repository/", new DefaultRepositoryLayout() );
+ ArtifactRepository repository = new DefaultArtifactRepository( "repository", "file:/"
+ + System.getProperty( "basedir" ) + "/src/test/repository/", new DefaultRepositoryLayout() );
VersionRange version = VersionRange.createFromVersion( "1.0" );
Artifact artifact = new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "",
handler );
@@ -193,14 +201,18 @@ public class ChecksumArtifactReporterTest
}
}
+ /**
+ * Test the corrupted checksum of a metadata file.
+ * The reporter must report 2 failures.
+ */
public void testChecksumMetadataReporterFailure()
{
try
{
ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
- ArtifactRepository repository = new DefaultArtifactRepository( "repository", System.getProperty( "basedir" )
- + "/src/test/repository/", new DefaultRepositoryLayout() );
+ ArtifactRepository repository = new DefaultArtifactRepository( "repository", "file:/"
+ + System.getProperty( "basedir" ) + "/src/test/repository/", new DefaultRepositoryLayout() );
VersionRange version = VersionRange.createFromVersion( "1.0" );
Artifact artifact = new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "",
handler );
@@ -223,11 +235,70 @@ public class ChecksumArtifactReporterTest
e.printStackTrace();
}
}
-
-
- public void testDeleteTestDirectory(){
- String[] split = super.repository.getUrl().split("file:/");
- assertTrue(deleteTestDirectory(new File(split[1] + "checksumTest") ));
- }
+
+ /**
+ * Test the checksum of an artifact located in a remote location.
+ */
+ public void testChecksumArtifactRemote()
+ {
+ ArtifactHandler handler = new DefaultArtifactHandler( remoteArtifactType );
+ VersionRange version = VersionRange.createFromVersion( remoteArtifactVersion );
+ Artifact artifact = new DefaultArtifact( remoteArtifactGroup, remoteArtifactId, version, remoteArtifactScope,
+ remoteArtifactType, "", handler );
+ ArtifactRepository repository = new DefaultArtifactRepository( remoteRepoId, remoteRepoUrl,
+ new DefaultRepositoryLayout() );
+
+ artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
+ Iterator iter = reporter.getArtifactSuccessIterator();
+ int ctr = 0;
+ while ( iter.hasNext() )
+ {
+ ArtifactResult result = (ArtifactResult) iter.next();
+ ctr++;
+ }
+ System.out.println( "[REMOTE] ARTIFACT Number of success --- " + ctr );
+ }
+
+ /**
+ * Test the checksum of a metadata file located in a remote location.
+ */
+ public void testChecksumMetadataRemote()
+ {
+
+ try
+ {
+ ArtifactHandler handler = new DefaultArtifactHandler( remoteArtifactType );
+ VersionRange version = VersionRange.createFromVersion( remoteArtifactVersion );
+ Artifact artifact = new DefaultArtifact( remoteArtifactGroup, remoteArtifactId, version,
+ remoteArtifactScope, remoteArtifactType, "", handler );
+ ArtifactRepository repository = new DefaultArtifactRepository( remoteRepoId, remoteRepoUrl,
+ new DefaultRepositoryLayout() );
+ RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
+
+ metadataReportProcessor.processMetadata( metadata, repository, reporter );
+ Iterator iter = reporter.getRepositoryMetadataFailureIterator();
+ int ctr = 0;
+ while ( iter.hasNext() )
+ {
+ RepositoryMetadataResult result = (RepositoryMetadataResult) iter.next();
+ ctr++;
+ }
+ System.out.println( "[REMOTE] REPORT METADATA Number of sucess --- " + ctr );
+
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Test deletion of the test directories created.
+ */
+ public void testDeleteTestDirectory()
+ {
+ String[] split = super.repository.getUrl().split( "file:/" );
+ assertTrue( deleteTestDirectory( new File( split[1] + "checksumTest" ) ) );
+ }
}
diff --git a/maven-repository-reports-standard/src/test/repository/maven-metadata.xml b/maven-repository-reports-standard/src/test/repository/maven-metadata-repository.xml
index 7fdf6a91a..7fdf6a91a 100644
--- a/maven-repository-reports-standard/src/test/repository/maven-metadata.xml
+++ b/maven-repository-reports-standard/src/test/repository/maven-metadata-repository.xml