001 package org.apache.maven.artifact.repository.layout; 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.codehaus.plexus.component.annotations.Component; 027 028 /** 029 * The code in this class is taken from DefaultRepositorylayout, located at: 030 * http://svn.apache.org/viewvc/maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/DefaultRepositoryLayout.java 031 * 032 */ 033 @Component( role = ArtifactRepositoryLayout.class, hint = "flat" ) 034 public class FlatRepositoryLayout 035 implements ArtifactRepositoryLayout 036 { 037 private static final char ARTIFACT_SEPARATOR = '-'; 038 039 private static final char GROUP_SEPARATOR = '.'; 040 041 public String getId() 042 { 043 return "flat"; 044 } 045 046 public String pathOf( Artifact artifact ) 047 { 048 ArtifactHandler artifactHandler = artifact.getArtifactHandler(); 049 050 StringBuilder path = new StringBuilder( 128 ); 051 052 path.append( artifact.getArtifactId() ).append( ARTIFACT_SEPARATOR ).append( artifact.getVersion() ); 053 054 if ( artifact.hasClassifier() ) 055 { 056 path.append( ARTIFACT_SEPARATOR ).append( artifact.getClassifier() ); 057 } 058 059 if ( artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0 ) 060 { 061 path.append( GROUP_SEPARATOR ).append( artifactHandler.getExtension() ); 062 } 063 064 return path.toString(); 065 } 066 067 public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository ) 068 { 069 return pathOfRepositoryMetadata( metadata.getLocalFilename( repository ) ); 070 } 071 072 private String pathOfRepositoryMetadata( String filename ) 073 { 074 StringBuilder path = new StringBuilder( 128 ); 075 076 path.append( filename ); 077 078 return path.toString(); 079 } 080 081 public String pathOfRemoteRepositoryMetadata( ArtifactMetadata metadata ) 082 { 083 return pathOfRepositoryMetadata( metadata.getRemoteFilename() ); 084 } 085 086 @Override 087 public String toString() 088 { 089 return getId(); 090 } 091 092 }