* under the License.
*/
+import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
+import org.apache.archiva.metadata.repository.storage.maven2.Maven2RepositoryPathTranslator;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.model.ArchivaArtifact;
protected static final char ARTIFACT_SEPARATOR = '-';
+ private RepositoryPathTranslator pathTranslator = new Maven2RepositoryPathTranslator();
+
private PathParser defaultPathParser = new DefaultPathParser();
public ArtifactReference toArtifactReference( String path )
private String toPath( String groupId, String artifactId, String baseVersion, String version, String classifier,
String type )
{
- StringBuffer path = new StringBuffer();
-
- path.append( formatAsDirectory( groupId ) ).append( PATH_SEPARATOR );
- path.append( artifactId ).append( PATH_SEPARATOR );
-
if ( baseVersion != null )
{
- path.append( baseVersion ).append( PATH_SEPARATOR );
- if ( ( version != null ) && ( type != null ) )
- {
- path.append( artifactId ).append( ARTIFACT_SEPARATOR ).append( version );
+ return pathTranslator.toPath( groupId, artifactId, baseVersion, constructId( artifactId, version,
+ classifier, type ) );
+ }
+ else
+ {
+ return pathTranslator.toPath( groupId, artifactId );
+ }
+ }
- if ( StringUtils.isNotBlank( classifier ) )
- {
- path.append( ARTIFACT_SEPARATOR ).append( classifier );
- }
+ // TODO: move into the Maven Artifact facet when refactoring away the caller - the caller will need to have access
+ // to the facet or filename (for the original ID)
+ private String constructId( String artifactId, String version, String classifier, String type )
+ {
+ StringBuilder id = new StringBuilder();
+ if ( ( version != null ) && ( type != null ) )
+ {
+ id.append( artifactId ).append( ARTIFACT_SEPARATOR ).append( version );
- path.append( GROUP_SEPARATOR ).append( ArtifactExtensionMapping.getExtension( type ) );
+ if ( StringUtils.isNotBlank( classifier ) )
+ {
+ id.append( ARTIFACT_SEPARATOR ).append( classifier );
}
- }
- return path.toString();
+ id.append( "." ).append( ArtifactExtensionMapping.getExtension( type ) );
+ }
+ return id.toString();
}
}
public interface RepositoryPathTranslator
{
- File toFile( File basedir, String namespace, String projectId, String projectVersion, String filename );
-
String toPath( String namespace, String projectId, String projectVersion, String filename );
+ String toPath( String namespace, String projectId );
+
+ File toFile( File basedir, String namespace, String projectId, String projectVersion, String filename );
+
File toFile( File basedir, String namespace, String projectId );
File toFile( File basedir, String namespace );