{
File directory = new File( getDirectory( repoId ), namespace + "/" + projectId + "/" + projectVersion );
Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY );
String id = properties.getProperty( "id" );
ProjectVersionMetadata versionMetadata = null;
if ( id != null )
{
versionMetadata = new ProjectVersionMetadata();
versionMetadata.setId( id );
versionMetadata.setName( properties.getProperty( "name" ) );
versionMetadata.setDescription( properties.getProperty( "description" ) );
versionMetadata.setUrl( properties.getProperty( "url" ) );
versionMetadata.setIncomplete( Boolean.valueOf( properties.getProperty( "incomplete", "false" ) ) );
String scmConnection = properties.getProperty( "scm.connection" );
String scmDeveloperConnection = properties.getProperty( "scm.developerConnection" );
String scmUrl = properties.getProperty( "scm.url" );
if ( scmConnection != null || scmDeveloperConnection != null || scmUrl != null )
{
Scm scm = new Scm();
scm.setConnection( scmConnection );
scm.setDeveloperConnection( scmDeveloperConnection );
scm.setUrl( scmUrl );
versionMetadata.setScm( scm );
}
String ciSystem = properties.getProperty( "ci.system" );
String ciUrl = properties.getProperty( "ci.url" );
if ( ciSystem != null || ciUrl != null )
{
CiManagement ci = new CiManagement();
ci.setSystem( ciSystem );
ci.setUrl( ciUrl );
versionMetadata.setCiManagement( ci );
}
String issueSystem = properties.getProperty( "issue.system" );
String issueUrl = properties.getProperty( "issue.url" );
if ( issueSystem != null || issueUrl != null )
{
IssueManagement issueManagement = new IssueManagement();
issueManagement.setSystem( issueSystem );
issueManagement.setUrl( issueUrl );
versionMetadata.setIssueManagement( issueManagement );
}
String orgName = properties.getProperty( "org.name" );
String orgUrl = properties.getProperty( "org.url" );
if ( orgName != null || orgUrl != null )
{
Organization org = new Organization();
org.setName( orgName );
org.setUrl( orgUrl );
versionMetadata.setOrganization( org );
}
boolean done = false;
int i = 0;
while ( !done )
{
String licenseName = properties.getProperty( "license." + i + ".name" );
String licenseUrl = properties.getProperty( "license." + i + ".url" );
if ( licenseName != null || licenseUrl != null )
{
License license = new License();
license.setName( licenseName );
license.setUrl( licenseUrl );
versionMetadata.addLicense( license );
}
else
{
done = true;
}
i++;
}
done = false;
i = 0;
while ( !done )
{
String mailingListName = properties.getProperty( "mailingList." + i + ".name" );
if ( mailingListName != null )
{
MailingList mailingList = new MailingList();
mailingList.setName( mailingListName );
mailingList.setMainArchiveUrl( properties.getProperty( "mailingList." + i + ".archive" ) );
String p = properties.getProperty( "mailingList." + i + ".otherArchives" );
if ( p != null && p.length() > 0 )
{
mailingList.setOtherArchives( Arrays.asList( p.split( "," ) ) );
}
else
{
mailingList.setOtherArchives( Collections.<String>emptyList() );
}
mailingList.setPostAddress( properties.getProperty( "mailingList." + i + ".post" ) );
mailingList.setSubscribeAddress( properties.getProperty( "mailingList." + i + ".subscribe" ) );
mailingList.setUnsubscribeAddress( properties.getProperty( "mailingList." + i + ".unsubscribe" ) );
versionMetadata.addMailingList( mailingList );
}
else
{
done = true;
}
i++;
}
done = false;
i = 0;
while ( !done )
{
String dependencyArtifactId = properties.getProperty( "dependency." + i + ".artifactId" );
if ( dependencyArtifactId != null )
{
Dependency dependency = new Dependency();
dependency.setArtifactId( dependencyArtifactId );
dependency.setGroupId( properties.getProperty( "dependency." + i + ".groupId" ) );
dependency.setClassifier( properties.getProperty( "dependency." + i + ".classifier" ) );
dependency.setOptional(
Boolean.valueOf( properties.getProperty( "dependency." + i + ".optional" ) ) );
dependency.setScope( properties.getProperty( "dependency." + i + ".scope" ) );
dependency.setSystemPath( properties.getProperty( "dependency." + i + ".systemPath" ) );
dependency.setType( properties.getProperty( "dependency." + i + ".type" ) );
dependency.setVersion( properties.getProperty( "dependency." + i + ".version" ) );
dependency.setOptional(
Boolean.valueOf( properties.getProperty( "dependency." + i + ".optional" ) ) );
versionMetadata.addDependency( dependency );
}
else
{
done = true;
}
i++;
}
String facetIds = properties.getProperty( "facetIds", "" );
if ( facetIds.length() > 0 )
{
for ( String facetId : facetIds.split( "," ) )
{
MetadataFacetFactory factory = metadataFacetFactories.get( facetId );
if ( factory == null )
{
log.error( "Attempted to load unknown project version metadata facet: {}", facetId );
}
else
{
MetadataFacet facet = factory.createMetadataFacet();
Map<String, String> map = new HashMap<String, String>();
for ( Object key : new ArrayList( properties.keySet() ) )
{
String property = (String) key;
if ( property.startsWith( facet.getFacetId() ) )
{
map.put( property.substring( facet.getFacetId().length() + 1 ),
properties.getProperty( property ) );
}
}
facet.fromProperties( map );
versionMetadata.addFacet( facet );
}
}
}
updateProjectVersionFacets( versionMetadata, properties );