From 58b11bca241f88957691ba0cf892e852108523c0 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 16 Sep 2011 08:54:07 +0000 Subject: [MRM-1003] Repackage sources from org.apache.maven.archiva.. to org.apache.archiva.. : archiva-consumer-api module git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1171453 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva/cli/AbstractProgressConsumer.java | 6 +- .../java/org/apache/archiva/cli/ArchivaCli.java | 8 +- .../apache/archiva/cli/ArtifactCountConsumer.java | 2 +- .../consumers/AbstractMonitoredConsumer.java | 108 ++++++ .../org/apache/archiva/consumers/Consumer.java | 63 ++++ .../archiva/consumers/ConsumerException.java | 41 +++ .../apache/archiva/consumers/ConsumerMonitor.java | 54 +++ .../InvalidRepositoryContentConsumer.java | 31 ++ .../consumers/KnownRepositoryContentConsumer.java | 31 ++ .../consumers/RepositoryContentConsumer.java | 131 ++++++++ .../functors/ConsumerWantsFilePredicate.java | 135 ++++++++ .../functors/PermanentConsumerPredicate.java | 47 +++ .../consumers/AbstractMonitoredConsumer.java | 108 ------ .../apache/maven/archiva/consumers/Consumer.java | 63 ---- .../maven/archiva/consumers/ConsumerException.java | 41 --- .../maven/archiva/consumers/ConsumerMonitor.java | 54 --- .../InvalidRepositoryContentConsumer.java | 31 -- .../consumers/KnownRepositoryContentConsumer.java | 31 -- .../consumers/RepositoryContentConsumer.java | 131 -------- .../functors/ConsumerWantsFilePredicate.java | 135 -------- .../functors/PermanentConsumerPredicate.java | 47 --- .../core/ArtifactMissingChecksumsConsumer.java | 214 ++++++++++++ .../archiva/consumers/core/AutoRemoveConsumer.java | 169 ++++++++++ .../archiva/consumers/core/AutoRenameConsumer.java | 164 +++++++++ .../consumers/core/MetadataUpdaterConsumer.java | 324 ++++++++++++++++++ .../consumers/core/ValidateChecksumConsumer.java | 183 ++++++++++ .../core/repository/AbstractRepositoryPurge.java | 138 ++++++++ .../core/repository/ArtifactFilenameFilter.java | 48 +++ .../CleanupReleasedSnapshotsRepositoryPurge.java | 266 +++++++++++++++ .../core/repository/DaysOldRepositoryPurge.java | 190 +++++++++++ .../consumers/core/repository/RepositoryPurge.java | 35 ++ .../core/repository/RepositoryPurgeConsumer.java | 350 +++++++++++++++++++ .../core/repository/RepositoryPurgeException.java | 48 +++ .../repository/RetentionCountRepositoryPurge.java | 129 +++++++ .../core/ArtifactMissingChecksumsConsumer.java | 214 ------------ .../archiva/consumers/core/AutoRemoveConsumer.java | 169 ---------- .../archiva/consumers/core/AutoRenameConsumer.java | 164 --------- .../consumers/core/MetadataUpdaterConsumer.java | 324 ------------------ .../consumers/core/ValidateChecksumConsumer.java | 183 ---------- .../core/repository/AbstractRepositoryPurge.java | 138 -------- .../core/repository/ArtifactFilenameFilter.java | 48 --- .../CleanupReleasedSnapshotsRepositoryPurge.java | 266 --------------- .../core/repository/DaysOldRepositoryPurge.java | 190 ----------- .../consumers/core/repository/RepositoryPurge.java | 35 -- .../core/repository/RepositoryPurgeConsumer.java | 350 ------------------- .../core/repository/RepositoryPurgeException.java | 48 --- .../repository/RetentionCountRepositoryPurge.java | 129 ------- .../src/main/resources/META-INF/spring-context.xml | 4 +- .../core/AbstractArtifactConsumerTest.java | 93 +++++ .../core/ArtifactMissingChecksumsConsumerTest.java | 105 ++++++ .../consumers/core/MetadataUpdateConsumerTest.java | 36 ++ .../repository/AbstractRepositoryPurgeTest.java | 181 ++++++++++ ...leanupReleasedSnapshotsRepositoryPurgeTest.java | 295 ++++++++++++++++ .../repository/DaysOldRepositoryPurgeTest.java | 233 +++++++++++++ .../repository/RepositoryPurgeConsumerTest.java | 373 +++++++++++++++++++++ .../RetentionCountRepositoryPurgeTest.java | 200 +++++++++++ .../core/AbstractArtifactConsumerTest.java | 93 ----- .../core/ArtifactMissingChecksumsConsumerTest.java | 105 ------ .../consumers/core/MetadataUpdateConsumerTest.java | 36 -- .../repository/AbstractRepositoryPurgeTest.java | 181 ---------- ...leanupReleasedSnapshotsRepositoryPurgeTest.java | 295 ---------------- .../repository/DaysOldRepositoryPurgeTest.java | 233 ------------- .../repository/RepositoryPurgeConsumerTest.java | 373 --------------------- .../RetentionCountRepositoryPurgeTest.java | 200 ----------- .../spring-context-purge-consumer-test.xml | 4 +- .../consumers/lucene/NexusIndexerConsumer.java | 6 +- .../consumers/lucene/NexusIndexerConsumerTest.java | 2 +- .../metadata/ArchivaMetadataCreationConsumer.java | 6 +- .../legacy/DefaultLegacyRepositoryConverter.java | 4 +- .../legacy/LegacyConverterArtifactConsumer.java | 6 +- .../scanner/DefaultRepositoryScanner.java | 6 +- .../scanner/RepositoryContentConsumers.java | 6 +- .../repository/scanner/RepositoryScanner.java | 4 +- .../scanner/RepositoryScannerInstance.java | 6 +- .../functors/ConsumerProcessFileClosure.java | 2 +- .../scanner/functors/TriggerBeginScanClosure.java | 4 +- .../functors/TriggerScanCompletedClosure.java | 2 +- .../repository/scanner/InvalidScanConsumer.java | 6 +- .../repository/scanner/KnownScanConsumer.java | 6 +- .../scanner/RepositoryContentConsumersTest.java | 4 +- .../repository/scanner/RepositoryScannerTest.java | 4 +- .../repository/scanner/SampleKnownConsumer.java | 6 +- .../archiva/scheduler/repository/TestConsumer.java | 6 +- .../scanning/AddAdminRepoConsumerClosure.java | 2 +- .../webdav/StubRepositoryContentConsumers.java | 4 +- .../xmlrpc/services/AdministrationServiceImpl.java | 4 +- .../services/AdministrationServiceImplTest.java | 4 +- .../consumers/DuplicateArtifactsConsumer.java | 6 +- .../consumers/DuplicateArtifactsConsumerTest.java | 2 +- 89 files changed, 4481 insertions(+), 4481 deletions(-) create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/AbstractMonitoredConsumer.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/Consumer.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/ConsumerException.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/ConsumerMonitor.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/InvalidRepositoryContentConsumer.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/KnownRepositoryContentConsumer.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/RepositoryContentConsumer.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/functors/ConsumerWantsFilePredicate.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/functors/PermanentConsumerPredicate.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/AbstractMonitoredConsumer.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/Consumer.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/ConsumerException.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/ConsumerMonitor.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/InvalidRepositoryContentConsumer.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/KnownRepositoryContentConsumer.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/RepositoryContentConsumer.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/functors/ConsumerWantsFilePredicate.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/functors/PermanentConsumerPredicate.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/AutoRemoveConsumer.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/AutoRenameConsumer.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ValidateChecksumConsumer.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/ArtifactFilenameFilter.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurge.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurge.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumer.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeException.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRemoveConsumer.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRenameConsumer.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/MetadataUpdaterConsumer.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ValidateChecksumConsumer.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/ArtifactFilenameFilter.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurge.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurge.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumer.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeException.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/AbstractArtifactConsumerTest.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/MetadataUpdateConsumerTest.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java create mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/AbstractArtifactConsumerTest.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/MetadataUpdateConsumerTest.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java delete mode 100644 archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java diff --git a/archiva-cli/src/main/java/org/apache/archiva/cli/AbstractProgressConsumer.java b/archiva-cli/src/main/java/org/apache/archiva/cli/AbstractProgressConsumer.java index a5ef33103..be78cb872 100644 --- a/archiva-cli/src/main/java/org/apache/archiva/cli/AbstractProgressConsumer.java +++ b/archiva-cli/src/main/java/org/apache/archiva/cli/AbstractProgressConsumer.java @@ -20,9 +20,9 @@ package org.apache.archiva.cli; */ import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; -import org.apache.maven.archiva.consumers.ConsumerException; -import org.apache.maven.archiva.consumers.RepositoryContentConsumer; +import org.apache.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.archiva.consumers.ConsumerException; +import org.apache.archiva.consumers.RepositoryContentConsumer; import java.util.Date; diff --git a/archiva-cli/src/main/java/org/apache/archiva/cli/ArchivaCli.java b/archiva-cli/src/main/java/org/apache/archiva/cli/ArchivaCli.java index e8fbb3c3a..4dc1bafbb 100644 --- a/archiva-cli/src/main/java/org/apache/archiva/cli/ArchivaCli.java +++ b/archiva-cli/src/main/java/org/apache/archiva/cli/ArchivaCli.java @@ -31,10 +31,10 @@ import org.apache.archiva.repository.scanner.RepositoryScanner; import org.apache.archiva.repository.scanner.RepositoryScannerException; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; -import org.apache.maven.archiva.consumers.ConsumerException; -import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.RepositoryContentConsumer; +import org.apache.archiva.consumers.ConsumerException; +import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.RepositoryContentConsumer; import org.apache.maven.artifact.manager.WagonManager; import org.springframework.context.support.ClassPathXmlApplicationContext; diff --git a/archiva-cli/src/main/java/org/apache/archiva/cli/ArtifactCountConsumer.java b/archiva-cli/src/main/java/org/apache/archiva/cli/ArtifactCountConsumer.java index 865e99245..ce647cef8 100644 --- a/archiva-cli/src/main/java/org/apache/archiva/cli/ArtifactCountConsumer.java +++ b/archiva-cli/src/main/java/org/apache/archiva/cli/ArtifactCountConsumer.java @@ -19,7 +19,7 @@ package org.apache.archiva.cli; * under the License. */ -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/AbstractMonitoredConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/AbstractMonitoredConsumer.java new file mode 100644 index 000000000..324f0c1d4 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/AbstractMonitoredConsumer.java @@ -0,0 +1,108 @@ +package org.apache.archiva.consumers; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.common.FileTypeUtils; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +/** + * AbstractMonitoredConsumer + * + * @version $Id$ + */ +public abstract class AbstractMonitoredConsumer + implements Consumer +{ + private Set monitors = new HashSet(); + + public void addConsumerMonitor( ConsumerMonitor monitor ) + { + monitors.add( monitor ); + } + + public void removeConsumerMonitor( ConsumerMonitor monitor ) + { + monitors.remove( monitor ); + } + + protected void triggerConsumerError( String type, String message ) + { + for ( Iterator itmonitors = monitors.iterator(); itmonitors.hasNext(); ) + { + ConsumerMonitor monitor = itmonitors.next(); + try + { + monitor.consumerError( this, type, message ); + } + catch ( Throwable t ) + { + /* discard error */ + } + } + } + + protected void triggerConsumerWarning( String type, String message ) + { + for ( Iterator itmonitors = monitors.iterator(); itmonitors.hasNext(); ) + { + ConsumerMonitor monitor = itmonitors.next(); + try + { + monitor.consumerWarning( this, type, message ); + } + catch ( Throwable t ) + { + /* discard error */ + } + } + } + + protected void triggerConsumerInfo( String message ) + { + for ( Iterator itmonitors = monitors.iterator(); itmonitors.hasNext(); ) + { + ConsumerMonitor monitor = itmonitors.next(); + try + { + monitor.consumerInfo( this, message ); + } + catch ( Throwable t ) + { + /* discard error */ + } + } + } + + public boolean isProcessUnmodified() + { + return false; + } + + protected List getDefaultArtifactExclusions() + { + return FileTypeUtils.DEFAULT_EXCLUSIONS; + } + + +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/Consumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/Consumer.java new file mode 100644 index 000000000..d50fe97eb --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/Consumer.java @@ -0,0 +1,63 @@ +package org.apache.archiva.consumers; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Consumer - the base set of methods for a consumer. + * + * @version $Id$ + */ +public abstract interface Consumer +{ + /** + * This is the id for the consumer. + * + * @return the consumer id. + */ + public String getId(); + + /** + * The human readable description for this consumer. + * + * @return the human readable description for this consumer. + */ + public String getDescription(); + + /** + * Flag indicating permanance of consumer. (if it can be disabled or not) + * + * @return true indicating that consumer is permanent and cannot be disabled. + */ + public boolean isPermanent(); + + /** + * Add a consumer monitor to the consumer. + * + * @param monitor the monitor to add. + */ + public void addConsumerMonitor( ConsumerMonitor monitor ); + + /** + * Remove a consumer monitor. + * + * @param monitor the monitor to remove. + */ + public void removeConsumerMonitor( ConsumerMonitor monitor ); +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/ConsumerException.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/ConsumerException.java new file mode 100644 index 000000000..f9fbf0343 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/ConsumerException.java @@ -0,0 +1,41 @@ +package org.apache.archiva.consumers; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.common.ArchivaException; + +/** + * ConsumerException - details about the failure of a consumer. + * + * @version $Id$ + */ +public class ConsumerException + extends ArchivaException +{ + public ConsumerException( String message, Throwable cause ) + { + super( message, cause ); + } + + public ConsumerException( String message ) + { + super( message ); + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/ConsumerMonitor.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/ConsumerMonitor.java new file mode 100644 index 000000000..dcbbdec94 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/ConsumerMonitor.java @@ -0,0 +1,54 @@ +package org.apache.archiva.consumers; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * ConsumerMonitor - a monitor for consumers. + * + * @version $Id$ + */ +public interface ConsumerMonitor +{ + /** + * A consumer error event. + * + * @param consumer the consumer that caused the error. + * @param type the type of error. + * @param message the message about the error. + */ + public void consumerError( Consumer consumer, String type, String message ); + + /** + * A consumer warning event. + * + * @param consumer the consumer that caused the warning. + * @param type the type of warning. + * @param message the message about the warning. + */ + public void consumerWarning( Consumer consumer, String type, String message ); + + /** + * A consumer informational event. + * + * @param consumer the consumer that caused the informational message. + * @param message the message. + */ + public void consumerInfo( Consumer consumer, String message ); +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/InvalidRepositoryContentConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/InvalidRepositoryContentConsumer.java new file mode 100644 index 000000000..3b2e7583e --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/InvalidRepositoryContentConsumer.java @@ -0,0 +1,31 @@ +package org.apache.archiva.consumers; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Consumer for Invalid Repository Content + * + * @version $Id$ + */ +public interface InvalidRepositoryContentConsumer + extends RepositoryContentConsumer +{ + // no op +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/KnownRepositoryContentConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/KnownRepositoryContentConsumer.java new file mode 100644 index 000000000..93cc10a48 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/KnownRepositoryContentConsumer.java @@ -0,0 +1,31 @@ +package org.apache.archiva.consumers; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Consumer for Known Repository Content. + * + * @version $Id$ + */ +public interface KnownRepositoryContentConsumer + extends RepositoryContentConsumer +{ + // no op +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/RepositoryContentConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/RepositoryContentConsumer.java new file mode 100644 index 000000000..8591d2fe2 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/RepositoryContentConsumer.java @@ -0,0 +1,131 @@ +package org.apache.archiva.consumers; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.admin.model.beans.ManagedRepository; + +import java.util.Date; +import java.util.List; + +/** + * A consumer of content (files) in the repository. + * + * @version $Id$ + */ +public interface RepositoryContentConsumer + extends Consumer +{ + /** + * Get the list of included file patterns for this consumer. + * + * @return the list of {@link String} patterns. (example: "**/*.pom") + */ + List getIncludes(); + + /** + * Get the list of excluded file patterns for this consumer. + * + * @return the list of {@link String} patterns. (example: "**/*.pom") - (can be null for no exclusions) + */ + List getExcludes(); + + /** + *

+ * Event that triggers at the beginning of a scan. + *

+ *

+ *

+ * NOTE: This would be a good place to initialize the consumer, to lock any resources, and to + * generally start tracking the scan as a whole. + *

+ * + * @param repository the repository that this consumer is being used for. + * @param whenGathered the start of the repository scan + * @throws ConsumerException if there was a problem with using the provided repository with the consumer. + */ + void beginScan( ManagedRepository repository, Date whenGathered ) + throws ConsumerException; + + /** + *

+ * Event that triggers at the beginning of a scan, where you can also indicate whether the consumers will be + * executed on an entire repository or on a specific resource. + *

+ * + * @param repository the repository that this consumer is being used for. + * @param whenGathered the start of the repository scan + * @param executeOnEntireRepo flags whether the consumer will be executed on an entire repository or just on a specific resource + * @throws ConsumerException if there was a problem with using the provided repository with the consumer. + * @see RepositoryContentConsumer#beginScan(ManagedRepository, java.util.Date) + */ + void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo ) + throws ConsumerException; + + /** + *

+ * Event indicating a file is to be processed by this consumer. + *

+ *

+ *

+ * NOTE: The consumer does not need to process the file immediately, can can opt to queue and/or track + * the files to be processed in batch. Just be sure to complete the processing by the {@link #completeScan()} + * event. + *

+ * + * @param path the relative file path (in the repository) to process. + * @throws ConsumerException if there was a problem processing this file. + */ + void processFile( String path ) + throws ConsumerException; + + /** + * @param path + * @param executeOnEntireRepo + * @throws Exception + */ + void processFile( String path, boolean executeOnEntireRepo ) + throws Exception; + + /** + *

+ * Event that triggers on the completion of a scan. + *

+ *

+ *

+ * NOTE: If the consumer opted to batch up processing requests in the {@link #processFile(String)} event + * this would be the last opportunity to drain any processing queue's. + *

+ */ + void completeScan(); + + /** + * @param executeOnEntireRepo + * @throws Exception + */ + void completeScan( boolean executeOnEntireRepo ); + + /** + * Whether the consumer should process files that have not been modified since the time passed in to the scan + * method. + * + * @return whether to process the unmodified files + */ + boolean isProcessUnmodified(); +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/functors/ConsumerWantsFilePredicate.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/functors/ConsumerWantsFilePredicate.java new file mode 100644 index 000000000..7fe9e533f --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/functors/ConsumerWantsFilePredicate.java @@ -0,0 +1,135 @@ +package org.apache.archiva.consumers.functors; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.List; + +import org.apache.commons.collections.Predicate; +import org.apache.commons.io.FilenameUtils; +import org.apache.archiva.common.utils.BaseFile; +import org.apache.archiva.consumers.RepositoryContentConsumer; +import org.codehaus.plexus.util.SelectorUtils; + +/** + * ConsumerWantsFilePredicate + * + * @version $Id$ + */ +public class ConsumerWantsFilePredicate + implements Predicate +{ + private BaseFile basefile; + + private boolean isCaseSensitive = true; + + private int wantedFileCount = 0; + + private long changesSince = 0; + + public boolean evaluate( Object object ) + { + boolean satisfies = false; + + if ( object instanceof RepositoryContentConsumer ) + { + RepositoryContentConsumer consumer = (RepositoryContentConsumer) object; + if ( wantsFile( consumer, FilenameUtils.separatorsToUnix( basefile.getRelativePath() ) ) ) + { + satisfies = true; + + // regardless of the timestamp, we record that it was wanted so it doesn't get counted as invalid + wantedFileCount++; + + if ( !consumer.isProcessUnmodified() ) + { + // Timestamp finished points to the last successful scan, not this current one. + if ( basefile.lastModified() < changesSince ) + { + // Skip file as no change has occurred. + satisfies = false; + } + } + } + } + + return satisfies; + } + + public BaseFile getBasefile() + { + return basefile; + } + + public int getWantedFileCount() + { + return wantedFileCount; + } + + public boolean isCaseSensitive() + { + return isCaseSensitive; + } + + public void setBasefile( BaseFile basefile ) + { + this.basefile = basefile; + this.wantedFileCount = 0; + } + + public void setCaseSensitive( boolean isCaseSensitive ) + { + this.isCaseSensitive = isCaseSensitive; + } + + private boolean wantsFile( RepositoryContentConsumer consumer, String relativePath ) + { + // Test excludes first. + List excludes = consumer.getExcludes(); + if ( excludes != null ) + { + for ( String pattern : excludes ) + { + if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) ) + { + // Definately does NOT WANT FILE. + return false; + } + } + } + + // Now test includes. + for ( String pattern : consumer.getIncludes() ) + { + if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) ) + { + // Specifically WANTS FILE. + return true; + } + } + + // Not included, and Not excluded? Default to EXCLUDE. + return false; + } + + public void setChangesSince( long changesSince ) + { + this.changesSince = changesSince; + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/functors/PermanentConsumerPredicate.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/functors/PermanentConsumerPredicate.java new file mode 100644 index 000000000..cc10aaafa --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/functors/PermanentConsumerPredicate.java @@ -0,0 +1,47 @@ +package org.apache.archiva.consumers.functors; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.commons.collections.Predicate; +import org.apache.archiva.consumers.Consumer; + +/** + * Selects Consumers that are flaged as 'permanent'. + * + * @version $Id$ + */ +public class PermanentConsumerPredicate + implements Predicate +{ + + public boolean evaluate( Object object ) + { + boolean satisfies = false; + + if ( object instanceof Consumer ) + { + Consumer consumer = (Consumer) object; + satisfies = consumer.isPermanent(); + } + + return satisfies; + } + +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/AbstractMonitoredConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/AbstractMonitoredConsumer.java deleted file mode 100644 index e0ae5fe82..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/AbstractMonitoredConsumer.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.apache.maven.archiva.consumers; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.common.FileTypeUtils; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -/** - * AbstractMonitoredConsumer - * - * @version $Id$ - */ -public abstract class AbstractMonitoredConsumer - implements Consumer -{ - private Set monitors = new HashSet(); - - public void addConsumerMonitor( ConsumerMonitor monitor ) - { - monitors.add( monitor ); - } - - public void removeConsumerMonitor( ConsumerMonitor monitor ) - { - monitors.remove( monitor ); - } - - protected void triggerConsumerError( String type, String message ) - { - for ( Iterator itmonitors = monitors.iterator(); itmonitors.hasNext(); ) - { - ConsumerMonitor monitor = itmonitors.next(); - try - { - monitor.consumerError( this, type, message ); - } - catch ( Throwable t ) - { - /* discard error */ - } - } - } - - protected void triggerConsumerWarning( String type, String message ) - { - for ( Iterator itmonitors = monitors.iterator(); itmonitors.hasNext(); ) - { - ConsumerMonitor monitor = itmonitors.next(); - try - { - monitor.consumerWarning( this, type, message ); - } - catch ( Throwable t ) - { - /* discard error */ - } - } - } - - protected void triggerConsumerInfo( String message ) - { - for ( Iterator itmonitors = monitors.iterator(); itmonitors.hasNext(); ) - { - ConsumerMonitor monitor = itmonitors.next(); - try - { - monitor.consumerInfo( this, message ); - } - catch ( Throwable t ) - { - /* discard error */ - } - } - } - - public boolean isProcessUnmodified() - { - return false; - } - - protected List getDefaultArtifactExclusions() - { - return FileTypeUtils.DEFAULT_EXCLUSIONS; - } - - -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/Consumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/Consumer.java deleted file mode 100644 index 3c3312504..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/Consumer.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.apache.maven.archiva.consumers; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * Consumer - the base set of methods for a consumer. - * - * @version $Id$ - */ -public abstract interface Consumer -{ - /** - * This is the id for the consumer. - * - * @return the consumer id. - */ - public String getId(); - - /** - * The human readable description for this consumer. - * - * @return the human readable description for this consumer. - */ - public String getDescription(); - - /** - * Flag indicating permanance of consumer. (if it can be disabled or not) - * - * @return true indicating that consumer is permanent and cannot be disabled. - */ - public boolean isPermanent(); - - /** - * Add a consumer monitor to the consumer. - * - * @param monitor the monitor to add. - */ - public void addConsumerMonitor( ConsumerMonitor monitor ); - - /** - * Remove a consumer monitor. - * - * @param monitor the monitor to remove. - */ - public void removeConsumerMonitor( ConsumerMonitor monitor ); -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/ConsumerException.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/ConsumerException.java deleted file mode 100644 index e401e21af..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/ConsumerException.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.apache.maven.archiva.consumers; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.common.ArchivaException; - -/** - * ConsumerException - details about the failure of a consumer. - * - * @version $Id$ - */ -public class ConsumerException - extends ArchivaException -{ - public ConsumerException( String message, Throwable cause ) - { - super( message, cause ); - } - - public ConsumerException( String message ) - { - super( message ); - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/ConsumerMonitor.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/ConsumerMonitor.java deleted file mode 100644 index 10338985d..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/ConsumerMonitor.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.apache.maven.archiva.consumers; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * ConsumerMonitor - a monitor for consumers. - * - * @version $Id$ - */ -public interface ConsumerMonitor -{ - /** - * A consumer error event. - * - * @param consumer the consumer that caused the error. - * @param type the type of error. - * @param message the message about the error. - */ - public void consumerError( Consumer consumer, String type, String message ); - - /** - * A consumer warning event. - * - * @param consumer the consumer that caused the warning. - * @param type the type of warning. - * @param message the message about the warning. - */ - public void consumerWarning( Consumer consumer, String type, String message ); - - /** - * A consumer informational event. - * - * @param consumer the consumer that caused the informational message. - * @param message the message. - */ - public void consumerInfo( Consumer consumer, String message ); -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/InvalidRepositoryContentConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/InvalidRepositoryContentConsumer.java deleted file mode 100644 index e6196167e..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/InvalidRepositoryContentConsumer.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.apache.maven.archiva.consumers; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * Consumer for Invalid Repository Content - * - * @version $Id$ - */ -public interface InvalidRepositoryContentConsumer - extends RepositoryContentConsumer -{ - // no op -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/KnownRepositoryContentConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/KnownRepositoryContentConsumer.java deleted file mode 100644 index 66d98459f..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/KnownRepositoryContentConsumer.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.apache.maven.archiva.consumers; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * Consumer for Known Repository Content. - * - * @version $Id$ - */ -public interface KnownRepositoryContentConsumer - extends RepositoryContentConsumer -{ - // no op -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/RepositoryContentConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/RepositoryContentConsumer.java deleted file mode 100644 index aa33e9901..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/RepositoryContentConsumer.java +++ /dev/null @@ -1,131 +0,0 @@ -package org.apache.maven.archiva.consumers; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.admin.model.beans.ManagedRepository; - -import java.util.Date; -import java.util.List; - -/** - * A consumer of content (files) in the repository. - * - * @version $Id$ - */ -public interface RepositoryContentConsumer - extends Consumer -{ - /** - * Get the list of included file patterns for this consumer. - * - * @return the list of {@link String} patterns. (example: "**/*.pom") - */ - List getIncludes(); - - /** - * Get the list of excluded file patterns for this consumer. - * - * @return the list of {@link String} patterns. (example: "**/*.pom") - (can be null for no exclusions) - */ - List getExcludes(); - - /** - *

- * Event that triggers at the beginning of a scan. - *

- *

- *

- * NOTE: This would be a good place to initialize the consumer, to lock any resources, and to - * generally start tracking the scan as a whole. - *

- * - * @param repository the repository that this consumer is being used for. - * @param whenGathered the start of the repository scan - * @throws ConsumerException if there was a problem with using the provided repository with the consumer. - */ - void beginScan( ManagedRepository repository, Date whenGathered ) - throws ConsumerException; - - /** - *

- * Event that triggers at the beginning of a scan, where you can also indicate whether the consumers will be - * executed on an entire repository or on a specific resource. - *

- * - * @param repository the repository that this consumer is being used for. - * @param whenGathered the start of the repository scan - * @param executeOnEntireRepo flags whether the consumer will be executed on an entire repository or just on a specific resource - * @throws ConsumerException if there was a problem with using the provided repository with the consumer. - * @see RepositoryContentConsumer#beginScan(ManagedRepository, java.util.Date) - */ - void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo ) - throws ConsumerException; - - /** - *

- * Event indicating a file is to be processed by this consumer. - *

- *

- *

- * NOTE: The consumer does not need to process the file immediately, can can opt to queue and/or track - * the files to be processed in batch. Just be sure to complete the processing by the {@link #completeScan()} - * event. - *

- * - * @param path the relative file path (in the repository) to process. - * @throws ConsumerException if there was a problem processing this file. - */ - void processFile( String path ) - throws ConsumerException; - - /** - * @param path - * @param executeOnEntireRepo - * @throws Exception - */ - void processFile( String path, boolean executeOnEntireRepo ) - throws Exception; - - /** - *

- * Event that triggers on the completion of a scan. - *

- *

- *

- * NOTE: If the consumer opted to batch up processing requests in the {@link #processFile(String)} event - * this would be the last opportunity to drain any processing queue's. - *

- */ - void completeScan(); - - /** - * @param executeOnEntireRepo - * @throws Exception - */ - void completeScan( boolean executeOnEntireRepo ); - - /** - * Whether the consumer should process files that have not been modified since the time passed in to the scan - * method. - * - * @return whether to process the unmodified files - */ - boolean isProcessUnmodified(); -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/functors/ConsumerWantsFilePredicate.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/functors/ConsumerWantsFilePredicate.java deleted file mode 100644 index 65f29c55d..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/functors/ConsumerWantsFilePredicate.java +++ /dev/null @@ -1,135 +0,0 @@ -package org.apache.maven.archiva.consumers.functors; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.List; - -import org.apache.commons.collections.Predicate; -import org.apache.commons.io.FilenameUtils; -import org.apache.archiva.common.utils.BaseFile; -import org.apache.maven.archiva.consumers.RepositoryContentConsumer; -import org.codehaus.plexus.util.SelectorUtils; - -/** - * ConsumerWantsFilePredicate - * - * @version $Id$ - */ -public class ConsumerWantsFilePredicate - implements Predicate -{ - private BaseFile basefile; - - private boolean isCaseSensitive = true; - - private int wantedFileCount = 0; - - private long changesSince = 0; - - public boolean evaluate( Object object ) - { - boolean satisfies = false; - - if ( object instanceof RepositoryContentConsumer ) - { - RepositoryContentConsumer consumer = (RepositoryContentConsumer) object; - if ( wantsFile( consumer, FilenameUtils.separatorsToUnix( basefile.getRelativePath() ) ) ) - { - satisfies = true; - - // regardless of the timestamp, we record that it was wanted so it doesn't get counted as invalid - wantedFileCount++; - - if ( !consumer.isProcessUnmodified() ) - { - // Timestamp finished points to the last successful scan, not this current one. - if ( basefile.lastModified() < changesSince ) - { - // Skip file as no change has occurred. - satisfies = false; - } - } - } - } - - return satisfies; - } - - public BaseFile getBasefile() - { - return basefile; - } - - public int getWantedFileCount() - { - return wantedFileCount; - } - - public boolean isCaseSensitive() - { - return isCaseSensitive; - } - - public void setBasefile( BaseFile basefile ) - { - this.basefile = basefile; - this.wantedFileCount = 0; - } - - public void setCaseSensitive( boolean isCaseSensitive ) - { - this.isCaseSensitive = isCaseSensitive; - } - - private boolean wantsFile( RepositoryContentConsumer consumer, String relativePath ) - { - // Test excludes first. - List excludes = consumer.getExcludes(); - if ( excludes != null ) - { - for ( String pattern : excludes ) - { - if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) ) - { - // Definately does NOT WANT FILE. - return false; - } - } - } - - // Now test includes. - for ( String pattern : consumer.getIncludes() ) - { - if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) ) - { - // Specifically WANTS FILE. - return true; - } - } - - // Not included, and Not excluded? Default to EXCLUDE. - return false; - } - - public void setChangesSince( long changesSince ) - { - this.changesSince = changesSince; - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/functors/PermanentConsumerPredicate.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/functors/PermanentConsumerPredicate.java deleted file mode 100644 index 64ad0bd98..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/functors/PermanentConsumerPredicate.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.apache.maven.archiva.consumers.functors; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.collections.Predicate; -import org.apache.maven.archiva.consumers.Consumer; - -/** - * Selects Consumers that are flaged as 'permanent'. - * - * @version $Id$ - */ -public class PermanentConsumerPredicate - implements Predicate -{ - - public boolean evaluate( Object object ) - { - boolean satisfies = false; - - if ( object instanceof Consumer ) - { - Consumer consumer = (Consumer) object; - satisfies = consumer.isPermanent(); - } - - return satisfies; - } - -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java new file mode 100644 index 000000000..790e506b7 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java @@ -0,0 +1,214 @@ +package org.apache.archiva.consumers.core; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.checksum.ChecksumAlgorithm; +import org.apache.archiva.checksum.ChecksummedFile; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.ConfigurationNames; +import org.apache.maven.archiva.configuration.FileTypes; +import org.apache.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.archiva.consumers.ConsumerException; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.codehaus.plexus.registry.Registry; +import org.codehaus.plexus.registry.RegistryListener; + +import javax.annotation.PostConstruct; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * ArtifactMissingChecksumsConsumer - Create missing and/or fix invalid checksums for the artifact. + * + * @version $Id$ + */ +public class ArtifactMissingChecksumsConsumer + extends AbstractMonitoredConsumer + implements KnownRepositoryContentConsumer, RegistryListener +{ + private String id; + + private String description; + + private ArchivaConfiguration configuration; + + private FileTypes filetypes; + + private ChecksummedFile checksum; + + private static final String TYPE_CHECKSUM_NOT_FILE = "checksum-bad-not-file"; + + private static final String TYPE_CHECKSUM_CANNOT_CALC = "checksum-calc-failure"; + + private static final String TYPE_CHECKSUM_CANNOT_CREATE = "checksum-create-failure"; + + private File repositoryDir; + + private List includes = new ArrayList(); + + public ArtifactMissingChecksumsConsumer(String id, + String description, + ArchivaConfiguration configuration, + FileTypes filetypes) { + this.id = id; + this.description = description; + this.configuration = configuration; + this.filetypes = filetypes; + + configuration.addChangeListener( this ); + + initIncludes(); + } + + public String getId() + { + return this.id; + } + + public String getDescription() + { + return this.description; + } + + public boolean isPermanent() + { + return false; + } + + public void beginScan( ManagedRepository repo, Date whenGathered ) + throws ConsumerException + { + this.repositoryDir = new File( repo.getLocation() ); + } + + public void beginScan( ManagedRepository repo, Date whenGathered, boolean executeOnEntireRepo ) + throws ConsumerException + { + beginScan( repo, whenGathered ); + } + + public void completeScan() + { + /* do nothing */ + } + + public void completeScan( boolean executeOnEntireRepo ) + { + completeScan(); + } + + public List getExcludes() + { + return getDefaultArtifactExclusions(); + } + + public List getIncludes() + { + return includes; + } + + public void processFile( String path ) + throws ConsumerException + { + createFixChecksum( path, new ChecksumAlgorithm[] { ChecksumAlgorithm.SHA1 } ); + createFixChecksum( path, new ChecksumAlgorithm[] { ChecksumAlgorithm.MD5 } ); + } + + public void processFile( String path, boolean executeOnEntireRepo ) + throws ConsumerException + { + processFile( path ); + } + + private void createFixChecksum( String path, ChecksumAlgorithm checksumAlgorithm[] ) + { + File artifactFile = new File( this.repositoryDir, path ); + File checksumFile = new File( this.repositoryDir, path + checksumAlgorithm[0].getExt() ); + + if( checksumFile.exists() ) + { + checksum = new ChecksummedFile( artifactFile ); + try + { + if( !checksum.isValidChecksum( checksumAlgorithm[0] ) ) + { + checksum.fixChecksums( checksumAlgorithm ); + triggerConsumerInfo( "Fixed checksum file " + checksumFile.getAbsolutePath() ); + } + } + catch ( IOException e ) + { + triggerConsumerError( TYPE_CHECKSUM_CANNOT_CALC, "Cannot calculate checksum for file " + checksumFile + + ": " + e.getMessage() ); + } + } + else if( !checksumFile.exists() ) + { + checksum = new ChecksummedFile( artifactFile ); + try + { + checksum.createChecksum( checksumAlgorithm[0] ); + triggerConsumerInfo( "Created missing checksum file " + checksumFile.getAbsolutePath() ); + } + catch ( IOException e ) + { + triggerConsumerError( TYPE_CHECKSUM_CANNOT_CREATE, "Cannot create checksum for file " + checksumFile + + ": " + e.getMessage() ); + } + } + else + { + triggerConsumerWarning( TYPE_CHECKSUM_NOT_FILE, + "Checksum file " + checksumFile.getAbsolutePath() + " is not a file." ); + } + } + + public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) + { + if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) + { + initIncludes(); + } + } + + public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) + { + /* do nothing */ + } + + private void initIncludes() + { + includes.clear(); + + includes.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) ); + } + + @PostConstruct + public void initialize() + { + configuration.addChangeListener( this ); + + initIncludes(); + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/AutoRemoveConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/AutoRemoveConsumer.java new file mode 100644 index 000000000..b5a65fa7b --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/AutoRemoveConsumer.java @@ -0,0 +1,169 @@ +package org.apache.archiva.consumers.core; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.ConfigurationNames; +import org.apache.maven.archiva.configuration.FileTypes; +import org.apache.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.archiva.consumers.ConsumerException; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.codehaus.plexus.registry.Registry; +import org.codehaus.plexus.registry.RegistryListener; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import java.io.File; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * AutoRemoveConsumer + * + * @version $Id$ + */ +@Service("knownRepositoryContentConsumer#auto-remove") +@Scope("prototype") +public class AutoRemoveConsumer + extends AbstractMonitoredConsumer + implements KnownRepositoryContentConsumer, RegistryListener +{ + /** + * default-value="auto-remove" + */ + private String id = "auto-remove"; + + /** + * default-value="Automatically Remove File from Filesystem." + */ + private String description = "Automatically Remove File from Filesystem."; + + /** + * + */ + @Inject + private ArchivaConfiguration configuration; + + /** + * + */ + @Inject + private FileTypes filetypes; + + private File repositoryDir; + + private List includes = new ArrayList(); + + public String getId() + { + return this.id; + } + + public String getDescription() + { + return this.description; + } + + public boolean isPermanent() + { + return false; + } + + public void beginScan( ManagedRepository repository, Date whenGathered ) + throws ConsumerException + { + this.repositoryDir = new File( repository.getLocation() ); + } + + public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo ) + throws ConsumerException + { + beginScan( repository, whenGathered ); + } + + public void completeScan() + { + /* do nothing */ + } + + public void completeScan( boolean executeOnEntireRepo ) + { + completeScan(); + } + + public List getExcludes() + { + return null; + } + + public List getIncludes() + { + return includes; + } + + public void processFile( String path ) + throws ConsumerException + { + File file = new File( this.repositoryDir, path ); + if ( file.exists() ) + { + triggerConsumerInfo( "(Auto) Removing File: " + file.getAbsolutePath() ); + file.delete(); + } + } + + public void processFile( String path, boolean executeOnEntireRepo ) + throws ConsumerException + { + processFile( path ); + } + + public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) + { + if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) + { + initIncludes(); + } + } + + public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) + { + /* do nothing */ + } + + private void initIncludes() + { + includes.clear(); + + includes.addAll( filetypes.getFileTypePatterns( FileTypes.AUTO_REMOVE ) ); + } + + @PostConstruct + public void initialize() + { + configuration.addChangeListener( this ); + + initIncludes(); + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/AutoRenameConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/AutoRenameConsumer.java new file mode 100644 index 000000000..a9dad0d3e --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/AutoRenameConsumer.java @@ -0,0 +1,164 @@ +package org.apache.archiva.consumers.core; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.commons.io.FileUtils; +import org.apache.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.archiva.consumers.ConsumerException; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * AutoRenameConsumer + * + * @version $Id$ + */ +@Service("knownRepositoryContentConsumer#auto-rename") +@Scope("prototype") +public class AutoRenameConsumer + extends AbstractMonitoredConsumer + implements KnownRepositoryContentConsumer +{ + /** + * default-value="auto-rename" + */ + private String id = "auto-rename"; + + /** + * default-value="Automatically rename common artifact mistakes." + */ + private String description = "Automatically rename common artifact mistakes."; + + private static final String RENAME_FAILURE = "rename_failure"; + + private File repositoryDir; + + private List includes = new ArrayList(); + + private Map extensionRenameMap = new HashMap(); + + public AutoRenameConsumer() + { + includes.add( "**/*.distribution-tgz" ); + includes.add( "**/*.distribution-zip" ); + includes.add( "**/*.plugin" ); + + extensionRenameMap.put( ".distribution-tgz", ".tar.gz" ); + extensionRenameMap.put( ".distribution-zip", ".zip" ); + extensionRenameMap.put( ".plugin", ".jar" ); + } + + public String getId() + { + return this.id; + } + + public String getDescription() + { + return this.description; + } + + public boolean isPermanent() + { + return false; + } + + public void beginScan( ManagedRepository repository, Date whenGathered ) + throws ConsumerException + { + this.repositoryDir = new File( repository.getLocation() ); + } + + public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo ) + throws ConsumerException + { + beginScan( repository, whenGathered ); + } + + public void completeScan() + { + /* do nothing */ + } + + public void completeScan( boolean executeOnEntireRepo ) + { + completeScan(); + } + + public List getExcludes() + { + return null; + } + + public List getIncludes() + { + return includes; + } + + public void processFile( String path ) + throws ConsumerException + { + File file = new File( this.repositoryDir, path ); + if ( file.exists() ) + { + Iterator itExtensions = this.extensionRenameMap.keySet().iterator(); + while ( itExtensions.hasNext() ) + { + String extension = (String) itExtensions.next(); + if ( path.endsWith( extension ) ) + { + String fixedExtension = (String) this.extensionRenameMap.get( extension ); + String correctedPath = path.substring( 0, path.length() - extension.length() ) + fixedExtension; + File to = new File( this.repositoryDir, correctedPath ); + try + { + // Rename the file. + FileUtils.moveFile( file, to ); + } + catch ( IOException e ) + { + triggerConsumerWarning( RENAME_FAILURE, "Unable to rename " + path + " to " + correctedPath + + ": " + e.getMessage() ); + } + } + } + + triggerConsumerInfo( "(Auto) Removing File: " + file.getAbsolutePath() ); + file.delete(); + } + } + + public void processFile( String path, boolean executeOnEntireRepo ) + throws ConsumerException + { + processFile( path ); + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java new file mode 100644 index 000000000..2efd46b0d --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java @@ -0,0 +1,324 @@ +package org.apache.archiva.consumers.core; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.ConfigurationNames; +import org.apache.maven.archiva.configuration.FileTypes; +import org.apache.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.archiva.consumers.ConsumerException; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.maven.archiva.model.ArtifactReference; +import org.apache.maven.archiva.model.ProjectReference; +import org.apache.maven.archiva.model.VersionedReference; +import org.apache.archiva.repository.ContentNotFoundException; +import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.RepositoryContentFactory; +import org.apache.archiva.repository.RepositoryException; +import org.apache.archiva.repository.RepositoryNotFoundException; +import org.apache.archiva.repository.layout.LayoutException; +import org.apache.archiva.repository.metadata.MetadataTools; +import org.apache.archiva.repository.metadata.RepositoryMetadataException; +import org.codehaus.plexus.registry.Registry; +import org.codehaus.plexus.registry.RegistryListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * MetadataUpdaterConsumer will create and update the metadata present within the repository. + * + * @version $Id$ + */ +@Service("knownRepositoryContentConsumer#metadata-updater") +@Scope("prototype") +public class MetadataUpdaterConsumer + extends AbstractMonitoredConsumer + implements KnownRepositoryContentConsumer, RegistryListener +{ + private Logger log = LoggerFactory.getLogger( MetadataUpdaterConsumer.class ); + + /** + * default-value="metadata-updater" + */ + private String id = "metadata-updater"; + + /** + * default-value="Update / Create maven-metadata.xml files" + */ + private String description = "Update / Create maven-metadata.xml files"; + + /** + * + */ + @Inject + private RepositoryContentFactory repositoryFactory; + + /** + * + */ + @Inject + private MetadataTools metadataTools; + + /** + * + */ + @Inject + private ArchivaConfiguration configuration; + + /** + * + */ + @Inject + private FileTypes filetypes; + + private static final String TYPE_METADATA_BAD_INTERNAL_REF = "metadata-bad-internal-ref"; + + private static final String TYPE_METADATA_WRITE_FAILURE = "metadata-write-failure"; + + private static final String TYPE_METADATA_IO = "metadata-io-warning"; + + private ManagedRepositoryContent repository; + + private File repositoryDir; + + private List includes = new ArrayList(); + + private long scanStartTimestamp = 0; + + public String getDescription() + { + return description; + } + + public String getId() + { + return id; + } + + public void setIncludes( List includes ) + { + this.includes = includes; + } + + public void beginScan( ManagedRepository repoConfig, Date whenGathered ) + throws ConsumerException + { + try + { + 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 ); + } + catch ( RepositoryException e ) + { + throw new ConsumerException( e.getMessage(), e ); + } + } + + public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo ) + throws ConsumerException + { + beginScan( repository, whenGathered ); + } + + public void completeScan() + { + /* do nothing here */ + } + + public void completeScan( boolean executeOnEntireRepo ) + { + completeScan(); + } + + public List getExcludes() + { + return getDefaultArtifactExclusions(); + } + + public List getIncludes() + { + return this.includes; + } + + public void processFile( String path ) + throws ConsumerException + { + // Ignore paths like .index etc + if ( !path.startsWith( "." ) ) + { + try + { + ArtifactReference artifact = repository.toArtifactReference( path ); + updateVersionMetadata( artifact, path ); + updateProjectMetadata( artifact, path ); + } + catch ( LayoutException e ) + { + log.info( "Not processing path that is not an artifact: " + path + " (" + e.getMessage() + ")" ); + } + } + } + + public void processFile( String path, boolean executeOnEntireRepo ) + throws Exception + { + processFile( path ); + } + + private void updateProjectMetadata( ArtifactReference artifact, String path ) + { + ProjectReference projectRef = new ProjectReference(); + projectRef.setGroupId( artifact.getGroupId() ); + projectRef.setArtifactId( artifact.getArtifactId() ); + + try + { + String metadataPath = this.metadataTools.toPath( projectRef ); + + File projectMetadata = new File( this.repositoryDir, metadataPath ); + + if ( projectMetadata.exists() && ( projectMetadata.lastModified() >= this.scanStartTimestamp ) ) + { + // This metadata is up to date. skip it. + log.debug( "Skipping uptodate metadata: {}", this.metadataTools.toPath( projectRef ) ); + return; + } + + metadataTools.updateMetadata( this.repository, projectRef ); + log.debug( "Updated metadata: {}", this.metadataTools.toPath( projectRef ) ); + } + catch ( LayoutException e ) + { + triggerConsumerWarning( TYPE_METADATA_BAD_INTERNAL_REF, "Unable to convert path [" + path + + "] to an internal project reference: " + e.getMessage() ); + } + catch ( RepositoryMetadataException e ) + { + triggerConsumerError( TYPE_METADATA_WRITE_FAILURE, "Unable to write project metadata for artifact [" + path + + "]: " + e.getMessage() ); + } + catch ( IOException e ) + { + triggerConsumerWarning( TYPE_METADATA_IO, "Project metadata not written due to IO warning: " + + e.getMessage() ); + } + catch ( ContentNotFoundException e ) + { + triggerConsumerWarning( TYPE_METADATA_IO, + "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() ); + + try + { + String metadataPath = this.metadataTools.toPath( versionRef ); + + File projectMetadata = new File( this.repositoryDir, metadataPath ); + + if ( projectMetadata.exists() && ( projectMetadata.lastModified() >= this.scanStartTimestamp ) ) + { + // This metadata is up to date. skip it. + log.debug( "Skipping uptodate metadata: {}", this.metadataTools.toPath( versionRef ) ); + return; + } + + metadataTools.updateMetadata( this.repository, versionRef ); + log.debug( "Updated metadata: {}", this.metadataTools.toPath( versionRef ) ); + } + catch ( LayoutException e ) + { + triggerConsumerWarning( TYPE_METADATA_BAD_INTERNAL_REF, "Unable to convert path [" + path + + "] to an internal version reference: " + e.getMessage() ); + } + catch ( RepositoryMetadataException e ) + { + triggerConsumerError( TYPE_METADATA_WRITE_FAILURE, "Unable to write version metadata for artifact [" + path + + "]: " + e.getMessage() ); + } + catch ( IOException e ) + { + triggerConsumerWarning( TYPE_METADATA_IO, "Version metadata not written due to IO warning: " + + e.getMessage() ); + } + catch ( ContentNotFoundException e ) + { + triggerConsumerWarning( TYPE_METADATA_IO, + "Version metadata not written because no versions were found to update: " + + e.getMessage() ); + } + } + + public boolean isPermanent() + { + return false; + } + + public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) + { + if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) + { + initIncludes(); + } + } + + public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) + { + /* do nothing here */ + } + + private void initIncludes() + { + includes.clear(); + + includes.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) ); + } + + @PostConstruct + public void initialize() + { + configuration.addChangeListener( this ); + + initIncludes(); + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ValidateChecksumConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ValidateChecksumConsumer.java new file mode 100644 index 000000000..3feace003 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ValidateChecksumConsumer.java @@ -0,0 +1,183 @@ +package org.apache.archiva.consumers.core; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.common.plexusbridge.DigesterUtils; +import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; +import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; +import org.apache.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.archiva.consumers.ConsumerException; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.codehaus.plexus.digest.ChecksumFile; +import org.codehaus.plexus.digest.Digester; +import org.codehaus.plexus.digest.DigesterException; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * ValidateChecksumConsumer - validate the provided checksum against the file it represents. + * + * @version $Id$ + */ +@Service( "knownRepositoryContentConsumer#validate-checksum" ) +@Scope( "prototype" ) +public class ValidateChecksumConsumer + extends AbstractMonitoredConsumer + implements KnownRepositoryContentConsumer +{ + private static final String NOT_VALID_CHECKSUM = "checksum-not-valid"; + + private static final String CHECKSUM_NOT_FOUND = "checksum-not-found"; + + private static final String CHECKSUM_DIGESTER_FAILURE = "checksum-digester-failure"; + + private static final String CHECKSUM_IO_ERROR = "checksum-io-error"; + + /** + * default-value="validate-checksums" + */ + private String id = "validate-checksums"; + + /** + * default-value="Validate checksums against file." + */ + private String description = "Validate checksums against file."; + + /** + * + */ + private ChecksumFile checksum; + + /** + * + */ + private List allDigesters; + + @Inject + private PlexusSisuBridge plexusSisuBridge; + + @Inject + private DigesterUtils digesterUtils; + + private File repositoryDir; + + private List includes = new ArrayList(); + + public String getId() + { + return this.id; + } + + public String getDescription() + { + return this.description; + } + + public boolean isPermanent() + { + return false; + } + + public void beginScan( ManagedRepository repository, Date whenGathered ) + throws ConsumerException + { + this.repositoryDir = new File( repository.getLocation() ); + } + + public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo ) + throws ConsumerException + { + beginScan( repository, whenGathered ); + } + + public void completeScan() + { + /* nothing to do */ + } + + public void completeScan( boolean executeOnEntireRepo ) + { + completeScan(); + } + + public List getExcludes() + { + return null; + } + + public List getIncludes() + { + return this.includes; + } + + public void processFile( String path ) + throws ConsumerException + { + File checksumFile = new File( this.repositoryDir, path ); + try + { + if ( !checksum.isValidChecksum( checksumFile ) ) + { + triggerConsumerWarning( NOT_VALID_CHECKSUM, "The checksum for " + checksumFile + " is invalid." ); + } + } + catch ( FileNotFoundException e ) + { + triggerConsumerError( CHECKSUM_NOT_FOUND, "File not found during checksum validation: " + e.getMessage() ); + } + catch ( DigesterException e ) + { + triggerConsumerError( CHECKSUM_DIGESTER_FAILURE, + "Digester failure during checksum validation on " + checksumFile ); + } + catch ( IOException e ) + { + triggerConsumerError( CHECKSUM_IO_ERROR, "Checksum I/O error during validation on " + checksumFile ); + } + } + + public void processFile( String path, boolean executeOnEntireReDpo ) + throws Exception + { + processFile( path ); + } + + @PostConstruct + public void initialize() + throws PlexusSisuBridgeException + { + checksum = plexusSisuBridge.lookup( ChecksumFile.class ); + List allDigesters = new ArrayList( digesterUtils.getAllDigesters() ); + for ( Digester digester : allDigesters ) + { + includes.add( "**/*" + digester.getFilenameExtension() ); + } + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java new file mode 100644 index 000000000..244be334d --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java @@ -0,0 +1,138 @@ +package org.apache.archiva.consumers.core.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.audit.AuditEvent; +import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.RepositorySession; +import org.apache.archiva.repository.events.RepositoryListener; +import org.apache.maven.archiva.model.ArtifactReference; +import org.apache.archiva.repository.ManagedRepositoryContent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FilenameFilter; +import java.util.List; +import java.util.Set; + +/** + * Base class for all repository purge tasks. + */ +public abstract class AbstractRepositoryPurge + implements RepositoryPurge +{ + protected Logger log = LoggerFactory.getLogger( AbstractRepositoryPurge.class ); + + protected final ManagedRepositoryContent repository; + + protected final RepositorySession repositorySession; + + protected final List listeners; + + private Logger logger = LoggerFactory.getLogger( "org.apache.archiva.AuditLog" ); + + private static final char DELIM = ' '; + + public AbstractRepositoryPurge( ManagedRepositoryContent repository, RepositorySession repositorySession, + List listeners ) + { + this.repository = repository; + this.repositorySession = repositorySession; + this.listeners = listeners; + } + + /** + * Purge the repo. Update db and index of removed artifacts. + * + * @param references + */ + protected void purge( Set references ) + { + if ( references != null && !references.isEmpty() ) + { + MetadataRepository metadataRepository = repositorySession.getRepository(); + for ( ArtifactReference reference : references ) + { + File artifactFile = repository.toFile( reference ); + + // FIXME: looks incomplete, might not delete related metadata? + for ( RepositoryListener listener : listeners ) + { + listener.deleteArtifact( metadataRepository, repository.getId(), reference.getGroupId(), + reference.getArtifactId(), reference.getVersion(), + artifactFile.getName() ); + } + + // TODO: this needs to be logged + artifactFile.delete(); + repositorySession.save(); + + triggerAuditEvent( repository.getRepository().getId(), ArtifactReference.toKey( reference ), + AuditEvent.PURGE_ARTIFACT ); + purgeSupportFiles( artifactFile ); + } + } + } + + /** + *

+ * This find support files for the artifactFile and deletes them. + *

+ *

+ * Support Files are things like ".sha1", ".md5", ".asc", etc. + *

+ * + * @param artifactFile the file to base off of. + */ + private void purgeSupportFiles( File artifactFile ) + { + File parentDir = artifactFile.getParentFile(); + + if ( !parentDir.exists() ) + { + return; + } + + FilenameFilter filter = new ArtifactFilenameFilter( artifactFile.getName() ); + + File[] files = parentDir.listFiles( filter ); + + for ( File file : files ) + { + if ( file.exists() && file.isFile() ) + { + String fileName = file.getName(); + file.delete(); + // TODO: log that it was deleted + triggerAuditEvent( repository.getRepository().getId(), fileName, AuditEvent.PURGE_FILE ); + } + } + } + + private void triggerAuditEvent( String repoId, String resource, String action ) + { + String msg = + repoId + DELIM + "" + DELIM + "" + DELIM + '\"' + resource + '\"' + DELIM + '\"' + + action + '\"'; + + logger.info( msg ); + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/ArtifactFilenameFilter.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/ArtifactFilenameFilter.java new file mode 100644 index 000000000..bb55fa827 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/ArtifactFilenameFilter.java @@ -0,0 +1,48 @@ +package org.apache.archiva.consumers.core.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.FilenameFilter; +import java.io.File; + +/** + * Filename filter for getting all the files related to a specific artifact. + * + */ +public class ArtifactFilenameFilter + implements FilenameFilter +{ + private String filename; + + public ArtifactFilenameFilter() + { + + } + + public ArtifactFilenameFilter( String filename ) + { + this.filename = filename; + } + + public boolean accept( File dir, String name ) + { + return ( name.startsWith( filename ) ); + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java new file mode 100644 index 000000000..00419020b --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java @@ -0,0 +1,266 @@ +package org.apache.archiva.consumers.core.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.admin.model.RepositoryAdminException; +import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; +import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.RepositorySession; +import org.apache.archiva.repository.events.RepositoryListener; +import org.apache.archiva.common.utils.VersionComparator; +import org.apache.archiva.common.utils.VersionUtil; +import org.apache.maven.archiva.model.ArchivaArtifact; +import org.apache.maven.archiva.model.ArtifactReference; +import org.apache.maven.archiva.model.ProjectReference; +import org.apache.maven.archiva.model.VersionedReference; +import org.apache.archiva.repository.ContentNotFoundException; +import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.RepositoryContentFactory; +import org.apache.archiva.repository.RepositoryException; +import org.apache.archiva.repository.RepositoryNotFoundException; +import org.apache.archiva.repository.layout.LayoutException; +import org.apache.archiva.repository.metadata.MetadataTools; +import org.apache.archiva.repository.metadata.RepositoryMetadataException; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + *

+ * This will look in a single managed repository, and purge any snapshots that are present + * that have a corresponding released version on the same repository. + *

+ *

+ *

+ * So, if you have the following (presented in the m2/default layout form) ... + *

+ *   /com/foo/foo-tool/1.0-SNAPSHOT/foo-tool-1.0-SNAPSHOT.jar
+ *   /com/foo/foo-tool/1.1-SNAPSHOT/foo-tool-1.1-SNAPSHOT.jar
+ *   /com/foo/foo-tool/1.2.1-SNAPSHOT/foo-tool-1.2.1-SNAPSHOT.jar
+ *   /com/foo/foo-tool/1.2.1/foo-tool-1.2.1.jar
+ *   /com/foo/foo-tool/2.0-SNAPSHOT/foo-tool-2.0-SNAPSHOT.jar
+ *   /com/foo/foo-tool/2.0/foo-tool-2.0.jar
+ *   /com/foo/foo-tool/2.1-SNAPSHOT/foo-tool-2.1-SNAPSHOT.jar
+ * 
+ * then the current highest ranked released (non-snapshot) version is 2.0, which means + * the snapshots from 1.0-SNAPSHOT, 1.1-SNAPSHOT, 1.2.1-SNAPSHOT, and 2.0-SNAPSHOT can + * be purged. Leaving 2.1-SNAPSHOT in alone. + *

+ * + * @version $Id$ + */ +public class CleanupReleasedSnapshotsRepositoryPurge + extends AbstractRepositoryPurge +{ + private MetadataTools metadataTools; + + private ManagedRepositoryAdmin managedRepositoryAdmin; + + private RepositoryContentFactory repoContentFactory; + + public CleanupReleasedSnapshotsRepositoryPurge( ManagedRepositoryContent repository, MetadataTools metadataTools, + ManagedRepositoryAdmin managedRepositoryAdmin, + RepositoryContentFactory repoContentFactory, + RepositorySession repositorySession, + List listeners ) + { + super( repository, repositorySession, listeners ); + this.metadataTools = metadataTools; + this.managedRepositoryAdmin = managedRepositoryAdmin; + this.repoContentFactory = repoContentFactory; + } + + public void process( String path ) + throws RepositoryPurgeException + { + try + { + File artifactFile = new File( repository.getRepoRoot(), path ); + + if ( !artifactFile.exists() ) + { + // Nothing to do here, file doesn't exist, skip it. + return; + } + + ArtifactReference artifactRef = repository.toArtifactReference( path ); + + 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() ); + + // Gather up all of the versions. + List allVersions = new ArrayList( repository.getVersions( reference ) ); + + List repos = managedRepositoryAdmin.getManagedRepositories(); + for ( ManagedRepository repo : repos ) + { + if ( repo.isReleases() && !repo.getId().equals( repository.getId() ) ) + { + try + { + ManagedRepositoryContent repoContent = + repoContentFactory.getManagedRepositoryContent( repo.getId() ); + allVersions.addAll( repoContent.getVersions( reference ) ); + } + catch ( RepositoryNotFoundException e ) + { + // swallow + } + catch ( RepositoryException e ) + { + // swallow + } + } + } + + // Split the versions into released and snapshots. + List releasedVersions = new ArrayList(); + List snapshotVersions = new ArrayList(); + + for ( String version : allVersions ) + { + if ( VersionUtil.isSnapshot( version ) ) + { + snapshotVersions.add( version ); + } + else + { + releasedVersions.add( version ); + } + } + + Collections.sort( allVersions, VersionComparator.getInstance() ); + Collections.sort( releasedVersions, VersionComparator.getInstance() ); + Collections.sort( snapshotVersions, 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() ); + + ArchivaArtifact artifact = + new ArchivaArtifact( artifactRef.getGroupId(), artifactRef.getArtifactId(), artifactRef.getVersion(), + artifactRef.getClassifier(), artifactRef.getType(), repository.getId() ); + + MetadataRepository metadataRepository = repositorySession.getRepository(); + for ( String version : snapshotVersions ) + { + if ( releasedVersions.contains( VersionUtil.getReleaseVersion( version ) ) ) + { + versionRef.setVersion( version ); + repository.deleteVersion( versionRef ); + + // FIXME: looks incomplete, might not delete related metadata? + for ( RepositoryListener listener : listeners ) + { + listener.deleteArtifact( metadataRepository, repository.getId(), artifact.getGroupId(), + artifact.getArtifactId(), artifact.getVersion(), + artifactFile.getName() ); + } + + needsMetadataUpdate = true; + } + } + + if ( needsMetadataUpdate ) + { + updateMetadata( artifactRef ); + } + } catch ( RepositoryAdminException e ) + { + throw new RepositoryPurgeException( e.getMessage(), e ); + } + catch ( LayoutException e ) + { + log.debug( "Not processing file that is not an artifact: {}", e.getMessage() ); + } + catch ( ContentNotFoundException e ) + { + throw new RepositoryPurgeException( e.getMessage(), e ); + } + } + + 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() ); + + try + { + metadataTools.updateMetadata( repository, versionRef ); + } + catch ( ContentNotFoundException e ) + { + // Ignore. (Just means we have no snapshot versions left to reference). + } + catch ( RepositoryMetadataException e ) + { + // Ignore. + } + catch ( IOException e ) + { + // Ignore. + } + catch ( LayoutException e ) + { + // Ignore. + } + + try + { + metadataTools.updateMetadata( repository, projectRef ); + } + catch ( ContentNotFoundException e ) + { + // Ignore. (Just means we have no snapshot versions left to reference). + } + catch ( RepositoryMetadataException e ) + { + // Ignore. + } + catch ( IOException e ) + { + // Ignore. + } + catch ( LayoutException e ) + { + // Ignore. + } + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurge.java new file mode 100644 index 000000000..549135f95 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurge.java @@ -0,0 +1,190 @@ +package org.apache.archiva.consumers.core.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.metadata.repository.RepositorySession; +import org.apache.archiva.repository.events.RepositoryListener; +import org.apache.commons.lang.time.DateUtils; +import org.apache.archiva.common.utils.VersionComparator; +import org.apache.archiva.common.utils.VersionUtil; +import org.apache.maven.archiva.model.ArtifactReference; +import org.apache.maven.archiva.model.VersionedReference; +import org.apache.archiva.repository.ContentNotFoundException; +import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.layout.LayoutException; + +import java.io.File; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Set; +import java.util.regex.Matcher; + +/** + * Purge from repository all snapshots older than the specified days in the repository configuration. + */ +public class DaysOldRepositoryPurge + extends AbstractRepositoryPurge +{ + private SimpleDateFormat timestampParser; + + private int daysOlder; + + private int retentionCount; + + public DaysOldRepositoryPurge( ManagedRepositoryContent repository, int daysOlder, int retentionCount, + RepositorySession repositorySession, List listeners ) + { + super( repository, repositorySession, listeners ); + this.daysOlder = daysOlder; + this.retentionCount = retentionCount; + timestampParser = new SimpleDateFormat( "yyyyMMdd.HHmmss" ); + timestampParser.setTimeZone( DateUtils.UTC_TIME_ZONE ); + } + + public void process( String path ) + throws RepositoryPurgeException + { + try + { + File artifactFile = new File( repository.getRepoRoot(), path ); + + if ( !artifactFile.exists() ) + { + return; + } + + ArtifactReference artifact = repository.toArtifactReference( path ); + + Calendar olderThanThisDate = Calendar.getInstance( DateUtils.UTC_TIME_ZONE ); + olderThanThisDate.add( Calendar.DATE, -daysOlder ); + + // respect retention count + VersionedReference reference = new VersionedReference(); + reference.setGroupId( artifact.getGroupId() ); + reference.setArtifactId( artifact.getArtifactId() ); + reference.setVersion( artifact.getVersion() ); + + List versions = new ArrayList( repository.getVersions( reference ) ); + + Collections.sort( versions, VersionComparator.getInstance() ); + + if ( retentionCount > versions.size() ) + { + // Done. nothing to do here. skip it. + return; + } + + int countToPurge = versions.size() - retentionCount; + + for ( String version : versions ) + { + if ( countToPurge-- <= 0 ) + { + break; + } + + ArtifactReference newArtifactReference = repository.toArtifactReference( + artifactFile.getAbsolutePath() ); + newArtifactReference.setVersion( version ); + + File newArtifactFile = repository.toFile( newArtifactReference ); + + // Is this a generic snapshot "1.0-SNAPSHOT" ? + if ( VersionUtil.isGenericSnapshot( newArtifactReference.getVersion() ) ) + { + if ( newArtifactFile.lastModified() < olderThanThisDate.getTimeInMillis() ) + { + doPurgeAllRelated( newArtifactReference ); + } + } + // Is this a timestamp snapshot "1.0-20070822.123456-42" ? + else if ( VersionUtil.isUniqueSnapshot( newArtifactReference.getVersion() ) ) + { + Calendar timestampCal = uniqueSnapshotToCalendar( newArtifactReference.getVersion() ); + + if ( timestampCal.getTimeInMillis() < olderThanThisDate.getTimeInMillis() ) + { + doPurgeAllRelated( newArtifactReference ); + } + } + } + } + catch ( ContentNotFoundException e ) + { + throw new RepositoryPurgeException( e.getMessage(), e ); + } + catch ( LayoutException e ) + { + log.debug( "Not processing file that is not an artifact: {}", e.getMessage() ); + } + } + + private Calendar uniqueSnapshotToCalendar( String version ) + { + // The latestVersion will contain the full version string "1.0-alpha-5-20070821.213044-8" + // This needs to be broken down into ${base}-${timestamp}-${build_number} + + Matcher m = VersionUtil.UNIQUE_SNAPSHOT_PATTERN.matcher( version ); + if ( m.matches() ) + { + Matcher mtimestamp = VersionUtil.TIMESTAMP_PATTERN.matcher( m.group( 2 ) ); + if ( mtimestamp.matches() ) + { + String tsDate = mtimestamp.group( 1 ); + String tsTime = mtimestamp.group( 2 ); + + Date versionDate; + try + { + versionDate = timestampParser.parse( tsDate + "." + tsTime ); + Calendar cal = Calendar.getInstance( DateUtils.UTC_TIME_ZONE ); + cal.setTime( versionDate ); + + return cal; + } + catch ( ParseException e ) + { + // Invalid Date/Time + return null; + } + } + } + return null; + } + + private void doPurgeAllRelated( ArtifactReference reference ) + { + try + { + Set related = repository.getRelatedArtifacts( reference ); + purge( related ); + } + catch ( ContentNotFoundException e ) + { + // Nothing to do here - it means the repository would have been constructed incorrectly + log.debug( e.getMessage(), e ); + } + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurge.java new file mode 100644 index 000000000..f3b64031a --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurge.java @@ -0,0 +1,35 @@ +package org.apache.archiva.consumers.core.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * @version $Id$ + */ +public interface RepositoryPurge +{ + /** + * Perform checking on artifact for repository purge + * + * @param path path to the scanned artifact + */ + void process( String path ) + throws RepositoryPurgeException; + +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumer.java new file mode 100644 index 000000000..827cecace --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumer.java @@ -0,0 +1,350 @@ +package org.apache.archiva.consumers.core.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; +import org.apache.archiva.metadata.repository.RepositorySession; +import org.apache.archiva.metadata.repository.RepositorySessionFactory; +import org.apache.archiva.repository.events.RepositoryListener; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.ConfigurationNames; +import org.apache.maven.archiva.configuration.FileTypes; +import org.apache.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.archiva.consumers.ConsumerException; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.RepositoryContentFactory; +import org.apache.archiva.repository.RepositoryException; +import org.apache.archiva.repository.RepositoryNotFoundException; +import org.apache.archiva.repository.metadata.MetadataTools; +import org.codehaus.plexus.registry.Registry; +import org.codehaus.plexus.registry.RegistryListener; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.inject.Named; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; + +/** + * Consumer for removing old snapshots in the repository based on the criteria + * specified by the user. + */ +@Service( "knownRepositoryContentConsumer#repository-purge" ) +@Scope( "prototype" ) +public class RepositoryPurgeConsumer + extends AbstractMonitoredConsumer + implements KnownRepositoryContentConsumer, RegistryListener +{ + /** + * default-value="repository-purge" + */ + private String id = "repository-purge"; + + /** + * default-value="Purge repository of old snapshots" + */ + private String description = "Purge repository of old snapshots"; + + /** + * + */ + @Inject + @Named( value = "archivaConfiguration#default" ) + private ArchivaConfiguration configuration; + + @Inject + private ManagedRepositoryAdmin managedRepositoryAdmin; + + /** + * + */ + @Inject + @Named( value = "repositoryContentFactory#default" ) + private RepositoryContentFactory repositoryContentFactory; + + /** + * + */ + @Inject + private MetadataTools metadataTools; + + /** + * + */ + @Inject + @Named( value = "fileTypes" ) + private FileTypes filetypes; + + private List includes = new ArrayList(); + + private RepositoryPurge repoPurge; + + private RepositoryPurge cleanUp; + + private boolean deleteReleasedSnapshots; + + /** + * + */ + @Inject + private List listeners = Collections.emptyList(); + + /** + * TODO: this could be multiple implementations and needs to be configured. + */ + @Inject + private RepositorySessionFactory repositorySessionFactory; + + private RepositorySession repositorySession; + + public String getId() + { + return this.id; + } + + public String getDescription() + { + return this.description; + } + + public boolean isPermanent() + { + return false; + } + + public List getExcludes() + { + return getDefaultArtifactExclusions(); + } + + public List getIncludes() + { + return this.includes; + } + + public void beginScan( ManagedRepository repository, Date whenGathered ) + throws ConsumerException + { + ManagedRepositoryContent repositoryContent; + try + { + repositoryContent = repositoryContentFactory.getManagedRepositoryContent( repository.getId() ); + } + catch ( RepositoryNotFoundException 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 ); + } + + repositorySession = repositorySessionFactory.createSession(); + + if ( repository.getDaysOlder() != 0 ) + { + repoPurge = new DaysOldRepositoryPurge( repositoryContent, repository.getDaysOlder(), + repository.getRetentionCount(), repositorySession, listeners ); + } + else + { + repoPurge = + new RetentionCountRepositoryPurge( repositoryContent, repository.getRetentionCount(), repositorySession, + listeners ); + } + + cleanUp = new CleanupReleasedSnapshotsRepositoryPurge( repositoryContent, metadataTools, managedRepositoryAdmin, + repositoryContentFactory, repositorySession, listeners ); + + deleteReleasedSnapshots = repository.isDeleteReleasedSnapshots(); + } + + public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo ) + throws ConsumerException + { + beginScan( repository, whenGathered ); + } + + public void processFile( String path ) + throws ConsumerException + { + try + { + if ( deleteReleasedSnapshots ) + { + cleanUp.process( path ); + } + + repoPurge.process( path ); + } + catch ( RepositoryPurgeException rpe ) + { + throw new ConsumerException( rpe.getMessage(), rpe ); + } + } + + public void processFile( String path, boolean executeOnEntireRepo ) + throws Exception + { + processFile( path ); + } + + public void completeScan() + { + repositorySession.close(); + } + + public void completeScan( boolean executeOnEntireRepo ) + { + completeScan(); + } + + public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) + { + if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) + { + initIncludes(); + } + } + + public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) + { + /* do nothing */ + } + + private void initIncludes() + { + includes.clear(); + + includes.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) ); + } + + @PostConstruct + public void initialize() + { + //this.listeners = + // new ArrayList( applicationContext.getBeansOfType( RepositoryListener.class ).values() ); + configuration.addChangeListener( this ); + + initIncludes(); + } + + public boolean isProcessUnmodified() + { + // we need to check all files for deletion, especially if not modified + return true; + } + + public ArchivaConfiguration getConfiguration() + { + return configuration; + } + + public void setConfiguration( ArchivaConfiguration configuration ) + { + this.configuration = configuration; + } + + public RepositoryContentFactory getRepositoryContentFactory() + { + return repositoryContentFactory; + } + + public void setRepositoryContentFactory( RepositoryContentFactory repositoryContentFactory ) + { + this.repositoryContentFactory = repositoryContentFactory; + } + + public MetadataTools getMetadataTools() + { + return metadataTools; + } + + public void setMetadataTools( MetadataTools metadataTools ) + { + this.metadataTools = metadataTools; + } + + public FileTypes getFiletypes() + { + return filetypes; + } + + public void setFiletypes( FileTypes filetypes ) + { + this.filetypes = filetypes; + } + + public RepositoryPurge getRepoPurge() + { + return repoPurge; + } + + public void setRepoPurge( RepositoryPurge repoPurge ) + { + this.repoPurge = repoPurge; + } + + public RepositoryPurge getCleanUp() + { + return cleanUp; + } + + public void setCleanUp( RepositoryPurge cleanUp ) + { + this.cleanUp = cleanUp; + } + + public boolean isDeleteReleasedSnapshots() + { + return deleteReleasedSnapshots; + } + + public void setDeleteReleasedSnapshots( boolean deleteReleasedSnapshots ) + { + this.deleteReleasedSnapshots = deleteReleasedSnapshots; + } + + public RepositorySessionFactory getRepositorySessionFactory() + { + return repositorySessionFactory; + } + + public void setRepositorySessionFactory( RepositorySessionFactory repositorySessionFactory ) + { + this.repositorySessionFactory = repositorySessionFactory; + } + + public RepositorySession getRepositorySession() + { + return repositorySession; + } + + public void setRepositorySession( RepositorySession repositorySession ) + { + this.repositorySession = repositorySession; + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeException.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeException.java new file mode 100644 index 000000000..eddeea960 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeException.java @@ -0,0 +1,48 @@ +package org.apache.archiva.consumers.core.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * + * @version $Id$ + */ +public class RepositoryPurgeException + extends Exception +{ + public RepositoryPurgeException() + { + super(); + } + + public RepositoryPurgeException( String message, Throwable cause ) + { + super( message, cause ); + } + + public RepositoryPurgeException( String message ) + { + super( message ); + } + + public RepositoryPurgeException( Throwable cause ) + { + super( cause ); + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java new file mode 100644 index 000000000..fb6c12815 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java @@ -0,0 +1,129 @@ +package org.apache.archiva.consumers.core.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.metadata.repository.RepositorySession; +import org.apache.archiva.repository.events.RepositoryListener; +import org.apache.archiva.common.utils.VersionComparator; +import org.apache.archiva.common.utils.VersionUtil; +import org.apache.maven.archiva.model.ArtifactReference; +import org.apache.maven.archiva.model.VersionedReference; +import org.apache.archiva.repository.ContentNotFoundException; +import org.apache.archiva.repository.ManagedRepositoryContent; +import org.apache.archiva.repository.layout.LayoutException; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +/** + * Purge the repository by retention count. Retain only the specified number of snapshots. + */ +public class RetentionCountRepositoryPurge + extends AbstractRepositoryPurge +{ + private int retentionCount; + + public RetentionCountRepositoryPurge( ManagedRepositoryContent repository, int retentionCount, + RepositorySession repositorySession, List listeners ) + { + super( repository, repositorySession, listeners ); + this.retentionCount = retentionCount; + } + + public void process( String path ) + throws RepositoryPurgeException + { + try + { + File artifactFile = new File( repository.getRepoRoot(), path ); + + if ( !artifactFile.exists() ) + { + return; + } + + ArtifactReference artifact = repository.toArtifactReference( path ); + + if ( VersionUtil.isSnapshot( artifact.getVersion() ) ) + { + VersionedReference reference = new VersionedReference(); + reference.setGroupId( artifact.getGroupId() ); + reference.setArtifactId( artifact.getArtifactId() ); + reference.setVersion( artifact.getVersion() ); + + List versions = new ArrayList( repository.getVersions( reference ) ); + + Collections.sort( versions, VersionComparator.getInstance() ); + + if ( retentionCount > versions.size() ) + { + // Done. nothing to do here. skip it. + return; + } + + int countToPurge = versions.size() - retentionCount; + + for ( String version : versions ) + { + if ( countToPurge-- <= 0 ) + { + break; + } + + doPurgeAllRelated( artifact, version ); + } + } + } + catch ( LayoutException le ) + { + throw new RepositoryPurgeException( le.getMessage(), le ); + } + catch ( ContentNotFoundException e ) + { + // Nothing to do here. + // TODO: Log this condition? + } + } + + private void doPurgeAllRelated( ArtifactReference reference, String version ) + throws LayoutException + { + ArtifactReference artifact = new ArtifactReference(); + artifact.setGroupId( reference.getGroupId() ); + artifact.setArtifactId( reference.getArtifactId() ); + artifact.setVersion( version ); + artifact.setClassifier( reference.getClassifier() ); + artifact.setType( reference.getType() ); + + try + { + Set related = repository.getRelatedArtifacts( artifact ); + purge( related ); + } + catch ( ContentNotFoundException e ) + { + // Nothing to do here. + // TODO: Log this? + } + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java deleted file mode 100644 index 2369c6a4c..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java +++ /dev/null @@ -1,214 +0,0 @@ -package org.apache.maven.archiva.consumers.core; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.archiva.checksum.ChecksumAlgorithm; -import org.apache.archiva.checksum.ChecksummedFile; -import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.ConfigurationNames; -import org.apache.maven.archiva.configuration.FileTypes; -import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; -import org.apache.maven.archiva.consumers.ConsumerException; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.codehaus.plexus.registry.Registry; -import org.codehaus.plexus.registry.RegistryListener; - -import javax.annotation.PostConstruct; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - * ArtifactMissingChecksumsConsumer - Create missing and/or fix invalid checksums for the artifact. - * - * @version $Id$ - */ -public class ArtifactMissingChecksumsConsumer - extends AbstractMonitoredConsumer - implements KnownRepositoryContentConsumer, RegistryListener -{ - private String id; - - private String description; - - private ArchivaConfiguration configuration; - - private FileTypes filetypes; - - private ChecksummedFile checksum; - - private static final String TYPE_CHECKSUM_NOT_FILE = "checksum-bad-not-file"; - - private static final String TYPE_CHECKSUM_CANNOT_CALC = "checksum-calc-failure"; - - private static final String TYPE_CHECKSUM_CANNOT_CREATE = "checksum-create-failure"; - - private File repositoryDir; - - private List includes = new ArrayList(); - - public ArtifactMissingChecksumsConsumer(String id, - String description, - ArchivaConfiguration configuration, - FileTypes filetypes) { - this.id = id; - this.description = description; - this.configuration = configuration; - this.filetypes = filetypes; - - configuration.addChangeListener( this ); - - initIncludes(); - } - - public String getId() - { - return this.id; - } - - public String getDescription() - { - return this.description; - } - - public boolean isPermanent() - { - return false; - } - - public void beginScan( ManagedRepository repo, Date whenGathered ) - throws ConsumerException - { - this.repositoryDir = new File( repo.getLocation() ); - } - - public void beginScan( ManagedRepository repo, Date whenGathered, boolean executeOnEntireRepo ) - throws ConsumerException - { - beginScan( repo, whenGathered ); - } - - public void completeScan() - { - /* do nothing */ - } - - public void completeScan( boolean executeOnEntireRepo ) - { - completeScan(); - } - - public List getExcludes() - { - return getDefaultArtifactExclusions(); - } - - public List getIncludes() - { - return includes; - } - - public void processFile( String path ) - throws ConsumerException - { - createFixChecksum( path, new ChecksumAlgorithm[] { ChecksumAlgorithm.SHA1 } ); - createFixChecksum( path, new ChecksumAlgorithm[] { ChecksumAlgorithm.MD5 } ); - } - - public void processFile( String path, boolean executeOnEntireRepo ) - throws ConsumerException - { - processFile( path ); - } - - private void createFixChecksum( String path, ChecksumAlgorithm checksumAlgorithm[] ) - { - File artifactFile = new File( this.repositoryDir, path ); - File checksumFile = new File( this.repositoryDir, path + checksumAlgorithm[0].getExt() ); - - if( checksumFile.exists() ) - { - checksum = new ChecksummedFile( artifactFile ); - try - { - if( !checksum.isValidChecksum( checksumAlgorithm[0] ) ) - { - checksum.fixChecksums( checksumAlgorithm ); - triggerConsumerInfo( "Fixed checksum file " + checksumFile.getAbsolutePath() ); - } - } - catch ( IOException e ) - { - triggerConsumerError( TYPE_CHECKSUM_CANNOT_CALC, "Cannot calculate checksum for file " + checksumFile + - ": " + e.getMessage() ); - } - } - else if( !checksumFile.exists() ) - { - checksum = new ChecksummedFile( artifactFile ); - try - { - checksum.createChecksum( checksumAlgorithm[0] ); - triggerConsumerInfo( "Created missing checksum file " + checksumFile.getAbsolutePath() ); - } - catch ( IOException e ) - { - triggerConsumerError( TYPE_CHECKSUM_CANNOT_CREATE, "Cannot create checksum for file " + checksumFile + - ": " + e.getMessage() ); - } - } - else - { - triggerConsumerWarning( TYPE_CHECKSUM_NOT_FILE, - "Checksum file " + checksumFile.getAbsolutePath() + " is not a file." ); - } - } - - public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) - { - if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) - { - initIncludes(); - } - } - - public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) - { - /* do nothing */ - } - - private void initIncludes() - { - includes.clear(); - - includes.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) ); - } - - @PostConstruct - public void initialize() - { - configuration.addChangeListener( this ); - - initIncludes(); - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRemoveConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRemoveConsumer.java deleted file mode 100644 index c12fb1f47..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRemoveConsumer.java +++ /dev/null @@ -1,169 +0,0 @@ -package org.apache.maven.archiva.consumers.core; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.ConfigurationNames; -import org.apache.maven.archiva.configuration.FileTypes; -import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; -import org.apache.maven.archiva.consumers.ConsumerException; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.codehaus.plexus.registry.Registry; -import org.codehaus.plexus.registry.RegistryListener; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Service; - -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import java.io.File; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - * AutoRemoveConsumer - * - * @version $Id$ - */ -@Service("knownRepositoryContentConsumer#auto-remove") -@Scope("prototype") -public class AutoRemoveConsumer - extends AbstractMonitoredConsumer - implements KnownRepositoryContentConsumer, RegistryListener -{ - /** - * default-value="auto-remove" - */ - private String id = "auto-remove"; - - /** - * default-value="Automatically Remove File from Filesystem." - */ - private String description = "Automatically Remove File from Filesystem."; - - /** - * - */ - @Inject - private ArchivaConfiguration configuration; - - /** - * - */ - @Inject - private FileTypes filetypes; - - private File repositoryDir; - - private List includes = new ArrayList(); - - public String getId() - { - return this.id; - } - - public String getDescription() - { - return this.description; - } - - public boolean isPermanent() - { - return false; - } - - public void beginScan( ManagedRepository repository, Date whenGathered ) - throws ConsumerException - { - this.repositoryDir = new File( repository.getLocation() ); - } - - public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo ) - throws ConsumerException - { - beginScan( repository, whenGathered ); - } - - public void completeScan() - { - /* do nothing */ - } - - public void completeScan( boolean executeOnEntireRepo ) - { - completeScan(); - } - - public List getExcludes() - { - return null; - } - - public List getIncludes() - { - return includes; - } - - public void processFile( String path ) - throws ConsumerException - { - File file = new File( this.repositoryDir, path ); - if ( file.exists() ) - { - triggerConsumerInfo( "(Auto) Removing File: " + file.getAbsolutePath() ); - file.delete(); - } - } - - public void processFile( String path, boolean executeOnEntireRepo ) - throws ConsumerException - { - processFile( path ); - } - - public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) - { - if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) - { - initIncludes(); - } - } - - public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) - { - /* do nothing */ - } - - private void initIncludes() - { - includes.clear(); - - includes.addAll( filetypes.getFileTypePatterns( FileTypes.AUTO_REMOVE ) ); - } - - @PostConstruct - public void initialize() - { - configuration.addChangeListener( this ); - - initIncludes(); - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRenameConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRenameConsumer.java deleted file mode 100644 index c4e7e61f6..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRenameConsumer.java +++ /dev/null @@ -1,164 +0,0 @@ -package org.apache.maven.archiva.consumers.core; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.commons.io.FileUtils; -import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; -import org.apache.maven.archiva.consumers.ConsumerException; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Service; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -/** - * AutoRenameConsumer - * - * @version $Id$ - */ -@Service("knownRepositoryContentConsumer#auto-rename") -@Scope("prototype") -public class AutoRenameConsumer - extends AbstractMonitoredConsumer - implements KnownRepositoryContentConsumer -{ - /** - * default-value="auto-rename" - */ - private String id = "auto-rename"; - - /** - * default-value="Automatically rename common artifact mistakes." - */ - private String description = "Automatically rename common artifact mistakes."; - - private static final String RENAME_FAILURE = "rename_failure"; - - private File repositoryDir; - - private List includes = new ArrayList(); - - private Map extensionRenameMap = new HashMap(); - - public AutoRenameConsumer() - { - includes.add( "**/*.distribution-tgz" ); - includes.add( "**/*.distribution-zip" ); - includes.add( "**/*.plugin" ); - - extensionRenameMap.put( ".distribution-tgz", ".tar.gz" ); - extensionRenameMap.put( ".distribution-zip", ".zip" ); - extensionRenameMap.put( ".plugin", ".jar" ); - } - - public String getId() - { - return this.id; - } - - public String getDescription() - { - return this.description; - } - - public boolean isPermanent() - { - return false; - } - - public void beginScan( ManagedRepository repository, Date whenGathered ) - throws ConsumerException - { - this.repositoryDir = new File( repository.getLocation() ); - } - - public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo ) - throws ConsumerException - { - beginScan( repository, whenGathered ); - } - - public void completeScan() - { - /* do nothing */ - } - - public void completeScan( boolean executeOnEntireRepo ) - { - completeScan(); - } - - public List getExcludes() - { - return null; - } - - public List getIncludes() - { - return includes; - } - - public void processFile( String path ) - throws ConsumerException - { - File file = new File( this.repositoryDir, path ); - if ( file.exists() ) - { - Iterator itExtensions = this.extensionRenameMap.keySet().iterator(); - while ( itExtensions.hasNext() ) - { - String extension = (String) itExtensions.next(); - if ( path.endsWith( extension ) ) - { - String fixedExtension = (String) this.extensionRenameMap.get( extension ); - String correctedPath = path.substring( 0, path.length() - extension.length() ) + fixedExtension; - File to = new File( this.repositoryDir, correctedPath ); - try - { - // Rename the file. - FileUtils.moveFile( file, to ); - } - catch ( IOException e ) - { - triggerConsumerWarning( RENAME_FAILURE, "Unable to rename " + path + " to " + correctedPath + - ": " + e.getMessage() ); - } - } - } - - triggerConsumerInfo( "(Auto) Removing File: " + file.getAbsolutePath() ); - file.delete(); - } - } - - public void processFile( String path, boolean executeOnEntireRepo ) - throws ConsumerException - { - processFile( path ); - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/MetadataUpdaterConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/MetadataUpdaterConsumer.java deleted file mode 100644 index 8642a7acb..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/MetadataUpdaterConsumer.java +++ /dev/null @@ -1,324 +0,0 @@ -package org.apache.maven.archiva.consumers.core; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.ConfigurationNames; -import org.apache.maven.archiva.configuration.FileTypes; -import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; -import org.apache.maven.archiva.consumers.ConsumerException; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.apache.maven.archiva.model.ArtifactReference; -import org.apache.maven.archiva.model.ProjectReference; -import org.apache.maven.archiva.model.VersionedReference; -import org.apache.archiva.repository.ContentNotFoundException; -import org.apache.archiva.repository.ManagedRepositoryContent; -import org.apache.archiva.repository.RepositoryContentFactory; -import org.apache.archiva.repository.RepositoryException; -import org.apache.archiva.repository.RepositoryNotFoundException; -import org.apache.archiva.repository.layout.LayoutException; -import org.apache.archiva.repository.metadata.MetadataTools; -import org.apache.archiva.repository.metadata.RepositoryMetadataException; -import org.codehaus.plexus.registry.Registry; -import org.codehaus.plexus.registry.RegistryListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Service; - -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - * MetadataUpdaterConsumer will create and update the metadata present within the repository. - * - * @version $Id$ - */ -@Service("knownRepositoryContentConsumer#metadata-updater") -@Scope("prototype") -public class MetadataUpdaterConsumer - extends AbstractMonitoredConsumer - implements KnownRepositoryContentConsumer, RegistryListener -{ - private Logger log = LoggerFactory.getLogger( MetadataUpdaterConsumer.class ); - - /** - * default-value="metadata-updater" - */ - private String id = "metadata-updater"; - - /** - * default-value="Update / Create maven-metadata.xml files" - */ - private String description = "Update / Create maven-metadata.xml files"; - - /** - * - */ - @Inject - private RepositoryContentFactory repositoryFactory; - - /** - * - */ - @Inject - private MetadataTools metadataTools; - - /** - * - */ - @Inject - private ArchivaConfiguration configuration; - - /** - * - */ - @Inject - private FileTypes filetypes; - - private static final String TYPE_METADATA_BAD_INTERNAL_REF = "metadata-bad-internal-ref"; - - private static final String TYPE_METADATA_WRITE_FAILURE = "metadata-write-failure"; - - private static final String TYPE_METADATA_IO = "metadata-io-warning"; - - private ManagedRepositoryContent repository; - - private File repositoryDir; - - private List includes = new ArrayList(); - - private long scanStartTimestamp = 0; - - public String getDescription() - { - return description; - } - - public String getId() - { - return id; - } - - public void setIncludes( List includes ) - { - this.includes = includes; - } - - public void beginScan( ManagedRepository repoConfig, Date whenGathered ) - throws ConsumerException - { - try - { - 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 ); - } - catch ( RepositoryException e ) - { - throw new ConsumerException( e.getMessage(), e ); - } - } - - public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo ) - throws ConsumerException - { - beginScan( repository, whenGathered ); - } - - public void completeScan() - { - /* do nothing here */ - } - - public void completeScan( boolean executeOnEntireRepo ) - { - completeScan(); - } - - public List getExcludes() - { - return getDefaultArtifactExclusions(); - } - - public List getIncludes() - { - return this.includes; - } - - public void processFile( String path ) - throws ConsumerException - { - // Ignore paths like .index etc - if ( !path.startsWith( "." ) ) - { - try - { - ArtifactReference artifact = repository.toArtifactReference( path ); - updateVersionMetadata( artifact, path ); - updateProjectMetadata( artifact, path ); - } - catch ( LayoutException e ) - { - log.info( "Not processing path that is not an artifact: " + path + " (" + e.getMessage() + ")" ); - } - } - } - - public void processFile( String path, boolean executeOnEntireRepo ) - throws Exception - { - processFile( path ); - } - - private void updateProjectMetadata( ArtifactReference artifact, String path ) - { - ProjectReference projectRef = new ProjectReference(); - projectRef.setGroupId( artifact.getGroupId() ); - projectRef.setArtifactId( artifact.getArtifactId() ); - - try - { - String metadataPath = this.metadataTools.toPath( projectRef ); - - File projectMetadata = new File( this.repositoryDir, metadataPath ); - - if ( projectMetadata.exists() && ( projectMetadata.lastModified() >= this.scanStartTimestamp ) ) - { - // This metadata is up to date. skip it. - log.debug( "Skipping uptodate metadata: {}", this.metadataTools.toPath( projectRef ) ); - return; - } - - metadataTools.updateMetadata( this.repository, projectRef ); - log.debug( "Updated metadata: {}", this.metadataTools.toPath( projectRef ) ); - } - catch ( LayoutException e ) - { - triggerConsumerWarning( TYPE_METADATA_BAD_INTERNAL_REF, "Unable to convert path [" + path - + "] to an internal project reference: " + e.getMessage() ); - } - catch ( RepositoryMetadataException e ) - { - triggerConsumerError( TYPE_METADATA_WRITE_FAILURE, "Unable to write project metadata for artifact [" + path - + "]: " + e.getMessage() ); - } - catch ( IOException e ) - { - triggerConsumerWarning( TYPE_METADATA_IO, "Project metadata not written due to IO warning: " - + e.getMessage() ); - } - catch ( ContentNotFoundException e ) - { - triggerConsumerWarning( TYPE_METADATA_IO, - "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() ); - - try - { - String metadataPath = this.metadataTools.toPath( versionRef ); - - File projectMetadata = new File( this.repositoryDir, metadataPath ); - - if ( projectMetadata.exists() && ( projectMetadata.lastModified() >= this.scanStartTimestamp ) ) - { - // This metadata is up to date. skip it. - log.debug( "Skipping uptodate metadata: {}", this.metadataTools.toPath( versionRef ) ); - return; - } - - metadataTools.updateMetadata( this.repository, versionRef ); - log.debug( "Updated metadata: {}", this.metadataTools.toPath( versionRef ) ); - } - catch ( LayoutException e ) - { - triggerConsumerWarning( TYPE_METADATA_BAD_INTERNAL_REF, "Unable to convert path [" + path - + "] to an internal version reference: " + e.getMessage() ); - } - catch ( RepositoryMetadataException e ) - { - triggerConsumerError( TYPE_METADATA_WRITE_FAILURE, "Unable to write version metadata for artifact [" + path - + "]: " + e.getMessage() ); - } - catch ( IOException e ) - { - triggerConsumerWarning( TYPE_METADATA_IO, "Version metadata not written due to IO warning: " - + e.getMessage() ); - } - catch ( ContentNotFoundException e ) - { - triggerConsumerWarning( TYPE_METADATA_IO, - "Version metadata not written because no versions were found to update: " - + e.getMessage() ); - } - } - - public boolean isPermanent() - { - return false; - } - - public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) - { - if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) - { - initIncludes(); - } - } - - public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) - { - /* do nothing here */ - } - - private void initIncludes() - { - includes.clear(); - - includes.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) ); - } - - @PostConstruct - public void initialize() - { - configuration.addChangeListener( this ); - - initIncludes(); - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ValidateChecksumConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ValidateChecksumConsumer.java deleted file mode 100644 index 171db69ab..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ValidateChecksumConsumer.java +++ /dev/null @@ -1,183 +0,0 @@ -package org.apache.maven.archiva.consumers.core; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.archiva.common.plexusbridge.DigesterUtils; -import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; -import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; -import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; -import org.apache.maven.archiva.consumers.ConsumerException; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.codehaus.plexus.digest.ChecksumFile; -import org.codehaus.plexus.digest.Digester; -import org.codehaus.plexus.digest.DigesterException; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Service; - -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - * ValidateChecksumConsumer - validate the provided checksum against the file it represents. - * - * @version $Id$ - */ -@Service( "knownRepositoryContentConsumer#validate-checksum" ) -@Scope( "prototype" ) -public class ValidateChecksumConsumer - extends AbstractMonitoredConsumer - implements KnownRepositoryContentConsumer -{ - private static final String NOT_VALID_CHECKSUM = "checksum-not-valid"; - - private static final String CHECKSUM_NOT_FOUND = "checksum-not-found"; - - private static final String CHECKSUM_DIGESTER_FAILURE = "checksum-digester-failure"; - - private static final String CHECKSUM_IO_ERROR = "checksum-io-error"; - - /** - * default-value="validate-checksums" - */ - private String id = "validate-checksums"; - - /** - * default-value="Validate checksums against file." - */ - private String description = "Validate checksums against file."; - - /** - * - */ - private ChecksumFile checksum; - - /** - * - */ - private List allDigesters; - - @Inject - private PlexusSisuBridge plexusSisuBridge; - - @Inject - private DigesterUtils digesterUtils; - - private File repositoryDir; - - private List includes = new ArrayList(); - - public String getId() - { - return this.id; - } - - public String getDescription() - { - return this.description; - } - - public boolean isPermanent() - { - return false; - } - - public void beginScan( ManagedRepository repository, Date whenGathered ) - throws ConsumerException - { - this.repositoryDir = new File( repository.getLocation() ); - } - - public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo ) - throws ConsumerException - { - beginScan( repository, whenGathered ); - } - - public void completeScan() - { - /* nothing to do */ - } - - public void completeScan( boolean executeOnEntireRepo ) - { - completeScan(); - } - - public List getExcludes() - { - return null; - } - - public List getIncludes() - { - return this.includes; - } - - public void processFile( String path ) - throws ConsumerException - { - File checksumFile = new File( this.repositoryDir, path ); - try - { - if ( !checksum.isValidChecksum( checksumFile ) ) - { - triggerConsumerWarning( NOT_VALID_CHECKSUM, "The checksum for " + checksumFile + " is invalid." ); - } - } - catch ( FileNotFoundException e ) - { - triggerConsumerError( CHECKSUM_NOT_FOUND, "File not found during checksum validation: " + e.getMessage() ); - } - catch ( DigesterException e ) - { - triggerConsumerError( CHECKSUM_DIGESTER_FAILURE, - "Digester failure during checksum validation on " + checksumFile ); - } - catch ( IOException e ) - { - triggerConsumerError( CHECKSUM_IO_ERROR, "Checksum I/O error during validation on " + checksumFile ); - } - } - - public void processFile( String path, boolean executeOnEntireReDpo ) - throws Exception - { - processFile( path ); - } - - @PostConstruct - public void initialize() - throws PlexusSisuBridgeException - { - checksum = plexusSisuBridge.lookup( ChecksumFile.class ); - List allDigesters = new ArrayList( digesterUtils.getAllDigesters() ); - for ( Digester digester : allDigesters ) - { - includes.add( "**/*" + digester.getFilenameExtension() ); - } - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java deleted file mode 100644 index f34f0b9b0..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java +++ /dev/null @@ -1,138 +0,0 @@ -package org.apache.maven.archiva.consumers.core.repository; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.audit.AuditEvent; -import org.apache.archiva.metadata.repository.MetadataRepository; -import org.apache.archiva.metadata.repository.RepositorySession; -import org.apache.archiva.repository.events.RepositoryListener; -import org.apache.maven.archiva.model.ArtifactReference; -import org.apache.archiva.repository.ManagedRepositoryContent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.FilenameFilter; -import java.util.List; -import java.util.Set; - -/** - * Base class for all repository purge tasks. - */ -public abstract class AbstractRepositoryPurge - implements RepositoryPurge -{ - protected Logger log = LoggerFactory.getLogger( AbstractRepositoryPurge.class ); - - protected final ManagedRepositoryContent repository; - - protected final RepositorySession repositorySession; - - protected final List listeners; - - private Logger logger = LoggerFactory.getLogger( "org.apache.archiva.AuditLog" ); - - private static final char DELIM = ' '; - - public AbstractRepositoryPurge( ManagedRepositoryContent repository, RepositorySession repositorySession, - List listeners ) - { - this.repository = repository; - this.repositorySession = repositorySession; - this.listeners = listeners; - } - - /** - * Purge the repo. Update db and index of removed artifacts. - * - * @param references - */ - protected void purge( Set references ) - { - if ( references != null && !references.isEmpty() ) - { - MetadataRepository metadataRepository = repositorySession.getRepository(); - for ( ArtifactReference reference : references ) - { - File artifactFile = repository.toFile( reference ); - - // FIXME: looks incomplete, might not delete related metadata? - for ( RepositoryListener listener : listeners ) - { - listener.deleteArtifact( metadataRepository, repository.getId(), reference.getGroupId(), - reference.getArtifactId(), reference.getVersion(), - artifactFile.getName() ); - } - - // TODO: this needs to be logged - artifactFile.delete(); - repositorySession.save(); - - triggerAuditEvent( repository.getRepository().getId(), ArtifactReference.toKey( reference ), - AuditEvent.PURGE_ARTIFACT ); - purgeSupportFiles( artifactFile ); - } - } - } - - /** - *

- * This find support files for the artifactFile and deletes them. - *

- *

- * Support Files are things like ".sha1", ".md5", ".asc", etc. - *

- * - * @param artifactFile the file to base off of. - */ - private void purgeSupportFiles( File artifactFile ) - { - File parentDir = artifactFile.getParentFile(); - - if ( !parentDir.exists() ) - { - return; - } - - FilenameFilter filter = new ArtifactFilenameFilter( artifactFile.getName() ); - - File[] files = parentDir.listFiles( filter ); - - for ( File file : files ) - { - if ( file.exists() && file.isFile() ) - { - String fileName = file.getName(); - file.delete(); - // TODO: log that it was deleted - triggerAuditEvent( repository.getRepository().getId(), fileName, AuditEvent.PURGE_FILE ); - } - } - } - - private void triggerAuditEvent( String repoId, String resource, String action ) - { - String msg = - repoId + DELIM + "" + DELIM + "" + DELIM + '\"' + resource + '\"' + DELIM + '\"' + - action + '\"'; - - logger.info( msg ); - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/ArtifactFilenameFilter.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/ArtifactFilenameFilter.java deleted file mode 100644 index 357aa4713..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/ArtifactFilenameFilter.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.apache.maven.archiva.consumers.core.repository; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.FilenameFilter; -import java.io.File; - -/** - * Filename filter for getting all the files related to a specific artifact. - * - */ -public class ArtifactFilenameFilter - implements FilenameFilter -{ - private String filename; - - public ArtifactFilenameFilter() - { - - } - - public ArtifactFilenameFilter( String filename ) - { - this.filename = filename; - } - - public boolean accept( File dir, String name ) - { - return ( name.startsWith( filename ) ); - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java deleted file mode 100644 index 8e40ad5f5..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java +++ /dev/null @@ -1,266 +0,0 @@ -package org.apache.maven.archiva.consumers.core.repository; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.admin.model.RepositoryAdminException; -import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; -import org.apache.archiva.metadata.repository.MetadataRepository; -import org.apache.archiva.metadata.repository.RepositorySession; -import org.apache.archiva.repository.events.RepositoryListener; -import org.apache.archiva.common.utils.VersionComparator; -import org.apache.archiva.common.utils.VersionUtil; -import org.apache.maven.archiva.model.ArchivaArtifact; -import org.apache.maven.archiva.model.ArtifactReference; -import org.apache.maven.archiva.model.ProjectReference; -import org.apache.maven.archiva.model.VersionedReference; -import org.apache.archiva.repository.ContentNotFoundException; -import org.apache.archiva.repository.ManagedRepositoryContent; -import org.apache.archiva.repository.RepositoryContentFactory; -import org.apache.archiva.repository.RepositoryException; -import org.apache.archiva.repository.RepositoryNotFoundException; -import org.apache.archiva.repository.layout.LayoutException; -import org.apache.archiva.repository.metadata.MetadataTools; -import org.apache.archiva.repository.metadata.RepositoryMetadataException; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - *

- * This will look in a single managed repository, and purge any snapshots that are present - * that have a corresponding released version on the same repository. - *

- *

- *

- * So, if you have the following (presented in the m2/default layout form) ... - *

- *   /com/foo/foo-tool/1.0-SNAPSHOT/foo-tool-1.0-SNAPSHOT.jar
- *   /com/foo/foo-tool/1.1-SNAPSHOT/foo-tool-1.1-SNAPSHOT.jar
- *   /com/foo/foo-tool/1.2.1-SNAPSHOT/foo-tool-1.2.1-SNAPSHOT.jar
- *   /com/foo/foo-tool/1.2.1/foo-tool-1.2.1.jar
- *   /com/foo/foo-tool/2.0-SNAPSHOT/foo-tool-2.0-SNAPSHOT.jar
- *   /com/foo/foo-tool/2.0/foo-tool-2.0.jar
- *   /com/foo/foo-tool/2.1-SNAPSHOT/foo-tool-2.1-SNAPSHOT.jar
- * 
- * then the current highest ranked released (non-snapshot) version is 2.0, which means - * the snapshots from 1.0-SNAPSHOT, 1.1-SNAPSHOT, 1.2.1-SNAPSHOT, and 2.0-SNAPSHOT can - * be purged. Leaving 2.1-SNAPSHOT in alone. - *

- * - * @version $Id$ - */ -public class CleanupReleasedSnapshotsRepositoryPurge - extends AbstractRepositoryPurge -{ - private MetadataTools metadataTools; - - private ManagedRepositoryAdmin managedRepositoryAdmin; - - private RepositoryContentFactory repoContentFactory; - - public CleanupReleasedSnapshotsRepositoryPurge( ManagedRepositoryContent repository, MetadataTools metadataTools, - ManagedRepositoryAdmin managedRepositoryAdmin, - RepositoryContentFactory repoContentFactory, - RepositorySession repositorySession, - List listeners ) - { - super( repository, repositorySession, listeners ); - this.metadataTools = metadataTools; - this.managedRepositoryAdmin = managedRepositoryAdmin; - this.repoContentFactory = repoContentFactory; - } - - public void process( String path ) - throws RepositoryPurgeException - { - try - { - File artifactFile = new File( repository.getRepoRoot(), path ); - - if ( !artifactFile.exists() ) - { - // Nothing to do here, file doesn't exist, skip it. - return; - } - - ArtifactReference artifactRef = repository.toArtifactReference( path ); - - 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() ); - - // Gather up all of the versions. - List allVersions = new ArrayList( repository.getVersions( reference ) ); - - List repos = managedRepositoryAdmin.getManagedRepositories(); - for ( ManagedRepository repo : repos ) - { - if ( repo.isReleases() && !repo.getId().equals( repository.getId() ) ) - { - try - { - ManagedRepositoryContent repoContent = - repoContentFactory.getManagedRepositoryContent( repo.getId() ); - allVersions.addAll( repoContent.getVersions( reference ) ); - } - catch ( RepositoryNotFoundException e ) - { - // swallow - } - catch ( RepositoryException e ) - { - // swallow - } - } - } - - // Split the versions into released and snapshots. - List releasedVersions = new ArrayList(); - List snapshotVersions = new ArrayList(); - - for ( String version : allVersions ) - { - if ( VersionUtil.isSnapshot( version ) ) - { - snapshotVersions.add( version ); - } - else - { - releasedVersions.add( version ); - } - } - - Collections.sort( allVersions, VersionComparator.getInstance() ); - Collections.sort( releasedVersions, VersionComparator.getInstance() ); - Collections.sort( snapshotVersions, 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() ); - - ArchivaArtifact artifact = - new ArchivaArtifact( artifactRef.getGroupId(), artifactRef.getArtifactId(), artifactRef.getVersion(), - artifactRef.getClassifier(), artifactRef.getType(), repository.getId() ); - - MetadataRepository metadataRepository = repositorySession.getRepository(); - for ( String version : snapshotVersions ) - { - if ( releasedVersions.contains( VersionUtil.getReleaseVersion( version ) ) ) - { - versionRef.setVersion( version ); - repository.deleteVersion( versionRef ); - - // FIXME: looks incomplete, might not delete related metadata? - for ( RepositoryListener listener : listeners ) - { - listener.deleteArtifact( metadataRepository, repository.getId(), artifact.getGroupId(), - artifact.getArtifactId(), artifact.getVersion(), - artifactFile.getName() ); - } - - needsMetadataUpdate = true; - } - } - - if ( needsMetadataUpdate ) - { - updateMetadata( artifactRef ); - } - } catch ( RepositoryAdminException e ) - { - throw new RepositoryPurgeException( e.getMessage(), e ); - } - catch ( LayoutException e ) - { - log.debug( "Not processing file that is not an artifact: {}", e.getMessage() ); - } - catch ( ContentNotFoundException e ) - { - throw new RepositoryPurgeException( e.getMessage(), e ); - } - } - - 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() ); - - try - { - metadataTools.updateMetadata( repository, versionRef ); - } - catch ( ContentNotFoundException e ) - { - // Ignore. (Just means we have no snapshot versions left to reference). - } - catch ( RepositoryMetadataException e ) - { - // Ignore. - } - catch ( IOException e ) - { - // Ignore. - } - catch ( LayoutException e ) - { - // Ignore. - } - - try - { - metadataTools.updateMetadata( repository, projectRef ); - } - catch ( ContentNotFoundException e ) - { - // Ignore. (Just means we have no snapshot versions left to reference). - } - catch ( RepositoryMetadataException e ) - { - // Ignore. - } - catch ( IOException e ) - { - // Ignore. - } - catch ( LayoutException e ) - { - // Ignore. - } - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurge.java deleted file mode 100644 index e4ffb4288..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurge.java +++ /dev/null @@ -1,190 +0,0 @@ -package org.apache.maven.archiva.consumers.core.repository; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.metadata.repository.RepositorySession; -import org.apache.archiva.repository.events.RepositoryListener; -import org.apache.commons.lang.time.DateUtils; -import org.apache.archiva.common.utils.VersionComparator; -import org.apache.archiva.common.utils.VersionUtil; -import org.apache.maven.archiva.model.ArtifactReference; -import org.apache.maven.archiva.model.VersionedReference; -import org.apache.archiva.repository.ContentNotFoundException; -import org.apache.archiva.repository.ManagedRepositoryContent; -import org.apache.archiva.repository.layout.LayoutException; - -import java.io.File; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Set; -import java.util.regex.Matcher; - -/** - * Purge from repository all snapshots older than the specified days in the repository configuration. - */ -public class DaysOldRepositoryPurge - extends AbstractRepositoryPurge -{ - private SimpleDateFormat timestampParser; - - private int daysOlder; - - private int retentionCount; - - public DaysOldRepositoryPurge( ManagedRepositoryContent repository, int daysOlder, int retentionCount, - RepositorySession repositorySession, List listeners ) - { - super( repository, repositorySession, listeners ); - this.daysOlder = daysOlder; - this.retentionCount = retentionCount; - timestampParser = new SimpleDateFormat( "yyyyMMdd.HHmmss" ); - timestampParser.setTimeZone( DateUtils.UTC_TIME_ZONE ); - } - - public void process( String path ) - throws RepositoryPurgeException - { - try - { - File artifactFile = new File( repository.getRepoRoot(), path ); - - if ( !artifactFile.exists() ) - { - return; - } - - ArtifactReference artifact = repository.toArtifactReference( path ); - - Calendar olderThanThisDate = Calendar.getInstance( DateUtils.UTC_TIME_ZONE ); - olderThanThisDate.add( Calendar.DATE, -daysOlder ); - - // respect retention count - VersionedReference reference = new VersionedReference(); - reference.setGroupId( artifact.getGroupId() ); - reference.setArtifactId( artifact.getArtifactId() ); - reference.setVersion( artifact.getVersion() ); - - List versions = new ArrayList( repository.getVersions( reference ) ); - - Collections.sort( versions, VersionComparator.getInstance() ); - - if ( retentionCount > versions.size() ) - { - // Done. nothing to do here. skip it. - return; - } - - int countToPurge = versions.size() - retentionCount; - - for ( String version : versions ) - { - if ( countToPurge-- <= 0 ) - { - break; - } - - ArtifactReference newArtifactReference = repository.toArtifactReference( - artifactFile.getAbsolutePath() ); - newArtifactReference.setVersion( version ); - - File newArtifactFile = repository.toFile( newArtifactReference ); - - // Is this a generic snapshot "1.0-SNAPSHOT" ? - if ( VersionUtil.isGenericSnapshot( newArtifactReference.getVersion() ) ) - { - if ( newArtifactFile.lastModified() < olderThanThisDate.getTimeInMillis() ) - { - doPurgeAllRelated( newArtifactReference ); - } - } - // Is this a timestamp snapshot "1.0-20070822.123456-42" ? - else if ( VersionUtil.isUniqueSnapshot( newArtifactReference.getVersion() ) ) - { - Calendar timestampCal = uniqueSnapshotToCalendar( newArtifactReference.getVersion() ); - - if ( timestampCal.getTimeInMillis() < olderThanThisDate.getTimeInMillis() ) - { - doPurgeAllRelated( newArtifactReference ); - } - } - } - } - catch ( ContentNotFoundException e ) - { - throw new RepositoryPurgeException( e.getMessage(), e ); - } - catch ( LayoutException e ) - { - log.debug( "Not processing file that is not an artifact: {}", e.getMessage() ); - } - } - - private Calendar uniqueSnapshotToCalendar( String version ) - { - // The latestVersion will contain the full version string "1.0-alpha-5-20070821.213044-8" - // This needs to be broken down into ${base}-${timestamp}-${build_number} - - Matcher m = VersionUtil.UNIQUE_SNAPSHOT_PATTERN.matcher( version ); - if ( m.matches() ) - { - Matcher mtimestamp = VersionUtil.TIMESTAMP_PATTERN.matcher( m.group( 2 ) ); - if ( mtimestamp.matches() ) - { - String tsDate = mtimestamp.group( 1 ); - String tsTime = mtimestamp.group( 2 ); - - Date versionDate; - try - { - versionDate = timestampParser.parse( tsDate + "." + tsTime ); - Calendar cal = Calendar.getInstance( DateUtils.UTC_TIME_ZONE ); - cal.setTime( versionDate ); - - return cal; - } - catch ( ParseException e ) - { - // Invalid Date/Time - return null; - } - } - } - return null; - } - - private void doPurgeAllRelated( ArtifactReference reference ) - { - try - { - Set related = repository.getRelatedArtifacts( reference ); - purge( related ); - } - catch ( ContentNotFoundException e ) - { - // Nothing to do here - it means the repository would have been constructed incorrectly - log.debug( e.getMessage(), e ); - } - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurge.java deleted file mode 100644 index 297daadc5..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurge.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apache.maven.archiva.consumers.core.repository; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * @version $Id$ - */ -public interface RepositoryPurge -{ - /** - * Perform checking on artifact for repository purge - * - * @param path path to the scanned artifact - */ - void process( String path ) - throws RepositoryPurgeException; - -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumer.java deleted file mode 100644 index a7186c8fd..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumer.java +++ /dev/null @@ -1,350 +0,0 @@ -package org.apache.maven.archiva.consumers.core.repository; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; -import org.apache.archiva.metadata.repository.RepositorySession; -import org.apache.archiva.metadata.repository.RepositorySessionFactory; -import org.apache.archiva.repository.events.RepositoryListener; -import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.ConfigurationNames; -import org.apache.maven.archiva.configuration.FileTypes; -import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; -import org.apache.maven.archiva.consumers.ConsumerException; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.apache.archiva.repository.ManagedRepositoryContent; -import org.apache.archiva.repository.RepositoryContentFactory; -import org.apache.archiva.repository.RepositoryException; -import org.apache.archiva.repository.RepositoryNotFoundException; -import org.apache.archiva.repository.metadata.MetadataTools; -import org.codehaus.plexus.registry.Registry; -import org.codehaus.plexus.registry.RegistryListener; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Service; - -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import javax.inject.Named; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; - -/** - * Consumer for removing old snapshots in the repository based on the criteria - * specified by the user. - */ -@Service( "knownRepositoryContentConsumer#repository-purge" ) -@Scope( "prototype" ) -public class RepositoryPurgeConsumer - extends AbstractMonitoredConsumer - implements KnownRepositoryContentConsumer, RegistryListener -{ - /** - * default-value="repository-purge" - */ - private String id = "repository-purge"; - - /** - * default-value="Purge repository of old snapshots" - */ - private String description = "Purge repository of old snapshots"; - - /** - * - */ - @Inject - @Named( value = "archivaConfiguration#default" ) - private ArchivaConfiguration configuration; - - @Inject - private ManagedRepositoryAdmin managedRepositoryAdmin; - - /** - * - */ - @Inject - @Named( value = "repositoryContentFactory#default" ) - private RepositoryContentFactory repositoryContentFactory; - - /** - * - */ - @Inject - private MetadataTools metadataTools; - - /** - * - */ - @Inject - @Named( value = "fileTypes" ) - private FileTypes filetypes; - - private List includes = new ArrayList(); - - private RepositoryPurge repoPurge; - - private RepositoryPurge cleanUp; - - private boolean deleteReleasedSnapshots; - - /** - * - */ - @Inject - private List listeners = Collections.emptyList(); - - /** - * TODO: this could be multiple implementations and needs to be configured. - */ - @Inject - private RepositorySessionFactory repositorySessionFactory; - - private RepositorySession repositorySession; - - public String getId() - { - return this.id; - } - - public String getDescription() - { - return this.description; - } - - public boolean isPermanent() - { - return false; - } - - public List getExcludes() - { - return getDefaultArtifactExclusions(); - } - - public List getIncludes() - { - return this.includes; - } - - public void beginScan( ManagedRepository repository, Date whenGathered ) - throws ConsumerException - { - ManagedRepositoryContent repositoryContent; - try - { - repositoryContent = repositoryContentFactory.getManagedRepositoryContent( repository.getId() ); - } - catch ( RepositoryNotFoundException 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 ); - } - - repositorySession = repositorySessionFactory.createSession(); - - if ( repository.getDaysOlder() != 0 ) - { - repoPurge = new DaysOldRepositoryPurge( repositoryContent, repository.getDaysOlder(), - repository.getRetentionCount(), repositorySession, listeners ); - } - else - { - repoPurge = - new RetentionCountRepositoryPurge( repositoryContent, repository.getRetentionCount(), repositorySession, - listeners ); - } - - cleanUp = new CleanupReleasedSnapshotsRepositoryPurge( repositoryContent, metadataTools, managedRepositoryAdmin, - repositoryContentFactory, repositorySession, listeners ); - - deleteReleasedSnapshots = repository.isDeleteReleasedSnapshots(); - } - - public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo ) - throws ConsumerException - { - beginScan( repository, whenGathered ); - } - - public void processFile( String path ) - throws ConsumerException - { - try - { - if ( deleteReleasedSnapshots ) - { - cleanUp.process( path ); - } - - repoPurge.process( path ); - } - catch ( RepositoryPurgeException rpe ) - { - throw new ConsumerException( rpe.getMessage(), rpe ); - } - } - - public void processFile( String path, boolean executeOnEntireRepo ) - throws Exception - { - processFile( path ); - } - - public void completeScan() - { - repositorySession.close(); - } - - public void completeScan( boolean executeOnEntireRepo ) - { - completeScan(); - } - - public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) - { - if ( ConfigurationNames.isRepositoryScanning( propertyName ) ) - { - initIncludes(); - } - } - - public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) - { - /* do nothing */ - } - - private void initIncludes() - { - includes.clear(); - - includes.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) ); - } - - @PostConstruct - public void initialize() - { - //this.listeners = - // new ArrayList( applicationContext.getBeansOfType( RepositoryListener.class ).values() ); - configuration.addChangeListener( this ); - - initIncludes(); - } - - public boolean isProcessUnmodified() - { - // we need to check all files for deletion, especially if not modified - return true; - } - - public ArchivaConfiguration getConfiguration() - { - return configuration; - } - - public void setConfiguration( ArchivaConfiguration configuration ) - { - this.configuration = configuration; - } - - public RepositoryContentFactory getRepositoryContentFactory() - { - return repositoryContentFactory; - } - - public void setRepositoryContentFactory( RepositoryContentFactory repositoryContentFactory ) - { - this.repositoryContentFactory = repositoryContentFactory; - } - - public MetadataTools getMetadataTools() - { - return metadataTools; - } - - public void setMetadataTools( MetadataTools metadataTools ) - { - this.metadataTools = metadataTools; - } - - public FileTypes getFiletypes() - { - return filetypes; - } - - public void setFiletypes( FileTypes filetypes ) - { - this.filetypes = filetypes; - } - - public RepositoryPurge getRepoPurge() - { - return repoPurge; - } - - public void setRepoPurge( RepositoryPurge repoPurge ) - { - this.repoPurge = repoPurge; - } - - public RepositoryPurge getCleanUp() - { - return cleanUp; - } - - public void setCleanUp( RepositoryPurge cleanUp ) - { - this.cleanUp = cleanUp; - } - - public boolean isDeleteReleasedSnapshots() - { - return deleteReleasedSnapshots; - } - - public void setDeleteReleasedSnapshots( boolean deleteReleasedSnapshots ) - { - this.deleteReleasedSnapshots = deleteReleasedSnapshots; - } - - public RepositorySessionFactory getRepositorySessionFactory() - { - return repositorySessionFactory; - } - - public void setRepositorySessionFactory( RepositorySessionFactory repositorySessionFactory ) - { - this.repositorySessionFactory = repositorySessionFactory; - } - - public RepositorySession getRepositorySession() - { - return repositorySession; - } - - public void setRepositorySession( RepositorySession repositorySession ) - { - this.repositorySession = repositorySession; - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeException.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeException.java deleted file mode 100644 index 0ebf4095d..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeException.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.apache.maven.archiva.consumers.core.repository; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * - * @version $Id$ - */ -public class RepositoryPurgeException - extends Exception -{ - public RepositoryPurgeException() - { - super(); - } - - public RepositoryPurgeException( String message, Throwable cause ) - { - super( message, cause ); - } - - public RepositoryPurgeException( String message ) - { - super( message ); - } - - public RepositoryPurgeException( Throwable cause ) - { - super( cause ); - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java deleted file mode 100644 index 9c60ece17..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java +++ /dev/null @@ -1,129 +0,0 @@ -package org.apache.maven.archiva.consumers.core.repository; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.metadata.repository.RepositorySession; -import org.apache.archiva.repository.events.RepositoryListener; -import org.apache.archiva.common.utils.VersionComparator; -import org.apache.archiva.common.utils.VersionUtil; -import org.apache.maven.archiva.model.ArtifactReference; -import org.apache.maven.archiva.model.VersionedReference; -import org.apache.archiva.repository.ContentNotFoundException; -import org.apache.archiva.repository.ManagedRepositoryContent; -import org.apache.archiva.repository.layout.LayoutException; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -/** - * Purge the repository by retention count. Retain only the specified number of snapshots. - */ -public class RetentionCountRepositoryPurge - extends AbstractRepositoryPurge -{ - private int retentionCount; - - public RetentionCountRepositoryPurge( ManagedRepositoryContent repository, int retentionCount, - RepositorySession repositorySession, List listeners ) - { - super( repository, repositorySession, listeners ); - this.retentionCount = retentionCount; - } - - public void process( String path ) - throws RepositoryPurgeException - { - try - { - File artifactFile = new File( repository.getRepoRoot(), path ); - - if ( !artifactFile.exists() ) - { - return; - } - - ArtifactReference artifact = repository.toArtifactReference( path ); - - if ( VersionUtil.isSnapshot( artifact.getVersion() ) ) - { - VersionedReference reference = new VersionedReference(); - reference.setGroupId( artifact.getGroupId() ); - reference.setArtifactId( artifact.getArtifactId() ); - reference.setVersion( artifact.getVersion() ); - - List versions = new ArrayList( repository.getVersions( reference ) ); - - Collections.sort( versions, VersionComparator.getInstance() ); - - if ( retentionCount > versions.size() ) - { - // Done. nothing to do here. skip it. - return; - } - - int countToPurge = versions.size() - retentionCount; - - for ( String version : versions ) - { - if ( countToPurge-- <= 0 ) - { - break; - } - - doPurgeAllRelated( artifact, version ); - } - } - } - catch ( LayoutException le ) - { - throw new RepositoryPurgeException( le.getMessage(), le ); - } - catch ( ContentNotFoundException e ) - { - // Nothing to do here. - // TODO: Log this condition? - } - } - - private void doPurgeAllRelated( ArtifactReference reference, String version ) - throws LayoutException - { - ArtifactReference artifact = new ArtifactReference(); - artifact.setGroupId( reference.getGroupId() ); - artifact.setArtifactId( reference.getArtifactId() ); - artifact.setVersion( version ); - artifact.setClassifier( reference.getClassifier() ); - artifact.setType( reference.getType() ); - - try - { - Set related = repository.getRelatedArtifacts( artifact ); - purge( related ); - } - catch ( ContentNotFoundException e ) - { - // Nothing to do here. - // TODO: Log this? - } - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/resources/META-INF/spring-context.xml index 41be77bd2..db3b65468 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/resources/META-INF/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/resources/META-INF/spring-context.xml @@ -28,9 +28,9 @@ default-lazy-init="true"> - + - + create-missing-checksums diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/AbstractArtifactConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/AbstractArtifactConsumerTest.java new file mode 100644 index 000000000..3d858d793 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/AbstractArtifactConsumerTest.java @@ -0,0 +1,93 @@ +package org.apache.archiva.consumers.core; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import junit.framework.TestCase; +import org.apache.archiva.common.utils.BaseFile; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.FileType; +import org.apache.maven.archiva.configuration.FileTypes; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import javax.inject.Inject; +import java.io.File; + +@RunWith( SpringJUnit4ClassRunner.class ) +@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} ) +public abstract class AbstractArtifactConsumerTest + extends TestCase +{ + private File repoLocation; + + protected KnownRepositoryContentConsumer consumer; + + @Inject + protected ApplicationContext applicationContext; + + @Inject + ArchivaConfiguration archivaConfiguration; + + @Before + public void setUp() + throws Exception + { + super.setUp(); + + FileType fileType = + (FileType) archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 ); + assertEquals( FileTypes.ARTIFACTS, fileType.getId() ); + fileType.addPattern( "**/*.xml" ); + + repoLocation = new File( "target/test-" + getName() + "/test-repo" ); + } + + @Test + public void testConsumption() + { + File localFile = + new File( repoLocation, "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" ); + + ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate(); + BaseFile baseFile = new BaseFile( repoLocation, localFile ); + predicate.setBasefile( baseFile ); + + assertFalse( predicate.evaluate( consumer ) ); + } + + @Test + public void testConsumptionOfOtherMetadata() + { + File localFile = + new File( repoLocation, "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata-central.xml" ); + + ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate(); + BaseFile baseFile = new BaseFile( repoLocation, localFile ); + predicate.setBasefile( baseFile ); + + assertFalse( predicate.evaluate( consumer ) ); + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java new file mode 100644 index 000000000..7e233c06b --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java @@ -0,0 +1,105 @@ +package org.apache.archiva.consumers.core; + +import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.checksum.ChecksumAlgorithm; +import org.apache.archiva.checksum.ChecksummedFile; +import org.apache.commons.io.FileUtils; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.util.Calendar; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public class ArtifactMissingChecksumsConsumerTest + extends AbstractArtifactConsumerTest +{ + private ManagedRepository repoConfig; + + @Before + public void setUp() + throws Exception + { + super.setUp(); + + repoConfig = new ManagedRepository(); + repoConfig.setId( "test-repo" ); + repoConfig.setName( "Test Repository" ); + repoConfig.setLayout( "default" ); + repoConfig.setLocation( new File( "target/test-classes/test-repo/" ).getPath() ); + + consumer = applicationContext.getBean( "knownRepositoryContentConsumer#artifact-missing-checksums-consumer", + KnownRepositoryContentConsumer.class ); + } + + @Test + public void testNoExistingChecksums() + throws Exception + { + String path = "/no-checksums-artifact/1.0/no-checksums-artifact-1.0.jar"; + + File sha1File = new File( repoConfig.getLocation(), path + ".sha1" ); + File md5File = new File( repoConfig.getLocation(), path + ".md5" ); + + sha1File.delete(); + md5File.delete(); + + assertFalse( sha1File.exists() ); + assertFalse( md5File.exists() ); + + consumer.beginScan( repoConfig, Calendar.getInstance().getTime() ); + + consumer.processFile( path ); + + assertTrue( sha1File.exists() ); + assertTrue( md5File.exists() ); + } + + @Test + public void testExistingIncorrectChecksums() + throws Exception + { + File newLocation = new File( "target/test-repo" ); + FileUtils.deleteDirectory( newLocation ); + FileUtils.copyDirectory( new File( repoConfig.getLocation() ), newLocation ); + repoConfig.setLocation( newLocation.getAbsolutePath() ); + + String path = "/incorrect-checksums/1.0/incorrect-checksums-1.0.jar"; + + File sha1File = new File( repoConfig.getLocation(), path + ".sha1" ); + File md5File = new File( repoConfig.getLocation(), path + ".md5" ); + + ChecksummedFile checksum = new ChecksummedFile( new File( repoConfig.getLocation(), path ) ); + + assertTrue( sha1File.exists() ); + assertTrue( md5File.exists() ); + assertFalse( checksum.isValidChecksums( new ChecksumAlgorithm[] { ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1 } ) ); + + consumer.beginScan( repoConfig, Calendar.getInstance().getTime() ); + + consumer.processFile( path ); + + assertTrue( sha1File.exists() ); + assertTrue( md5File.exists() ); + assertTrue( checksum.isValidChecksums( new ChecksumAlgorithm[] { ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1 } ) ); + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/MetadataUpdateConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/MetadataUpdateConsumerTest.java new file mode 100644 index 000000000..1ff915a5d --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/MetadataUpdateConsumerTest.java @@ -0,0 +1,36 @@ +package org.apache.archiva.consumers.core; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.junit.Before; + +public class MetadataUpdateConsumerTest + extends AbstractArtifactConsumerTest +{ + @Before + public void setUp() + throws Exception + { + super.setUp(); + consumer = applicationContext.getBean( "knownRepositoryContentConsumer#metadata-updater", + KnownRepositoryContentConsumer.class ); + } +} \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java new file mode 100644 index 000000000..0831b49b1 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java @@ -0,0 +1,181 @@ +package org.apache.archiva.consumers.core.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import junit.framework.TestCase; +import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.RepositorySession; +import org.apache.archiva.repository.events.RepositoryListener; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.archiva.repository.ManagedRepositoryContent; +import org.easymock.MockControl; +import org.junit.After; +import org.junit.Before; +import org.junit.runner.RunWith; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import javax.inject.Inject; +import java.io.File; +import java.io.IOException; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + */ +@RunWith( SpringJUnit4ClassRunner.class ) +@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) +public abstract class AbstractRepositoryPurgeTest + extends TestCase +{ + public static final String TEST_REPO_ID = "test-repo"; + + public static final String TEST_REPO_NAME = "Test Repository"; + + public static final int TEST_RETENTION_COUNT = 2; + + public static final int TEST_DAYS_OLDER = 30; + + public static final String PATH_TO_BY_DAYS_OLD_ARTIFACT = + "org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar"; + + public static final String PATH_TO_BY_DAYS_OLD_METADATA_DRIVEN_ARTIFACT = + "org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070113.163208-4.jar"; + + public static final String PATH_TO_BY_RETENTION_COUNT_ARTIFACT = + "org/jruby/plugins/jruby-rake-plugin/1.0RC1-SNAPSHOT/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar"; + + public static final String PATH_TO_BY_RETENTION_COUNT_POM = + "org/codehaus/castor/castor-anttasks/1.1.2-SNAPSHOT/castor-anttasks-1.1.2-20070506.163513-2.pom"; + + public static final String PATH_TO_TEST_ORDER_OF_DELETION = + "org/apache/maven/plugins/maven-assembly-plugin/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar"; + + protected static final String RELEASES_TEST_REPO_ID = "releases-test-repo-one"; + + protected static final String RELEASES_TEST_REPO_NAME = "Releases Test Repo One"; + + private ManagedRepository config; + + private ManagedRepositoryContent repo; + + protected RepositoryPurge repoPurge; + + protected MockControl listenerControl; + + protected RepositoryListener listener; + + protected RepositorySession repositorySession; + + protected MetadataRepository metadataRepository; + + @Inject + protected ApplicationContext applicationContext; + + @Before + public void setUp() + throws Exception + { + super.setUp(); + + listenerControl = MockControl.createControl( RepositoryListener.class ); + + listener = (RepositoryListener) listenerControl.getMock(); + + repositorySession = mock( RepositorySession.class ); + metadataRepository = mock( MetadataRepository.class ); + when( repositorySession.getRepository() ).thenReturn( metadataRepository ); + } + + @After + public void tearDown() + throws Exception + { + super.tearDown(); + config = null; + repo = null; + } + + public ManagedRepository getRepoConfiguration( String repoId, String repoName ) + { + config = new ManagedRepository(); + config.setId( repoId ); + config.setName( repoName ); + config.setDaysOlder( TEST_DAYS_OLDER ); + config.setLocation( new File( "target/test-" + getName() + "/" + repoId ).getAbsolutePath() ); + config.setReleases( true ); + config.setSnapshots( true ); + config.setDeleteReleasedSnapshots( true ); + config.setRetentionCount( TEST_RETENTION_COUNT ); + + return config; + } + + public ManagedRepositoryContent getRepository() + throws Exception + { + if ( repo == null ) + { + repo = applicationContext.getBean( "managedRepositoryContent#default", ManagedRepositoryContent.class ); + repo.setRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) ); + } + + return repo; + } + + protected void assertDeleted( String path ) + { + assertFalse( "File should have been deleted: " + path, new File( path ).exists() ); + } + + protected void assertExists( String path ) + { + assertTrue( "File should exist: " + path, new File( path ).exists() ); + } + + protected File getTestRepoRoot() + { + return new File( "target/test-" + getName() + "/" + TEST_REPO_ID ); + } + + protected String prepareTestRepos() + throws IOException + { + File testDir = getTestRepoRoot(); + FileUtils.deleteDirectory( testDir ); + FileUtils.copyDirectory( new File( "target/test-classes/" + TEST_REPO_ID ), testDir ); + + File releasesTestDir = new File( "target/test-" + getName() + "/" + RELEASES_TEST_REPO_ID ); + FileUtils.deleteDirectory( releasesTestDir ); + FileUtils.copyDirectory( new File( "target/test-classes/" + RELEASES_TEST_REPO_ID ), releasesTestDir ); + + return testDir.getAbsolutePath(); + } + + @Override + public String getName() + { + return StringUtils.substringAfterLast( getClass().getName(), "." ); + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java new file mode 100644 index 000000000..8b457af22 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java @@ -0,0 +1,295 @@ +package org.apache.archiva.consumers.core.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; +import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; +import org.apache.archiva.repository.events.RepositoryListener; +import org.apache.commons.io.FileUtils; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.archiva.repository.RepositoryContentFactory; +import org.apache.archiva.repository.metadata.MetadataTools; +import org.custommonkey.xmlunit.XMLAssert; +import org.easymock.MockControl; +import org.junit.Before; +import org.junit.Test; +import org.springframework.test.context.ContextConfiguration; + +import javax.inject.Inject; +import java.io.File; +import java.util.Collections; +import java.util.List; + + +/** + */ +@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", + "classpath:/spring-context-cleanup-released-snapshots.xml" } ) +public class CleanupReleasedSnapshotsRepositoryPurgeTest + extends AbstractRepositoryPurgeTest +{ + private static final String INDEX_PATH = ".index\\nexus-maven-repository-index.zip"; + + private ArchivaConfiguration archivaConfiguration; + + public static final String PATH_TO_RELEASED_SNAPSHOT_IN_DIFF_REPO = + "org/apache/archiva/released-artifact-in-diff-repo/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.jar"; + + public static final String PATH_TO_HIGHER_SNAPSHOT_EXISTS_IN_SAME_REPO = + "org/apache/maven/plugins/maven-source-plugin/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar"; + + public static final String PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO = + "org/apache/maven/plugins/maven-plugin-plugin/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar"; + + @Inject + MetadataTools metadataTools; + + @Before + public void setUp() + throws Exception + { + super.setUp(); + + RepositoryContentFactory factory = + applicationContext.getBean( "repositoryContentFactory#cleanup-released-snapshots", + RepositoryContentFactory.class ); + + archivaConfiguration = + applicationContext.getBean( "archivaConfiguration#cleanup-released-snapshots", ArchivaConfiguration.class ); + + listenerControl = MockControl.createControl( RepositoryListener.class ); + + listener = (RepositoryListener) listenerControl.getMock(); + List listeners = Collections.singletonList( listener ); + repoPurge = new CleanupReleasedSnapshotsRepositoryPurge( getRepository(), metadataTools, + applicationContext.getBean( + ManagedRepositoryAdmin.class ), factory, + repositorySession, listeners ); + + ( (DefaultManagedRepositoryAdmin) applicationContext.getBean( + ManagedRepositoryAdmin.class ) ).setArchivaConfiguration( archivaConfiguration ); + } + + @Test + public void testReleasedSnapshotsExistsInSameRepo() + throws Exception + { + /** + Configuration config = archivaConfiguration.getConfiguration(); + config.removeManagedRepository( config.findManagedRepositoryById( TEST_REPO_ID ) ); + config.addManagedRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) ); + **/ + + applicationContext.getBean( ManagedRepositoryAdmin.class ).deleteManagedRepository( TEST_REPO_ID, null, false ); + applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( + getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null ); + + String repoRoot = prepareTestRepos(); + + // test listeners for the correct artifacts + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", + "maven-plugin-plugin", "2.3-SNAPSHOT", "maven-plugin-plugin-2.3-SNAPSHOT.jar" ); + listenerControl.replay(); + + repoPurge.process( PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO ); + + listenerControl.verify(); + + String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-plugin-plugin"; + + // check if the snapshot was removed + assertDeleted( projectRoot + "/2.3-SNAPSHOT" ); + assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" ); + assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5" ); + assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1" ); + assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom" ); + assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5" ); + assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1" ); + + // check if the released version was not removed + assertExists( projectRoot + "/2.3" ); + assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3-sources.jar" ); + assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3-sources.jar.md5" ); + assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3-sources.jar.sha1" ); + assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3.jar" ); + assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3.jar.md5" ); + assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3.jar.sha1" ); + assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3.pom" ); + assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3.pom.md5" ); + assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3.pom.sha1" ); + + // check if metadata file was updated + File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" ); + + String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null ); + + String expectedVersions = + "2.2" + "2.3"; + + XMLAssert.assertXpathEvaluatesTo( "2.3", "//metadata/versioning/release", metadataXml ); + XMLAssert.assertXpathEvaluatesTo( "2.3", "//metadata/versioning/latest", metadataXml ); + XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions, + "//metadata/versioning/versions/version", metadataXml ); + XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml ); + } + + @Test + public void testNonArtifactFile() + throws Exception + { + /*Configuration config = archivaConfiguration.getConfiguration(); + config.removeManagedRepository( config.findManagedRepositoryById( TEST_REPO_ID ) ); + config.addManagedRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) );*/ + + applicationContext.getBean( ManagedRepositoryAdmin.class ).deleteManagedRepository( TEST_REPO_ID, null, false ); + applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( + getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null ); + + String repoRoot = prepareTestRepos(); + + // test listeners for the correct artifacts + listenerControl.replay(); + + File file = new File( repoRoot, INDEX_PATH ); + if ( !file.exists() ) + { + // help windauze to create directory with . + file.getParentFile().mkdirs(); + file.createNewFile(); + } + assertTrue( file.exists() ); + + repoPurge.process( INDEX_PATH ); + + listenerControl.verify(); + + assertTrue( file.exists() ); + } + + @Test + public void testReleasedSnapshotsExistsInDifferentRepo() + throws Exception + { + /* + Configuration config = archivaConfiguration.getConfiguration(); + config.removeManagedRepository( config.findManagedRepositoryById( TEST_REPO_ID ) ); + config.addManagedRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) ); + config.addManagedRepository( getRepoConfiguration( RELEASES_TEST_REPO_ID, RELEASES_TEST_REPO_NAME ) ); + */ + applicationContext.getBean( ManagedRepositoryAdmin.class ).deleteManagedRepository( TEST_REPO_ID, null, false ); + applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( + getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null ); + + applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( + getRepoConfiguration( RELEASES_TEST_REPO_ID, RELEASES_TEST_REPO_NAME ), false, null ); + + String repoRoot = prepareTestRepos(); + + // test listeners for the correct artifacts + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.archiva", + "released-artifact-in-diff-repo", "1.0-SNAPSHOT", + "released-artifact-in-diff-repo-1.0-SNAPSHOT.jar" ); + listenerControl.replay(); + + repoPurge.process( PATH_TO_RELEASED_SNAPSHOT_IN_DIFF_REPO ); + + listenerControl.verify(); + + String projectRoot = repoRoot + "/org/apache/archiva/released-artifact-in-diff-repo"; + + // check if the snapshot was removed + assertDeleted( projectRoot + "/1.0-SNAPSHOT" ); + assertDeleted( projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.jar" ); + assertDeleted( projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.jar.md5" ); + assertDeleted( projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.jar.sha1" ); + assertDeleted( projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.pom" ); + assertDeleted( projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.pom.md5" ); + assertDeleted( projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.pom.sha1" ); + + String releasesProjectRoot = + new File( "target/test-" + getName() + "/releases-test-repo-one" ).getAbsolutePath() + + "/org/apache/archiva/released-artifact-in-diff-repo"; + + // check if the released version was not removed + assertExists( releasesProjectRoot + "/1.0" ); + assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.jar" ); + assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.jar.md5" ); + assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.jar.sha1" ); + assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.pom" ); + assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.pom.md5" ); + assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.pom.sha1" ); + } + + @Test + public void testHigherSnapshotExistsInSameRepo() + throws Exception + { + /* + Configuration config = archivaConfiguration.getConfiguration(); + config.removeManagedRepository( config.findManagedRepositoryById( TEST_REPO_ID ) ); + config.addManagedRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) ); + */ + applicationContext.getBean( ManagedRepositoryAdmin.class ).deleteManagedRepository( TEST_REPO_ID, null, false ); + applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( + getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null ); + + String repoRoot = prepareTestRepos(); + + // test listeners for the correct artifacts - no deletions + listenerControl.replay(); + + repoPurge.process( CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_HIGHER_SNAPSHOT_EXISTS_IN_SAME_REPO ); + + listenerControl.verify(); + + String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-source-plugin"; + + // check if the snapshot was not removed + assertExists( projectRoot + "/2.0.3-SNAPSHOT" ); + assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar" ); + assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar.md5" ); + assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar.sha1" ); + assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom" ); + assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom.md5" ); + assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom.sha1" ); + + // check if the released version was not removed + assertExists( projectRoot + "/2.0.4-SNAPSHOT" ); + assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.jar" ); + assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.jar.md5" ); + assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.jar.sha1" ); + assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom" ); + assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom.md5" ); + assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom.sha1" ); + + // check if metadata file was not updated (because nothing was removed) + File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" ); + + String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null ); + + String expectedVersions = "2.0.3-SNAPSHOT" + + "2.0.4-SNAPSHOT"; + + XMLAssert.assertXpathEvaluatesTo( "2.0.4-SNAPSHOT", "//metadata/versioning/latest", metadataXml ); + XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions, + "//metadata/versioning/versions/version", metadataXml ); + XMLAssert.assertXpathEvaluatesTo( "20070427033345", "//metadata/versioning/lastUpdated", metadataXml ); + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java new file mode 100644 index 000000000..0f846983d --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java @@ -0,0 +1,233 @@ +package org.apache.archiva.consumers.core.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.repository.events.RepositoryListener; +import org.apache.commons.lang.time.DateUtils; +import org.junit.After; +import org.junit.Test; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Collections; +import java.util.List; + +/** + */ +public class DaysOldRepositoryPurgeTest + extends AbstractRepositoryPurgeTest +{ + private static final int OLD_TIMESTAMP = 1179382029; + + private void setLastModified( String dirPath, long lastModified ) + { + File dir = new File( dirPath ); + File[] contents = dir.listFiles(); + for ( File content : contents ) + { + content.setLastModified( lastModified ); + } + } + + @Test + public void testByLastModified() + throws Exception + { + ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + repoPurge = new DaysOldRepositoryPurge( getRepository(), repoConfiguration.getDaysOlder(), + repoConfiguration.getRetentionCount(), repositorySession, + Collections.singletonList( listener ) ); + + String repoRoot = prepareTestRepos(); + + String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-install-plugin"; + + setLastModified( projectRoot + "/2.2-SNAPSHOT/", OLD_TIMESTAMP ); + + // test listeners for the correct artifacts + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", + "maven-install-plugin", "2.2-SNAPSHOT", "maven-install-plugin-2.2-SNAPSHOT.jar" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", + "maven-install-plugin", "2.2-SNAPSHOT", "maven-install-plugin-2.2-SNAPSHOT.pom" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", + "maven-install-plugin", "2.2-20061118.060401-2", + "maven-install-plugin-2.2-20061118.060401-2.jar" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", + "maven-install-plugin", "2.2-20061118.060401-2", + "maven-install-plugin-2.2-20061118.060401-2.pom" ); + listenerControl.replay(); + + repoPurge.process( PATH_TO_BY_DAYS_OLD_ARTIFACT ); + + listenerControl.verify(); + + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.md5" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.sha1" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.md5" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.sha1" ); + + // shouldn't be deleted because even if older than 30 days (because retention count = 2) + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.md5" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.sha1" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.md5" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.sha1" ); + + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.md5" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.sha1" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.md5" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.sha1" ); + + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.md5" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.sha1" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.md5" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.sha1" ); + } + + @Test + public void testOrderOfDeletion() + throws Exception + { + ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + List listeners = Collections.singletonList( listener ); + repoPurge = new DaysOldRepositoryPurge( getRepository(), repoConfiguration.getDaysOlder(), + repoConfiguration.getRetentionCount(), repositorySession, listeners ); + + String repoRoot = prepareTestRepos(); + + String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-assembly-plugin"; + + setLastModified( projectRoot + "/1.1.2-SNAPSHOT/", OLD_TIMESTAMP ); + + // test listeners for the correct artifacts + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", + "maven-assembly-plugin", "1.1.2-20070427.065136-1", + "maven-assembly-plugin-1.1.2-20070427.065136-1.jar" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", + "maven-assembly-plugin", "1.1.2-20070427.065136-1", + "maven-assembly-plugin-1.1.2-20070427.065136-1.pom" ); + listenerControl.replay(); + + repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION ); + + listenerControl.verify(); + + assertDeleted( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.jar" ); + assertDeleted( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.sha1" ); + assertDeleted( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.md5" ); + assertDeleted( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.pom" ); + assertDeleted( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.sha1" ); + assertDeleted( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.md5" ); + + // the following should not have been deleted + assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.jar" ); + assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.sha1" ); + assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.md5" ); + assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.pom" ); + assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.sha1" ); + assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.md5" ); + + assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar" ); + assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.sha1" ); + assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.md5" ); + assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom" ); + assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.sha1" ); + assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.md5" ); + } + + @Test + public void testMetadataDrivenSnapshots() + throws Exception + { + ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + List listeners = Collections.singletonList( listener ); + repoPurge = new DaysOldRepositoryPurge( getRepository(), repoConfiguration.getDaysOlder(), + repoConfiguration.getRetentionCount(), repositorySession, listeners ); + + String repoRoot = prepareTestRepos(); + + String versionRoot = repoRoot + "/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT"; + + Calendar currentDate = Calendar.getInstance( DateUtils.UTC_TIME_ZONE ); + setLastModified( versionRoot, currentDate.getTimeInMillis() ); + + String timestamp = new SimpleDateFormat( "yyyyMMdd.HHmmss" ).format( currentDate.getTime() ); + + for ( int i = 5; i <= 7; i++ ) + { + File jarFile = new File( versionRoot, "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".jar" ); + jarFile.createNewFile(); + File pomFile = new File( versionRoot, "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".pom" ); + pomFile.createNewFile(); + + // set timestamp to older than 100 days for the first build, but ensure the filename timestamp is honoured instead + if ( i == 5 ) + { + jarFile.setLastModified( OLD_TIMESTAMP ); + pomFile.setLastModified( OLD_TIMESTAMP ); + } + } + + // test listeners for the correct artifacts + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.plexus", "plexus-utils", + "1.4.3-20070113.163208-4", "plexus-utils-1.4.3-20070113.163208-4.jar" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.plexus", "plexus-utils", + "1.4.3-20070113.163208-4", "plexus-utils-1.4.3-20070113.163208-4.pom" ); + listenerControl.replay(); + + repoPurge.process( PATH_TO_BY_DAYS_OLD_METADATA_DRIVEN_ARTIFACT ); + + listenerControl.verify(); + + // this should be deleted since the filename version (timestamp) is older than + // 100 days even if the last modified date was <100 days ago + assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.jar" ); + assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.jar.sha1" ); + assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.pom" ); + assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.pom.sha1" ); + + // this should not be deleted because last modified date is <100 days ago + assertExists( versionRoot + "/plexus-utils-1.4.3-SNAPSHOT.jar" ); + assertExists( versionRoot + "/plexus-utils-1.4.3-SNAPSHOT.pom" ); + + for ( int i = 5; i <= 7; i++ ) + { + assertExists( versionRoot + "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".jar" ); + assertExists( versionRoot + "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".pom" ); + } + } + + @After + public void tearDown() + throws Exception + { + super.tearDown(); + repoPurge = null; + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java new file mode 100644 index 000000000..6c6c37f1c --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java @@ -0,0 +1,373 @@ +package org.apache.archiva.consumers.core.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; +import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; +import org.apache.archiva.metadata.repository.TestRepositorySessionFactory; +import org.apache.commons.io.FileUtils; +import org.apache.archiva.common.utils.BaseFile; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.FileType; +import org.apache.maven.archiva.configuration.FileTypes; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate; +import org.custommonkey.xmlunit.XMLAssert; +import org.junit.Before; +import org.junit.Test; +import org.springframework.test.context.ContextConfiguration; + +import java.io.File; + +/** + */ +@ContextConfiguration( + locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-purge-consumer-test.xml" } ) +public class RepositoryPurgeConsumerTest + extends AbstractRepositoryPurgeTest +{ + @Before + public void setUp() + throws Exception + { + super.setUp(); + + TestRepositorySessionFactory factory = applicationContext.getBean( TestRepositorySessionFactory.class ); + factory.setRepository( metadataRepository ); + } + + @Test + public void testConsumption() + throws Exception + { + assertNotConsumed( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" ); + cleanupFileTypes(); + } + + @Test + public void testConsumptionOfOtherMetadata() + throws Exception + { + assertNotConsumed( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata-central.xml" ); + cleanupFileTypes(); + } + + private void cleanupFileTypes() + { + ArchivaConfiguration archivaConfiguration = + applicationContext.getBean( "archivaConfiguration#default", ArchivaConfiguration.class ); + + FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 ); + fileType.removePattern( "**/*.xml" ); + } + + private void assertNotConsumed( String path ) + throws Exception + { + ArchivaConfiguration archivaConfiguration = + applicationContext.getBean( "archivaConfiguration#default", ArchivaConfiguration.class ); + + FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 ); + assertEquals( FileTypes.ARTIFACTS, fileType.getId() ); + fileType.addPattern( "**/*.xml" ); + + // trigger reload + //FileTypes fileTypes = applicationContext.getBean( FileTypes.class ); + for ( FileTypes fileTypes : applicationContext.getBeansOfType( FileTypes.class ).values() ) + { + fileTypes.afterConfigurationChange( null, "repositoryScanning.fileTypes", null ); + } + KnownRepositoryContentConsumer repoPurgeConsumer = + applicationContext.getBean( "knownRepositoryContentConsumer#repository-purge", + KnownRepositoryContentConsumer.class ); + + File repoLocation = new File( "target/test-" + getName() + "/test-repo" ); + + File localFile = new File( repoLocation, path ); + + ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate(); + BaseFile baseFile = new BaseFile( repoLocation, localFile ); + predicate.setBasefile( baseFile ); + + assertFalse( predicate.evaluate( repoPurgeConsumer ) ); + } + + private void setLastModified( String path ) + { + File dir = new File( path ); + File[] contents = dir.listFiles(); + for ( int i = 0; i < contents.length; i++ ) + { + contents[i].setLastModified( 1179382029 ); + } + } + + @Test + public void testConsumerByRetentionCount() + throws Exception + { + KnownRepositoryContentConsumer repoPurgeConsumer = + applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count", + KnownRepositoryContentConsumer.class ); + + ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + repoConfiguration.setDaysOlder( 0 ); // force days older off to allow retention count purge to execute. + repoConfiguration.setRetentionCount( TEST_RETENTION_COUNT ); + addRepoToConfiguration( "retention-count", repoConfiguration ); + + repoPurgeConsumer.beginScan( repoConfiguration, null ); + + String repoRoot = prepareTestRepos(); + + repoPurgeConsumer.processFile( PATH_TO_BY_RETENTION_COUNT_ARTIFACT ); + + String versionRoot = repoRoot + "/org/jruby/plugins/jruby-rake-plugin/1.0RC1-SNAPSHOT"; + + // assert if removed from repo + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.md5" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.sha1" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.md5" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.sha1" ); + + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.md5" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.sha1" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.md5" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.sha1" ); + + // assert if not removed from repo + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.md5" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.sha1" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.md5" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.sha1" ); + + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.md5" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.sha1" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.md5" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.sha1" ); + + removeRepoFromConfiguration( "retention-count", repoConfiguration ); + } + + private void addRepoToConfiguration( String configHint, ManagedRepository repoConfiguration ) + throws Exception + { + ArchivaConfiguration archivaConfiguration = + applicationContext.getBean( "archivaConfiguration#" + configHint, ArchivaConfiguration.class ); + ( (DefaultManagedRepositoryAdmin) applicationContext.getBean( + ManagedRepositoryAdmin.class ) ).setArchivaConfiguration( archivaConfiguration ); + /** + Configuration configuration = archivaConfiguration.getConfiguration(); + ManagedRepositoryConfiguration managedRepositoryConfiguration = + configuration.findManagedRepositoryById( repoConfiguration.getId() ); + if ( managedRepositoryConfiguration != null ) + { + configuration.removeManagedRepository( managedRepositoryConfiguration ); + } + configuration.addManagedRepository( repoConfiguration ); + **/ + ManagedRepositoryAdmin managedRepositoryAdmin = applicationContext.getBean( ManagedRepositoryAdmin.class ); + if ( managedRepositoryAdmin.getManagedRepository( repoConfiguration.getId() ) != null ) + { + managedRepositoryAdmin.deleteManagedRepository( repoConfiguration.getId(), null, false ); + } + managedRepositoryAdmin.addManagedRepository( repoConfiguration, false, null ); + } + + private void removeRepoFromConfiguration( String configHint, ManagedRepository repoConfiguration ) + throws Exception + { + ArchivaConfiguration archivaConfiguration = + applicationContext.getBean( "archivaConfiguration#" + configHint, ArchivaConfiguration.class ); + + ( (DefaultManagedRepositoryAdmin) applicationContext.getBean( + ManagedRepositoryAdmin.class ) ).setArchivaConfiguration( archivaConfiguration ); + /** + Configuration configuration = archivaConfiguration.getConfiguration(); + ManagedRepositoryConfiguration managedRepositoryConfiguration = + configuration.findManagedRepositoryById( repoConfiguration.getId() ); + if ( managedRepositoryConfiguration != null ) + { + configuration.removeManagedRepository( managedRepositoryConfiguration ); + }*/ + ManagedRepositoryAdmin managedRepositoryAdmin = applicationContext.getBean( ManagedRepositoryAdmin.class ); + if ( managedRepositoryAdmin.getManagedRepository( repoConfiguration.getId() ) != null ) + { + managedRepositoryAdmin.deleteManagedRepository( repoConfiguration.getId(), null, true ); + } + } + + @Test + public void testConsumerByDaysOld() + throws Exception + { + KnownRepositoryContentConsumer repoPurgeConsumer = + applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-days-old", + KnownRepositoryContentConsumer.class ); + + ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + repoConfiguration.setDaysOlder( TEST_DAYS_OLDER ); + addRepoToConfiguration( "days-old", repoConfiguration ); + + repoPurgeConsumer.beginScan( repoConfiguration, null ); + + String repoRoot = prepareTestRepos(); + String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-install-plugin"; + + setLastModified( projectRoot + "/2.2-SNAPSHOT" ); + + repoPurgeConsumer.processFile( PATH_TO_BY_DAYS_OLD_ARTIFACT ); + + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.md5" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.sha1" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.md5" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.sha1" ); + + // shouldn't be deleted because even if older than 30 days (because retention count = 2) + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.md5" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.sha1" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.md5" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.sha1" ); + + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.md5" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.sha1" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.md5" ); + assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.sha1" ); + + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.md5" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.sha1" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.md5" ); + assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.sha1" ); + + removeRepoFromConfiguration( "days-old", repoConfiguration ); + } + + /** + * Test the snapshot clean consumer on a repository set to NOT clean/delete snapshots based on released versions. + * + * @throws Exception + */ + @Test + public void testReleasedSnapshotsWereNotCleaned() + throws Exception + { + KnownRepositoryContentConsumer repoPurgeConsumer = + applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count", + KnownRepositoryContentConsumer.class ); + + ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + repoConfiguration.setDeleteReleasedSnapshots( false ); // Set to NOT delete released snapshots. + addRepoToConfiguration( "retention-count", repoConfiguration ); + + repoPurgeConsumer.beginScan( repoConfiguration, null ); + + String repoRoot = prepareTestRepos(); + + repoPurgeConsumer.processFile( + CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO ); + + // check if the snapshot wasn't removed + String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-plugin-plugin"; + + assertExists( projectRoot + "/2.3-SNAPSHOT" ); + assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" ); + assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5" ); + assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1" ); + assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom" ); + assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5" ); + assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1" ); + + // check if metadata file wasn't updated + File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" ); + + String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null ); + + String expectedVersions = "2.3-SNAPSHOT"; + + XMLAssert.assertXpathEvaluatesTo( "2.3-SNAPSHOT", "//metadata/versioning/latest", metadataXml ); + XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions, + "//metadata/versioning/versions/version", metadataXml ); + XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml ); + + removeRepoFromConfiguration( "retention-count", repoConfiguration ); + } + + @Test + public void testReleasedSnapshotsWereCleaned() + throws Exception + { + KnownRepositoryContentConsumer repoPurgeConsumer = + applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-days-old", + KnownRepositoryContentConsumer.class ); + + ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + repoConfiguration.setDeleteReleasedSnapshots( true ); + addRepoToConfiguration( "days-old", repoConfiguration ); + + repoPurgeConsumer.beginScan( repoConfiguration, null ); + + String repoRoot = prepareTestRepos(); + + repoPurgeConsumer.processFile( + CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO ); + + String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-plugin-plugin"; + + // check if the snapshot was removed + assertDeleted( projectRoot + "/2.3-SNAPSHOT" ); + assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" ); + assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5" ); + assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1" ); + assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom" ); + assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5" ); + assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1" ); + + // check if metadata file was updated + File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" ); + + String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null ); + + String expectedVersions = + "2.2" + "2.3"; + + XMLAssert.assertXpathEvaluatesTo( "2.3", "//metadata/versioning/latest", metadataXml ); + XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions, + "//metadata/versioning/versions/version", metadataXml ); + XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml ); + + removeRepoFromConfiguration( "days-old", repoConfiguration ); + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java new file mode 100644 index 000000000..fa3805792 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java @@ -0,0 +1,200 @@ +package org.apache.archiva.consumers.core.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.repository.events.RepositoryListener; +import org.junit.Before; +import org.junit.Test; + +import java.util.Collections; +import java.util.List; + +/** + * Test RetentionsCountRepositoryPurgeTest + */ +public class RetentionCountRepositoryPurgeTest + extends AbstractRepositoryPurgeTest +{ + @Before + public void setUp() + throws Exception + { + super.setUp(); + + ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); + List listeners = Collections.singletonList( listener ); + repoPurge = new RetentionCountRepositoryPurge( getRepository(), repoConfiguration.getRetentionCount(), + repositorySession, listeners ); + } + + /** + * Test if the artifact to be processed was a jar. + */ + @Test + public void testIfAJarWasFound() + throws Exception + { + String repoRoot = prepareTestRepos(); + + // test listeners for the correct artifacts + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", + "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", + "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", + "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", + "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" ); + listenerControl.replay(); + + repoPurge.process( PATH_TO_BY_RETENTION_COUNT_ARTIFACT ); + + listenerControl.verify(); + + String versionRoot = repoRoot + "/org/jruby/plugins/jruby-rake-plugin/1.0RC1-SNAPSHOT"; + + // assert if removed from repo + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.md5" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.sha1" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.md5" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.sha1" ); + + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.md5" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.sha1" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.md5" ); + assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.sha1" ); + + // assert if not removed from repo + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.md5" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.sha1" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.md5" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.sha1" ); + + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.md5" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.sha1" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.md5" ); + assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.sha1" ); + } + + /** + * Test if the artifact to be processed is a pom + */ + @Test + public void testIfAPomWasFound() + throws Exception + { + String repoRoot = prepareTestRepos(); + + // test listeners for the correct artifacts + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks", + "1.1.2-20070427.065136-1", "castor-anttasks-1.1.2-20070427.065136-1.jar" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks", + "1.1.2-20070427.065136-1", "castor-anttasks-1.1.2-20070427.065136-1.pom" ); + listenerControl.replay(); + + repoPurge.process( PATH_TO_BY_RETENTION_COUNT_POM ); + + listenerControl.verify(); + + String versionRoot = repoRoot + "/org/codehaus/castor/castor-anttasks/1.1.2-SNAPSHOT"; + + // assert if removed from repo + assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar" ); + assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.md5" ); + assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.sha1" ); + assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom" ); + assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom.md5" ); + assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom.sha1" ); + + // assert if not removed from repo + assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom" ); + assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom.md5" ); + assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom.sha1" ); + assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar" ); + assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar.md5" ); + assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar.sha1" ); + assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar" ); + assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar.md5" ); + assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar.sha1" ); + + assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom" ); + assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom.md5" ); + assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom.sha1" ); + assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar" ); + assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar.md5" ); + assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar.sha1" ); + assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar" ); + assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.md5" ); + assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.sha1" ); + } + + @Test + public void testOrderOfDeletion() + throws Exception + { + String repoRoot = prepareTestRepos(); + + // test listeners for the correct artifacts + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", + "maven-assembly-plugin", "1.1.2-20070427.065136-1", + "maven-assembly-plugin-1.1.2-20070427.065136-1.jar" ); + listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", + "maven-assembly-plugin", "1.1.2-20070427.065136-1", + "maven-assembly-plugin-1.1.2-20070427.065136-1.pom" ); + listenerControl.replay(); + + repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION ); + + listenerControl.verify(); + + String versionRoot = repoRoot + "/org/apache/maven/plugins/maven-assembly-plugin/1.1.2-SNAPSHOT"; + + assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar" ); + assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.sha1" ); + assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.md5" ); + assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom" ); + assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.sha1" ); + assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.md5" ); + + // the following should not have been deleted + assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar" ); + assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.sha1" ); + assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.md5" ); + assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom" ); + assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.sha1" ); + assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.md5" ); + + assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar" ); + assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.sha1" ); + assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.md5" ); + assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom" ); + assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.sha1" ); + assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.md5" ); + } +} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/AbstractArtifactConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/AbstractArtifactConsumerTest.java deleted file mode 100644 index 3a4316e8a..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/AbstractArtifactConsumerTest.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.apache.maven.archiva.consumers.core; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import junit.framework.TestCase; -import org.apache.archiva.common.utils.BaseFile; -import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.FileType; -import org.apache.maven.archiva.configuration.FileTypes; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.functors.ConsumerWantsFilePredicate; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.context.ApplicationContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import javax.inject.Inject; -import java.io.File; - -@RunWith( SpringJUnit4ClassRunner.class ) -@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} ) -public abstract class AbstractArtifactConsumerTest - extends TestCase -{ - private File repoLocation; - - protected KnownRepositoryContentConsumer consumer; - - @Inject - protected ApplicationContext applicationContext; - - @Inject - ArchivaConfiguration archivaConfiguration; - - @Before - public void setUp() - throws Exception - { - super.setUp(); - - FileType fileType = - (FileType) archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 ); - assertEquals( FileTypes.ARTIFACTS, fileType.getId() ); - fileType.addPattern( "**/*.xml" ); - - repoLocation = new File( "target/test-" + getName() + "/test-repo" ); - } - - @Test - public void testConsumption() - { - File localFile = - new File( repoLocation, "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" ); - - ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate(); - BaseFile baseFile = new BaseFile( repoLocation, localFile ); - predicate.setBasefile( baseFile ); - - assertFalse( predicate.evaluate( consumer ) ); - } - - @Test - public void testConsumptionOfOtherMetadata() - { - File localFile = - new File( repoLocation, "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata-central.xml" ); - - ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate(); - BaseFile baseFile = new BaseFile( repoLocation, localFile ); - predicate.setBasefile( baseFile ); - - assertFalse( predicate.evaluate( consumer ) ); - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java deleted file mode 100644 index 83672928a..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.apache.maven.archiva.consumers.core; - -import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.archiva.checksum.ChecksumAlgorithm; -import org.apache.archiva.checksum.ChecksummedFile; -import org.apache.commons.io.FileUtils; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.junit.Before; -import org.junit.Test; - -import java.io.File; -import java.util.Calendar; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -public class ArtifactMissingChecksumsConsumerTest - extends AbstractArtifactConsumerTest -{ - private ManagedRepository repoConfig; - - @Before - public void setUp() - throws Exception - { - super.setUp(); - - repoConfig = new ManagedRepository(); - repoConfig.setId( "test-repo" ); - repoConfig.setName( "Test Repository" ); - repoConfig.setLayout( "default" ); - repoConfig.setLocation( new File( "target/test-classes/test-repo/" ).getPath() ); - - consumer = applicationContext.getBean( "knownRepositoryContentConsumer#artifact-missing-checksums-consumer", - KnownRepositoryContentConsumer.class ); - } - - @Test - public void testNoExistingChecksums() - throws Exception - { - String path = "/no-checksums-artifact/1.0/no-checksums-artifact-1.0.jar"; - - File sha1File = new File( repoConfig.getLocation(), path + ".sha1" ); - File md5File = new File( repoConfig.getLocation(), path + ".md5" ); - - sha1File.delete(); - md5File.delete(); - - assertFalse( sha1File.exists() ); - assertFalse( md5File.exists() ); - - consumer.beginScan( repoConfig, Calendar.getInstance().getTime() ); - - consumer.processFile( path ); - - assertTrue( sha1File.exists() ); - assertTrue( md5File.exists() ); - } - - @Test - public void testExistingIncorrectChecksums() - throws Exception - { - File newLocation = new File( "target/test-repo" ); - FileUtils.deleteDirectory( newLocation ); - FileUtils.copyDirectory( new File( repoConfig.getLocation() ), newLocation ); - repoConfig.setLocation( newLocation.getAbsolutePath() ); - - String path = "/incorrect-checksums/1.0/incorrect-checksums-1.0.jar"; - - File sha1File = new File( repoConfig.getLocation(), path + ".sha1" ); - File md5File = new File( repoConfig.getLocation(), path + ".md5" ); - - ChecksummedFile checksum = new ChecksummedFile( new File( repoConfig.getLocation(), path ) ); - - assertTrue( sha1File.exists() ); - assertTrue( md5File.exists() ); - assertFalse( checksum.isValidChecksums( new ChecksumAlgorithm[] { ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1 } ) ); - - consumer.beginScan( repoConfig, Calendar.getInstance().getTime() ); - - consumer.processFile( path ); - - assertTrue( sha1File.exists() ); - assertTrue( md5File.exists() ); - assertTrue( checksum.isValidChecksums( new ChecksumAlgorithm[] { ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1 } ) ); - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/MetadataUpdateConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/MetadataUpdateConsumerTest.java deleted file mode 100644 index 991291f64..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/MetadataUpdateConsumerTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apache.maven.archiva.consumers.core; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.junit.Before; - -public class MetadataUpdateConsumerTest - extends AbstractArtifactConsumerTest -{ - @Before - public void setUp() - throws Exception - { - super.setUp(); - consumer = applicationContext.getBean( "knownRepositoryContentConsumer#metadata-updater", - KnownRepositoryContentConsumer.class ); - } -} \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java deleted file mode 100644 index c4c923661..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java +++ /dev/null @@ -1,181 +0,0 @@ -package org.apache.maven.archiva.consumers.core.repository; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import junit.framework.TestCase; -import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.archiva.metadata.repository.MetadataRepository; -import org.apache.archiva.metadata.repository.RepositorySession; -import org.apache.archiva.repository.events.RepositoryListener; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.archiva.repository.ManagedRepositoryContent; -import org.easymock.MockControl; -import org.junit.After; -import org.junit.Before; -import org.junit.runner.RunWith; -import org.springframework.context.ApplicationContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import javax.inject.Inject; -import java.io.File; -import java.io.IOException; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -/** - */ -@RunWith( SpringJUnit4ClassRunner.class ) -@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) -public abstract class AbstractRepositoryPurgeTest - extends TestCase -{ - public static final String TEST_REPO_ID = "test-repo"; - - public static final String TEST_REPO_NAME = "Test Repository"; - - public static final int TEST_RETENTION_COUNT = 2; - - public static final int TEST_DAYS_OLDER = 30; - - public static final String PATH_TO_BY_DAYS_OLD_ARTIFACT = - "org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar"; - - public static final String PATH_TO_BY_DAYS_OLD_METADATA_DRIVEN_ARTIFACT = - "org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070113.163208-4.jar"; - - public static final String PATH_TO_BY_RETENTION_COUNT_ARTIFACT = - "org/jruby/plugins/jruby-rake-plugin/1.0RC1-SNAPSHOT/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar"; - - public static final String PATH_TO_BY_RETENTION_COUNT_POM = - "org/codehaus/castor/castor-anttasks/1.1.2-SNAPSHOT/castor-anttasks-1.1.2-20070506.163513-2.pom"; - - public static final String PATH_TO_TEST_ORDER_OF_DELETION = - "org/apache/maven/plugins/maven-assembly-plugin/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar"; - - protected static final String RELEASES_TEST_REPO_ID = "releases-test-repo-one"; - - protected static final String RELEASES_TEST_REPO_NAME = "Releases Test Repo One"; - - private ManagedRepository config; - - private ManagedRepositoryContent repo; - - protected RepositoryPurge repoPurge; - - protected MockControl listenerControl; - - protected RepositoryListener listener; - - protected RepositorySession repositorySession; - - protected MetadataRepository metadataRepository; - - @Inject - protected ApplicationContext applicationContext; - - @Before - public void setUp() - throws Exception - { - super.setUp(); - - listenerControl = MockControl.createControl( RepositoryListener.class ); - - listener = (RepositoryListener) listenerControl.getMock(); - - repositorySession = mock( RepositorySession.class ); - metadataRepository = mock( MetadataRepository.class ); - when( repositorySession.getRepository() ).thenReturn( metadataRepository ); - } - - @After - public void tearDown() - throws Exception - { - super.tearDown(); - config = null; - repo = null; - } - - public ManagedRepository getRepoConfiguration( String repoId, String repoName ) - { - config = new ManagedRepository(); - config.setId( repoId ); - config.setName( repoName ); - config.setDaysOlder( TEST_DAYS_OLDER ); - config.setLocation( new File( "target/test-" + getName() + "/" + repoId ).getAbsolutePath() ); - config.setReleases( true ); - config.setSnapshots( true ); - config.setDeleteReleasedSnapshots( true ); - config.setRetentionCount( TEST_RETENTION_COUNT ); - - return config; - } - - public ManagedRepositoryContent getRepository() - throws Exception - { - if ( repo == null ) - { - repo = applicationContext.getBean( "managedRepositoryContent#default", ManagedRepositoryContent.class ); - repo.setRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) ); - } - - return repo; - } - - protected void assertDeleted( String path ) - { - assertFalse( "File should have been deleted: " + path, new File( path ).exists() ); - } - - protected void assertExists( String path ) - { - assertTrue( "File should exist: " + path, new File( path ).exists() ); - } - - protected File getTestRepoRoot() - { - return new File( "target/test-" + getName() + "/" + TEST_REPO_ID ); - } - - protected String prepareTestRepos() - throws IOException - { - File testDir = getTestRepoRoot(); - FileUtils.deleteDirectory( testDir ); - FileUtils.copyDirectory( new File( "target/test-classes/" + TEST_REPO_ID ), testDir ); - - File releasesTestDir = new File( "target/test-" + getName() + "/" + RELEASES_TEST_REPO_ID ); - FileUtils.deleteDirectory( releasesTestDir ); - FileUtils.copyDirectory( new File( "target/test-classes/" + RELEASES_TEST_REPO_ID ), releasesTestDir ); - - return testDir.getAbsolutePath(); - } - - @Override - public String getName() - { - return StringUtils.substringAfterLast( getClass().getName(), "." ); - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java deleted file mode 100644 index 7d378f13c..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java +++ /dev/null @@ -1,295 +0,0 @@ -package org.apache.maven.archiva.consumers.core.repository; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; -import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; -import org.apache.archiva.repository.events.RepositoryListener; -import org.apache.commons.io.FileUtils; -import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.archiva.repository.RepositoryContentFactory; -import org.apache.archiva.repository.metadata.MetadataTools; -import org.custommonkey.xmlunit.XMLAssert; -import org.easymock.MockControl; -import org.junit.Before; -import org.junit.Test; -import org.springframework.test.context.ContextConfiguration; - -import javax.inject.Inject; -import java.io.File; -import java.util.Collections; -import java.util.List; - - -/** - */ -@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", - "classpath:/spring-context-cleanup-released-snapshots.xml" } ) -public class CleanupReleasedSnapshotsRepositoryPurgeTest - extends AbstractRepositoryPurgeTest -{ - private static final String INDEX_PATH = ".index\\nexus-maven-repository-index.zip"; - - private ArchivaConfiguration archivaConfiguration; - - public static final String PATH_TO_RELEASED_SNAPSHOT_IN_DIFF_REPO = - "org/apache/archiva/released-artifact-in-diff-repo/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.jar"; - - public static final String PATH_TO_HIGHER_SNAPSHOT_EXISTS_IN_SAME_REPO = - "org/apache/maven/plugins/maven-source-plugin/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar"; - - public static final String PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO = - "org/apache/maven/plugins/maven-plugin-plugin/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar"; - - @Inject - MetadataTools metadataTools; - - @Before - public void setUp() - throws Exception - { - super.setUp(); - - RepositoryContentFactory factory = - applicationContext.getBean( "repositoryContentFactory#cleanup-released-snapshots", - RepositoryContentFactory.class ); - - archivaConfiguration = - applicationContext.getBean( "archivaConfiguration#cleanup-released-snapshots", ArchivaConfiguration.class ); - - listenerControl = MockControl.createControl( RepositoryListener.class ); - - listener = (RepositoryListener) listenerControl.getMock(); - List listeners = Collections.singletonList( listener ); - repoPurge = new CleanupReleasedSnapshotsRepositoryPurge( getRepository(), metadataTools, - applicationContext.getBean( - ManagedRepositoryAdmin.class ), factory, - repositorySession, listeners ); - - ( (DefaultManagedRepositoryAdmin) applicationContext.getBean( - ManagedRepositoryAdmin.class ) ).setArchivaConfiguration( archivaConfiguration ); - } - - @Test - public void testReleasedSnapshotsExistsInSameRepo() - throws Exception - { - /** - Configuration config = archivaConfiguration.getConfiguration(); - config.removeManagedRepository( config.findManagedRepositoryById( TEST_REPO_ID ) ); - config.addManagedRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) ); - **/ - - applicationContext.getBean( ManagedRepositoryAdmin.class ).deleteManagedRepository( TEST_REPO_ID, null, false ); - applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( - getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null ); - - String repoRoot = prepareTestRepos(); - - // test listeners for the correct artifacts - listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", - "maven-plugin-plugin", "2.3-SNAPSHOT", "maven-plugin-plugin-2.3-SNAPSHOT.jar" ); - listenerControl.replay(); - - repoPurge.process( PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO ); - - listenerControl.verify(); - - String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-plugin-plugin"; - - // check if the snapshot was removed - assertDeleted( projectRoot + "/2.3-SNAPSHOT" ); - assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" ); - assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5" ); - assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1" ); - assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom" ); - assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5" ); - assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1" ); - - // check if the released version was not removed - assertExists( projectRoot + "/2.3" ); - assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3-sources.jar" ); - assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3-sources.jar.md5" ); - assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3-sources.jar.sha1" ); - assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3.jar" ); - assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3.jar.md5" ); - assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3.jar.sha1" ); - assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3.pom" ); - assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3.pom.md5" ); - assertExists( projectRoot + "/2.3/maven-plugin-plugin-2.3.pom.sha1" ); - - // check if metadata file was updated - File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" ); - - String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null ); - - String expectedVersions = - "2.2" + "2.3"; - - XMLAssert.assertXpathEvaluatesTo( "2.3", "//metadata/versioning/release", metadataXml ); - XMLAssert.assertXpathEvaluatesTo( "2.3", "//metadata/versioning/latest", metadataXml ); - XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions, - "//metadata/versioning/versions/version", metadataXml ); - XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml ); - } - - @Test - public void testNonArtifactFile() - throws Exception - { - /*Configuration config = archivaConfiguration.getConfiguration(); - config.removeManagedRepository( config.findManagedRepositoryById( TEST_REPO_ID ) ); - config.addManagedRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) );*/ - - applicationContext.getBean( ManagedRepositoryAdmin.class ).deleteManagedRepository( TEST_REPO_ID, null, false ); - applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( - getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null ); - - String repoRoot = prepareTestRepos(); - - // test listeners for the correct artifacts - listenerControl.replay(); - - File file = new File( repoRoot, INDEX_PATH ); - if ( !file.exists() ) - { - // help windauze to create directory with . - file.getParentFile().mkdirs(); - file.createNewFile(); - } - assertTrue( file.exists() ); - - repoPurge.process( INDEX_PATH ); - - listenerControl.verify(); - - assertTrue( file.exists() ); - } - - @Test - public void testReleasedSnapshotsExistsInDifferentRepo() - throws Exception - { - /* - Configuration config = archivaConfiguration.getConfiguration(); - config.removeManagedRepository( config.findManagedRepositoryById( TEST_REPO_ID ) ); - config.addManagedRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) ); - config.addManagedRepository( getRepoConfiguration( RELEASES_TEST_REPO_ID, RELEASES_TEST_REPO_NAME ) ); - */ - applicationContext.getBean( ManagedRepositoryAdmin.class ).deleteManagedRepository( TEST_REPO_ID, null, false ); - applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( - getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null ); - - applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( - getRepoConfiguration( RELEASES_TEST_REPO_ID, RELEASES_TEST_REPO_NAME ), false, null ); - - String repoRoot = prepareTestRepos(); - - // test listeners for the correct artifacts - listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.archiva", - "released-artifact-in-diff-repo", "1.0-SNAPSHOT", - "released-artifact-in-diff-repo-1.0-SNAPSHOT.jar" ); - listenerControl.replay(); - - repoPurge.process( PATH_TO_RELEASED_SNAPSHOT_IN_DIFF_REPO ); - - listenerControl.verify(); - - String projectRoot = repoRoot + "/org/apache/archiva/released-artifact-in-diff-repo"; - - // check if the snapshot was removed - assertDeleted( projectRoot + "/1.0-SNAPSHOT" ); - assertDeleted( projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.jar" ); - assertDeleted( projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.jar.md5" ); - assertDeleted( projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.jar.sha1" ); - assertDeleted( projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.pom" ); - assertDeleted( projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.pom.md5" ); - assertDeleted( projectRoot + "/1.0-SNAPSHOT/released-artifact-in-diff-repo-1.0-SNAPSHOT.pom.sha1" ); - - String releasesProjectRoot = - new File( "target/test-" + getName() + "/releases-test-repo-one" ).getAbsolutePath() - + "/org/apache/archiva/released-artifact-in-diff-repo"; - - // check if the released version was not removed - assertExists( releasesProjectRoot + "/1.0" ); - assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.jar" ); - assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.jar.md5" ); - assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.jar.sha1" ); - assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.pom" ); - assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.pom.md5" ); - assertExists( releasesProjectRoot + "/1.0/released-artifact-in-diff-repo-1.0.pom.sha1" ); - } - - @Test - public void testHigherSnapshotExistsInSameRepo() - throws Exception - { - /* - Configuration config = archivaConfiguration.getConfiguration(); - config.removeManagedRepository( config.findManagedRepositoryById( TEST_REPO_ID ) ); - config.addManagedRepository( getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ) ); - */ - applicationContext.getBean( ManagedRepositoryAdmin.class ).deleteManagedRepository( TEST_REPO_ID, null, false ); - applicationContext.getBean( ManagedRepositoryAdmin.class ).addManagedRepository( - getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ), false, null ); - - String repoRoot = prepareTestRepos(); - - // test listeners for the correct artifacts - no deletions - listenerControl.replay(); - - repoPurge.process( CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_HIGHER_SNAPSHOT_EXISTS_IN_SAME_REPO ); - - listenerControl.verify(); - - String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-source-plugin"; - - // check if the snapshot was not removed - assertExists( projectRoot + "/2.0.3-SNAPSHOT" ); - assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar" ); - assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar.md5" ); - assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.jar.sha1" ); - assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom" ); - assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom.md5" ); - assertExists( projectRoot + "/2.0.3-SNAPSHOT/maven-source-plugin-2.0.3-SNAPSHOT.pom.sha1" ); - - // check if the released version was not removed - assertExists( projectRoot + "/2.0.4-SNAPSHOT" ); - assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.jar" ); - assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.jar.md5" ); - assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.jar.sha1" ); - assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom" ); - assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom.md5" ); - assertExists( projectRoot + "/2.0.4-SNAPSHOT/maven-source-plugin-2.0.4-SNAPSHOT.pom.sha1" ); - - // check if metadata file was not updated (because nothing was removed) - File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" ); - - String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null ); - - String expectedVersions = "2.0.3-SNAPSHOT" - + "2.0.4-SNAPSHOT"; - - XMLAssert.assertXpathEvaluatesTo( "2.0.4-SNAPSHOT", "//metadata/versioning/latest", metadataXml ); - XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions, - "//metadata/versioning/versions/version", metadataXml ); - XMLAssert.assertXpathEvaluatesTo( "20070427033345", "//metadata/versioning/lastUpdated", metadataXml ); - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java deleted file mode 100644 index 783c65a5d..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java +++ /dev/null @@ -1,233 +0,0 @@ -package org.apache.maven.archiva.consumers.core.repository; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.archiva.repository.events.RepositoryListener; -import org.apache.commons.lang.time.DateUtils; -import org.junit.After; -import org.junit.Test; - -import java.io.File; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Collections; -import java.util.List; - -/** - */ -public class DaysOldRepositoryPurgeTest - extends AbstractRepositoryPurgeTest -{ - private static final int OLD_TIMESTAMP = 1179382029; - - private void setLastModified( String dirPath, long lastModified ) - { - File dir = new File( dirPath ); - File[] contents = dir.listFiles(); - for ( File content : contents ) - { - content.setLastModified( lastModified ); - } - } - - @Test - public void testByLastModified() - throws Exception - { - ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); - repoPurge = new DaysOldRepositoryPurge( getRepository(), repoConfiguration.getDaysOlder(), - repoConfiguration.getRetentionCount(), repositorySession, - Collections.singletonList( listener ) ); - - String repoRoot = prepareTestRepos(); - - String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-install-plugin"; - - setLastModified( projectRoot + "/2.2-SNAPSHOT/", OLD_TIMESTAMP ); - - // test listeners for the correct artifacts - listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", - "maven-install-plugin", "2.2-SNAPSHOT", "maven-install-plugin-2.2-SNAPSHOT.jar" ); - listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", - "maven-install-plugin", "2.2-SNAPSHOT", "maven-install-plugin-2.2-SNAPSHOT.pom" ); - listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", - "maven-install-plugin", "2.2-20061118.060401-2", - "maven-install-plugin-2.2-20061118.060401-2.jar" ); - listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", - "maven-install-plugin", "2.2-20061118.060401-2", - "maven-install-plugin-2.2-20061118.060401-2.pom" ); - listenerControl.replay(); - - repoPurge.process( PATH_TO_BY_DAYS_OLD_ARTIFACT ); - - listenerControl.verify(); - - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.md5" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.sha1" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.md5" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.sha1" ); - - // shouldn't be deleted because even if older than 30 days (because retention count = 2) - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.md5" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.sha1" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.md5" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.sha1" ); - - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.md5" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.sha1" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.md5" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.sha1" ); - - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.md5" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.sha1" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.md5" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.sha1" ); - } - - @Test - public void testOrderOfDeletion() - throws Exception - { - ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); - List listeners = Collections.singletonList( listener ); - repoPurge = new DaysOldRepositoryPurge( getRepository(), repoConfiguration.getDaysOlder(), - repoConfiguration.getRetentionCount(), repositorySession, listeners ); - - String repoRoot = prepareTestRepos(); - - String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-assembly-plugin"; - - setLastModified( projectRoot + "/1.1.2-SNAPSHOT/", OLD_TIMESTAMP ); - - // test listeners for the correct artifacts - listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", - "maven-assembly-plugin", "1.1.2-20070427.065136-1", - "maven-assembly-plugin-1.1.2-20070427.065136-1.jar" ); - listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", - "maven-assembly-plugin", "1.1.2-20070427.065136-1", - "maven-assembly-plugin-1.1.2-20070427.065136-1.pom" ); - listenerControl.replay(); - - repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION ); - - listenerControl.verify(); - - assertDeleted( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.jar" ); - assertDeleted( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.sha1" ); - assertDeleted( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.md5" ); - assertDeleted( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.pom" ); - assertDeleted( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.sha1" ); - assertDeleted( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.md5" ); - - // the following should not have been deleted - assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.jar" ); - assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.sha1" ); - assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.md5" ); - assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.pom" ); - assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.sha1" ); - assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.md5" ); - - assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar" ); - assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.sha1" ); - assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.md5" ); - assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom" ); - assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.sha1" ); - assertExists( projectRoot + "/1.1.2-SNAPSHOT/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.md5" ); - } - - @Test - public void testMetadataDrivenSnapshots() - throws Exception - { - ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); - List listeners = Collections.singletonList( listener ); - repoPurge = new DaysOldRepositoryPurge( getRepository(), repoConfiguration.getDaysOlder(), - repoConfiguration.getRetentionCount(), repositorySession, listeners ); - - String repoRoot = prepareTestRepos(); - - String versionRoot = repoRoot + "/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT"; - - Calendar currentDate = Calendar.getInstance( DateUtils.UTC_TIME_ZONE ); - setLastModified( versionRoot, currentDate.getTimeInMillis() ); - - String timestamp = new SimpleDateFormat( "yyyyMMdd.HHmmss" ).format( currentDate.getTime() ); - - for ( int i = 5; i <= 7; i++ ) - { - File jarFile = new File( versionRoot, "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".jar" ); - jarFile.createNewFile(); - File pomFile = new File( versionRoot, "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".pom" ); - pomFile.createNewFile(); - - // set timestamp to older than 100 days for the first build, but ensure the filename timestamp is honoured instead - if ( i == 5 ) - { - jarFile.setLastModified( OLD_TIMESTAMP ); - pomFile.setLastModified( OLD_TIMESTAMP ); - } - } - - // test listeners for the correct artifacts - listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.plexus", "plexus-utils", - "1.4.3-20070113.163208-4", "plexus-utils-1.4.3-20070113.163208-4.jar" ); - listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.plexus", "plexus-utils", - "1.4.3-20070113.163208-4", "plexus-utils-1.4.3-20070113.163208-4.pom" ); - listenerControl.replay(); - - repoPurge.process( PATH_TO_BY_DAYS_OLD_METADATA_DRIVEN_ARTIFACT ); - - listenerControl.verify(); - - // this should be deleted since the filename version (timestamp) is older than - // 100 days even if the last modified date was <100 days ago - assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.jar" ); - assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.jar.sha1" ); - assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.pom" ); - assertDeleted( versionRoot + "/plexus-utils-1.4.3-20070113.163208-4.pom.sha1" ); - - // this should not be deleted because last modified date is <100 days ago - assertExists( versionRoot + "/plexus-utils-1.4.3-SNAPSHOT.jar" ); - assertExists( versionRoot + "/plexus-utils-1.4.3-SNAPSHOT.pom" ); - - for ( int i = 5; i <= 7; i++ ) - { - assertExists( versionRoot + "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".jar" ); - assertExists( versionRoot + "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".pom" ); - } - } - - @After - public void tearDown() - throws Exception - { - super.tearDown(); - repoPurge = null; - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java deleted file mode 100644 index 37006627e..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java +++ /dev/null @@ -1,373 +0,0 @@ -package org.apache.maven.archiva.consumers.core.repository; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; -import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; -import org.apache.archiva.metadata.repository.TestRepositorySessionFactory; -import org.apache.commons.io.FileUtils; -import org.apache.archiva.common.utils.BaseFile; -import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.FileType; -import org.apache.maven.archiva.configuration.FileTypes; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.functors.ConsumerWantsFilePredicate; -import org.custommonkey.xmlunit.XMLAssert; -import org.junit.Before; -import org.junit.Test; -import org.springframework.test.context.ContextConfiguration; - -import java.io.File; - -/** - */ -@ContextConfiguration( - locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-purge-consumer-test.xml" } ) -public class RepositoryPurgeConsumerTest - extends AbstractRepositoryPurgeTest -{ - @Before - public void setUp() - throws Exception - { - super.setUp(); - - TestRepositorySessionFactory factory = applicationContext.getBean( TestRepositorySessionFactory.class ); - factory.setRepository( metadataRepository ); - } - - @Test - public void testConsumption() - throws Exception - { - assertNotConsumed( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata.xml" ); - cleanupFileTypes(); - } - - @Test - public void testConsumptionOfOtherMetadata() - throws Exception - { - assertNotConsumed( "org/apache/maven/plugins/maven-plugin-plugin/2.4.1/maven-metadata-central.xml" ); - cleanupFileTypes(); - } - - private void cleanupFileTypes() - { - ArchivaConfiguration archivaConfiguration = - applicationContext.getBean( "archivaConfiguration#default", ArchivaConfiguration.class ); - - FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 ); - fileType.removePattern( "**/*.xml" ); - } - - private void assertNotConsumed( String path ) - throws Exception - { - ArchivaConfiguration archivaConfiguration = - applicationContext.getBean( "archivaConfiguration#default", ArchivaConfiguration.class ); - - FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 ); - assertEquals( FileTypes.ARTIFACTS, fileType.getId() ); - fileType.addPattern( "**/*.xml" ); - - // trigger reload - //FileTypes fileTypes = applicationContext.getBean( FileTypes.class ); - for ( FileTypes fileTypes : applicationContext.getBeansOfType( FileTypes.class ).values() ) - { - fileTypes.afterConfigurationChange( null, "repositoryScanning.fileTypes", null ); - } - KnownRepositoryContentConsumer repoPurgeConsumer = - applicationContext.getBean( "knownRepositoryContentConsumer#repository-purge", - KnownRepositoryContentConsumer.class ); - - File repoLocation = new File( "target/test-" + getName() + "/test-repo" ); - - File localFile = new File( repoLocation, path ); - - ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate(); - BaseFile baseFile = new BaseFile( repoLocation, localFile ); - predicate.setBasefile( baseFile ); - - assertFalse( predicate.evaluate( repoPurgeConsumer ) ); - } - - private void setLastModified( String path ) - { - File dir = new File( path ); - File[] contents = dir.listFiles(); - for ( int i = 0; i < contents.length; i++ ) - { - contents[i].setLastModified( 1179382029 ); - } - } - - @Test - public void testConsumerByRetentionCount() - throws Exception - { - KnownRepositoryContentConsumer repoPurgeConsumer = - applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count", - KnownRepositoryContentConsumer.class ); - - ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); - repoConfiguration.setDaysOlder( 0 ); // force days older off to allow retention count purge to execute. - repoConfiguration.setRetentionCount( TEST_RETENTION_COUNT ); - addRepoToConfiguration( "retention-count", repoConfiguration ); - - repoPurgeConsumer.beginScan( repoConfiguration, null ); - - String repoRoot = prepareTestRepos(); - - repoPurgeConsumer.processFile( PATH_TO_BY_RETENTION_COUNT_ARTIFACT ); - - String versionRoot = repoRoot + "/org/jruby/plugins/jruby-rake-plugin/1.0RC1-SNAPSHOT"; - - // assert if removed from repo - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.md5" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.sha1" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.md5" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.sha1" ); - - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.md5" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.sha1" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.md5" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.sha1" ); - - // assert if not removed from repo - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.md5" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.sha1" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.md5" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.sha1" ); - - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.md5" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.sha1" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.md5" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.sha1" ); - - removeRepoFromConfiguration( "retention-count", repoConfiguration ); - } - - private void addRepoToConfiguration( String configHint, ManagedRepository repoConfiguration ) - throws Exception - { - ArchivaConfiguration archivaConfiguration = - applicationContext.getBean( "archivaConfiguration#" + configHint, ArchivaConfiguration.class ); - ( (DefaultManagedRepositoryAdmin) applicationContext.getBean( - ManagedRepositoryAdmin.class ) ).setArchivaConfiguration( archivaConfiguration ); - /** - Configuration configuration = archivaConfiguration.getConfiguration(); - ManagedRepositoryConfiguration managedRepositoryConfiguration = - configuration.findManagedRepositoryById( repoConfiguration.getId() ); - if ( managedRepositoryConfiguration != null ) - { - configuration.removeManagedRepository( managedRepositoryConfiguration ); - } - configuration.addManagedRepository( repoConfiguration ); - **/ - ManagedRepositoryAdmin managedRepositoryAdmin = applicationContext.getBean( ManagedRepositoryAdmin.class ); - if ( managedRepositoryAdmin.getManagedRepository( repoConfiguration.getId() ) != null ) - { - managedRepositoryAdmin.deleteManagedRepository( repoConfiguration.getId(), null, false ); - } - managedRepositoryAdmin.addManagedRepository( repoConfiguration, false, null ); - } - - private void removeRepoFromConfiguration( String configHint, ManagedRepository repoConfiguration ) - throws Exception - { - ArchivaConfiguration archivaConfiguration = - applicationContext.getBean( "archivaConfiguration#" + configHint, ArchivaConfiguration.class ); - - ( (DefaultManagedRepositoryAdmin) applicationContext.getBean( - ManagedRepositoryAdmin.class ) ).setArchivaConfiguration( archivaConfiguration ); - /** - Configuration configuration = archivaConfiguration.getConfiguration(); - ManagedRepositoryConfiguration managedRepositoryConfiguration = - configuration.findManagedRepositoryById( repoConfiguration.getId() ); - if ( managedRepositoryConfiguration != null ) - { - configuration.removeManagedRepository( managedRepositoryConfiguration ); - }*/ - ManagedRepositoryAdmin managedRepositoryAdmin = applicationContext.getBean( ManagedRepositoryAdmin.class ); - if ( managedRepositoryAdmin.getManagedRepository( repoConfiguration.getId() ) != null ) - { - managedRepositoryAdmin.deleteManagedRepository( repoConfiguration.getId(), null, true ); - } - } - - @Test - public void testConsumerByDaysOld() - throws Exception - { - KnownRepositoryContentConsumer repoPurgeConsumer = - applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-days-old", - KnownRepositoryContentConsumer.class ); - - ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); - repoConfiguration.setDaysOlder( TEST_DAYS_OLDER ); - addRepoToConfiguration( "days-old", repoConfiguration ); - - repoPurgeConsumer.beginScan( repoConfiguration, null ); - - String repoRoot = prepareTestRepos(); - String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-install-plugin"; - - setLastModified( projectRoot + "/2.2-SNAPSHOT" ); - - repoPurgeConsumer.processFile( PATH_TO_BY_DAYS_OLD_ARTIFACT ); - - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.md5" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.jar.sha1" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.md5" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.pom.sha1" ); - - // shouldn't be deleted because even if older than 30 days (because retention count = 2) - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.md5" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.jar.sha1" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.md5" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070513.034619-5.pom.sha1" ); - - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.md5" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.jar.sha1" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.md5" ); - assertExists( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20070510.010101-4.pom.sha1" ); - - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.md5" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.jar.sha1" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.md5" ); - assertDeleted( projectRoot + "/2.2-SNAPSHOT/maven-install-plugin-2.2-20061118.060401-2.pom.sha1" ); - - removeRepoFromConfiguration( "days-old", repoConfiguration ); - } - - /** - * Test the snapshot clean consumer on a repository set to NOT clean/delete snapshots based on released versions. - * - * @throws Exception - */ - @Test - public void testReleasedSnapshotsWereNotCleaned() - throws Exception - { - KnownRepositoryContentConsumer repoPurgeConsumer = - applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count", - KnownRepositoryContentConsumer.class ); - - ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); - repoConfiguration.setDeleteReleasedSnapshots( false ); // Set to NOT delete released snapshots. - addRepoToConfiguration( "retention-count", repoConfiguration ); - - repoPurgeConsumer.beginScan( repoConfiguration, null ); - - String repoRoot = prepareTestRepos(); - - repoPurgeConsumer.processFile( - CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO ); - - // check if the snapshot wasn't removed - String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-plugin-plugin"; - - assertExists( projectRoot + "/2.3-SNAPSHOT" ); - assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" ); - assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5" ); - assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1" ); - assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom" ); - assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5" ); - assertExists( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1" ); - - // check if metadata file wasn't updated - File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" ); - - String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null ); - - String expectedVersions = "2.3-SNAPSHOT"; - - XMLAssert.assertXpathEvaluatesTo( "2.3-SNAPSHOT", "//metadata/versioning/latest", metadataXml ); - XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions, - "//metadata/versioning/versions/version", metadataXml ); - XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml ); - - removeRepoFromConfiguration( "retention-count", repoConfiguration ); - } - - @Test - public void testReleasedSnapshotsWereCleaned() - throws Exception - { - KnownRepositoryContentConsumer repoPurgeConsumer = - applicationContext.getBean( "knownRepositoryContentConsumer#repo-purge-consumer-by-days-old", - KnownRepositoryContentConsumer.class ); - - ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); - repoConfiguration.setDeleteReleasedSnapshots( true ); - addRepoToConfiguration( "days-old", repoConfiguration ); - - repoPurgeConsumer.beginScan( repoConfiguration, null ); - - String repoRoot = prepareTestRepos(); - - repoPurgeConsumer.processFile( - CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO ); - - String projectRoot = repoRoot + "/org/apache/maven/plugins/maven-plugin-plugin"; - - // check if the snapshot was removed - assertDeleted( projectRoot + "/2.3-SNAPSHOT" ); - assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar" ); - assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.md5" ); - assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.jar.sha1" ); - assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom" ); - assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.md5" ); - assertDeleted( projectRoot + "/2.3-SNAPSHOT/maven-plugin-plugin-2.3-SNAPSHOT.pom.sha1" ); - - // check if metadata file was updated - File artifactMetadataFile = new File( projectRoot + "/maven-metadata.xml" ); - - String metadataXml = FileUtils.readFileToString( artifactMetadataFile, null ); - - String expectedVersions = - "2.2" + "2.3"; - - XMLAssert.assertXpathEvaluatesTo( "2.3", "//metadata/versioning/latest", metadataXml ); - XMLAssert.assertXpathsEqual( "//expected/versions/version", expectedVersions, - "//metadata/versioning/versions/version", metadataXml ); - XMLAssert.assertXpathEvaluatesTo( "20070315032817", "//metadata/versioning/lastUpdated", metadataXml ); - - removeRepoFromConfiguration( "days-old", repoConfiguration ); - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java deleted file mode 100644 index babac9e0a..000000000 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java +++ /dev/null @@ -1,200 +0,0 @@ -package org.apache.maven.archiva.consumers.core.repository; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.archiva.repository.events.RepositoryListener; -import org.junit.Before; -import org.junit.Test; - -import java.util.Collections; -import java.util.List; - -/** - * Test RetentionsCountRepositoryPurgeTest - */ -public class RetentionCountRepositoryPurgeTest - extends AbstractRepositoryPurgeTest -{ - @Before - public void setUp() - throws Exception - { - super.setUp(); - - ManagedRepository repoConfiguration = getRepoConfiguration( TEST_REPO_ID, TEST_REPO_NAME ); - List listeners = Collections.singletonList( listener ); - repoPurge = new RetentionCountRepositoryPurge( getRepository(), repoConfiguration.getRetentionCount(), - repositorySession, listeners ); - } - - /** - * Test if the artifact to be processed was a jar. - */ - @Test - public void testIfAJarWasFound() - throws Exception - { - String repoRoot = prepareTestRepos(); - - // test listeners for the correct artifacts - listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", - "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" ); - listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", - "1.0RC1-20070504.153317-1", "jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" ); - listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", - "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" ); - listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin", - "1.0RC1-20070504.160758-2", "jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" ); - listenerControl.replay(); - - repoPurge.process( PATH_TO_BY_RETENTION_COUNT_ARTIFACT ); - - listenerControl.verify(); - - String versionRoot = repoRoot + "/org/jruby/plugins/jruby-rake-plugin/1.0RC1-SNAPSHOT"; - - // assert if removed from repo - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.md5" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.jar.sha1" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.md5" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.153317-1.pom.sha1" ); - - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.md5" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.jar.sha1" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.md5" ); - assertDeleted( versionRoot + "/jruby-rake-plugin-1.0RC1-20070504.160758-2.pom.sha1" ); - - // assert if not removed from repo - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.md5" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.jar.sha1" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.md5" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070505.090015-3.pom.sha1" ); - - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.md5" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.jar.sha1" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.md5" ); - assertExists( versionRoot + "/jruby-rake-plugin-1.0RC1-20070506.090132-4.pom.sha1" ); - } - - /** - * Test if the artifact to be processed is a pom - */ - @Test - public void testIfAPomWasFound() - throws Exception - { - String repoRoot = prepareTestRepos(); - - // test listeners for the correct artifacts - listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks", - "1.1.2-20070427.065136-1", "castor-anttasks-1.1.2-20070427.065136-1.jar" ); - listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks", - "1.1.2-20070427.065136-1", "castor-anttasks-1.1.2-20070427.065136-1.pom" ); - listenerControl.replay(); - - repoPurge.process( PATH_TO_BY_RETENTION_COUNT_POM ); - - listenerControl.verify(); - - String versionRoot = repoRoot + "/org/codehaus/castor/castor-anttasks/1.1.2-SNAPSHOT"; - - // assert if removed from repo - assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar" ); - assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.md5" ); - assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.jar.sha1" ); - assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom" ); - assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom.md5" ); - assertDeleted( versionRoot + "/castor-anttasks-1.1.2-20070427.065136-1.pom.sha1" ); - - // assert if not removed from repo - assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom" ); - assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom.md5" ); - assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.pom.sha1" ); - assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar" ); - assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar.md5" ); - assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3.jar.sha1" ); - assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar" ); - assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar.md5" ); - assertExists( versionRoot + "/castor-anttasks-1.1.2-20070615.105019-3-sources.jar.sha1" ); - - assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom" ); - assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom.md5" ); - assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.pom.sha1" ); - assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar" ); - assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar.md5" ); - assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2.jar.sha1" ); - assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar" ); - assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.md5" ); - assertExists( versionRoot + "/castor-anttasks-1.1.2-20070506.163513-2-sources.jar.sha1" ); - } - - @Test - public void testOrderOfDeletion() - throws Exception - { - String repoRoot = prepareTestRepos(); - - // test listeners for the correct artifacts - listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", - "maven-assembly-plugin", "1.1.2-20070427.065136-1", - "maven-assembly-plugin-1.1.2-20070427.065136-1.jar" ); - listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins", - "maven-assembly-plugin", "1.1.2-20070427.065136-1", - "maven-assembly-plugin-1.1.2-20070427.065136-1.pom" ); - listenerControl.replay(); - - repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION ); - - listenerControl.verify(); - - String versionRoot = repoRoot + "/org/apache/maven/plugins/maven-assembly-plugin/1.1.2-SNAPSHOT"; - - assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar" ); - assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.sha1" ); - assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.jar.md5" ); - assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom" ); - assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.sha1" ); - assertDeleted( versionRoot + "/maven-assembly-plugin-1.1.2-20070427.065136-1.pom.md5" ); - - // the following should not have been deleted - assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar" ); - assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.sha1" ); - assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.jar.md5" ); - assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom" ); - assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.sha1" ); - assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070506.163513-2.pom.md5" ); - - assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar" ); - assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.sha1" ); - assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.jar.md5" ); - assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom" ); - assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.sha1" ); - assertExists( versionRoot + "/maven-assembly-plugin-1.1.2-20070615.105019-3.pom.md5" ); - } -} diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/spring-context-purge-consumer-test.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/spring-context-purge-consumer-test.xml index ea10f40a0..0f2224efa 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/spring-context-purge-consumer-test.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/spring-context-purge-consumer-test.xml @@ -32,7 +32,7 @@ - + @@ -69,7 +69,7 @@ - + diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java index da2e09a9e..f85d94d05 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java @@ -28,9 +28,9 @@ import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ConfigurationNames; import org.apache.maven.archiva.configuration.FileTypes; -import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; -import org.apache.maven.archiva.consumers.ConsumerException; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.archiva.consumers.ConsumerException; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.maven.index.NexusIndexer; import org.apache.maven.index.context.IndexCreator; import org.apache.maven.index.context.IndexingContext; diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java index 480c11044..4c9d6fe0f 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java @@ -28,7 +28,7 @@ import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask; import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.FileTypes; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.codehaus.plexus.taskqueue.TaskQueueException; import org.junit.After; import org.junit.Before; diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java index bd1cba860..e2ab24807 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java @@ -34,9 +34,9 @@ import org.apache.archiva.common.utils.VersionUtil; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ConfigurationNames; import org.apache.maven.archiva.configuration.FileTypes; -import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; -import org.apache.maven.archiva.consumers.ConsumerException; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.archiva.consumers.ConsumerException; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.codehaus.plexus.registry.Registry; import org.codehaus.plexus.registry.RegistryListener; import org.slf4j.Logger; diff --git a/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java b/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java index 34594a061..26a817a48 100644 --- a/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java +++ b/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java @@ -26,8 +26,8 @@ import org.apache.archiva.converter.RepositoryConversionException; import org.apache.archiva.repository.scanner.RepositoryScanner; import org.apache.archiva.repository.scanner.RepositoryScannerException; import org.apache.archiva.common.utils.PathUtil; -import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; diff --git a/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/LegacyConverterArtifactConsumer.java b/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/LegacyConverterArtifactConsumer.java index c0bc6bc12..4569bc46f 100644 --- a/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/LegacyConverterArtifactConsumer.java +++ b/archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/LegacyConverterArtifactConsumer.java @@ -22,9 +22,9 @@ package org.apache.archiva.converter.legacy; import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; -import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; -import org.apache.maven.archiva.consumers.ConsumerException; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.archiva.consumers.ConsumerException; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.archiva.converter.artifact.ArtifactConversionException; import org.apache.archiva.converter.artifact.ArtifactConverter; import org.apache.maven.archiva.model.ArtifactReference; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/DefaultRepositoryScanner.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/DefaultRepositoryScanner.java index f8fcdd2c5..b24da6463 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/DefaultRepositoryScanner.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/DefaultRepositoryScanner.java @@ -23,9 +23,9 @@ import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.commons.collections.CollectionUtils; import org.apache.maven.archiva.configuration.FileTypes; -import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.RepositoryContentConsumer; +import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.RepositoryContentConsumer; import org.codehaus.plexus.util.DirectoryWalker; import org.springframework.stereotype.Service; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java index 7a0c387a4..a0f73512a 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java @@ -29,9 +29,9 @@ import org.apache.commons.collections.Closure; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.functors.IfClosure; import org.apache.archiva.common.utils.BaseFile; -import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.functors.ConsumerWantsFilePredicate; +import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScanner.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScanner.java index 40a53c565..3dbcf6fba 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScanner.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScanner.java @@ -20,8 +20,8 @@ package org.apache.archiva.repository.scanner; */ import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import java.util.List; import java.util.Set; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScannerInstance.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScannerInstance.java index e0f628e60..059d6b528 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScannerInstance.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScannerInstance.java @@ -28,9 +28,9 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.functors.IfClosure; import org.apache.commons.lang.SystemUtils; import org.apache.archiva.common.utils.BaseFile; -import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.functors.ConsumerWantsFilePredicate; +import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate; import org.codehaus.plexus.util.DirectoryWalkListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/ConsumerProcessFileClosure.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/ConsumerProcessFileClosure.java index 370a28df2..fda9f9fa7 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/ConsumerProcessFileClosure.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/ConsumerProcessFileClosure.java @@ -21,7 +21,7 @@ package org.apache.archiva.repository.scanner.functors; import org.apache.commons.collections.Closure; import org.apache.archiva.common.utils.BaseFile; -import org.apache.maven.archiva.consumers.RepositoryContentConsumer; +import org.apache.archiva.consumers.RepositoryContentConsumer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerBeginScanClosure.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerBeginScanClosure.java index 4b775bfb0..de2c06186 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerBeginScanClosure.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerBeginScanClosure.java @@ -21,8 +21,8 @@ package org.apache.archiva.repository.scanner.functors; import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.commons.collections.Closure; -import org.apache.maven.archiva.consumers.ConsumerException; -import org.apache.maven.archiva.consumers.RepositoryContentConsumer; +import org.apache.archiva.consumers.ConsumerException; +import org.apache.archiva.consumers.RepositoryContentConsumer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java index e6a4b6a9c..775037825 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java @@ -21,7 +21,7 @@ package org.apache.archiva.repository.scanner.functors; import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.commons.collections.Closure; -import org.apache.maven.archiva.consumers.RepositoryContentConsumer; +import org.apache.archiva.consumers.RepositoryContentConsumer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/InvalidScanConsumer.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/InvalidScanConsumer.java index 765da49e8..901925ac6 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/InvalidScanConsumer.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/InvalidScanConsumer.java @@ -20,9 +20,9 @@ package org.apache.archiva.repository.scanner; */ import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; -import org.apache.maven.archiva.consumers.ConsumerException; -import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; +import org.apache.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.archiva.consumers.ConsumerException; +import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; import java.util.Date; import java.util.List; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/KnownScanConsumer.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/KnownScanConsumer.java index 0937cbc33..caacfd5e5 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/KnownScanConsumer.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/KnownScanConsumer.java @@ -20,9 +20,9 @@ package org.apache.archiva.repository.scanner; */ import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; -import org.apache.maven.archiva.consumers.ConsumerException; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.archiva.consumers.ConsumerException; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import java.util.ArrayList; import java.util.Arrays; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java index 6596daaa5..7e81a10d7 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java @@ -24,8 +24,8 @@ import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.admin.model.beans.RemoteRepository; import org.apache.commons.lang.SystemUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.easymock.MockControl; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryScannerTest.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryScannerTest.java index 840601f07..89896838b 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryScannerTest.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryScannerTest.java @@ -23,8 +23,8 @@ import junit.framework.TestCase; import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.admin.model.beans.RemoteRepository; import org.apache.commons.io.FileUtils; -import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.context.ApplicationContext; diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/SampleKnownConsumer.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/SampleKnownConsumer.java index ceba75cd2..11069bf04 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/SampleKnownConsumer.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/SampleKnownConsumer.java @@ -20,9 +20,9 @@ package org.apache.archiva.repository.scanner; */ import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; -import org.apache.maven.archiva.consumers.ConsumerException; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.archiva.consumers.ConsumerException; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import java.util.Date; import java.util.List; diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestConsumer.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestConsumer.java index 67561d784..678113099 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestConsumer.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestConsumer.java @@ -20,9 +20,9 @@ package org.apache.archiva.scheduler.repository; */ import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; -import org.apache.maven.archiva.consumers.ConsumerException; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.archiva.consumers.ConsumerException; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.RepositoryContentFactory; diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/scanning/AddAdminRepoConsumerClosure.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/scanning/AddAdminRepoConsumerClosure.java index 89aca8cf5..4085cdbba 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/scanning/AddAdminRepoConsumerClosure.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/scanning/AddAdminRepoConsumerClosure.java @@ -20,7 +20,7 @@ package org.apache.maven.archiva.web.action.admin.scanning; */ import org.apache.commons.collections.Closure; -import org.apache.maven.archiva.consumers.RepositoryContentConsumer; +import org.apache.archiva.consumers.RepositoryContentConsumer; import java.util.ArrayList; import java.util.List; diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/StubRepositoryContentConsumers.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/StubRepositoryContentConsumers.java index 5f221617a..1524c2892 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/StubRepositoryContentConsumers.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/StubRepositoryContentConsumers.java @@ -21,8 +21,8 @@ package org.apache.maven.archiva.webdav; import org.apache.archiva.admin.model.admin.ArchivaAdministration; import org.apache.archiva.repository.scanner.RepositoryContentConsumers; -import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import java.util.List; diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java index f9118064e..77638befa 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java @@ -46,8 +46,8 @@ import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository; import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; -import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.maven.archiva.model.VersionedReference; import org.apache.archiva.repository.ContentNotFoundException; import org.apache.archiva.repository.ManagedRepositoryContent; diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java index 875d87994..36abd7a79 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java @@ -53,8 +53,8 @@ import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration; import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration; -import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.archiva.repository.RepositoryContentFactory; import org.apache.archiva.repository.content.ManagedDefaultRepositoryContent; diff --git a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java index 196b51064..df39ec396 100644 --- a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java +++ b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java @@ -33,9 +33,9 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ConfigurationNames; import org.apache.maven.archiva.configuration.FileTypes; -import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; -import org.apache.maven.archiva.consumers.ConsumerException; -import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.AbstractMonitoredConsumer; +import org.apache.archiva.consumers.ConsumerException; +import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.codehaus.plexus.registry.Registry; import org.codehaus.plexus.registry.RegistryListener; import org.slf4j.Logger; diff --git a/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java b/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java index 93bb997be..75676975e 100644 --- a/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java +++ b/archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java @@ -28,7 +28,7 @@ import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; import org.apache.archiva.reports.RepositoryProblemFacet; -import org.apache.maven.archiva.consumers.ConsumerException; +import org.apache.archiva.consumers.ConsumerException; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -- cgit v1.2.3