]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1003] Repackage sources from org.apache.maven.archiva.. to org.apache.archiva...
authorOlivier Lamy <olamy@apache.org>
Fri, 16 Sep 2011 08:54:07 +0000 (08:54 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 16 Sep 2011 08:54:07 +0000 (08:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1171453 13f79535-47bb-0310-9956-ffa450edef68

89 files changed:
archiva-cli/src/main/java/org/apache/archiva/cli/AbstractProgressConsumer.java
archiva-cli/src/main/java/org/apache/archiva/cli/ArchivaCli.java
archiva-cli/src/main/java/org/apache/archiva/cli/ArtifactCountConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/AbstractMonitoredConsumer.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/Consumer.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/ConsumerException.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/ConsumerMonitor.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/InvalidRepositoryContentConsumer.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/KnownRepositoryContentConsumer.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/RepositoryContentConsumer.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/functors/ConsumerWantsFilePredicate.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/functors/PermanentConsumerPredicate.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/AbstractMonitoredConsumer.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/Consumer.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/ConsumerException.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/ConsumerMonitor.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/InvalidRepositoryContentConsumer.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/KnownRepositoryContentConsumer.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/RepositoryContentConsumer.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/functors/ConsumerWantsFilePredicate.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/maven/archiva/consumers/functors/PermanentConsumerPredicate.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/AutoRemoveConsumer.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/AutoRenameConsumer.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ValidateChecksumConsumer.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurge.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/ArtifactFilenameFilter.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurge.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurge.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumer.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeException.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRemoveConsumer.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/AutoRenameConsumer.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/MetadataUpdaterConsumer.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/ValidateChecksumConsumer.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/ArtifactFilenameFilter.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurge.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurge.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumer.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeException.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurge.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/resources/META-INF/spring-context.xml
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/AbstractArtifactConsumerTest.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/MetadataUpdateConsumerTest.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/AbstractArtifactConsumerTest.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/MetadataUpdateConsumerTest.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/maven/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java [deleted file]
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/resources/spring-context-purge-consumer-test.xml
archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java
archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java
archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/DefaultLegacyRepositoryConverter.java
archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/legacy/LegacyConverterArtifactConsumer.java
archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/DefaultRepositoryScanner.java
archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java
archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScanner.java
archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScannerInstance.java
archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/ConsumerProcessFileClosure.java
archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerBeginScanClosure.java
archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java
archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/InvalidScanConsumer.java
archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/KnownScanConsumer.java
archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java
archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryScannerTest.java
archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/SampleKnownConsumer.java
archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestConsumer.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/scanning/AddAdminRepoConsumerClosure.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/StubRepositoryContentConsumers.java
archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java
archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java
archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java
archiva-modules/plugins/problem-reports/src/test/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumerTest.java

index a5ef33103d41017c9742098f9e3ac9d32cf9502c..be78cb872b7fc3893219be4253605f656478ecc1 100644 (file)
@@ -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;
 
index e8fbb3c3af7cf4d24f2cacc8f880a68e05b67da0..4dc1bafbb09ea79201f04bfebaca775ffb70b440 100644 (file)
@@ -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;
 
index 865e992451036de50d966d51c944b175a37f0b02..ce647cef89eac3bf9ac315231ae107284117af4f 100644 (file)
@@ -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 (file)
index 0000000..324f0c1
--- /dev/null
@@ -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<ConsumerMonitor> monitors = new HashSet<ConsumerMonitor>();
+    
+    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<ConsumerMonitor> 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<ConsumerMonitor> 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<ConsumerMonitor> 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<String> 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 (file)
index 0000000..d50fe97
--- /dev/null
@@ -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 (file)
index 0000000..f9fbf03
--- /dev/null
@@ -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 (file)
index 0000000..dcbbdec
--- /dev/null
@@ -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 (file)
index 0000000..3b2e758
--- /dev/null
@@ -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 (file)
index 0000000..93cc10a
--- /dev/null
@@ -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 (file)
index 0000000..8591d2f
--- /dev/null
@@ -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: <code>"**<span />/*.pom"</code>)
+     */
+    List<String> getIncludes();
+
+    /**
+     * Get the list of excluded file patterns for this consumer.
+     *
+     * @return the list of {@link String} patterns. (example: <code>"**<span />/*.pom"</code>) - (can be null for no exclusions)
+     */
+    List<String> getExcludes();
+
+    /**
+     * <p>
+     * Event that triggers at the beginning of a scan.
+     * </p>
+     * <p/>
+     * <p>
+     * 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.
+     * </p>
+     *
+     * @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;
+
+    /**
+     * <p>
+     * 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.
+     * </p>
+     *
+     * @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;
+
+    /**
+     * <p>
+     * Event indicating a file is to be processed by this consumer.
+     * </p>
+     * <p/>
+     * <p>
+     * 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.
+     * </p>
+     *
+     * @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;
+
+    /**
+     * <p>
+     * Event that triggers on the completion of a scan.
+     * </p>
+     * <p/>
+     * <p>
+     * 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.
+     * </p>
+     */
+    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 (file)
index 0000000..7fe9e53
--- /dev/null
@@ -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<String> 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 (file)
index 0000000..cc10aaa
--- /dev/null
@@ -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 (file)
index e0ae5fe..0000000
+++ /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<ConsumerMonitor> monitors = new HashSet<ConsumerMonitor>();
-    
-    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<ConsumerMonitor> 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<ConsumerMonitor> 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<ConsumerMonitor> 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<String> 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 (file)
index 3c33125..0000000
+++ /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 (file)
index e401e21..0000000
+++ /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 (file)
index 1033898..0000000
+++ /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 (file)
index e619616..0000000
+++ /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 (file)
index 66d9845..0000000
+++ /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 (file)
index aa33e99..0000000
+++ /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: <code>"**<span />/*.pom"</code>)
-     */
-    List<String> getIncludes();
-
-    /**
-     * Get the list of excluded file patterns for this consumer.
-     *
-     * @return the list of {@link String} patterns. (example: <code>"**<span />/*.pom"</code>) - (can be null for no exclusions)
-     */
-    List<String> getExcludes();
-
-    /**
-     * <p>
-     * Event that triggers at the beginning of a scan.
-     * </p>
-     * <p/>
-     * <p>
-     * 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.
-     * </p>
-     *
-     * @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;
-
-    /**
-     * <p>
-     * 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.
-     * </p>
-     *
-     * @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;
-
-    /**
-     * <p>
-     * Event indicating a file is to be processed by this consumer.
-     * </p>
-     * <p/>
-     * <p>
-     * 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.
-     * </p>
-     *
-     * @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;
-
-    /**
-     * <p>
-     * Event that triggers on the completion of a scan.
-     * </p>
-     * <p/>
-     * <p>
-     * 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.
-     * </p>
-     */
-    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 (file)
index 65f29c5..0000000
+++ /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<String> 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 (file)
index 64ad0bd..0000000
+++ /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 (file)
index 0000000..790e506
--- /dev/null
@@ -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<String> includes = new ArrayList<String>();
+    
+    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<String> getExcludes()
+    {
+        return getDefaultArtifactExclusions();
+    }
+
+    public List<String> 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 (file)
index 0000000..b5a65fa
--- /dev/null
@@ -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<String> includes = new ArrayList<String>();
+
+    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<String> getExcludes()
+    {
+        return null;
+    }
+
+    public List<String> 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 (file)
index 0000000..a9dad0d
--- /dev/null
@@ -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<String> includes = new ArrayList<String>();
+
+    private Map<String, String> extensionRenameMap = new HashMap<String, String>();
+
+    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<String> getExcludes()
+    {
+        return null;
+    }
+
+    public List<String> getIncludes()
+    {
+        return includes;
+    }
+
+    public void processFile( String path )
+        throws ConsumerException
+    {
+        File file = new File( this.repositoryDir, path );
+        if ( file.exists() )
+        {
+            Iterator<String> 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 (file)
index 0000000..2efd46b
--- /dev/null
@@ -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<String> includes = new ArrayList<String>();
+
+    private long scanStartTimestamp = 0;
+
+    public String getDescription()
+    {
+        return description;
+    }
+
+    public String getId()
+    {
+        return id;
+    }
+
+    public void setIncludes( List<String> 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<String> getExcludes()
+    {
+        return getDefaultArtifactExclusions();
+    }
+
+    public List<String> 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 (file)
index 0000000..3feace0
--- /dev/null
@@ -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<Digester> allDigesters;
+
+    @Inject
+    private PlexusSisuBridge plexusSisuBridge;
+
+    @Inject
+    private DigesterUtils digesterUtils;
+
+    private File repositoryDir;
+
+    private List<String> includes = new ArrayList<String>();
+
+    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<String> getExcludes()
+    {
+        return null;
+    }
+
+    public List<String> 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<Digester> allDigesters = new ArrayList<Digester>( 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 (file)
index 0000000..244be33
--- /dev/null
@@ -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<RepositoryListener> listeners;
+
+    private Logger logger = LoggerFactory.getLogger( "org.apache.archiva.AuditLog" );
+
+    private static final char DELIM = ' ';
+
+    public AbstractRepositoryPurge( ManagedRepositoryContent repository, RepositorySession repositorySession,
+                                    List<RepositoryListener> 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<ArtifactReference> 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 );
+            }
+        }
+    }
+
+    /**
+     * <p>
+     * This find support files for the artifactFile and deletes them.
+     * </p>
+     * <p>
+     * Support Files are things like ".sha1", ".md5", ".asc", etc.
+     * </p>
+     *
+     * @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 + "<system-purge>" + DELIM + "<system>" + 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 (file)
index 0000000..bb55fa8
--- /dev/null
@@ -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 (file)
index 0000000..0041902
--- /dev/null
@@ -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;
+
+/**
+ * <p>
+ * 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.
+ * </p>
+ * <p/>
+ * <p>
+ * So, if you have the following (presented in the m2/default layout form) ...
+ * <pre>
+ *   /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
+ * </pre>
+ * 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.
+ * </p>
+ *
+ * @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<RepositoryListener> 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<String> allVersions = new ArrayList<String>( repository.getVersions( reference ) );
+
+            List<ManagedRepository> 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<String> releasedVersions = new ArrayList<String>();
+            List<String> snapshotVersions = new ArrayList<String>();
+
+            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 (file)
index 0000000..549135f
--- /dev/null
@@ -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<RepositoryListener> 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<String> versions = new ArrayList<String>( 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<ArtifactReference> 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 (file)
index 0000000..f3b6403
--- /dev/null
@@ -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 (file)
index 0000000..827ceca
--- /dev/null
@@ -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<String> includes = new ArrayList<String>();
+
+    private RepositoryPurge repoPurge;
+
+    private RepositoryPurge cleanUp;
+
+    private boolean deleteReleasedSnapshots;
+
+    /**
+     *
+     */
+    @Inject
+    private List<RepositoryListener> 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<String> getExcludes()
+    {
+        return getDefaultArtifactExclusions();
+    }
+
+    public List<String> 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<RepositoryListener>( 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 (file)
index 0000000..eddeea9
--- /dev/null
@@ -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 (file)
index 0000000..fb6c128
--- /dev/null
@@ -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<RepositoryListener> 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<String> versions = new ArrayList<String>( 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<ArtifactReference> 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 (file)
index 2369c6a..0000000
+++ /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<String> includes = new ArrayList<String>();
-    
-    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<String> getExcludes()
-    {
-        return getDefaultArtifactExclusions();
-    }
-
-    public List<String> 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 (file)
index c12fb1f..0000000
+++ /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<String> includes = new ArrayList<String>();
-
-    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<String> getExcludes()
-    {
-        return null;
-    }
-
-    public List<String> 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 (file)
index c4e7e61..0000000
+++ /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<String> includes = new ArrayList<String>();
-
-    private Map<String, String> extensionRenameMap = new HashMap<String, String>();
-
-    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<String> getExcludes()
-    {
-        return null;
-    }
-
-    public List<String> getIncludes()
-    {
-        return includes;
-    }
-
-    public void processFile( String path )
-        throws ConsumerException
-    {
-        File file = new File( this.repositoryDir, path );
-        if ( file.exists() )
-        {
-            Iterator<String> 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 (file)
index 8642a7a..0000000
+++ /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<String> includes = new ArrayList<String>();
-
-    private long scanStartTimestamp = 0;
-
-    public String getDescription()
-    {
-        return description;
-    }
-
-    public String getId()
-    {
-        return id;
-    }
-
-    public void setIncludes( List<String> 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<String> getExcludes()
-    {
-        return getDefaultArtifactExclusions();
-    }
-
-    public List<String> 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 (file)
index 171db69..0000000
+++ /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<Digester> allDigesters;
-
-    @Inject
-    private PlexusSisuBridge plexusSisuBridge;
-
-    @Inject
-    private DigesterUtils digesterUtils;
-
-    private File repositoryDir;
-
-    private List<String> includes = new ArrayList<String>();
-
-    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<String> getExcludes()
-    {
-        return null;
-    }
-
-    public List<String> 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<Digester> allDigesters = new ArrayList<Digester>( 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 (file)
index f34f0b9..0000000
+++ /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<RepositoryListener> listeners;
-
-    private Logger logger = LoggerFactory.getLogger( "org.apache.archiva.AuditLog" );
-
-    private static final char DELIM = ' ';
-
-    public AbstractRepositoryPurge( ManagedRepositoryContent repository, RepositorySession repositorySession,
-                                    List<RepositoryListener> 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<ArtifactReference> 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 );
-            }
-        }
-    }
-
-    /**
-     * <p>
-     * This find support files for the artifactFile and deletes them.
-     * </p>
-     * <p>
-     * Support Files are things like ".sha1", ".md5", ".asc", etc.
-     * </p>
-     *
-     * @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 + "<system-purge>" + DELIM + "<system>" + 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 (file)
index 357aa47..0000000
+++ /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 (file)
index 8e40ad5..0000000
+++ /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;
-
-/**
- * <p>
- * 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.
- * </p>
- * <p/>
- * <p>
- * So, if you have the following (presented in the m2/default layout form) ...
- * <pre>
- *   /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
- * </pre>
- * 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.
- * </p>
- *
- * @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<RepositoryListener> 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<String> allVersions = new ArrayList<String>( repository.getVersions( reference ) );
-
-            List<ManagedRepository> 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<String> releasedVersions = new ArrayList<String>();
-            List<String> snapshotVersions = new ArrayList<String>();
-
-            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 (file)
index e4ffb42..0000000
+++ /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<RepositoryListener> 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<String> versions = new ArrayList<String>( 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<ArtifactReference> 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 (file)
index 297daad..0000000
+++ /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 (file)
index a7186c8..0000000
+++ /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<String> includes = new ArrayList<String>();
-
-    private RepositoryPurge repoPurge;
-
-    private RepositoryPurge cleanUp;
-
-    private boolean deleteReleasedSnapshots;
-
-    /**
-     *
-     */
-    @Inject
-    private List<RepositoryListener> 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<String> getExcludes()
-    {
-        return getDefaultArtifactExclusions();
-    }
-
-    public List<String> 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<RepositoryListener>( 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 (file)
index 0ebf409..0000000
+++ /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 (file)
index 9c60ece..0000000
+++ /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<RepositoryListener> 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<String> versions = new ArrayList<String>( 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<ArtifactReference> related = repository.getRelatedArtifacts( artifact );
-            purge( related );
-        }
-        catch ( ContentNotFoundException e )
-        {
-            // Nothing to do here.
-            // TODO: Log this?
-        }
-    }
-}
index 41be77bd2fa5920ea4416ad35466764112313bc7..db3b65468d6689842a018cf5082ba793df5e1663 100644 (file)
@@ -28,9 +28,9 @@
        default-lazy-init="true">
 
   <context:annotation-config/>
-  <context:component-scan base-package="org.apache.maven.archiva.consumers.core"/>
+  <context:component-scan base-package="org.apache.archiva.consumers.core"/>
 
-  <bean id="artifactMissingChecksumsConsumer" class="org.apache.maven.archiva.consumers.core.ArtifactMissingChecksumsConsumer" scope="prototype">
+  <bean id="artifactMissingChecksumsConsumer" class="org.apache.archiva.consumers.core.ArtifactMissingChecksumsConsumer" scope="prototype">
    <constructor-arg>
      <value>create-missing-checksums</value>
    </constructor-arg>
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 (file)
index 0000000..3d858d7
--- /dev/null
@@ -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 (file)
index 0000000..7e233c0
--- /dev/null
@@ -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 (file)
index 0000000..1ff915a
--- /dev/null
@@ -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 (file)
index 0000000..0831b49
--- /dev/null
@@ -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 (file)
index 0000000..8b457af
--- /dev/null
@@ -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<RepositoryListener> 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 =
+            "<expected><versions><version>2.2</version>" + "<version>2.3</version></versions></expected>";
+
+        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 = "<expected><versions><version>2.0.3-SNAPSHOT</version>"
+            + "<version>2.0.4-SNAPSHOT</version></versions></expected>";
+
+        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 (file)
index 0000000..0f84698
--- /dev/null
@@ -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<RepositoryListener> 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<RepositoryListener> 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 (file)
index 0000000..6c6c37f
--- /dev/null
@@ -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 = "<expected><versions><version>2.3-SNAPSHOT</version></versions></expected>";
+
+        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 =
+            "<expected><versions><version>2.2</version>" + "<version>2.3</version></versions></expected>";
+
+        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 (file)
index 0000000..fa38057
--- /dev/null
@@ -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<RepositoryListener> 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 (file)
index 3a4316e..0000000
+++ /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 (file)
index 8367292..0000000
+++ /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 (file)
index 991291f..0000000
+++ /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 (file)
index c4c9236..0000000
+++ /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 (file)
index 7d378f1..0000000
+++ /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<RepositoryListener> 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 =
-            "<expected><versions><version>2.2</version>" + "<version>2.3</version></versions></expected>";
-
-        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 = "<expected><versions><version>2.0.3-SNAPSHOT</version>"
-            + "<version>2.0.4-SNAPSHOT</version></versions></expected>";
-
-        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 (file)
index 783c65a..0000000
+++ /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<RepositoryListener> 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<RepositoryListener> 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 (file)
index 3700662..0000000
+++ /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 = "<expected><versions><version>2.3-SNAPSHOT</version></versions></expected>";
-
-        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 =
-            "<expected><versions><version>2.2</version>" + "<version>2.3</version></versions></expected>";
-
-        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 (file)
index babac9e..0000000
+++ /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<RepositoryListener> 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" );
-    }
-}
index ea10f40a003b70df09e02910e8e252d7237915b7..0f2224efa5852afa4a73b328e84c1bedd7a0603b 100644 (file)
@@ -32,7 +32,7 @@
 
   <!-- for testing repo purge using retention count -->
 
-  <bean name="knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count" class="org.apache.maven.archiva.consumers.core.repository.RepositoryPurgeConsumer">
+  <bean name="knownRepositoryContentConsumer#repo-purge-consumer-by-retention-count" class="org.apache.archiva.consumers.core.repository.RepositoryPurgeConsumer">
     <property name="configuration" ref="archivaConfiguration#retention-count"/>
     <property name="repositoryContentFactory" ref="repositoryContentFactory#retention-count"/>
     <property name="filetypes" ref="filetypes#retention-count"/>
@@ -69,7 +69,7 @@
   <alias name="filetypes#retention-count" alias="filetypes"/>
 
   <!-- for testing repo purge by # of days old and delete cleanupSnapshots -->
-  <bean name="knownRepositoryContentConsumer#repo-purge-consumer-by-days-old" class="org.apache.maven.archiva.consumers.core.repository.RepositoryPurgeConsumer">
+  <bean name="knownRepositoryContentConsumer#repo-purge-consumer-by-days-old" class="org.apache.archiva.consumers.core.repository.RepositoryPurgeConsumer">
     <property name="configuration" ref="archivaConfiguration#days-old"/>
     <property name="repositoryContentFactory" ref="repositoryContentFactory#days-old"/>
     <property name="filetypes" ref="filetypes#days-old"/>
index da2e09a9e5d80f382787710b26f1ce350005013c..f85d94d05954c10aab86a2d547fcb4ad35f1a0fe 100644 (file)
@@ -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;
index 480c11044d1235c74fd7aef63aad26a444f5351d..4c9d6fe0f4e70b927da882058c666a42d6de1ddd 100644 (file)
@@ -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;
index bd1cba8607cd9ae977a898cbed210c345ec4c336..e2ab24807f871d7de517bea2a32f886244b0c3c7 100644 (file)
@@ -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;
index 34594a061775d65341c65eb3b738cdb337078d80..26a817a481f089ab481d39917e118bfc712e26b6 100644 (file)
@@ -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;
index c0bc6bc1226aa9d816a49ce321e0a0b663d7ed80..4569bc46f49ac512c3e42cf36970db1f15c65a54 100644 (file)
@@ -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;
index f8fcdd2c57ae84cc3b7392ffbb675e128b3dbb1b..b24da6463ef78e3fed7c4f368581e6ba0251ff93 100644 (file)
@@ -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;
 
index 7a0c387a44e463a917c8f5b556c2bc94b89bd30a..a0f73512a136786db3b5600a37ce9b7d04efd686 100644 (file)
@@ -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;
index 40a53c5654a3dff297fd7ad3ab9eabd3f0177305..3dbcf6fba7ffd9a873cb48d48dca556bbb4efede 100644 (file)
@@ -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;
index e0f628e608e2d54ca18ee992a9968d5f0eb491a6..059d6b528ea80a279fdac5424a6612b0138249a1 100644 (file)
@@ -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;
index 370a28df216c704500132e194c14ea769708e5d6..fda9f9fa765d92e0d3cf8c71bfba83fb4f8611f5 100644 (file)
@@ -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;
 
index 4b775bfb0bc1b4b52415efef292e9d6c970023a9..de2c0618648966c2dc21eb562d7b5e785acc7cf9 100644 (file)
@@ -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;
 
index e6a4b6a9cf9d49d3587517be68cc2e44588e9132..77503782535b603e8ed418ab8a33436748c51668 100644 (file)
@@ -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;
 
index 765da49e81b355b6f43092a52847347da9212f70..901925ac60d420afa4263eebe8a996c0656274ff 100644 (file)
@@ -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;
index 0937cbc3314e9fab090f174e486a9131e6d8ef24..caacfd5e5e39c60ac887728dd5cf007b3d869e53 100644 (file)
@@ -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;
index 6596daaa5d196bee64015a83740e1feb0a4b32cf..7e81a10d7d16910717773f2b4b45a8c0a37c1dc8 100644 (file)
@@ -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;
index 840601f07ecf2d0ed83531c755d8eedddd95c31a..89896838bf1d11824f7335c7d996788a52ed26ab 100644 (file)
@@ -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;
index ceba75cd2a672f7ec4683689d90e8119fae0680c..11069bf04c7fc21be64532e9ba66662d06424d04 100644 (file)
@@ -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;
index 67561d784f08692fddf7c80134a79742ec60714b..67811309956fb559d388cce82081ea1e0241a2cf 100644 (file)
@@ -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;
index 89aca8cf56fecb1013a677a7fa51f122b5f9144d..4085cdbba7c27d1b824e7d111ef6e92523d05b88 100644 (file)
@@ -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;
index 5f221617ae21ce30b2be0fecb0c98dfafd76a4d0..1524c289286313fab9b7226e580def997dd22ee6 100644 (file)
@@ -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;
 
index f9118064e43b0e74fbb0aaa5ac5f327586d47a11..77638befa32a9d940d16cd02b83874bb3ac307b7 100644 (file)
@@ -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;
index 875d87994b9fbaf3286767eb9be027d612502a2d..36abd7a79272f7059e62a847872257647e857d46 100644 (file)
@@ -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;
index 196b51064d1a92e14b7d9d61af03fcf668b351ba..df39ec3962dfdb1aec91504253a1d895e1378cff 100644 (file)
@@ -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;
index 93bb997bef8cf7667f31dfe566c9d224ce3f6515..75676975ebd11d9ee3dbf075c706e37f941cde9d 100644 (file)
@@ -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;