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++;
}
return artifacts;
}
+ /**
+ * @noinspection CollectionDeclaredAsConcreteClass
+ */
private Artifact buildArtifact( String path )
{
StringTokenizer tokens = new StringTokenizer( path, "/\\" );
}
}
+ // 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]*)|" +
"([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();
{
if ( firstVersionTokenEncountered )
{
+ //noinspection BreakStatement
break;
}
else
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;
* @author Edwin Punzalan
*/
public abstract class AbstractRepositoryIndex
+ extends AbstractLogEnabled
implements RepositoryIndex
{
protected String indexPath;
public void optimize()
throws RepositoryIndexException
{
- if ( !isOpen() )
+ if ( !indexOpen )
{
throw new RepositoryIndexException( "Unable to optimize index on a closed index" );
}
/**
* method used to query the index status
*
- * @param true if the index is open.
+ * @return true if the index is open.
*/
public boolean isOpen()
{
}
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() )
{
private StringBuffer files;
+ private static final int CHEKCSUM_BUFFER_SIZE = 256;
+
/**
* method to get the Analyzer used to create indices
*
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
private boolean addFile( ZipEntry entry )
{
- boolean isAdded = false;
-
String name = entry.getName();
int idx = name.lastIndexOf( '/' );
if ( idx >= 0 )
name = name.substring( idx + 1 );
}
+ boolean isAdded = false;
+
if ( files.indexOf( name + "\n" ) < 0 )
{
files.append( name ).append( "\n" );
/**
* 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 )
{
/**
* 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 )
{
/**
* 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 );
}
*/
protected boolean isTokenChar( char character )
{
- boolean token;
-
- switch ( character )
- {
- case '.':
- case '-':
- token = false;
- break;
- default:
- token = true;
- }
-
- return token;
+ return character != '.' && character != '-';
}
}
}
*/
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;
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;
private static final String VERSION = "version";
- private IndexSearcher searcher;
-
private ArtifactRepository repository;
private ArtifactFactory factory;
* @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++ )
{
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;
--- /dev/null
+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 );
+ }
+}
*/
public interface RepositoryIndexSearcher
{
-
String ROLE = RepositoryIndexSearcher.class.getName();
/**
* @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;
}
protected String indexPath;
- private RepositoryIndexSearcher repoSearcher;
-
protected void setUp()
throws Exception
{
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() );
* 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 );
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
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();
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.
* 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 )
{
* 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 )
{
makeMostRecent( cacheEntry );
- retValue = cacheEntry.cacheValue;
+ retValue = cacheEntry.getCacheValue();
cacheHits++;
}
/**
* 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 );
}
/**
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()
private void trimCache()
{
DblLinkedList leastRecent = getLeastRecent();
- cache.remove( leastRecent.cacheKey );
+ cache.remove( leastRecent.getCacheKey() );
if ( cache.size() > 0 )
{
removeFromLinks( leastRecent );
{
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;
+ }
}
}
{
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()
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.
*
* @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() ) )
{
repositoryUrl = repository.getBasedir();
}
- artifactUrl = repositoryUrl + artifact.getGroupId() + "/" + artifact.getArtifactId() + "/" +
+ String artifactUrl = repositoryUrl + artifact.getGroupId() + "/" + artifact.getArtifactId() + "/" +
artifact.getBaseVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "." +
artifact.getType();
/**
* 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;
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() + "/";
* 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 )
{
* 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 )
{
*
* @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
{
{
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;
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;
}
/**
* @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 )
URL url = new URL( filename );
fis = url.openStream();
}
+ byte[] buffer = new byte[CHECKSUM_BUFFER_SIZE];
MessageDigest complete = MessageDigest.getInstance( algo );
int numRead;
* 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 = "";
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 );
public class DefaultArtifactReportProcessor
implements ArtifactReportProcessor
{
- private final static String EMPTY_STRING = "";
+ private static final String EMPTY_STRING = "";
// plexus components
private ArtifactFactory artifactFactory;
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 )
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()
* @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() ) )
{
try
{
- Model pomModel = pomReader.read( reader );
+ pomReader.read( reader );
reporter.addSuccess( artifact );
}
catch ( XmlPullParserException xe )
{
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 );
+++ /dev/null
-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;
- }
-
-}
--- /dev/null
+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" );
+ }
+ }
+
+}
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;
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
{
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";
cache.put( key + ctr, value + ctr );
}
- while ( cache.getHitRate() < 0.75 )
+ while ( cache.getHitRate() < CACHE_HIT_RATIO_THRESHOLD )
{
cache.get( "key2" );
}
public void testCacheManagementBasedOnCacheSizeAndHitRate()
{
- cache = new Cache( 0.5, 9 );
+ cache = new Cache( CACHE_HIT_RATIO, 9 );
newCacheObjectTests();
String key = "key";
cache.put( key + ctr, value + ctr );
}
- while ( cache.getHitRate() < 0.5 )
+ while ( cache.getHitRate() < CACHE_HIT_RATIO )
{
cache.get( "key3" );
}
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" );
}
public void testCacheOnRedundantData()
{
- cache = new Cache( 0.5, 9 );
+ cache = new Cache( CACHE_HIT_RATIO, 9 );
newCacheObjectTests();
String key = "key";
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 );
public class CachedRepositoryQueryLayerTest
extends AbstractRepositoryQueryLayerTest
{
+ // TODO: share
+ private static final double CACHE_HIT_RATIO = 0.5;
+
protected void setUp()
throws Exception
{
testContainsArtifactTrue();
assertEquals( 0, queryLayer.getCacheHitRate(), 0 );
testContainsArtifactTrue();
- assertEquals( 0.50, queryLayer.getCacheHitRate(), 0 );
+ assertEquals( CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 );
}
public void testUseMetadataCache()
testArtifactVersionsTrue();
assertEquals( 0, queryLayer.getCacheHitRate(), 0 );
testArtifactVersionsTrue();
- assertEquals( 0.50, queryLayer.getCacheHitRate(), 0 );
+ assertEquals( CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 );
}
public void testUseFileCacheOnSnapshot()
testContainsSnapshotArtifactTrue();
assertEquals( 0, queryLayer.getCacheHitRate(), 0 );
testContainsSnapshotArtifactTrue();
- assertEquals( 0.50, queryLayer.getCacheHitRate(), 0 );
+ assertEquals( CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 );
}
}
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;
private MetadataReportProcessor metadataReportProcessor;
- public ChecksumArtifactReporterTest()
- {
-
- }
-
public void setUp()
throws Exception
{
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() );
}
/**
* 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() );
}
/**
* 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() );
}
/**
}
*/
- /**
- * 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" ) );
}
}
public class GenericMockObject
implements InvocationHandler
{
- Map invocations = new HashMap();
+ private Map invocations = new HashMap();
public GenericMockObject()
{
public GenericMockObject( Map returnMap )
{
- invocations = returnMap;
+ invocations = new HashMap( returnMap );
}
public void setExpectedReturns( Method method, List returnList )
}
public Object invoke( Object proxy, Method method, Object[] args )
- throws Throwable
{
if ( !invocations.containsKey( method ) )
{
}
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
{
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() );
}
}
}
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 )
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()
{
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()
*/
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;