continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r679588 [4/8] - in /continuum/branches/CONTINUUM-782: ./ continuum-api/ continuum-api/src/main/java/org/apache/continuum/purge/ continuum-api/src/main/java/org/apache/continuum/purge/controller/ continuum-api/src/main/java/org/apache/contin...
Date Thu, 24 Jul 2008 22:31:26 GMT
Propchange: continuum/branches/CONTINUUM-782/continuum-purge-07242008.patch
------------------------------------------------------------------------------
    svn:executable = *

Added: continuum/branches/CONTINUUM-782/continuum-purge/pom.xml
URL: http://svn.apache.org/viewvc/continuum/branches/CONTINUUM-782/continuum-purge/pom.xml?rev=679588&view=auto
==============================================================================
--- continuum/branches/CONTINUUM-782/continuum-purge/pom.xml (added)
+++ continuum/branches/CONTINUUM-782/continuum-purge/pom.xml Thu Jul 24 15:31:19 2008
@@ -0,0 +1,130 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>continuum</artifactId>
+    <groupId>org.apache.continuum</groupId>
+    <version>1.2-SNAPSHOT</version>
+  </parent>
+  <artifactId>continuum-purge</artifactId>
+  <name>Continuum Purge System</name>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.continuum</groupId>
+      <artifactId>continuum-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.continuum</groupId>
+      <artifactId>continuum-commons</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.continuum</groupId>
+      <artifactId>continuum-release</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-taskqueue</artifactId>
+    </dependency>
+	<dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>archiva-common</artifactId>
+      <version>${archiva.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>archiva-core-consumers</artifactId>
+      <version>${archiva.version}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.archiva</groupId>
+          <artifactId>archiva-database</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.apache.archiva</groupId>
+          <artifactId>archiva-configuration</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.apache.archiva</groupId>
+          <artifactId>archiva-indexer</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.apache.archiva</groupId>
+          <artifactId>archiva-consumer-api</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.apache.archiva</groupId>
+          <artifactId>archiva-repository-layer</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>archiva-repository-layer</artifactId>
+      <version>${archiva.version}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.archiva</groupId>
+          <artifactId>archiva-configuration</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
+    <!-- === Testing Dependencies === -->
+    <dependency>
+      <groupId>hsqldb</groupId>
+      <artifactId>hsqldb</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.continuum</groupId>
+      <artifactId>continuum-test</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.plexus</groupId>
+        <artifactId>plexus-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>generate</id>
+            <goals>
+              <goal>descriptor</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>merge</id>
+            <goals>
+              <goal>merge-descriptors</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+    <testResources>
+      <testResource>
+        <directory>src/test/resources</directory>
+      </testResource>
+    </testResources>
+  </build>
+</project>

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/ContinuumPurgeConstants.java
URL: http://svn.apache.org/viewvc/continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/ContinuumPurgeConstants.java?rev=679588&view=auto
==============================================================================
--- continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/ContinuumPurgeConstants.java (added)
+++ continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/ContinuumPurgeConstants.java Thu Jul 24 15:31:19 2008
@@ -0,0 +1,10 @@
+package org.apache.continuum.purge;
+
+public class ContinuumPurgeConstants
+{
+    public static final String PURGE_REPOSITORY = "repository";
+    
+    public static final String PURGE_DIRECTORY_RELEASES = "releases";
+    
+    public static final String PURGE_DIRECTORY_BUILDOUTPUT = "buildOutput";
+}

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/ContinuumPurgeConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/ContinuumPurgeConstants.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Added: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/DefaultPurgeConfigurationService.java
URL: http://svn.apache.org/viewvc/continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/DefaultPurgeConfigurationService.java?rev=679588&view=auto
==============================================================================
--- continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/DefaultPurgeConfigurationService.java (added)
+++ continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/DefaultPurgeConfigurationService.java Thu Jul 24 15:31:19 2008
@@ -0,0 +1,355 @@
+package org.apache.continuum.purge;
+
+/*
+ * 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.ArrayList;
+import java.util.List;
+
+import org.apache.continuum.model.repository.AbstractPurgeConfiguration;
+import org.apache.continuum.model.repository.DirectoryPurgeConfiguration;
+import org.apache.continuum.model.repository.LocalRepository;
+import org.apache.continuum.model.repository.RepositoryPurgeConfiguration;
+import org.apache.continuum.purge.repository.content.RepositoryManagedContent;
+import org.apache.maven.continuum.store.ContinuumObjectNotFoundException;
+import org.apache.maven.continuum.store.ContinuumStore;
+import org.apache.maven.continuum.store.ContinuumStoreException;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
+
+/**
+ * DefaultPurgeConfigurationService
+ * 
+ * @author Maria Catherine Tan
+ * @plexus.component role="org.apache.continuum.purge.PurgeConfigurationService" role-hint="default"
+ */
+public class DefaultPurgeConfigurationService
+    implements PurgeConfigurationService, Contextualizable
+{
+    /**
+     * @plexus.requirement role-hint="jdo"
+     */
+    private ContinuumStore store;
+ 
+    private PlexusContainer container;
+ 
+    public AbstractPurgeConfiguration addPurgeConfiguration( AbstractPurgeConfiguration purgeConfig )
+        throws PurgeConfigurationServiceException
+    {
+        AbstractPurgeConfiguration purgeConfiguration = null;
+        
+        if ( purgeConfig instanceof RepositoryPurgeConfiguration )
+        {
+            purgeConfiguration = addRepositoryPurgeConfiguration( (RepositoryPurgeConfiguration) purgeConfig );
+        }
+        else if ( purgeConfig instanceof DirectoryPurgeConfiguration )
+        {
+            purgeConfiguration = addDirectoryPurgeConfiguration( (DirectoryPurgeConfiguration) purgeConfig );
+        }
+        
+        return purgeConfiguration;
+    }
+    
+    public void updatePurgeConfiguration( AbstractPurgeConfiguration purgeConfig )
+        throws PurgeConfigurationServiceException
+    {
+        if ( purgeConfig instanceof RepositoryPurgeConfiguration )
+        {
+            updateRepositoryPurgeConfiguration( (RepositoryPurgeConfiguration) purgeConfig );
+        }
+        else if ( purgeConfig instanceof DirectoryPurgeConfiguration )
+        {
+            updateDirectoryPurgeConfiguration( (DirectoryPurgeConfiguration) purgeConfig );
+        }
+    }
+    
+    public void removePurgeConfiguration( int purgeConfigId )
+        throws PurgeConfigurationServiceException
+    {
+        AbstractPurgeConfiguration purgeConfig = getPurgeConfiguration( purgeConfigId );
+        
+        if ( purgeConfig instanceof RepositoryPurgeConfiguration )
+        {
+            removeRepositoryPurgeConfiguration( (RepositoryPurgeConfiguration) purgeConfig );
+        }
+        else if ( purgeConfig instanceof DirectoryPurgeConfiguration )
+        {
+            removeDirectoryPurgeConfiguration( (DirectoryPurgeConfiguration) purgeConfig );
+        }
+    }
+    
+    public DirectoryPurgeConfiguration addDirectoryPurgeConfiguration( DirectoryPurgeConfiguration dirPurge )
+        throws PurgeConfigurationServiceException
+    {
+        DirectoryPurgeConfiguration dirPurgeConfig = null;
+        
+        try
+        {
+            dirPurgeConfig = store.addDirectoryPurgeConfiguration( dirPurge );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new PurgeConfigurationServiceException( e.getMessage(), e );
+        }
+        
+        return dirPurgeConfig;
+    }
+    
+    public RepositoryPurgeConfiguration addRepositoryPurgeConfiguration( RepositoryPurgeConfiguration repoPurge )
+        throws PurgeConfigurationServiceException
+    {
+        RepositoryPurgeConfiguration repoPurgeConfig = null;
+        
+        try
+        {
+            repoPurgeConfig = store.addRepositoryPurgeConfiguration( repoPurge );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new PurgeConfigurationServiceException( e.getMessage(), e );
+        }
+        
+        return repoPurgeConfig;
+    }
+    
+    public RepositoryPurgeConfiguration getDefaultPurgeConfigurationForRepository( int repositoryId )
+    {
+        List<RepositoryPurgeConfiguration> purgeConfigs = getRepositoryPurgeConfigurationsByRepository( repositoryId );
+        
+        for ( RepositoryPurgeConfiguration purgeConfig : purgeConfigs )
+        {
+            if ( purgeConfig.isDefaultPurge() )
+            {
+                return purgeConfig;
+            }
+        }
+        
+        return null;
+    }
+    
+    public List<DirectoryPurgeConfiguration> getAllDirectoryPurgeConfigurations()
+    {
+        return store.getAllDirectoryPurgeConfigurations();
+    }
+    
+    public List<RepositoryPurgeConfiguration> getAllRepositoryPurgeConfigurations()
+    {
+        return store.getAllRepositoryPurgeConfigurations();
+    }
+    
+    public List<AbstractPurgeConfiguration> getAllPurgeConfigurations()
+    {
+        List<RepositoryPurgeConfiguration> repoPurge = getAllRepositoryPurgeConfigurations();
+        List<DirectoryPurgeConfiguration> dirPurge = getAllDirectoryPurgeConfigurations();
+        
+        List<AbstractPurgeConfiguration> allPurgeConfigs = new ArrayList<AbstractPurgeConfiguration>();
+        
+        allPurgeConfigs.addAll( repoPurge );
+        allPurgeConfigs.addAll( dirPurge );
+        
+        return allPurgeConfigs;
+    }
+    
+    public DirectoryPurgeConfiguration getDefaultPurgeConfigurationForDirectoryType( String directoryType )
+    {
+        List<DirectoryPurgeConfiguration> purgeConfigs = store.getDirectoryPurgeConfigurationsByType( directoryType );
+        
+        for ( DirectoryPurgeConfiguration purgeConfig : purgeConfigs )
+        {
+            if ( purgeConfig.isDefaultPurge() )
+            {
+                return purgeConfig;
+            }
+        }
+        
+        return null;
+    }
+    
+    public List<DirectoryPurgeConfiguration> getDirectoryPurgeConfigurationsByLocation( String location )
+    {
+        return store.getDirectoryPurgeConfigurationsByLocation( location );
+    }
+    
+    public List<DirectoryPurgeConfiguration> getDirectoryPurgeConfigurationsBySchedule( int scheduleId )
+    {
+        return store.getDirectoryPurgeConfigurationsBySchedule( scheduleId );
+    }
+    
+    public List<RepositoryPurgeConfiguration> getRepositoryPurgeConfigurationsByRepository( int repositoryId )
+    {
+        return store.getRepositoryPurgeConfigurationsByLocalRepository( repositoryId );
+    }
+    
+    public List<RepositoryPurgeConfiguration> getRepositoryPurgeConfigurationsBySchedule( int scheduleId )
+    {
+        return store.getRepositoryPurgeConfigurationsBySchedule( scheduleId );
+    }
+    
+    public void removeDirectoryPurgeConfiguration( DirectoryPurgeConfiguration purgeConfig )
+        throws PurgeConfigurationServiceException
+    {
+        try
+        {
+            store.removeDirectoryPurgeConfiguration( purgeConfig );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new PurgeConfigurationServiceException( e.getMessage(), e );
+        }
+    }
+    
+    public void removeRepositoryPurgeConfiguration( RepositoryPurgeConfiguration purgeConfig )
+        throws PurgeConfigurationServiceException
+    {
+        try
+        {
+            store.removeRepositoryPurgeConfiguration( purgeConfig );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new PurgeConfigurationServiceException( e.getMessage(), e );
+        }
+    }
+    
+    public void updateDirectoryPurgeConfiguration( DirectoryPurgeConfiguration purgeConfig )
+        throws PurgeConfigurationServiceException
+    {
+        try
+        {
+            store.updateDirectoryPurgeConfiguration( purgeConfig );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new PurgeConfigurationServiceException( e.getMessage(), e );
+        }
+    }
+    
+    public void updateRepositoryPurgeConfiguration( RepositoryPurgeConfiguration purgeConfig )
+        throws PurgeConfigurationServiceException
+    {
+        try
+        {
+            store.updateRepositoryPurgeConfiguration( purgeConfig );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new PurgeConfigurationServiceException( e.getMessage(), e );
+        }
+    }
+    
+    public DirectoryPurgeConfiguration getDirectoryPurgeConfiguration( int purgeConfigId )
+        throws PurgeConfigurationServiceException
+    {
+        try
+        {
+            return store.getDirectoryPurgeConfiguration( purgeConfigId );
+        }
+        catch ( ContinuumObjectNotFoundException e )
+        {
+            throw new PurgeConfigurationServiceException( e.getMessage(), e );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new PurgeConfigurationServiceException( e.getMessage(), e );
+        }
+    }
+    
+    public RepositoryPurgeConfiguration getRepositoryPurgeConfiguration( int purgeConfigId )
+        throws PurgeConfigurationServiceException
+    {
+        try
+        {
+            return store.getRepositoryPurgeConfiguration( purgeConfigId );
+        }
+        catch ( ContinuumObjectNotFoundException e )
+        {
+            throw new PurgeConfigurationServiceException( e.getMessage(), e );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new PurgeConfigurationServiceException( e.getMessage(), e );
+        }
+    }
+    
+    public AbstractPurgeConfiguration getPurgeConfiguration( int purgeConfigId )
+    {
+        AbstractPurgeConfiguration purgeConfig = null;
+        
+        try
+        {
+            purgeConfig = getRepositoryPurgeConfiguration( purgeConfigId );
+        }
+        catch ( PurgeConfigurationServiceException e )
+        {
+            // purgeConfigId is not of type repository purge configuration
+        }
+        
+        if ( purgeConfig == null )
+        {
+            try
+            {
+                purgeConfig = getDirectoryPurgeConfiguration( purgeConfigId );
+            }
+            catch ( PurgeConfigurationServiceException e )
+            {
+                // purgeConfigId is not of type directory purge configuration
+            }
+        }
+        
+        return purgeConfig;
+    }
+    
+    public RepositoryManagedContent getManagedRepositoryContent( int repositoryId )
+        throws PurgeConfigurationServiceException
+    {
+        try
+        {
+            LocalRepository repository = store.getLocalRepository( repositoryId );
+            
+            RepositoryManagedContent repoContent;
+            
+            repoContent = (RepositoryManagedContent) container.lookup( RepositoryManagedContent.class, repository.getLayout() );
+            repoContent.setRepository( repository );
+            
+            return repoContent;
+        }
+        catch ( ContinuumObjectNotFoundException e )
+        {
+            throw new PurgeConfigurationServiceException( "Error retrieving managed repository content for: " + repositoryId, e );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new PurgeConfigurationServiceException( "Error retrieving managed repository content for: " + repositoryId, e );
+        }
+        catch ( ComponentLookupException e )
+        {
+            throw new PurgeConfigurationServiceException( "Error retrieving managed repository content for: " + repositoryId, e );
+        }
+    }
+    
+    public void contextualize( Context context )
+        throws ContextException
+    {
+        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+    }
+}

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/DefaultPurgeConfigurationService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/DefaultPurgeConfigurationService.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Added: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/controller/DirectoryPurgeController.java
URL: http://svn.apache.org/viewvc/continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/controller/DirectoryPurgeController.java?rev=679588&view=auto
==============================================================================
--- continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/controller/DirectoryPurgeController.java (added)
+++ continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/controller/DirectoryPurgeController.java Thu Jul 24 15:31:19 2008
@@ -0,0 +1,73 @@
+package org.apache.continuum.purge.controller;
+
+/*
+ * 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.continuum.model.repository.AbstractPurgeConfiguration;
+import org.apache.continuum.model.repository.DirectoryPurgeConfiguration;
+import org.apache.continuum.purge.executor.CleanAllPurgeExecutor;
+import org.apache.continuum.purge.executor.ContinuumPurgeExecutor;
+import org.apache.continuum.purge.executor.ContinuumPurgeExecutorException;
+import org.apache.continuum.purge.executor.DaysOldDirectoryPurgeExecutor;
+import org.apache.continuum.purge.executor.RetentionCountDirectoryPurgeExecutor;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
+/**
+ * DirectoryPurgeController
+ * 
+ * @author Maria Catherine Tan
+ * @plexus.component role="org.apache.continuum.purge.controller.PurgeController" role-hint="purge-directory"
+ */
+public class DirectoryPurgeController
+    extends AbstractLogEnabled
+    implements PurgeController
+{
+    private ContinuumPurgeExecutor purgeExecutor;
+    
+    public void doPurge( String path ) 
+    {
+        try 
+        {
+            purgeExecutor.purge( path );
+        }
+        catch ( ContinuumPurgeExecutorException e )
+        {
+            getLogger().error( e.getMessage(), e );
+        }
+    }
+
+    public void initializeExecutors( AbstractPurgeConfiguration purgeConfig )
+        throws ContinuumPurgeExecutorException
+    {
+        DirectoryPurgeConfiguration dirPurge = (DirectoryPurgeConfiguration) purgeConfig;
+        
+        if ( dirPurge.isDeleteAll() )
+        {
+            purgeExecutor = new CleanAllPurgeExecutor( dirPurge.getDirectoryType() );
+        }
+        else if ( dirPurge.getDaysOlder() > 0 )
+        {
+            purgeExecutor = new DaysOldDirectoryPurgeExecutor( dirPurge.getDaysOlder(), dirPurge.getRetentionCount(), dirPurge.getDirectoryType() );
+        }
+        else
+        {
+            purgeExecutor = new RetentionCountDirectoryPurgeExecutor( dirPurge.getRetentionCount(), dirPurge.getDirectoryType() );
+        }
+    }
+}

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/controller/DirectoryPurgeController.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/controller/DirectoryPurgeController.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Added: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/controller/RepositoryPurgeController.java
URL: http://svn.apache.org/viewvc/continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/controller/RepositoryPurgeController.java?rev=679588&view=auto
==============================================================================
--- continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/controller/RepositoryPurgeController.java (added)
+++ continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/controller/RepositoryPurgeController.java Thu Jul 24 15:31:19 2008
@@ -0,0 +1,109 @@
+package org.apache.continuum.purge.controller;
+
+/*
+ * 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.continuum.model.repository.AbstractPurgeConfiguration;
+import org.apache.continuum.model.repository.RepositoryPurgeConfiguration;
+import org.apache.continuum.purge.ContinuumPurgeConstants;
+import org.apache.continuum.purge.PurgeConfigurationService;
+import org.apache.continuum.purge.PurgeConfigurationServiceException;
+import org.apache.continuum.purge.executor.CleanAllPurgeExecutor;
+import org.apache.continuum.purge.executor.ContinuumPurgeExecutor;
+import org.apache.continuum.purge.executor.ContinuumPurgeExecutorException;
+import org.apache.continuum.purge.executor.DaysOldRepositoryPurgeExecutor;
+import org.apache.continuum.purge.executor.ReleasedSnapshotsRepositoryPurgeExecutor;
+import org.apache.continuum.purge.executor.RetentionCountRepositoryPurgeExecutor;
+import org.apache.continuum.purge.repository.content.RepositoryManagedContent;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
+/**
+ * DefaultPurgeController
+ * 
+ * @author Maria Catherine Tan
+ * @plexus.component role="org.apache.continuum.purge.controller.PurgeController" role-hint="purge-repository"
+ */
+public class RepositoryPurgeController
+    extends AbstractLogEnabled
+    implements PurgeController
+{
+    private ContinuumPurgeExecutor purgeExecutor;
+    
+    private ContinuumPurgeExecutor purgeReleasedSnapshotsExecutor;
+    
+    /**
+     * @plexus.requirement
+     */
+    private PurgeConfigurationService purgeConfigurationService;
+    
+    private boolean deleteReleasedSnapshots = false;
+    
+    public void initializeExecutors( AbstractPurgeConfiguration purgeConfig )
+        throws ContinuumPurgeExecutorException
+    {
+        RepositoryManagedContent repositoryContent;
+     
+        RepositoryPurgeConfiguration repoPurge = (RepositoryPurgeConfiguration) purgeConfig;
+        
+        try
+        {
+            repositoryContent = purgeConfigurationService.getManagedRepositoryContent( repoPurge.getRepository().getId() );
+        }
+        catch( PurgeConfigurationServiceException e )
+        {
+            throw new ContinuumPurgeExecutorException( "Error while initializing purge executors", e );
+        }
+            
+        if ( repoPurge.isDeleteAll() )
+        {
+            purgeExecutor = new CleanAllPurgeExecutor( ContinuumPurgeConstants.PURGE_REPOSITORY );
+        }
+        else 
+        {    
+            if ( repoPurge.getDaysOlder() > 0 )
+            {
+                purgeExecutor = new DaysOldRepositoryPurgeExecutor( repositoryContent, repoPurge.getDaysOlder(), repoPurge.getRetentionCount() );
+            }
+            else
+            {
+                purgeExecutor = new RetentionCountRepositoryPurgeExecutor( repositoryContent, repoPurge.getRetentionCount() );
+            }
+            
+            purgeReleasedSnapshotsExecutor = new ReleasedSnapshotsRepositoryPurgeExecutor( repositoryContent );
+            deleteReleasedSnapshots = repoPurge.isDeleteReleasedSnapshots();
+        }
+    }
+    
+    public void doPurge( String path )
+    {
+        try 
+        {
+            if ( deleteReleasedSnapshots)
+            {
+                purgeReleasedSnapshotsExecutor.purge( path );
+            }
+            
+            purgeExecutor.purge( path );
+        }
+        catch ( ContinuumPurgeExecutorException e )
+        {
+            getLogger().error( e.getMessage(), e );
+        }
+    }
+}
\ No newline at end of file

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/controller/RepositoryPurgeController.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/controller/RepositoryPurgeController.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Added: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/AbstractContinuumPurgeExecutor.java
URL: http://svn.apache.org/viewvc/continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/AbstractContinuumPurgeExecutor.java?rev=679588&view=auto
==============================================================================
--- continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/AbstractContinuumPurgeExecutor.java (added)
+++ continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/AbstractContinuumPurgeExecutor.java Thu Jul 24 15:31:19 2008
@@ -0,0 +1,83 @@
+package org.apache.continuum.purge.executor;
+
+/*
+ * 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.File;
+import java.io.FilenameFilter;
+import java.util.Set;
+
+import org.apache.continuum.purge.repository.content.RepositoryManagedContent;
+import org.apache.maven.archiva.consumers.core.repository.ArtifactFilenameFilter;
+import org.apache.maven.archiva.model.ArtifactReference;
+
+/**
+ * Some codes were taken from Archiva.
+ * @author Maria Catherine Tan
+ */
+public abstract class AbstractContinuumPurgeExecutor
+    implements ContinuumPurgeExecutor
+{
+    public void purge( Set<ArtifactReference> references, RepositoryManagedContent repository )
+    {
+        if( references != null && !references.isEmpty() )
+        {
+            for ( ArtifactReference reference : references )
+            {
+                File artifactFile = repository.toFile( reference );
+                artifactFile.delete();
+                purgeSupportFiles( artifactFile, artifactFile.getName() );
+                // purge maven metadata
+                purgeSupportFiles( artifactFile.getParentFile(), "maven-metadata" );
+            }
+        }
+    }
+    
+    /**
+     * <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.
+     */
+    protected void purgeSupportFiles( File artifactFile, String filename )
+    {
+        File parentDir = artifactFile.getParentFile();
+
+        if ( !parentDir.exists() )
+        {
+            return;
+        }
+
+        FilenameFilter filter = new ArtifactFilenameFilter( filename );
+
+        File[] files = parentDir.listFiles( filter );
+
+        for ( File file : files )
+        {
+            if ( file.exists() && file.isFile() )
+            {
+                file.delete();
+            }
+        }
+    }
+}
\ No newline at end of file

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/AbstractContinuumPurgeExecutor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/AbstractContinuumPurgeExecutor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Added: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/CleanAllPurgeExecutor.java
URL: http://svn.apache.org/viewvc/continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/CleanAllPurgeExecutor.java?rev=679588&view=auto
==============================================================================
--- continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/CleanAllPurgeExecutor.java (added)
+++ continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/CleanAllPurgeExecutor.java Thu Jul 24 15:31:19 2008
@@ -0,0 +1,118 @@
+package org.apache.continuum.purge.executor;
+
+/*
+ * 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.File;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
+import java.io.IOException;
+
+import org.apache.commons.io.filefilter.DirectoryFileFilter;
+import org.apache.continuum.purge.ContinuumPurgeConstants;
+import org.apache.maven.archiva.consumers.core.repository.ArtifactFilenameFilter;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * @author Maria Catherine Tan
+ */
+public class CleanAllPurgeExecutor
+    extends AbstractContinuumPurgeExecutor
+{
+    private String purgeType;
+    
+    public CleanAllPurgeExecutor( String purgeType )
+    {
+        this.purgeType = purgeType;
+    }
+    
+    public void purge( String path )
+        throws ContinuumPurgeExecutorException
+    {
+        if ( purgeType.equals( ContinuumPurgeConstants.PURGE_REPOSITORY ) )
+        {
+            purgeRepository( path );
+        }
+        else if ( purgeType.equals( ContinuumPurgeConstants.PURGE_DIRECTORY_RELEASES ) )
+        {
+            purgeReleases( path );
+        }
+        else if ( purgeType.equals( ContinuumPurgeConstants.PURGE_DIRECTORY_BUILDOUTPUT ) )
+        {
+            purgeBuildOutput( path );
+        }
+    }
+    
+    private void purgeRepository( String path )
+        throws ContinuumPurgeExecutorException
+    {
+        try
+        {
+            FileUtils.cleanDirectory( path );
+        }
+        catch ( IOException e )
+        {
+            throw new ContinuumPurgeExecutorException( "Error while purging all artifacts or directories in " + path, e );
+        }
+    }
+    
+    private void purgeReleases( String path )
+        throws ContinuumPurgeExecutorException
+    {
+        File workingDir = new File( path );
+        
+        FilenameFilter filter = new ArtifactFilenameFilter( "releases-" );
+        
+        File[] releasesDir = workingDir.listFiles( filter );
+        
+        try
+        {
+            for ( File releaseDir : releasesDir )
+            {
+                FileUtils.deleteDirectory( releaseDir );
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new ContinuumPurgeExecutorException( "Error while purging all releases directories", e );
+        }
+    }
+    
+    private void purgeBuildOutput( String path )
+        throws ContinuumPurgeExecutorException
+    {
+        File buildOutputDir = new File( path );
+        
+        FileFilter filter = DirectoryFileFilter.DIRECTORY;
+        
+        File[] projectsDir = buildOutputDir.listFiles( filter );
+     
+        try
+        {
+            for ( File projectDir : projectsDir )
+            {
+                FileUtils.cleanDirectory( projectDir );
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new ContinuumPurgeExecutorException( "Error while purging all buildOutput directories", e );
+        }
+    }
+}

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/CleanAllPurgeExecutor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/CleanAllPurgeExecutor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Added: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/DaysOldDirectoryPurgeExecutor.java
URL: http://svn.apache.org/viewvc/continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/DaysOldDirectoryPurgeExecutor.java?rev=679588&view=auto
==============================================================================
--- continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/DaysOldDirectoryPurgeExecutor.java (added)
+++ continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/DaysOldDirectoryPurgeExecutor.java Thu Jul 24 15:31:19 2008
@@ -0,0 +1,166 @@
+package org.apache.continuum.purge.executor;
+
+/*
+ * 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.File;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Calendar;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.comparator.LastModifiedFileComparator;
+import org.apache.commons.io.filefilter.DirectoryFileFilter;
+import org.apache.commons.lang.time.DateUtils;
+import org.apache.continuum.purge.ContinuumPurgeConstants;
+import org.apache.maven.archiva.consumers.core.repository.ArtifactFilenameFilter;
+
+/**
+ * @author Maria Catherine Tan
+ */
+public class DaysOldDirectoryPurgeExecutor
+    extends AbstractContinuumPurgeExecutor
+    implements ContinuumPurgeExecutor
+{
+    private int daysOlder;
+    
+    private int retentionCount;
+    
+    private String directoryType;
+    
+    public DaysOldDirectoryPurgeExecutor( int daysOlder, int retentionCount, String directoryType )
+    {
+        this.daysOlder = daysOlder;
+        
+        this.retentionCount = retentionCount;
+        
+        this.directoryType = directoryType;
+    }
+
+    public void purge( String path )
+        throws ContinuumPurgeExecutorException
+    {
+        if ( directoryType.equals( ContinuumPurgeConstants.PURGE_DIRECTORY_RELEASES ) )
+        {
+            purgeReleaseDirectory( path );
+        }
+        else if ( directoryType.equals( ContinuumPurgeConstants.PURGE_DIRECTORY_BUILDOUTPUT ) )
+        {
+            purgeBuildOutputDirectory( path );
+        }
+    }
+    
+    private void purgeReleaseDirectory( String path )
+    {
+        File releaseDir = new File( path );
+        
+        FilenameFilter filter = new ArtifactFilenameFilter( "releases-" );
+            
+        File[] releasesDir = releaseDir.listFiles( filter );
+            
+        if ( retentionCount > releasesDir.length )
+        {
+            return;
+        }
+        
+        Arrays.sort( releasesDir, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR );
+            
+        Calendar olderThanThisDate = Calendar.getInstance( DateUtils.UTC_TIME_ZONE );
+        olderThanThisDate.add( Calendar.DATE, -daysOlder );
+        
+        int countToPurge = releasesDir.length - retentionCount;
+        
+        for ( File dir : releasesDir )
+        {
+            if ( countToPurge <= 0 )
+            {
+                break;
+            }
+            
+            if ( dir.lastModified() < olderThanThisDate.getTimeInMillis() )
+            {
+                try
+                {
+                    FileUtils.deleteDirectory( dir );
+                    countToPurge--;
+                }
+                catch ( IOException e )
+                {
+                    //throw new ContinuumPurgeExecutorException( "Error while purging release directories", e );
+                }
+            }
+        }
+    }
+    
+    private void purgeBuildOutputDirectory( String path )
+    {
+        File buildOutputDir = new File( path );
+        
+        FileFilter filter = DirectoryFileFilter.DIRECTORY;
+        
+        File[] projectsDir = buildOutputDir.listFiles( filter );
+        
+        for ( File projectDir : projectsDir )
+        {
+            File[] buildsDir = projectDir.listFiles( filter );
+            
+            if ( retentionCount > buildsDir.length )
+            {
+                continue;
+            }
+            
+            int countToPurge = buildsDir.length - retentionCount;
+            
+            Calendar olderThanThisDate = Calendar.getInstance( DateUtils.UTC_TIME_ZONE );
+            olderThanThisDate.add( Calendar.DATE, -daysOlder );
+            
+            Arrays.sort( buildsDir, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR );
+            
+            for ( File buildDir : buildsDir )
+            {
+                if ( countToPurge <= 0 )
+                {
+                    break;
+                }
+                
+                if ( buildDir.lastModified() < olderThanThisDate.getTimeInMillis() )
+                {
+                    try
+                    {
+                        FileUtils.deleteDirectory( buildDir );
+                        File logFile = new File ( buildDir.getAbsoluteFile() + ".log.txt" );
+                        
+                        if ( logFile.exists() )
+                        {
+                            logFile.delete();   
+                        }
+                        
+                        countToPurge--;
+                    }
+                    catch ( IOException e )
+                    {
+                        // swallow?
+                    }
+                }
+            }
+        }
+    }
+}

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/DaysOldDirectoryPurgeExecutor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/DaysOldDirectoryPurgeExecutor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Added: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/DaysOldRepositoryPurgeExecutor.java
URL: http://svn.apache.org/viewvc/continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/DaysOldRepositoryPurgeExecutor.java?rev=679588&view=auto
==============================================================================
--- continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/DaysOldRepositoryPurgeExecutor.java (added)
+++ continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/DaysOldRepositoryPurgeExecutor.java Thu Jul 24 15:31:19 2008
@@ -0,0 +1,200 @@
+package org.apache.continuum.purge.executor;
+
+/*
+ * 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.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;
+
+import org.apache.commons.lang.time.DateUtils;
+import org.apache.continuum.purge.repository.content.RepositoryManagedContent;
+import org.apache.maven.archiva.common.utils.VersionComparator;
+import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.model.VersionedReference;
+import org.apache.maven.archiva.repository.ContentNotFoundException;
+import org.apache.maven.archiva.repository.layout.LayoutException;
+
+/**
+ * Codes were taken from  Archiva's DaysOldRepositoryPurge and made some few changes.
+ * 
+ * @author Maria Catherine Tan
+ */
+public class DaysOldRepositoryPurgeExecutor
+    extends AbstractContinuumPurgeExecutor
+    implements ContinuumPurgeExecutor
+{
+    private int daysOlder;
+    
+    private int retentionCount;
+    
+    private RepositoryManagedContent repository;
+    
+    private SimpleDateFormat timestampParser;
+    
+    public DaysOldRepositoryPurgeExecutor( RepositoryManagedContent repository, int daysOlder, int retentionCount )
+    {
+        this.repository = repository;
+        this.daysOlder = daysOlder;
+        this.retentionCount = retentionCount;
+        timestampParser = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
+        timestampParser.setTimeZone( DateUtils.UTC_TIME_ZONE );
+    }
+    
+    public void purge( String path )
+        throws ContinuumPurgeExecutorException
+    {
+        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 );
+                        countToPurge--;
+                    }
+                }
+                // 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 );
+                        countToPurge--;
+                    }
+                    else if ( newArtifactFile.lastModified() < olderThanThisDate.getTimeInMillis() )
+                    {
+                        doPurgeAllRelated( newArtifactReference );
+                        countToPurge--;
+                    }
+                }
+            }
+        }
+        catch ( LayoutException e )
+        {
+            throw new ContinuumPurgeExecutorException( e.getMessage() + ": " + path, e );
+        }
+        catch ( ContentNotFoundException e )
+        {
+            throw new ContinuumPurgeExecutorException( e.getMessage(), e );
+        }
+    }
+    
+    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 )
+        throws LayoutException
+    {
+        try
+        {
+            Set<ArtifactReference> related = repository.getRelatedArtifacts( reference );
+            purge( related, repository );
+        }
+        catch ( ContentNotFoundException e )
+        {
+            // Nothing to do here.
+            // TODO: Log this?
+        }
+    }
+}
\ No newline at end of file

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/DaysOldRepositoryPurgeExecutor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/DaysOldRepositoryPurgeExecutor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Added: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/ReleasedSnapshotsRepositoryPurgeExecutor.java
URL: http://svn.apache.org/viewvc/continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/ReleasedSnapshotsRepositoryPurgeExecutor.java?rev=679588&view=auto
==============================================================================
--- continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/ReleasedSnapshotsRepositoryPurgeExecutor.java (added)
+++ continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/ReleasedSnapshotsRepositoryPurgeExecutor.java Thu Jul 24 15:31:19 2008
@@ -0,0 +1,134 @@
+package org.apache.continuum.purge.executor;
+
+/*
+ * 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.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.continuum.purge.repository.content.RepositoryManagedContent;
+import org.apache.maven.archiva.common.utils.VersionComparator;
+import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.model.ProjectReference;
+import org.apache.maven.archiva.model.VersionedReference;
+import org.apache.maven.archiva.repository.ContentNotFoundException;
+import org.apache.maven.archiva.repository.layout.LayoutException;
+
+/**
+ * Codes were taken from Archiva's CleanupReleasedSnapshotsRepositoryPurge and just made some few changes
+ * 
+ * @author Maria Catherine Tan
+ */
+public class ReleasedSnapshotsRepositoryPurgeExecutor
+    extends AbstractContinuumPurgeExecutor
+{
+    private RepositoryManagedContent repository;
+    
+    public ReleasedSnapshotsRepositoryPurgeExecutor( RepositoryManagedContent repository )
+    {
+        this.repository = repository;
+    }
+    
+    public void purge( String path )
+        throws ContinuumPurgeExecutorException
+    {
+        try
+        {
+            File artifactFile = new File( repository.getRepoRoot(), path );
+    
+            if ( !artifactFile.exists() )
+            {
+                // Nothing to do here, file doesn't exist, skip it.
+                return;
+            }
+    
+            ArtifactReference artifact = repository.toArtifactReference( path );
+    
+            if ( !VersionUtil.isSnapshot( artifact.getVersion() ) )
+            {
+                // Nothing to do here, not a snapshot, skip it.
+                return;
+            }
+    
+            ProjectReference reference = new ProjectReference();
+            reference.setGroupId( artifact.getGroupId() );
+            reference.setArtifactId( artifact.getArtifactId() );
+            
+            // Gather up all of the versions.
+            List<String> allVersions = new ArrayList<String>( repository.getVersions( reference ) );
+            
+            // 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() );
+            
+            VersionedReference versionRef = new VersionedReference();
+            versionRef.setGroupId( artifact.getGroupId() );
+            versionRef.setArtifactId( artifact.getArtifactId() );
+            
+            for ( String version : snapshotVersions )
+            {   
+                if( releasedVersions.contains( VersionUtil.getReleaseVersion( version ) ) )
+                {                    
+                    versionRef.setVersion( version );
+                    repository.deleteVersion( versionRef );
+                    
+                    removeMetadata( versionRef );
+                }
+            }
+        }
+        catch ( LayoutException e )
+        {
+            throw new ContinuumPurgeExecutorException( e.getMessage(), e );
+        }
+        catch ( ContentNotFoundException e )
+        {
+            throw new ContinuumPurgeExecutorException( e.getMessage(), e );
+        }
+    }
+    
+    private void removeMetadata( VersionedReference versionRef )
+        throws ContinuumPurgeExecutorException
+    {
+        String path = repository.toMetadataPath( versionRef );
+        File projectPath = new File( repository.getRepoRoot(), path );
+        
+        File projectDir = projectPath.getParentFile();
+        
+        purgeSupportFiles( projectDir, "maven-metadata" );
+    }
+}
\ No newline at end of file

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/ReleasedSnapshotsRepositoryPurgeExecutor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/ReleasedSnapshotsRepositoryPurgeExecutor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Added: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/RetentionCountDirectoryPurgeExecutor.java
URL: http://svn.apache.org/viewvc/continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/RetentionCountDirectoryPurgeExecutor.java?rev=679588&view=auto
==============================================================================
--- continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/RetentionCountDirectoryPurgeExecutor.java (added)
+++ continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/RetentionCountDirectoryPurgeExecutor.java Thu Jul 24 15:31:19 2008
@@ -0,0 +1,146 @@
+package org.apache.continuum.purge.executor;
+
+/*
+ * 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.File;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.comparator.LastModifiedFileComparator;
+import org.apache.commons.io.filefilter.DirectoryFileFilter;
+import org.apache.continuum.purge.ContinuumPurgeConstants;
+import org.apache.maven.archiva.consumers.core.repository.ArtifactFilenameFilter;
+
+/**
+ * @author Maria Catherine Tan
+ */
+public class RetentionCountDirectoryPurgeExecutor
+    extends AbstractContinuumPurgeExecutor
+    implements ContinuumPurgeExecutor
+{    
+    private int retentionCount;
+    
+    private String directoryType;
+    
+    public RetentionCountDirectoryPurgeExecutor( int retentionCount, String directoryType )
+    {
+        this.retentionCount = retentionCount;
+        
+        this.directoryType = directoryType;
+    }
+    
+    public void purge( String path )
+        throws ContinuumPurgeExecutorException
+    {
+        if ( directoryType.equals( ContinuumPurgeConstants.PURGE_DIRECTORY_RELEASES ) )
+        {
+            purgeReleaseDirectory( path );
+        }
+        else if ( directoryType.equals( ContinuumPurgeConstants.PURGE_DIRECTORY_BUILDOUTPUT ) )
+        {
+            purgeBuildOutputDirectory( path );
+        }        
+    }
+    
+    private void purgeReleaseDirectory( String path )
+    {
+        File releaseDir = new File( path );
+        
+        FilenameFilter filter = new ArtifactFilenameFilter( "releases-" );
+        
+        File[] files = releaseDir.listFiles( filter );
+        
+        if ( retentionCount > files.length )
+        {
+            return;
+        }
+    
+        Arrays.sort( files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR );
+        
+        int countToPurge = files.length - retentionCount;
+        
+        for ( File file : files )
+        {
+            if ( countToPurge-- <= 0 )
+            {
+                break;
+            }
+            
+            try
+            {
+                FileUtils.deleteDirectory( file );
+                countToPurge--;
+            }
+            catch ( IOException e )
+            {
+                //throw new ContinuumPurgeExecutorException( "Error while purging release directories", e );
+            }
+        }
+    }
+    
+    private void purgeBuildOutputDirectory( String path )
+    {
+        File buildOutputDir = new File( path );
+        
+        FileFilter filter = DirectoryFileFilter.DIRECTORY;
+        
+        File[] projectsDir = buildOutputDir.listFiles( filter );
+        
+        for ( File projectDir : projectsDir )
+        {
+            File[] buildsDir = projectDir.listFiles( filter );
+            
+            if ( retentionCount > buildsDir.length )
+            {
+                continue;
+            }
+        
+            Arrays.sort( buildsDir, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR );
+            
+            int countToPurge = buildsDir.length - retentionCount;
+            
+            for ( File buildDir : buildsDir )
+            {
+                if ( countToPurge-- <= 0 )
+                {
+                    break;
+                }
+                
+                try
+                {
+                    FileUtils.deleteDirectory( buildDir );
+                    File logFile = new File ( buildDir.getAbsoluteFile() + ".log.txt" );
+                    
+                    if ( logFile.exists() )
+                    {
+                        logFile.delete();   
+                    }
+                }
+                catch ( IOException e )
+                {
+                    //swallow?
+                }
+            }
+        }
+    }
+}

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/RetentionCountDirectoryPurgeExecutor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/RetentionCountDirectoryPurgeExecutor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Added: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/RetentionCountRepositoryPurgeExecutor.java
URL: http://svn.apache.org/viewvc/continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/RetentionCountRepositoryPurgeExecutor.java?rev=679588&view=auto
==============================================================================
--- continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/RetentionCountRepositoryPurgeExecutor.java (added)
+++ continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/RetentionCountRepositoryPurgeExecutor.java Thu Jul 24 15:31:19 2008
@@ -0,0 +1,131 @@
+package org.apache.continuum.purge.executor;
+
+/*
+ * 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.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.continuum.purge.repository.content.RepositoryManagedContent;
+import org.apache.maven.archiva.common.utils.VersionComparator;
+import org.apache.maven.archiva.common.utils.VersionUtil;
+import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.model.VersionedReference;
+import org.apache.maven.archiva.repository.ContentNotFoundException;
+import org.apache.maven.archiva.repository.layout.LayoutException;
+
+/**
+ * Codes were taken from Archiva's RetentionCountRepository Purge and made some few changes.
+ * 
+ * @author Maria Catherine Tan
+ */
+public class RetentionCountRepositoryPurgeExecutor
+    extends AbstractContinuumPurgeExecutor
+    implements ContinuumPurgeExecutor
+{
+    private int retentionCount;
+    
+    private RepositoryManagedContent repository;
+
+    public RetentionCountRepositoryPurgeExecutor( RepositoryManagedContent repository, int retentionCount )
+    {
+        this.repository = repository;
+        this.retentionCount = retentionCount;
+    }
+    
+    public void purge( String path )
+        throws ContinuumPurgeExecutorException
+    {
+        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 e )
+        {
+            throw new ContinuumPurgeExecutorException( e.getMessage(), e );
+        }
+        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, repository );
+        }
+        catch ( ContentNotFoundException e )
+        {
+            // Nothing to do here.
+            // TODO: Log this?
+        }
+    }
+}
\ No newline at end of file

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/RetentionCountRepositoryPurgeExecutor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/CONTINUUM-782/continuum-purge/src/main/java/org/apache/continuum/purge/executor/RetentionCountRepositoryPurgeExecutor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id



Mime
View raw message