if ( !path.endsWith( "/" + MAVEN_METADATA ) )
{
throw new RepositoryMetadataException( "Cannot convert to versioned reference, not a metadata file. " );
}
ProjectReference reference = new ProjectReference();
String normalizedPath = StringUtils.replace( path, "\\", "/" );
String pathParts[] = StringUtils.split( normalizedPath, '/' );
// Assume last part of the path is the version.
int artifactIdOffset = pathParts.length - 2;
int groupIdEnd = artifactIdOffset - 1;
reference.setArtifactId( pathParts[artifactIdOffset] );
StringBuilder gid = new StringBuilder();
for ( int i = 0; i <= groupIdEnd; i++ )
{
if ( i > 0 )
{
gid.append( "." );
}
gid.append( pathParts[i] );
}
reference.setGroupId( gid.toString() );
return reference;
}