[MRM-453]

- Added tests for metadata driven snapshots in DaysOldRepositoryPurgeTest
- Added test data

Changes made in DaysOldRepositoryPurge:
- Added functionality to consider the metadata driven snapshots (check the timestamp in the filename first before the last modified date of the 
file if it is a unique versioned snapshot)



git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@570089 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Maria Odea B. Ching 2007-08-27 12:27:13 +00:00
parent 51e10b3364
commit 124fe26ea9
23 changed files with 442 additions and 22 deletions

View File

@ -24,13 +24,11 @@ import org.apache.maven.archiva.repository.layout.LayoutException;
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;
/**
@ -66,20 +64,43 @@ public class DaysOldRepositoryPurge
FilenameParts parts = getFilenameParts( path );
if ( VersionUtil.isSnapshot( parts.version ) )
{
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 );
File[] artifactFiles = getFiles( artifactFile.getParentFile(), fileParts[0] );
purge( artifactFiles );
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 ) );
Calendar timestampDate = Calendar.getInstance();
timestampDate.set( year, month, day, hour, min, sec );
if( timestampDate.getTimeInMillis() < olderThanThisDate.getTimeInMillis() )
{
doPurge( artifactFile, parts.extension );
}
else
{
if ( artifactFile.lastModified() < olderThanThisDate.getTimeInMillis() )
{
doPurge( artifactFile, parts.extension );
}
}
}
}
catch ( LayoutException le )
{
@ -87,4 +108,13 @@ public class DaysOldRepositoryPurge
}
}
private void doPurge( File artifactFile, String extension )
{
String[] fileParts = artifactFile.getName().split( "." + extension );
File[] artifactFiles = getFiles( artifactFile.getParentFile(), fileParts[0] );
purge( artifactFiles );
}
}

View File

@ -61,6 +61,9 @@ public class AbstractRepositoryPurgeTest
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";
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";

View File

@ -40,10 +40,9 @@ public class DaysOldRepositoryPurgeTest
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++ )
{
@ -51,15 +50,15 @@ public class DaysOldRepositoryPurgeTest
}
}
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 );
@ -79,6 +78,64 @@ public class DaysOldRepositoryPurgeTest
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
{
@ -86,7 +143,7 @@ public class DaysOldRepositoryPurgeTest
repoPurge = null;
}
private void populateDb()
private void populateDbForTestByLastModified()
throws Exception
{
List versions = new ArrayList();
@ -94,4 +151,17 @@ public class DaysOldRepositoryPurgeTest
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 );
}
}

View File

@ -0,0 +1,12 @@
<?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>

View File

@ -0,0 +1,52 @@
<?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>

View File

@ -0,0 +1,61 @@
<?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>

View File

@ -0,0 +1,61 @@
<?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>

View File

@ -0,0 +1,61 @@
<?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>

View File

@ -0,0 +1,61 @@
<?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>