public String doUpload()
{
try
{
ManagedRepositoryConfiguration repoConfig =
configuration.getConfiguration().findManagedRepositoryById( 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( '/' );
File targetPath = new File( repoConfig.getLocation(), artifactPath.substring( 0, lastIndex ) );
Date lastUpdatedTimestamp = Calendar.getInstance().getTime();
int newBuildNumber = -1;
String timestamp = null;
File metadataFile = getMetadata( targetPath.getAbsolutePath() );
ArchivaRepositoryMetadata metadata = getMetadata( metadataFile );
if (VersionUtil.isSnapshot(version))
{
TimeZone timezone = TimeZone.getTimeZone( "UTC" );
DateFormat fmt = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
fmt.setTimeZone( timezone );
timestamp = fmt.format( lastUpdatedTimestamp );
if ( metadata.getSnapshotVersion() != null )
{
newBuildNumber = metadata.getSnapshotVersion().getBuildNumber() + 1;
}
else
{
metadata.setSnapshotVersion( new SnapshotVersion() );
newBuildNumber = 1;
}
}
if ( !targetPath.exists() )
{
targetPath.mkdirs();
}
String filename = artifactPath.substring( lastIndex + 1 );
if ( VersionUtil.isSnapshot( version ) )
{
filename = filename.replaceAll( "SNAPSHOT", timestamp + "-" + newBuildNumber );
}
try
{
copyFile( artifactFile, targetPath, filename );
queueRepositoryTask( repository.getId(), repository.toFile( artifactReference ) );
//consumers.executeConsumers( repoConfig, repository.toFile( artifactReference ) );
}
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 );
queueRepositoryTask( repoConfig.getId(), generatedPomFile );
//consumers.executeConsumers( repoConfig, generatedPomFile );
}
catch ( IOException ie )
{
addActionError( "Error encountered while writing pom file: " + ie.getMessage() );
return ERROR;
}
catch ( ProjectModelException pe )
{
addActionError( "Error encountered while generating pom file: " + pe.getMessage() );
return ERROR;
}
}
if ( pomFile != null && pomFile.length() > 0 )
{
try
{
copyFile( pomFile, targetPath, pomFilename );
queueRepositoryTask( repoConfig.getId(), new File( targetPath, pomFilename ) );
//consumers.executeConsumers( repoConfig, new File( targetPath, pomFilename ) );
}
catch ( IOException ie )
{
addActionError( "Error encountered while uploading pom file: " + ie.getMessage() );