Преглед на файлове

exception clean up (all done!)

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@360170 13f79535-47bb-0310-9956-ffa450edef68
tags/archiva-0.9-alpha-1
Brett Porter преди 18 години
родител
ревизия
95c50f42ef

+ 5
- 0
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java Целия файл

@@ -35,6 +35,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
@@ -175,6 +176,10 @@ public class DefaultMetadataDiscoverer
{
// TODO: log ignored metadata
}
catch ( MalformedURLException e )
{
// TODO: log ignored metadata
}
catch ( IOException ie )
{
// TODO: log ignored metadata

+ 0
- 1
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/MetadataDiscoverer.java Целия файл

@@ -32,7 +32,6 @@ public interface MetadataDiscoverer
*
* @param repositoryBase The repository directory.
* @param blacklistedPatterns Patterns that are to be excluded from the discovery process.
* @return
*/
List discoverMetadata( File repositoryBase, String blacklistedPatterns );


+ 2
- 2
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java Целия файл

@@ -94,9 +94,9 @@ public abstract class AbstractRepositoryIndex

indexOpen = false;
}
catch ( Exception e )
catch ( IOException e )
{
throw new RepositoryIndexException( e );
throw new RepositoryIndexException( e.getMessage(), e );
}
}


+ 115
- 50
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java Целия файл

@@ -20,9 +20,9 @@ import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.maven.artifact.Artifact;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -31,6 +31,7 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;


@@ -65,7 +66,9 @@ public class ArtifactRepositoryIndex

private Analyzer analyzer;

private static final int CHEKCSUM_BUFFER_SIZE = 256;
private static final int CHECKSUM_BUFFER_SIZE = 16384;

private static final int BYTE_MASK = 0xFF;

/**
* method to get the Analyzer used to create indices
@@ -124,75 +127,137 @@ public class ArtifactRepositoryIndex
throw new RepositoryIndexException( "Unable to add artifact index on a closed index" );
}

StringBuffer classes = new StringBuffer();
StringBuffer packages = new StringBuffer();
StringBuffer files = new StringBuffer();

String sha1sum;
String md5sum;
ZipFile jar;
try
{
IndexWriter indexWriter = getIndexWriter();
sha1sum = byteArrayToHexStr( createChecksum( artifact.getFile(), "SHA-1" ) );
md5sum = byteArrayToHexStr( createChecksum( artifact.getFile(), "MD5" ) );
jar = new ZipFile( artifact.getFile() );
}
catch ( NoSuchAlgorithmException e )
{
throw new RepositoryIndexException( "Unable to create a checksum", e );
}
catch ( FileNotFoundException e )
{
throw new RepositoryIndexException( "Error reading from artifact file", e );
}
catch ( ZipException e )
{
throw new RepositoryIndexException( "Error reading from artifact file", e );
}
catch ( IOException e )
{
throw new RepositoryIndexException( "Error reading from artifact file", e );
}

StringBuffer classes = new StringBuffer();
StringBuffer packages = new StringBuffer();
StringBuffer files = new StringBuffer();
ZipFile jar = new ZipFile( artifact.getFile() );
for ( Enumeration entries = jar.entries(); entries.hasMoreElements(); )
for ( Enumeration entries = jar.entries(); entries.hasMoreElements(); )
{
ZipEntry entry = (ZipEntry) entries.nextElement();
if ( addIfClassEntry( entry, classes ) )
{
ZipEntry entry = (ZipEntry) entries.nextElement();
if ( addIfClassEntry( entry, classes ) )
{
addClassPackage( entry.getName(), packages );
}
addFile( entry, files );
addClassPackage( entry.getName(), packages );
}
addFile( entry, files );
}

//@todo should some of these fields be Keyword instead of Text ?
Document doc = new Document();
doc.add( Field.Text( NAME, artifact.getFile().getName() ) );
doc.add( Field.Text( GROUPID, artifact.getGroupId() ) );
doc.add( Field.Text( ARTIFACTID, artifact.getArtifactId() ) );
doc.add( Field.Text( VERSION, artifact.getVersion() ) );
doc.add( Field.Text( SHA1, getSha1( artifact ) ) );
doc.add( Field.Text( MD5, getMd5( artifact ) ) );
doc.add( Field.Text( CLASSES, classes.toString() ) );
doc.add( Field.Text( PACKAGES, packages.toString() ) );
doc.add( Field.Text( FILES, files.toString() ) );
indexWriter.addDocument( doc );
//@todo should some of these fields be Keyword instead of Text ?
Document doc = new Document();
doc.add( Field.Text( NAME, artifact.getFile().getName() ) );
doc.add( Field.Text( GROUPID, artifact.getGroupId() ) );
doc.add( Field.Text( ARTIFACTID, artifact.getArtifactId() ) );
doc.add( Field.Text( VERSION, artifact.getVersion() ) );
doc.add( Field.Text( SHA1, sha1sum ) );
doc.add( Field.Text( MD5, md5sum ) );
doc.add( Field.Text( CLASSES, classes.toString() ) );
doc.add( Field.Text( PACKAGES, packages.toString() ) );
doc.add( Field.Text( FILES, files.toString() ) );

try
{
getIndexWriter().addDocument( doc );
}
catch ( Exception e )
catch ( IOException e )
{
throw new RepositoryIndexException( e );
throw new RepositoryIndexException( "Error opening index", e );
}
}

private String getSha1( Artifact artifact )
throws FileNotFoundException, IOException, NoSuchAlgorithmException
/**
* Convert an incoming array of bytes into a string that represents each of
* the bytes as two hex characters.
*
* @param data
* @todo move to utilities
*/
private static String byteArrayToHexStr( byte[] data )
{
FileInputStream fIn = new FileInputStream( artifact.getFile() );
return new String( getChecksum( fIn, "SHA-1" ) );
}
String output = "";

private String getMd5( Artifact artifact )
throws FileNotFoundException, IOException, NoSuchAlgorithmException
{
FileInputStream fIn = new FileInputStream( artifact.getFile() );
return new String( getChecksum( fIn, "MD5" ) );
for ( int cnt = 0; cnt < data.length; cnt++ )
{
//Deposit a byte into the 8 lsb of an int.
int tempInt = data[cnt] & BYTE_MASK;

//Get hex representation of the int as a string.
String tempStr = Integer.toHexString( tempInt );

//Append a leading 0 if necessary so that each hex string will contain 2 characters.
if ( tempStr.length() == 1 )
{
tempStr = "0" + tempStr;
}

//Concatenate the two characters to the output string.
output = output + tempStr;
}

return output.toUpperCase();
}

private byte[] getChecksum( InputStream inStream, String algorithm )
throws IOException, NoSuchAlgorithmException
/**
* Create a checksum from the specified metadata file.
*
* @param file The file that will be created a checksum.
* @param algo The algorithm to be used (MD5, SHA-1)
* @return
* @throws FileNotFoundException
* @throws NoSuchAlgorithmException
* @throws IOException
* @todo move to utility class
*/
private static byte[] createChecksum( File file, String algo )
throws FileNotFoundException, NoSuchAlgorithmException, IOException
{
byte[] buffer = new byte[ CHEKCSUM_BUFFER_SIZE ];
MessageDigest complete = MessageDigest.getInstance( algorithm );
int numRead;
do
MessageDigest digest = MessageDigest.getInstance( algo );
InputStream fis = new FileInputStream( file );
try
{
numRead = inStream.read( buffer );
if ( numRead > 0 )
byte[] buffer = new byte[CHECKSUM_BUFFER_SIZE];
int numRead;
do
{
complete.update( buffer, 0, numRead );
numRead = fis.read( buffer );
if ( numRead > 0 )
{
digest.update( buffer, 0, numRead );
}
}
while ( numRead != -1 );
}
finally
{
fis.close();
}
while ( numRead != -1 );
inStream.close();

return complete.digest();
return digest.digest();
}

private boolean addIfClassEntry( ZipEntry entry, StringBuffer classes )

+ 12
- 1
maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java Целия файл

@@ -22,9 +22,12 @@ import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.Snapshot;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;

/**
@@ -80,7 +83,15 @@ public abstract class AbstractRepositoryQueryLayer
{
metadata = reader.read( new FileReader( metadataFile ) );
}
catch ( Exception e )
catch ( FileNotFoundException e )
{
throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
}
catch ( IOException e )
{
throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
}
catch ( XmlPullParserException e )
{
throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
}

+ 2
- 2
maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java Целия файл

@@ -42,7 +42,7 @@ public class ChecksumArtifactReporter
{
private static final int BYTE_MASK = 0xFF;

private static final int CHECKSUM_BUFFER_SIZE = 256;
private static final int CHECKSUM_BUFFER_SIZE = 16384;

/**
* Validate the checksum of the specified artifact.
@@ -232,7 +232,7 @@ public class ChecksumArtifactReporter
* @throws IOException
* @todo move to utility class
*/
private byte[] createChecksum( File file, String algo )
private static byte[] createChecksum( File file, String algo )
throws FileNotFoundException, NoSuchAlgorithmException, IOException
{
MessageDigest digest = MessageDigest.getInstance( algo );

Loading…
Отказ
Запис