]> source.dussan.org Git - archiva.git/commitdiff
more cleaning up
authorBrett Porter <brett@apache.org>
Fri, 30 Dec 2005 08:24:41 +0000 (08:24 +0000)
committerBrett Porter <brett@apache.org>
Fri, 30 Dec 2005 08:24:41 +0000 (08:24 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@360028 13f79535-47bb-0310-9956-ffa450edef68

29 files changed:
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.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/ArtifactRepositoryIndexAnalyzer.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearchException.java [new file with mode: 0644]
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.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/ArtifactReporter.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/Cache.java
maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.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/DefaultArtifactReportProcessor.java
maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java
maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java
maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayer.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java [deleted file]
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTestCase.java [new file with mode: 0644]
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.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/ChecksumArtifactReporterTest.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java
maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java

index 14acf5d3760f1dad1f291c6beaf6ce3fb334c312..b0024db437224f5ddc721a73961b4bfaa559bee4 100644 (file)
@@ -145,13 +145,14 @@ public class DefaultMetadataDiscoverer
                 int ctr = 0;
                 for ( it = pathParts.iterator(); it.hasNext(); )
                 {
+                    String path = (String) it.next();
                     if ( ctr == 0 )
                     {
-                        groupDir = (String) it.next();
+                        groupDir = path;
                     }
                     else
                     {
-                        groupDir = (String) it.next() + "." + groupDir;
+                        groupDir = path + "." + groupDir;
                     }
                     ctr++;
                 }
index 4cac9168d2cb670afbf095d58239e9887b71cfc3..405578323a764dc5285912e60102984619c480c0 100644 (file)
@@ -62,6 +62,9 @@ public class LegacyArtifactDiscoverer
         return artifacts;
     }
 
+    /**
+     * @noinspection CollectionDeclaredAsConcreteClass
+     */
     private Artifact buildArtifact( String path )
     {
         StringTokenizer tokens = new StringTokenizer( path, "/\\" );
@@ -154,6 +157,11 @@ public class LegacyArtifactDiscoverer
             }
         }
 
+        // let's discover the version, and whatever's leftover will be either
+        // a classifier, or part of the artifactId, depending on position.
+        // Since version is at the end, we have to move in from the back.
+        Collections.reverse( avceTokenList );
+
         // TODO: this is obscene - surely a better way?
         String validVersionParts = "([Dd][Ee][Vv][_.0-9]*)|" + "([Ss][Nn][Aa][Pp][Ss][Hh][Oo][Tt])|" +
             "([0-9][_.0-9a-zA-Z]*)|" + "([Gg]?[_.0-9ab]*([Pp][Rr][Ee]|[Rr][Cc]|[Gg]|[Mm])[_.0-9]*)|" +
@@ -163,11 +171,6 @@ public class LegacyArtifactDiscoverer
             "([Ll][Aa][Tt][Ee][Ss][Tt])|" + "([Ff][Cc][Ss])|" + "([Rr][Ee][Ll][Ee][Aa][Ss][Ee][_.0-9]*)|" +
             "([Nn][Ii][Gg][Hh][Tt][Ll][Yy])|" + "([AaBb][_.0-9]*)";
 
-        // let's discover the version, and whatever's leftover will be either
-        // a classifier, or part of the artifactId, depending on position.
-        // Since version is at the end, we have to move in from the back.
-        Collections.reverse( avceTokenList );
-
         StringBuffer classifierBuffer = new StringBuffer();
         StringBuffer versionBuffer = new StringBuffer();
 
@@ -190,6 +193,7 @@ public class LegacyArtifactDiscoverer
             {
                 if ( firstVersionTokenEncountered )
                 {
+                    //noinspection BreakStatement
                     break;
                 }
                 else
index 9d5e304c3503378100f694cc997282320d787c38..04e3d2575efb1cd49446d076dd1be53494fda249 100644 (file)
@@ -18,6 +18,7 @@ package org.apache.maven.repository.indexing;
 
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
 
 import java.io.File;
 import java.io.IOException;
@@ -29,6 +30,7 @@ import java.util.Collection;
  * @author Edwin Punzalan
  */
 public abstract class AbstractRepositoryIndex
+    extends AbstractLogEnabled
     implements RepositoryIndex
 {
     protected String indexPath;
@@ -45,7 +47,7 @@ public abstract class AbstractRepositoryIndex
     public void optimize()
         throws RepositoryIndexException
     {
-        if ( !isOpen() )
+        if ( !indexOpen )
         {
             throw new RepositoryIndexException( "Unable to optimize index on a closed index" );
         }
@@ -63,7 +65,7 @@ public abstract class AbstractRepositoryIndex
     /**
      * method used to query the index status
      *
-     * @param true if the index is open.
+     * @return true if the index is open.
      */
     public boolean isOpen()
     {
@@ -165,13 +167,13 @@ public abstract class AbstractRepositoryIndex
             }
             else
             {
-                System.out.println( "Skipping index field validations for empty index." );
+                getLogger().info( "Skipping index field validations for empty index." );
             }
         }
         else if ( !indexDir.exists() )
         {
             indexWriter = new IndexWriter( indexPath, getAnalyzer(), true );
-            System.out.println( "New index directory created in: " + indexDir.getAbsolutePath() );
+            getLogger().info( "New index directory created in: " + indexDir.getAbsolutePath() );
         }
         else if ( indexDir.isDirectory() )
         {
index c07ffdb5c769457916157f3436f45ac26560d17d..e7cfcc3464bd1e009691cecc85b76dc98085e26f 100644 (file)
@@ -71,6 +71,8 @@ public class ArtifactRepositoryIndex
 
     private StringBuffer files;
 
+    private static final int CHEKCSUM_BUFFER_SIZE = 256;
+
     /**
      * method to get the Analyzer used to create indices
      *
@@ -172,7 +174,7 @@ public class ArtifactRepositoryIndex
     private byte[] getChecksum( InputStream inStream, String algorithm )
         throws IOException, NoSuchAlgorithmException
     {
-        byte[] buffer = new byte[ 256 ];
+        byte[] buffer = new byte[ CHEKCSUM_BUFFER_SIZE ];
         MessageDigest complete = MessageDigest.getInstance( algorithm );
         int numRead;
         do
@@ -263,8 +265,6 @@ public class ArtifactRepositoryIndex
 
     private boolean addFile( ZipEntry entry )
     {
-        boolean isAdded = false;
-
         String name = entry.getName();
         int idx = name.lastIndexOf( '/' );
         if ( idx >= 0 )
@@ -272,6 +272,8 @@ public class ArtifactRepositoryIndex
             name = name.substring( idx + 1 );
         }
 
+        boolean isAdded = false;
+
         if ( files.indexOf( name + "\n" ) < 0 )
         {
             files.append( name ).append( "\n" );
index ba09036313a83467287f71e34b5c451b8993bde6..4b52e12823820fba90e560dd002a2cda75bd4ba5 100644 (file)
@@ -35,7 +35,7 @@ public class ArtifactRepositoryIndexAnalyzer
     /**
      * constructor to for this analyzer
      *
-     * @character defaultAnalyzer the analyzer to use as default for the general fields of the artifact indeces
+     * @param defaultAnalyzer the analyzer to use as default for the general fields of the artifact indeces
      */
     public ArtifactRepositoryIndexAnalyzer( Analyzer defaultAnalyzer )
     {
@@ -45,9 +45,9 @@ public class ArtifactRepositoryIndexAnalyzer
     /**
      * Method called by lucence during indexing operations
      *
+     * @param fieldName the field name that the lucene object is currently processing
+     * @param reader    a Reader object to the index stream
      * @return an analyzer to specific to the field name or the default analyzer if none is present
-     * @character fieldName the field name that the lucene object is currently processing
-     * @character reader a Reader object to the index stream
      */
     public TokenStream tokenStream( String fieldName, Reader reader )
     {
@@ -68,15 +68,15 @@ public class ArtifactRepositoryIndexAnalyzer
     /**
      * Class used to tokenize an artifact's version.
      */
-    private class VersionTokenizer
+    private static class VersionTokenizer
         extends CharTokenizer
     {
         /**
          * Constructor with the required reader to the index stream
          *
-         * @reader the Reader object of the index stream
+         * @param reader the Reader object of the index stream
          */
-        public VersionTokenizer( Reader reader )
+        VersionTokenizer( Reader reader )
         {
             super( reader );
         }
@@ -89,19 +89,7 @@ public class ArtifactRepositoryIndexAnalyzer
          */
         protected boolean isTokenChar( char character )
         {
-            boolean token;
-
-            switch ( character )
-            {
-                case '.':
-                case '-':
-                    token = false;
-                    break;
-                default:
-                    token = true;
-            }
-
-            return token;
+            return character != '.' && character != '-';
         }
     }
 }
index c03548ae2b3381fe15a96e728ab0255fb08e6242..8760e16a9823154c3d949e248cfe040691fb00ed 100644 (file)
@@ -17,6 +17,7 @@ package org.apache.maven.repository.indexing;
  */
 
 import org.apache.lucene.document.Document;
+import org.apache.lucene.queryParser.ParseException;
 import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.search.Hits;
 import org.apache.lucene.search.IndexSearcher;
@@ -25,6 +26,7 @@ import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -44,8 +46,6 @@ public class ArtifactRepositoryIndexSearcher
 
     private static final String VERSION = "version";
 
-    private IndexSearcher searcher;
-
     private ArtifactRepository repository;
 
     private ArtifactFactory factory;
@@ -59,16 +59,16 @@ public class ArtifactRepositoryIndexSearcher
      * @return
      */
     public List search( RepositoryIndex index, String queryString, String searchField )
+        throws RepositoryIndexSearchException
     {
         List artifactList = new ArrayList();
 
         try
         {
-            searcher = new IndexSearcher( index.getIndexPath() );
+            IndexSearcher searcher = new IndexSearcher( index.getIndexPath() );
             QueryParser parser = new QueryParser( searchField, index.getAnalyzer() );
             Query qry = parser.parse( queryString );
             Hits hits = searcher.search( qry );
-            //System.out.println("HITS SIZE --> " + hits.length());
 
             for ( int i = 0; i < hits.length(); i++ )
             {
@@ -84,9 +84,13 @@ public class ArtifactRepositoryIndexSearcher
                 artifactList.add( artifact );
             }
         }
-        catch ( Exception e )
+        catch ( IOException e )
+        {
+            throw new RepositoryIndexSearchException( e.getMessage(), e );
+        }
+        catch ( ParseException e )
         {
-            e.printStackTrace();
+            throw new RepositoryIndexSearchException( "Error parsing query: " + e.getMessage() );
         }
 
         return artifactList;
diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearchException.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearchException.java
new file mode 100644 (file)
index 0000000..f303536
--- /dev/null
@@ -0,0 +1,39 @@
+package org.apache.maven.repository.indexing;
+
+/*
+ * 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.
+ */
+
+/**
+ * @author Brett Porter
+ */
+public class RepositoryIndexSearchException
+    extends Exception
+{
+    public RepositoryIndexSearchException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+    public RepositoryIndexSearchException( Throwable cause )
+    {
+        super( cause );
+    }
+
+    public RepositoryIndexSearchException( String message )
+    {
+        super( message );
+    }
+}
index 81ca498d5bb54754eb5035da44f9cae46475e7ad..ac592818dc05251806e8ff648766070e6cd9f3a0 100644 (file)
@@ -23,7 +23,6 @@ import java.util.List;
  */
 public interface RepositoryIndexSearcher
 {
-
     String ROLE = RepositoryIndexSearcher.class.getName();
 
     /**
@@ -33,7 +32,7 @@ public interface RepositoryIndexSearcher
      * @param index
      * @param queryString
      * @param searchField
-     * @return
      */
-    public List search( RepositoryIndex index, String queryString, String searchField );
+    List search( RepositoryIndex index, String queryString, String searchField )
+        throws RepositoryIndexSearchException;
 }
index 742545a9452810e647f32d7d443edf2a5abb49fc..dc7f8a20870e7558abd14309d9e90f4f35cc5332 100644 (file)
@@ -58,8 +58,6 @@ public class ArtifactRepositoryIndexingTest
 
     protected String indexPath;
 
-    private RepositoryIndexSearcher repoSearcher;
-
     protected void setUp()
         throws Exception
     {
@@ -176,7 +174,8 @@ public class ArtifactRepositoryIndexingTest
         indexer.open( getTestPath( "src/test/index" ) );
 
         //repoSearcher = new ArtifactRepositoryIndexSearcher( indexer, indexPath, repository );
-        repoSearcher = (RepositoryIndexSearcher) lookup( RepositoryIndexSearcher.ROLE, "artifact" );
+        RepositoryIndexSearcher repoSearcher =
+            (RepositoryIndexSearcher) lookup( RepositoryIndexSearcher.ROLE, "artifact" );
 
         List artifacts = repoSearcher.search( indexer, "test", GROUPID );
         assertEquals( 1, artifacts.size() );
index 4dfb932972ed1b6f51ac977488f30757876bec47..a4847649147680e6d06b80c404d07120a74d7a3e 100644 (file)
@@ -27,32 +27,34 @@ import java.util.Iterator;
  * The initial implementation of this will just need to be a mock implementation in src/test/java, used to track the
  * failures and successes for checking assertions. Later, implementations will be made to present reports on the
  * web interface, send them via mail, and so on.
+ *
+ * @todo i18n
  */
 public interface ArtifactReporter
 {
     String ROLE = ArtifactReporter.class.getName();
 
-    public static String NULL_MODEL = "Provided model was null";
+    String NULL_MODEL = "Provided model was null";
 
-    public static String NULL_ARTIFACT = "Provided artifact was null";
+    String NULL_ARTIFACT = "Provided artifact was null";
 
-    public static String EMPTY_GROUP_ID = "Group id was empty or null";
+    String EMPTY_GROUP_ID = "Group id was empty or null";
 
-    public static String EMPTY_ARTIFACT_ID = "Artifact id was empty or null";
+    String EMPTY_ARTIFACT_ID = "Artifact id was empty or null";
 
-    public static String EMPTY_VERSION = "Version was empty or null";
+    String EMPTY_VERSION = "Version was empty or null";
 
-    public static String EMPTY_DEPENDENCY_GROUP_ID = "Group id was empty or null";
+    String EMPTY_DEPENDENCY_GROUP_ID = "Group id was empty or null";
 
-    public static String EMPTY_DEPENDENCY_ARTIFACT_ID = "Artifact id was empty or null";
+    String EMPTY_DEPENDENCY_ARTIFACT_ID = "Artifact id was empty or null";
 
-    public static String EMPTY_DEPENDENCY_VERSION = "Version was empty or null";
+    String EMPTY_DEPENDENCY_VERSION = "Version was empty or null";
 
-    public static String NO_DEPENDENCIES = "Artifact has no dependencies";
+    String NO_DEPENDENCIES = "Artifact has no dependencies";
 
-    public static String ARTIFACT_NOT_FOUND = "Artifact does not exist in the repository";
+    String ARTIFACT_NOT_FOUND = "Artifact does not exist in the repository";
 
-    public static String DEPENDENCY_NOT_FOUND = "Artifact's dependency does not exist in the repository";
+    String DEPENDENCY_NOT_FOUND = "Artifact's dependency does not exist in the repository";
 
     void addFailure( Artifact artifact, String reason );
 
index 645468d44fce75a1ea532a762689bf67e838eb67..1108af25d4d3e27911f3aa0619e0e22f19580bc9 100644 (file)
@@ -32,7 +32,7 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-
+import java.util.Map;
 
 /**
  * This class will report on bad metadata files.  These include invalid version declarations and incomplete version
@@ -128,7 +128,7 @@ public class BadMetadataReportProcessor
             new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( metadata ) ).getParentFile();
         List pluginDirs = getArtifactIdFiles( metadataDir );
 
-        HashMap prefixes = new HashMap();
+        Map prefixes = new HashMap();
         for ( Iterator plugins = metadata.getMetadata().getPlugins().iterator(); plugins.hasNext(); )
         {
             Plugin plugin = (Plugin) plugins.next();
index bb748b75d9056941526a237756dd87d3b1fa1d1f..45df43027dc440037e0d1e1303e7231abd45094d 100644 (file)
@@ -28,13 +28,13 @@ public class Cache
 
     private DblLinkedList mostRecent;
 
-    private double cacheHitRatio = 0;
+    private double cacheHitRatio;
 
-    private long cacheMaxSize = 0;
+    private long cacheMaxSize;
 
-    private long cacheHits = 0;
+    private long cacheHits;
 
-    private long cacheMiss = 0;
+    private long cacheMiss;
 
     /**
      * Caches all data and expires only the oldest data when the specified cache hit rate is reached.
@@ -68,7 +68,7 @@ public class Cache
      * Check if the specified key is already mapped to an object.
      *
      * @param key the key used to map the cached object
-     * @returns true if the cache contains an object associated with the given key
+     * @return true if the cache contains an object associated with the given key
      */
     public boolean containsKey( Object key )
     {
@@ -90,7 +90,7 @@ public class Cache
      * Check for a cached object and return it if it exists. Returns null when the keyed object is not found
      *
      * @param key the key used to map the cached object
-     * @returns the object mapped to the given key, or null if no cache object is mapped to the given key
+     * @return the object mapped to the given key, or null if no cache object is mapped to the given key
      */
     public Object get( Object key )
     {
@@ -102,7 +102,7 @@ public class Cache
 
             makeMostRecent( cacheEntry );
 
-            retValue = cacheEntry.cacheValue;
+            retValue = cacheEntry.getCacheValue();
 
             cacheHits++;
         }
@@ -140,11 +140,11 @@ public class Cache
     /**
      * Compute for the efficiency of this cache.
      *
-     * @returns the ratio of cache hits to the cache misses to queries for cache objects
+     * @return the ratio of cache hits to the cache misses to queries for cache objects
      */
     public double getHitRate()
     {
-        return ( cacheHits == 0 && cacheMiss == 0 ) ? 0 : ( (double) cacheHits ) / (double) ( cacheHits + cacheMiss );
+        return cacheHits == 0 && cacheMiss == 0 ? 0 : (double) cacheHits / (double) ( cacheHits + cacheMiss );
     }
 
     /**
@@ -171,32 +171,39 @@ public class Cache
 
     private void makeMostRecent( DblLinkedList list )
     {
-        if ( mostRecent != list )
+        if ( mostRecent != null )
         {
-            removeFromLinks( list );
-
-            if ( mostRecent != null )
+            if ( !mostRecent.equals( list ) )
             {
-                list.next = mostRecent;
-                mostRecent.prev = list;
+                removeFromLinks( list );
+
+                list.setNext( mostRecent );
+                mostRecent.setPrev( list );
+
+                mostRecent = list;
             }
+        }
+        else if ( list != null )
+        {
+            removeFromLinks( list );
+
             mostRecent = list;
         }
     }
 
     private void removeFromLinks( DblLinkedList list )
     {
-        if ( list.prev != null )
+        if ( list.getPrev() != null )
         {
-            list.prev.next = list.next;
+            list.getPrev().setNext( list.getNext() );
         }
-        if ( list.next != null )
+        if ( list.getNext() != null )
         {
-            list.next.prev = list.prev;
+            list.getNext().setPrev( list.getPrev() );
         }
 
-        list.prev = null;
-        list.next = null;
+        list.setPrev( null );
+        list.setNext( null );
     }
 
     private void manageCache()
@@ -231,7 +238,7 @@ public class Cache
     private void trimCache()
     {
         DblLinkedList leastRecent = getLeastRecent();
-        cache.remove( leastRecent.cacheKey );
+        cache.remove( leastRecent.getCacheKey() );
         if ( cache.size() > 0 )
         {
             removeFromLinks( leastRecent );
@@ -246,28 +253,61 @@ public class Cache
     {
         DblLinkedList trail = mostRecent;
 
-        while ( trail.next != null )
+        while ( trail.getNext() != null )
         {
-            trail = trail.next;
+            trail = trail.getNext();
         }
 
         return trail;
     }
 
-    private class DblLinkedList
+    /**
+     * @todo replace with standard collection (commons-collections?)
+     */
+    private static class DblLinkedList
     {
-        Object cacheKey;
+        private Object cacheKey;
 
-        Object cacheValue;
+        private Object cacheValue;
 
-        DblLinkedList prev;
+        private DblLinkedList prev;
 
-        DblLinkedList next;
+        private DblLinkedList next;
 
-        public DblLinkedList( Object key, Object value )
+        DblLinkedList( Object key, Object value )
         {
             this.cacheKey = key;
             this.cacheValue = value;
         }
+
+        public DblLinkedList getNext()
+        {
+            return next;
+        }
+
+        public Object getCacheValue()
+        {
+            return cacheValue;
+        }
+
+        public void setPrev( DblLinkedList prev )
+        {
+            this.prev = prev;
+        }
+
+        public void setNext( DblLinkedList next )
+        {
+            this.next = next;
+        }
+
+        public Object getCacheKey()
+        {
+            return cacheKey;
+        }
+
+        public DblLinkedList getPrev()
+        {
+            return prev;
+        }
     }
 }
index 73e77432023f9b9848674a9c4b67c4c3b1d87e46..d52453e91815d02affad2295d51f99c607b7779d 100644 (file)
@@ -30,12 +30,14 @@ public class CachedRepositoryQueryLayer
 {
     private Cache cache;
 
+    private static final double CACHE_HIT_RATIO = 0.5;
+
 
     public CachedRepositoryQueryLayer( ArtifactRepository repository )
     {
         this.repository = repository;
 
-        cache = new Cache( 0.5 );
+        cache = new Cache( CACHE_HIT_RATIO );
     }
 
     public double getCacheHitRate()
index 7e2a5e5c14ee19de40d9aa3389143edd98a3795a..7b45ac7c763fc32c90ddb102cd59e7772e072811 100644 (file)
@@ -38,14 +38,16 @@ import java.security.NoSuchAlgorithmException;
 public class ChecksumArtifactReporter
     implements ArtifactReportProcessor, MetadataReportProcessor
 {
-    String ROLE = ChecksumArtifactReporter.class.getName();
-
     protected InputStream md5InputStream;
 
     protected InputStream sha1InputStream;
 
     private boolean isLocal = true;
 
+    private static final int BYTE_MASK = 0xFF;
+
+    private static final int CHECKSUM_BUFFER_SIZE = 256;
+
     /**
      * Validate the checksum of the specified artifact.
      *
@@ -53,16 +55,12 @@ public class ChecksumArtifactReporter
      * @param artifact
      * @param reporter
      * @param repository
+     * @todo fix repo paths
      */
     public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
                                  ArtifactRepository repository )
     {
-        //System.out.println( " " );
-        //System.out
-        //   .println( "===================================== +++++  PROCESS ARTIFACT +++++ ====================================" );
-
-        String artifactUrl = "";
-        String repositoryUrl = "";
+        String repositoryUrl;
 
         if ( !"file".equals( repository.getProtocol() ) )
         {
@@ -74,7 +72,7 @@ public class ChecksumArtifactReporter
             repositoryUrl = repository.getBasedir();
         }
 
-        artifactUrl = repositoryUrl + artifact.getGroupId() + "/" + artifact.getArtifactId() + "/" +
+        String artifactUrl = repositoryUrl + artifact.getGroupId() + "/" + artifact.getArtifactId() + "/" +
             artifact.getBaseVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "." +
             artifact.getType();
 
@@ -118,14 +116,13 @@ 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 )
     {
-        // System.out.println( " " );
-        // System.out
-        //   .println( "====================================== +++++  PROCESS METADATA +++++ ==============================" );
-
-        String metadataUrl = "", repositoryUrl = "", filename = "";
+        String repositoryUrl;
+        String filename;
         if ( !"file".equals( repository.getProtocol() ) )
         {
             isLocal = false;
@@ -137,14 +134,15 @@ public class ChecksumArtifactReporter
             repositoryUrl = repository.getBasedir() + "/";
             filename = metadata.getLocalFilename( repository );
         }
+        String metadataUrl;
 
-        if ( metadata.storedInArtifactVersionDirectory() == true && metadata.storedInGroupDirectory() == false )
+        if ( metadata.storedInArtifactVersionDirectory() && !metadata.storedInGroupDirectory() )
         {
             //version metadata
             metadataUrl = repositoryUrl + metadata.getGroupId() + "/" + metadata.getArtifactId() + "/" +
                 metadata.getBaseVersion() + "/";
         }
-        else if ( metadata.storedInArtifactVersionDirectory() == false && metadata.storedInGroupDirectory() == true )
+        else if ( !metadata.storedInArtifactVersionDirectory() && metadata.storedInGroupDirectory() )
         {
             //group metadata
             metadataUrl = repositoryUrl + metadata.getGroupId() + "/";
@@ -200,7 +198,7 @@ public class ChecksumArtifactReporter
      * 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
+     * @todo fix this erroneous object state
      */
     public boolean getMD5File( String filename )
     {
@@ -229,7 +227,7 @@ public class ChecksumArtifactReporter
      * 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
+     * @todo fix this erroneous object state
      */
     public boolean getSHA1File( String filename )
     {
@@ -258,12 +256,10 @@ public class ChecksumArtifactReporter
      *
      * @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
         {
@@ -273,12 +269,11 @@ public class ChecksumArtifactReporter
             {
                 ext = ".sha1";
             }
-            chk1 = createChecksum( fileUrl, algo );
+            byte[] chk1 = createChecksum( fileUrl, algo );
             if ( chk1 != null )
             {
 
                 //read the md5 file
-                chk2 = new byte[chk1.length];
                 File f = new File( fileUrl + ext );
                 InputStream is = null;
 
@@ -299,28 +294,15 @@ public class ChecksumArtifactReporter
                 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.toUpperCase().equals( byteArrayToHexStr( chk1 ).toUpperCase() ) )
-                {
-                    valid = true;
-                }
-                else
-                {
-                    valid = false;
-                }
+                valid = chk2Str.toUpperCase().equals( byteArrayToHexStr( chk1 ).toUpperCase() );
             }
-            return valid;
-
         }
         catch ( Exception e )
         {
-            //e.printStackTrace();
-            return valid;
+            // TODO: fix this error handling
         }
+        return valid;
     }
 
     /**
@@ -332,13 +314,12 @@ public class ChecksumArtifactReporter
      * @throws FileNotFoundException
      * @throws NoSuchAlgorithmException
      * @throws IOException
+     * @todo move to utility class
      */
     protected byte[] createChecksum( String filename, String algo )
         throws FileNotFoundException, NoSuchAlgorithmException, IOException
     {
-
-        InputStream fis = null;
-        byte[] buffer = new byte[1024];
+        InputStream fis;
 
         //check whether file is located locally or remotely
         if ( isLocal )
@@ -350,6 +331,7 @@ public class ChecksumArtifactReporter
             URL url = new URL( filename );
             fis = url.openStream();
         }
+        byte[] buffer = new byte[CHECKSUM_BUFFER_SIZE];
 
         MessageDigest complete = MessageDigest.getInstance( algo );
         int numRead;
@@ -372,9 +354,9 @@ public class ChecksumArtifactReporter
      * the bytes as two hex characters.
      *
      * @param data
-     * @return
+     * @todo move to utilities
      */
-    public String byteArrayToHexStr( byte[] data )
+    public static String byteArrayToHexStr( byte[] data )
     {
         String output = "";
         String tempStr = "";
@@ -383,7 +365,7 @@ public class ChecksumArtifactReporter
         for ( int cnt = 0; cnt < data.length; cnt++ )
         {
             //Deposit a byte into the 8 lsb of an int.
-            tempInt = data[cnt] & 0xFF;
+            tempInt = data[cnt] & BYTE_MASK;
 
             //Get hex representation of the int as a string.
             tempStr = Integer.toHexString( tempInt );
index 8af45d652c322616b855cad622a4f93966f4b020..6eece5fbbc39e2d24b475a1fbaf5da4f10cc84c7 100644 (file)
@@ -31,7 +31,7 @@ import java.util.List;
 public class DefaultArtifactReportProcessor
     implements ArtifactReportProcessor
 {
-    private final static String EMPTY_STRING = "";
+    private static final String EMPTY_STRING = "";
 
     // plexus components
     private ArtifactFactory artifactFactory;
index a0c167fea5296ef878007af56db529b3105b6bbb..2769dc59a12215ad1ff2b0dfd5ab0cd6557f7239 100644 (file)
@@ -51,9 +51,9 @@ public class DefaultArtifactReporter
         artifactSuccesses.add( new ArtifactResult( artifact ) );
     }
 
-    public void addWarning( Artifact artifact, String reason )
+    public void addWarning( Artifact artifact, String message )
     {
-        artifactWarnings.add( new ArtifactResult( artifact, reason ) );
+        artifactWarnings.add( new ArtifactResult( artifact, message ) );
     }
 
     public void addFailure( RepositoryMetadata metadata, String reason )
@@ -66,9 +66,9 @@ public class DefaultArtifactReporter
         metadataSuccesses.add( new RepositoryMetadataResult( metadata ) );
     }
 
-    public void addWarning( RepositoryMetadata metadata, String reason )
+    public void addWarning( RepositoryMetadata metadata, String message )
     {
-        metadataWarnings.add( new RepositoryMetadataResult( metadata, reason ) );
+        metadataWarnings.add( new RepositoryMetadataResult( metadata, message ) );
     }
 
     public Iterator getArtifactFailureIterator()
index 75eecd9c305cfeb272434c398fd80dd6a0f4b1af..834a70d19cbb6198d1fba9b6426a48ce58e557b6 100644 (file)
@@ -43,14 +43,14 @@ public class InvalidPomArtifactReportProcessor
      * @param artifact   The pom xml file to be validated, passed as an artifact object.
      * @param reporter   The artifact reporter object.
      * @param repository the repository where the artifact is located.
+     * @todo fix repo paths
      */
     public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
                                  ArtifactRepository repository )
     {
-        InputStream is = null;
-
         if ( "pom".equals( artifact.getType().toLowerCase() ) )
         {
+            InputStream is = null;
 
             if ( "file".equals( repository.getProtocol() ) )
             {
@@ -90,7 +90,7 @@ public class InvalidPomArtifactReportProcessor
 
             try
             {
-                Model pomModel = pomReader.read( reader );
+                pomReader.read( reader );
                 reporter.addSuccess( artifact );
             }
             catch ( XmlPullParserException xe )
index 942b052fe5859e93b564c1e5539383dd3486907c..bb411701547ff8bfbd47f6ccc012c4fbd89dddac 100644 (file)
@@ -28,9 +28,9 @@ public interface RepositoryQueryLayer
 {
     String ROLE = RepositoryQueryLayer.class.getName();
 
-    public final static boolean ARTIFACT_FOUND = true;
+    boolean ARTIFACT_FOUND = true;
 
-    public final static boolean ARTIFACT_NOT_FOUND = false;
+    boolean ARTIFACT_NOT_FOUND = false;
 
     boolean containsArtifact( Artifact artifact );
 
diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java
deleted file mode 100644 (file)
index c05bf71..0000000
+++ /dev/null
@@ -1,452 +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.codehaus.plexus.util.FileUtils;
-
-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;
-
-/**
- * This class creates the artifact and metadata files used for testing the ChecksumArtifactReporter.
- * It is extended by ChecksumArtifactReporterTest class.
- */
-public abstract class AbstractChecksumArtifactReporterTest
-    extends AbstractRepositoryReportsTestCase
-{
-    protected static final String[] validArtifactChecksumJars = {"validArtifact-1.0"};
-
-    protected static final String[] invalidArtifactChecksumJars = {"invalidArtifact-1.0"};
-
-    protected static final String metadataChecksumFilename = "maven-metadata-repository";
-
-    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 ( "VALID".equals( type ) )
-        {
-            for ( int i = 0; i < validArtifactChecksumJars.length; i++ )
-            {
-                written = writeChecksumFile( "checksumTest/", validArtifactChecksumJars[i], "jar", true );
-                if ( written == false )
-                {
-                    i = validArtifactChecksumJars.length;
-                }
-            }
-        }
-        else if ( "INVALID".equals( type ) )
-        {
-            for ( int i = 0; i < invalidArtifactChecksumJars.length; i++ )
-            {
-                written = writeChecksumFile( "checksumTest/", invalidArtifactChecksumJars[i], "jar", false );
-                if ( written == false )
-                {
-                    i = invalidArtifactChecksumJars.length;
-                }
-            }
-        }
-
-        return written;
-    }
-
-    /**
-     * Create checksum files for metadata.
-     *
-     * @param type The type of checksum to be created. (Valid or invalid)
-     * @return
-     */
-    protected boolean createMetadataFile( String type )
-    {
-        boolean written = true;
-
-        //loop through the valid artifact names..
-        if ( "VALID".equals( type ) )
-        {
-            writeMetadataFile( "checksumTest/validArtifact/1.0/", metadataChecksumFilename, "xml", true );
-            writeMetadataFile( "checksumTest/validArtifact/", metadataChecksumFilename, "xml", true );
-            writeMetadataFile( "checksumTest/", metadataChecksumFilename, "xml", true );
-
-        }
-        else if ( "INVALID".equals( type ) )
-        {
-            writeMetadataFile( "checksumTest/invalidArtifact/1.0/", metadataChecksumFilename, "xml", false );
-        }
-
-        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 )
-    {
-        //System.out.println( " " );
-        //System.out.println( "========================= ARTIFACT CHECKSUM ==================================" );
-
-        //Initialize variables for creating jar files
-        FileOutputStream f = null;
-        JarOutputStream out = null;
-        String repoUrl = super.repository.getBasedir();
-        try
-        {
-            String dirs = filename.replace( '-', '/' );
-            //create the group level directory of the artifact    
-            File dirFiles = new File( repoUrl + relativePath + dirs );
-
-            if ( dirFiles.mkdirs() )
-            {
-
-                // create a jar file
-                f = new FileOutputStream( repoUrl + relativePath + dirs + "/" + filename + "." + type );
-                out = new JarOutputStream( new BufferedOutputStream( f ) );
-
-                // jar sample.txt
-                String filename1 = repoUrl + 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( repoUrl + relativePath + dirs + "/" + filename + "." + type, "MD5" );
-                byte[] sha1chk = createChecksum( repoUrl + 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( repoUrl + 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( repoUrl + 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 metadata file 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 writeMetadataFile( String relativePath, String filename, String type, boolean isValid )
-    {
-        // System.out.println( " " );
-        // System.out.println( "========================= METADATA CHECKSUM ==================================" );
-        try
-        {
-            //create checksum for the metadata file..
-            String repoUrl = repository.getBasedir();
-            String url = repository.getBasedir() + "/" + filename + "." + type;
-
-            FileUtils.copyFile( new File( url ), new File( repoUrl + relativePath + filename + "." + type ) );
-
-            //Create md5 and sha-1 checksum files..
-            byte[] md5chk = createChecksum( repoUrl + relativePath + filename + "." + type, "MD5" );
-            byte[] sha1chk = createChecksum( repoUrl + relativePath + 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( repoUrl + relativePath + 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( repoUrl + relativePath + 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 )
-        {
-            e.printStackTrace();
-            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();
-    }
-
-    /**
-     * Delete the test directory created in the repository.
-     *
-     * @param dirname The directory to be deleted.
-     * @return
-     */
-    protected boolean deleteTestDirectory( File dir )
-    {
-        boolean b = false;
-
-        try
-        {
-            FileUtils.deleteDirectory( dir );
-            b = true;
-        }
-        catch ( IOException ioe )
-        {
-            ioe.printStackTrace();
-        }
-
-        return b;
-    }
-
-    private boolean deleteFile( String filename )
-    {
-        File f = new File( filename );
-        return f.delete();
-    }
-
-    /**
-     * @return
-     */
-    protected boolean deleteChecksumFiles( String type )
-    {
-
-        boolean b = true;
-
-        //delete valid checksum files of artifacts created
-        for ( int i = 0; i < validArtifactChecksumJars.length; i++ )
-        {
-            b = deleteFile( repository.getBasedir() + "checksumTest/" +
-                validArtifactChecksumJars[i].replace( '-', '/' ) + "/" + validArtifactChecksumJars[i] + "." + type +
-                ".md5" );
-            if ( b == false )
-            {
-                return b;
-            }
-
-            b = deleteFile( repository.getBasedir() + "checksumTest/" +
-                validArtifactChecksumJars[i].replace( '-', '/' ) + "/" + validArtifactChecksumJars[i] + "." + type +
-                ".sha1" );
-            if ( b == false )
-            {
-                return b;
-            }
-        }
-
-        //delete valid checksum files of metadata file
-        for ( int i = 0; i < validArtifactChecksumJars.length; i++ )
-        {
-            b = deleteFile( repository.getBasedir() + "checksumTest/" +
-                validArtifactChecksumJars[i].replace( '-', '/' ) + "/" + metadataChecksumFilename + ".xml.md5" );
-            if ( b == false )
-            {
-                return b;
-            }
-
-            b = deleteFile( repository.getBasedir() + "checksumTest/" +
-                validArtifactChecksumJars[i].replace( '-', '/' ) + "/" + metadataChecksumFilename + ".xml.sha1" );
-            if ( b == false )
-            {
-                return b;
-            }
-        }
-        return b;
-    }
-
-}
diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTestCase.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTestCase.java
new file mode 100644 (file)
index 0000000..b860c0d
--- /dev/null
@@ -0,0 +1,339 @@
+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.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+
+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;
+
+/**
+ * This class creates the artifact and metadata files used for testing the ChecksumArtifactReporter.
+ * It is extended by ChecksumArtifactReporterTest class.
+ */
+public abstract class AbstractChecksumArtifactReporterTestCase
+    extends AbstractRepositoryReportsTestCase
+{
+    protected static final String[] validArtifactChecksumJars = {"validArtifact-1.0"};
+
+    protected static final String[] invalidArtifactChecksumJars = {"invalidArtifact-1.0"};
+
+    protected static final String metadataChecksumFilename = "maven-metadata-repository";
+
+    private static final int CHECKSUM_BUFFER_SIZE = 256;
+
+    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.
+     */
+    protected void createChecksumFile( String type )
+        throws NoSuchAlgorithmException, IOException
+    {
+        //loop through the valid artifact names..
+        if ( "VALID".equals( type ) )
+        {
+            for ( int i = 0; i < validArtifactChecksumJars.length; i++ )
+            {
+                writeChecksumFile( "checksumTest/", validArtifactChecksumJars[i], "jar", true );
+            }
+        }
+        else if ( "INVALID".equals( type ) )
+        {
+            for ( int i = 0; i < invalidArtifactChecksumJars.length; i++ )
+            {
+                writeChecksumFile( "checksumTest/", invalidArtifactChecksumJars[i], "jar", false );
+            }
+        }
+    }
+
+    /**
+     * Create checksum files for metadata.
+     *
+     * @param type The type of checksum to be created. (Valid or invalid)
+     */
+    protected void createMetadataFile( String type )
+        throws NoSuchAlgorithmException, IOException
+    {
+        //loop through the valid artifact names..
+        if ( "VALID".equals( type ) )
+        {
+            writeMetadataFile( "checksumTest/validArtifact/1.0/", metadataChecksumFilename, "xml", true );
+            writeMetadataFile( "checksumTest/validArtifact/", metadataChecksumFilename, "xml", true );
+            writeMetadataFile( "checksumTest/", metadataChecksumFilename, "xml", true );
+        }
+        else if ( "INVALID".equals( type ) )
+        {
+            writeMetadataFile( "checksumTest/invalidArtifact/1.0/", metadataChecksumFilename, "xml", false );
+        }
+    }
+
+    /**
+     * 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.
+     */
+    private void writeChecksumFile( String relativePath, String filename, String type, boolean isValid )
+        throws IOException, NoSuchAlgorithmException
+    {
+        //Initialize variables for creating jar files
+        String repoUrl = repository.getBasedir();
+
+        String dirs = filename.replace( '-', '/' );
+        //create the group level directory of the artifact
+        File dirFiles = new File( repoUrl + relativePath + dirs );
+
+        if ( dirFiles.mkdirs() )
+        {
+
+            // create a jar file
+            FileOutputStream f = new FileOutputStream( repoUrl + relativePath + dirs + "/" + filename + "." + type );
+            JarOutputStream out = new JarOutputStream( new BufferedOutputStream( f ) );
+
+            // jar sample.txt
+            String filename1 = repoUrl + relativePath + dirs + "/sample.txt";
+            createSampleFile( filename1 );
+
+            BufferedReader in = new BufferedReader( new FileReader( filename1 ) );
+            out.putNextEntry( new JarEntry( filename1 ) );
+            IOUtil.copy( in, out );
+            in.close();
+            out.close();
+
+            //Create md5 and sha-1 checksum files..
+            byte[] md5chk = createChecksum( repoUrl + relativePath + dirs + "/" + filename + "." + type, "MD5" );
+            byte[] sha1chk = createChecksum( repoUrl + relativePath + dirs + "/" + filename + "." + type, "SHA-1" );
+
+            File file;
+
+            if ( md5chk != null )
+            {
+                file = new File( repoUrl + relativePath + dirs + "/" + filename + "." + type + ".md5" );
+                OutputStream os = new FileOutputStream( file );
+                OutputStreamWriter osw = new OutputStreamWriter( os );
+                if ( !isValid )
+                {
+                    osw.write( ChecksumArtifactReporter.byteArrayToHexStr( md5chk ) + "1" );
+                }
+                else
+                {
+                    osw.write( ChecksumArtifactReporter.byteArrayToHexStr( md5chk ) );
+                }
+                osw.close();
+            }
+
+            if ( sha1chk != null )
+            {
+                file = new File( repoUrl + relativePath + dirs + "/" + filename + "." + type + ".sha1" );
+                OutputStream os = new FileOutputStream( file );
+                OutputStreamWriter osw = new OutputStreamWriter( os );
+                if ( !isValid )
+                {
+                    osw.write( ChecksumArtifactReporter.byteArrayToHexStr( sha1chk ) + "2" );
+                }
+                else
+                {
+                    osw.write( ChecksumArtifactReporter.byteArrayToHexStr( sha1chk ) );
+                }
+                osw.close();
+            }
+        }
+    }
+
+    /**
+     * Create metadata file 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.
+     */
+    private void writeMetadataFile( String relativePath, String filename, String type, boolean isValid )
+        throws IOException, NoSuchAlgorithmException
+    {
+        //create checksum for the metadata file..
+        String repoUrl = repository.getBasedir();
+        String url = repository.getBasedir() + "/" + filename + "." + type;
+
+        FileUtils.copyFile( new File( url ), new File( repoUrl + relativePath + filename + "." + type ) );
+
+        //Create md5 and sha-1 checksum files..
+        byte[] md5chk = createChecksum( repoUrl + relativePath + filename + "." + type, "MD5" );
+        byte[] sha1chk = createChecksum( repoUrl + relativePath + filename + "." + type, "SHA-1" );
+
+        File file;
+
+        if ( md5chk != null )
+        {
+            file = new File( repoUrl + relativePath + filename + "." + type + ".md5" );
+            OutputStream os = new FileOutputStream( file );
+            OutputStreamWriter osw = new OutputStreamWriter( os );
+            if ( !isValid )
+            {
+                osw.write( ChecksumArtifactReporter.byteArrayToHexStr( md5chk ) + "1" );
+            }
+            else
+            {
+                osw.write( ChecksumArtifactReporter.byteArrayToHexStr( md5chk ) );
+            }
+            osw.close();
+        }
+
+        if ( sha1chk != null )
+        {
+            file = new File( repoUrl + relativePath + filename + "." + type + ".sha1" );
+            OutputStream os = new FileOutputStream( file );
+            OutputStreamWriter osw = new OutputStreamWriter( os );
+            if ( !isValid )
+            {
+                osw.write( ChecksumArtifactReporter.byteArrayToHexStr( sha1chk ) + "2" );
+            }
+            else
+            {
+                osw.write( ChecksumArtifactReporter.byteArrayToHexStr( sha1chk ) );
+            }
+            osw.close();
+        }
+    }
+
+    /**
+     * Create the sample file that will be included in the jar.
+     *
+     * @param filename
+     */
+    private void createSampleFile( String filename )
+        throws IOException
+    {
+        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();
+    }
+
+    /**
+     * Create a checksum from the specified metadata file.
+     *
+     * @throws FileNotFoundException
+     * @throws NoSuchAlgorithmException
+     * @throws IOException
+     */
+    private byte[] createChecksum( String filename, String algo )
+        throws FileNotFoundException, NoSuchAlgorithmException, IOException
+    {
+
+        // TODO: share with ArtifactRepositoryIndex.getChecksum(), ChecksumArtifactReporter.getChecksum()
+        InputStream fis = new FileInputStream( filename );
+        byte[] buffer = new byte[CHECKSUM_BUFFER_SIZE];
+
+        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();
+    }
+
+    /**
+     * Delete the test directory created in the repository.
+     *
+     * @param dir The directory to be deleted.
+     */
+    protected boolean deleteTestDirectory( File dir )
+    {
+        boolean b;
+
+        try
+        {
+            FileUtils.deleteDirectory( dir );
+            b = true;
+        }
+        catch ( IOException ioe )
+        {
+            b = false;
+        }
+
+        return b;
+    }
+
+    private void deleteFile( String filename )
+    {
+        File f = new File( filename );
+        f.delete();
+    }
+
+    protected void deleteChecksumFiles( String type )
+    {
+        //delete valid checksum files of artifacts created
+        for ( int i = 0; i < validArtifactChecksumJars.length; i++ )
+        {
+            deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) +
+                "/" + validArtifactChecksumJars[i] + "." + type + ".md5" );
+
+            deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) +
+                "/" + validArtifactChecksumJars[i] + "." + type + ".sha1" );
+        }
+
+        //delete valid checksum files of metadata file
+        for ( int i = 0; i < validArtifactChecksumJars.length; i++ )
+        {
+            deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) +
+                "/" + metadataChecksumFilename + ".xml.md5" );
+
+            deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) +
+                "/" + metadataChecksumFilename + ".xml.sha1" );
+        }
+    }
+
+}
index cd6bd78698e6c6bfdb42c846bff39c7311fc6394..3cc5fb72d67a895fe5200dbbd5bda2b1946af225 100644 (file)
@@ -28,9 +28,9 @@ import java.util.Iterator;
 public class ArtifactReportProcessorTest
     extends AbstractRepositoryReportsTestCase
 {
-    private final static String EMPTY_STRING = "";
+    private static final String EMPTY_STRING = "";
 
-    private final static String VALID = "temp";
+    private static final String VALID = "temp";
 
     protected MockArtifactReporter reporter;
 
@@ -53,12 +53,12 @@ public class ArtifactReportProcessorTest
     public void testNullArtifact()
     {
         processor.processArtifact( model, null, reporter, null );
-        assertTrue( reporter.getSuccesses() == 0 );
-        assertTrue( reporter.getFailures() == 1 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 0, reporter.getSuccesses() );
+        assertEquals( 1, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
         Iterator failures = reporter.getArtifactFailureIterator();
         ArtifactResult result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.NULL_ARTIFACT.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.NULL_ARTIFACT, result.getReason() );
     }
 
     public void testNoProjectDescriptor()
@@ -68,12 +68,12 @@ public class ArtifactReportProcessorTest
         processor.setRepositoryQueryLayer( queryLayer );
         setRequiredElements( artifact, VALID, VALID, VALID );
         processor.processArtifact( null, artifact, reporter, null );
-        assertTrue( reporter.getSuccesses() == 1 );
-        assertTrue( reporter.getFailures() == 1 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 1, reporter.getSuccesses() );
+        assertEquals( 1, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
         Iterator failures = reporter.getArtifactFailureIterator();
         ArtifactResult result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.NULL_MODEL.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.NULL_MODEL, result.getReason() );
     }
 
     public void testArtifactFoundButNoDirectDependencies()
@@ -83,9 +83,9 @@ public class ArtifactReportProcessorTest
         processor.setRepositoryQueryLayer( queryLayer );
         setRequiredElements( artifact, VALID, VALID, VALID );
         processor.processArtifact( model, artifact, reporter, null );
-        assertTrue( reporter.getSuccesses() == 1 );
-        assertTrue( reporter.getFailures() == 0 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 1, reporter.getSuccesses() );
+        assertEquals( 0, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
     }
 
     public void testArtifactNotFound()
@@ -95,12 +95,12 @@ public class ArtifactReportProcessorTest
         processor.setRepositoryQueryLayer( queryLayer );
         setRequiredElements( artifact, VALID, VALID, VALID );
         processor.processArtifact( model, artifact, reporter, null );
-        assertTrue( reporter.getSuccesses() == 0 );
-        assertTrue( reporter.getFailures() == 1 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 0, reporter.getSuccesses() );
+        assertEquals( 1, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
         Iterator failures = reporter.getArtifactFailureIterator();
         ArtifactResult result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.ARTIFACT_NOT_FOUND.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.ARTIFACT_NOT_FOUND, result.getReason() );
     }
 
     public void testValidArtifactWithNullDependency()
@@ -119,9 +119,9 @@ public class ArtifactReportProcessorTest
 
         processor.setRepositoryQueryLayer( queryLayer );
         processor.processArtifact( model, artifact, reporter, null );
-        assertTrue( reporter.getSuccesses() == 2 );
-        assertTrue( reporter.getFailures() == 0 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 2, reporter.getSuccesses() );
+        assertEquals( 0, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
     }
 
     public void testValidArtifactWithValidSingleDependency()
@@ -140,9 +140,9 @@ public class ArtifactReportProcessorTest
 
         processor.setRepositoryQueryLayer( queryLayer );
         processor.processArtifact( model, artifact, reporter, null );
-        assertTrue( reporter.getSuccesses() == 2 );
-        assertTrue( reporter.getFailures() == 0 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 2, reporter.getSuccesses() );
+        assertEquals( 0, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
     }
 
     public void testValidArtifactWithValidMultipleDependencies()
@@ -169,9 +169,9 @@ public class ArtifactReportProcessorTest
         setRequiredElements( artifact, VALID, VALID, VALID );
         processor.setRepositoryQueryLayer( queryLayer );
         processor.processArtifact( model, artifact, reporter, null );
-        assertTrue( reporter.getSuccesses() == 6 );
-        assertTrue( reporter.getFailures() == 0 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 6, reporter.getSuccesses() );
+        assertEquals( 0, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
     }
 
     public void testValidArtifactWithAnInvalidDependency()
@@ -198,13 +198,13 @@ public class ArtifactReportProcessorTest
         setRequiredElements( artifact, VALID, VALID, VALID );
         processor.setRepositoryQueryLayer( queryLayer );
         processor.processArtifact( model, artifact, reporter, null );
-        assertTrue( reporter.getSuccesses() == 5 );
-        assertTrue( reporter.getFailures() == 1 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 5, reporter.getSuccesses() );
+        assertEquals( 1, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
 
         Iterator failures = reporter.getArtifactFailureIterator();
         ArtifactResult result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.DEPENDENCY_NOT_FOUND.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
     }
 
     public void testEmptyGroupId()
@@ -215,13 +215,13 @@ public class ArtifactReportProcessorTest
 
         setRequiredElements( artifact, EMPTY_STRING, VALID, VALID );
         processor.processArtifact( model, artifact, reporter, null );
-        assertTrue( reporter.getSuccesses() == 0 );
-        assertTrue( reporter.getFailures() == 1 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 0, reporter.getSuccesses() );
+        assertEquals( 1, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
 
         Iterator failures = reporter.getArtifactFailureIterator();
         ArtifactResult result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.EMPTY_GROUP_ID.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.EMPTY_GROUP_ID, result.getReason() );
     }
 
     public void testEmptyArtifactId()
@@ -232,13 +232,13 @@ public class ArtifactReportProcessorTest
 
         setRequiredElements( artifact, VALID, EMPTY_STRING, VALID );
         processor.processArtifact( model, artifact, reporter, null );
-        assertTrue( reporter.getSuccesses() == 0 );
-        assertTrue( reporter.getFailures() == 1 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 0, reporter.getSuccesses() );
+        assertEquals( 1, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
 
         Iterator failures = reporter.getArtifactFailureIterator();
         ArtifactResult result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.EMPTY_ARTIFACT_ID.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.EMPTY_ARTIFACT_ID, result.getReason() );
     }
 
     public void testEmptyVersion()
@@ -249,13 +249,13 @@ public class ArtifactReportProcessorTest
 
         setRequiredElements( artifact, VALID, VALID, EMPTY_STRING );
         processor.processArtifact( model, artifact, reporter, null );
-        assertTrue( reporter.getSuccesses() == 0 );
-        assertTrue( reporter.getFailures() == 1 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 0, reporter.getSuccesses() );
+        assertEquals( 1, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
 
         Iterator failures = reporter.getArtifactFailureIterator();
         ArtifactResult result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.EMPTY_VERSION.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.EMPTY_VERSION, result.getReason() );
     }
 
     public void testNullGroupId()
@@ -266,13 +266,13 @@ public class ArtifactReportProcessorTest
 
         setRequiredElements( artifact, null, VALID, VALID );
         processor.processArtifact( model, artifact, reporter, null );
-        assertTrue( reporter.getSuccesses() == 0 );
-        assertTrue( reporter.getFailures() == 1 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 0, reporter.getSuccesses() );
+        assertEquals( 1, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
 
         Iterator failures = reporter.getArtifactFailureIterator();
         ArtifactResult result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.EMPTY_GROUP_ID.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.EMPTY_GROUP_ID, result.getReason() );
     }
 
     public void testNullArtifactId()
@@ -283,13 +283,13 @@ public class ArtifactReportProcessorTest
 
         setRequiredElements( artifact, VALID, null, VALID );
         processor.processArtifact( model, artifact, reporter, null );
-        assertTrue( reporter.getSuccesses() == 0 );
-        assertTrue( reporter.getFailures() == 1 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 0, reporter.getSuccesses() );
+        assertEquals( 1, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
 
         Iterator failures = reporter.getArtifactFailureIterator();
         ArtifactResult result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.EMPTY_ARTIFACT_ID.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.EMPTY_ARTIFACT_ID, result.getReason() );
     }
 
     public void testNullVersion()
@@ -300,13 +300,13 @@ public class ArtifactReportProcessorTest
 
         setRequiredElements( artifact, VALID, VALID, null );
         processor.processArtifact( model, artifact, reporter, null );
-        assertTrue( reporter.getSuccesses() == 0 );
-        assertTrue( reporter.getFailures() == 1 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 0, reporter.getSuccesses() );
+        assertEquals( 1, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
 
         Iterator failures = reporter.getArtifactFailureIterator();
         ArtifactResult result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.EMPTY_VERSION.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.EMPTY_VERSION, result.getReason() );
     }
 
     public void testMultipleFailures()
@@ -317,17 +317,17 @@ public class ArtifactReportProcessorTest
 
         setRequiredElements( artifact, null, null, null );
         processor.processArtifact( model, artifact, reporter, null );
-        assertTrue( reporter.getSuccesses() == 0 );
-        assertTrue( reporter.getFailures() == 3 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 0, reporter.getSuccesses() );
+        assertEquals( 3, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
 
         Iterator failures = reporter.getArtifactFailureIterator();
         ArtifactResult result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.EMPTY_GROUP_ID.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.EMPTY_GROUP_ID, result.getReason() );
         result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.EMPTY_ARTIFACT_ID.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.EMPTY_ARTIFACT_ID, result.getReason() );
         result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.EMPTY_VERSION.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.EMPTY_VERSION, result.getReason() );
     }
 
     public void testValidArtifactWithInvalidDependencyGroupId()
@@ -346,13 +346,13 @@ public class ArtifactReportProcessorTest
 
         processor.setRepositoryQueryLayer( queryLayer );
         processor.processArtifact( model, artifact, reporter, null );
-        assertTrue( reporter.getSuccesses() == 1 );
-        assertTrue( reporter.getFailures() == 1 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 1, reporter.getSuccesses() );
+        assertEquals( 1, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
 
         Iterator failures = reporter.getArtifactFailureIterator();
         ArtifactResult result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID, result.getReason() );
     }
 
     public void testValidArtifactWithInvalidDependencyArtifactId()
@@ -371,13 +371,13 @@ public class ArtifactReportProcessorTest
 
         processor.setRepositoryQueryLayer( queryLayer );
         processor.processArtifact( model, artifact, reporter, null );
-        assertTrue( reporter.getSuccesses() == 1 );
-        assertTrue( reporter.getFailures() == 1 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 1, reporter.getSuccesses() );
+        assertEquals( 1, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
 
         Iterator failures = reporter.getArtifactFailureIterator();
         ArtifactResult result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID, result.getReason() );
     }
 
     public void testValidArtifactWithInvalidDependencyVersion()
@@ -396,13 +396,13 @@ public class ArtifactReportProcessorTest
 
         processor.setRepositoryQueryLayer( queryLayer );
         processor.processArtifact( model, artifact, reporter, null );
-        assertTrue( reporter.getSuccesses() == 1 );
-        assertTrue( reporter.getFailures() == 1 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 1, reporter.getSuccesses() );
+        assertEquals( 1, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
 
         Iterator failures = reporter.getArtifactFailureIterator();
         ArtifactResult result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.EMPTY_DEPENDENCY_VERSION.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_VERSION, result.getReason() );
     }
 
     public void testValidArtifactWithInvalidDependencyRequiredElements()
@@ -421,17 +421,17 @@ public class ArtifactReportProcessorTest
 
         processor.setRepositoryQueryLayer( queryLayer );
         processor.processArtifact( model, artifact, reporter, null );
-        assertTrue( reporter.getSuccesses() == 1 );
-        assertTrue( reporter.getFailures() == 3 );
-        assertTrue( reporter.getWarnings() == 0 );
+        assertEquals( 1, reporter.getSuccesses() );
+        assertEquals( 3, reporter.getFailures() );
+        assertEquals( 0, reporter.getWarnings() );
 
         Iterator failures = reporter.getArtifactFailureIterator();
         ArtifactResult result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID, result.getReason() );
         result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID, result.getReason() );
         result = (ArtifactResult) failures.next();
-        assertTrue( ArtifactReporter.EMPTY_DEPENDENCY_VERSION.equals( result.getReason() ) );
+        assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_VERSION, result.getReason() );
     }
 
     protected void tearDown()
index 16698ffdf59078d9442b3764cda6e8683ee14cc0..b0239d336516f7775a79d3d9286ed79d8ceb161c 100644 (file)
@@ -26,9 +26,13 @@ public class CacheTest
 {
     private Cache cache;
 
+    private static final double CACHE_HIT_RATIO = 0.5;
+
+    private static final double CACHE_HIT_RATIO_THRESHOLD = 0.75;
+
     public void testCacheManagementBasedOnHitsRatio()
     {
-        cache = new Cache( 0.5 );
+        cache = new Cache( CACHE_HIT_RATIO );
         newCacheObjectTests();
 
         String key = "key";
@@ -38,7 +42,7 @@ public class CacheTest
             cache.put( key + ctr, value + ctr );
         }
 
-        while ( cache.getHitRate() < 0.75 )
+        while ( cache.getHitRate() < CACHE_HIT_RATIO_THRESHOLD )
         {
             cache.get( "key2" );
         }
@@ -65,7 +69,7 @@ public class CacheTest
 
     public void testCacheManagementBasedOnCacheSizeAndHitRate()
     {
-        cache = new Cache( 0.5, 9 );
+        cache = new Cache( CACHE_HIT_RATIO, 9 );
         newCacheObjectTests();
 
         String key = "key";
@@ -75,7 +79,7 @@ public class CacheTest
             cache.put( key + ctr, value + ctr );
         }
 
-        while ( cache.getHitRate() < 0.5 )
+        while ( cache.getHitRate() < CACHE_HIT_RATIO )
         {
             cache.get( "key3" );
         }
@@ -83,7 +87,7 @@ public class CacheTest
         cache.put( "key10", "value10" );
         assertNull( "first key must be expired", cache.get( "key1" ) );
 
-        while ( cache.getHitRate() >= 0.5 )
+        while ( cache.getHitRate() >= CACHE_HIT_RATIO )
         {
             cache.get( "key11" );
         }
@@ -100,7 +104,7 @@ public class CacheTest
 
     public void testCacheOnRedundantData()
     {
-        cache = new Cache( 0.5, 9 );
+        cache = new Cache( CACHE_HIT_RATIO, 9 );
         newCacheObjectTests();
 
         String key = "key";
@@ -129,7 +133,7 @@ public class CacheTest
         assertEquals( (double) 1, cache.getHitRate(), 0 );
         assertEquals( "check cache size", 1, cache.size() );
         assertNull( "check cache miss", cache.get( "none" ) );
-        assertEquals( (double) 0.5, cache.getHitRate(), 0 );
+        assertEquals( CACHE_HIT_RATIO, cache.getHitRate(), 0 );
         cache.flush();
         assertNull( "check flushed object", cache.get( "key" ) );
         assertEquals( (double) 0, cache.getHitRate(), 0 );
index de18378a77740424d93d81af7f6a220f73af8b6a..13ab29f963df239d30f517d9dd3bab9736cdf7e8 100644 (file)
@@ -22,6 +22,9 @@ package org.apache.maven.repository.reporting;
 public class CachedRepositoryQueryLayerTest
     extends AbstractRepositoryQueryLayerTest
 {
+    // TODO: share
+    private static final double CACHE_HIT_RATIO = 0.5;
+
     protected void setUp()
         throws Exception
     {
@@ -35,7 +38,7 @@ public class CachedRepositoryQueryLayerTest
         testContainsArtifactTrue();
         assertEquals( 0, queryLayer.getCacheHitRate(), 0 );
         testContainsArtifactTrue();
-        assertEquals( 0.50, queryLayer.getCacheHitRate(), 0 );
+        assertEquals( CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 );
     }
 
     public void testUseMetadataCache()
@@ -44,7 +47,7 @@ public class CachedRepositoryQueryLayerTest
         testArtifactVersionsTrue();
         assertEquals( 0, queryLayer.getCacheHitRate(), 0 );
         testArtifactVersionsTrue();
-        assertEquals( 0.50, queryLayer.getCacheHitRate(), 0 );
+        assertEquals( CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 );
     }
 
     public void testUseFileCacheOnSnapshot()
@@ -52,6 +55,6 @@ public class CachedRepositoryQueryLayerTest
         testContainsSnapshotArtifactTrue();
         assertEquals( 0, queryLayer.getCacheHitRate(), 0 );
         testContainsSnapshotArtifactTrue();
-        assertEquals( 0.50, queryLayer.getCacheHitRate(), 0 );
+        assertEquals( CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 );
     }
 }
index 6225dc05ddc068a5591d0a193abe5701e9a04249..1e2f2a8da14382cc2562a91d361c9aa0a3767514 100644 (file)
@@ -27,14 +27,16 @@ import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryM
 import org.apache.maven.artifact.versioning.VersionRange;
 
 import java.io.File;
+import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
 import java.util.Iterator;
 
 /**
  * This class tests the ChecksumArtifactReporter.
- * It extends the AbstractChecksumArtifactReporterTest class.
+ * It extends the AbstractChecksumArtifactReporterTestCase class.
  */
 public class ChecksumArtifactReporterTest
-    extends AbstractChecksumArtifactReporterTest
+    extends AbstractChecksumArtifactReporterTestCase
 {
     private ArtifactReportProcessor artifactReportProcessor;
 
@@ -42,11 +44,6 @@ public class ChecksumArtifactReporterTest
 
     private MetadataReportProcessor metadataReportProcessor;
 
-    public ChecksumArtifactReporterTest()
-    {
-
-    }
-
     public void setUp()
         throws Exception
     {
@@ -55,74 +52,37 @@ public class ChecksumArtifactReporterTest
         metadataReportProcessor = (MetadataReportProcessor) lookup( MetadataReportProcessor.ROLE, "checksum-metadata" );
     }
 
-    public void tearDown()
-        throws Exception
-    {
-        super.tearDown();
-    }
-
-    /**
-     * Test creation of artifact with checksum files.
-     */
-    public void testCreateChecksumFile()
-    {
-        assertTrue( createChecksumFile( "VALID" ) );
-        assertTrue( createChecksumFile( "INVALID" ) );
-    }
-
-    /**
-     * Test creation of metadata file together with its checksums.
-     */
-    public void testCreateMetadataFile()
-    {
-        assertTrue( createMetadataFile( "VALID" ) );
-        assertTrue( createMetadataFile( "INVALID" ) );
-    }
-
     /**
      * Test the ChecksumArtifactReporter when the checksum files are valid.
      */
     public void testChecksumArtifactReporterSuccess()
+        throws ReportProcessorException, NoSuchAlgorithmException, IOException
     {
-        try
-        {
-            ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
-            VersionRange version = VersionRange.createFromVersion( "1.0" );
-            Artifact artifact =
-                new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler );
+        createChecksumFile( "VALID" );
+        createChecksumFile( "INVALID" );
 
-            artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
-            assertTrue( reporter.getSuccesses() == 2 );
-            //System.out.println( "1 - SUCCESS ---> " + reporter.getSuccesses() );
+        ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
+        VersionRange version = VersionRange.createFromVersion( "1.0" );
+        Artifact artifact =
+            new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler );
 
-        }
-        catch ( Exception e )
-        {
-            e.printStackTrace();
-        }
+        artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
+        assertEquals( 2, reporter.getSuccesses() );
     }
 
     /**
      * Test the ChecksumArtifactReporter when the checksum files are invalid.
      */
     public void testChecksumArtifactReporterFailed()
+        throws ReportProcessorException
     {
+        ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
+        VersionRange version = VersionRange.createFromVersion( "1.0" );
+        Artifact artifact =
+            new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "", handler );
 
-        try
-        {
-            ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
-            VersionRange version = VersionRange.createFromVersion( "1.0" );
-            Artifact artifact =
-                new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "", handler );
-
-            artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
-            assertTrue( reporter.getFailures() == 2 );
-            //System.out.println( "2 - FAILURES ---> " + reporter.getFailures() );
-        }
-        catch ( Exception e )
-        {
-            e.printStackTrace();
-        }
+        artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
+        assertEquals( 2, reporter.getFailures() );
     }
 
     /**
@@ -130,36 +90,30 @@ public class ChecksumArtifactReporterTest
      * The reporter should report 2 success validation.
      */
     public void testChecksumMetadataReporterSuccess()
+        throws ReportProcessorException, NoSuchAlgorithmException, IOException
     {
+        createMetadataFile( "VALID" );
+        createMetadataFile( "INVALID" );
 
-        try
-        {
-            ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
-            VersionRange version = VersionRange.createFromVersion( "1.0" );
-            Artifact artifact =
-                new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler );
+        ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
+        VersionRange version = VersionRange.createFromVersion( "1.0" );
+        Artifact artifact =
+            new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler );
 
-            //Version level metadata
-            RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
-            metadataReportProcessor.processMetadata( metadata, repository, reporter );
+        //Version level metadata
+        RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
+        metadataReportProcessor.processMetadata( metadata, repository, reporter );
 
-            //Artifact level metadata
-            metadata = new ArtifactRepositoryMetadata( artifact );
-            metadataReportProcessor.processMetadata( metadata, repository, reporter );
+        //Artifact level metadata
+        metadata = new ArtifactRepositoryMetadata( artifact );
+        metadataReportProcessor.processMetadata( metadata, repository, reporter );
 
-            //Group level metadata
-            metadata = new GroupRepositoryMetadata( "checksumTest" );
-            metadataReportProcessor.processMetadata( metadata, repository, reporter );
-
-            Iterator iter = reporter.getRepositoryMetadataSuccessIterator();
-            //System.out.println( "3 - META SUCCESS ---> " + iter.hasNext() );
-            assertTrue( "check if there is a success", iter.hasNext() );
+        //Group level metadata
+        metadata = new GroupRepositoryMetadata( "checksumTest" );
+        metadataReportProcessor.processMetadata( metadata, repository, reporter );
 
-        }
-        catch ( Exception e )
-        {
-            e.printStackTrace();
-        }
+        Iterator iter = reporter.getRepositoryMetadataSuccessIterator();
+        assertTrue( "check if there is a success", iter.hasNext() );
     }
 
     /**
@@ -167,29 +121,18 @@ public class ChecksumArtifactReporterTest
      * The reporter must report 2 failures.
      */
     public void testChecksumMetadataReporterFailure()
+        throws ReportProcessorException
     {
+        ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
+        VersionRange version = VersionRange.createFromVersion( "1.0" );
+        Artifact artifact =
+            new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "", handler );
 
-        try
-        {
-            ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
-            VersionRange version = VersionRange.createFromVersion( "1.0" );
-            Artifact artifact =
-                new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "", handler );
-
-            RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
-            metadataReportProcessor.processMetadata( metadata, repository, reporter );
-
-            //System.out.println("reporter.getFailures() ---> " + reporter.getFailures());
-
-            Iterator iter = reporter.getRepositoryMetadataFailureIterator();
-            //System.out.println( "4 - META FAILURE ---> " + iter.hasNext() );
-            assertTrue( "check if there is a failure", iter.hasNext() );
+        RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
+        metadataReportProcessor.processMetadata( metadata, repository, reporter );
 
-        }
-        catch ( Exception e )
-        {
-            e.printStackTrace();
-        }
+        Iterator iter = reporter.getRepositoryMetadataFailureIterator();
+        assertTrue( "check if there is a failure", iter.hasNext() );
     }
 
     /**
@@ -248,55 +191,30 @@ public class ChecksumArtifactReporterTest
     }
     */
 
-    /**
-     * Test deletion of the test directories created.
-     */
-    public void testDeleteChecksumFiles()
-    {
-        assertTrue( deleteChecksumFiles( "jar" ) );
-    }
-
-    /**
-     * Test deletion of the test directories created.
-     */
-    public void testDeleteTestDirectory()
-    {
-        assertTrue( deleteTestDirectory( new File( repository.getBasedir() + "checksumTest" ) ) );
-    }
-
     /**
      * Test the conditional when the checksum files of the artifact & metadata do not exist.
      */
     public void testChecksumFilesDoNotExist()
+        throws ReportProcessorException, NoSuchAlgorithmException, IOException
     {
         createChecksumFile( "VALID" );
         createMetadataFile( "VALID" );
-        boolean b = deleteChecksumFiles( "jar" );
+        deleteChecksumFiles( "jar" );
 
-        try
-        {
-            ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
-            VersionRange version = VersionRange.createFromVersion( "1.0" );
-            Artifact artifact =
-                new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler );
+        ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
+        VersionRange version = VersionRange.createFromVersion( "1.0" );
+        Artifact artifact =
+            new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler );
 
-            artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
-            //System.out.println( "5 - ART FAILURE ---> " + reporter.getFailures() );
-            assertTrue( reporter.getFailures() == 2 );
-
-            RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
-            metadataReportProcessor.processMetadata( metadata, repository, reporter );
+        artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
+        assertEquals( 2, reporter.getFailures() );
 
-            Iterator iter = reporter.getRepositoryMetadataFailureIterator();
-            //System.out.println( "5 - META FAILURE ---> " + iter.hasNext() );
-            assertTrue( "check if there is a failure", iter.hasNext() );
+        RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
+        metadataReportProcessor.processMetadata( metadata, repository, reporter );
 
-        }
-        catch ( Exception e )
-        {
-            e.printStackTrace();
-        }
+        Iterator iter = reporter.getRepositoryMetadataFailureIterator();
+        assertTrue( "check if there is a failure", iter.hasNext() );
 
-        b = deleteTestDirectory( new File( repository.getBasedir() + "checksumTest" ) );
+        deleteTestDirectory( new File( repository.getBasedir() + "checksumTest" ) );
     }
 }
index 9e9bfc759cacd44ec3bf07ebc5f6409649125411..7ab3de25091a6f3c3f46376bb299dcbdb19e1db2 100644 (file)
@@ -28,7 +28,7 @@ import java.util.Map;
 public class GenericMockObject
     implements InvocationHandler
 {
-    Map invocations = new HashMap();
+    private Map invocations = new HashMap();
 
     public GenericMockObject()
     {
@@ -37,7 +37,7 @@ public class GenericMockObject
 
     public GenericMockObject( Map returnMap )
     {
-        invocations = returnMap;
+        invocations = new HashMap( returnMap );
     }
 
     public void setExpectedReturns( Method method, List returnList )
@@ -46,7 +46,6 @@ public class GenericMockObject
     }
 
     public Object invoke( Object proxy, Method method, Object[] args )
-        throws Throwable
     {
         if ( !invocations.containsKey( method ) )
         {
index 38ed0124dc76502e845c92258eba2c847f666b90..00bdc23ae1d5041f9637926ca37bfea16e96d349 100644 (file)
@@ -40,7 +40,7 @@ public class MockArtifactReportProcessor
     }
 
     public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
-                                 ArtifactRepository artifactRepository )
+                                 ArtifactRepository repository )
     {
         if ( iterator == null || !iterator.hasNext() ) // not initialized or reached end of the list. start again
         {
@@ -51,23 +51,18 @@ public class MockArtifactReportProcessor
             while ( iterator.hasNext() )
             {
                 ReportCondition reportCondition = (ReportCondition) iterator.next();
-                switch ( reportCondition.getResult() )
+                int i = reportCondition.getResult();
+                if ( i == ReportCondition.SUCCESS )
                 {
-                    case ReportCondition.SUCCESS:
-                    {
-                        reporter.addSuccess( reportCondition.getArtifact() );
-                        break;
-                    }
-                    case ReportCondition.WARNING:
-                    {
-                        reporter.addWarning( reportCondition.getArtifact(), reportCondition.getReason() );
-                        break;
-                    }
-                    case ReportCondition.FAILURE:
-                    {
-                        reporter.addFailure( reportCondition.getArtifact(), reportCondition.getReason() );
-                        break;
-                    }
+                    reporter.addSuccess( reportCondition.getArtifact() );
+                }
+                else if ( i == ReportCondition.WARNING )
+                {
+                    reporter.addWarning( reportCondition.getArtifact(), reportCondition.getReason() );
+                }
+                else if ( i == ReportCondition.FAILURE )
+                {
+                    reporter.addFailure( reportCondition.getArtifact(), reportCondition.getReason() );
                 }
             }
         }
index 93b446fefbe10c1d8da8d7fa7cc6a925947f8f81..f13e660cf13d0e3fe328c0b87a1fa8fc9a4b3866 100755 (executable)
@@ -54,9 +54,9 @@ public class MockArtifactReporter
         artifactSuccesses.add( new ArtifactResult( artifact ) );
     }
 
-    public void addWarning( Artifact artifact, String reason )
+    public void addWarning( Artifact artifact, String message )
     {
-        artifactWarnings.add( new ArtifactResult( artifact, reason ) );
+        artifactWarnings.add( new ArtifactResult( artifact, message ) );
     }
 
     public void addFailure( RepositoryMetadata metadata, String reason )
@@ -69,9 +69,9 @@ public class MockArtifactReporter
         metadataSuccesses.add( new RepositoryMetadataResult( metadata ) );
     }
 
-    public void addWarning( RepositoryMetadata metadata, String reason )
+    public void addWarning( RepositoryMetadata metadata, String message )
     {
-        metadataWarnings.add( new RepositoryMetadataResult( metadata, reason ) );
+        metadataWarnings.add( new RepositoryMetadataResult( metadata, message ) );
     }
 
     public Iterator getArtifactFailureIterator()
index abe72552248f379b43b7df8676ca4e3a1f37ecaa..7c2460ac9101f19e9cf58e0130411823257420f3 100644 (file)
@@ -44,20 +44,21 @@ public class MockRepositoryQueryLayer
         {
             iterator = queryConditions.iterator();
         }
+        boolean b;
         if ( queryConditions.isEmpty() )
         {
-            return false;
+            b = false;
         }
         else
         {
-            boolean temp = ( (Boolean) iterator.next() ).booleanValue();
-            return temp;
+            b = ( (Boolean) iterator.next() ).booleanValue();
         }
+        return b;
     }
 
     public void addReturnValue( boolean queryCondition )
     {
-        queryConditions.add( new Boolean( queryCondition ) );
+        queryConditions.add( Boolean.valueOf( queryCondition ) );
     }
 
     public void clearList()
index 6cdfcec6958fc8923ce267f93275c206c72b0b0e..98df89646d9f10f1d01ab9207bb9d5b41d8e3552 100644 (file)
@@ -23,11 +23,11 @@ import org.apache.maven.artifact.Artifact;
  */
 public class ReportCondition
 {
-    public final static int SUCCESS = 0;
+    public static final int SUCCESS = 0;
 
-    public final static int FAILURE = -1;
+    public static final int FAILURE = -1;
 
-    public final static int WARNING = 1;
+    public static final int WARNING = 1;
 
     private int result;