]> git.pld-linux.org Git - packages/maven.git/blob - maven-JPackageRepositoryLayout.java
- DF does not like macros in URLs
[packages/maven.git] / maven-JPackageRepositoryLayout.java
1 package org.apache.maven.artifact.repository.layout;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
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
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
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;
25
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;
35
36 /**
37  * Repository layout for jpackage based repositories. 
38  * This class resolves items for jpp style repos (i.e things located in 
39  * /usr/share/java).
40  */
41
42 public class JPackageRepositoryLayout
43         implements ArtifactRepositoryLayout
44 {
45         private static Hashtable jppArtifactMap;
46
47         private static final char GROUP_SEPARATOR = '.';
48         private static final char PATH_SEPARATOR = '/';
49
50         public String pathOf( Artifact artifact )
51         {
52
53                 ArtifactHandler artifactHandler = artifact.getArtifactHandler();
54                 StringBuffer path = new StringBuffer();
55
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();
61
62                 if (!groupId.startsWith("JPP")) {
63                         MavenJPackageDepmap map = MavenJPackageDepmap.getInstance();
64                         Hashtable newInfo = map.getMappedInfo(groupId, artifactId, version);
65                         
66                         groupId = (String) newInfo.get("group");
67                         artifactId = (String) newInfo.get("artifact");
68                 }
69
70                 if (groupId.startsWith("JPP")) {
71                         if (artifactHandler.getPackaging().equals("pom")) {
72                                 path = getPOMPath(groupId, artifactId);
73
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());
78                         }
79                 } else {
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")) {
84                                 path.append( "pom" );
85                         } else {
86                                 path.append( artifactHandler.getPackaging() );
87                         }
88                 }
89
90                 return path.toString();
91         }
92
93         private StringBuffer getPOMPath(String groupId, String artifactId) {
94
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);
98                 java.io.File f;
99
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");
106                 if (!f.exists()) {
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);
110                 }
111
112                 return path;
113         }
114
115         public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
116         {
117                 return pathOfRepositoryMetadata( metadata, metadata.getLocalFilename( repository ) );
118         }
119
120         private String pathOfRepositoryMetadata( ArtifactMetadata metadata, String filename )
121         {
122
123         StringBuffer path = new StringBuffer();
124
125         if (filename.substring(filename.length()-4).equals(".pom")) {
126                         path = getPOMPath(metadata.getGroupId(), metadata.getArtifactId());
127         } else {
128
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);
131         }
132
133                 return path.toString();
134         }
135
136         public String pathOfRemoteRepositoryMetadata( ArtifactMetadata metadata )
137         {
138                 return pathOfRepositoryMetadata( metadata, metadata.getRemoteFilename() );
139         }
140 }
This page took 0.036107 seconds and 3 git commands to generate.