ref.setType( type );
File file = managedRepositoryContent.toFile( ref );
String extension = FilenameUtils.getExtension( file.getName() );
Artifact artifact = new Artifact( ref.getGroupId(), ref.getArtifactId(), ref.getVersion() );
artifact.setRepositoryId( artifactMetadata.getRepositoryId() );
artifact.setClassifier( classifier );
artifact.setPackaging( type );
artifact.setType( type );
artifact.setFileExtension( extension );
artifact.setPath( managedRepositoryContent.toPath( ref ) );
// TODO: find a reusable formatter for this
double s = this.artifactMetadata.getSize();
String symbol = "b";
if ( s > 1024 )
{
symbol = "K";
s /= 1024;
if ( s > 1024 )
{
symbol = "M";
s /= 1024;
if ( s > 1024 )
{
symbol = "G";
s /= 1024;
}
}
}
artifact.setContext( managedRepositoryContent.getId() );
DecimalFormat df = new DecimalFormat( "#,###.##", new DecimalFormatSymbols( Locale.US ) );
artifact.setSize( df.format( s ) + " " + symbol );
artifact.setId( ref.getArtifactId() + "-" + ref.getVersion() + "." + ref.getType() );
return artifact;
}