// the initial scan. Any request for this information will be intercepted and populated on-demand
// or picked up by subsequent scans
ArtifactMetadata artifact = repositoryStorage.readArtifactMetadataFromPath( repoId, path );
ProjectMetadata project = new ProjectMetadata();
project.setNamespace( artifact.getNamespace() );
project.setId( artifact.getProject() );
String projectVersion = VersionUtil.getBaseVersion( artifact.getVersion() );
RepositorySession repositorySession = repositorySessionFactory.createSession();
try
{
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
{
versionMetadata = repositoryStorage.readProjectVersionMetadata( repoId, artifact.getNamespace(),
artifact.getProject(), projectVersion );
createVersionMetadata = true;
}
catch ( RepositoryStorageMetadataNotFoundException e )
{
log.warn( "Missing or invalid POM for artifact: " + path + "; creating empty metadata" );
versionMetadata = new ProjectVersionMetadata();
versionMetadata.setId( projectVersion );
versionMetadata.setIncomplete( true );
createVersionMetadata = true;
}
catch ( RepositoryStorageMetadataInvalidException e )
{
log.warn( "Error occurred resolving POM for artifact: " + path + "; message: " + 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();
}