*
* @plexus.component role="com.opensymphony.xwork2.Action" role-hint="uploadAction" instantiation-strategy="per-lookup"
*/
+@SuppressWarnings( "serial" )
public class UploadAction
extends PlexusActionSupport
implements Validateable, Preparable, Auditable
int newBuildNumber = -1;
String timestamp = null;
- File metadataFile = getMetadata( targetPath.getAbsolutePath() );
- ArchivaRepositoryMetadata metadata = getMetadata( metadataFile );
+ File versionMetadataFile = getMetadata( targetPath.getAbsolutePath() );
+ ArchivaRepositoryMetadata versionMetadata = getMetadata( versionMetadataFile );
if ( VersionUtil.isSnapshot( version ) )
{
DateFormat fmt = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
fmt.setTimeZone( timezone );
timestamp = fmt.format( lastUpdatedTimestamp );
- if ( metadata.getSnapshotVersion() != null )
+ if ( versionMetadata.getSnapshotVersion() != null )
{
- newBuildNumber = metadata.getSnapshotVersion().getBuildNumber() + 1;
+ newBuildNumber = versionMetadata.getSnapshotVersion().getBuildNumber() + 1;
}
else
{
- metadata.setSnapshotVersion( new SnapshotVersion() );
newBuildNumber = 1;
}
}
}
- // explicitly update only if metadata-updater consumer is not enabled!
- if ( !config.getRepositoryScanning().getKnownContentConsumers().contains( "metadata-updater" ) )
+ // explicitly update only if versionMetadata-updater consumer is not enabled!
+ if ( !config.getRepositoryScanning().getKnownContentConsumers().contains( "versionMetadata-updater" ) )
{
- updateMetadata( metadata, metadataFile, lastUpdatedTimestamp, timestamp, newBuildNumber, fixChecksums );
+ updateProjectMetadata( targetPath.getAbsolutePath(), lastUpdatedTimestamp, timestamp, newBuildNumber,
+ fixChecksums );
+
+ if ( VersionUtil.isSnapshot( version ) )
+ {
+ updateVersionMetadata( versionMetadata, versionMetadataFile, lastUpdatedTimestamp, timestamp,
+ newBuildNumber, fixChecksums );
+ }
}
String msg = "Artifact \'" + groupId + ":" + artifactId + ":" + version +
private File getMetadata( String targetPath )
{
- String artifactPath = targetPath.substring( 0, targetPath.lastIndexOf( File.separatorChar ) );
-
- return new File( artifactPath, MetadataTools.MAVEN_METADATA );
+ return new File( targetPath, MetadataTools.MAVEN_METADATA );
}
private ArchivaRepositoryMetadata getMetadata( File metadataFile )
}
return metadata;
}
+
+
+ /**
+ * Update version level metadata for snapshot artifacts. If it does not exist, create the metadata and fix checksums
+ * if necessary.
+ */
+ private void updateVersionMetadata( ArchivaRepositoryMetadata metadata, File metadataFile,
+ Date lastUpdatedTimestamp, String timestamp, int buildNumber,
+ boolean fixChecksums )
+ throws RepositoryMetadataException
+ {
+ if ( !metadataFile.exists() )
+ {
+ metadata.setGroupId( groupId );
+ metadata.setArtifactId( artifactId );
+ metadata.setVersion( version );
+ }
+
+ if ( metadata.getSnapshotVersion() == null )
+ {
+ metadata.setSnapshotVersion( new SnapshotVersion() );
+ }
+
+ metadata.getSnapshotVersion().setBuildNumber( buildNumber );
+ metadata.getSnapshotVersion().setTimestamp( timestamp );
+ metadata.setLastUpdatedTimestamp( lastUpdatedTimestamp );
+
+ RepositoryMetadataWriter.write( metadata, metadataFile );
+
+ if ( fixChecksums )
+ {
+ fixChecksums( metadataFile );
+ }
+ }
/**
- * Update artifact level metadata. If it does not exist, create the metadata and
- * fix checksums if necessary.
+ * Update artifact level metadata. If it does not exist, create the metadata and fix checksums if necessary.
*/
- private void updateMetadata( ArchivaRepositoryMetadata metadata, File metadataFile, Date lastUpdatedTimestamp,
- String timestamp, int buildNumber, boolean fixChecksums )
+ private void updateProjectMetadata( String targetPath, Date lastUpdatedTimestamp, String timestamp,
+ int buildNumber, boolean fixChecksums )
throws RepositoryMetadataException
{
List<String> availableVersions = new ArrayList<String>();
String latestVersion = version;
- if ( metadataFile.exists() )
+ String projectPath = targetPath.substring( 0, targetPath.lastIndexOf( File.separatorChar ) );
+ File projectMetadataFile = getMetadata( projectPath );
+ ArchivaRepositoryMetadata projectMetadata = getMetadata( projectMetadataFile );
+
+ if ( projectMetadataFile.exists() )
{
- availableVersions = metadata.getAvailableVersions();
+ availableVersions = projectMetadata.getAvailableVersions();
Collections.sort( availableVersions, VersionComparator.getInstance() );
{
availableVersions.add( version );
- metadata.setGroupId( groupId );
- metadata.setArtifactId( artifactId );
+ projectMetadata.setGroupId( groupId );
+ projectMetadata.setArtifactId( artifactId );
}
- if ( metadata.getGroupId() == null )
+ if ( projectMetadata.getGroupId() == null )
{
- metadata.setGroupId( groupId );
+ projectMetadata.setGroupId( groupId );
}
- if ( metadata.getArtifactId() == null )
+
+ if ( projectMetadata.getArtifactId() == null )
{
- metadata.setArtifactId( artifactId );
+ projectMetadata.setArtifactId( artifactId );
}
- metadata.setLatestVersion( latestVersion );
- metadata.setLastUpdatedTimestamp( lastUpdatedTimestamp );
- metadata.setAvailableVersions( availableVersions );
+ projectMetadata.setLatestVersion( latestVersion );
+ projectMetadata.setLastUpdatedTimestamp( lastUpdatedTimestamp );
+ projectMetadata.setAvailableVersions( availableVersions );
if ( !VersionUtil.isSnapshot( version ) )
{
- metadata.setReleasedVersion( latestVersion );
+ projectMetadata.setReleasedVersion( latestVersion );
}
- else
- {
- metadata.getSnapshotVersion().setBuildNumber( buildNumber );
- metadata.getSnapshotVersion().setTimestamp( timestamp );
- }
-
- RepositoryMetadataWriter.write( metadata, metadataFile );
+ RepositoryMetadataWriter.write( projectMetadata, projectMetadataFile );
if ( fixChecksums )
{
- fixChecksums( metadataFile );
+ fixChecksums( projectMetadataFile );
}
}
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
+import org.apache.maven.archiva.model.ArchivaRepositoryMetadata;
+import org.apache.maven.archiva.model.SnapshotVersion;
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.archiva.repository.RepositoryContentFactory;
import org.apache.maven.archiva.repository.RepositoryNotFoundException;
import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
import org.apache.maven.archiva.repository.metadata.MetadataTools;
+import org.apache.maven.archiva.repository.metadata.RepositoryMetadataReader;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.easymock.MockControl;
import org.easymock.classextension.MockClassControl;
uploadAction.setGeneratePom( generatePom );
}
- private void assertAllArtifactsIncludingSupportArtifactsArePresent( String repoLocation )
+ private void assertAllArtifactsIncludingSupportArtifactsArePresent( String repoLocation, String artifact,
+ String version )
{
- assertTrue(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ).exists() );
- assertTrue(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.sha1" ).exists() );
- assertTrue(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.md5" ).exists() );
-
- assertTrue(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
- assertTrue(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ).exists() );
- assertTrue(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ).exists() );
-
- assertTrue(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
- ".sha1" ).exists() );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
- ".md5" ).exists() );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/" + artifact + ".jar" ).exists() );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/" + artifact
+ + ".jar.sha1" ).exists() );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/" + artifact
+ + ".jar.md5" ).exists() );
+
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/" + artifact + ".pom" ).exists() );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/" + artifact
+ + ".pom.sha1" ).exists() );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/" + artifact
+ + ".pom.md5" ).exists() );
+
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA
+ + ".sha1" ).exists() );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA
+ + ".md5" ).exists() );
}
- private void verifyChecksums( String repoLocation )
+ private void verifyVersionMetadataChecksums( String repoLocation, String version )
throws IOException
{
- // verify checksums of jar file
- ChecksummedFile checksum = new ChecksummedFile(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ) );
+ ChecksummedFile checksum =
+ new ChecksummedFile( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/"
+ + MetadataTools.MAVEN_METADATA ) );
String sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
String md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
- String contents = FileUtils.readFileToString(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.sha1" ) );
+ String contents =
+ FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/"
+ + MetadataTools.MAVEN_METADATA + ".sha1" ) );
assertTrue( StringUtils.contains( contents, sha1 ) );
- contents = FileUtils.readFileToString(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.md5" ) );
+ contents =
+ FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/"
+ + MetadataTools.MAVEN_METADATA + ".md5" ) );
assertTrue( StringUtils.contains( contents, md5 ) );
+ }
- // verify checksums of pom file
- checksum = new ChecksummedFile(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
- sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
- md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
+ private void verifyProjectMetadataChecksums( String repoLocation )
+ throws IOException
+ {
+ ChecksummedFile checksum =
+ new ChecksummedFile( new File( repoLocation, "/org/apache/archiva/artifact-upload/"
+ + MetadataTools.MAVEN_METADATA ) );
+ String sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
+ String md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
- contents = FileUtils.readFileToString(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ) );
+ String contents =
+ FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/"
+ + MetadataTools.MAVEN_METADATA + ".sha1" ) );
assertTrue( StringUtils.contains( contents, sha1 ) );
- contents = FileUtils.readFileToString(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ) );
+ contents =
+ FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/"
+ + MetadataTools.MAVEN_METADATA + ".md5" ) );
assertTrue( StringUtils.contains( contents, md5 ) );
+ }
- // verify checksums of metadata file
- checksum = new ChecksummedFile(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ) );
+ private void verifyPomChecksums( String repoLocation, String artifact, String version )
+ throws IOException
+ {
+ ChecksummedFile checksum;
+ String sha1;
+ String md5;
+ String contents;
+ checksum =
+ new ChecksummedFile( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/"
+ + artifact + ".pom" ) );
sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
- contents = FileUtils.readFileToString(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA + ".sha1" ) );
+ contents =
+ FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/"
+ + artifact + ".pom.sha1" ) );
assertTrue( StringUtils.contains( contents, sha1 ) );
- contents = FileUtils.readFileToString(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA + ".md5" ) );
+ contents =
+ FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/"
+ + artifact + ".pom.md5" ) );
assertTrue( StringUtils.contains( contents, md5 ) );
}
- public void testArtifactUploadWithPomSuccessful()
- throws Exception
+ private void verifyArtifactChecksums( String repoLocation, String artifact, String version )
+ throws IOException
{
- setUploadParameters( "1.0", null, new File( getBasedir(),
- "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
- new File( getBasedir(), "target/test-classes/upload-artifact-test/pom.xml" ), false );
-
- ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
- content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
-
- archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
- repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
-
- archivaConfigControl.replay();
- repoFactoryControl.replay();
+ ChecksummedFile checksum =
+ new ChecksummedFile( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/"
+ + artifact + ".jar" ) );
+ String sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
+ String md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
- MockControl control = mockAuditLogs(
- Arrays.asList( "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar",
- "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
+ String contents =
+ FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/"
+ + artifact + ".jar.sha1" ) );
+ assertTrue( StringUtils.contains( contents, sha1 ) );
- String returnString = uploadAction.doUpload();
- assertEquals( Action.SUCCESS, returnString );
+ contents =
+ FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + version + "/"
+ + artifact + ".jar.md5" ) );
+ assertTrue( StringUtils.contains( contents, md5 ) );
+ }
- archivaConfigControl.verify();
- repoFactoryControl.verify();
- control.verify();
+ private String getTimestamp( String[] artifactsList, int startIndex, int index )
+ {
+ int endIndex = -1;
+ String timestamp;
- String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
- assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
+ if ( artifactsList[index].contains( "jar" ) )
+ {
+ endIndex = artifactsList[index].indexOf( ".jar" );
+ }
+ else
+ {
+ endIndex = artifactsList[index].indexOf( ".pom" );
+ }
+
+ timestamp = artifactsList[index].substring( startIndex, endIndex );
- verifyChecksums( repoLocation );
+ return timestamp;
}
-
+
private MockControl mockAuditLogs( List<String> resources )
{
return mockAuditLogs( AuditEvent.UPLOAD_FILE, resources );
uploadAction.setAuditListeners( Collections.singletonList( listener ) );
return control;
}
-
- public void testArtifactUploadWithClassifier()
+
+ public void testArtifactUploadWithPomSuccessful()
throws Exception
{
- setUploadParameters( "1.0", "tests", new File( getBasedir(),
- "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
+ setUploadParameters( "1.0", null, new File( getBasedir(),
+ "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
new File( getBasedir(), "target/test-classes/upload-artifact-test/pom.xml" ), false );
ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
repoFactoryControl.replay();
MockControl control = mockAuditLogs(
- Arrays.asList( "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar",
+ Arrays.asList( "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar",
"org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
String returnString = uploadAction.doUpload();
control.verify();
String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
- assertTrue( new File( repoLocation,
- "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar" ).exists() );
- assertTrue( new File( repoLocation,
- "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.sha1" ).exists() );
- assertTrue( new File( repoLocation,
- "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.md5" ).exists() );
+ assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation, "artifact-upload-1.0", "1.0" );
- assertTrue(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
- assertTrue(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ).exists() );
- assertTrue(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ).exists() );
+ verifyArtifactChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
+ verifyPomChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
+ verifyProjectMetadataChecksums( repoLocation );
+ }
- assertTrue(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
- ".sha1" ).exists() );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
- ".md5" ).exists() );
+ public void testArtifactUploadWithClassifier()
+ throws Exception
+ {
+ setUploadParameters( "1.0", "tests", new File( getBasedir(),
+ "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
+ new File( getBasedir(), "target/test-classes/upload-artifact-test/pom.xml" ), false );
- // verify checksums of jar file
- ChecksummedFile checksum = new ChecksummedFile(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar" ) );
- String sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
- String md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
+ ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
+ content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
- String contents = FileUtils.readFileToString(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.sha1" ) );
- assertTrue( StringUtils.contains( contents, sha1 ) );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
- contents = FileUtils.readFileToString(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.md5" ) );
- assertTrue( StringUtils.contains( contents, md5 ) );
+ archivaConfigControl.replay();
+ repoFactoryControl.replay();
- // verify checksums of jar file
- checksum = new ChecksummedFile(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
- sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
- md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
+ MockControl control = mockAuditLogs(
+ Arrays.asList( "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar",
+ "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
- contents = FileUtils.readFileToString(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ) );
- assertTrue( StringUtils.contains( contents, sha1 ) );
+ String returnString = uploadAction.doUpload();
+ assertEquals( Action.SUCCESS, returnString );
- contents = FileUtils.readFileToString(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ) );
- assertTrue( StringUtils.contains( contents, md5 ) );
+ archivaConfigControl.verify();
+ repoFactoryControl.verify();
+ control.verify();
- // verify checksums of metadata file
- checksum = new ChecksummedFile(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ) );
- sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
- md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
+ String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar" ).exists() );
+ assertTrue( new File( repoLocation,
+ "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.sha1" ).exists() );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.md5" ).exists() );
- contents = FileUtils.readFileToString(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA + ".sha1" ) );
- assertTrue( StringUtils.contains( contents, sha1 ) );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ).exists() );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ).exists() );
- contents = FileUtils.readFileToString(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA + ".md5" ) );
- assertTrue( StringUtils.contains( contents, md5 ) );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA
+ + ".sha1" ).exists() );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA
+ + ".md5" ).exists() );
+
+ verifyArtifactChecksums( repoLocation, "artifact-upload-1.0-tests", "1.0" );
+ verifyProjectMetadataChecksums( repoLocation );
}
public void testArtifactUploadGeneratePomSuccessful()
control.verify();
String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
- assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
+ assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation, "artifact-upload-1.0", "1.0" );
- verifyChecksums( repoLocation );
+ verifyArtifactChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
+ verifyPomChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
+ verifyProjectMetadataChecksums( repoLocation );
}
public void testArtifactUploadNoPomSuccessful()
repoFactoryControl.verify();
String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
- assertFalse(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ).exists() );
+ assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ).exists() );
- assertFalse(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
+ assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
- assertFalse(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
+ assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
}
public void testArtifactUploadSnapshots()
String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
String[] artifactsList = new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/" ).list();
-
- assertEquals( 6, artifactsList.length );
+ Arrays.sort( artifactsList );
+
+ assertEquals( 9, artifactsList.length );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/"
+ + MetadataTools.MAVEN_METADATA ).exists() );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/"
+ + MetadataTools.MAVEN_METADATA + ".sha1" ).exists() );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/"
+ + MetadataTools.MAVEN_METADATA + ".md5" ).exists() );
- assertTrue(
- new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
- ".sha1" ).exists() );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
- ".md5" ).exists() );
-
int startIndex = "artifact-upload-1.0-".length();
- int endIndex = -1;
+ String timestampPath = getTimestamp( artifactsList, startIndex, 0 );
- if ( artifactsList[0].contains( "jar" ) )
- {
- endIndex = artifactsList[0].indexOf( ".jar" );
- }
- else
- {
- endIndex = artifactsList[0].indexOf( ".pom" );
- }
+ assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation, "artifact-upload-1.0-" + timestampPath,
+ "1.0-SNAPSHOT" );
+ verifyArtifactChecksums( repoLocation, "artifact-upload-1.0-" + timestampPath, "1.0-SNAPSHOT" );
+ verifyPomChecksums( repoLocation, "artifact-upload-1.0-" + timestampPath, "1.0-SNAPSHOT" );
+ verifyProjectMetadataChecksums( repoLocation );
+ verifyVersionMetadataChecksums( repoLocation, "1.0-SNAPSHOT" );
- String actualTimestamp = artifactsList[0].substring( startIndex, endIndex );
+ // verify build number
+ File metadataFile =
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/" + MetadataTools.MAVEN_METADATA );
+ ArchivaRepositoryMetadata artifactMetadata = RepositoryMetadataReader.read( metadataFile );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".jar" ).exists() );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".jar.md5" ).exists() );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".jar.sha1" ).exists() );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".pom" ).exists() );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".pom.md5" ).exists() );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".pom.sha1" ).exists() );
+ SnapshotVersion snapshotVersion = artifactMetadata.getSnapshotVersion();
+ assertEquals( "Incorrect build number set in artifact metadata.", 1, snapshotVersion.getBuildNumber() );
- // verify checksums of jar file
- ChecksummedFile checksum =
- new ChecksummedFile( new File( repoLocation,
- "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".jar" ) );
- String sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
- String md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
+ String timestampPart = StringUtils.substringBeforeLast( timestampPath, "-" );
+ assertEquals( "Incorrect timestamp set in artifact metadata.", timestampPart, snapshotVersion.getTimestamp() );
- String contents =
- FileUtils.readFileToString( new File( repoLocation,
- "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".jar.sha1" ) );
- assertTrue( StringUtils.contains( contents, sha1 ) );
+ String buildnumber = StringUtils.substringAfterLast( timestampPath, "-" );
+ assertEquals( "Incorrect build number in filename.", "1", buildnumber );
- contents =
- FileUtils.readFileToString( new File( repoLocation,
- "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".jar.md5" ) );
- assertTrue( StringUtils.contains( contents, md5 ) );
+ archivaConfigControl.reset();
+ repoFactoryControl.reset();
+ control.reset();
- // verify checksums of pom file
- checksum =
- new ChecksummedFile( new File( repoLocation,
- "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".pom" ) );
- sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
- md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
+ control.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
- contents =
- FileUtils.readFileToString( new File( repoLocation,
- "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".pom.sha1" ) );
- assertTrue( StringUtils.contains( contents, sha1 ) );
+ // MRM-1353
+ // upload snapshot artifact again and check if build number was incremented
+ setUploadParameters( "1.0-SNAPSHOT", null,
+ new File( getBasedir(),
+ "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
+ true );
- contents =
- FileUtils.readFileToString( new File( repoLocation,
- "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".pom.md5" ) );
- assertTrue( StringUtils.contains( contents, md5 ) );
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
+
+ archivaConfigControl.replay();
+ repoFactoryControl.replay();
+
+ fmt = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
+ fmt.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
+ timestamp = fmt.format( new Date() );
+
+ control = mockAuditLogs( Arrays.asList(
+ "org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + timestamp + "-2.jar",
+ "org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + timestamp + "-2.pom" ) );
+
+ returnString = uploadAction.doUpload();
+ assertEquals( Action.SUCCESS, returnString );
+ archivaConfigControl.verify();
+ repoFactoryControl.verify();
+ control.verify();
- // verify checksums of metadata file
- checksum =
- new ChecksummedFile( new File( repoLocation, "/org/apache/archiva/artifact-upload/" +
- MetadataTools.MAVEN_METADATA ) );
- sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
- md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
+ artifactsList = new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/" ).list();
+ Arrays.sort( artifactsList );
+
+ assertEquals( 15, artifactsList.length );
- contents =
- FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" +
- MetadataTools.MAVEN_METADATA + ".sha1" ) );
- assertTrue( StringUtils.contains( contents, sha1 ) );
+ timestampPath = getTimestamp( artifactsList, startIndex, 6 );
- contents =
- FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" +
- MetadataTools.MAVEN_METADATA + ".md5" ) );
- assertTrue( StringUtils.contains( contents, md5 ) );
+ assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation, "artifact-upload-1.0-" + timestampPath,
+ "1.0-SNAPSHOT" );
+ verifyArtifactChecksums( repoLocation, "artifact-upload-1.0-" + timestampPath, "1.0-SNAPSHOT" );
+ verifyPomChecksums( repoLocation, "artifact-upload-1.0-" + timestampPath, "1.0-SNAPSHOT" );
+ verifyProjectMetadataChecksums( repoLocation );
+ verifyVersionMetadataChecksums( repoLocation, "1.0-SNAPSHOT" );
+
+ // verify build number set in metadata and in filename
+ metadataFile =
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/" + MetadataTools.MAVEN_METADATA );
+ artifactMetadata = RepositoryMetadataReader.read( metadataFile );
+
+ snapshotVersion = artifactMetadata.getSnapshotVersion();
+ assertEquals( "Incorrect build number set in artifact metadata.", 2, snapshotVersion.getBuildNumber() );
+
+ timestampPart = StringUtils.substringBeforeLast( timestampPath, "-" );
+ assertEquals( "Incorrect timestamp set in artifact metadata.", timestampPart, snapshotVersion.getTimestamp() );
+
+ buildnumber = StringUtils.substringAfterLast( timestampPath, "-" );
+ assertEquals( "Incorrect build number in filename.", "2", buildnumber );
}
public void testChecksumIsCorrectWhenArtifactIsReUploaded()
repoFactoryControl.reset();
String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
- assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
+ assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation, "artifact-upload-1.0", "1.0" );
- verifyChecksums( repoLocation );
+ verifyArtifactChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
+ verifyPomChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
+ verifyProjectMetadataChecksums( repoLocation );
// RE-upload artifact
setUploadParameters( "1.0", null, new File( getBasedir(),
control.verify();
repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
- assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
+ assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation, "artifact-upload-1.0", "1.0" );
- verifyChecksums( repoLocation );
+ verifyArtifactChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
+ verifyPomChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
+ verifyProjectMetadataChecksums( repoLocation );
}
public void testUploadArtifactAlreadyExistingRedeploymentsBlocked()
control.verify();
String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
- assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
+ assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation, "artifact-upload-1.0", "1.0" );
- verifyChecksums( repoLocation );
+ verifyArtifactChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
+ verifyPomChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
+ verifyProjectMetadataChecksums( repoLocation );
}
public void testUploadArtifactAlreadyExistingRedeploymentsAllowed()
control.verify();
String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
- assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
+ assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation, "artifact-upload-1.0", "1.0" );
- verifyChecksums( repoLocation );
+ verifyArtifactChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
+ verifyPomChecksums( repoLocation, "artifact-upload-1.0", "1.0" );
+ verifyProjectMetadataChecksums( repoLocation );
}
-
}