From 8b235c12833a6215b84f9ab6ce8d47fa436c0f55 Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Mon, 27 Jul 2009 07:39:34 +0000 Subject: [PATCH] [MRM-1212] o fix/create checksums and update metadata in action class only if create-missing-checksum and metadata-updater consumers are not enabled git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@798060 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva/web/action/UploadAction.java | 43 +++++++++++++------ .../archiva/web/action/UploadActionTest.java | 12 +++++- 2 files changed, 40 insertions(+), 15 deletions(-) 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 ); - } + } } -- 2.39.5