]> source.dussan.org Git - archiva.git/commitdiff
continue clean up, refactor some code
authorBrett Porter <brett@apache.org>
Fri, 30 Dec 2005 21:22:12 +0000 (21:22 +0000)
committerBrett Porter <brett@apache.org>
Fri, 30 Dec 2005 21:22:12 +0000 (21:22 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@360168 13f79535-47bb-0310-9956-ffa450edef68

22 files changed:
maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java
maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java
maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java
maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java
maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java
maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTestCase.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTest.java [deleted file]
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTestCase.java [new file with mode: 0644]
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessorTest.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessorTest.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifact.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactFactory.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java
maven-repository-reports-standard/src/test/repository/maven-metadata-repository.xml [deleted file]
maven-repository-reports-standard/src/test/repository/maven-metadata.xml [new file with mode: 0644]

index f9138e7733f8331b7378f8baa0007154442d5ade..2e958fc3960c60bd6052809d286d38e848a41ca6 100644 (file)
@@ -69,7 +69,7 @@ public class DefaultMetadataDiscovererTest
      */
     public void testKickoutWrongDirectory()
     {
-        List metadataPaths = discoverer.discoverMetadata( repositoryLocation, null );
+        discoverer.discoverMetadata( repositoryLocation, null );
         Iterator iter = discoverer.getKickedOutPathsIterator();
         boolean found = false;
         while ( iter.hasNext() && !found )
@@ -89,7 +89,7 @@ public class DefaultMetadataDiscovererTest
      */
     public void testKickoutBlankMetadata()
     {
-        List metadataPaths = discoverer.discoverMetadata( repositoryLocation, null );
+        discoverer.discoverMetadata( repositoryLocation, null );
         Iterator iter = discoverer.getKickedOutPathsIterator();
         boolean found = false;
         while ( iter.hasNext() && !found )
index 849b8c81e020f15afdb3492a83a070898a0f4e09..e16458c514c4a05ca8e492b0868e196b7e52a930 100644 (file)
@@ -39,7 +39,7 @@ public abstract class AbstractRepositoryIndex
 
     private IndexReader indexReader;
 
-    protected IndexWriter indexWriter;
+    private IndexWriter indexWriter;
 
     /**
      * method to encapsulate the optimize() method for lucene
@@ -122,22 +122,24 @@ public abstract class AbstractRepositoryIndex
         return indexPath;
     }
 
-    protected void getIndexWriter()
+    protected IndexWriter getIndexWriter()
         throws IOException
     {
         if ( indexWriter == null )
         {
             indexWriter = new IndexWriter( indexPath, getAnalyzer(), false );
         }
+        return indexWriter;
     }
 
-    private void getIndexReader()
+    private IndexReader getIndexReader()
         throws IOException
     {
         if ( indexReader == null )
         {
             indexReader = IndexReader.open( indexPath );
         }
+        return indexReader;
     }
 
     /**
@@ -151,7 +153,7 @@ public abstract class AbstractRepositoryIndex
         File indexDir = new File( indexPath );
         if ( IndexReader.indexExists( indexDir ) )
         {
-            getIndexReader();
+            IndexReader indexReader = getIndexReader();
             if ( indexReader.numDocs() > 0 )
             {
                 Collection fields = indexReader.getFieldNames();
index 1f15beca1539614202079cbf0bc7db1d050a8ae4..7bb5c525d4da9d429c93df3f395df24d812a3151 100644 (file)
@@ -20,9 +20,9 @@ import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.SimpleAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
+import org.apache.lucene.index.IndexWriter;
 import org.apache.maven.artifact.Artifact;
 
-import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -31,7 +31,6 @@ import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.Enumeration;
 import java.util.zip.ZipEntry;
-import java.util.zip.ZipException;
 import java.util.zip.ZipFile;
 
 
@@ -39,7 +38,6 @@ import java.util.zip.ZipFile;
  * Class used to index Artifact objects in a specified repository
  *
  * @author Edwin Punzalan
- *
  * @plexus.component role="org.apache.maven.repository.indexing.RepositoryIndex" role-hint="artifact" instantiation-strategy="per-lookup"
  */
 public class ArtifactRepositoryIndex
@@ -67,12 +65,6 @@ public class ArtifactRepositoryIndex
 
     private Analyzer analyzer;
 
-    private StringBuffer classes;
-
-    private StringBuffer packages;
-
-    private StringBuffer files;
-
     private static final int CHEKCSUM_BUFFER_SIZE = 256;
 
     /**
@@ -134,9 +126,21 @@ public class ArtifactRepositoryIndex
 
         try
         {
-            getIndexWriter();
+            IndexWriter indexWriter = getIndexWriter();
 
-            processArtifactContents( artifact.getFile() );
+            StringBuffer classes = new StringBuffer();
+            StringBuffer packages = new StringBuffer();
+            StringBuffer files = new StringBuffer();
+            ZipFile jar = new ZipFile( artifact.getFile() );
+            for ( Enumeration entries = jar.entries(); entries.hasMoreElements(); )
+            {
+                ZipEntry entry = (ZipEntry) entries.nextElement();
+                if ( addIfClassEntry( entry, classes ) )
+                {
+                    addClassPackage( entry.getName(), packages );
+                }
+                addFile( entry, files );
+            }
 
             //@todo should some of these fields be Keyword instead of Text ?
             Document doc = new Document();
@@ -150,8 +154,6 @@ public class ArtifactRepositoryIndex
             doc.add( Field.Text( PACKAGES, packages.toString() ) );
             doc.add( Field.Text( FILES, files.toString() ) );
             indexWriter.addDocument( doc );
-
-            removeBuffers();
         }
         catch ( Exception e )
         {
@@ -193,37 +195,7 @@ public class ArtifactRepositoryIndex
         return complete.digest();
     }
 
-    private void initBuffers()
-    {
-        classes = new StringBuffer();
-        packages = new StringBuffer();
-        files = new StringBuffer();
-    }
-
-    private void removeBuffers()
-    {
-        classes = null;
-        packages = null;
-        files = null;
-    }
-
-    private void processArtifactContents( File artifact )
-        throws IOException, ZipException
-    {
-        initBuffers();
-        ZipFile jar = new ZipFile( artifact );
-        for ( Enumeration entries = jar.entries(); entries.hasMoreElements(); )
-        {
-            ZipEntry entry = (ZipEntry) entries.nextElement();
-            if ( addIfClassEntry( entry ) )
-            {
-                addClassPackage( entry.getName() );
-            }
-            addFile( entry );
-        }
-    }
-
-    private boolean addIfClassEntry( ZipEntry entry )
+    private boolean addIfClassEntry( ZipEntry entry, StringBuffer classes )
     {
         boolean isAdded = false;
 
@@ -247,7 +219,7 @@ public class ArtifactRepositoryIndex
         return isAdded;
     }
 
-    private boolean addClassPackage( String name )
+    private boolean addClassPackage( String name, StringBuffer packages )
     {
         boolean isAdded = false;
 
@@ -265,7 +237,7 @@ public class ArtifactRepositoryIndex
         return isAdded;
     }
 
-    private boolean addFile( ZipEntry entry )
+    private boolean addFile( ZipEntry entry, StringBuffer files )
     {
         String name = entry.getName();
         int idx = name.lastIndexOf( '/' );
index 95d2dda408ecc504507fbd1d9668f0d75c77e27c..91acdc9c9d74508edfe9241b7b502c650d860213 100644 (file)
@@ -47,7 +47,9 @@ public class ArtifactRepositoryIndexSearcher
 
     private static final String VERSION = "version";
 
-    /** @plexus.requirement */
+    /**
+     * @plexus.requirement
+     */
     private ArtifactFactory factory;
 
     /**
@@ -56,7 +58,6 @@ public class ArtifactRepositoryIndexSearcher
      *
      * @param queryString
      * @param searchField
-     * @return
      */
     public List search( RepositoryIndex index, String queryString, String searchField )
         throws RepositoryIndexSearchException
index f02b4108181a0fff52a24259393a2ca73c64d42e..fef34439fefcf8f23eaea986a22b837a57bf4eee 100644 (file)
@@ -25,7 +25,6 @@ import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.util.FileUtils;
 
 import java.io.File;
-import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -40,18 +39,12 @@ public class ArtifactRepositoryIndexingTest
 
     private static final String VERSION = "version";
 
-    private static final String SHA1 = "sha1";
-
-    private static final String MD5 = "md5";
-
     private static final String CLASSES = "classes";
 
     private static final String PACKAGES = "packages";
 
     private static final String FILES = "files";
 
-    private ArtifactRepositoryIndex indexer;
-
     private ArtifactFactory artifactFactory;
 
     private ArtifactRepository repository;
@@ -77,6 +70,7 @@ public class ArtifactRepositoryIndexingTest
     public void testIndexerExceptions()
         throws Exception
     {
+        ArtifactRepositoryIndex indexer;
         try
         {
             String notIndexDir = new File( "pom.xml" ).getAbsolutePath();
@@ -146,7 +140,7 @@ public class ArtifactRepositoryIndexingTest
         throws Exception
     {
         //indexer = (ArtifactRepositoryIndex) factory.getArtifactRepositoryIndexer( indexPath, repository );
-        indexer = (ArtifactRepositoryIndex) lookup( RepositoryIndex.ROLE, "artifact" );
+        ArtifactRepositoryIndex indexer = (ArtifactRepositoryIndex) lookup( RepositoryIndex.ROLE, "artifact" );
         indexer.open( indexPath );
 
         Artifact artifact = getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" );
@@ -165,15 +159,16 @@ public class ArtifactRepositoryIndexingTest
         artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
         indexer.index( artifact );
         indexer.close();
+
+        // TODO: assert something!
     }
 
     public void testSearch()
         throws Exception
     {
-        indexer = (ArtifactRepositoryIndex) lookup( RepositoryIndex.ROLE, "artifact" );
+        ArtifactRepositoryIndex indexer = (ArtifactRepositoryIndex) lookup( RepositoryIndex.ROLE, "artifact" );
         indexer.open( getTestPath( "src/test/index" ) );
 
-        //repoSearcher = new ArtifactRepositoryIndexSearcher( indexer, indexPath, repository );
         RepositoryIndexSearcher repoSearcher =
             (RepositoryIndexSearcher) lookup( RepositoryIndexSearcher.ROLE, "artifact" );
 
@@ -195,14 +190,6 @@ public class ArtifactRepositoryIndexingTest
         artifacts = repoSearcher.search( indexer, "pom.xml", FILES );
         assertEquals( 3, artifacts.size() );
 
-        for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
-        {
-            Artifact artifact = (Artifact) iter.next();
-            File f = artifact.getFile();
-            //assertNotNull( f );
-            //assertTrue( f.exists() );
-        }
-
         artifacts = repoSearcher.search( indexer, "org.apache.maven", GROUPID );
         assertEquals( 2, artifacts.size() );
 
index d024a934d14594845e64aa4d60abe23b015349ab..4b938e4b301644365c89c2d261118aed7ee64544 100644 (file)
@@ -68,7 +68,7 @@ public abstract class AbstractRepositoryQueryLayer
     protected Metadata getMetadata( Artifact artifact )
         throws RepositoryQueryLayerException
     {
-        Metadata metadata = null;
+        Metadata metadata;
 
         ArtifactRepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata( artifact );
         String path = repository.pathOfRemoteRepositoryMetadata( repositoryMetadata );
index 8236d70e514eeee5c3c10ccabbf4a56aaf9295a3..027af116f686c93b7ffc8dca6484e491d3a4ca2b 100644 (file)
@@ -70,7 +70,7 @@ public class BadMetadataReportProcessor
         {
             try
             {
-                checkPluginMetadata( metadata, repository, reporter );
+                hasFailures = checkPluginMetadata( metadata, repository, reporter );
             }
             catch ( IOException e )
             {
@@ -88,7 +88,7 @@ public class BadMetadataReportProcessor
 
             if ( metadata.storedInArtifactVersionDirectory() )
             {
-                checkSnapshotMetadata( metadata, repository, reporter );
+                hasFailures |= checkSnapshotMetadata( metadata, repository, reporter );
             }
             else
             {
index 67e403c05beeef7209f6df15d59965c081a9b215..02f25f28ddde235ad505423926630eb8e0fe767f 100644 (file)
@@ -20,14 +20,13 @@ import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
 import org.apache.maven.model.Model;
+import org.codehaus.plexus.util.FileUtils;
 
 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.net.URL;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 
@@ -36,17 +35,11 @@ import java.security.NoSuchAlgorithmException;
  * It validates MD5 and SHA-1 checksums.
  *
  * @todo remove stateful parts, change to singleton instantiation
- * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="checksum" instantiation-strategy="per-lookup"
+ * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="checksum"
  */
 public class ChecksumArtifactReporter
     implements ArtifactReportProcessor
 {
-    private InputStream md5InputStream;
-
-    private InputStream sha1InputStream;
-
-    private boolean isLocal = true;
-
     private static final int BYTE_MASK = 0xFF;
 
     private static final int CHECKSUM_BUFFER_SIZE = 256;
@@ -58,40 +51,42 @@ public class ChecksumArtifactReporter
      * @param artifact
      * @param reporter
      * @param repository
-     * @todo fix repo paths
      */
     public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
                                  ArtifactRepository repository )
     {
-        String repositoryUrl;
-
         if ( !"file".equals( repository.getProtocol() ) )
         {
-            isLocal = false;
-            repositoryUrl = repository.getUrl();
-        }
-        else
-        {
-            repositoryUrl = repository.getBasedir();
+            // We can't check other types of URLs yet. Need to use Wagon, with an exists() method.
+            throw new UnsupportedOperationException(
+                "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" );
         }
 
-        String 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 );
+        String path = repository.pathOf( artifact );
+        File file = new File( repository.getBasedir(), path );
 
-        if ( md5Exists )
+        File md5File = new File( repository.getBasedir(), path + ".md5" );
+        if ( md5File.exists() )
         {
-            if ( validateChecksum( artifactUrl, "MD5" ) )
+            try
             {
-                reporter.addSuccess( artifact );
+                if ( validateChecksum( file, md5File, "MD5" ) )
+                {
+                    reporter.addSuccess( artifact );
+                }
+                else
+                {
+                    reporter.addFailure( artifact, "MD5 checksum does not match." );
+                }
             }
-            else
+            catch ( NoSuchAlgorithmException e )
             {
-                reporter.addFailure( artifact, "MD5 checksum does not match." );
+                reporter.addFailure( artifact, "Unable to read MD5: " + e.getMessage() );
+            }
+            catch ( IOException e )
+            {
+                reporter.addFailure( artifact, "Unable to read MD5: " + e.getMessage() );
             }
         }
         else
@@ -99,15 +94,27 @@ public class ChecksumArtifactReporter
             reporter.addFailure( artifact, "MD5 checksum file does not exist." );
         }
 
-        if ( sha1Exists )
+        File sha1File = new File( repository.getBasedir(), path + ".sha1" );
+        if ( sha1File.exists() )
         {
-            if ( validateChecksum( artifactUrl, "SHA-1" ) )
+            try
             {
-                reporter.addSuccess( artifact );
+                if ( validateChecksum( file, sha1File, "SHA-1" ) )
+                {
+                    reporter.addSuccess( artifact );
+                }
+                else
+                {
+                    reporter.addFailure( artifact, "SHA-1 checksum does not match." );
+                }
             }
-            else
+            catch ( NoSuchAlgorithmException e )
             {
-                reporter.addFailure( artifact, "SHA-1 checksum does not match." );
+                reporter.addFailure( artifact, "Unable to read SHA-1: " + e.getMessage() );
+            }
+            catch ( IOException e )
+            {
+                reporter.addFailure( artifact, "Unable to read SHA-1: " + e.getMessage() );
             }
         }
         else
@@ -119,191 +126,97 @@ public class ChecksumArtifactReporter
     /**
      * Validate the checksums of the metadata. Get the metadata file from the
      * repository then validate the checksum.
-     *
-     * @todo fix repo paths
      */
     public void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter )
     {
-        String repositoryUrl;
-        String filename;
         if ( !"file".equals( repository.getProtocol() ) )
         {
-            isLocal = false;
-            repositoryUrl = repository.getUrl() + "/";
-            filename = metadata.getRemoteFilename();
-        }
-        else
-        {
-            repositoryUrl = repository.getBasedir() + "/";
-            filename = metadata.getLocalFilename( repository );
-        }
-        String metadataUrl;
-
-        if ( metadata.storedInArtifactVersionDirectory() && !metadata.storedInGroupDirectory() )
-        {
-            //version metadata
-            metadataUrl = repositoryUrl + metadata.getGroupId() + "/" + metadata.getArtifactId() + "/" +
-                metadata.getBaseVersion() + "/";
-        }
-        else if ( !metadata.storedInArtifactVersionDirectory() && metadata.storedInGroupDirectory() )
-        {
-            //group metadata
-            metadataUrl = repositoryUrl + metadata.getGroupId() + "/";
-        }
-        else
-        {
-            //artifact metadata
-            metadataUrl = repositoryUrl + metadata.getGroupId() + "/" + metadata.getArtifactId() + "/";
+            // We can't check other types of URLs yet. Need to use Wagon, with an exists() method.
+            throw new UnsupportedOperationException(
+                "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" );
         }
 
-        //add the file name of the metadata
-        metadataUrl = metadataUrl + filename;
-
         //check if checksum files exist
-        boolean md5Exists = getMD5File( metadataUrl );
-        boolean sha1Exists = getSHA1File( metadataUrl );
+        String path = repository.pathOfRemoteRepositoryMetadata( metadata );
+        File file = new File( repository.getBasedir(), path );
 
-        if ( md5Exists )
+        File md5File = new File( repository.getBasedir(), path + ".md5" );
+        if ( md5File.exists() )
         {
-            if ( validateChecksum( metadataUrl, "MD5" ) )
-            {
-                reporter.addSuccess( metadata );
-            }
-            else
+            try
             {
-                reporter.addFailure( metadata, "MD5 checksum does not match." );
+                if ( validateChecksum( file, md5File, "MD5" ) )
+                {
+                    reporter.addSuccess( metadata );
+                }
+                else
+                {
+                    reporter.addFailure( metadata, "MD5 checksum does not match." );
+                }
             }
-        }
-        else
-        {
-            reporter.addFailure( metadata, "MD5 checksum file does not exist." );
-        }
-
-        if ( sha1Exists )
-        {
-            if ( validateChecksum( metadataUrl, "SHA-1" ) )
+            catch ( NoSuchAlgorithmException e )
             {
-                reporter.addSuccess( metadata );
+                reporter.addFailure( metadata, "Unable to read MD5: " + e.getMessage() );
             }
-            else
+            catch ( IOException e )
             {
-                reporter.addFailure( metadata, "SHA-1 checksum does not match." );
+                reporter.addFailure( metadata, "Unable to read MD5: " + e.getMessage() );
             }
         }
         else
         {
-            reporter.addFailure( metadata, "SHA-1 checksum file does not exist." );
+            reporter.addFailure( metadata, "MD5 checksum file does not exist." );
         }
 
-    }
-
-    /**
-     * Get the MD5 Checksum file. If not found, return false.
-     *
-     * @param filename The name of the artifact whose MD5 Checksum file will be retrieved.
-     * @todo fix this erroneous object state
-     */
-    private boolean getMD5File( String filename )
-    {
-        try
+        File sha1File = new File( repository.getBasedir(), path + ".sha1" );
+        if ( sha1File.exists() )
         {
-            if ( isLocal )
+            try
             {
-                md5InputStream = new FileInputStream( filename + ".md5" );
+                if ( validateChecksum( file, sha1File, "SHA-1" ) )
+                {
+                    reporter.addSuccess( metadata );
+                }
+                else
+                {
+                    reporter.addFailure( metadata, "SHA-1 checksum does not match." );
+                }
             }
-            else
+            catch ( NoSuchAlgorithmException e )
             {
-                URL url = new URL( filename );
-                md5InputStream = url.openStream();
+                reporter.addFailure( metadata, "Unable to read SHA1: " + e.getMessage() );
             }
-
-            md5InputStream.close();
-        }
-        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.
-     * @todo fix this erroneous object state
-     */
-    private boolean getSHA1File( String filename )
-    {
-        try
-        {
-            if ( isLocal )
+            catch ( IOException e )
             {
-                sha1InputStream = new FileInputStream( filename + ".sha1" );
+                reporter.addFailure( metadata, "Unable to read SHA1: " + e.getMessage() );
             }
-            else
-            {
-                URL url = new URL( filename );
-                sha1InputStream = url.openStream();
-            }
-            sha1InputStream.close();
         }
-        catch ( Exception e )
+        else
         {
-            return false;
+            reporter.addFailure( metadata, "SHA-1 checksum file does not exist." );
         }
-        return true;
+
     }
 
     /**
      * Validate the checksum of the file.
      *
-     * @param fileUrl The file to be validated.
-     * @param algo    The checksum algorithm used.
+     * @param file         The file to be validated.
+     * @param checksumFile the checksum to validate against
+     * @param algo         The checksum algorithm used.
      */
-    private boolean validateChecksum( String fileUrl, String algo )
+    private boolean validateChecksum( File file, File checksumFile, String algo )
+        throws NoSuchAlgorithmException, IOException
     {
         boolean valid = false;
 
-        try
-        {
-            //Create checksum for jar file
-            String ext = ".md5";
-            if ( "SHA-1".equals( algo ) )
-            {
-                ext = ".sha1";
-            }
-            byte[] chk1 = createChecksum( fileUrl, algo );
-            if ( chk1 != null )
-            {
-
-                //read the md5 file
-                File f = new File( fileUrl + ext );
-                InputStream is;
-
-                //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 );
-                isr.close();
-
-                String chk2Str = new String( chars );
-
-                valid = chk2Str.toUpperCase().equals( byteArrayToHexStr( chk1 ).toUpperCase() );
-            }
-        }
-        catch ( Exception e )
+        //Create checksum for jar file
+        byte[] chk1 = createChecksum( file, algo );
+        if ( chk1 != null )
         {
-            // TODO: fix this error handling
+            //read the checksum file
+            String checksum = FileUtils.fileRead( checksumFile );
+            valid = checksum.toUpperCase().equals( byteArrayToHexStr( chk1 ).toUpperCase() );
         }
         return valid;
     }
@@ -311,45 +224,40 @@ public class ChecksumArtifactReporter
     /**
      * 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)
+     * @param file 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
      * @todo move to utility class
      */
-    private byte[] createChecksum( String filename, String algo )
+    private byte[] createChecksum( File file, String algo )
         throws FileNotFoundException, NoSuchAlgorithmException, IOException
     {
-        InputStream fis;
+        MessageDigest digest = MessageDigest.getInstance( algo );
 
-        //check whether file is located locally or remotely
-        if ( isLocal )
-        {
-            fis = new FileInputStream( filename );
-        }
-        else
-        {
-            URL url = new URL( filename );
-            fis = url.openStream();
-        }
-        byte[] buffer = new byte[CHECKSUM_BUFFER_SIZE];
-
-        MessageDigest complete = MessageDigest.getInstance( algo );
-        int numRead;
-        do
+        InputStream fis = new FileInputStream( file );
+        try
         {
-            numRead = fis.read( buffer );
-            if ( numRead > 0 )
+            byte[] buffer = new byte[CHECKSUM_BUFFER_SIZE];
+            int numRead;
+            do
             {
-                complete.update( buffer, 0, numRead );
+                numRead = fis.read( buffer );
+                if ( numRead > 0 )
+                {
+                    digest.update( buffer, 0, numRead );
+                }
             }
+            while ( numRead != -1 );
+        }
+        finally
+        {
+            fis.close();
         }
-        while ( numRead != -1 );
-        fis.close();
 
-        return complete.digest();
+        return digest.digest();
     }
 
     /**
index 3a832f43953099ad1f30789babcf3f797fbddf3a..5ff2fa1e6f56a7b3c694506c9f8a1528c638eef0 100644 (file)
@@ -20,19 +20,18 @@ import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
-import java.io.FileInputStream;
+import java.io.File;
 import java.io.FileNotFoundException;
+import java.io.FileReader;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.io.Reader;
-import java.net.MalformedURLException;
-import java.net.URL;
 
 /**
  * This class validates well-formedness of pom xml file.
+ *
  * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="invalid-pom"
  */
 public class InvalidPomArtifactReportProcessor
@@ -48,60 +47,51 @@ public class InvalidPomArtifactReportProcessor
     public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
                                  ArtifactRepository repository )
     {
+        if ( !"file".equals( repository.getProtocol() ) )
+        {
+            // We can't check other types of URLs yet. Need to use Wagon, with an exists() method.
+            throw new UnsupportedOperationException(
+                "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" );
+        }
+
         if ( "pom".equals( artifact.getType().toLowerCase() ) )
         {
-            InputStream is = null;
+            File f = new File( repository.getBasedir(), repository.pathOf( artifact ) );
 
-            if ( "file".equals( repository.getProtocol() ) )
+            if ( !f.exists() )
+            {
+                reporter.addFailure( artifact, "Artifact not found." );
+            }
+            else
             {
+                Reader reader = null;
+
+                MavenXpp3Reader pomReader = new MavenXpp3Reader();
+
                 try
                 {
-                    is = new FileInputStream( repository.getBasedir() + artifact.getGroupId() + "/" +
-                        artifact.getArtifactId() + "/" + artifact.getBaseVersion() + "/" + artifact.getArtifactId() +
-                        "-" + artifact.getBaseVersion() + "." + artifact.getType() );
+                    reader = new FileReader( f );
+                    pomReader.read( reader );
+                    reporter.addSuccess( artifact );
                 }
-                catch ( FileNotFoundException fe )
+                catch ( XmlPullParserException e )
                 {
-                    reporter.addFailure( artifact, "Artifact not found." );
+                    reporter.addFailure( artifact, "The pom xml file is not well-formed. Error while parsing: " +
+                        e.getMessage() );
                 }
-            }
-            else
-            {
-                try
+                catch ( FileNotFoundException e )
                 {
-                    URL url = new URL( repository.getUrl() + artifact.getGroupId() + "/" + artifact.getArtifactId() +
-                        "/" + artifact.getBaseVersion() + "/" + artifact.getArtifactId() + "-" +
-                        artifact.getBaseVersion() + "." + artifact.getType() );
-                    is = url.openStream();
-
+                    reporter.addFailure( artifact, "Error while reading the pom xml file: " + e.getMessage() );
                 }
-                catch ( MalformedURLException me )
+                catch ( IOException e )
                 {
-                    reporter.addFailure( artifact, "Error retrieving artifact from remote repository." );
+                    reporter.addFailure( artifact, "Error while reading the pom xml file: " + e.getMessage() );
                 }
-                catch ( IOException ie )
+                finally
                 {
-                    reporter.addFailure( artifact, "Error retrieving artifact from remote repository." );
+                    IOUtil.close( reader );
                 }
             }
-
-            Reader reader = new InputStreamReader( is );
-            MavenXpp3Reader pomReader = new MavenXpp3Reader();
-
-            try
-            {
-                pomReader.read( reader );
-                reporter.addSuccess( artifact );
-            }
-            catch ( XmlPullParserException xe )
-            {
-                reporter.addFailure( artifact, "The pom xml file is not well-formed. Error while parsing." );
-            }
-            catch ( IOException oe )
-            {
-                reporter.addFailure( artifact, "Error while reading the pom xml file." );
-            }
-
         }
         else
         {
index 11c394eae89683a3230e6d3e6de19d3c46006e75..770879b0e3d6446dba0342171ae85b715025737d 100644 (file)
@@ -46,7 +46,7 @@ public abstract class AbstractChecksumArtifactReporterTestCase
 
     private static final String[] invalidArtifactChecksumJars = {"invalidArtifact-1.0"};
 
-    private static final String metadataChecksumFilename = "maven-metadata-repository";
+    private static final String metadataChecksumFilename = "maven-metadata";
 
     private static final int CHECKSUM_BUFFER_SIZE = 256;
 
@@ -56,12 +56,6 @@ public abstract class AbstractChecksumArtifactReporterTestCase
         super.setUp();
     }
 
-    public void tearDown()
-        throws Exception
-    {
-        super.tearDown();
-    }
-
     /**
      * Create checksum files.
      *
@@ -290,21 +284,16 @@ public abstract class AbstractChecksumArtifactReporterTestCase
      *
      * @param dir The directory to be deleted.
      */
-    protected boolean deleteTestDirectory( File dir )
+    protected void deleteTestDirectory( File dir )
     {
-        boolean b;
-
         try
         {
             FileUtils.deleteDirectory( dir );
-            b = true;
         }
-        catch ( IOException ioe )
+        catch ( IOException e )
         {
-            b = false;
+            // ignore
         }
-
-        return b;
     }
 
     private void deleteFile( String filename )
diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTest.java
deleted file mode 100644 (file)
index 7d9a8de..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-package org.apache.maven.repository.reporting;
-
-/*
- * Copyright 2005-2006 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 org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
-import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
-import org.apache.maven.artifact.repository.metadata.Snapshot;
-import org.codehaus.plexus.PlexusTestCase;
-
-import java.io.File;
-import java.util.List;
-
-/**
- *
- */
-public abstract class AbstractRepositoryQueryLayerTest
-    extends PlexusTestCase
-{
-    private ArtifactFactory artifactFactory;
-
-    protected ArtifactRepository repository;
-
-    protected CachedRepositoryQueryLayer queryLayer;
-
-    protected void setUp()
-        throws Exception
-    {
-        super.setUp();
-        File repositoryDirectory = getTestFile( "src/test/repository" );
-
-        artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
-        ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
-        ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
-
-        repository =
-            factory.createArtifactRepository( "test", repositoryDirectory.toURL().toString(), layout, null, null );
-    }
-
-    public void testContainsArtifactTrue()
-    {
-        Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-alpha-1" );
-
-        assertTrue( "check artifact", queryLayer.containsArtifact( artifact ) );
-    }
-
-    public void testContainsArtifactFalse()
-    {
-        Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-beta-1" );
-
-        assertFalse( "check non-existent artifact", queryLayer.containsArtifact( artifact ) );
-    }
-
-    public void testContainsSnapshotArtifactTrue()
-    {
-        Snapshot snapshot = new Snapshot();
-        snapshot.setTimestamp( "20050611.202024" );
-        snapshot.setBuildNumber( 1 );
-
-        Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" );
-        assertTrue( "check for snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) );
-    }
-
-    public void testContainsSnapshotArtifactFalse()
-    {
-        Snapshot snapshot = new Snapshot();
-        snapshot.setTimestamp( "20050611.202024" );
-        snapshot.setBuildNumber( 2 );
-
-        Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" );
-        assertFalse( "check for non-existent snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) );
-    }
-
-    public void testArtifactVersionsTrue()
-        throws Exception
-    {
-        Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" );
-
-        List versions = queryLayer.getVersions( artifact );
-
-        assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) );
-        assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) );
-        assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) );
-    }
-
-    public void testArtifactVersionsFalse()
-        throws Exception
-    {
-        Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" );
-
-        List versions = queryLayer.getVersions( artifact );
-
-        assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) );
-        assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) );
-        assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) );
-    }
-
-    public void testArtifactVersionsError()
-    {
-        Artifact artifact = getArtifact( "groupId", "none", "ignored" );
-
-        try
-        {
-            queryLayer.getVersions( artifact );
-            fail( "expected error not thrown" );
-        }
-        catch ( RepositoryQueryLayerException e )
-        {
-            //expected
-        }
-    }
-
-    private Artifact getArtifact( String groupId, String artifactId, String version )
-    {
-        return artifactFactory.createBuildArtifact( groupId, artifactId, version, "pom" );
-    }
-
-    protected void tearDown()
-        throws Exception
-    {
-        release( artifactFactory );
-        super.tearDown();
-        artifactFactory = null;
-        repository = null;
-    }
-}
diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTestCase.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTestCase.java
new file mode 100644 (file)
index 0000000..6de998c
--- /dev/null
@@ -0,0 +1,142 @@
+package org.apache.maven.repository.reporting;
+
+/*
+ * Copyright 2005-2006 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 org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.artifact.repository.metadata.Snapshot;
+import org.codehaus.plexus.PlexusTestCase;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ *
+ */
+public abstract class AbstractRepositoryQueryLayerTestCase
+    extends PlexusTestCase
+{
+    private ArtifactFactory artifactFactory;
+
+    protected ArtifactRepository repository;
+
+    protected CachedRepositoryQueryLayer queryLayer;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        File repositoryDirectory = getTestFile( "src/test/repository" );
+
+        artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+        ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
+        ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
+
+        repository =
+            factory.createArtifactRepository( "test", repositoryDirectory.toURL().toString(), layout, null, null );
+    }
+
+    public void testContainsArtifactTrue()
+    {
+        Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-alpha-1" );
+
+        assertTrue( "check artifact", queryLayer.containsArtifact( artifact ) );
+    }
+
+    public void testContainsArtifactFalse()
+    {
+        Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-beta-1" );
+
+        assertFalse( "check non-existent artifact", queryLayer.containsArtifact( artifact ) );
+    }
+
+    public void testContainsSnapshotArtifactTrue()
+    {
+        Snapshot snapshot = new Snapshot();
+        snapshot.setTimestamp( "20050611.202024" );
+        snapshot.setBuildNumber( 1 );
+
+        Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" );
+        assertTrue( "check for snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) );
+    }
+
+    public void testContainsSnapshotArtifactFalse()
+    {
+        Snapshot snapshot = new Snapshot();
+        snapshot.setTimestamp( "20050611.202024" );
+        snapshot.setBuildNumber( 2 );
+
+        Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" );
+        assertFalse( "check for non-existent snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) );
+    }
+
+    public void testArtifactVersionsTrue()
+        throws Exception
+    {
+        Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" );
+
+        List versions = queryLayer.getVersions( artifact );
+
+        assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) );
+        assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) );
+        assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) );
+    }
+
+    public void testArtifactVersionsFalse()
+        throws Exception
+    {
+        Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" );
+
+        List versions = queryLayer.getVersions( artifact );
+
+        assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) );
+        assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) );
+        assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) );
+    }
+
+    public void testArtifactVersionsError()
+    {
+        Artifact artifact = getArtifact( "groupId", "none", "ignored" );
+
+        try
+        {
+            queryLayer.getVersions( artifact );
+            fail( "expected error not thrown" );
+        }
+        catch ( RepositoryQueryLayerException e )
+        {
+            //expected
+        }
+    }
+
+    private Artifact getArtifact( String groupId, String artifactId, String version )
+    {
+        return artifactFactory.createBuildArtifact( groupId, artifactId, version, "pom" );
+    }
+
+    protected void tearDown()
+        throws Exception
+    {
+        release( artifactFactory );
+        super.tearDown();
+        artifactFactory = null;
+        repository = null;
+    }
+}
index e01f80021405e32b88b6d89e89ba895f4bdc2d96..e3fc97f6b97e38682bd5a8965f3f9e4e73103993 100644 (file)
@@ -31,14 +31,10 @@ public class ArtifactReporterTest
 {
     private ArtifactReporter reporter;
 
-    private ArtifactFactory artifactFactory;
-
     private Artifact artifact;
 
     private MockArtifactReportProcessor processor;
 
-    private Versioning versioning;
-
     private Model model;
 
     protected void setUp()
@@ -46,10 +42,10 @@ public class ArtifactReporterTest
     {
         super.setUp();
         reporter = new DefaultArtifactReporter();
-        artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+        ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
         artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
         processor = new MockArtifactReportProcessor();
-        versioning = new Versioning();
+        Versioning versioning = new Versioning();
         versioning.addVersion( "1.0-alpha-1" );
         versioning.setLastUpdated( "20050611.202020" );
         model = new Model();
@@ -61,11 +57,11 @@ public class ArtifactReporterTest
         processor.processArtifact( model, artifact, reporter, null );
         Iterator success = reporter.getArtifactSuccessIterator();
         assertTrue( success.hasNext() );
-        assertTrue( reporter.getSuccesses() == 1 );
+        assertEquals( 1, reporter.getSuccesses() );
         Artifact result = ( (ArtifactResult) success.next() ).getArtifact();
-        assertTrue( "groupId".equals( result.getGroupId() ) );
-        assertTrue( "artifactId".equals( result.getArtifactId() ) );
-        assertTrue( "1.0-alpha-1".equals( result.getVersion() ) );
+        assertEquals( "groupId", result.getGroupId() );
+        assertEquals( "artifactId", result.getArtifactId() );
+        assertEquals( "1.0-alpha-1", result.getVersion() );
         assertFalse( success.hasNext() );
     }
 
@@ -84,10 +80,10 @@ public class ArtifactReporterTest
         {
             success.next();
         }
-        assertTrue( i == 3 );
-        assertTrue( reporter.getSuccesses() == 3 );
-        assertTrue( reporter.getFailures() == 0 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 3, i );
+        assertEquals( 3, reporter.getSuccesses() );
+        assertEquals( 0, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
     }
 
     public void testArtifactReporterSingleFailure()
@@ -98,9 +94,9 @@ public class ArtifactReporterTest
         assertTrue( failure.hasNext() );
         failure.next();
         assertFalse( failure.hasNext() );
-        assertTrue( reporter.getSuccesses() == 0 );
-        assertTrue( reporter.getFailures() == 1 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 0, reporter.getSuccesses() );
+        assertEquals( 1, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
     }
 
     public void testArtifactReporterMultipleFailure()
@@ -116,10 +112,10 @@ public class ArtifactReporterTest
         {
             failure.next();
         }
-        assertTrue( i == 3 );
-        assertTrue( reporter.getSuccesses() == 0 );
-        assertTrue( reporter.getFailures() == 3 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 3, i );
+        assertEquals( 0, reporter.getSuccesses() );
+        assertEquals( 3, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
     }
 
     public void testFailureMessages()
@@ -129,9 +125,9 @@ public class ArtifactReporterTest
         processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed thrice" );
         processor.processArtifact( model, artifact, reporter, null );
         Iterator failure = reporter.getArtifactFailureIterator();
-        assertTrue( "failed once".equals( ( (ArtifactResult) failure.next() ).getReason() ) );
-        assertTrue( "failed twice".equals( ( (ArtifactResult) failure.next() ).getReason() ) );
-        assertTrue( "failed thrice".equals( ( (ArtifactResult) failure.next() ).getReason() ) );
+        assertEquals( "failed once", ( (ArtifactResult) failure.next() ).getReason() );
+        assertEquals( "failed twice", ( (ArtifactResult) failure.next() ).getReason() );
+        assertEquals( "failed thrice", ( (ArtifactResult) failure.next() ).getReason() );
     }
 
     public void testArtifactReporterSingleWarning()
@@ -142,9 +138,9 @@ public class ArtifactReporterTest
         assertTrue( warning.hasNext() );
         warning.next();
         assertFalse( warning.hasNext() );
-        assertTrue( reporter.getSuccesses() == 0 );
-        assertTrue( reporter.getFailures() == 0 );
-        assertTrue( reporter.getWarnings() == 1 );
+        assertEquals( 0, reporter.getSuccesses() );
+        assertEquals( 0, reporter.getFailures() );
+        assertEquals( 1, reporter.getWarnings() );
     }
 
     public void testArtifactReporterMultipleWarning()
@@ -160,10 +156,10 @@ public class ArtifactReporterTest
         {
             warning.next();
         }
-        assertTrue( i == 3 );
-        assertTrue( reporter.getSuccesses() == 0 );
-        assertTrue( reporter.getFailures() == 0 );
-        assertTrue( reporter.getWarnings() == 3 );
+        assertEquals( 3, i );
+        assertEquals( 0, reporter.getSuccesses() );
+        assertEquals( 0, reporter.getFailures() );
+        assertEquals( 3, reporter.getWarnings() );
     }
 
     public void testWarningMessages()
@@ -173,19 +169,17 @@ public class ArtifactReporterTest
         processor.addReturnValue( ReportCondition.WARNING, artifact, "all right... that does it!" );
         processor.processArtifact( model, artifact, reporter, null );
         Iterator warning = reporter.getArtifactWarningIterator();
-        assertTrue( "i'm warning you".equals( ( (ArtifactResult) warning.next() ).getReason() ) );
-        assertTrue( "you have to stop now".equals( ( (ArtifactResult) warning.next() ).getReason() ) );
-        assertTrue( "all right... that does it!".equals( ( (ArtifactResult) warning.next() ).getReason() ) );
+        assertEquals( "i'm warning you", ( (ArtifactResult) warning.next() ).getReason() );
+        assertEquals( "you have to stop now", ( (ArtifactResult) warning.next() ).getReason() );
+        assertEquals( "all right... that does it!", ( (ArtifactResult) warning.next() ).getReason() );
     }
 
     protected void tearDown()
         throws Exception
     {
         model = null;
-        versioning = null;
         processor.clearList();
         processor = null;
-        artifactFactory = null;
         reporter = null;
         super.tearDown();
     }
index 13ab29f963df239d30f517d9dd3bab9736cdf7e8..6c8e535cba19f3b0308ce269998b7e6bd5bee431 100644 (file)
@@ -20,7 +20,7 @@ package org.apache.maven.repository.reporting;
  *
  */
 public class CachedRepositoryQueryLayerTest
-    extends AbstractRepositoryQueryLayerTest
+    extends AbstractRepositoryQueryLayerTestCase
 {
     // TODO: share
     private static final double CACHE_HIT_RATIO = 0.5;
index eabf37e48ab0beb466c0a038b5570d9b86e33970..ac19ab3e09e665b786ad837bc90c36bf0f91dd37 100644 (file)
@@ -171,7 +171,6 @@ public class DefaultArtifactReporterTest
         Versioning versioning = new Versioning();
         versioning.addVersion( "1.0-alpha-1" );
         versioning.addVersion( "1.0-alpha-2" );
-        RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
     }
 
     protected void tearDown()
index e03d8f1722e0b41c98f76b575f377076ab76595e..71c53d8bd66a77c4d382a494a0c040358d3dbdeb 100644 (file)
@@ -39,34 +39,19 @@ public class InvalidPomArtifactReportProcessorTest
         artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "invalid-pom" );
     }
 
-    public void tearDown()
-        throws Exception
-    {
-        super.tearDown();
-    }
-
     /**
      * Test the InvalidPomArtifactReportProcessor when the artifact is an invalid pom.
      */
     public void testInvalidPomArtifactReportProcessorFailure()
+        throws ReportProcessorException
     {
+        ArtifactHandler handler = new DefaultArtifactHandler( "pom" );
+        VersionRange version = VersionRange.createFromVersion( "1.0-alpha-3" );
+        Artifact artifact =
+            new DefaultArtifact( "org.apache.maven", "artifactId", version, "compile", "pom", "", handler );
 
-        try
-        {
-            ArtifactHandler handler = new DefaultArtifactHandler( "pom" );
-            VersionRange version = VersionRange.createFromVersion( "1.0-alpha-3" );
-            Artifact artifact =
-                new DefaultArtifact( "org.apache.maven", "artifactId", version, "compile", "pom", "", handler );
-
-            artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
-            assertTrue( reporter.getFailures() == 1 );
-            //System.out.println("INVALID POM ARTIFACT FAILURES --->> " + reporter.getFailures());
-
-        }
-        catch ( Exception e )
-        {
-
-        }
+        artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
+        assertEquals( 1, reporter.getFailures() );
     }
 
 
@@ -74,23 +59,14 @@ public class InvalidPomArtifactReportProcessorTest
      * Test the InvalidPomArtifactReportProcessor when the artifact is a valid pom.
      */
     public void testInvalidPomArtifactReportProcessorSuccess()
+        throws ReportProcessorException
     {
+        ArtifactHandler handler = new DefaultArtifactHandler( "pom" );
+        VersionRange version = VersionRange.createFromVersion( "1.0-alpha-2" );
+        Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "pom", "", handler );
 
-        try
-        {
-            ArtifactHandler handler = new DefaultArtifactHandler( "pom" );
-            VersionRange version = VersionRange.createFromVersion( "1.0-alpha-2" );
-            Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "pom", "", handler );
-
-            artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
-            assertTrue( reporter.getSuccesses() == 1 );
-            //System.out.println("VALID POM ARTIFACT SUCCESS --->> " + reporter.getSuccesses());
-
-        }
-        catch ( Exception e )
-        {
-
-        }
+        artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
+        assertEquals( 1, reporter.getSuccesses() );
     }
 
 
@@ -98,23 +74,14 @@ public class InvalidPomArtifactReportProcessorTest
      * Test the InvalidPomArtifactReportProcessor when the artifact is not a pom.
      */
     public void testNotAPomArtifactReportProcessorSuccess()
+        throws ReportProcessorException
     {
+        ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
+        VersionRange version = VersionRange.createFromVersion( "1.0-alpha-1" );
+        Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "jar", "", handler );
 
-        try
-        {
-            ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
-            VersionRange version = VersionRange.createFromVersion( "1.0-alpha-1" );
-            Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "jar", "", handler );
-
-            artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
-            assertTrue( reporter.getWarnings() == 1 );
-            //System.out.println("NOT A POM ARTIFACT WARNINGS --->> " + reporter.getWarnings());
-
-        }
-        catch ( Exception e )
-        {
-
-        }
+        artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
+        assertEquals( 1, reporter.getWarnings() );
     }
 
     /**
@@ -134,7 +101,6 @@ public class InvalidPomArtifactReportProcessorTest
             if(reporter.getSuccesses() == 1)
                 assertTrue(reporter.getSuccesses() == 1);
                         
-            //System.out.println("Remote pom SUCCESS --> " + reporter.getSuccesses());
         }catch(Exception e){
             
         }
index 620b985ee53bb06b4b9ae134c36843387d860395..d892dd3a6ad277fe3b3f8ad93c0f41ceefc83f01 100644 (file)
@@ -214,8 +214,6 @@ public class LocationArtifactReportProcessorTest
             if ( reporter.getSuccesses() > 0 )
                 assertTrue( reporter.getSuccesses() == 1 );
 
-            //    System.out.println("REMOTE ARTIFACT MATCH SUCCESSES ---> " + reporter.getSuccesses());
-
         }
         catch ( Exception e )
         {
index 1f2ccbddc778e2ab0f79e9d6a178fb492830d618..f5658a1f31ec707bded097ca930d8426476d5365 100644 (file)
@@ -30,7 +30,7 @@ import java.util.Collection;
 import java.util.List;
 
 /**
- * 
+ * @noinspection ReturnOfNull
  */
 public class MockArtifact
     implements Artifact
index 44abcef9adcb8946780d968e924db32be5be53a6..3052a12c9995af0e5069db31138353b5532951dd 100644 (file)
@@ -21,7 +21,7 @@ import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.versioning.VersionRange;
 
 /**
- * 
+ * @noinspection ReturnOfNull
  */
 public class MockArtifactFactory
     implements ArtifactFactory
index 7c2460ac9101f19e9cf58e0130411823257420f3..aeaa7e6d3f295275e6b43e28ef63af30b94da3c4 100644 (file)
@@ -20,6 +20,7 @@ import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.metadata.Snapshot;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
@@ -72,13 +73,8 @@ public class MockRepositoryQueryLayer
         return containsArtifact( artifact );
     }
 
-    public boolean containsArtifactVersion( Artifact artifact, String version )
-    {
-        return false;
-    }
-
     public List getVersions( Artifact artifact )
     {
-        return null;
+        return Collections.EMPTY_LIST;
     }
 }
diff --git a/maven-repository-reports-standard/src/test/repository/maven-metadata-repository.xml b/maven-repository-reports-standard/src/test/repository/maven-metadata-repository.xml
deleted file mode 100644 (file)
index 9efaee3..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<!--
-  ~ Copyright 2005-2006 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.
-  -->
-
-<metadata>
-  <groupId>checksumTest</groupId>
-  <artifactId>invalidArtifact</artifactId>
-  <version>1.0</version>
-</metadata>
diff --git a/maven-repository-reports-standard/src/test/repository/maven-metadata.xml b/maven-repository-reports-standard/src/test/repository/maven-metadata.xml
new file mode 100644 (file)
index 0000000..9efaee3
--- /dev/null
@@ -0,0 +1,21 @@
+<!--
+  ~ Copyright 2005-2006 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.
+  -->
+
+<metadata>
+  <groupId>checksumTest</groupId>
+  <artifactId>invalidArtifact</artifactId>
+  <version>1.0</version>
+</metadata>