//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; | ||||
} | } | ||||
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 | ||||
} | } | ||||
@Override | @Override | ||||
public void completeScan() | |||||
public void completeScan( ) | |||||
{ | { | ||||
/* do nothing */ | /* do nothing */ | ||||
} | } | ||||
@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; | ||||
} | } | ||||
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 } ); | |||||
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 ) | 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() ); | |||||
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 ) | 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." ); | |||||
} | } | ||||
} | } | ||||
*/ | */ | ||||
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( ); | |||||
} | } | ||||
} | } |
/** | /** | ||||
* AutoRemoveConsumer | * AutoRemoveConsumer | ||||
* | |||||
* | |||||
*/ | */ | ||||
@Service( "knownRepositoryContentConsumer#auto-remove" ) | @Service( "knownRepositoryContentConsumer#auto-remove" ) | ||||
@Scope( "prototype" ) | @Scope( "prototype" ) | ||||
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; | ||||
} | } | ||||
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 | ||||
} | } | ||||
@Override | @Override | ||||
public void completeScan() | |||||
public void completeScan( ) | |||||
{ | { | ||||
/* do nothing */ | /* do nothing */ | ||||
} | } | ||||
@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; | ||||
} | } | ||||
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() ); | |||||
triggerConsumerInfo( "(Auto) Removing File: " + file.getAbsolutePath() ); | |||||
file.delete(); | |||||
log.info( "(Auto) Removing File: {}", file.getAbsolutePath( ) ); | |||||
triggerConsumerInfo( "(Auto) Removing File: " + file.getAbsolutePath( ) ); | |||||
file.delete( ); | |||||
} | } | ||||
} | } | ||||
{ | { | ||||
if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) | if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) | ||||
{ | { | ||||
initIncludes(); | |||||
initIncludes( ); | |||||
} | } | ||||
} | } | ||||
/* 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( ); | |||||
} | } | ||||
} | } |
/** | /** | ||||
* AutoRenameConsumer | * AutoRenameConsumer | ||||
* | |||||
* | |||||
*/ | */ | ||||
@Service( "knownRepositoryContentConsumer#auto-rename" ) | @Service( "knownRepositoryContentConsumer#auto-rename" ) | ||||
@Scope( "prototype" ) | @Scope( "prototype" ) | ||||
extends AbstractMonitoredConsumer | extends AbstractMonitoredConsumer | ||||
implements KnownRepositoryContentConsumer | implements KnownRepositoryContentConsumer | ||||
{ | { | ||||
private Logger log = LoggerFactory.getLogger( AutoRenameConsumer.class ); | |||||
private Logger log = LoggerFactory.getLogger( AutoRenameConsumer.class ); | |||||
private String id = "auto-rename"; | private String id = "auto-rename"; | ||||
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" ); | ||||
} | } | ||||
@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; | ||||
} | } | ||||
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 | ||||
} | } | ||||
@Override | @Override | ||||
public void completeScan() | |||||
public void completeScan( ) | |||||
{ | { | ||||
/* do nothing */ | /* do nothing */ | ||||
} | } | ||||
@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; | ||||
} | } | ||||
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(); | |||||
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 ) ) | 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 | ||||
{ | { | ||||
{ | { | ||||
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() ); | |||||
triggerConsumerInfo( "(Auto) Removing File: " + file.getAbsolutePath() ); | |||||
file.delete(); | |||||
log.info( "(Auto) Removing File: {} ", file.getAbsolutePath( ) ); | |||||
triggerConsumerInfo( "(Auto) Removing File: " + file.getAbsolutePath( ) ); | |||||
file.delete( ); | |||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* 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" ) | ||||
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; | ||||
} | } | ||||
{ | { | ||||
try | 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 ) | 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 ); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@Override | @Override | ||||
public void completeScan() | |||||
public void completeScan( ) | |||||
{ | { | ||||
/* do nothing here */ | /* do nothing here */ | ||||
} | } | ||||
@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; | ||||
} | } | ||||
} | } | ||||
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( ) ); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
private void updateProjectMetadata( ArtifactReference artifact, String path ) | 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 | try | ||||
{ | { | ||||
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 ) ); | ||||
{ | { | ||||
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: " | |||||
+ e.getMessage() ); | |||||
"Unable to convert path [" + path + "] to an internal project reference: " | |||||
+ 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: " | |||||
+ e.getMessage() ); | |||||
"Project metadata not written because no versions were found to update: " | |||||
+ e.getMessage( ) ); | |||||
} | } | ||||
} | } | ||||
private void updateVersionMetadata( ArtifactReference artifact, String path ) | 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 | try | ||||
{ | { | ||||
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 ) ); | ||||
{ | { | ||||
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: " | |||||
+ e.getMessage() ); | |||||
"Unable to convert path [" + path + "] to an internal version reference: " | |||||
+ 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: " | |||||
+ e.getMessage() ); | |||||
"Version metadata not written because no versions were found to update: " | |||||
+ e.getMessage( ) ); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
*/ | */ | ||||
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( ); | |||||
} | } | ||||
} | } |
/** | /** | ||||
* 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" ) | ||||
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; | ||||
} | } | ||||
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 | ||||
} | } | ||||
@Override | @Override | ||||
public void completeScan() | |||||
public void completeScan( ) | |||||
{ | { | ||||
/* nothing to do */ | /* nothing to do */ | ||||
} | } | ||||
@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; | ||||
} | } | ||||
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 ) | ||||
{ | { | ||||
log.error( "Digester failure during checksum validation on {}", checksumFile ); | log.error( "Digester failure during checksum validation on {}", checksumFile ); | ||||
triggerConsumerError( CHECKSUM_DIGESTER_FAILURE, | triggerConsumerError( CHECKSUM_DIGESTER_FAILURE, | ||||
"Digester failure during checksum validation on " + checksumFile ); | |||||
"Digester failure during checksum validation on " + checksumFile ); | |||||
} | } | ||||
catch ( IOException e ) | catch ( IOException e ) | ||||
{ | { | ||||
} | } | ||||
@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() ); | |||||
includes = new ArrayList<>( allDigesters.size() ); | |||||
List<Digester> allDigesters = new ArrayList<>( digesterUtils.getAllDigesters( ) ); | |||||
includes = new ArrayList<>( allDigesters.size( ) ); | |||||
for ( Digester digester : allDigesters ) | for ( Digester digester : allDigesters ) | ||||
{ | { | ||||
includes.add( "**/*" + digester.getFilenameExtension() ); | |||||
includes.add( "**/*" + digester.getFilenameExtension( ) ); | |||||
} | } | ||||
} | } | ||||
} | } |
} | } | ||||
} | } | ||||
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 ); | |||||
} | } | ||||
} | } | ||||
*/ | */ | ||||
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, | |||||
( 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 ) | 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 ); | |||||
} | } | ||||
} | } |
{ | { | ||||
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; | ||||
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(); | |||||
reference.setGroupId( artifactRef.getGroupId() ); | |||||
reference.setArtifactId( artifactRef.getArtifactId() ); | |||||
ProjectReference reference = new ProjectReference( ); | |||||
reference.setGroupId( artifactRef.getGroupId( ) ); | |||||
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 ) ) | ||||
} | } | ||||
} | } | ||||
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(); | |||||
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 ); | repository.deleteVersion( versionRef ); | ||||
for ( RepositoryListener listener : listeners ) | 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; | needsMetadataUpdate = true; | ||||
} | } | ||||
{ | { | ||||
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(); | |||||
versionRef.setGroupId( artifact.getGroupId() ); | |||||
versionRef.setArtifactId( artifact.getArtifactId() ); | |||||
versionRef.setVersion( artifact.getVersion() ); | |||||
ProjectReference projectRef = new ProjectReference(); | |||||
projectRef.setGroupId( artifact.getGroupId() ); | |||||
projectRef.setArtifactId( artifact.getArtifactId() ); | |||||
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( ) ); | |||||
try | try | ||||
{ | { |
{ | { | ||||
try | try | ||||
{ | { | ||||
File artifactFile = new File( repository.getRepoRoot(), path ); | |||||
File artifactFile = new File( repository.getRepoRoot( ), path ); | |||||
if ( !artifactFile.exists() ) | |||||
if ( !artifactFile.exists( ) ) | |||||
{ | { | ||||
return; | return; | ||||
} | } | ||||
olderThanThisDate.add( Calendar.DATE, -daysOlder ); | olderThanThisDate.add( Calendar.DATE, -daysOlder ); | ||||
// respect retention count | // 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 ) ); | 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 ) | ||||
} | } | ||||
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( ) ); | |||||
} | } | ||||
} | } | ||||
// 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 ); |
/** | /** | ||||
* Perform checking on artifact for repository purge | * 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 ) | void process( String path ) | ||||
throws RepositoryPurgeException; | throws RepositoryPurgeException; |
@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; | ||||
* | * | ||||
*/ | */ | ||||
@Inject | @Inject | ||||
@Autowired(required = false) | |||||
private List<RepositoryListener> listeners = Collections.emptyList(); | |||||
@Autowired( required = false ) | |||||
private List<RepositoryListener> listeners = Collections.emptyList( ); | |||||
@Inject | @Inject | ||||
private RepositorySessionFactory repositorySessionFactory; | private RepositorySessionFactory repositorySessionFactory; | ||||
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; | ||||
} | } | ||||
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(), | |||||
repository.getRetentionCount(), repositorySession, listeners ); | |||||
repoPurge = new DaysOldRepositoryPurge( repositoryContent, repository.getDaysOlder( ), | |||||
repository.getRetentionCount( ), repositorySession, listeners ); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
repoPurge = | repoPurge = | ||||
new RetentionCountRepositoryPurge( repositoryContent, repository.getRetentionCount(), repositorySession, | |||||
listeners ); | |||||
new RetentionCountRepositoryPurge( repositoryContent, repository.getRetentionCount( ), repositorySession, | |||||
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 | ||||
} | } | ||||
catch ( RepositoryPurgeException rpe ) | catch ( RepositoryPurgeException rpe ) | ||||
{ | { | ||||
throw new ConsumerException( rpe.getMessage(), rpe ); | |||||
throw new ConsumerException( rpe.getMessage( ), rpe ); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@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 | ||||
{ | { | ||||
if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) | if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) | ||||
{ | { | ||||
initIncludes(); | |||||
initIncludes( ); | |||||
} | } | ||||
} | } | ||||
/* 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; | ||||
} | } | ||||
this.configuration = configuration; | this.configuration = configuration; | ||||
} | } | ||||
public RepositoryContentFactory getRepositoryContentFactory() | |||||
public RepositoryContentFactory getRepositoryContentFactory( ) | |||||
{ | { | ||||
return repositoryContentFactory; | return repositoryContentFactory; | ||||
} | } | ||||
this.repositoryContentFactory = repositoryContentFactory; | this.repositoryContentFactory = repositoryContentFactory; | ||||
} | } | ||||
public MetadataTools getMetadataTools() | |||||
public MetadataTools getMetadataTools( ) | |||||
{ | { | ||||
return metadataTools; | return metadataTools; | ||||
} | } | ||||
this.metadataTools = metadataTools; | this.metadataTools = metadataTools; | ||||
} | } | ||||
public FileTypes getFiletypes() | |||||
public FileTypes getFiletypes( ) | |||||
{ | { | ||||
return filetypes; | return filetypes; | ||||
} | } | ||||
this.filetypes = filetypes; | this.filetypes = filetypes; | ||||
} | } | ||||
public RepositoryPurge getRepoPurge() | |||||
public RepositoryPurge getRepoPurge( ) | |||||
{ | { | ||||
return repoPurge; | return repoPurge; | ||||
} | } | ||||
this.repoPurge = repoPurge; | this.repoPurge = repoPurge; | ||||
} | } | ||||
public RepositoryPurge getCleanUp() | |||||
public RepositoryPurge getCleanUp( ) | |||||
{ | { | ||||
return cleanUp; | return cleanUp; | ||||
} | } | ||||
this.cleanUp = cleanUp; | this.cleanUp = cleanUp; | ||||
} | } | ||||
public boolean isDeleteReleasedSnapshots() | |||||
public boolean isDeleteReleasedSnapshots( ) | |||||
{ | { | ||||
return deleteReleasedSnapshots; | return deleteReleasedSnapshots; | ||||
} | } | ||||
this.deleteReleasedSnapshots = deleteReleasedSnapshots; | this.deleteReleasedSnapshots = deleteReleasedSnapshots; | ||||
} | } | ||||
public RepositorySessionFactory getRepositorySessionFactory() | |||||
public RepositorySessionFactory getRepositorySessionFactory( ) | |||||
{ | { | ||||
return repositorySessionFactory; | return repositorySessionFactory; | ||||
} | } | ||||
this.repositorySessionFactory = repositorySessionFactory; | this.repositorySessionFactory = repositorySessionFactory; | ||||
} | } | ||||
public RepositorySession getRepositorySession() | |||||
public RepositorySession getRepositorySession( ) | |||||
{ | { | ||||
return repositorySession; | return repositorySession; | ||||
} | } |
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 ) |
{ | { | ||||
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(); | |||||
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 ) ); | 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; | |||||
Set<ArtifactReference> artifactsToDelete = new HashSet<>(); | |||||
int countToPurge = versions.size( ) - retentionCount; | |||||
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 ); | |||||
} | } | ||||
} | } | ||||
private ArtifactReference getNewArtifactReference( ArtifactReference reference, String version ) | private ArtifactReference getNewArtifactReference( ArtifactReference reference, String version ) | ||||
throws LayoutException | 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.setVersion( version ); | ||||
artifact.setClassifier( reference.getClassifier() ); | |||||
artifact.setType( reference.getType() ); | |||||
artifact.setClassifier( reference.getClassifier( ) ); | |||||
artifact.setType( reference.getType( ) ); | |||||
return artifact; | return artifact; | ||||
} | } |