]> source.dussan.org Git - archiva.git/commitdiff
remove some duplicates
authorBrett Porter <brett@apache.org>
Wed, 7 Jun 2006 06:23:12 +0000 (06:23 +0000)
committerBrett Porter <brett@apache.org>
Wed, 7 Jun 2006 06:23:12 +0000 (06:23 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@412303 13f79535-47bb-0310-9956-ffa450edef68

maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java
maven-repository-converter/src/test/java/org/apache/maven/repository/converter/RepositoryConverterTest.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexSearcher.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/MetadataRepositoryIndex.java
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java
maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java
maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumMetadataReporter.java
maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/execution/DiscovererExecution.java

index a14c8016caa22561a45824b2032a4f411dfca619..5f74a6504a600f7faad903981c97a7251d361255 100644 (file)
@@ -480,33 +480,17 @@ public class DefaultRepositoryConverter
         if ( properties.containsKey( "relocated.groupId" ) || properties.containsKey( "relocated.artifactId" ) ||
             properties.containsKey( "relocated.version" ) )
         {
-            String newGroupId = v3Model.getGroupId();
-            if ( properties.containsKey( "relocated.groupId" ) )
-            {
-                newGroupId = properties.getProperty( "relocated.groupId" );
-                properties.remove( "relocated.groupId" );
-            }
+            String newGroupId = properties.getProperty( "relocated.groupId", v3Model.getGroupId() );
+            properties.remove( "relocated.groupId" );
 
-            String newArtifactId = v3Model.getArtifactId();
-            if ( properties.containsKey( "relocated.artifactId" ) )
-            {
-                newArtifactId = properties.getProperty( "relocated.artifactId" );
-                properties.remove( "relocated.artifactId" );
-            }
+            String newArtifactId = properties.getProperty( "relocated.artifactId", v3Model.getArtifactId() );
+            properties.remove( "relocated.artifactId" );
 
-            String newVersion = v3Model.getVersion();
-            if ( properties.containsKey( "relocated.version" ) )
-            {
-                newVersion = properties.getProperty( "relocated.version" );
-                properties.remove( "relocated.version" );
-            }
+            String newVersion = properties.getProperty( "relocated.version", v3Model.getVersion() );
+            properties.remove( "relocated.version" );
 
-            String message = "";
-            if ( properties.containsKey( "relocated.message" ) )
-            {
-                message = properties.getProperty( "relocated.message" );
-                properties.remove( "relocated.message" );
-            }
+            String message = properties.getProperty( "relocated.message", "" );
+            properties.remove( "relocated.message" );
 
             if ( properties.isEmpty() )
             {
@@ -580,31 +564,14 @@ public class DefaultRepositoryConverter
     private boolean testChecksums( Artifact artifact, File file, ArtifactReporter reporter )
         throws IOException, RepositoryConversionException
     {
-        boolean result = true;
+        boolean result;
 
         try
         {
-            File md5 = new File( file.getParentFile(), file.getName() + ".md5" );
-            if ( md5.exists() )
-            {
-                String checksum = FileUtils.fileRead( md5 );
-                if ( !digester.verifyChecksum( file, checksum, Digester.MD5 ) )
-                {
-                    reporter.addFailure( artifact, getI18NString( "failure.incorrect.md5" ) );
-                    result = false;
-                }
-            }
-
-            File sha1 = new File( file.getParentFile(), file.getName() + ".sha1" );
-            if ( sha1.exists() )
-            {
-                String checksum = FileUtils.fileRead( sha1 );
-                if ( !digester.verifyChecksum( file, checksum, Digester.SHA1 ) )
-                {
-                    reporter.addFailure( artifact, getI18NString( "failure.incorrect.sha1" ) );
-                    result = false;
-                }
-            }
+            result = verifyChecksum( file, file.getName() + ".md5", Digester.MD5, reporter, artifact,
+                                     "failure.incorrect.md5" );
+            result = result && verifyChecksum( file, file.getName() + ".sha1", Digester.SHA1, reporter, artifact,
+                                               "failure.incorrect.sha1" );
         }
         catch ( NoSuchAlgorithmException e )
         {
@@ -613,6 +580,25 @@ public class DefaultRepositoryConverter
         return result;
     }
 
+    private boolean verifyChecksum( File file, String fileName, String algorithm, ArtifactReporter reporter,
+                                    Artifact artifact, String key )
+        throws IOException, NoSuchAlgorithmException
+    {
+        boolean result = true;
+
+        File md5 = new File( file.getParentFile(), fileName );
+        if ( md5.exists() )
+        {
+            String checksum = FileUtils.fileRead( md5 );
+            if ( !digester.verifyChecksum( file, checksum, algorithm ) )
+            {
+                reporter.addFailure( artifact, getI18NString( key ) );
+                result = false;
+            }
+        }
+        return result;
+    }
+
     private boolean copyArtifact( Artifact artifact, ArtifactRepository targetRepository, ArtifactReporter reporter,
                                   FileTransaction transaction )
         throws RepositoryConversionException
index 3dadd5420bea1c16a5a592a06bff713021142357..f33895eb53bbcec23a4a47a9ddbe027224162a61 100644 (file)
@@ -253,12 +253,12 @@ public class RepositoryConverterTest
         // TODO: check 2 warnings (extend and versions) matched on i18n key
     }
 
-    public void testV4SnapshotPomConvert()
-        throws IOException, RepositoryConversionException
+    private void doTestV4SnapshotPomConvert( String version, String expectedMetadataFileName )
+        throws RepositoryConversionException, IOException
     {
         // test that it is copied as is
 
-        Artifact artifact = createArtifact( "test", "v4artifact", "1.0.0-SNAPSHOT" );
+        Artifact artifact = createArtifact( "test", "v4artifact", version );
         ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
         File artifactMetadataFile = new File( targetRepository.getBasedir(),
                                               targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
@@ -291,7 +291,7 @@ public class RepositoryConverterTest
 
         assertTrue( "Check snapshot metadata created", snapshotMetadataFile.exists() );
 
-        expectedMetadataFile = getTestFile( "src/test/expected-files/v4-snapshot-metadata.xml" );
+        expectedMetadataFile = getTestFile( expectedMetadataFileName );
 
         compareFiles( expectedMetadataFile, snapshotMetadataFile );
     }
@@ -339,47 +339,21 @@ public class RepositoryConverterTest
         compareFiles( expectedMetadataFile, snapshotMetadataFile );
     }
 
-    public void testV4TimestampedSnapshotPomConvert()
+    public void testV4SnapshotPomConvert()
         throws IOException, RepositoryConversionException
     {
-        // test that it is copied as is
-
-        Artifact artifact = createArtifact( "test", "v4artifact", "1.0.0-20060111.120115-1" );
-        ArtifactMetadata artifactMetadata = new ArtifactRepositoryMetadata( artifact );
-        File artifactMetadataFile = new File( targetRepository.getBasedir(),
-                                              targetRepository.pathOfRemoteRepositoryMetadata( artifactMetadata ) );
-        artifactMetadataFile.delete();
-
-        ArtifactMetadata snapshotMetadata = new SnapshotArtifactRepositoryMetadata( artifact );
-        File snapshotMetadataFile = new File( targetRepository.getBasedir(),
-                                              targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) );
-        snapshotMetadataFile.delete();
-
-        repositoryConverter.convert( artifact, targetRepository, reporter );
-        checkSuccess();
-
-        File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
-        assertTrue( "Check artifact created", artifactFile.exists() );
-        assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
-
-        artifact = createPomArtifact( artifact );
-        File pomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
-        File sourcePomFile = new File( sourceRepository.getBasedir(), sourceRepository.pathOf( artifact ) );
-        assertTrue( "Check POM created", pomFile.exists() );
-
-        compareFiles( sourcePomFile, pomFile );
-
-        assertTrue( "Check artifact metadata created", artifactMetadataFile.exists() );
+        doTestV4SnapshotPomConvert( "1.0.0-SNAPSHOT", "src/test/expected-files/v4-snapshot-metadata.xml" );
 
-        File expectedMetadataFile = getTestFile( "src/test/expected-files/v4-snapshot-artifact-metadata.xml" );
-
-        compareFiles( expectedMetadataFile, artifactMetadataFile );
-
-        assertTrue( "Check snapshot metadata created", snapshotMetadataFile.exists() );
+        assertTrue( true );
+    }
 
-        expectedMetadataFile = getTestFile( "src/test/expected-files/v4-timestamped-snapshot-metadata.xml" );
+    public void testV4TimestampedSnapshotPomConvert()
+        throws IOException, RepositoryConversionException
+    {
+        doTestV4SnapshotPomConvert( "1.0.0-20060111.120115-1",
+                                    "src/test/expected-files/v4-timestamped-snapshot-metadata.xml" );
 
-        compareFiles( expectedMetadataFile, snapshotMetadataFile );
+        assertTrue( true );
     }
 
     public void testV3TimestampedSnapshotPomConvert()
index 2b7db9e976259ceb73397e08c1d597247ce7ea0e..fabe952bdd22a7ff483350370eb2391b8495ab05 100644 (file)
@@ -276,6 +276,7 @@ public class DefaultRepositoryIndexSearcher
         //group metadata\r
         if ( metadataType.equals( MetadataRepositoryIndex.GROUP_METADATA ) )\r
         {\r
+            // TODO! use pathOfMetadata\r
             is = new FileInputStream(\r
                 new File( index.getRepository().getBasedir() + groupId.replace( '.', '/' ) + "/" + filename ) );\r
             repoMetadata = new GroupRepositoryMetadata( groupId );\r
@@ -284,6 +285,7 @@ public class DefaultRepositoryIndexSearcher
         //artifact metadata\r
         else if ( metadataType.equals( MetadataRepositoryIndex.ARTIFACT_METADATA ) )\r
         {\r
+            // TODO! use pathOfMetadata\r
             is = new FileInputStream( new File( index.getRepository().getBasedir() + groupId.replace( '.', '/' ) + "/" +\r
                 artifactId + "/" + filename ) );\r
             repoMetadata =\r
@@ -293,6 +295,7 @@ public class DefaultRepositoryIndexSearcher
         //snapshot/version metadata\r
         else if ( metadataType.equals( MetadataRepositoryIndex.SNAPSHOT_METADATA ) )\r
         {\r
+            // TODO! use pathOfMetadata\r
             is = new FileInputStream( new File( index.getRepository().getBasedir() + groupId.replace( '.', '/' ) + "/" +\r
                 artifactId + "/" + version + "/" + filename ) );\r
             repoMetadata = new SnapshotArtifactRepositoryMetadata(\r
index ab39819350cdafd524d98901fc9f235f9caf4817..ded2c30df0b291e62b2936a8a8e73ed65b05581b 100644 (file)
@@ -153,6 +153,7 @@ public class MetadataRepositoryIndex
         {\r
             doc.add( Field.Text( FLD_VERSION, "" ) );\r
         }\r
+        // TODO! do we need to add all these empty fields?\r
         doc.add( Field.Text( FLD_DOCTYPE, METADATA ) );\r
         doc.add( Field.Keyword( FLD_PACKAGING, "" ) );\r
         doc.add( Field.Text( FLD_SHA1, "" ) );\r
index cca1e72e6545665553fd0a4c4b5646f2ecdff9fe..a911b83f8d1ce384bccbe1db83fa28af8cf9cc8e 100644 (file)
@@ -140,6 +140,7 @@ public class PomRepositoryIndex
             doc.add( Field.Text( FLD_PLUGINS_ALL, "" ) );
         }
         doc.add( Field.UnIndexed( FLD_DOCTYPE, POM ) );
+        // TODO! do we need to add all these empty fields?
         doc.add( Field.Text( FLD_PLUGINPREFIX, "" ) );
         doc.add( Field.Text( FLD_LASTUPDATE, "" ) );
         doc.add( Field.Text( FLD_NAME, "" ) );
index bd0c4d2589fa60641178938e2d90dc0667f8df1d..7048fae234a6f793c7cc0074702624e5186f8be8 100644 (file)
@@ -35,7 +35,9 @@ import java.security.NoSuchAlgorithmException;
 public class ChecksumArtifactReporter
     implements ArtifactReportProcessor
 {
-    /** @plexus.requirement */
+    /**
+     * @plexus.requirement
+     */
     private Digester digester;
 
     /**
@@ -60,60 +62,39 @@ public class ChecksumArtifactReporter
         String path = repository.pathOf( artifact );
         File file = new File( repository.getBasedir(), path );
 
-        File md5File = new File( repository.getBasedir(), path + ".md5" );
-        if ( md5File.exists() )
-        {
-            try
-            {
-                if ( digester.verifyChecksum( file, FileUtils.fileRead( md5File ), Digester.MD5 ) )
-                {
-                    reporter.addSuccess( artifact );
-                }
-                else
-                {
-                    reporter.addFailure( artifact, "MD5 checksum does not match." );
-                }
-            }
-            catch ( NoSuchAlgorithmException e )
-            {
-                reporter.addFailure( artifact, "Unable to read MD5: " + e.getMessage() );
-            }
-            catch ( IOException e )
-            {
-                reporter.addFailure( artifact, "Unable to read MD5: " + e.getMessage() );
-            }
-        }
-        else
-        {
-            reporter.addFailure( artifact, "MD5 checksum file does not exist." );
-        }
+        verifyChecksum( repository, path + ".md5", file, Digester.MD5, reporter, artifact );
+        verifyChecksum( repository, path + ".sha1", file, Digester.SHA1, reporter, artifact );
+    }
 
-        File sha1File = new File( repository.getBasedir(), path + ".sha1" );
-        if ( sha1File.exists() )
+    private void verifyChecksum( ArtifactRepository repository, String path, File file, String checksumAlgorithm,
+                                 ArtifactReporter reporter, Artifact artifact )
+    {
+        File checksumFile = new File( repository.getBasedir(), path );
+        if ( checksumFile.exists() )
         {
             try
             {
-                if ( digester.verifyChecksum( file, FileUtils.fileRead( sha1File ), Digester.SHA1 ) )
+                if ( digester.verifyChecksum( file, FileUtils.fileRead( checksumFile ), checksumAlgorithm ) )
                 {
                     reporter.addSuccess( artifact );
                 }
                 else
                 {
-                    reporter.addFailure( artifact, "SHA-1 checksum does not match." );
+                    reporter.addFailure( artifact, checksumAlgorithm + " checksum does not match." );
                 }
             }
             catch ( NoSuchAlgorithmException e )
             {
-                reporter.addFailure( artifact, "Unable to read SHA-1: " + e.getMessage() );
+                reporter.addFailure( artifact, "Unable to read " + checksumAlgorithm + ": " + e.getMessage() );
             }
             catch ( IOException e )
             {
-                reporter.addFailure( artifact, "Unable to read SHA-1: " + e.getMessage() );
+                reporter.addFailure( artifact, "Unable to read " + checksumAlgorithm + ": " + e.getMessage() );
             }
         }
         else
         {
-            reporter.addFailure( artifact, "SHA-1 checksum file does not exist." );
+            reporter.addFailure( artifact, checksumAlgorithm + " checksum file does not exist." );
         }
     }
 }
index 22c7dffe4edbc8783abc7e2f2c0883990d4569db..e33e6f8ca540871ef4ba074652eed5125bb9e24b 100644 (file)
@@ -34,7 +34,9 @@ import java.security.NoSuchAlgorithmException;
 public class ChecksumMetadataReporter
     implements MetadataReportProcessor
 {
-    /** @plexus.requirement */
+    /**
+     * @plexus.requirement
+     */
     private Digester digester;
 
     /**
@@ -54,62 +56,41 @@ public class ChecksumMetadataReporter
         String path = repository.pathOfRemoteRepositoryMetadata( metadata );
         File file = new File( repository.getBasedir(), path );
 
-        File md5File = new File( repository.getBasedir(), path + ".md5" );
-        if ( md5File.exists() )
-        {
-            try
-            {
-                if ( digester.verifyChecksum( file, FileUtils.fileRead( md5File ), Digester.MD5 ) )
-                {
-                    reporter.addSuccess( metadata );
-                }
-                else
-                {
-                    reporter.addFailure( metadata, "MD5 checksum does not match." );
-                }
-            }
-            catch ( NoSuchAlgorithmException e )
-            {
-                reporter.addFailure( metadata, "Unable to read MD5: " + e.getMessage() );
-            }
-            catch ( IOException e )
-            {
-                reporter.addFailure( metadata, "Unable to read MD5: " + e.getMessage() );
-            }
-        }
-        else
-        {
-            reporter.addFailure( metadata, "MD5 checksum file does not exist." );
-        }
+        verifyChecksum( repository, path + ".md5", file, Digester.MD5, reporter, metadata );
+        verifyChecksum( repository, path + ".sha1", file, Digester.SHA1, reporter, metadata );
+
+    }
 
-        File sha1File = new File( repository.getBasedir(), path + ".sha1" );
-        if ( sha1File.exists() )
+    private void verifyChecksum( ArtifactRepository repository, String path, File file, String checksumAlgorithm,
+                                 ArtifactReporter reporter, RepositoryMetadata metadata )
+    {
+        File checksumFile = new File( repository.getBasedir(), path );
+        if ( checksumFile.exists() )
         {
             try
             {
-                if ( digester.verifyChecksum( file, FileUtils.fileRead( sha1File ), Digester.SHA1 ) )
+                if ( digester.verifyChecksum( file, FileUtils.fileRead( checksumFile ), checksumAlgorithm ) )
                 {
                     reporter.addSuccess( metadata );
                 }
                 else
                 {
-                    reporter.addFailure( metadata, "SHA-1 checksum does not match." );
+                    reporter.addFailure( metadata, checksumAlgorithm + " checksum does not match." );
                 }
             }
             catch ( NoSuchAlgorithmException e )
             {
-                reporter.addFailure( metadata, "Unable to read SHA1: " + e.getMessage() );
+                reporter.addFailure( metadata, "Unable to read " + checksumAlgorithm + ": " + e.getMessage() );
             }
             catch ( IOException e )
             {
-                reporter.addFailure( metadata, "Unable to read SHA1: " + e.getMessage() );
+                reporter.addFailure( metadata, "Unable to read " + checksumAlgorithm + ": " + e.getMessage() );
             }
         }
         else
         {
-            reporter.addFailure( metadata, "SHA-1 checksum file does not exist." );
+            reporter.addFailure( metadata, checksumAlgorithm + " checksum file does not exist." );
         }
-
     }
 
 }
index 465ebe412ffb28bc14b4d30af3151eb5b1c3b898..dcff2a79869db1efa42b1a63fd86b57643d8e3cf 100644 (file)
@@ -152,10 +152,11 @@ public class DiscovererExecution
 
     /**
      * Method that discovers and indexes artifacts, poms and metadata in a default
-     * m2 repository structure
+     * m2 repository structure.
      *
      * @throws MalformedURLException
      * @throws RepositoryIndexException
+     * @todo why is this any different from legacy?
      */
     protected void executeDiscovererInDefaultRepo()
         throws MalformedURLException, RepositoryIndexException