if ( tok.hasMoreTokens() && "artifact".equals( tok.nextToken() ) )
{
String field = tok.nextToken();
String id = tok.nextToken();
ArtifactMetadata artifact = artifacts.get( id );
if ( artifact == null )
{
artifact = new ArtifactMetadata();
artifact.setRepositoryId( repoId );
artifact.setNamespace( namespace );
artifact.setProject( projectId );
artifact.setProjectVersion( projectVersion );
artifact.setVersion( projectVersion );
artifact.setId( id );
artifacts.put( id, artifact );
}
String value = (String) entry.getValue();
if ( "updated".equals( field ) )
{
artifact.setFileLastModified( Long.parseLong( value ) );
}
else if ( "size".equals( field ) )
{
artifact.setSize( Long.valueOf( value ) );
}
else if ( "whenGathered".equals( field ) )
{
artifact.setWhenGathered( new Date( Long.parseLong( value ) ) );
}
else if ( "version".equals( field ) )
{
artifact.setVersion( value );
}
else if ( "md5".equals( field ) )
{
artifact.setMd5( value );
}
else if ( "sha1".equals( field ) )
{
artifact.setSha1( value );
}
else if ( "facetIds".equals( field ) )
{
if ( value.length() > 0 )
{
String propertyPrefix = "artifact:facet:" + id + ":";
for ( String facetId : value.split( "," ) )
{
MetadataFacetFactory factory = metadataFacetFactories.get( facetId );
if ( factory == null )
{
log.error( "Attempted to load unknown artifact metadata facet: " + facetId );
}
else
{
MetadataFacet facet = factory.createMetadataFacet();
String prefix = propertyPrefix + facet.getFacetId();
Map<String, String> map = new HashMap<String, String>();
for ( Object key : new ArrayList( properties.keySet() ) )
{
String property = (String) key;
if ( property.startsWith( prefix ) )
{
map.put( property.substring( prefix.length() + 1 ),
properties.getProperty( property ) );
}
}
facet.fromProperties( map );
artifact.addFacet( facet );
}
}
}
updateArtifactFacets( artifact, properties );