2010-12-21 14:25:37 +00:00
|
|
|
package org.apache.maven.artifact.resolver;
|
|
|
|
|
|
|
|
import org.apache.maven.artifact.repository.MavenJPackageDepmap;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.Hashtable;
|
|
|
|
|
|
|
|
import org.sonatype.aether.repository.WorkspaceReader;
|
|
|
|
import org.sonatype.aether.repository.WorkspaceRepository;
|
|
|
|
import org.sonatype.aether.artifact.Artifact;
|
|
|
|
|
2011-06-10 08:33:20 +00:00
|
|
|
public class JavadirWorkspaceReader implements WorkspaceReader {
|
2010-12-21 14:25:37 +00:00
|
|
|
private WorkspaceRepository workspaceRepository;
|
|
|
|
|
|
|
|
private static final char GROUP_SEPARATOR = '.';
|
|
|
|
private static final char PATH_SEPARATOR = '/';
|
|
|
|
|
|
|
|
public JavadirWorkspaceReader() {
|
|
|
|
workspaceRepository = new WorkspaceRepository("javadir-workspace");
|
|
|
|
}
|
|
|
|
|
|
|
|
public WorkspaceRepository getRepository() {
|
|
|
|
return workspaceRepository;
|
|
|
|
}
|
|
|
|
|
2011-06-10 08:33:20 +00:00
|
|
|
public File findArtifact(Artifact artifact) {
|
|
|
|
MavenJPackageDepmap.debug("=============JAVADIRREADER-FIND_ARTIFACT: "
|
|
|
|
+ artifact.getArtifactId());
|
2010-12-21 14:25:37 +00:00
|
|
|
StringBuffer path = new StringBuffer();
|
|
|
|
|
|
|
|
String artifactId = artifact.getArtifactId();
|
|
|
|
String groupId = artifact.getGroupId();
|
|
|
|
String version = artifact.getVersion();
|
|
|
|
|
|
|
|
MavenJPackageDepmap.debug("Wanted GROUPID=" + groupId);
|
|
|
|
MavenJPackageDepmap.debug("Wanted ARTIFACTID=" + artifactId);
|
2011-05-10 11:40:59 +00:00
|
|
|
|
2010-12-21 14:25:37 +00:00
|
|
|
if (!groupId.startsWith("JPP")) {
|
|
|
|
MavenJPackageDepmap map = MavenJPackageDepmap.getInstance();
|
2011-06-10 08:33:20 +00:00
|
|
|
Hashtable<String, String> newInfo = map.getMappedInfo(groupId,
|
|
|
|
artifactId, version);
|
2010-12-21 14:25:37 +00:00
|
|
|
|
|
|
|
groupId = (String) newInfo.get("group");
|
|
|
|
artifactId = (String) newInfo.get("artifact");
|
|
|
|
}
|
|
|
|
MavenJPackageDepmap.debug("Resolved GROUPID=" + groupId);
|
|
|
|
MavenJPackageDepmap.debug("Resolved ARTIFACTID=" + artifactId);
|
|
|
|
|
|
|
|
if (artifact.getExtension().equals("pom")) {
|
|
|
|
path = getPOMPath(groupId, artifactId);
|
|
|
|
} else if (artifact.getExtension().equals("signature")) {
|
2011-05-10 11:40:59 +00:00
|
|
|
path.append("/usr/share/maven/repository/");
|
2011-06-10 08:33:20 +00:00
|
|
|
path.append(groupId).append('/');
|
|
|
|
path.append(artifactId).append(".signature");
|
2011-05-10 11:40:59 +00:00
|
|
|
} else if (artifact.getExtension().equals("zip")) {
|
|
|
|
path.append("/usr/share/maven/repository/");
|
2011-06-10 08:33:20 +00:00
|
|
|
path.append(groupId).append('/');
|
|
|
|
path.append(artifactId).append(".zip");
|
2010-12-21 14:25:37 +00:00
|
|
|
} else {
|
2011-06-10 08:33:20 +00:00
|
|
|
path.append("/usr/share/maven/repository/");
|
|
|
|
path.append(groupId).append('/');
|
|
|
|
path.append(artifactId).append(".jar");
|
2010-12-21 14:25:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MavenJPackageDepmap.debug("Returning " + path.toString());
|
2011-01-11 15:40:20 +00:00
|
|
|
File ret = new File(path.toString());
|
|
|
|
// if file doesn't exist return null to delegate to other
|
|
|
|
// resolvers (reactor/local repo)
|
2011-06-10 08:33:20 +00:00
|
|
|
if (ret.isFile()) {
|
2011-01-11 15:40:20 +00:00
|
|
|
MavenJPackageDepmap.debug("Returning " + path.toString());
|
|
|
|
return ret;
|
|
|
|
} else {
|
2011-06-10 08:33:20 +00:00
|
|
|
MavenJPackageDepmap.debug("Returning null for gid:aid =>" + groupId
|
|
|
|
+ ":" + artifactId);
|
2011-01-11 15:40:20 +00:00
|
|
|
return null;
|
|
|
|
}
|
2010-12-21 14:25:37 +00:00
|
|
|
}
|
|
|
|
|
2011-06-10 08:33:20 +00:00
|
|
|
public List<String> findVersions(Artifact artifact) {
|
2010-12-21 14:25:37 +00:00
|
|
|
List<String> ret = new LinkedList<String>();
|
|
|
|
ret.add("latest");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
private StringBuffer getPOMPath(String groupId, String artifactId) {
|
|
|
|
|
2011-06-10 08:33:20 +00:00
|
|
|
String fName = groupId.replace(PATH_SEPARATOR, GROUP_SEPARATOR) + "-"
|
|
|
|
+ artifactId + ".pom";
|
|
|
|
String m2path = System.getProperty("maven2.local.pom.path",
|
|
|
|
"JPP/maven2/poms") + "/" + fName;
|
|
|
|
String m3path = System.getProperty("maven.local.pom.path",
|
|
|
|
"JPP/maven/poms") + "/" + fName;
|
2011-05-10 11:40:59 +00:00
|
|
|
File f;
|
|
|
|
|
|
|
|
// let's try maven 2 repo first
|
2011-06-10 08:33:20 +00:00
|
|
|
f = new File(System.getProperty("maven2.local.default.repo",
|
|
|
|
"/usr/share/maven2/repository") + "/" + m2path);
|
|
|
|
if (f.exists()) {
|
2011-05-10 11:40:59 +00:00
|
|
|
return new StringBuffer(f.getPath());
|
2010-12-21 14:25:37 +00:00
|
|
|
}
|
2011-05-10 11:40:59 +00:00
|
|
|
|
2011-06-10 08:33:20 +00:00
|
|
|
f = new File(System.getProperty("maven.local.default.repo",
|
|
|
|
"/usr/share/maven/repository") + "/" + m3path);
|
|
|
|
if (f.exists()) {
|
2011-05-10 11:40:59 +00:00
|
|
|
return new StringBuffer(f.getPath());
|
|
|
|
}
|
|
|
|
|
|
|
|
// final fallback to m2 default poms
|
2011-06-10 08:33:20 +00:00
|
|
|
return new StringBuffer("/usr/share/maven2/repository/"
|
|
|
|
+ System.getProperty("maven.local.default.repo",
|
|
|
|
"JPP/maven2/default_poms") + "/" + fName);
|
2010-12-21 14:25:37 +00:00
|
|
|
}
|
|
|
|
}
|