Reformat code

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

View File

@ -82,17 +82,17 @@ public class ArtifactMissingChecksumsConsumer
//configuration.addChangeListener( this );
initIncludes();
initIncludes( );
}
@Override
public String getId()
public String getId( )
{
return this.id;
}
@Override
public String getDescription()
public String getDescription( )
{
return this.description;
}
@ -101,7 +101,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( ) );
}
@Override
@ -112,7 +112,7 @@ public class ArtifactMissingChecksumsConsumer
}
@Override
public void completeScan()
public void completeScan( )
{
/* do nothing */
}
@ -120,17 +120,17 @@ public class ArtifactMissingChecksumsConsumer
@Override
public void completeScan( boolean executeOnEntireRepo )
{
completeScan();
completeScan( );
}
@Override
public List<String> getExcludes()
public List<String> getExcludes( )
{
return getDefaultArtifactExclusions();
return getDefaultArtifactExclusions( );
}
@Override
public List<String> getIncludes()
public List<String> getIncludes( )
{
return includes;
}
@ -153,48 +153,48 @@ public class ArtifactMissingChecksumsConsumer
private void createFixChecksum( String path, ChecksumAlgorithm checksumAlgorithm )
{
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 );
try
{
if ( !checksum.isValidChecksum( checksumAlgorithm ) )
{
checksum.fixChecksums( new ChecksumAlgorithm[]{ checksumAlgorithm } );
log.info( "Fixed checksum file {}", checksumFile.getAbsolutePath() );
triggerConsumerInfo( "Fixed checksum file " + checksumFile.getAbsolutePath() );
checksum.fixChecksums( new ChecksumAlgorithm[]{checksumAlgorithm} );
log.info( "Fixed checksum file {}", checksumFile.getAbsolutePath( ) );
triggerConsumerInfo( "Fixed checksum file " + checksumFile.getAbsolutePath( ) );
}
}
catch ( IOException e )
{
log.error( "Cannot calculate checksum for file {} :", checksumFile, 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 );
log.info( "Created missing checksum file {}", checksumFile.getAbsolutePath() );
triggerConsumerInfo( "Created missing checksum file " + checksumFile.getAbsolutePath() );
log.info( "Created missing checksum file {}", checksumFile.getAbsolutePath( ) );
triggerConsumerInfo( "Created missing checksum file " + checksumFile.getAbsolutePath( ) );
}
catch ( IOException e )
{
log.error( "Cannot create checksum for file {} :", checksumFile, e );
triggerConsumerError( TYPE_CHECKSUM_CANNOT_CREATE, "Cannot create checksum for file " + checksumFile +
": " + e.getMessage() );
": " + e.getMessage( ) );
}
}
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,
"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 ) );
}
@PostConstruct
public void initialize()
public void initialize( )
{
//configuration.addChangeListener( this );
initIncludes();
initIncludes( );
}
}

View File

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

View File

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

View File

@ -51,8 +51,6 @@ import java.util.List;
/**
* MetadataUpdaterConsumer will create and update the metadata present within the repository.
*
*
*/
@Service( "knownRepositoryContentConsumer#metadata-updater" )
@Scope( "prototype" )
@ -98,13 +96,13 @@ public class MetadataUpdaterConsumer
private long scanStartTimestamp = 0;
@Override
public String getDescription()
public String getDescription( )
{
return description;
}
@Override
public String getId()
public String getId( )
{
return id;
}
@ -120,17 +118,17 @@ public class MetadataUpdaterConsumer
{
try
{
this.repository = repositoryFactory.getManagedRepositoryContent( repoConfig.getId() );
this.repositoryDir = new File( repository.getRepoRoot() );
this.scanStartTimestamp = System.currentTimeMillis();
this.repository = repositoryFactory.getManagedRepositoryContent( repoConfig.getId( ) );
this.repositoryDir = new File( repository.getRepoRoot( ) );
this.scanStartTimestamp = System.currentTimeMillis( );
}
catch ( RepositoryNotFoundException e )
{
throw new ConsumerException( e.getMessage(), e );
throw new ConsumerException( e.getMessage( ), e );
}
catch ( RepositoryException e )
{
throw new ConsumerException( e.getMessage(), e );
throw new ConsumerException( e.getMessage( ), e );
}
}
@ -142,7 +140,7 @@ public class MetadataUpdaterConsumer
}
@Override
public void completeScan()
public void completeScan( )
{
/* do nothing here */
}
@ -150,17 +148,17 @@ public class MetadataUpdaterConsumer
@Override
public void completeScan( boolean executeOnEntireRepo )
{
completeScan();
completeScan( );
}
@Override
public List<String> getExcludes()
public List<String> getExcludes( )
{
return getDefaultArtifactExclusions();
return getDefaultArtifactExclusions( );
}
@Override
public List<String> getIncludes()
public List<String> getIncludes( )
{
return this.includes;
}
@ -180,7 +178,7 @@ public class MetadataUpdaterConsumer
}
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 )
{
ProjectReference projectRef = new ProjectReference();
projectRef.setGroupId( artifact.getGroupId() );
projectRef.setArtifactId( artifact.getArtifactId() );
ProjectReference projectRef = new ProjectReference( );
projectRef.setGroupId( artifact.getGroupId( ) );
projectRef.setArtifactId( artifact.getArtifactId( ) );
try
{
@ -204,7 +202,7 @@ public class MetadataUpdaterConsumer
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.
log.debug( "Skipping uptodate metadata: {}", this.metadataTools.toPath( projectRef ) );
@ -218,36 +216,36 @@ public class MetadataUpdaterConsumer
{
log.warn( "Unable to convert path [{}] to an internal project reference: ", path, e );
triggerConsumerWarning( TYPE_METADATA_BAD_INTERNAL_REF,
"Unable to convert path [" + path + "] to an internal project reference: "
+ e.getMessage() );
"Unable to convert path [" + path + "] to an internal project reference: "
+ e.getMessage( ) );
}
catch ( RepositoryMetadataException e )
{
log.error( "Unable to write project metadat for artifact [{}]:", path, e );
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 )
{
log.warn( "Project metadata not written due to IO warning: ", e );
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 )
{
log.warn( "Project metadata not written because no versions were found to update: ", e );
triggerConsumerWarning( TYPE_METADATA_IO,
"Project metadata not written because no versions were found to update: "
+ e.getMessage() );
"Project metadata not written because no versions were found to update: "
+ e.getMessage( ) );
}
}
private void updateVersionMetadata( ArtifactReference artifact, String path )
{
VersionedReference versionRef = new VersionedReference();
versionRef.setGroupId( artifact.getGroupId() );
versionRef.setArtifactId( artifact.getArtifactId() );
versionRef.setVersion( artifact.getVersion() );
VersionedReference versionRef = new VersionedReference( );
versionRef.setGroupId( artifact.getGroupId( ) );
versionRef.setArtifactId( artifact.getArtifactId( ) );
versionRef.setVersion( artifact.getVersion( ) );
try
{
@ -255,7 +253,7 @@ public class MetadataUpdaterConsumer
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.
log.debug( "Skipping uptodate metadata: {}", this.metadataTools.toPath( versionRef ) );
@ -269,27 +267,27 @@ public class MetadataUpdaterConsumer
{
log.warn( "Unable to convert path [{}] to an internal version reference: ", path, e );
triggerConsumerWarning( TYPE_METADATA_BAD_INTERNAL_REF,
"Unable to convert path [" + path + "] to an internal version reference: "
+ e.getMessage() );
"Unable to convert path [" + path + "] to an internal version reference: "
+ e.getMessage( ) );
}
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,
"Unable to write version metadata for artifact [" + path + "]: " + e.getMessage() );
"Unable to write version metadata for artifact [" + path + "]: " + e.getMessage( ) );
}
catch ( IOException e )
{
log.warn( "Version metadata not written due to IO warning: ", e );
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 )
{
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,
"Version metadata not written because no versions were found to update: "
+ e.getMessage() );
"Version metadata not written because no versions were found to update: "
+ e.getMessage( ) );
}
}
@ -310,16 +308,16 @@ public class MetadataUpdaterConsumer
}
*/
private void initIncludes()
private void initIncludes( )
{
includes = new ArrayList<>( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) );
}
@PostConstruct
public void initialize()
public void initialize( )
{
//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.
*
*
*/
@Service( "knownRepositoryContentConsumer#validate-checksums" )
@Scope( "prototype" )
@ -83,13 +81,13 @@ public class ValidateChecksumConsumer
private List<String> includes;
@Override
public String getId()
public String getId( )
{
return this.id;
}
@Override
public String getDescription()
public String getDescription( )
{
return this.description;
}
@ -98,7 +96,7 @@ public class ValidateChecksumConsumer
public void beginScan( ManagedRepository repository, Date whenGathered )
throws ConsumerException
{
this.repositoryDir = new File( repository.getLocation() );
this.repositoryDir = new File( repository.getLocation( ) );
}
@Override
@ -109,7 +107,7 @@ public class ValidateChecksumConsumer
}
@Override
public void completeScan()
public void completeScan( )
{
/* nothing to do */
}
@ -117,17 +115,17 @@ public class ValidateChecksumConsumer
@Override
public void completeScan( boolean executeOnEntireRepo )
{
completeScan();
completeScan( );
}
@Override
public List<String> getExcludes()
public List<String> getExcludes( )
{
return null;
}
@Override
public List<String> getIncludes()
public List<String> getIncludes( )
{
return this.includes;
}
@ -148,13 +146,13 @@ public class ValidateChecksumConsumer
catch ( FileNotFoundException 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 )
{
log.error( "Digester failure during checksum validation on {}", checksumFile );
triggerConsumerError( CHECKSUM_DIGESTER_FAILURE,
"Digester failure during checksum validation on " + checksumFile );
"Digester failure during checksum validation on " + checksumFile );
}
catch ( IOException e )
{
@ -171,15 +169,15 @@ public class ValidateChecksumConsumer
}
@PostConstruct
public void initialize()
public void initialize( )
throws PlexusSisuBridgeException
{
checksum = plexusSisuBridge.lookup( ChecksumFile.class );
List<Digester> allDigesters = new ArrayList<>( digesterUtils.getAllDigesters() );
includes = new ArrayList<>( allDigesters.size() );
List<Digester> allDigesters = new ArrayList<>( digesterUtils.getAllDigesters( ) );
includes = new ArrayList<>( allDigesters.size( ) );
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
{
Files.deleteIfExists( path );
triggerAuditEvent( repository.getRepository( ).getId( ), path.toString(), AuditEvent.PURGE_FILE );
triggerAuditEvent( repository.getRepository( ).getId( ), path.toString( ), AuditEvent.PURGE_FILE );
}
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 )
{
Path parentDir = artifactFile.getParent();
Path parentDir = artifactFile.getParent( );
if ( !Files.exists(parentDir) )
if ( !Files.exists( parentDir ) )
{
return;
}
final String artifactName = artifactFile.getFileName().toString();
final String artifactName = artifactFile.getFileName( ).toString( );
try
{
Files.find(parentDir, 3,
( path, basicFileAttributes ) -> path.getFileName().toString().startsWith(artifactName)
&& Files.isRegularFile( path ) ).forEach( this::deleteSilently );
Files.find( parentDir, 3,
( path, basicFileAttributes ) -> path.getFileName( ).toString( ).startsWith( artifactName )
&& Files.isRegularFile( path ) ).forEach( this::deleteSilently );
}
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
{
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.
return;
@ -103,28 +103,28 @@ public class CleanupReleasedSnapshotsRepositoryPurge
ArtifactReference artifactRef = repository.toArtifactReference( path );
if ( !VersionUtil.isSnapshot( artifactRef.getVersion() ) )
if ( !VersionUtil.isSnapshot( artifactRef.getVersion( ) ) )
{
// Nothing to do here, not a snapshot, skip it.
return;
}
ProjectReference reference = new ProjectReference();
reference.setGroupId( artifactRef.getGroupId() );
reference.setArtifactId( artifactRef.getArtifactId() );
ProjectReference reference = new ProjectReference( );
reference.setGroupId( artifactRef.getGroupId( ) );
reference.setArtifactId( artifactRef.getArtifactId( ) );
// 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 )
{
if ( repo.isReleases() )
if ( repo.isReleases( ) )
{
try
{
ManagedRepositoryContent repoContent =
repoContentFactory.getManagedRepositoryContent( repo.getId() );
repoContentFactory.getManagedRepositoryContent( repo.getId( ) );
for ( String version : repoContent.getVersions( reference ) )
{
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.
boolean needsMetadataUpdate = false;
VersionedReference versionRef = new VersionedReference();
versionRef.setGroupId( artifactRef.getGroupId() );
versionRef.setArtifactId( artifactRef.getArtifactId() );
VersionedReference versionRef = new VersionedReference( );
versionRef.setGroupId( artifactRef.getGroupId( ) );
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 );
for ( RepositoryListener listener : listeners )
{
listener.deleteArtifact( metadataRepository, repository.getId(), artifactRef.getGroupId(),
artifactRef.getArtifactId(), artifactRef.getVersion(),
artifactFile.getName() );
listener.deleteArtifact( metadataRepository, repository.getId( ), artifactRef.getGroupId( ),
artifactRef.getArtifactId( ), artifactRef.getVersion( ),
artifactFile.getName( ) );
}
metadataRepository.removeProjectVersion( repository.getId(), artifactRef.getGroupId(),
artifactRef.getArtifactId(), artifactRef.getVersion());
metadataRepository.removeProjectVersion( repository.getId( ), artifactRef.getGroupId( ),
artifactRef.getArtifactId( ), artifactRef.getVersion( ) );
needsMetadataUpdate = true;
}
@ -176,34 +176,35 @@ public class CleanupReleasedSnapshotsRepositoryPurge
{
updateMetadata( artifactRef );
}
} catch ( RepositoryAdminException e )
}
catch ( RepositoryAdminException e )
{
throw new RepositoryPurgeException( e.getMessage(), e );
throw new RepositoryPurgeException( e.getMessage( ), 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 )
{
throw new RepositoryPurgeException( e.getMessage(), e );
throw new RepositoryPurgeException( e.getMessage( ), 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 )
{
VersionedReference versionRef = new VersionedReference();
versionRef.setGroupId( artifact.getGroupId() );
versionRef.setArtifactId( artifact.getArtifactId() );
versionRef.setVersion( artifact.getVersion() );
VersionedReference versionRef = new VersionedReference( );
versionRef.setGroupId( artifact.getGroupId( ) );
versionRef.setArtifactId( artifact.getArtifactId( ) );
versionRef.setVersion( artifact.getVersion( ) );
ProjectReference projectRef = new ProjectReference();
projectRef.setGroupId( artifact.getGroupId() );
projectRef.setArtifactId( artifact.getArtifactId() );
ProjectReference projectRef = new ProjectReference( );
projectRef.setGroupId( artifact.getGroupId( ) );
projectRef.setArtifactId( artifact.getArtifactId( ) );
try
{

View File

@ -70,9 +70,9 @@ public class DaysOldRepositoryPurge
{
try
{
File artifactFile = new File( repository.getRepoRoot(), path );
File artifactFile = new File( repository.getRepoRoot( ), path );
if ( !artifactFile.exists() )
if ( !artifactFile.exists( ) )
{
return;
}
@ -83,24 +83,24 @@ public class DaysOldRepositoryPurge
olderThanThisDate.add( Calendar.DATE, -daysOlder );
// respect retention count
VersionedReference reference = new VersionedReference();
reference.setGroupId( artifact.getGroupId() );
reference.setArtifactId( artifact.getArtifactId() );
reference.setVersion( artifact.getVersion() );
VersionedReference reference = new VersionedReference( );
reference.setGroupId( artifact.getGroupId( ) );
reference.setArtifactId( artifact.getArtifactId( ) );
reference.setVersion( artifact.getVersion( ) );
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.
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 )
{
if ( countToPurge-- <= 0 )
@ -109,39 +109,39 @@ public class DaysOldRepositoryPurge
}
ArtifactReference newArtifactReference = repository.toArtifactReference(
artifactFile.getAbsolutePath() );
artifactFile.getAbsolutePath( ) );
newArtifactReference.setVersion( version );
File newArtifactFile = repository.toFile( newArtifactReference );
// 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" ?
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 )
{
throw new RepositoryPurgeException( e.getMessage(), e );
throw new RepositoryPurgeException( e.getMessage( ), 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}
Matcher m = VersionUtil.UNIQUE_SNAPSHOT_PATTERN.matcher( version );
if ( m.matches() )
if ( m.matches( ) )
{
Matcher mtimestamp = VersionUtil.TIMESTAMP_PATTERN.matcher( m.group( 2 ) );
if ( mtimestamp.matches() )
if ( mtimestamp.matches( ) )
{
String tsDate = mtimestamp.group( 1 );
String tsTime = mtimestamp.group( 2 );

View File

@ -27,7 +27,7 @@ public interface RepositoryPurge
/**
* Perform checking on artifact for repository purge
*
* @param path path to the scanned artifact
* @param path path to the scanned artifact
*/
void process( String path )
throws RepositoryPurgeException;

View File

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

View File

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

View File

@ -57,53 +57,53 @@ public class RetentionCountRepositoryPurge
{
try
{
File artifactFile = new File( repository.getRepoRoot(), path );
File artifactFile = new File( repository.getRepoRoot( ), path );
if ( !artifactFile.exists() )
if ( !artifactFile.exists( ) )
{
return;
}
ArtifactReference artifact = repository.toArtifactReference( path );
if ( VersionUtil.isSnapshot( artifact.getVersion() ) )
if ( VersionUtil.isSnapshot( artifact.getVersion( ) ) )
{
VersionedReference reference = new VersionedReference();
reference.setGroupId( artifact.getGroupId() );
reference.setArtifactId( artifact.getArtifactId() );
reference.setVersion( artifact.getVersion() );
VersionedReference reference = new VersionedReference( );
reference.setGroupId( artifact.getGroupId( ) );
reference.setArtifactId( artifact.getArtifactId( ) );
reference.setVersion( artifact.getVersion( ) );
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.
return;
}
int countToPurge = versions.size() - retentionCount;
Set<ArtifactReference> artifactsToDelete = new HashSet<>();
int countToPurge = versions.size( ) - retentionCount;
Set<ArtifactReference> artifactsToDelete = new HashSet<>( );
for ( String version : versions )
{
if ( countToPurge-- <= 0 )
{
break;
}
artifactsToDelete.addAll(repository.getRelatedArtifacts( getNewArtifactReference( artifact, version) ));
artifactsToDelete.addAll( repository.getRelatedArtifacts( getNewArtifactReference( artifact, version ) ) );
}
purge(artifactsToDelete);
purge( artifactsToDelete );
}
}
catch ( LayoutException le )
{
throw new RepositoryPurgeException( le.getMessage(), le );
throw new RepositoryPurgeException( le.getMessage( ), le );
}
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 )
throws LayoutException
{
ArtifactReference artifact = new ArtifactReference();
artifact.setGroupId( reference.getGroupId() );
artifact.setArtifactId( reference.getArtifactId() );
ArtifactReference artifact = new ArtifactReference( );
artifact.setGroupId( reference.getGroupId( ) );
artifact.setArtifactId( reference.getArtifactId( ) );
artifact.setVersion( version );
artifact.setClassifier( reference.getClassifier() );
artifact.setType( reference.getType() );
artifact.setClassifier( reference.getClassifier( ) );
artifact.setType( reference.getType( ) );
return artifact;
}