public String doUpload()
{
try
{
ManagedRepository repoConfig = managedRepositoryAdmin.getManagedRepository( repositoryId );
ArtifactReference artifactReference = new ArtifactReference();
artifactReference.setArtifactId( artifactId );
artifactReference.setGroupId( groupId );
artifactReference.setVersion( version );
artifactReference.setClassifier( classifier );
artifactReference.setType( packaging );
ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );
String artifactPath = repository.toPath( artifactReference );
int lastIndex = artifactPath.lastIndexOf( '/' );
String path = artifactPath.substring( 0, lastIndex );
File targetPath = new File( repoConfig.getLocation(), path );
Date lastUpdatedTimestamp = Calendar.getInstance().getTime();
int newBuildNumber = -1;
String timestamp = null;
File versionMetadataFile = new File( targetPath, MetadataTools.MAVEN_METADATA );
ArchivaRepositoryMetadata versionMetadata = getMetadata( versionMetadataFile );
if ( VersionUtil.isSnapshot( version ) )
{
TimeZone timezone = TimeZone.getTimeZone( "UTC" );
DateFormat fmt = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
fmt.setTimeZone( timezone );
timestamp = fmt.format( lastUpdatedTimestamp );
if ( versionMetadata.getSnapshotVersion() != null )
{
newBuildNumber = versionMetadata.getSnapshotVersion().getBuildNumber() + 1;
}
else
{
newBuildNumber = 1;
}
}
if ( !targetPath.exists() )
{
targetPath.mkdirs();
}
String filename = artifactPath.substring( lastIndex + 1 );
if ( VersionUtil.isSnapshot( version ) )
{
filename = filename.replaceAll( "SNAPSHOT", timestamp + "-" + newBuildNumber );
}
boolean fixChecksums =
!( archivaAdministration.getKnownContentConsumers().contains( "create-missing-checksums" ) );
try
{
File targetFile = new File( targetPath, filename );
if ( targetFile.exists() && !VersionUtil.isSnapshot( version ) && repoConfig.isBlockRedeployments() )
{
addActionError(
"Overwriting released artifacts in repository '" + repoConfig.getId() + "' is not allowed." );
return ERROR;
}
else
{
copyFile( artifactFile, targetPath, filename, fixChecksums );
triggerAuditEvent( repository.getId(), path + "/" + filename, AuditEvent.UPLOAD_FILE );
queueRepositoryTask( repository.getId(), targetFile );
}
}
catch ( IOException ie )
{
addActionError( "Error encountered while uploading file: " + ie.getMessage() );
return ERROR;
}
String pomFilename = filename;
if ( classifier != null && !"".equals( classifier ) )
{
pomFilename = StringUtils.remove( pomFilename, "-" + classifier );
}
pomFilename = FilenameUtils.removeExtension( pomFilename ) + ".pom";
if ( generatePom )
{
try
{
File generatedPomFile = createPom( targetPath, pomFilename );
triggerAuditEvent( repoConfig.getId(), path + "/" + pomFilename, AuditEvent.UPLOAD_FILE );
if ( fixChecksums )
{
fixChecksums( generatedPomFile );
}
queueRepositoryTask( repoConfig.getId(), generatedPomFile );
}
catch ( IOException ie )
{
addActionError( "Error encountered while writing pom file: " + ie.getMessage() );
return ERROR;
}
}
if ( pomFile != null && pomFile.length() > 0 )
{
try
{
copyFile( pomFile, targetPath, pomFilename, fixChecksums );
triggerAuditEvent( repoConfig.getId(), path + "/" + pomFilename, AuditEvent.UPLOAD_FILE );
queueRepositoryTask( repoConfig.getId(), new File( targetPath, pomFilename ) );
}
catch ( IOException ie )
{
addActionError( "Error encountered while uploading pom file: " + ie.getMessage() );
return ERROR;