maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r360170 - in /maven/repository-manager/trunk: maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/ maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ maven-repository-reports-standard/src...
Date Fri, 30 Dec 2005 21:46:20 GMT
Author: brett
Date: Fri Dec 30 13:46:08 2005
New Revision: 360170

URL: http://svn.apache.org/viewcvs?rev=360170&view=rev
Log:
exception clean up (all done!)

Modified:
    maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java
    maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/MetadataDiscoverer.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java
    maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java
    maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java

Modified: maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java?rev=360170&r1=360169&r2=360170&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java
(original)
+++ maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java
Fri Dec 30 13:46:08 2005
@@ -35,6 +35,7 @@
 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;
@@ -172,6 +173,10 @@
             // TODO: log ignored metadata
         }
         catch ( XmlPullParserException xe )
+        {
+            // TODO: log ignored metadata
+        }
+        catch ( MalformedURLException e )
         {
             // TODO: log ignored metadata
         }

Modified: maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/MetadataDiscoverer.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/MetadataDiscoverer.java?rev=360170&r1=360169&r2=360170&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/MetadataDiscoverer.java
(original)
+++ maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/MetadataDiscoverer.java
Fri Dec 30 13:46:08 2005
@@ -32,7 +32,6 @@
      *
      * @param repositoryBase      The repository directory.
      * @param blacklistedPatterns Patterns that are to be excluded from the discovery process.
-     * @return
      */
     List discoverMetadata( File repositoryBase, String blacklistedPatterns );
 

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java?rev=360170&r1=360169&r2=360170&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java
(original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java
Fri Dec 30 13:46:08 2005
@@ -94,9 +94,9 @@
 
             indexOpen = false;
         }
-        catch ( Exception e )
+        catch ( IOException e )
         {
-            throw new RepositoryIndexException( e );
+            throw new RepositoryIndexException( e.getMessage(), e );
         }
     }
 

Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java?rev=360170&r1=360169&r2=360170&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java
(original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java
Fri Dec 30 13:46:08 2005
@@ -20,9 +20,9 @@
 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.NoSuchAlgorithmException;
 import java.util.Enumeration;
 import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
 import java.util.zip.ZipFile;
 
 
@@ -65,7 +66,9 @@
 
     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 @@
             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, 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() ) );
 
-            //@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 );
+        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 )

Modified: maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java?rev=360170&r1=360169&r2=360170&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java
(original)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java
Fri Dec 30 13:46:08 2005
@@ -22,9 +22,12 @@
 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 @@
             {
                 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 );
             }

Modified: maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java?rev=360170&r1=360169&r2=360170&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java
(original)
+++ maven/repository-manager/trunk/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java
Fri Dec 30 13:46:08 2005
@@ -42,7 +42,7 @@
 {
     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 @@
      * @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 );



Mime
View raw message