*/
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;
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;
* 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;
--- /dev/null
+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;
+ }
+
+
+}
--- /dev/null
+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 );
+}
--- /dev/null
+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 );
+ }
+}
--- /dev/null
+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 );
+}
--- /dev/null
+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
+}
--- /dev/null
+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
+}
--- /dev/null
+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();
+}
--- /dev/null
+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;
+ }
+}
--- /dev/null
+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;
+ }
+
+}
+++ /dev/null
-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;
- }
-
-
-}
+++ /dev/null
-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 );
-}
+++ /dev/null
-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 );
- }
-}
+++ /dev/null
-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 );
-}
+++ /dev/null
-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
-}
+++ /dev/null
-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
-}
+++ /dev/null
-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();
-}
+++ /dev/null
-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;
- }
-}
+++ /dev/null
-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;
- }
-
-}
--- /dev/null
+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();
+ }
+}
--- /dev/null
+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();
+ }
+}
--- /dev/null
+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 );
+ }
+}
--- /dev/null
+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();
+ }
+}
--- /dev/null
+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() );
+ }
+ }
+}
--- /dev/null
+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 );
+ }
+}
--- /dev/null
+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 ) );
+ }
+}
--- /dev/null
+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.
+ }
+ }
+}
--- /dev/null
+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 );
+ }
+ }
+}
--- /dev/null
+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;
+
+}
--- /dev/null
+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;
+ }
+}
--- /dev/null
+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 );
+ }
+}
--- /dev/null
+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?
+ }
+ }
+}
+++ /dev/null
-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();
- }
-}
+++ /dev/null
-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();
- }
-}
+++ /dev/null
-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 );
- }
-}
+++ /dev/null
-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();
- }
-}
+++ /dev/null
-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() );
- }
- }
-}
+++ /dev/null
-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 );
- }
-}
+++ /dev/null
-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 ) );
- }
-}
+++ /dev/null
-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.
- }
- }
-}
+++ /dev/null
-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 );
- }
- }
-}
+++ /dev/null
-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;
-
-}
+++ /dev/null
-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;
- }
-}
+++ /dev/null
-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 );
- }
-}
+++ /dev/null
-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?
- }
- }
-}
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>
--- /dev/null
+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 ) );
+ }
+}
--- /dev/null
+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 } ) );
+ }
+}
--- /dev/null
+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
--- /dev/null
+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(), "." );
+ }
+}
--- /dev/null
+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 );
+ }
+}
--- /dev/null
+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;
+ }
+}
--- /dev/null
+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 );
+ }
+}
--- /dev/null
+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" );
+ }
+}
+++ /dev/null
-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 ) );
- }
-}
+++ /dev/null
-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 } ) );
- }
-}
+++ /dev/null
-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
+++ /dev/null
-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(), "." );
- }
-}
+++ /dev/null
-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 );
- }
-}
+++ /dev/null
-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;
- }
-}
+++ /dev/null
-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 );
- }
-}
+++ /dev/null
-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" );
- }
-}
<!-- 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"/>
<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"/>
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;
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;
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;
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;
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;
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;
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;
*/
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;
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;
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;
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;
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;
*/
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;
*/
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;
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;
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;
*/
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;
*/
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;
*/
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;
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;
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;
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;
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;
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;