From: Olivier Lamy Date: Thu, 6 Oct 2011 14:13:37 +0000 (+0000) Subject: fix spring annotations for missing checksum consumer X-Git-Tag: archiva-1.4-M1~66 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d66e72fcd20e441b71e4f36d0fa11e71b731da51;p=archiva.git fix spring annotations for missing checksum consumer git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1179635 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java index e9a665451..98ca53f98 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java @@ -34,6 +34,7 @@ import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; +import javax.inject.Inject; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -45,15 +46,15 @@ import java.util.List; * * @version $Id$ */ -@Service("knownRepositoryContentConsumer#create-missing-checksums") -@Scope("prototype") +@Service( "knownRepositoryContentConsumer#create-missing-checksums" ) +@Scope( "prototype" ) public class ArtifactMissingChecksumsConsumer extends AbstractMonitoredConsumer implements KnownRepositoryContentConsumer, RegistryListener -{ - private String id; +{ + private String id = "create-missing-checksums"; - private String description; + private String description = "Create Missing and/or Fix Invalid Checksums (.sha1, .md5)"; private ArchivaConfiguration configuration; @@ -62,40 +63,38 @@ public class ArtifactMissingChecksumsConsumer private ChecksummedFile checksum; private static final String TYPE_CHECKSUM_NOT_FILE = "checksum-bad-not-file"; - + private static final String TYPE_CHECKSUM_CANNOT_CALC = "checksum-calc-failure"; - + private static final String TYPE_CHECKSUM_CANNOT_CREATE = "checksum-create-failure"; private File repositoryDir; - - private List includes = new ArrayList(); - - public ArtifactMissingChecksumsConsumer(String id, - String description, - ArchivaConfiguration configuration, - FileTypes filetypes) { - this.id = id; - this.description = description; + + private List includes = new ArrayList( ); + + @Inject + public ArtifactMissingChecksumsConsumer( ArchivaConfiguration configuration, + FileTypes filetypes ) + { this.configuration = configuration; this.filetypes = filetypes; configuration.addChangeListener( this ); - initIncludes(); + initIncludes( ); } - public String getId() + public String getId( ) { return this.id; } - public String getDescription() + public String getDescription( ) { return this.description; } - public boolean isPermanent() + public boolean isPermanent( ) { return false; } @@ -103,7 +102,7 @@ public class ArtifactMissingChecksumsConsumer public void beginScan( ManagedRepository repo, Date whenGathered ) throws ConsumerException { - this.repositoryDir = new File( repo.getLocation() ); + this.repositoryDir = new File( repo.getLocation( ) ); } public void beginScan( ManagedRepository repo, Date whenGathered, boolean executeOnEntireRepo ) @@ -112,22 +111,22 @@ public class ArtifactMissingChecksumsConsumer beginScan( repo, whenGathered ); } - public void completeScan() + public void completeScan( ) { /* do nothing */ } public void completeScan( boolean executeOnEntireRepo ) { - completeScan(); + completeScan( ); } - public List getExcludes() + public List getExcludes( ) { - return getDefaultArtifactExclusions(); + return getDefaultArtifactExclusions( ); } - public List getIncludes() + public List getIncludes( ) { return includes; } @@ -135,64 +134,64 @@ public class ArtifactMissingChecksumsConsumer public void processFile( String path ) throws ConsumerException { - createFixChecksum( path, new ChecksumAlgorithm[] { ChecksumAlgorithm.SHA1 } ); - createFixChecksum( path, new ChecksumAlgorithm[] { ChecksumAlgorithm.MD5 } ); + createFixChecksum( path, new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1 } ); + createFixChecksum( path, new ChecksumAlgorithm[]{ ChecksumAlgorithm.MD5 } ); } public void processFile( String path, boolean executeOnEntireRepo ) throws ConsumerException { - processFile( path ); + processFile( path ); } - + private void createFixChecksum( String path, ChecksumAlgorithm checksumAlgorithm[] ) { File artifactFile = new File( this.repositoryDir, path ); - File checksumFile = new File( this.repositoryDir, path + checksumAlgorithm[0].getExt() ); - - if( checksumFile.exists() ) + File checksumFile = new File( this.repositoryDir, path + checksumAlgorithm[0].getExt( ) ); + + if ( checksumFile.exists( ) ) { checksum = new ChecksummedFile( artifactFile ); try { - if( !checksum.isValidChecksum( checksumAlgorithm[0] ) ) - { + if ( !checksum.isValidChecksum( checksumAlgorithm[0] ) ) + { checksum.fixChecksums( checksumAlgorithm ); - triggerConsumerInfo( "Fixed checksum file " + checksumFile.getAbsolutePath() ); + triggerConsumerInfo( "Fixed checksum file " + checksumFile.getAbsolutePath( ) ); } } catch ( IOException e ) { triggerConsumerError( TYPE_CHECKSUM_CANNOT_CALC, "Cannot calculate checksum for file " + checksumFile + - ": " + e.getMessage() ); + ": " + e.getMessage( ) ); } } - else if( !checksumFile.exists() ) - { + else if ( !checksumFile.exists( ) ) + { checksum = new ChecksummedFile( artifactFile ); try { checksum.createChecksum( checksumAlgorithm[0] ); - triggerConsumerInfo( "Created missing checksum file " + checksumFile.getAbsolutePath() ); + triggerConsumerInfo( "Created missing checksum file " + checksumFile.getAbsolutePath( ) ); } catch ( IOException e ) { triggerConsumerError( TYPE_CHECKSUM_CANNOT_CREATE, "Cannot create checksum for file " + checksumFile + - ": " + e.getMessage() ); + ": " + e.getMessage( ) ); } } else { triggerConsumerWarning( TYPE_CHECKSUM_NOT_FILE, - "Checksum file " + checksumFile.getAbsolutePath() + " is not a file." ); + "Checksum file " + checksumFile.getAbsolutePath( ) + " is not a file." ); } } public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) - { + { if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) { - initIncludes(); + initIncludes( ); } } @@ -201,18 +200,18 @@ public class ArtifactMissingChecksumsConsumer /* do nothing */ } - private void initIncludes() + private void initIncludes( ) { - includes.clear(); + includes.clear( ); includes.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) ); } @PostConstruct - public void initialize() + public void initialize( ) { configuration.addChangeListener( this ); - - initIncludes(); + + initIncludes( ); } } diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/resources/META-INF/spring-context.xml index db3b65468..6c1ec14a4 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/resources/META-INF/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/resources/META-INF/spring-context.xml @@ -30,19 +30,4 @@ - - - create-missing-checksums - - - Create Missing and/or Fix Invalid Checksums (.sha1, .md5) - - - - - - - - - \ No newline at end of file