import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
import org.apache.maven.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.configuration.RepositoryConfiguration;
-import org.apache.maven.archiva.configuration.Configuration;
-import org.apache.maven.archiva.indexer.RepositoryIndexException;
import org.apache.maven.archiva.model.ArchivaRepository;
import org.apache.maven.archiva.database.ArtifactDAO;
+import org.apache.commons.lang.StringUtils;
import java.util.Calendar;
-import java.util.GregorianCalendar;
import java.io.File;
/**
FilenameParts parts = getFilenameParts( path );
- if ( VersionUtil.isSnapshot( parts.version ) )
- {
- Calendar olderThanThisDate = Calendar.getInstance();
- olderThanThisDate.add( Calendar.DATE, ( -1 * repoConfig.getDaysOlder() ) );
+ Calendar olderThanThisDate = Calendar.getInstance();
+ olderThanThisDate.add( Calendar.DATE, ( -1 * repoConfig.getDaysOlder() ) );
+ if ( VersionUtil.isGenericSnapshot( parts.version ) )
+ {
if ( artifactFile.lastModified() < olderThanThisDate.getTimeInMillis() )
{
- String[] fileParts = artifactFile.getName().split( "." + parts.extension );
+ doPurge( artifactFile, parts.extension );
+ }
+ }
+ else if ( VersionUtil.isUniqueSnapshot( parts.version ) )
+ {
+ String[] versionParts = StringUtils.split( parts.version, '-' );
+ String timestamp = StringUtils.remove( versionParts[1], '.' );
+ int year = Integer.parseInt( StringUtils.substring( timestamp, 0, 4 ) );
+ int month = Integer.parseInt( StringUtils.substring( timestamp, 4, 6 ) ) - 1;
+ int day = Integer.parseInt( StringUtils.substring( timestamp, 6, 8 ) );
+ int hour = Integer.parseInt( StringUtils.substring( timestamp, 8, 10 ) );
+ int min = Integer.parseInt( StringUtils.substring( timestamp, 10, 12 ) );
+ int sec = Integer.parseInt( StringUtils.substring( timestamp, 12 ) );
- File[] artifactFiles = getFiles( artifactFile.getParentFile(), fileParts[0] );
+ Calendar timestampDate = Calendar.getInstance();
+ timestampDate.set( year, month, day, hour, min, sec );
- purge( artifactFiles );
+ if( timestampDate.getTimeInMillis() < olderThanThisDate.getTimeInMillis() )
+ {
+ doPurge( artifactFile, parts.extension );
+ }
+ else
+ {
+ if ( artifactFile.lastModified() < olderThanThisDate.getTimeInMillis() )
+ {
+ doPurge( artifactFile, parts.extension );
+ }
}
}
+
}
catch ( LayoutException le )
{
throw new RepositoryPurgeException( le.getMessage() );
}
}
-
+
+ private void doPurge( File artifactFile, String extension )
+ {
+ String[] fileParts = artifactFile.getName().split( "." + extension );
+
+ File[] artifactFiles = getFiles( artifactFile.getParentFile(), fileParts[0] );
+
+ purge( artifactFiles );
+ }
}
+
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-SNAPSHOT.jar";
+ "org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/maven-install-plugin-2.2-SNAPSHOT.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 class DaysOldRepositoryPurgeTest
extends AbstractRepositoryPurgeTest
{
-
+
protected void setUp()
throws Exception
{
repoPurge = new DaysOldRepositoryPurge( getRepository(), getLayout(), dao, getRepoConfiguration() );
}
- private void setLastModified()
+ private void setLastModified( String dirPath )
{
- File dir =
- new File( "target/test/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/" );
+ File dir = new File( dirPath );
File[] contents = dir.listFiles();
for ( int i = 0; i < contents.length; i++ )
{
}
}
- public void testIfAJarIsFound()
+ public void testByLastModified()
throws Exception
{
- populateDb();
+ populateDbForTestByLastModified();
File testDir = new File( "target/test" );
FileUtils.copyDirectoryToDirectory( new File( "target/test-classes/test-repo" ), testDir );
- setLastModified();
+ setLastModified( "target/test/test-repo/org/apache/maven/plugins/maven-install-plugin/2.2-SNAPSHOT/" );
repoPurge.process( PATH_TO_BY_DAYS_OLD_ARTIFACT );
FileUtils.deleteDirectory( testDir );
}
+ public void testMetadataDrivenSnapshots()
+ throws Exception
+ {
+ populateDbForTestMetadataDrivenSnapshots();
+
+ File testDir = new File( "target/test" );
+ FileUtils.copyDirectoryToDirectory( new File( "target/test-classes/test-repo" ), testDir );
+
+ repoPurge.process( PATH_TO_BY_DAYS_OLD_METADATA_DRIVEN_ARTIFACT );
+
+ // this should be deleted since the filename version (timestamp) is older than
+ // 100 days even if the last modified date was <100 days ago
+ assertFalse( new File(
+ "target/test/test-repo/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070113.163208-4.jar" ).exists() );
+ assertFalse( new File(
+ "target/test/test-repo/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070113.163208-4.jar.sha1" ).exists() );
+ assertFalse( new File(
+ "target/test/test-repo/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070113.163208-4.pom" ).exists() );
+ assertFalse( new File(
+ "target/test/test-repo/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070113.163208-4.pom.sha1" ).exists() );
+
+ // musn't be deleted since the filename version (timestamp) is not older than 100 days
+ assertTrue( new File(
+ "target/test/test-repo/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070618.102615-5.jar" ).exists() );
+ assertTrue( new File(
+ "target/test/test-repo/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070618.102615-5.jar.sha1" ).exists() );
+ assertTrue( new File(
+ "target/test/test-repo/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070618.102615-5.pom" ).exists() );
+ assertTrue( new File(
+ "target/test/test-repo/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070618.102615-5.pom.sha1" ).exists() );
+
+ assertTrue( new File(
+ "target/test/test-repo/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070630.113158-6.jar" ).exists() );
+ assertTrue( new File(
+ "target/test/test-repo/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070630.113158-6.jar.sha1" ).exists() );
+ assertTrue( new File(
+ "target/test/test-repo/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070630.113158-6.pom" ).exists() );
+ assertTrue( new File(
+ "target/test/test-repo/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070630.113158-6.pom.sha1" ).exists() );
+
+ assertTrue( new File(
+ "target/test/test-repo/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070707.122114-7.jar" ).exists() );
+ assertTrue( new File(
+ "target/test/test-repo/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070707.122114-7.jar.sha1" ).exists() );
+ assertTrue( new File(
+ "target/test/test-repo/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070707.122114-7.pom" ).exists() );
+ assertTrue( new File(
+ "target/test/test-repo/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-20070707.122114-7.pom.sha1" ).exists() );
+
+ // mustn't be deleted since the last modified date is <100 days (this is not a timestamped version)
+ assertTrue( new File(
+ "target/test/test-repo/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-SNAPSHOT.jar" ).exists() );
+ assertTrue( new File(
+ "target/test/test-repo/org/codehaus/plexus/plexus-utils/1.4.3-SNAPSHOT/plexus-utils-1.4.3-SNAPSHOT.pom" ).exists() );
+
+ FileUtils.deleteDirectory( testDir );
+ }
+
protected void tearDown()
throws Exception
{
repoPurge = null;
}
- private void populateDb()
+ private void populateDbForTestByLastModified()
throws Exception
{
List versions = new ArrayList();
populateDb( "org.apache.maven.plugins", "maven-install-plugin", versions );
}
+
+ private void populateDbForTestMetadataDrivenSnapshots()
+ throws Exception
+ {
+ List versions = new ArrayList();
+ versions.add( "1.4.3-20070113.163208-4" );
+ versions.add( "1.4.3-20070618.102615-5" );
+ versions.add( "1.4.3-20070630.113158-6" );
+ versions.add( "1.4.3-20070707.122114-7" );
+ versions.add( "1.4.3-SNAPSHOT" );
+
+ populateDb( "org.codehaus.plexus", "plexus-utils", versions );
+ }
}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?><metadata>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>1.4.3-SNAPSHOT</version>
+ <versioning>
+ <snapshot>
+ <timestamp>20070707.122114</timestamp>
+ <buildNumber>7</buildNumber>
+ </snapshot>
+ <lastUpdated>20070707122118</lastUpdated>
+ </versioning>
+</metadata>
\ No newline at end of file
--- /dev/null
+9bf3732f0d4f32363e3331630def1832ab991007
\ No newline at end of file
--- /dev/null
+4055e3444fc6be00eafe634ea738930b22cf5475
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?><project>
+ <parent>
+ <artifactId>plexus</artifactId>
+ <groupId>org.codehaus.plexus</groupId>
+ <version>1.0.11</version>
+ <relativePath>../pom/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>plexus-utils</artifactId>
+ <name>Plexus Common Utilities</name>
+ <version>1.4.3-20070613.163208-4</version>
+ <url>http://plexus.codehaus.org/plexus-utils</url>
+ <scm>
+ <connection>scm:svn:http://svn.codehaus.org/plexus/plexus-utils/trunk/</connection>
+ <developerConnection>scm:svn:https://svn.codehaus.org/plexus/plexus-utils/trunk</developerConnection>
+ <url>http://fisheye.codehaus.org/browse/plexus/plexus-utils/trunk/</url>
+ </scm>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.3</source>
+ <target>1.3</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <childDelegation>true</childDelegation>
+ <excludes>
+ <exclude>org/codehaus/plexus/util/FileBasedTestCase.java</exclude>
+ <exclude>**/Test*.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jxr-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </reporting>
+ <distributionManagement>
+ <status>deployed</status>
+ </distributionManagement>
+</project>
\ No newline at end of file
--- /dev/null
+8f771b7916b90153ff2c1ba0f3102df6faa08652
\ No newline at end of file
--- /dev/null
+a2237ddc9e7925b4badd748afd7f62ec0a800630
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?><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">
+ <parent>
+ <artifactId>plexus</artifactId>
+ <groupId>org.codehaus.plexus</groupId>
+ <version>1.0.11</version>
+ <relativePath>../pom/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>plexus-utils</artifactId>
+ <name>Plexus Common Utilities</name>
+ <version>1.4.3-SNAPSHOT</version>
+ <url>http://plexus.codehaus.org/plexus-utils</url>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <!-- surefire requires plexus-utils to be jdk 1.3 compatible -->
+ <source>1.3</source>
+ <target>1.3</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <!-- required to ensure the test classes are used, not surefire's plexus-utils -->
+ <childDelegation>true</childDelegation>
+ <excludes>
+ <exclude>org/codehaus/plexus/util/FileBasedTestCase.java</exclude>
+ <exclude>**/Test*.java</exclude>
+ </excludes>
+ <systemProperties>
+ <property>
+ <name>JAVA_HOME</name>
+ <value>${JAVA_HOME}</value>
+ </property>
+ <property>
+ <name>M2_HOME</name>
+ <value>${M2_HOME}</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <scm>
+ <connection>scm:svn:http://svn.codehaus.org/plexus/plexus-utils/trunk/</connection>
+ <developerConnection>scm:svn:https://svn.codehaus.org/plexus/plexus-utils/trunk</developerConnection>
+ <url>http://fisheye.codehaus.org/browse/plexus/plexus-utils/trunk/</url>
+ </scm>
+ <reporting>
+ <plugins>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jxr-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>
--- /dev/null
+730554bce63d59d4411f971397adee9ad2e63ce5
\ No newline at end of file
--- /dev/null
+4e700aed4f9883d3e614a41377ecc713dd97307e
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?><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">
+ <parent>
+ <artifactId>plexus</artifactId>
+ <groupId>org.codehaus.plexus</groupId>
+ <version>1.0.11</version>
+ <relativePath>../pom/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>plexus-utils</artifactId>
+ <name>Plexus Common Utilities</name>
+ <version>1.4.3-SNAPSHOT</version>
+ <url>http://plexus.codehaus.org/plexus-utils</url>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <!-- surefire requires plexus-utils to be jdk 1.3 compatible -->
+ <source>1.3</source>
+ <target>1.3</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <!-- required to ensure the test classes are used, not surefire's plexus-utils -->
+ <childDelegation>true</childDelegation>
+ <excludes>
+ <exclude>org/codehaus/plexus/util/FileBasedTestCase.java</exclude>
+ <exclude>**/Test*.java</exclude>
+ </excludes>
+ <systemProperties>
+ <property>
+ <name>JAVA_HOME</name>
+ <value>${JAVA_HOME}</value>
+ </property>
+ <property>
+ <name>M2_HOME</name>
+ <value>${M2_HOME}</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <scm>
+ <connection>scm:svn:http://svn.codehaus.org/plexus/plexus-utils/trunk/</connection>
+ <developerConnection>scm:svn:https://svn.codehaus.org/plexus/plexus-utils/trunk</developerConnection>
+ <url>http://fisheye.codehaus.org/browse/plexus/plexus-utils/trunk/</url>
+ </scm>
+ <reporting>
+ <plugins>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jxr-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>
--- /dev/null
+730554bce63d59d4411f971397adee9ad2e63ce5
\ No newline at end of file
--- /dev/null
+7a78a6050e8c582fd5818c218c37532b9b3c23d1
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?><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">
+ <parent>
+ <artifactId>plexus</artifactId>
+ <groupId>org.codehaus.plexus</groupId>
+ <version>1.0.11</version>
+ <relativePath>../pom/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>plexus-utils</artifactId>
+ <name>Plexus Common Utilities</name>
+ <version>1.4.3-SNAPSHOT</version>
+ <url>http://plexus.codehaus.org/plexus-utils</url>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <!-- surefire requires plexus-utils to be jdk 1.3 compatible -->
+ <source>1.3</source>
+ <target>1.3</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <!-- required to ensure the test classes are used, not surefire's plexus-utils -->
+ <childDelegation>true</childDelegation>
+ <excludes>
+ <exclude>org/codehaus/plexus/util/FileBasedTestCase.java</exclude>
+ <exclude>**/Test*.java</exclude>
+ </excludes>
+ <systemProperties>
+ <property>
+ <name>JAVA_HOME</name>
+ <value>${JAVA_HOME}</value>
+ </property>
+ <property>
+ <name>M2_HOME</name>
+ <value>${M2_HOME}</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <scm>
+ <connection>scm:svn:http://svn.codehaus.org/plexus/plexus-utils/trunk/</connection>
+ <developerConnection>scm:svn:https://svn.codehaus.org/plexus/plexus-utils/trunk</developerConnection>
+ <url>http://fisheye.codehaus.org/browse/plexus/plexus-utils/trunk/</url>
+ </scm>
+ <reporting>
+ <plugins>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jxr-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>
--- /dev/null
+730554bce63d59d4411f971397adee9ad2e63ce5
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?><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">
+ <parent>
+ <artifactId>plexus</artifactId>
+ <groupId>org.codehaus.plexus</groupId>
+ <version>1.0.11</version>
+ <relativePath>../pom/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>plexus-utils</artifactId>
+ <name>Plexus Common Utilities</name>
+ <version>1.4.3-SNAPSHOT</version>
+ <url>http://plexus.codehaus.org/plexus-utils</url>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <!-- surefire requires plexus-utils to be jdk 1.3 compatible -->
+ <source>1.3</source>
+ <target>1.3</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <!-- required to ensure the test classes are used, not surefire's plexus-utils -->
+ <childDelegation>true</childDelegation>
+ <excludes>
+ <exclude>org/codehaus/plexus/util/FileBasedTestCase.java</exclude>
+ <exclude>**/Test*.java</exclude>
+ </excludes>
+ <systemProperties>
+ <property>
+ <name>JAVA_HOME</name>
+ <value>${JAVA_HOME}</value>
+ </property>
+ <property>
+ <name>M2_HOME</name>
+ <value>${M2_HOME}</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <scm>
+ <connection>scm:svn:http://svn.codehaus.org/plexus/plexus-utils/trunk/</connection>
+ <developerConnection>scm:svn:https://svn.codehaus.org/plexus/plexus-utils/trunk</developerConnection>
+ <url>http://fisheye.codehaus.org/browse/plexus/plexus-utils/trunk/</url>
+ </scm>
+ <reporting>
+ <plugins>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jxr-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>