From 4d159b3a2644256f5cc8b5f94950feb5f55bc87f Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Fri, 30 Dec 2005 08:24:41 +0000 Subject: [PATCH] more cleaning up git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@360028 13f79535-47bb-0310-9956-ffa450edef68 --- .../discovery/DefaultMetadataDiscoverer.java | 5 +- .../discovery/LegacyArtifactDiscoverer.java | 14 +- .../indexing/AbstractRepositoryIndex.java | 10 +- .../indexing/ArtifactRepositoryIndex.java | 8 +- .../ArtifactRepositoryIndexAnalyzer.java | 26 +- .../ArtifactRepositoryIndexSearcher.java | 16 +- .../RepositoryIndexSearchException.java | 39 ++ .../indexing/RepositoryIndexSearcher.java | 5 +- .../ArtifactRepositoryIndexingTest.java | 5 +- .../reporting/ArtifactReporter.java | 24 +- .../reporting/BadMetadataReportProcessor.java | 4 +- .../maven/repository/reporting/Cache.java | 100 ++-- .../reporting/CachedRepositoryQueryLayer.java | 4 +- .../reporting/ChecksumArtifactReporter.java | 70 +-- .../DefaultArtifactReportProcessor.java | 2 +- .../reporting/DefaultArtifactReporter.java | 8 +- .../InvalidPomArtifactReportProcessor.java | 6 +- .../reporting/RepositoryQueryLayer.java | 4 +- .../AbstractChecksumArtifactReporterTest.java | 452 ------------------ ...tractChecksumArtifactReporterTestCase.java | 339 +++++++++++++ .../ArtifactReportProcessorTest.java | 156 +++--- .../maven/repository/reporting/CacheTest.java | 18 +- .../CachedRepositoryQueryLayerTest.java | 9 +- .../ChecksumArtifactReporterTest.java | 202 +++----- .../reporting/GenericMockObject.java | 5 +- .../MockArtifactReportProcessor.java | 29 +- .../reporting/MockArtifactReporter.java | 8 +- .../reporting/MockRepositoryQueryLayer.java | 9 +- .../repository/reporting/ReportCondition.java | 6 +- 29 files changed, 727 insertions(+), 856 deletions(-) create mode 100644 maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearchException.java delete mode 100644 maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java create mode 100644 maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTestCase.java diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java index 14acf5d37..b0024db43 100644 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java @@ -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++; } diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java index 4cac9168d..405578323 100644 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java @@ -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 diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java index 9d5e304c3..04e3d2575 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java @@ -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() ) { diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java index c07ffdb5c..e7cfcc346 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java @@ -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" ); diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexAnalyzer.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexAnalyzer.java index ba0903631..4b52e1282 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexAnalyzer.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexAnalyzer.java @@ -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 != '-'; } } } diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java index c03548ae2..8760e16a9 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java @@ -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 index 000000000..f3035360f --- /dev/null +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearchException.java @@ -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 ); + } +} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.java index 81ca498d5..ac592818d 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.java @@ -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; } diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java index 742545a94..dc7f8a208 100644 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java +++ b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java @@ -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() ); diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java index 4dfb93297..a48476491 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java @@ -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 ); diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java index 645468d44..1108af25d 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java @@ -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(); diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/Cache.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/Cache.java index bb748b75d..45df43027 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/Cache.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/Cache.java @@ -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; + } } } diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.java index 73e774320..d52453e91 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.java @@ -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() diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java index 7e2a5e5c1..7b45ac7c7 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java @@ -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 ); diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReportProcessor.java index 8af45d652..6eece5fbb 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReportProcessor.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReportProcessor.java @@ -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; diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java index a0c167fea..2769dc59a 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java @@ -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() diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java index 75eecd9c3..834a70d19 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java @@ -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 ) diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayer.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayer.java index 942b052fe..bb4117015 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayer.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayer.java @@ -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 index c05bf7169..000000000 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java +++ /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 index 000000000..b860c0d37 --- /dev/null +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTestCase.java @@ -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" ); + } + } + +} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java index cd6bd7869..3cc5fb72d 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java @@ -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() diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.java index 16698ffdf..b0239d336 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.java @@ -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 ); diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java index de18378a7..13ab29f96 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java @@ -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 ); } } diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java index 6225dc05d..1e2f2a8da 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java @@ -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" ) ); } } diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java index 9e9bfc759..7ab3de250 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java @@ -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 ) ) { diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java index 38ed0124d..00bdc23ae 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java @@ -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() ); } } } diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java index 93b446fef..f13e660cf 100755 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java @@ -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() diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java index abe725522..7c2460ac9 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java @@ -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() diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java index 6cdfcec69..98df89646 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java @@ -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; -- 2.39.5