project.setNamespace( artifact.getNamespace() );
project.setId( artifact.getProject() );
String projectVersion = VersionUtil.getBaseVersion( artifact.getVersion() );
MetadataRepository metadataRepository = repositorySession.getRepository();
boolean createVersionMetadata = false;
// FIXME: maybe not too efficient since it may have already been read and stored for this artifact
ProjectVersionMetadata versionMetadata = null;
try
{
ReadMetadataRequest readMetadataRequest =
new ReadMetadataRequest().repositoryId( repoId ).namespace( artifact.getNamespace() ).projectId(
artifact.getProject() ).projectVersion( projectVersion );
versionMetadata = repositoryStorage.readProjectVersionMetadata( readMetadataRequest );
createVersionMetadata = true;
}
catch ( RepositoryStorageMetadataNotFoundException e )
{
log.warn( "Missing or invalid POM for artifact:{} (repository:{}); creating empty metadata", path,
repoId );
versionMetadata = new ProjectVersionMetadata();
versionMetadata.setId( projectVersion );
versionMetadata.setIncomplete( true );
createVersionMetadata = true;
}
catch ( RepositoryStorageMetadataInvalidException e )
{
log.warn( "Error occurred resolving POM for artifact:{} (repository:{}); message: {}",
new Object[]{ path, repoId, e.getMessage() } );
}
// read the metadata and update it if it is newer or doesn't exist
artifact.setWhenGathered( whenGathered );
metadataRepository.updateArtifact( repoId, project.getNamespace(), project.getId(), projectVersion,
artifact );
if ( createVersionMetadata )
{
metadataRepository.updateProjectVersion( repoId, project.getNamespace(), project.getId(),
versionMetadata );
}
metadataRepository.updateProject( repoId, project );
repositorySession.save();
}
catch ( MetadataRepositoryException e )
{
log.warn(