You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ep...@apache.org on 2005/12/06 06:56:05 UTC

svn commit: r354326 - in /maven/repository-manager/trunk/maven-repository-reports-standard: ./ src/main/java/org/apache/maven/repository/reporting/ src/main/resources/META-INF/plexus/ src/test/java/org/apache/maven/repository/reporting/

Author: epunzalan
Date: Mon Dec  5 21:55:45 2005
New Revision: 354326

URL: http://svn.apache.org/viewcvs?rev=354326&view=rev
Log:
PR: MRM-17
Submitted by: Maria Odea Ching

Also include improvements on BadMetadataReportProcessor metadata handling

Added:
    maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java   (with props)
    maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java   (with props)
    maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java   (with props)
Modified:
    maven/repository-manager/trunk/maven-repository-reports-standard/pom.xml
    maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java
    maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java
    maven/repository-manager/trunk/maven-repository-reports-standard/src/main/resources/META-INF/plexus/components.xml
    maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java
    maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java
    maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java

Modified: maven/repository-manager/trunk/maven-repository-reports-standard/pom.xml
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-reports-standard/pom.xml?rev=354326&r1=354325&r2=354326&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/pom.xml (original)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/pom.xml Mon Dec  5 21:55:45 2005
@@ -23,11 +23,19 @@
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact-manager</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
       <artifactId>maven-model</artifactId>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-repository-metadata</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-provider-api</artifactId>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>

Modified: maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java?rev=354326&r1=354325&r2=354326&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java (original)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java Mon Dec  5 21:55:45 2005
@@ -18,6 +18,7 @@
  */
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.model.Model;
 
 /**
@@ -28,5 +29,6 @@
 {
     String ROLE = ArtifactReportProcessor.class.getName();
 
-    void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter );
+    void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, ArtifactRepository repository );
+    
 }

Modified: maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java?rev=354326&r1=354325&r2=354326&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java (original)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java Mon Dec  5 21:55:45 2005
@@ -27,6 +27,8 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -61,7 +63,14 @@
 
         if ( metadata.storedInGroupDirectory() )
         {
-            checkPluginMetadata( metadata, repository, reporter );
+            try
+            {
+                checkPluginMetadata( metadata, repository, reporter );
+            }
+            catch ( IOException e )
+            {
+                throw new ReportProcessorException( "Error getting plugin artifact directories versions", e );
+            }
         }
         else
         {
@@ -112,11 +121,13 @@
      */
     protected boolean checkPluginMetadata( RepositoryMetadata metadata, ArtifactRepository repository,
                                         ArtifactReporter reporter )
+        throws IOException
     {
         boolean hasFailures = false;
 
         File metadataDir =
             new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( metadata ) ).getParentFile();
+        List pluginDirs = getArtifactIdFiles( metadataDir );
 
         HashMap prefixes = new HashMap();
         for ( Iterator plugins = metadata.getMetadata().getPlugins().iterator(); plugins.hasNext(); )
@@ -149,16 +160,31 @@
                 }
             }
 
-            if ( artifactId != null )
+            if ( artifactId != null && artifactId.length() > 0 )
             {
                 File pluginDir = new File( metadataDir, artifactId );
-                if ( !pluginDir.exists() )
+                if ( !pluginDirs.contains( pluginDir ) )
                 {
-                    reporter.addFailure( metadata, "Metadata plugin " + artifactId + " is not present in the repository" );
+                    reporter.addFailure( metadata, "Metadata plugin " + artifactId + " not found in the repository" );
                     hasFailures = true;
                 }
+                else
+                {
+                    pluginDirs.remove( pluginDir );
+                }
             }
         }
+        
+        if ( pluginDirs.size() > 0 )
+        {
+            for( Iterator plugins = pluginDirs.iterator(); plugins.hasNext(); )
+            {
+                File plugin = (File) plugins.next();
+                reporter.addFailure( metadata, "Plugin " + plugin.getName() + " is present in the repository but " +
+                    "missing in the metadata." );
+            }
+            hasFailures = true;
+        }
 
         return hasFailures;
     }
@@ -270,5 +296,31 @@
     private Artifact createArtifact( RepositoryMetadata metadata, String version )
     {
         return artifactFactory.createBuildArtifact( metadata.getGroupId(), metadata.getArtifactId(), version, "pom" );
+    }
+    
+    /**
+     * Used to gather artifactIds from a groupId directory
+     */
+    private List getArtifactIdFiles( File groupIdDir )
+        throws IOException
+    {
+        List artifactIdFiles = new ArrayList();
+        
+        List fileArray = new ArrayList( Arrays.asList( groupIdDir.listFiles() ) );
+        for( Iterator files=fileArray.iterator(); files.hasNext(); )
+        {
+            File artifactDir = (File) files.next();
+            
+            if ( artifactDir.isDirectory() )
+            {
+                List versions = FileUtils.getFileNames( artifactDir, "*/*.pom", null, false );
+                if ( versions.size() > 0 )
+                {
+                    artifactIdFiles.add( artifactDir );
+                }
+            }
+        }
+        
+        return artifactIdFiles;
     }
 }

Added: maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java?rev=354326&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java (added)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java Mon Dec  5 21:55:45 2005
@@ -0,0 +1,286 @@
+package org.apache.maven.repository.reporting;
+
+/* 
+ * Copyright 2001-2005 The Apache Software Foundation. 
+ * 
+ * Licensed 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.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
+import org.apache.maven.model.Model;
+import org.apache.maven.artifact.repository.*;
+
+/**
+ * This class reports invalid and mismatched checksums of artifacts and metadata files. 
+ * It validates MD5 and SHA-1 chacksums.
+ */
+public class ChecksumArtifactReporter
+    implements ArtifactReportProcessor, MetadataReportProcessor
+{
+    String ROLE = ChecksumArtifactReporter.class.getName();
+
+    protected InputStream md5InputStream;
+
+    protected InputStream sha1InputStream;
+
+    /**
+     * Validate the checksum of the specified artifact.
+     * @param model
+     * @param artifact
+     * @param reporter
+     * @param repository
+     */
+    public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
+                                ArtifactRepository repository )
+    {
+        String artifactUrl = "";
+        String repositoryUrl = repository.getUrl();
+
+        artifactUrl = repositoryUrl + artifact.getGroupId() + "/" + artifact.getArtifactId() + "/"
+            + artifact.getBaseVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "."
+            + artifact.getType();
+
+        //check if checksum files exist
+        boolean md5Exists = getMD5File( artifactUrl );
+        boolean sha1Exists = getSHA1File( artifactUrl );
+        if ( md5Exists )
+        {
+            if ( validateChecksum( artifactUrl, "MD5" ) )
+            {
+                reporter.addSuccess( artifact );
+            }
+            else
+            {
+                reporter.addFailure( artifact, "MD5 checksum does not match." );
+            }
+        }
+
+        if ( sha1Exists )
+        {
+            if ( validateChecksum( artifactUrl, "SHA-1" ) )
+            {
+                reporter.addSuccess( artifact );
+            }
+            else
+            {
+                reporter.addFailure( artifact, "SHA-1 checksum does not match." );
+            }
+        }
+    }
+
+    /**
+     * Validate the checksums of the metadata. Get the metadata file from the 
+     * repository then validate the checksum.
+     */
+    public void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter )
+    {
+
+        /*
+         String metadataUrl = "";
+         String filename = metadata.getLocalFilename(repository);
+         String repositoryUrl = repository.getUrl();
+         
+         String groupId, artifactId, version;
+         version = metadata.getBaseVersion();
+         groupId = metadata.getGroupId();
+         artifactId = metadata.getArtifactId();
+         
+         //version metadata
+         if(metadata.storedInArtifactVersionDirectory() == true && metadata.storedInGroupDirectory() == false){
+         metadataUrl = repositoryUrl + groupId + "/" + artifactId + "/" + version;
+         //group metadata
+         }else if(metadata.storedInArtifactVersionDirectory() == false && metadata.storedInGroupDirectory() == true){
+         metadataUrl = repositoryUrl + groupId;
+         //artifact metadata
+         }else{
+         metadataUrl = repositoryUrl + groupId + "/" + artifactId;
+         }
+         
+         metadataUrl = metadataUrl + "/" + filename;        
+         boolean valid = validateChecksum(metadataUrl);
+         
+         if(!valid){
+         reporter.addFailure(metadata, "Mismatched metadata checksum.");
+         }else{
+         reporter.addSuccess(metadata);
+         }
+         */
+    }
+
+    /**
+     * Get the MD5 Checksum file. If not found, return false.
+     * @param filename The name of the artifact whose MD5 Checksum file will be retrieved.
+     * @return
+     */
+    public boolean getMD5File( String filename )
+    {
+        try
+        {
+            md5InputStream = new FileInputStream( filename + ".md5" );
+        }
+        catch ( Exception e )
+        {
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * Get the SHA1 Checksum file. If not found, return false.
+     * @param filename The name of the artifact whose SHA-1 Checksum file will be retrieved.
+     * @return
+     */
+    public boolean getSHA1File( String filename )
+    {
+        try
+        {
+            sha1InputStream = new FileInputStream( filename + ".sha1" );
+        }
+        catch ( Exception e )
+        {
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * Validate the checksum of the file.
+     * @param fileUrl The file to be validated.
+     * @param algo The checksum algorithm used. 
+     * @return
+     */
+    protected boolean validateChecksum( String fileUrl, String algo )
+    {
+        boolean valid = false;
+        byte[] chk1 = null, chk2 = null;
+
+        try
+        {
+            //Create checksum for jar file
+            String ext = ".md5";
+            if ( algo.equals( "SHA-1" ) )
+                ext = ".sha1";
+            chk1 = createChecksum( fileUrl, algo );
+            if ( chk1 != null )
+            {
+
+                //read the md5 file
+                chk2 = new byte[chk1.length];
+
+                File f = new File( fileUrl + ext );
+                InputStream is = new FileInputStream( f );
+                char[] chars = new char[is.available()];
+                InputStreamReader isr = new InputStreamReader( is );
+                isr.read( chars );
+                isr.close();
+
+                String chk2Str = new String( chars );
+                System.out.println( "-----" + algo + " Checksum value (CHK1 - created checksum for jar file) ::::: "
+                    + byteArrayToHexStr( chk1 ) );
+                System.out.println( "-----" + algo + " Checksum value (CHK2 - content of CHECKSUM file) ::::: "
+                    + chk2Str );
+
+                if ( chk2Str.equals( byteArrayToHexStr( chk1 ) ) )
+                {
+                    valid = true;
+                }
+                else
+                {
+                    valid = false;
+                }
+            }
+            return valid;
+
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+            return valid;
+        }
+    }
+
+    /**
+     * Create a checksum from the specified metadata file.
+     * @param filename The file that will be created a checksum.
+     * @param algo The algorithm to be used (MD5, SHA-1)
+     * @return
+     * @throws FileNotFoundException
+     * @throws NoSuchAlgorithmException
+     * @throws IOException
+     */
+    protected byte[] createChecksum( String filename, String algo )
+        throws FileNotFoundException, NoSuchAlgorithmException, IOException
+    {
+
+        InputStream fis = new FileInputStream( filename );
+        byte[] buffer = new byte[1024];
+
+        MessageDigest complete = MessageDigest.getInstance( algo );
+        int numRead;
+        do
+        {
+            numRead = fis.read( buffer );
+            if ( numRead > 0 )
+            {
+                complete.update( buffer, 0, numRead );
+            }
+        }
+        while ( numRead != -1 );
+        fis.close();
+
+        return complete.digest();
+    }
+
+    /**
+     * Convert an incoming array of bytes into a string that represents each of
+     * the bytes as two hex characters.
+     * @param data
+     * @return
+     */
+    public String byteArrayToHexStr( byte[] data )
+    {
+        String output = "";
+        String tempStr = "";
+        int tempInt = 0;
+
+        for ( int cnt = 0; cnt < data.length; cnt++ )
+        {
+            //Deposit a byte into the 8 lsb of an int.
+            tempInt = data[cnt] & 0xFF;
+
+            //Get hex representation of the int as a string.
+            tempStr = Integer.toHexString( tempInt );
+
+            //Append a leading 0 if necessary so that each hex string will contain 2 characters.
+            if ( tempStr.length() == 1 )
+                tempStr = "0" + tempStr;
+
+            //Concatenate the two characters to the output string.
+            output = output + tempStr;
+        }
+
+        return output.toUpperCase();
+    }
+
+}

Propchange: maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/repository-manager/trunk/maven-repository-reports-standard/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-reports-standard/src/main/resources/META-INF/plexus/components.xml?rev=354326&r1=354325&r2=354326&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/src/main/resources/META-INF/plexus/components.xml (original)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/src/main/resources/META-INF/plexus/components.xml Mon Dec  5 21:55:45 2005
@@ -17,5 +17,11 @@
         </requirement>
       </requirements>
     </component>
+    <component>
+    	<role>org.apache.maven.repository.reporting.ArtifactReportProcessor</role>
+    	<role-hint>default</role-hint>
+    	<implementation>org.apache.maven.repository.reporting.ChecksumArtifactReporter</implementation>
+    	<instantiation-strategy>per-lookup</instantiation-strategy>
+    </component>
   </components>
 </component-set>

Added: maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java?rev=354326&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java (added)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java Mon Dec  5 21:55:45 2005
@@ -0,0 +1,260 @@
+package org.apache.maven.repository.reporting;
+
+/* 
+ * Copyright 2001-2005 The Apache Software Foundation. 
+ * 
+ * Licensed 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.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+
+public class AbstractChecksumArtifactReporterTest
+    extends AbstractRepositoryReportsTestCase
+{
+    protected static final String[] validArtifactChecksumJars = { "validArtifact-1.0" };
+
+    protected static final String[] invalidArtifactChecksumJars = { "invalidArtifact-1.0" };
+
+    public AbstractChecksumArtifactReporterTest()
+    {
+    }
+
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+    }
+
+    public void tearDown()
+        throws Exception
+    {
+        super.tearDown();
+    }
+
+    /**
+     * Create checksum files.
+     * @param type The type of checksum file to be created.
+     * @return
+     */
+    protected boolean createChecksumFile( String type )
+    {
+        boolean written = true;
+
+        //loop through the valid artifact names..
+        if ( type.equals( "VALID" ) )
+        {
+            for ( int i = 0; i < validArtifactChecksumJars.length; i++ )
+            {
+                written = writeChecksumFile( "checksumTest/", validArtifactChecksumJars[i], "jar", true );
+                if ( written == false )
+                {
+                    i = validArtifactChecksumJars.length;
+                }
+            }
+        }
+        else if ( type.equals( "INVALID" ) )
+        {
+            for ( int i = 0; i < invalidArtifactChecksumJars.length; i++ )
+            {
+                written = writeChecksumFile( "checksumTest/", invalidArtifactChecksumJars[i], "jar", false );
+                if ( written == false )
+                {
+                    i = invalidArtifactChecksumJars.length;
+                }
+            }
+        }
+
+        return written;
+    }
+
+    /**
+     * Create artifact together with its checksums.
+     * @param relativePath The groupId
+     * @param filename The filename of the artifact to be created.
+     * @param type The file type (JAR)
+     * @param isValid Indicates whether the checksum to be created is valid or not.
+     * @return
+     */
+    private boolean writeChecksumFile( String relativePath, String filename, String type, boolean isValid )
+    {
+
+        //Initialize variables for creating jar files
+        FileOutputStream f = null;
+        JarOutputStream out = null;
+        String repoUrl = super.repository.getUrl();
+
+        try
+        {
+            String dirs = filename.replace( '-', '/' );
+            String[] split1 = repoUrl.split( "file:/" );
+            split1[1] = split1[1] + "/";
+
+            //create the group level directory of the artifact    
+            File dirFiles = new File( split1[1] + relativePath + dirs );
+
+            if ( dirFiles.mkdirs() )
+            {
+
+                // create a jar file
+                f = new FileOutputStream( split1[1] + relativePath + dirs + "/" + filename + "." + type );
+                out = new JarOutputStream( new BufferedOutputStream( f ) );
+
+                // jar sample.txt
+                String filename1 = split1[1] + relativePath + dirs + "/sample.txt";
+                boolean bool = createSampleFile( filename1 );
+
+                BufferedReader in = new BufferedReader( new FileReader( filename1 ) );
+                out.putNextEntry( new JarEntry( filename1 ) );
+                int c;
+                while ( ( c = in.read() ) != -1 )
+                {
+                    out.write( c );
+                }
+                in.close();
+                out.close();
+
+                //Create md5 and sha-1 checksum files..
+                byte[] md5chk = createChecksum( split1[1] + relativePath + dirs + "/" + filename + "." + type, "MD5" );
+                byte[] sha1chk = createChecksum( split1[1] + relativePath + dirs + "/" + filename + "." + type, "SHA-1" );
+                System.out.println( "----- CREATED MD5 checksum ::: " + byteArrayToHexStr( md5chk ) );
+                System.out.println( "----- CREATED SHA-1 checksum ::: " + byteArrayToHexStr( sha1chk ) );
+
+                File file = null;
+
+                if ( md5chk != null )
+                {
+                    file = new File( split1[1] + relativePath + dirs + "/" + filename + "." + type + ".md5" );
+                    OutputStream os = new FileOutputStream( file );
+                    OutputStreamWriter osw = new OutputStreamWriter( os );
+                    if ( !isValid )
+                        osw.write( byteArrayToHexStr( md5chk ) + "1" );
+                    else
+                        osw.write( byteArrayToHexStr( md5chk ) );
+                    osw.close();
+                }
+
+                if ( sha1chk != null )
+                {
+                    file = new File( split1[1] + relativePath + dirs + "/" + filename + "." + type + ".sha1" );
+                    OutputStream os = new FileOutputStream( file );
+                    OutputStreamWriter osw = new OutputStreamWriter( os );
+                    if ( !isValid )
+                        osw.write( byteArrayToHexStr( sha1chk ) + "2" );
+                    else
+                        osw.write( byteArrayToHexStr( sha1chk ) );
+                    osw.close();
+                }
+            }
+        }
+        catch ( Exception e )
+        {
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * Create the sample file that will be included in the jar.
+     * @param filename
+     * @return
+     */
+    private boolean createSampleFile( String filename )
+    {
+        try
+        {
+            File file = new File( filename );
+            OutputStream os = new FileOutputStream( file );
+            OutputStreamWriter osw = new OutputStreamWriter( os );
+            osw.write( "This is the content of the sample file that will be included in the jar file." );
+            osw.close();
+        }
+        catch ( Exception e )
+        {
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * Create a checksum from the specified metadata file.
+     * 
+     * @param metadataUrl
+     * @return
+     * @throws FileNotFoundException
+     * @throws NoSuchAlgorithmException
+     * @throws IOException
+     */
+    private byte[] createChecksum( String filename, String algo )
+        throws FileNotFoundException, NoSuchAlgorithmException, IOException
+    {
+
+        InputStream fis = new FileInputStream( filename );
+        byte[] buffer = new byte[1024];
+
+        MessageDigest complete = MessageDigest.getInstance( algo );
+        int numRead;
+        do
+        {
+            numRead = fis.read( buffer );
+            if ( numRead > 0 )
+            {
+                complete.update( buffer, 0, numRead );
+            }
+        }
+        while ( numRead != -1 );
+        fis.close();
+
+        return complete.digest();
+    }
+
+    /**
+     * Convert an incoming array of bytes into a string that represents each of
+     * the bytes as two hex characters.
+     * @param data
+     * @return
+     */
+    private String byteArrayToHexStr( byte[] data )
+    {
+        String output = "";
+        String tempStr = "";
+        int tempInt = 0;
+
+        for ( int cnt = 0; cnt < data.length; cnt++ )
+        {
+            tempInt = data[cnt] & 0xFF;
+            tempStr = Integer.toHexString( tempInt );
+
+            if ( tempStr.length() == 1 )
+                tempStr = "0" + tempStr;
+            output = output + tempStr;
+        }
+
+        return output.toUpperCase();
+    }
+
+}

Propchange: maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java?rev=354326&r1=354325&r2=354326&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java (original)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java Mon Dec  5 21:55:45 2005
@@ -54,7 +54,7 @@
     public void testArtifactReporterSingleSuccess()
     {
         processor.addReturnValue( ReportCondition.SUCCESS, artifact, "all is good" );
-        processor.processArtifact( model, artifact, reporter );
+        processor.processArtifact( model, artifact, reporter, null );
         Iterator success = reporter.getArtifactSuccessIterator();
         assertTrue( success.hasNext() );
         success.next();
@@ -66,7 +66,7 @@
         processor.addReturnValue( ReportCondition.SUCCESS, artifact, "one" );
         processor.addReturnValue( ReportCondition.SUCCESS, artifact, "two" );
         processor.addReturnValue( ReportCondition.SUCCESS, artifact, "three" );
-        processor.processArtifact( model, artifact, reporter );
+        processor.processArtifact( model, artifact, reporter, null );
         Iterator success = reporter.getArtifactSuccessIterator();
         assertTrue( success.hasNext() );
         int i;
@@ -80,7 +80,7 @@
     public void testArtifactReporterSingleFailure()
     {
         processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed once" );
-        processor.processArtifact( model, artifact, reporter );
+        processor.processArtifact( model, artifact, reporter, null );
         Iterator failure = reporter.getArtifactFailureIterator();
         assertTrue( failure.hasNext() );
         failure.next();
@@ -92,7 +92,7 @@
         processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed once" );
         processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed twice" );
         processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed thrice" );
-        processor.processArtifact( model, artifact, reporter );
+        processor.processArtifact( model, artifact, reporter, null );
         Iterator failure = reporter.getArtifactFailureIterator();
         assertTrue( failure.hasNext() );
         int i;
@@ -106,7 +106,7 @@
     public void testArtifactReporterSingleWarning()
     {
         processor.addReturnValue( ReportCondition.WARNING, artifact, "you've been warned" );
-        processor.processArtifact( model, artifact, reporter );
+        processor.processArtifact( model, artifact, reporter, null );
         Iterator warning = reporter.getArtifactFailureIterator();
         assertTrue( warning.hasNext() );
         warning.next();
@@ -118,7 +118,7 @@
         processor.addReturnValue( ReportCondition.WARNING, artifact, "i'm warning you" );
         processor.addReturnValue( ReportCondition.WARNING, artifact, "you have to stop now" );
         processor.addReturnValue( ReportCondition.WARNING, artifact, "all right... that does it!" );
-        processor.processArtifact( model, artifact, reporter );
+        processor.processArtifact( model, artifact, reporter, null );
         Iterator warning = reporter.getArtifactFailureIterator();
         assertTrue( warning.hasNext() );
         int i;

Modified: maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java?rev=354326&r1=354325&r2=354326&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java (original)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java Mon Dec  5 21:55:45 2005
@@ -20,13 +20,13 @@
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
 import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.Plugin;
 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
 import org.apache.maven.artifact.repository.metadata.Snapshot;
+import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
 import org.apache.maven.artifact.repository.metadata.Versioning;
 
 import java.util.Iterator;
-import org.apache.maven.artifact.repository.metadata.Plugin;
-import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
 
 /**
  * @todo???  should use MetadataXpp3Reader instead ?
@@ -187,6 +187,7 @@
 
         RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
         metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) );
+        metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) );
         
         badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
         
@@ -200,7 +201,9 @@
         ArtifactReporter reporter = new MockArtifactReporter();
 
         RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
-        metadata.getMetadata().addPlugin( createMetadataPlugin( "missing-plugin", "default" ) );
+        metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) );
+        metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) );
+        metadata.getMetadata().addPlugin( createMetadataPlugin( "missing-plugin", "default3" ) );
         
         badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
 
@@ -208,7 +211,7 @@
         assertTrue( "check there is a failure", failures.hasNext() );
         RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
         // TODO: should be more robust
-        assertEquals( "check reason", "Metadata plugin missing-plugin is not present in the repository", result.getReason() );
+        assertEquals( "check reason", "Metadata plugin missing-plugin not found in the repository", result.getReason() );
         assertFalse( "check no more failures", failures.hasNext() );
     }
     
@@ -218,8 +221,10 @@
         ArtifactReporter reporter = new MockArtifactReporter();
 
         RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
-        metadata.getMetadata().addPlugin( createMetadataPlugin( null, "default" ) );
-        metadata.getMetadata().addPlugin( createMetadataPlugin( "", "default2" ) );
+        metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) );
+        metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) );
+        metadata.getMetadata().addPlugin( createMetadataPlugin( null, "default3" ) );
+        metadata.getMetadata().addPlugin( createMetadataPlugin( "", "default4" ) );
         
         badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
 

Added: maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java?rev=354326&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java (added)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java Mon Dec  5 21:55:45 2005
@@ -0,0 +1,125 @@
+package org.apache.maven.repository.reporting;
+
+/* 
+ * Copyright 2001-2005 The Apache Software Foundation. 
+ * 
+ * Licensed 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.util.Iterator;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.DefaultArtifactRepository;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.apache.maven.artifact.versioning.VersionRange;
+
+public class ChecksumArtifactReporterTest
+    extends AbstractChecksumArtifactReporterTest
+{
+    private ArtifactReportProcessor artifactReportProcessor;
+
+    private ArtifactReporter reporter = new MockArtifactReporter();
+
+    public ChecksumArtifactReporterTest()
+    {
+
+    }
+
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+        artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "default" );
+    }
+
+    public void tearDown()
+        throws Exception
+    {
+        super.tearDown();
+    }
+
+    public void testCreateChecksumFile()
+    {
+        assertTrue( createChecksumFile( "VALID" ) );
+        assertTrue( createChecksumFile( "INVALID" ) );
+    }
+
+    /**
+     * Test the ChecksumArtifactReporter when the checksum files are valid.
+     */
+    public void testChecksumArtifactReporterSuccess()
+    {
+        try
+        {
+            ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
+            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() );
+
+            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( "Number of success --- " + ctr );
+
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * Test the ChecksumArtifactReporter when the checksum files are invalid.
+     */
+    public void testChecksumArtifactReporterFailed()
+    {
+
+        try
+        {
+            ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
+            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() );
+
+            artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
+
+            Iterator iter = reporter.getArtifactFailureIterator();
+            int ctr = 0;
+            while ( iter.hasNext() )
+            {
+                ArtifactResult result = (ArtifactResult) iter.next();
+                ctr++;
+            }
+            System.out.println( "Number of failures --- " + ctr );
+
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+        }
+    }
+}

Propchange: maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java?rev=354326&r1=354325&r2=354326&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java (original)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java Mon Dec  5 21:55:45 2005
@@ -1,6 +1,7 @@
 package org.apache.maven.repository.reporting;
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.model.Model;
 
 import java.util.List;
@@ -38,7 +39,7 @@
         reportConditions = new ArrayList();
     }
 
-    public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter )
+    public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, ArtifactRepository repository )
     {
         if ( iterator == null || !iterator.hasNext() ) // not initialized or reached end of the list. start again
         {