1 package org.apache.maven.artifact.repository.layout;
4 * Copyright 2001-2005 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import java.io.FileInputStream;
20 import java.io.FileNotFoundException;
21 import java.io.IOException;
22 import java.util.Hashtable;
23 import java.util.Iterator;
24 import java.util.List;
26 import org.apache.maven.artifact.Artifact;
27 import org.apache.maven.artifact.handler.ArtifactHandler;
28 import org.apache.maven.artifact.metadata.ArtifactMetadata;
29 import org.apache.maven.artifact.repository.ArtifactRepository;
30 import org.jdom.Document;
31 import org.jdom.Element;
32 import org.jdom.JDOMException;
33 import org.jdom.input.SAXBuilder;
34 import org.xml.sax.InputSource;
37 * Repository layout for jpackage based repositories.
38 * This class resolves items for jpp style repos (i.e things located in
42 public class JPackageRepositoryLayout
43 implements ArtifactRepositoryLayout
45 private static Hashtable jppArtifactMap;
47 private static final char GROUP_SEPARATOR = '.';
48 private static final char PATH_SEPARATOR = '/';
50 public String pathOf( Artifact artifact )
53 ArtifactHandler artifactHandler = artifact.getArtifactHandler();
54 StringBuffer path = new StringBuffer();
56 String artifactId = artifact.getArtifactId();
57 String groupId = artifact.getGroupId();
58 String version = artifact.getVersion();
59 String classifierSuffix = (artifact.getClassifier() == null || artifact.getClassifier() == "") ?
60 "" : "-" + artifact.getClassifier();
62 if (!groupId.startsWith("JPP")) {
63 MavenJPackageDepmap map = MavenJPackageDepmap.getInstance();
64 Hashtable newInfo = map.getMappedInfo(groupId, artifactId, version);
66 groupId = (String) newInfo.get("group");
67 artifactId = (String) newInfo.get("artifact");
70 if (groupId.startsWith("JPP")) {
71 if (artifactHandler.getPackaging().equals("pom")) {
72 path = getPOMPath(groupId, artifactId);
74 } else { // Assume if it is not pom it is jar
75 // as "maven-plugin" type is a JAR
76 path.append( groupId ).append( '/' );
77 path.append( artifactId ).append(classifierSuffix).append( "." + artifactHandler.getExtension());
80 path.append( groupId.replace(GROUP_SEPARATOR, PATH_SEPARATOR) ).append( '/' ).append( artifactId ).append( '/' ).append( version ).append( '/' );
81 path.append( artifactId ).append( '-' ).append( version ).append( "." );
82 // Parent poms may come with type "xml"
83 if (artifactHandler.getPackaging().equals("xml")) {
86 path.append( artifactHandler.getPackaging() );
90 return path.toString();
93 private StringBuffer getPOMPath(String groupId, String artifactId) {
95 StringBuffer path = new StringBuffer();
96 String fName = groupId.replace(PATH_SEPARATOR, GROUP_SEPARATOR) + "-" + artifactId + ".pom";
97 path.append(System.getProperty("maven2.jpp.pom.path", "JPP/maven2/poms")).append("/").append(fName);
100 // NOTE: We are returning default_poms/ as the path for this pom
101 // even though it may not exist there. This may cause an error,
102 // but that is fine because if the pom is not there, there is
103 // a serious problem anyways..
104 f = new java.io.File(System.getProperty("maven2.jpp.default.repo", "/usr/share/maven2/repository") + "/" + path.toString());
105 System.err.println("Checking path " + f.getAbsolutePath() + " for the pom");
107 System.err.println(f.getAbsolutePath() + " not found");
108 path = new StringBuffer();
109 path.append(System.getProperty("maven2.jpp.default.pom.path", "JPP/maven2/default_poms")).append("/").append(fName);
115 public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
117 return pathOfRepositoryMetadata( metadata, metadata.getLocalFilename( repository ) );
120 private String pathOfRepositoryMetadata( ArtifactMetadata metadata, String filename )
123 StringBuffer path = new StringBuffer();
125 if (filename.substring(filename.length()-4).equals(".pom")) {
126 path = getPOMPath(metadata.getGroupId(), metadata.getArtifactId());
129 // FIXME: If it gets here, something other than a pom was requested.. where are those things located?
130 path.append(System.getProperty("maven2.jpp.pom.path", "maven2/poms")).append("/").append(filename);
133 return path.toString();
136 public String pathOfRemoteRepositoryMetadata( ArtifactMetadata metadata )
138 return pathOfRepositoryMetadata( metadata, metadata.getRemoteFilename() );