Reformat code

This commit is contained in:
Martin Stockhammer 2017-08-27 16:18:57 +02:00
parent c50c6d5e3f
commit a015600d48
12 changed files with 240 additions and 246 deletions

View File

@ -82,17 +82,17 @@ public class ArtifactMissingChecksumsConsumer
//configuration.addChangeListener( this ); //configuration.addChangeListener( this );
initIncludes(); initIncludes( );
} }
@Override @Override
public String getId() public String getId( )
{ {
return this.id; return this.id;
} }
@Override @Override
public String getDescription() public String getDescription( )
{ {
return this.description; return this.description;
} }
@ -101,7 +101,7 @@ public class ArtifactMissingChecksumsConsumer
public void beginScan( ManagedRepository repo, Date whenGathered ) public void beginScan( ManagedRepository repo, Date whenGathered )
throws ConsumerException throws ConsumerException
{ {
this.repositoryDir = new File( repo.getLocation() ); this.repositoryDir = new File( repo.getLocation( ) );
} }
@Override @Override
@ -112,7 +112,7 @@ public class ArtifactMissingChecksumsConsumer
} }
@Override @Override
public void completeScan() public void completeScan( )
{ {
/* do nothing */ /* do nothing */
} }
@ -120,17 +120,17 @@ public class ArtifactMissingChecksumsConsumer
@Override @Override
public void completeScan( boolean executeOnEntireRepo ) public void completeScan( boolean executeOnEntireRepo )
{ {
completeScan(); completeScan( );
} }
@Override @Override
public List<String> getExcludes() public List<String> getExcludes( )
{ {
return getDefaultArtifactExclusions(); return getDefaultArtifactExclusions( );
} }
@Override @Override
public List<String> getIncludes() public List<String> getIncludes( )
{ {
return includes; return includes;
} }
@ -153,48 +153,48 @@ public class ArtifactMissingChecksumsConsumer
private void createFixChecksum( String path, ChecksumAlgorithm checksumAlgorithm ) private void createFixChecksum( String path, ChecksumAlgorithm checksumAlgorithm )
{ {
File artifactFile = new File( this.repositoryDir, path ); File artifactFile = new File( this.repositoryDir, path );
File checksumFile = new File( this.repositoryDir, path + "." + checksumAlgorithm.getExt() ); File checksumFile = new File( this.repositoryDir, path + "." + checksumAlgorithm.getExt( ) );
if ( checksumFile.exists() ) if ( checksumFile.exists( ) )
{ {
checksum = new ChecksummedFile( artifactFile ); checksum = new ChecksummedFile( artifactFile );
try try
{ {
if ( !checksum.isValidChecksum( checksumAlgorithm ) ) if ( !checksum.isValidChecksum( checksumAlgorithm ) )
{ {
checksum.fixChecksums( new ChecksumAlgorithm[]{ checksumAlgorithm } ); checksum.fixChecksums( new ChecksumAlgorithm[]{checksumAlgorithm} );
log.info( "Fixed checksum file {}", checksumFile.getAbsolutePath() ); log.info( "Fixed checksum file {}", checksumFile.getAbsolutePath( ) );
triggerConsumerInfo( "Fixed checksum file " + checksumFile.getAbsolutePath() ); triggerConsumerInfo( "Fixed checksum file " + checksumFile.getAbsolutePath( ) );
} }
} }
catch ( IOException e ) catch ( IOException e )
{ {
log.error( "Cannot calculate checksum for file {} :", checksumFile, e ); log.error( "Cannot calculate checksum for file {} :", checksumFile, e );
triggerConsumerError( TYPE_CHECKSUM_CANNOT_CALC, "Cannot calculate checksum for file " + checksumFile + 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 ); checksum = new ChecksummedFile( artifactFile );
try try
{ {
checksum.createChecksum( checksumAlgorithm ); checksum.createChecksum( checksumAlgorithm );
log.info( "Created missing checksum file {}", checksumFile.getAbsolutePath() ); log.info( "Created missing checksum file {}", checksumFile.getAbsolutePath( ) );
triggerConsumerInfo( "Created missing checksum file " + checksumFile.getAbsolutePath() ); triggerConsumerInfo( "Created missing checksum file " + checksumFile.getAbsolutePath( ) );
} }
catch ( IOException e ) catch ( IOException e )
{ {
log.error( "Cannot create checksum for file {} :", checksumFile, e ); log.error( "Cannot create checksum for file {} :", checksumFile, e );
triggerConsumerError( TYPE_CHECKSUM_CANNOT_CREATE, "Cannot create checksum for file " + checksumFile + triggerConsumerError( TYPE_CHECKSUM_CANNOT_CREATE, "Cannot create checksum for file " + checksumFile +
": " + e.getMessage() ); ": " + e.getMessage( ) );
} }
} }
else else
{ {
log.warn( "Checksum file {} is not a file. ", checksumFile.getAbsolutePath() ); log.warn( "Checksum file {} is not a file. ", checksumFile.getAbsolutePath( ) );
triggerConsumerWarning( TYPE_CHECKSUM_NOT_FILE, triggerConsumerWarning( TYPE_CHECKSUM_NOT_FILE,
"Checksum file " + checksumFile.getAbsolutePath() + " is not a file." ); "Checksum file " + checksumFile.getAbsolutePath( ) + " is not a file." );
} }
} }
@ -217,17 +217,17 @@ public class ArtifactMissingChecksumsConsumer
*/ */
private void initIncludes() private void initIncludes( )
{ {
includes = new ArrayList<>( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) ); includes = new ArrayList<>( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) );
} }
@PostConstruct @PostConstruct
public void initialize() public void initialize( )
{ {
//configuration.addChangeListener( this ); //configuration.addChangeListener( this );
initIncludes(); initIncludes( );
} }
} }

View File

@ -42,8 +42,6 @@ import java.util.List;
/** /**
* AutoRemoveConsumer * AutoRemoveConsumer
*
*
*/ */
@Service( "knownRepositoryContentConsumer#auto-remove" ) @Service( "knownRepositoryContentConsumer#auto-remove" )
@Scope( "prototype" ) @Scope( "prototype" )
@ -81,13 +79,13 @@ public class AutoRemoveConsumer
private List<String> includes = new ArrayList<>( 0 ); private List<String> includes = new ArrayList<>( 0 );
@Override @Override
public String getId() public String getId( )
{ {
return this.id; return this.id;
} }
@Override @Override
public String getDescription() public String getDescription( )
{ {
return this.description; return this.description;
} }
@ -96,7 +94,7 @@ public class AutoRemoveConsumer
public void beginScan( ManagedRepository repository, Date whenGathered ) public void beginScan( ManagedRepository repository, Date whenGathered )
throws ConsumerException throws ConsumerException
{ {
this.repositoryDir = new File( repository.getLocation() ); this.repositoryDir = new File( repository.getLocation( ) );
} }
@Override @Override
@ -107,7 +105,7 @@ public class AutoRemoveConsumer
} }
@Override @Override
public void completeScan() public void completeScan( )
{ {
/* do nothing */ /* do nothing */
} }
@ -115,17 +113,17 @@ public class AutoRemoveConsumer
@Override @Override
public void completeScan( boolean executeOnEntireRepo ) public void completeScan( boolean executeOnEntireRepo )
{ {
completeScan(); completeScan( );
} }
@Override @Override
public List<String> getExcludes() public List<String> getExcludes( )
{ {
return null; return null;
} }
@Override @Override
public List<String> getIncludes() public List<String> getIncludes( )
{ {
return includes; return includes;
} }
@ -135,11 +133,11 @@ public class AutoRemoveConsumer
throws ConsumerException throws ConsumerException
{ {
File file = new File( this.repositoryDir, path ); File file = new File( this.repositoryDir, path );
if ( file.exists() ) if ( file.exists( ) )
{ {
log.info( "(Auto) Removing File: {}", file.getAbsolutePath() ); log.info( "(Auto) Removing File: {}", file.getAbsolutePath( ) );
triggerConsumerInfo( "(Auto) Removing File: " + file.getAbsolutePath() ); triggerConsumerInfo( "(Auto) Removing File: " + file.getAbsolutePath( ) );
file.delete(); file.delete( );
} }
} }
@ -155,7 +153,7 @@ public class AutoRemoveConsumer
{ {
if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) if ( ConfigurationNames.isRepositoryScanning( propertyName ) )
{ {
initIncludes(); initIncludes( );
} }
} }
@ -165,16 +163,16 @@ public class AutoRemoveConsumer
/* do nothing */ /* do nothing */
} }
private void initIncludes() private void initIncludes( )
{ {
includes = new ArrayList<>( filetypes.getFileTypePatterns( FileTypes.AUTO_REMOVE ) ); includes = new ArrayList<>( filetypes.getFileTypePatterns( FileTypes.AUTO_REMOVE ) );
} }
@PostConstruct @PostConstruct
public void initialize() public void initialize( )
{ {
configuration.addChangeListener( this ); configuration.addChangeListener( this );
initIncludes(); initIncludes( );
} }
} }

View File

@ -40,8 +40,6 @@ import java.util.Map;
/** /**
* AutoRenameConsumer * AutoRenameConsumer
*
*
*/ */
@Service( "knownRepositoryContentConsumer#auto-rename" ) @Service( "knownRepositoryContentConsumer#auto-rename" )
@Scope( "prototype" ) @Scope( "prototype" )
@ -61,9 +59,9 @@ public class AutoRenameConsumer
private List<String> includes = new ArrayList<>( 3 ); private List<String> includes = new ArrayList<>( 3 );
private Map<String, String> extensionRenameMap = new HashMap<>(); private Map<String, String> extensionRenameMap = new HashMap<>( );
public AutoRenameConsumer() public AutoRenameConsumer( )
{ {
includes.add( "**/*.distribution-tgz" ); includes.add( "**/*.distribution-tgz" );
includes.add( "**/*.distribution-zip" ); includes.add( "**/*.distribution-zip" );
@ -75,13 +73,13 @@ public class AutoRenameConsumer
} }
@Override @Override
public String getId() public String getId( )
{ {
return this.id; return this.id;
} }
@Override @Override
public String getDescription() public String getDescription( )
{ {
return this.description; return this.description;
} }
@ -90,7 +88,7 @@ public class AutoRenameConsumer
public void beginScan( ManagedRepository repository, Date whenGathered ) public void beginScan( ManagedRepository repository, Date whenGathered )
throws ConsumerException throws ConsumerException
{ {
this.repositoryDir = new File( repository.getLocation() ); this.repositoryDir = new File( repository.getLocation( ) );
} }
@Override @Override
@ -101,7 +99,7 @@ public class AutoRenameConsumer
} }
@Override @Override
public void completeScan() public void completeScan( )
{ {
/* do nothing */ /* do nothing */
} }
@ -109,17 +107,17 @@ public class AutoRenameConsumer
@Override @Override
public void completeScan( boolean executeOnEntireRepo ) public void completeScan( boolean executeOnEntireRepo )
{ {
completeScan(); completeScan( );
} }
@Override @Override
public List<String> getExcludes() public List<String> getExcludes( )
{ {
return null; return null;
} }
@Override @Override
public List<String> getIncludes() public List<String> getIncludes( )
{ {
return includes; return includes;
} }
@ -129,16 +127,16 @@ public class AutoRenameConsumer
throws ConsumerException throws ConsumerException
{ {
File file = new File( this.repositoryDir, path ); File file = new File( this.repositoryDir, path );
if ( file.exists() ) if ( file.exists( ) )
{ {
Iterator<String> itExtensions = this.extensionRenameMap.keySet().iterator(); Iterator<String> itExtensions = this.extensionRenameMap.keySet( ).iterator( );
while ( itExtensions.hasNext() ) while ( itExtensions.hasNext( ) )
{ {
String extension = itExtensions.next(); String extension = itExtensions.next( );
if ( path.endsWith( extension ) ) if ( path.endsWith( extension ) )
{ {
String fixedExtension = this.extensionRenameMap.get( extension ); String fixedExtension = this.extensionRenameMap.get( extension );
String correctedPath = path.substring( 0, path.length() - extension.length() ) + fixedExtension; String correctedPath = path.substring( 0, path.length( ) - extension.length( ) ) + fixedExtension;
File to = new File( this.repositoryDir, correctedPath ); File to = new File( this.repositoryDir, correctedPath );
try try
{ {
@ -149,14 +147,14 @@ public class AutoRenameConsumer
{ {
log.warn( "Unable to rename {} to {} :", path, correctedPath, e ); log.warn( "Unable to rename {} to {} :", path, correctedPath, e );
triggerConsumerWarning( RENAME_FAILURE, "Unable to rename " + path + " to " + correctedPath + triggerConsumerWarning( RENAME_FAILURE, "Unable to rename " + path + " to " + correctedPath +
": " + e.getMessage() ); ": " + e.getMessage( ) );
} }
} }
} }
log.info( "(Auto) Removing File: {} ", file.getAbsolutePath() ); log.info( "(Auto) Removing File: {} ", file.getAbsolutePath( ) );
triggerConsumerInfo( "(Auto) Removing File: " + file.getAbsolutePath() ); triggerConsumerInfo( "(Auto) Removing File: " + file.getAbsolutePath( ) );
file.delete(); file.delete( );
} }
} }

View File

@ -51,8 +51,6 @@ import java.util.List;
/** /**
* MetadataUpdaterConsumer will create and update the metadata present within the repository. * MetadataUpdaterConsumer will create and update the metadata present within the repository.
*
*
*/ */
@Service( "knownRepositoryContentConsumer#metadata-updater" ) @Service( "knownRepositoryContentConsumer#metadata-updater" )
@Scope( "prototype" ) @Scope( "prototype" )
@ -98,13 +96,13 @@ public class MetadataUpdaterConsumer
private long scanStartTimestamp = 0; private long scanStartTimestamp = 0;
@Override @Override
public String getDescription() public String getDescription( )
{ {
return description; return description;
} }
@Override @Override
public String getId() public String getId( )
{ {
return id; return id;
} }
@ -120,17 +118,17 @@ public class MetadataUpdaterConsumer
{ {
try try
{ {
this.repository = repositoryFactory.getManagedRepositoryContent( repoConfig.getId() ); this.repository = repositoryFactory.getManagedRepositoryContent( repoConfig.getId( ) );
this.repositoryDir = new File( repository.getRepoRoot() ); this.repositoryDir = new File( repository.getRepoRoot( ) );
this.scanStartTimestamp = System.currentTimeMillis(); this.scanStartTimestamp = System.currentTimeMillis( );
} }
catch ( RepositoryNotFoundException e ) catch ( RepositoryNotFoundException e )
{ {
throw new ConsumerException( e.getMessage(), e ); throw new ConsumerException( e.getMessage( ), e );
} }
catch ( RepositoryException e ) catch ( RepositoryException e )
{ {
throw new ConsumerException( e.getMessage(), e ); throw new ConsumerException( e.getMessage( ), e );
} }
} }
@ -142,7 +140,7 @@ public class MetadataUpdaterConsumer
} }
@Override @Override
public void completeScan() public void completeScan( )
{ {
/* do nothing here */ /* do nothing here */
} }
@ -150,17 +148,17 @@ public class MetadataUpdaterConsumer
@Override @Override
public void completeScan( boolean executeOnEntireRepo ) public void completeScan( boolean executeOnEntireRepo )
{ {
completeScan(); completeScan( );
} }
@Override @Override
public List<String> getExcludes() public List<String> getExcludes( )
{ {
return getDefaultArtifactExclusions(); return getDefaultArtifactExclusions( );
} }
@Override @Override
public List<String> getIncludes() public List<String> getIncludes( )
{ {
return this.includes; return this.includes;
} }
@ -180,7 +178,7 @@ public class MetadataUpdaterConsumer
} }
catch ( LayoutException e ) catch ( LayoutException e )
{ {
log.info( "Not processing path that is not an artifact: {} ({})", path, e.getMessage() ); log.info( "Not processing path that is not an artifact: {} ({})", path, e.getMessage( ) );
} }
} }
} }
@ -194,9 +192,9 @@ public class MetadataUpdaterConsumer
private void updateProjectMetadata( ArtifactReference artifact, String path ) private void updateProjectMetadata( ArtifactReference artifact, String path )
{ {
ProjectReference projectRef = new ProjectReference(); ProjectReference projectRef = new ProjectReference( );
projectRef.setGroupId( artifact.getGroupId() ); projectRef.setGroupId( artifact.getGroupId( ) );
projectRef.setArtifactId( artifact.getArtifactId() ); projectRef.setArtifactId( artifact.getArtifactId( ) );
try try
{ {
@ -204,7 +202,7 @@ public class MetadataUpdaterConsumer
File projectMetadata = new File( this.repositoryDir, metadataPath ); File projectMetadata = new File( this.repositoryDir, metadataPath );
if ( projectMetadata.exists() && ( projectMetadata.lastModified() >= this.scanStartTimestamp ) ) if ( projectMetadata.exists( ) && ( projectMetadata.lastModified( ) >= this.scanStartTimestamp ) )
{ {
// This metadata is up to date. skip it. // This metadata is up to date. skip it.
log.debug( "Skipping uptodate metadata: {}", this.metadataTools.toPath( projectRef ) ); log.debug( "Skipping uptodate metadata: {}", this.metadataTools.toPath( projectRef ) );
@ -219,35 +217,35 @@ public class MetadataUpdaterConsumer
log.warn( "Unable to convert path [{}] to an internal project reference: ", path, e ); log.warn( "Unable to convert path [{}] to an internal project reference: ", path, e );
triggerConsumerWarning( TYPE_METADATA_BAD_INTERNAL_REF, triggerConsumerWarning( TYPE_METADATA_BAD_INTERNAL_REF,
"Unable to convert path [" + path + "] to an internal project reference: " "Unable to convert path [" + path + "] to an internal project reference: "
+ e.getMessage() ); + e.getMessage( ) );
} }
catch ( RepositoryMetadataException e ) catch ( RepositoryMetadataException e )
{ {
log.error( "Unable to write project metadat for artifact [{}]:", path, e ); log.error( "Unable to write project metadat for artifact [{}]:", path, e );
triggerConsumerError( TYPE_METADATA_WRITE_FAILURE, triggerConsumerError( TYPE_METADATA_WRITE_FAILURE,
"Unable to write project metadata for artifact [" + path + "]: " + e.getMessage() ); "Unable to write project metadata for artifact [" + path + "]: " + e.getMessage( ) );
} }
catch ( IOException e ) catch ( IOException e )
{ {
log.warn( "Project metadata not written due to IO warning: ", e ); log.warn( "Project metadata not written due to IO warning: ", e );
triggerConsumerWarning( TYPE_METADATA_IO, triggerConsumerWarning( TYPE_METADATA_IO,
"Project metadata not written due to IO warning: " + e.getMessage() ); "Project metadata not written due to IO warning: " + e.getMessage( ) );
} }
catch ( ContentNotFoundException e ) catch ( ContentNotFoundException e )
{ {
log.warn( "Project metadata not written because no versions were found to update: ", e ); log.warn( "Project metadata not written because no versions were found to update: ", e );
triggerConsumerWarning( TYPE_METADATA_IO, triggerConsumerWarning( TYPE_METADATA_IO,
"Project metadata not written because no versions were found to update: " "Project metadata not written because no versions were found to update: "
+ e.getMessage() ); + e.getMessage( ) );
} }
} }
private void updateVersionMetadata( ArtifactReference artifact, String path ) private void updateVersionMetadata( ArtifactReference artifact, String path )
{ {
VersionedReference versionRef = new VersionedReference(); VersionedReference versionRef = new VersionedReference( );
versionRef.setGroupId( artifact.getGroupId() ); versionRef.setGroupId( artifact.getGroupId( ) );
versionRef.setArtifactId( artifact.getArtifactId() ); versionRef.setArtifactId( artifact.getArtifactId( ) );
versionRef.setVersion( artifact.getVersion() ); versionRef.setVersion( artifact.getVersion( ) );
try try
{ {
@ -255,7 +253,7 @@ public class MetadataUpdaterConsumer
File projectMetadata = new File( this.repositoryDir, metadataPath ); File projectMetadata = new File( this.repositoryDir, metadataPath );
if ( projectMetadata.exists() && ( projectMetadata.lastModified() >= this.scanStartTimestamp ) ) if ( projectMetadata.exists( ) && ( projectMetadata.lastModified( ) >= this.scanStartTimestamp ) )
{ {
// This metadata is up to date. skip it. // This metadata is up to date. skip it.
log.debug( "Skipping uptodate metadata: {}", this.metadataTools.toPath( versionRef ) ); log.debug( "Skipping uptodate metadata: {}", this.metadataTools.toPath( versionRef ) );
@ -270,26 +268,26 @@ public class MetadataUpdaterConsumer
log.warn( "Unable to convert path [{}] to an internal version reference: ", path, e ); log.warn( "Unable to convert path [{}] to an internal version reference: ", path, e );
triggerConsumerWarning( TYPE_METADATA_BAD_INTERNAL_REF, triggerConsumerWarning( TYPE_METADATA_BAD_INTERNAL_REF,
"Unable to convert path [" + path + "] to an internal version reference: " "Unable to convert path [" + path + "] to an internal version reference: "
+ e.getMessage() ); + e.getMessage( ) );
} }
catch ( RepositoryMetadataException e ) catch ( RepositoryMetadataException e )
{ {
log.error( "Unable to write version metadata for artifact [{}]: ", path, e ); log.error( "Unable to write version metadata for artifact [{}]: ", path, e );
triggerConsumerError( TYPE_METADATA_WRITE_FAILURE, triggerConsumerError( TYPE_METADATA_WRITE_FAILURE,
"Unable to write version metadata for artifact [" + path + "]: " + e.getMessage() ); "Unable to write version metadata for artifact [" + path + "]: " + e.getMessage( ) );
} }
catch ( IOException e ) catch ( IOException e )
{ {
log.warn( "Version metadata not written due to IO warning: ", e ); log.warn( "Version metadata not written due to IO warning: ", e );
triggerConsumerWarning( TYPE_METADATA_IO, triggerConsumerWarning( TYPE_METADATA_IO,
"Version metadata not written due to IO warning: " + e.getMessage() ); "Version metadata not written due to IO warning: " + e.getMessage( ) );
} }
catch ( ContentNotFoundException e ) catch ( ContentNotFoundException e )
{ {
log.warn( "Version metadata not written because no versions were found to update: ", e ); log.warn( "Version metadata not written because no versions were found to update: ", e );
triggerConsumerWarning( TYPE_METADATA_IO, triggerConsumerWarning( TYPE_METADATA_IO,
"Version metadata not written because no versions were found to update: " "Version metadata not written because no versions were found to update: "
+ e.getMessage() ); + e.getMessage( ) );
} }
} }
@ -310,16 +308,16 @@ public class MetadataUpdaterConsumer
} }
*/ */
private void initIncludes() private void initIncludes( )
{ {
includes = new ArrayList<>( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) ); includes = new ArrayList<>( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) );
} }
@PostConstruct @PostConstruct
public void initialize() public void initialize( )
{ {
//configuration.addChangeListener( this ); //configuration.addChangeListener( this );
initIncludes(); initIncludes( );
} }
} }

View File

@ -45,8 +45,6 @@ import java.util.List;
/** /**
* ValidateChecksumConsumer - validate the provided checksum against the file it represents. * ValidateChecksumConsumer - validate the provided checksum against the file it represents.
*
*
*/ */
@Service( "knownRepositoryContentConsumer#validate-checksums" ) @Service( "knownRepositoryContentConsumer#validate-checksums" )
@Scope( "prototype" ) @Scope( "prototype" )
@ -83,13 +81,13 @@ public class ValidateChecksumConsumer
private List<String> includes; private List<String> includes;
@Override @Override
public String getId() public String getId( )
{ {
return this.id; return this.id;
} }
@Override @Override
public String getDescription() public String getDescription( )
{ {
return this.description; return this.description;
} }
@ -98,7 +96,7 @@ public class ValidateChecksumConsumer
public void beginScan( ManagedRepository repository, Date whenGathered ) public void beginScan( ManagedRepository repository, Date whenGathered )
throws ConsumerException throws ConsumerException
{ {
this.repositoryDir = new File( repository.getLocation() ); this.repositoryDir = new File( repository.getLocation( ) );
} }
@Override @Override
@ -109,7 +107,7 @@ public class ValidateChecksumConsumer
} }
@Override @Override
public void completeScan() public void completeScan( )
{ {
/* nothing to do */ /* nothing to do */
} }
@ -117,17 +115,17 @@ public class ValidateChecksumConsumer
@Override @Override
public void completeScan( boolean executeOnEntireRepo ) public void completeScan( boolean executeOnEntireRepo )
{ {
completeScan(); completeScan( );
} }
@Override @Override
public List<String> getExcludes() public List<String> getExcludes( )
{ {
return null; return null;
} }
@Override @Override
public List<String> getIncludes() public List<String> getIncludes( )
{ {
return this.includes; return this.includes;
} }
@ -148,7 +146,7 @@ public class ValidateChecksumConsumer
catch ( FileNotFoundException e ) catch ( FileNotFoundException e )
{ {
log.error( "File not found during checksum validation: ", e ); log.error( "File not found during checksum validation: ", e );
triggerConsumerError( CHECKSUM_NOT_FOUND, "File not found during checksum validation: " + e.getMessage() ); triggerConsumerError( CHECKSUM_NOT_FOUND, "File not found during checksum validation: " + e.getMessage( ) );
} }
catch ( DigesterException e ) catch ( DigesterException e )
{ {
@ -171,15 +169,15 @@ public class ValidateChecksumConsumer
} }
@PostConstruct @PostConstruct
public void initialize() public void initialize( )
throws PlexusSisuBridgeException throws PlexusSisuBridgeException
{ {
checksum = plexusSisuBridge.lookup( ChecksumFile.class ); checksum = plexusSisuBridge.lookup( ChecksumFile.class );
List<Digester> allDigesters = new ArrayList<>( digesterUtils.getAllDigesters() ); List<Digester> allDigesters = new ArrayList<>( digesterUtils.getAllDigesters( ) );
includes = new ArrayList<>( allDigesters.size() ); includes = new ArrayList<>( allDigesters.size( ) );
for ( Digester digester : allDigesters ) for ( Digester digester : allDigesters )
{ {
includes.add( "**/*" + digester.getFilenameExtension() ); includes.add( "**/*" + digester.getFilenameExtension( ) );
} }
} }
} }

View File

@ -364,15 +364,16 @@ public abstract class AbstractRepositoryPurge
} }
} }
private void deleteSilently(Path path) { private void deleteSilently( Path path )
{
try try
{ {
Files.deleteIfExists( path ); Files.deleteIfExists( path );
triggerAuditEvent( repository.getRepository( ).getId( ), path.toString(), AuditEvent.PURGE_FILE ); triggerAuditEvent( repository.getRepository( ).getId( ), path.toString( ), AuditEvent.PURGE_FILE );
} }
catch ( IOException e ) catch ( IOException e )
{ {
log.error("Error occured during file deletion {}: {} ",path,e.getMessage(), e); log.error( "Error occured during file deletion {}: {} ", path, e.getMessage( ), e );
} }
} }
@ -388,24 +389,24 @@ public abstract class AbstractRepositoryPurge
*/ */
private void purgeSupportFiles( Path artifactFile ) private void purgeSupportFiles( Path artifactFile )
{ {
Path parentDir = artifactFile.getParent(); Path parentDir = artifactFile.getParent( );
if ( !Files.exists(parentDir) ) if ( !Files.exists( parentDir ) )
{ {
return; return;
} }
final String artifactName = artifactFile.getFileName().toString(); final String artifactName = artifactFile.getFileName( ).toString( );
try try
{ {
Files.find(parentDir, 3, Files.find( parentDir, 3,
( path, basicFileAttributes ) -> path.getFileName().toString().startsWith(artifactName) ( path, basicFileAttributes ) -> path.getFileName( ).toString( ).startsWith( artifactName )
&& Files.isRegularFile( path ) ).forEach( this::deleteSilently ); && Files.isRegularFile( path ) ).forEach( this::deleteSilently );
} }
catch ( IOException e ) catch ( IOException e )
{ {
log.error("Purge of support files failed {}: {}", artifactFile, e.getMessage(), e); log.error( "Purge of support files failed {}: {}", artifactFile, e.getMessage( ), e );
} }
} }

View File

@ -93,9 +93,9 @@ public class CleanupReleasedSnapshotsRepositoryPurge
{ {
try try
{ {
File artifactFile = new File( repository.getRepoRoot(), path ); File artifactFile = new File( repository.getRepoRoot( ), path );
if ( !artifactFile.exists() ) if ( !artifactFile.exists( ) )
{ {
// Nothing to do here, file doesn't exist, skip it. // Nothing to do here, file doesn't exist, skip it.
return; return;
@ -103,28 +103,28 @@ public class CleanupReleasedSnapshotsRepositoryPurge
ArtifactReference artifactRef = repository.toArtifactReference( path ); ArtifactReference artifactRef = repository.toArtifactReference( path );
if ( !VersionUtil.isSnapshot( artifactRef.getVersion() ) ) if ( !VersionUtil.isSnapshot( artifactRef.getVersion( ) ) )
{ {
// Nothing to do here, not a snapshot, skip it. // Nothing to do here, not a snapshot, skip it.
return; return;
} }
ProjectReference reference = new ProjectReference(); ProjectReference reference = new ProjectReference( );
reference.setGroupId( artifactRef.getGroupId() ); reference.setGroupId( artifactRef.getGroupId( ) );
reference.setArtifactId( artifactRef.getArtifactId() ); reference.setArtifactId( artifactRef.getArtifactId( ) );
// Gether the released versions // Gether the released versions
List<String> releasedVersions = new ArrayList<>(); List<String> releasedVersions = new ArrayList<>( );
List<ManagedRepository> repos = managedRepositoryAdmin.getManagedRepositories(); List<ManagedRepository> repos = managedRepositoryAdmin.getManagedRepositories( );
for ( ManagedRepository repo : repos ) for ( ManagedRepository repo : repos )
{ {
if ( repo.isReleases() ) if ( repo.isReleases( ) )
{ {
try try
{ {
ManagedRepositoryContent repoContent = ManagedRepositoryContent repoContent =
repoContentFactory.getManagedRepositoryContent( repo.getId() ); repoContentFactory.getManagedRepositoryContent( repo.getId( ) );
for ( String version : repoContent.getVersions( reference ) ) for ( String version : repoContent.getVersions( reference ) )
{ {
if ( !VersionUtil.isSnapshot( version ) ) if ( !VersionUtil.isSnapshot( version ) )
@ -144,30 +144,30 @@ public class CleanupReleasedSnapshotsRepositoryPurge
} }
} }
Collections.sort( releasedVersions, VersionComparator.getInstance() ); Collections.sort( releasedVersions, VersionComparator.getInstance( ) );
// Now clean out any version that is earlier than the highest released version. // Now clean out any version that is earlier than the highest released version.
boolean needsMetadataUpdate = false; boolean needsMetadataUpdate = false;
VersionedReference versionRef = new VersionedReference(); VersionedReference versionRef = new VersionedReference( );
versionRef.setGroupId( artifactRef.getGroupId() ); versionRef.setGroupId( artifactRef.getGroupId( ) );
versionRef.setArtifactId( artifactRef.getArtifactId() ); versionRef.setArtifactId( artifactRef.getArtifactId( ) );
MetadataRepository metadataRepository = repositorySession.getRepository(); MetadataRepository metadataRepository = repositorySession.getRepository( );
if ( releasedVersions.contains( VersionUtil.getReleaseVersion( artifactRef.getVersion() ) ) ) if ( releasedVersions.contains( VersionUtil.getReleaseVersion( artifactRef.getVersion( ) ) ) )
{ {
versionRef.setVersion( artifactRef.getVersion() ); versionRef.setVersion( artifactRef.getVersion( ) );
repository.deleteVersion( versionRef ); repository.deleteVersion( versionRef );
for ( RepositoryListener listener : listeners ) for ( RepositoryListener listener : listeners )
{ {
listener.deleteArtifact( metadataRepository, repository.getId(), artifactRef.getGroupId(), listener.deleteArtifact( metadataRepository, repository.getId( ), artifactRef.getGroupId( ),
artifactRef.getArtifactId(), artifactRef.getVersion(), artifactRef.getArtifactId( ), artifactRef.getVersion( ),
artifactFile.getName() ); artifactFile.getName( ) );
} }
metadataRepository.removeProjectVersion( repository.getId(), artifactRef.getGroupId(), metadataRepository.removeProjectVersion( repository.getId( ), artifactRef.getGroupId( ),
artifactRef.getArtifactId(), artifactRef.getVersion()); artifactRef.getArtifactId( ), artifactRef.getVersion( ) );
needsMetadataUpdate = true; needsMetadataUpdate = true;
} }
@ -176,34 +176,35 @@ public class CleanupReleasedSnapshotsRepositoryPurge
{ {
updateMetadata( artifactRef ); updateMetadata( artifactRef );
} }
} catch ( RepositoryAdminException e ) }
catch ( RepositoryAdminException e )
{ {
throw new RepositoryPurgeException( e.getMessage(), e ); throw new RepositoryPurgeException( e.getMessage( ), e );
} }
catch ( LayoutException e ) catch ( LayoutException e )
{ {
log.debug( "Not processing file that is not an artifact: {}", e.getMessage() ); log.debug( "Not processing file that is not an artifact: {}", e.getMessage( ) );
} }
catch ( ContentNotFoundException e ) catch ( ContentNotFoundException e )
{ {
throw new RepositoryPurgeException( e.getMessage(), e ); throw new RepositoryPurgeException( e.getMessage( ), e );
} }
catch ( MetadataRepositoryException e ) catch ( MetadataRepositoryException e )
{ {
log.error("Could not remove metadata during cleanup of released snapshots of {}", path, e); log.error( "Could not remove metadata during cleanup of released snapshots of {}", path, e );
} }
} }
private void updateMetadata( ArtifactReference artifact ) private void updateMetadata( ArtifactReference artifact )
{ {
VersionedReference versionRef = new VersionedReference(); VersionedReference versionRef = new VersionedReference( );
versionRef.setGroupId( artifact.getGroupId() ); versionRef.setGroupId( artifact.getGroupId( ) );
versionRef.setArtifactId( artifact.getArtifactId() ); versionRef.setArtifactId( artifact.getArtifactId( ) );
versionRef.setVersion( artifact.getVersion() ); versionRef.setVersion( artifact.getVersion( ) );
ProjectReference projectRef = new ProjectReference(); ProjectReference projectRef = new ProjectReference( );
projectRef.setGroupId( artifact.getGroupId() ); projectRef.setGroupId( artifact.getGroupId( ) );
projectRef.setArtifactId( artifact.getArtifactId() ); projectRef.setArtifactId( artifact.getArtifactId( ) );
try try
{ {

View File

@ -70,9 +70,9 @@ public class DaysOldRepositoryPurge
{ {
try try
{ {
File artifactFile = new File( repository.getRepoRoot(), path ); File artifactFile = new File( repository.getRepoRoot( ), path );
if ( !artifactFile.exists() ) if ( !artifactFile.exists( ) )
{ {
return; return;
} }
@ -83,24 +83,24 @@ public class DaysOldRepositoryPurge
olderThanThisDate.add( Calendar.DATE, -daysOlder ); olderThanThisDate.add( Calendar.DATE, -daysOlder );
// respect retention count // respect retention count
VersionedReference reference = new VersionedReference(); VersionedReference reference = new VersionedReference( );
reference.setGroupId( artifact.getGroupId() ); reference.setGroupId( artifact.getGroupId( ) );
reference.setArtifactId( artifact.getArtifactId() ); reference.setArtifactId( artifact.getArtifactId( ) );
reference.setVersion( artifact.getVersion() ); reference.setVersion( artifact.getVersion( ) );
List<String> versions = new ArrayList<>( repository.getVersions( reference ) ); List<String> versions = new ArrayList<>( repository.getVersions( reference ) );
Collections.sort( versions, VersionComparator.getInstance() ); Collections.sort( versions, VersionComparator.getInstance( ) );
if ( retentionCount > versions.size() ) if ( retentionCount > versions.size( ) )
{ {
// Done. nothing to do here. skip it. // Done. nothing to do here. skip it.
return; return;
} }
int countToPurge = versions.size() - retentionCount; int countToPurge = versions.size( ) - retentionCount;
Set<ArtifactReference> artifactsToDelete = new HashSet<>(); Set<ArtifactReference> artifactsToDelete = new HashSet<>( );
for ( String version : versions ) for ( String version : versions )
{ {
if ( countToPurge-- <= 0 ) if ( countToPurge-- <= 0 )
@ -109,39 +109,39 @@ public class DaysOldRepositoryPurge
} }
ArtifactReference newArtifactReference = repository.toArtifactReference( ArtifactReference newArtifactReference = repository.toArtifactReference(
artifactFile.getAbsolutePath() ); artifactFile.getAbsolutePath( ) );
newArtifactReference.setVersion( version ); newArtifactReference.setVersion( version );
File newArtifactFile = repository.toFile( newArtifactReference ); File newArtifactFile = repository.toFile( newArtifactReference );
// Is this a generic snapshot "1.0-SNAPSHOT" ? // Is this a generic snapshot "1.0-SNAPSHOT" ?
if ( VersionUtil.isGenericSnapshot( newArtifactReference.getVersion() ) ) if ( VersionUtil.isGenericSnapshot( newArtifactReference.getVersion( ) ) )
{ {
if ( newArtifactFile.lastModified() < olderThanThisDate.getTimeInMillis() ) if ( newArtifactFile.lastModified( ) < olderThanThisDate.getTimeInMillis( ) )
{ {
artifactsToDelete.addAll(repository.getRelatedArtifacts(newArtifactReference) ); artifactsToDelete.addAll( repository.getRelatedArtifacts( newArtifactReference ) );
} }
} }
// Is this a timestamp snapshot "1.0-20070822.123456-42" ? // Is this a timestamp snapshot "1.0-20070822.123456-42" ?
else if ( VersionUtil.isUniqueSnapshot( newArtifactReference.getVersion() ) ) else if ( VersionUtil.isUniqueSnapshot( newArtifactReference.getVersion( ) ) )
{ {
Calendar timestampCal = uniqueSnapshotToCalendar( newArtifactReference.getVersion() ); Calendar timestampCal = uniqueSnapshotToCalendar( newArtifactReference.getVersion( ) );
if ( timestampCal.getTimeInMillis() < olderThanThisDate.getTimeInMillis() ) if ( timestampCal.getTimeInMillis( ) < olderThanThisDate.getTimeInMillis( ) )
{ {
artifactsToDelete.addAll( repository.getRelatedArtifacts(newArtifactReference)); artifactsToDelete.addAll( repository.getRelatedArtifacts( newArtifactReference ) );
} }
} }
} }
purge(artifactsToDelete); purge( artifactsToDelete );
} }
catch ( ContentNotFoundException e ) catch ( ContentNotFoundException e )
{ {
throw new RepositoryPurgeException( e.getMessage(), e ); throw new RepositoryPurgeException( e.getMessage( ), e );
} }
catch ( LayoutException e ) catch ( LayoutException e )
{ {
log.debug( "Not processing file that is not an artifact: {}", e.getMessage() ); log.debug( "Not processing file that is not an artifact: {}", e.getMessage( ) );
} }
} }
@ -151,10 +151,10 @@ public class DaysOldRepositoryPurge
// This needs to be broken down into ${base}-${timestamp}-${build_number} // This needs to be broken down into ${base}-${timestamp}-${build_number}
Matcher m = VersionUtil.UNIQUE_SNAPSHOT_PATTERN.matcher( version ); Matcher m = VersionUtil.UNIQUE_SNAPSHOT_PATTERN.matcher( version );
if ( m.matches() ) if ( m.matches( ) )
{ {
Matcher mtimestamp = VersionUtil.TIMESTAMP_PATTERN.matcher( m.group( 2 ) ); Matcher mtimestamp = VersionUtil.TIMESTAMP_PATTERN.matcher( m.group( 2 ) );
if ( mtimestamp.matches() ) if ( mtimestamp.matches( ) )
{ {
String tsDate = mtimestamp.group( 1 ); String tsDate = mtimestamp.group( 1 );
String tsTime = mtimestamp.group( 2 ); String tsTime = mtimestamp.group( 2 );

View File

@ -87,7 +87,7 @@ public class RepositoryPurgeConsumer
@Named( value = "fileTypes" ) @Named( value = "fileTypes" )
private FileTypes filetypes; private FileTypes filetypes;
private List<String> includes = new ArrayList<>(); private List<String> includes = new ArrayList<>( );
private RepositoryPurge repoPurge; private RepositoryPurge repoPurge;
@ -99,8 +99,8 @@ public class RepositoryPurgeConsumer
* *
*/ */
@Inject @Inject
@Autowired(required = false) @Autowired( required = false )
private List<RepositoryListener> listeners = Collections.emptyList(); private List<RepositoryListener> listeners = Collections.emptyList( );
@Inject @Inject
private RepositorySessionFactory repositorySessionFactory; private RepositorySessionFactory repositorySessionFactory;
@ -108,25 +108,25 @@ public class RepositoryPurgeConsumer
private RepositorySession repositorySession; private RepositorySession repositorySession;
@Override @Override
public String getId() public String getId( )
{ {
return this.id; return this.id;
} }
@Override @Override
public String getDescription() public String getDescription( )
{ {
return this.description; return this.description;
} }
@Override @Override
public List<String> getExcludes() public List<String> getExcludes( )
{ {
return getDefaultArtifactExclusions(); return getDefaultArtifactExclusions( );
} }
@Override @Override
public List<String> getIncludes() public List<String> getIncludes( )
{ {
return this.includes; return this.includes;
} }
@ -138,35 +138,35 @@ public class RepositoryPurgeConsumer
ManagedRepositoryContent repositoryContent; ManagedRepositoryContent repositoryContent;
try try
{ {
repositoryContent = repositoryContentFactory.getManagedRepositoryContent( repository.getId() ); repositoryContent = repositoryContentFactory.getManagedRepositoryContent( repository.getId( ) );
} }
catch ( RepositoryNotFoundException e ) catch ( RepositoryNotFoundException e )
{ {
throw new ConsumerException( "Can't run repository purge: " + e.getMessage(), e ); throw new ConsumerException( "Can't run repository purge: " + e.getMessage( ), e );
} }
catch ( RepositoryException e ) catch ( RepositoryException e )
{ {
throw new ConsumerException( "Can't run repository purge: " + e.getMessage(), e ); throw new ConsumerException( "Can't run repository purge: " + e.getMessage( ), e );
} }
repositorySession = repositorySessionFactory.createSession(); repositorySession = repositorySessionFactory.createSession( );
if ( repository.getDaysOlder() != 0 ) if ( repository.getDaysOlder( ) != 0 )
{ {
repoPurge = new DaysOldRepositoryPurge( repositoryContent, repository.getDaysOlder(), repoPurge = new DaysOldRepositoryPurge( repositoryContent, repository.getDaysOlder( ),
repository.getRetentionCount(), repositorySession, listeners ); repository.getRetentionCount( ), repositorySession, listeners );
} }
else else
{ {
repoPurge = repoPurge =
new RetentionCountRepositoryPurge( repositoryContent, repository.getRetentionCount(), repositorySession, new RetentionCountRepositoryPurge( repositoryContent, repository.getRetentionCount( ), repositorySession,
listeners ); listeners );
} }
cleanUp = new CleanupReleasedSnapshotsRepositoryPurge( repositoryContent, metadataTools, managedRepositoryAdmin, cleanUp = new CleanupReleasedSnapshotsRepositoryPurge( repositoryContent, metadataTools, managedRepositoryAdmin,
repositoryContentFactory, repositorySession, listeners ); repositoryContentFactory, repositorySession, listeners );
deleteReleasedSnapshots = repository.isDeleteReleasedSnapshots(); deleteReleasedSnapshots = repository.isDeleteReleasedSnapshots( );
} }
@Override @Override
@ -190,7 +190,7 @@ public class RepositoryPurgeConsumer
} }
catch ( RepositoryPurgeException rpe ) catch ( RepositoryPurgeException rpe )
{ {
throw new ConsumerException( rpe.getMessage(), rpe ); throw new ConsumerException( rpe.getMessage( ), rpe );
} }
} }
@ -202,15 +202,15 @@ public class RepositoryPurgeConsumer
} }
@Override @Override
public void completeScan() public void completeScan( )
{ {
repositorySession.close(); repositorySession.close( );
} }
@Override @Override
public void completeScan( boolean executeOnEntireRepo ) public void completeScan( boolean executeOnEntireRepo )
{ {
completeScan(); completeScan( );
} }
@Override @Override
@ -218,7 +218,7 @@ public class RepositoryPurgeConsumer
{ {
if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) if ( ConfigurationNames.isRepositoryScanning( propertyName ) )
{ {
initIncludes(); initIncludes( );
} }
} }
@ -228,27 +228,27 @@ public class RepositoryPurgeConsumer
/* do nothing */ /* do nothing */
} }
private void initIncludes() private void initIncludes( )
{ {
includes = new ArrayList<>( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) ); includes = new ArrayList<>( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) );
} }
@PostConstruct @PostConstruct
public void initialize() public void initialize( )
{ {
configuration.addChangeListener( this ); configuration.addChangeListener( this );
initIncludes(); initIncludes( );
} }
@Override @Override
public boolean isProcessUnmodified() public boolean isProcessUnmodified( )
{ {
// we need to check all files for deletion, especially if not modified // we need to check all files for deletion, especially if not modified
return true; return true;
} }
public ArchivaConfiguration getConfiguration() public ArchivaConfiguration getConfiguration( )
{ {
return configuration; return configuration;
} }
@ -258,7 +258,7 @@ public class RepositoryPurgeConsumer
this.configuration = configuration; this.configuration = configuration;
} }
public RepositoryContentFactory getRepositoryContentFactory() public RepositoryContentFactory getRepositoryContentFactory( )
{ {
return repositoryContentFactory; return repositoryContentFactory;
} }
@ -268,7 +268,7 @@ public class RepositoryPurgeConsumer
this.repositoryContentFactory = repositoryContentFactory; this.repositoryContentFactory = repositoryContentFactory;
} }
public MetadataTools getMetadataTools() public MetadataTools getMetadataTools( )
{ {
return metadataTools; return metadataTools;
} }
@ -278,7 +278,7 @@ public class RepositoryPurgeConsumer
this.metadataTools = metadataTools; this.metadataTools = metadataTools;
} }
public FileTypes getFiletypes() public FileTypes getFiletypes( )
{ {
return filetypes; return filetypes;
} }
@ -288,7 +288,7 @@ public class RepositoryPurgeConsumer
this.filetypes = filetypes; this.filetypes = filetypes;
} }
public RepositoryPurge getRepoPurge() public RepositoryPurge getRepoPurge( )
{ {
return repoPurge; return repoPurge;
} }
@ -298,7 +298,7 @@ public class RepositoryPurgeConsumer
this.repoPurge = repoPurge; this.repoPurge = repoPurge;
} }
public RepositoryPurge getCleanUp() public RepositoryPurge getCleanUp( )
{ {
return cleanUp; return cleanUp;
} }
@ -308,7 +308,7 @@ public class RepositoryPurgeConsumer
this.cleanUp = cleanUp; this.cleanUp = cleanUp;
} }
public boolean isDeleteReleasedSnapshots() public boolean isDeleteReleasedSnapshots( )
{ {
return deleteReleasedSnapshots; return deleteReleasedSnapshots;
} }
@ -318,7 +318,7 @@ public class RepositoryPurgeConsumer
this.deleteReleasedSnapshots = deleteReleasedSnapshots; this.deleteReleasedSnapshots = deleteReleasedSnapshots;
} }
public RepositorySessionFactory getRepositorySessionFactory() public RepositorySessionFactory getRepositorySessionFactory( )
{ {
return repositorySessionFactory; return repositorySessionFactory;
} }
@ -328,7 +328,7 @@ public class RepositoryPurgeConsumer
this.repositorySessionFactory = repositorySessionFactory; this.repositorySessionFactory = repositorySessionFactory;
} }
public RepositorySession getRepositorySession() public RepositorySession getRepositorySession( )
{ {
return repositorySession; return repositorySession;
} }

View File

@ -26,9 +26,9 @@ package org.apache.archiva.consumers.core.repository;
public class RepositoryPurgeException public class RepositoryPurgeException
extends Exception extends Exception
{ {
public RepositoryPurgeException() public RepositoryPurgeException( )
{ {
super(); super( );
} }
public RepositoryPurgeException( String message, Throwable cause ) public RepositoryPurgeException( String message, Throwable cause )

View File

@ -57,53 +57,53 @@ public class RetentionCountRepositoryPurge
{ {
try try
{ {
File artifactFile = new File( repository.getRepoRoot(), path ); File artifactFile = new File( repository.getRepoRoot( ), path );
if ( !artifactFile.exists() ) if ( !artifactFile.exists( ) )
{ {
return; return;
} }
ArtifactReference artifact = repository.toArtifactReference( path ); ArtifactReference artifact = repository.toArtifactReference( path );
if ( VersionUtil.isSnapshot( artifact.getVersion() ) ) if ( VersionUtil.isSnapshot( artifact.getVersion( ) ) )
{ {
VersionedReference reference = new VersionedReference(); VersionedReference reference = new VersionedReference( );
reference.setGroupId( artifact.getGroupId() ); reference.setGroupId( artifact.getGroupId( ) );
reference.setArtifactId( artifact.getArtifactId() ); reference.setArtifactId( artifact.getArtifactId( ) );
reference.setVersion( artifact.getVersion() ); reference.setVersion( artifact.getVersion( ) );
List<String> versions = new ArrayList<>( repository.getVersions( reference ) ); List<String> versions = new ArrayList<>( repository.getVersions( reference ) );
Collections.sort( versions, VersionComparator.getInstance() ); Collections.sort( versions, VersionComparator.getInstance( ) );
if ( retentionCount > versions.size() ) if ( retentionCount > versions.size( ) )
{ {
log.trace("No deletion, because retention count is higher than actual number of artifacts."); log.trace( "No deletion, because retention count is higher than actual number of artifacts." );
// Done. nothing to do here. skip it. // Done. nothing to do here. skip it.
return; return;
} }
int countToPurge = versions.size() - retentionCount; int countToPurge = versions.size( ) - retentionCount;
Set<ArtifactReference> artifactsToDelete = new HashSet<>(); Set<ArtifactReference> artifactsToDelete = new HashSet<>( );
for ( String version : versions ) for ( String version : versions )
{ {
if ( countToPurge-- <= 0 ) if ( countToPurge-- <= 0 )
{ {
break; break;
} }
artifactsToDelete.addAll(repository.getRelatedArtifacts( getNewArtifactReference( artifact, version) )); artifactsToDelete.addAll( repository.getRelatedArtifacts( getNewArtifactReference( artifact, version ) ) );
} }
purge(artifactsToDelete); purge( artifactsToDelete );
} }
} }
catch ( LayoutException le ) catch ( LayoutException le )
{ {
throw new RepositoryPurgeException( le.getMessage(), le ); throw new RepositoryPurgeException( le.getMessage( ), le );
} }
catch ( ContentNotFoundException e ) catch ( ContentNotFoundException e )
{ {
log.error("Repostory artifact not found {}", path); log.error( "Repostory artifact not found {}", path );
} }
} }
@ -113,12 +113,12 @@ public class RetentionCountRepositoryPurge
private ArtifactReference getNewArtifactReference( ArtifactReference reference, String version ) private ArtifactReference getNewArtifactReference( ArtifactReference reference, String version )
throws LayoutException throws LayoutException
{ {
ArtifactReference artifact = new ArtifactReference(); ArtifactReference artifact = new ArtifactReference( );
artifact.setGroupId( reference.getGroupId() ); artifact.setGroupId( reference.getGroupId( ) );
artifact.setArtifactId( reference.getArtifactId() ); artifact.setArtifactId( reference.getArtifactId( ) );
artifact.setVersion( version ); artifact.setVersion( version );
artifact.setClassifier( reference.getClassifier() ); artifact.setClassifier( reference.getClassifier( ) );
artifact.setType( reference.getType() ); artifact.setType( reference.getType( ) );
return artifact; return artifact;
} }