1 package org.apache.archiva.metadata.repository.storage.maven2;
5 import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
8 * Licensed to the Apache Software Foundation (ASF) under one
9 * or more contributor license agreements. See the NOTICE file
10 * distributed with this work for additional information
11 * regarding copyright ownership. The ASF licenses this file
12 * to you under the Apache License, Version 2.0 (the
13 * "License"); you may not use this file except in compliance
14 * with the License. You may obtain a copy of the License at
16 * http://www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing,
19 * software distributed under the License is distributed on an
20 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 * KIND, either express or implied. See the License for the
22 * specific language governing permissions and limitations
27 * @plexus.component role="org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator" role-hint="maven2"
29 public class Maven2RepositoryPathTranslator
30 implements RepositoryPathTranslator
32 private static final char PATH_SEPARATOR = '/';
34 private static final char GROUP_SEPARATOR = '.';
36 public File toFile( File basedir, String namespace, String projectId, String projectVersion, String filename )
38 return new File( basedir, toPath( namespace, projectId, projectVersion, filename ) );
41 public String toPath( String namespace, String projectId, String projectVersion, String filename )
43 StringBuilder path = new StringBuilder();
45 appendNamespaceAndProject( path, namespace, projectId );
46 path.append( projectVersion ).append( PATH_SEPARATOR );
47 path.append( filename );
49 return path.toString();
52 public String toPath( String namespace )
54 StringBuilder path = new StringBuilder();
56 appendNamespace( path, namespace );
58 return path.toString();
61 public String toPath( String namespace, String projectId )
63 StringBuilder path = new StringBuilder();
65 appendNamespaceAndProject( path, namespace, projectId );
67 return path.toString();
70 private void appendNamespaceAndProject( StringBuilder path, String namespace, String projectId )
72 appendNamespace( path, namespace );
73 path.append( projectId ).append( PATH_SEPARATOR );
76 private void appendNamespace( StringBuilder path, String namespace )
78 path.append( formatAsDirectory( namespace ) ).append( PATH_SEPARATOR );
81 public File toFile( File basedir, String namespace, String projectId )
83 return new File( basedir, toPath( namespace, projectId ) );
86 public File toFile( File basedir, String namespace )
88 return new File( basedir, toPath( namespace ) );
91 private String formatAsDirectory( String directory )
93 return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR );