[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
This commit is contained in:
Maria Odea B. Ching 2009-07-27 07:39:34 +00:00
parent a4bd8b9c5a
commit 8b235c1283
2 changed files with 40 additions and 15 deletions

View File

@ -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 )
@ -368,7 +372,10 @@ public class UploadAction
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<String> availableVersions = new ArrayList<String>();
@ -543,7 +556,11 @@ public class UploadAction
}
RepositoryMetadataWriter.write( metadata, metadataFile );
fixChecksums( metadataFile );
if( fixChecksums )
{
fixChecksums( metadataFile );
}
}
public void validate()

View File

@ -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<String>() );
config.setRepositoryScanning( repoScanning );
}
public void tearDown()
@ -401,6 +407,8 @@ 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 );