import org.apache.commons.lang.time.DateUtils;
import java.io.File;
-import java.io.IOException;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
public class DaysOldRepositoryPurgeTest
extends AbstractRepositoryPurgeTest
{
- private static final String[] extensions =
- new String[] { "-5.jar", "-5.pom", "-6.jar", "-6.pom", "-7.jar", "-7.pom" };
-
- private String year;
-
- private String mon;
-
- private String day;
-
- private String hr;
-
- private String min;
-
- private String sec;
-
private void setLastModified( String dirPath, long lastModified )
{
File dir = new File( dirPath );
Calendar currentDate = Calendar.getInstance( DateUtils.UTC_TIME_ZONE );
setLastModified( versionRoot, currentDate.getTimeInMillis() );
- year = String.valueOf( currentDate.get( Calendar.YEAR ) );
- mon = String.valueOf( currentDate.get( Calendar.MONTH ) + 1 );
- day = String.valueOf( currentDate.get( Calendar.DATE ) );
- hr = String.valueOf( currentDate.get( Calendar.HOUR ) );
- min = String.valueOf( currentDate.get( Calendar.MINUTE ) );
- sec = String.valueOf( currentDate.get( Calendar.SECOND ) );
-
- if ( mon.length() == 1 )
- {
- mon = "0" + mon;
- }
-
- if ( day.length() == 1 )
- {
- day = "0" + day;
- }
+ String timestamp = new SimpleDateFormat( "yyyyMMdd.HHmmss" ).format( currentDate.getTime() );
- if ( hr.length() == 1 )
+ for ( int i = 5; i <= 7; i++ )
{
- hr = "0" + hr;
+ new File( versionRoot, "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".jar" ).createNewFile();
+ new File( versionRoot, "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".pom" ).createNewFile();
}
- if ( min.length() == 1 )
- {
- min = "0" + min;
- }
-
- if ( sec.length() == 1 )
- {
- sec = "0" + sec;
- }
-
- createFiles( versionRoot );
-
List<String> versions = new ArrayList<String>();
versions.add( "1.4.3-20070113.163208-4" );
- versions.add( "1.4.3-" + year + mon + day + "." + hr + min + sec + "-5" );
- versions.add( "1.4.3-" + year + mon + day + "." + hr + min + sec + "-6" );
- versions.add( "1.4.3-" + year + mon + day + "." + hr + min + sec + "-7" );
+ versions.add( "1.4.3-" + timestamp + "-5" );
+ versions.add( "1.4.3-" + timestamp + "-6" );
+ versions.add( "1.4.3-" + timestamp + "-7" );
versions.add( "1.4.3-SNAPSHOT" );
// test listeners for the correct artifacts
assertExists( versionRoot + "/plexus-utils-1.4.3-SNAPSHOT.jar" );
assertExists( versionRoot + "/plexus-utils-1.4.3-SNAPSHOT.pom" );
- for ( int i = 0; i < extensions.length; i++ )
- {
- assertExists( versionRoot + "/plexus-utils-1.4.3-" + year + mon + day + "." + hr + min + sec +
- extensions[i] );
- }
- }
-
- private void createFiles( String versionRoot )
- throws IOException
- {
- for ( int i = 0; i < extensions.length; i++ )
+ for ( int i = 5; i <= 7; i++ )
{
- File file =
- new File( versionRoot, "/plexus-utils-1.4.3-" + year + mon + day + "." + hr + min + sec + extensions[i] );
- file.createNewFile();
+ assertExists( versionRoot + "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".jar" );
+ assertExists( versionRoot + "/plexus-utils-1.4.3-" + timestamp + "-" + i + ".pom" );
}
}