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