diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java index a23bc334e..349f4eab9 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java @@ -42,6 +42,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.common.utils.VersionComparator; import org.apache.maven.archiva.common.utils.VersionUtil; import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.model.ArchivaProjectModel; import org.apache.maven.archiva.model.ArchivaRepositoryMetadata; @@ -292,8 +293,9 @@ public class UploadAction { try { + Configuration config = configuration.getConfiguration(); ManagedRepositoryConfiguration repoConfig = - configuration.getConfiguration().findManagedRepositoryById( repositoryId ); + config.findManagedRepositoryById( repositoryId ); ArtifactReference artifactReference = new ArtifactReference(); artifactReference.setArtifactId( artifactId ); @@ -345,9 +347,11 @@ public class UploadAction filename = filename.replaceAll( "SNAPSHOT", timestamp + "-" + newBuildNumber ); } + boolean fixChecksums = !( config.getRepositoryScanning().getKnownContentConsumers().contains( "create-missing-checksums" ) ); + try { - copyFile( artifactFile, targetPath, filename ); + copyFile( artifactFile, targetPath, filename, fixChecksums ); queueRepositoryTask( repository.getId(), repository.toFile( artifactReference ) ); } catch ( IOException ie ) @@ -362,13 +366,16 @@ public class UploadAction pomFilename = StringUtils.remove( pomFilename, "-" + classifier ); } pomFilename = FilenameUtils.removeExtension( pomFilename ) + ".pom"; - + if ( generatePom ) { try { File generatedPomFile = createPom( targetPath, pomFilename ); - fixChecksums( generatedPomFile ); + if( fixChecksums ) + { + fixChecksums( generatedPomFile ); + } queueRepositoryTask( repoConfig.getId(), generatedPomFile ); } catch ( IOException ie ) @@ -387,7 +394,7 @@ public class UploadAction { try { - copyFile( pomFile, targetPath, pomFilename ); + copyFile( pomFile, targetPath, pomFilename, fixChecksums ); queueRepositoryTask( repoConfig.getId(), new File( targetPath, pomFilename ) ); } catch ( IOException ie ) @@ -398,7 +405,11 @@ public class UploadAction } - updateMetadata( metadata, metadataFile, lastUpdatedTimestamp, timestamp, newBuildNumber ); + // explicitly update only if metadata-updater consumer is not enabled! + if( !config.getRepositoryScanning().getKnownContentConsumers().contains( "metadata-updater" ) ) + { + updateMetadata( metadata, metadataFile, lastUpdatedTimestamp, timestamp, newBuildNumber, fixChecksums ); + } String msg = "Artifact \'" + groupId + ":" + artifactId + ":" + version + "\' was successfully deployed to repository \'" + repositoryId + "\'"; @@ -428,7 +439,7 @@ public class UploadAction checksum.fixChecksums( algorithms ); } - private void copyFile( File sourceFile, File targetPath, String targetFilename ) + private void copyFile( File sourceFile, File targetPath, String targetFilename, boolean fixChecksums ) throws IOException { FileOutputStream out = new FileOutputStream( new File( targetPath, targetFilename ) ); @@ -449,7 +460,10 @@ public class UploadAction input.close(); } - fixChecksums( new File( targetPath, targetFilename ) ); + if( fixChecksums ) + { + fixChecksums( new File( targetPath, targetFilename ) ); + } } private File createPom( File targetPath, String filename ) @@ -486,12 +500,11 @@ public class UploadAction } /** - * Update artifact level metadata. If it does not exist, create the metadata. - * - * @param metadata + * 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 ) + String timestamp, int buildNumber, boolean fixChecksums ) throws RepositoryMetadataException { List availableVersions = new ArrayList(); @@ -543,7 +556,11 @@ public class UploadAction } RepositoryMetadataWriter.write( metadata, metadataFile ); - fixChecksums( metadataFile ); + + if( fixChecksums ) + { + fixChecksums( metadataFile ); + } } public void validate() diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/UploadActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/UploadActionTest.java index 769c18050..f18aa17ff 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/UploadActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/UploadActionTest.java @@ -21,6 +21,7 @@ package org.apache.maven.archiva.web.action; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.archiva.checksum.ChecksummedFile; @@ -29,6 +30,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; 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.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.RepositoryContentFactory; import org.apache.maven.archiva.repository.RepositoryNotFoundException; @@ -96,6 +98,10 @@ public class UploadActionTest repoConfig.setLocation( testRepo.getPath() ); repoConfig.setName( REPOSITORY_ID ); config.addManagedRepository( repoConfig ); + + RepositoryScanningConfiguration repoScanning = new RepositoryScanningConfiguration(); + repoScanning.setKnownContentConsumers( new ArrayList() ); + config.setRepositoryScanning( repoScanning ); } public void tearDown() @@ -401,9 +407,11 @@ public class UploadActionTest 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(); @@ -443,5 +451,5 @@ public class UploadActionTest assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation ); verifyChecksums( repoLocation ); - } + } }