if ( !path.endsWith( "/" + MAVEN_METADATA ) )
{
throw new RepositoryMetadataException( "Cannot convert to versioned reference, not a metadata file. " );
}
VersionedReference reference = new VersionedReference();
String normalizedPath = StringUtils.replace( path, "\\", "/" );
String pathParts[] = StringUtils.split( normalizedPath, '/' );
int versionOffset = pathParts.length - 2;
int artifactIdOffset = versionOffset - 1;
int groupIdEnd = artifactIdOffset - 1;
reference.setVersion( pathParts[versionOffset] );
if ( !hasNumberAnywhere( reference.getVersion() ) )
{
// Scary check, but without it, all paths are version references;
throw new RepositoryMetadataException(
"Not a versioned reference, as version id on path has no number in it." );
}
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;
}