MetadataResolver metadataResolver = repositorySession.getResolver();
ProjectVersionMetadata sharedModel = new ProjectVersionMetadata();
MavenProjectFacet mavenFacet = new MavenProjectFacet();
mavenFacet.setGroupId( groupId );
mavenFacet.setArtifactId( artifactId );
sharedModel.addFacet( mavenFacet );
boolean isFirstVersion = true;
for ( String version : projectVersions )
{
ProjectVersionMetadata versionMetadata = null;
for ( String repoId : selectedRepos )
{
if ( versionMetadata == null || versionMetadata.isIncomplete() )
{
try
{
ProjectVersionMetadata projectVersionMetadataResolved = null;
boolean useCache = !StringUtils.endsWith( version, VersionUtil.SNAPSHOT );
String cacheKey = null;
boolean cacheToUpdate = false;
// FIXME a bit maven centric!!!
// not a snapshot so get it from cache
if ( useCache )
{
cacheKey = repoId + groupId + artifactId + version;
projectVersionMetadataResolved = versionMetadataCache.get( cacheKey );
}
if ( useCache && projectVersionMetadataResolved != null )
{
versionMetadata = projectVersionMetadataResolved;
}
else
{
projectVersionMetadataResolved =
metadataResolver.resolveProjectVersion( repositorySession, repoId, groupId,
artifactId, version );
versionMetadata = projectVersionMetadataResolved;
cacheToUpdate = true;
}
if ( useCache && cacheToUpdate )
{
versionMetadataCache.put( cacheKey, projectVersionMetadataResolved );
}
}
catch ( MetadataResolutionException e )
{
log.error( "Skipping invalid metadata while compiling shared model for " + groupId + ":"
+ artifactId + " in repo " + repoId + ": " + e.getMessage() );
}
}
}
if ( versionMetadata == null )
{
continue;
}
if ( isFirstVersion )
{
sharedModel = versionMetadata;
sharedModel.setId( null );
}
else
{
MavenProjectFacet versionMetadataMavenFacet =
(MavenProjectFacet) versionMetadata.getFacet( MavenProjectFacet.FACET_ID );
if ( versionMetadataMavenFacet != null )
{
if ( mavenFacet.getPackaging() != null //
&& !StringUtils.equalsIgnoreCase( mavenFacet.getPackaging(),
versionMetadataMavenFacet.getPackaging() ) )
{
mavenFacet.setPackaging( null );
}
}