001 package org.apache.archiva.converter.artifact; 002 /* 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 */ 020 021 import org.apache.maven.artifact.Artifact; 022 import org.apache.maven.artifact.handler.ArtifactHandler; 023 import org.apache.maven.artifact.metadata.ArtifactMetadata; 024 import org.apache.maven.artifact.repository.ArtifactRepository; 025 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; 026 027 /** 028 * @author jdcasey 029 */ 030 public class LegacyRepositoryLayout 031 implements ArtifactRepositoryLayout 032 { 033 034 private static final String PATH_SEPARATOR = "/"; 035 036 public String getId() 037 { 038 return "legacy"; 039 } 040 041 public String pathOf( Artifact artifact ) 042 { 043 ArtifactHandler artifactHandler = artifact.getArtifactHandler(); 044 045 StringBuilder path = new StringBuilder( 128 ); 046 047 path.append( artifact.getGroupId() ).append( '/' ); 048 path.append( artifactHandler.getDirectory() ).append( '/' ); 049 path.append( artifact.getArtifactId() ).append( '-' ).append( artifact.getVersion() ); 050 051 if ( artifact.hasClassifier() ) 052 { 053 path.append( '-' ).append( artifact.getClassifier() ); 054 } 055 056 if ( artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0 ) 057 { 058 path.append( '.' ).append( artifactHandler.getExtension() ); 059 } 060 061 return path.toString(); 062 } 063 064 public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository ) 065 { 066 return pathOfRepositoryMetadata( metadata, metadata.getLocalFilename( repository ) ); 067 } 068 069 private String pathOfRepositoryMetadata( ArtifactMetadata metadata, String filename ) 070 { 071 StringBuilder path = new StringBuilder( 128 ); 072 073 path.append( metadata.getGroupId() ).append( PATH_SEPARATOR ).append( "poms" ).append( PATH_SEPARATOR ); 074 075 path.append( filename ); 076 077 return path.toString(); 078 } 079 080 public String pathOfRemoteRepositoryMetadata( ArtifactMetadata metadata ) 081 { 082 return pathOfRepositoryMetadata( metadata, metadata.getRemoteFilename() ); 083 } 084 085 }