From 0cb280cd5f8905231b32bdc54c18ab02ec15531c Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 30 Oct 2006 19:32:43 +0000 Subject: [PATCH] Moving from internal Digest routines to plexus-digest. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@469245 13f79535-47bb-0310-9956-ffa450edef68 --- .../converter/DefaultRepositoryConverter.java | 4 +- .../converter/RepositoryConverterTest.xml | 10 +- archiva-indexer/pom.xml | 4 + .../AbstractArtifactIndexRecordFactory.java | 4 +- .../MinimalArtifactIndexRecordFactory.java | 2 +- .../StandardArtifactIndexRecordFactory.java | 2 +- archiva-proxy/pom.xml | 4 + .../proxy/DefaultProxyRequestHandler.java | 4 +- .../ChecksumArtifactReportProcessor.java | 4 +- .../ChecksumMetadataReportProcessor.java | 4 +- .../DuplicateArtifactFileReportProcessor.java | 4 +- ...tractChecksumArtifactReporterTestCase.java | 4 +- .../ChecksumArtifactReporterTest.java | 2 +- ...plicateArtifactFileReportProcessorTest.xml | 2 +- .../archiva/digest/AbstractDigester.java | 88 ------- .../digest/AbstractStreamingDigester.java | 102 -------- .../maven/archiva/digest/DigestUtils.java | 67 ----- .../apache/maven/archiva/digest/Digester.java | 56 ----- .../archiva/digest/DigesterException.java | 34 --- .../maven/archiva/digest/Md5Digester.java | 34 --- .../maven/archiva/digest/Sha1Digester.java | 34 --- .../archiva/digest/StreamingDigester.java | 64 ----- .../archiva/digest/StreamingMd5Digester.java | 35 --- .../archiva/digest/StreamingSha1Digester.java | 35 --- .../maven/archiva/digest/DigestUtilsTest.java | 36 --- .../maven/archiva/digest/DigesterTest.java | 229 ------------------ pom.xml | 5 + 27 files changed, 36 insertions(+), 837 deletions(-) delete mode 100644 archiva-utils/src/main/java/org/apache/maven/archiva/digest/AbstractDigester.java delete mode 100644 archiva-utils/src/main/java/org/apache/maven/archiva/digest/AbstractStreamingDigester.java delete mode 100644 archiva-utils/src/main/java/org/apache/maven/archiva/digest/DigestUtils.java delete mode 100644 archiva-utils/src/main/java/org/apache/maven/archiva/digest/Digester.java delete mode 100644 archiva-utils/src/main/java/org/apache/maven/archiva/digest/DigesterException.java delete mode 100644 archiva-utils/src/main/java/org/apache/maven/archiva/digest/Md5Digester.java delete mode 100644 archiva-utils/src/main/java/org/apache/maven/archiva/digest/Sha1Digester.java delete mode 100644 archiva-utils/src/main/java/org/apache/maven/archiva/digest/StreamingDigester.java delete mode 100644 archiva-utils/src/main/java/org/apache/maven/archiva/digest/StreamingMd5Digester.java delete mode 100644 archiva-utils/src/main/java/org/apache/maven/archiva/digest/StreamingSha1Digester.java delete mode 100644 archiva-utils/src/test/java/org/apache/maven/archiva/digest/DigestUtilsTest.java delete mode 100644 archiva-utils/src/test/java/org/apache/maven/archiva/digest/DigesterTest.java diff --git a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/DefaultRepositoryConverter.java b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/DefaultRepositoryConverter.java index d45a26a16..10cb3c9d7 100644 --- a/archiva-converter/src/main/java/org/apache/maven/archiva/converter/DefaultRepositoryConverter.java +++ b/archiva-converter/src/main/java/org/apache/maven/archiva/converter/DefaultRepositoryConverter.java @@ -17,8 +17,6 @@ package org.apache.maven.archiva.converter; */ import org.apache.maven.archiva.converter.transaction.FileTransaction; -import org.apache.maven.archiva.digest.Digester; -import org.apache.maven.archiva.digest.DigesterException; import org.apache.maven.archiva.reporting.ReportingDatabase; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; @@ -39,6 +37,8 @@ import org.apache.maven.model.converter.ModelConverter; import org.apache.maven.model.converter.PomTranslationException; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.model.v3_0_0.io.xpp3.MavenXpp3Reader; +import org.codehaus.plexus.digest.Digester; +import org.codehaus.plexus.digest.DigesterException; import org.codehaus.plexus.i18n.I18N; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; diff --git a/archiva-converter/src/test/resources/org/apache/maven/archiva/converter/RepositoryConverterTest.xml b/archiva-converter/src/test/resources/org/apache/maven/archiva/converter/RepositoryConverterTest.xml index 9670e97d8..06ed025a0 100644 --- a/archiva-converter/src/test/resources/org/apache/maven/archiva/converter/RepositoryConverterTest.xml +++ b/archiva-converter/src/test/resources/org/apache/maven/archiva/converter/RepositoryConverterTest.xml @@ -26,12 +26,12 @@ - org.apache.maven.archiva.digest.Digester + org.codehaus.plexus.digest.Digester sha1 sha1Digester - org.apache.maven.archiva.digest.Digester + org.codehaus.plexus.digest.Digester md5 md5Digester @@ -58,12 +58,12 @@ - org.apache.maven.archiva.digest.Digester + org.codehaus.plexus.digest.Digester sha1 sha1Digester - org.apache.maven.archiva.digest.Digester + org.codehaus.plexus.digest.Digester md5 md5Digester @@ -82,4 +82,4 @@ - \ No newline at end of file + diff --git a/archiva-indexer/pom.xml b/archiva-indexer/pom.xml index 1d1e9cb46..7bf3125cc 100644 --- a/archiva-indexer/pom.xml +++ b/archiva-indexer/pom.xml @@ -59,6 +59,10 @@ org.apache.maven.archiva archiva-utils + + org.codehaus.plexus + plexus-digest + org.apache.maven maven-repository-metadata diff --git a/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/AbstractArtifactIndexRecordFactory.java b/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/AbstractArtifactIndexRecordFactory.java index 4984bb745..4a9019df5 100644 --- a/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/AbstractArtifactIndexRecordFactory.java +++ b/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/AbstractArtifactIndexRecordFactory.java @@ -16,8 +16,8 @@ package org.apache.maven.archiva.indexer.record; * limitations under the License. */ -import org.apache.maven.archiva.digest.Digester; -import org.apache.maven.archiva.digest.DigesterException; +import org.codehaus.plexus.digest.Digester; +import org.codehaus.plexus.digest.DigesterException; import org.codehaus.plexus.logging.AbstractLogEnabled; import java.io.File; diff --git a/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/MinimalArtifactIndexRecordFactory.java b/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/MinimalArtifactIndexRecordFactory.java index 1c0062357..0c6c0b41f 100644 --- a/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/MinimalArtifactIndexRecordFactory.java +++ b/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/MinimalArtifactIndexRecordFactory.java @@ -16,8 +16,8 @@ package org.apache.maven.archiva.indexer.record; * limitations under the License. */ -import org.apache.maven.archiva.digest.Digester; import org.apache.maven.artifact.Artifact; +import org.codehaus.plexus.digest.Digester; import java.io.File; import java.io.IOException; diff --git a/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/StandardArtifactIndexRecordFactory.java b/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/StandardArtifactIndexRecordFactory.java index df25677e4..048143a23 100644 --- a/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/StandardArtifactIndexRecordFactory.java +++ b/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/StandardArtifactIndexRecordFactory.java @@ -16,7 +16,6 @@ package org.apache.maven.archiva.indexer.record; * limitations under the License. */ -import org.apache.maven.archiva.digest.Digester; import org.apache.maven.archiva.indexer.RepositoryIndexException; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; @@ -27,6 +26,7 @@ import org.apache.maven.model.Model; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.ProjectBuildingException; +import org.codehaus.plexus.digest.Digester; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.Xpp3DomBuilder; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; diff --git a/archiva-proxy/pom.xml b/archiva-proxy/pom.xml index 6f3bd7c91..4f7f03f4b 100644 --- a/archiva-proxy/pom.xml +++ b/archiva-proxy/pom.xml @@ -43,6 +43,10 @@ org.apache.maven.wagon wagon-provider-api + + org.codehaus.plexus + plexus-digest + easymock easymock diff --git a/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultProxyRequestHandler.java b/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultProxyRequestHandler.java index 0d19c3012..e0242794e 100644 --- a/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultProxyRequestHandler.java +++ b/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultProxyRequestHandler.java @@ -16,8 +16,6 @@ package org.apache.maven.archiva.proxy; * limitations under the License. */ -import org.apache.maven.archiva.digest.DigestUtils; -import org.apache.maven.archiva.digest.DigesterException; import org.apache.maven.archiva.discoverer.ArtifactDiscoverer; import org.apache.maven.archiva.discoverer.DiscovererException; import org.apache.maven.artifact.Artifact; @@ -40,6 +38,8 @@ import org.apache.maven.wagon.authorization.AuthorizationException; import org.apache.maven.wagon.observers.ChecksumObserver; import org.apache.maven.wagon.proxy.ProxyInfo; import org.apache.maven.wagon.repository.Repository; +import org.codehaus.plexus.digest.DigestUtils; +import org.codehaus.plexus.digest.DigesterException; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumArtifactReportProcessor.java index 776336d3f..245ccfd60 100644 --- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumArtifactReportProcessor.java +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumArtifactReportProcessor.java @@ -16,11 +16,11 @@ package org.apache.maven.archiva.reporting; * limitations under the License. */ -import org.apache.maven.archiva.digest.Digester; -import org.apache.maven.archiva.digest.DigesterException; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.model.Model; +import org.codehaus.plexus.digest.Digester; +import org.codehaus.plexus.digest.DigesterException; import org.codehaus.plexus.util.FileUtils; import java.io.File; diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReportProcessor.java index 7a2e57b21..0361d9928 100644 --- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReportProcessor.java +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReportProcessor.java @@ -16,10 +16,10 @@ package org.apache.maven.archiva.reporting; * limitations under the License. */ -import org.apache.maven.archiva.digest.Digester; -import org.apache.maven.archiva.digest.DigesterException; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import org.codehaus.plexus.digest.Digester; +import org.codehaus.plexus.digest.DigesterException; import org.codehaus.plexus.util.FileUtils; import java.io.File; diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessor.java index de12033d4..a05062d88 100644 --- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessor.java +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessor.java @@ -18,8 +18,6 @@ package org.apache.maven.archiva.reporting; import org.apache.lucene.index.Term; import org.apache.lucene.search.TermQuery; -import org.apache.maven.archiva.digest.Digester; -import org.apache.maven.archiva.digest.DigesterException; import org.apache.maven.archiva.indexer.RepositoryArtifactIndex; import org.apache.maven.archiva.indexer.RepositoryArtifactIndexFactory; import org.apache.maven.archiva.indexer.RepositoryIndexSearchException; @@ -29,6 +27,8 @@ import org.apache.maven.archiva.indexer.record.StandardIndexRecordFields; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.model.Model; +import org.codehaus.plexus.digest.Digester; +import org.codehaus.plexus.digest.DigesterException; import java.io.File; import java.util.Iterator; diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractChecksumArtifactReporterTestCase.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractChecksumArtifactReporterTestCase.java index bed4097ef..e7148fdf5 100644 --- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractChecksumArtifactReporterTestCase.java +++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractChecksumArtifactReporterTestCase.java @@ -16,8 +16,8 @@ package org.apache.maven.archiva.reporting; * limitations under the License. */ -import org.apache.maven.archiva.digest.Digester; -import org.apache.maven.archiva.digest.DigesterException; +import org.codehaus.plexus.digest.Digester; +import org.codehaus.plexus.digest.DigesterException; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ChecksumArtifactReporterTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ChecksumArtifactReporterTest.java index 27b7c7ff3..0830448ff 100644 --- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ChecksumArtifactReporterTest.java +++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ChecksumArtifactReporterTest.java @@ -16,13 +16,13 @@ package org.apache.maven.archiva.reporting; * limitations under the License. */ -import org.apache.maven.archiva.digest.DigesterException; import org.apache.maven.archiva.reporting.model.MetadataResults; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; +import org.codehaus.plexus.digest.DigesterException; import java.io.File; import java.io.IOException; diff --git a/archiva-reports-standard/src/test/resources/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessorTest.xml b/archiva-reports-standard/src/test/resources/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessorTest.xml index f0c16341f..bda4e9aca 100644 --- a/archiva-reports-standard/src/test/resources/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessorTest.xml +++ b/archiva-reports-standard/src/test/resources/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessorTest.xml @@ -23,7 +23,7 @@ org.apache.maven.archiva.reporting.DuplicateArtifactFileReportProcessor - org.apache.maven.archiva.digest.Digester + org.codehaus.plexus.digest.Digester md5 diff --git a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/AbstractDigester.java b/archiva-utils/src/main/java/org/apache/maven/archiva/digest/AbstractDigester.java deleted file mode 100644 index 3abc041d8..000000000 --- a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/AbstractDigester.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.apache.maven.archiva.digest; - -/* - * 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.IOUtil; -import org.codehaus.plexus.util.StringUtils; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.security.NoSuchAlgorithmException; - -/** - * Create a digest for a file. - * - * @author Brett Porter - */ -public abstract class AbstractDigester - implements Digester -{ - private final StreamingDigester streamingDigester; - - protected AbstractDigester( StreamingDigester streamingDigester ) - throws NoSuchAlgorithmException - { - this.streamingDigester = streamingDigester; - } - - public String getAlgorithm() - { - return streamingDigester.getAlgorithm(); - } - - public String calc( File file ) - throws DigesterException - { - FileInputStream fis = null; - try - { - fis = new FileInputStream( file ); - streamingDigester.reset(); - streamingDigester.update( fis ); - return streamingDigester.calc(); - } - catch ( IOException e ) - { - throw new DigesterException( "Unable to calculate the " + streamingDigester.getAlgorithm() + - " hashcode for " + file.getAbsolutePath() + ": " + e.getMessage(), e ); - } - finally - { - IOUtil.close( fis ); - } - } - - public void verify( File file, String checksum ) - throws DigesterException - { - String trimmedChecksum = - DigestUtils.cleanChecksum( checksum, streamingDigester.getAlgorithm(), file.getName() ); - - //Create checksum for jar file - String sum = calc( file ); - if ( !StringUtils.equalsIgnoreCase( trimmedChecksum, sum ) ) - { - throw new DigesterException( "Checksum failed" ); - } - } - - public String toString() - { - return "[Digester:" + streamingDigester.getAlgorithm() + "]"; - } -} diff --git a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/AbstractStreamingDigester.java b/archiva-utils/src/main/java/org/apache/maven/archiva/digest/AbstractStreamingDigester.java deleted file mode 100644 index 4852f6043..000000000 --- a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/AbstractStreamingDigester.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.apache.maven.archiva.digest; - -/* - * 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 java.io.IOException; -import java.io.InputStream; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -/** - * Gradually create a digest for a stream. - * - * @author Brett Porter - */ -public abstract class AbstractStreamingDigester - implements StreamingDigester -{ - protected final MessageDigest md; - - private static final char[] HEX_CHARS = "0123456789ABCDEF".toCharArray(); - - private static final int HI_MASK = 0xF0; - - private static final int LO_MASK = 0x0F; - - private static final int BUFFER_SIZE = 32768; - - protected AbstractStreamingDigester( String algorithm ) - throws NoSuchAlgorithmException - { - md = MessageDigest.getInstance( algorithm ); - } - - public String getAlgorithm() - { - return md.getAlgorithm(); - } - - public String calc() - throws DigesterException - { - return calc( this.md ); - } - - public void reset() - throws DigesterException - { - md.reset(); - } - - public void update( InputStream is ) - throws DigesterException - { - update( is, md ); - } - - protected static String calc( MessageDigest md ) - { - byte[] digest = md.digest(); - - char[] hash = new char[digest.length * 2]; - for ( int i = 0; i < digest.length; i++ ) - { - hash[i * 2] = HEX_CHARS[( digest[i] & HI_MASK ) >> 4]; - hash[i * 2 + 1] = HEX_CHARS[( digest[i] & LO_MASK )]; - } - return new String( hash ); - } - - protected static void update( InputStream is, MessageDigest digest ) - throws DigesterException - { - try - { - byte[] buffer = new byte[BUFFER_SIZE]; - int size = is.read( buffer, 0, BUFFER_SIZE ); - while ( size >= 0 ) - { - digest.update( buffer, 0, size ); - size = is.read( buffer, 0, BUFFER_SIZE ); - } - } - catch ( IOException e ) - { - throw new DigesterException( "Unable to update " + digest.getAlgorithm() + " hash: " + e.getMessage(), e ); - } - } -} diff --git a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/DigestUtils.java b/archiva-utils/src/main/java/org/apache/maven/archiva/digest/DigestUtils.java deleted file mode 100644 index 8cb659f2a..000000000 --- a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/DigestUtils.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.apache.maven.archiva.digest; - -/* - * 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 java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Parse files from checksum file formats. - * - * @author Brett Porter - */ -public class DigestUtils -{ - private DigestUtils() - { - // don't create this class - } - - public static String cleanChecksum( String checksum, String algorithm, String path ) - throws DigesterException - { - String trimmedChecksum = checksum.replace( '\n', ' ' ).trim(); - - // Free-BSD / openssl - String regex = algorithm.replaceAll( "-", "" ) + "\\s*\\((.*?)\\)\\s*=\\s*([a-fA-F0-9]+)"; - Matcher m = Pattern.compile( regex ).matcher( trimmedChecksum ); - if ( m.matches() ) - { - String filename = m.group( 1 ); - if ( !filename.endsWith( path ) ) - { - throw new DigesterException( "Supplied checksum does not match checksum pattern" ); - } - trimmedChecksum = m.group( 2 ); - } - else - { - // GNU tools - m = Pattern.compile( "([a-fA-F0-9]+)\\s\\*?(.+)" ).matcher( trimmedChecksum ); - if ( m.matches() ) - { - String filename = m.group( 2 ); - if ( !filename.endsWith( path ) ) - { - throw new DigesterException( "Supplied checksum does not match checksum pattern" ); - } - trimmedChecksum = m.group( 1 ); - } - } - return trimmedChecksum; - } -} diff --git a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/Digester.java b/archiva-utils/src/main/java/org/apache/maven/archiva/digest/Digester.java deleted file mode 100644 index 231fa5527..000000000 --- a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/Digester.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.apache.maven.archiva.digest; - -/* - * 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 java.io.File; - -/** - * Create a digest for a file. - * - * @author Brett Porter - */ -public interface Digester -{ - String ROLE = Digester.class.getName(); - - /** - * Get the algorithm used for the checksum. - * - * @return the algorithm - */ - String getAlgorithm(); - - /** - * Calculate a checksum for a file. - * - * @param file the file to calculate the checksum for - * @return the current checksum. - * @throws DigesterException if there was a problem computing the hashcode. - */ - String calc( File file ) - throws DigesterException; - - /** - * Verify that a checksum is correct. - * - * @param file the file to compute the checksum for - * @param checksum the checksum to compare to - * @throws DigesterException if there was a problem computing the hashcode. - */ - void verify( File file, String checksum ) - throws DigesterException; -} diff --git a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/DigesterException.java b/archiva-utils/src/main/java/org/apache/maven/archiva/digest/DigesterException.java deleted file mode 100644 index 6391d8c8b..000000000 --- a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/DigesterException.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apache.maven.archiva.digest; - -/* - * 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 Edwin Punzalan - */ -public class DigesterException - extends Exception -{ - public DigesterException( String message ) - { - super( message ); - } - - public DigesterException( String message, Throwable cause ) - { - super( message, cause ); - } -} diff --git a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/Md5Digester.java b/archiva-utils/src/main/java/org/apache/maven/archiva/digest/Md5Digester.java deleted file mode 100644 index 22e4a008b..000000000 --- a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/Md5Digester.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apache.maven.archiva.digest; - -/* - * 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 java.security.NoSuchAlgorithmException; - -/** - * Digester that does MD5 Message Digesting Only. - * - * @plexus.component role="org.apache.maven.archiva.digest.Digester" role-hint="md5" - */ -public class Md5Digester - extends AbstractDigester -{ - public Md5Digester() - throws NoSuchAlgorithmException - { - super( new StreamingMd5Digester() ); - } -} diff --git a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/Sha1Digester.java b/archiva-utils/src/main/java/org/apache/maven/archiva/digest/Sha1Digester.java deleted file mode 100644 index 4c883479e..000000000 --- a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/Sha1Digester.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apache.maven.archiva.digest; - -/* - * 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 java.security.NoSuchAlgorithmException; - -/** - * Digester that does SHA1 Message Digesting Only. - * - * @plexus.component role="org.apache.maven.archiva.digest.Digester" role-hint="sha1" - */ -public class Sha1Digester - extends AbstractDigester -{ - public Sha1Digester() - throws NoSuchAlgorithmException - { - super( new StreamingSha1Digester() ); - } -} diff --git a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/StreamingDigester.java b/archiva-utils/src/main/java/org/apache/maven/archiva/digest/StreamingDigester.java deleted file mode 100644 index d2cf2886d..000000000 --- a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/StreamingDigester.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.apache.maven.archiva.digest; - -/* - * 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 java.io.InputStream; - -/** - * Gradually create a digest for a stream. - * - * @author Brett Porter - */ -public interface StreamingDigester -{ - String ROLE = StreamingDigester.class.getName(); - - /** - * Get the algorithm used for the checksum. - * - * @return the algorithm - */ - String getAlgorithm(); - - /** - * Reset the hashcode calculation algorithm. - * Only useful when performing incremental hashcodes based on repeated use of {@link #update(InputStream)} - * - * @throws DigesterException if there was a problem with the internal message digest - */ - void reset() - throws DigesterException; - - /** - * Calculate the current checksum. - * - * @return the current checksum. - * @throws DigesterException if there was a problem computing the hashcode. - */ - String calc() - throws DigesterException; - - /** - * Update the checksum with the content of the input stream. - * - * @param is the input stream - * @throws DigesterException if there was a problem computing the hashcode. - */ - void update( InputStream is ) - throws DigesterException; - -} diff --git a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/StreamingMd5Digester.java b/archiva-utils/src/main/java/org/apache/maven/archiva/digest/StreamingMd5Digester.java deleted file mode 100644 index 10c0ba14e..000000000 --- a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/StreamingMd5Digester.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apache.maven.archiva.digest; - -/* - * 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 java.security.NoSuchAlgorithmException; - -/** - * An MD5 implementation of the streaming digester. - * - * @author Brett Porter - * @plexus.component role="org.apache.maven.archiva.digest.StreamingDigester" role-hint="md5" - */ -public class StreamingMd5Digester - extends AbstractStreamingDigester -{ - public StreamingMd5Digester() - throws NoSuchAlgorithmException - { - super( "MD5" ); - } -} diff --git a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/StreamingSha1Digester.java b/archiva-utils/src/main/java/org/apache/maven/archiva/digest/StreamingSha1Digester.java deleted file mode 100644 index 253a83133..000000000 --- a/archiva-utils/src/main/java/org/apache/maven/archiva/digest/StreamingSha1Digester.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apache.maven.archiva.digest; - -/* - * 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 java.security.NoSuchAlgorithmException; - -/** - * An SHA-1 implementation of the streaming digester. - * - * @author Brett Porter - * @plexus.component role="org.apache.maven.archiva.digest.StreamingDigester" role-hint="sha1" - */ -public class StreamingSha1Digester - extends AbstractStreamingDigester -{ - public StreamingSha1Digester() - throws NoSuchAlgorithmException - { - super( "SHA-1" ); - } -} diff --git a/archiva-utils/src/test/java/org/apache/maven/archiva/digest/DigestUtilsTest.java b/archiva-utils/src/test/java/org/apache/maven/archiva/digest/DigestUtilsTest.java deleted file mode 100644 index c4deb5d99..000000000 --- a/archiva-utils/src/test/java/org/apache/maven/archiva/digest/DigestUtilsTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apache.maven.archiva.digest; - -/* - * 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 junit.framework.TestCase; - -public class DigestUtilsTest - extends TestCase -{ - public void testCleanChecksum() - throws DigesterException - { - // SHA1 checksum from www.ibiblio.org/maven2, incuding file path - DigestUtils.cleanChecksum( - "bcc82975c0f9c681fcb01cc38504c992553e93ba /home/projects/maven/repository-staging/to-ibiblio/maven2/servletapi/servletapi/2.4/servletapi-2.4.pom", - "SHA1", "servletapi/servletapi/2.4/servletapi-2.4.pom" ); - - DigestUtils.cleanChecksum( - "SHA1(/home/projects/maven/repository-staging/to-ibiblio/maven2/servletapi/servletapi/2.4/servletapi-2.4.pom)=bcc82975c0f9c681fcb01cc38504c992553e93ba", - "SHA1", "servletapi/servletapi/2.4/servletapi-2.4.pom" ); - } -} diff --git a/archiva-utils/src/test/java/org/apache/maven/archiva/digest/DigesterTest.java b/archiva-utils/src/test/java/org/apache/maven/archiva/digest/DigesterTest.java deleted file mode 100644 index 4e9a9782a..000000000 --- a/archiva-utils/src/test/java/org/apache/maven/archiva/digest/DigesterTest.java +++ /dev/null @@ -1,229 +0,0 @@ -package org.apache.maven.archiva.digest; - -/* - * 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.PlexusTestCase; - -import java.io.File; -import java.io.IOException; -import java.security.NoSuchAlgorithmException; - -/** - * Test the digester. - * - * @author Brett Porter - */ -public class DigesterTest - extends PlexusTestCase -{ - private static final String MD5 = "adbc688ce77fa2aece4bb72cad9f98ba"; - - private static final String SHA1 = "2a7b459938e12a2dc35d1bf6cff35e9c2b592fa9"; - - private static final String WRONG_SHA1 = "4d8703779816556cdb8be7f6bb5c954f4b5730e2"; - - private Digester sha1Digest; - - private Digester md5Digest; - - protected void setUp() - throws Exception - { - super.setUp(); - - sha1Digest = (Digester) lookup( Digester.ROLE, "sha1" ); - md5Digest = (Digester) lookup( Digester.ROLE, "md5" ); - } - - public void testAlgorithm() - { - assertEquals( "SHA-1", sha1Digest.getAlgorithm() ); - assertEquals( "MD5", md5Digest.getAlgorithm() ); - } - - public void testBareDigestFormat() - throws DigesterException, IOException - { - File file = new File( getClass().getResource( "/test-file.txt" ).getPath() ); - - try - { - md5Digest.verify( file, MD5 ); - } - catch ( DigesterException e ) - { - fail( "Bare format MD5 must not throw exception" ); - } - - try - { - sha1Digest.verify( file, SHA1 ); - } - catch ( DigesterException e ) - { - fail( "Bare format SHA1 must not throw exception" ); - } - - try - { - sha1Digest.verify( file, WRONG_SHA1 ); - fail( "wrong checksum must throw an exception" ); - } - catch ( DigesterException e ) - { - //expected - } - } - - public void testOpensslDigestFormat() - throws IOException, DigesterException - { - File file = new File( getClass().getResource( "/test-file.txt" ).getPath() ); - - try - { - md5Digest.verify( file, "MD5(test-file.txt)= " + MD5 ); - } - catch ( DigesterException e ) - { - fail( "OpenSSL MD5 format must not cause exception" ); - } - - try - { - md5Digest.verify( file, "MD5 (test-file.txt) = " + MD5 ); - } - catch ( DigesterException e ) - { - fail( "FreeBSD MD5 format must not cause exception" ); - } - - try - { - sha1Digest.verify( file, "SHA1(test-file.txt)= " + SHA1 ); - } - catch ( DigesterException e ) - { - fail( "OpenSSL SHA1 format must not cause exception" ); - } - - try - { - sha1Digest.verify( file, "SHA1 (test-file.txt) = " + SHA1 ); - } - catch ( DigesterException e ) - { - fail( "FreeBSD SHA1 format must not cause exception" ); - } - - try - { - sha1Digest.verify( file, "SHA1 (FOO) = " + SHA1 ); - fail( "Wrong filename should cause an exception" ); - } - catch ( DigesterException e ) - { - //expected - } - - try - { - sha1Digest.verify( file, "SHA1 (test-file.txt) = " + WRONG_SHA1 ); - fail( "Wrong sha1 should cause an exception" ); - } - catch ( DigesterException e ) - { - //expected - } - } - - public void testGnuDigestFormat() - throws NoSuchAlgorithmException, IOException, DigesterException - { - File file = new File( getClass().getResource( "/test-file.txt" ).getPath() ); - - try - { - md5Digest.verify( file, MD5 + " *test-file.txt" ); - } - catch ( DigesterException e ) - { - fail( "GNU format MD5 must not cause exception" ); - } - - try - { - md5Digest.verify( file, MD5 + " test-file.txt" ); - } - catch ( DigesterException e ) - { - fail( "GNU text format MD5 must not cause exception" ); - } - - try - { - sha1Digest.verify( file, SHA1 + " *test-file.txt" ); - } - catch ( DigesterException e ) - { - fail( "GNU format SHA1 must not cause exception" ); - } - - try - { - sha1Digest.verify( file, SHA1 + " test-file.txt" ); - } - catch ( DigesterException e ) - { - fail( "GNU text format SHA1 must not cause exception" ); - } - - try - { - sha1Digest.verify( file, SHA1 + " FOO" ); - fail( "Wrong filename cause an exception" ); - } - catch ( DigesterException e ) - { - //expected - } - - try - { - sha1Digest.verify( file, WRONG_SHA1 + " test-file.txt" ); - fail( "Wrong SHA1 cause an exception" ); - } - catch ( DigesterException e ) - { - //expected - } - } - - public void testUntrimmedContent() - throws NoSuchAlgorithmException, IOException - { - File file = new File( getClass().getResource( "/test-file.txt" ).getPath() ); - try - { - sha1Digest.verify( file, SHA1 + " *test-file.txt \n" ); - } - catch ( DigesterException e ) - { - fail( "GNU untrimmed SHA1 must not cause exception" ); - } - } -} diff --git a/pom.xml b/pom.xml index d6522c9ae..f2d6bc4c7 100644 --- a/pom.xml +++ b/pom.xml @@ -259,6 +259,11 @@ archiva-converter ${pom.version} + + org.codehaus.plexus + plexus-digest + 1.0-SNAPSHOT + org.codehaus.plexus.security plexus-security-rbac-profile -- 2.39.5