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 File toFile( File basedir, String namespace, String projectId, String projectVersion )
43 return new File( basedir, toPath( namespace, projectId, projectVersion ) );
46 public String toPath( String namespace, String projectId, String projectVersion, String filename )
48 StringBuilder path = new StringBuilder();
50 appendNamespaceToProjectVersion( path, namespace, projectId, projectVersion );
51 path.append( PATH_SEPARATOR );
52 path.append( filename );
54 return path.toString();
57 private void appendNamespaceToProjectVersion( StringBuilder path, String namespace, String projectId,
58 String projectVersion )
60 appendNamespaceAndProject( path, namespace, projectId );
61 path.append( projectVersion );
64 public String toPath( String namespace, String projectId, String projectVersion )
66 StringBuilder path = new StringBuilder();
68 appendNamespaceToProjectVersion( path, namespace, projectId, projectVersion );
70 return path.toString();
73 public String toPath( String namespace )
75 StringBuilder path = new StringBuilder();
77 appendNamespace( path, namespace );
79 return path.toString();
82 public String toPath( String namespace, String projectId )
84 StringBuilder path = new StringBuilder();
86 appendNamespaceAndProject( path, namespace, projectId );
88 return path.toString();
91 private void appendNamespaceAndProject( StringBuilder path, String namespace, String projectId )
93 appendNamespace( path, namespace );
94 path.append( projectId ).append( PATH_SEPARATOR );
97 private void appendNamespace( StringBuilder path, String namespace )
99 path.append( formatAsDirectory( namespace ) ).append( PATH_SEPARATOR );
102 public File toFile( File basedir, String namespace, String projectId )
104 return new File( basedir, toPath( namespace, projectId ) );
107 public File toFile( File basedir, String namespace )
109 return new File( basedir, toPath( namespace ) );
112 private String formatAsDirectory( String directory )
114 return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR );