2010-12-21 14:25:37 +00:00
|
|
|
package org.apache.maven.artifact.resolver;
|
|
|
|
|
|
|
|
import java.io.File;
|
2012-10-18 13:51:02 +00:00
|
|
|
import java.util.ArrayList;
|
2010-12-21 14:25:37 +00:00
|
|
|
import java.util.Hashtable;
|
2011-06-10 09:17:07 +00:00
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2010-12-21 14:25:37 +00:00
|
|
|
|
2011-06-10 09:17:07 +00:00
|
|
|
import org.apache.maven.artifact.repository.MavenJPackageDepmap;
|
|
|
|
import org.sonatype.aether.artifact.Artifact;
|
2010-12-21 14:25:37 +00:00
|
|
|
import org.sonatype.aether.repository.WorkspaceReader;
|
|
|
|
import org.sonatype.aether.repository.WorkspaceRepository;
|
|
|
|
|
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 = '.';
|
2012-10-18 13:51:02 +00:00
|
|
|
private static final char PATH_SEPARATOR = File.separatorChar;
|
2010-12-21 14:25:37 +00:00
|
|
|
|
|
|
|
public JavadirWorkspaceReader() {
|
|
|
|
workspaceRepository = new WorkspaceRepository("javadir-workspace");
|
|
|
|
}
|
|
|
|
|
|
|
|
public WorkspaceRepository getRepository() {
|
|
|
|
return workspaceRepository;
|
|
|
|
}
|
|
|
|
|
2012-10-18 13:51:02 +00:00
|
|
|
private static final String LOG_FILE = System
|
|
|
|
.getProperty("maven.resolver.logfile");
|
|
|
|
private static final java.util.concurrent.Semaphore LOG_SEMAPHORE = new java.util.concurrent.Semaphore(
|
|
|
|
1);
|
2012-06-11 18:49:09 +00:00
|
|
|
|
2011-06-10 08:33:20 +00:00
|
|
|
public File findArtifact(Artifact artifact) {
|
2012-10-18 13:51:02 +00:00
|
|
|
File f = findArtifactImpl(artifact);
|
|
|
|
|
|
|
|
LOG_SEMAPHORE.acquireUninterruptibly();
|
|
|
|
try {
|
|
|
|
if (LOG_FILE != null && f != null) {
|
|
|
|
java.io.FileOutputStream fos = new java.io.FileOutputStream(
|
|
|
|
LOG_FILE, true);
|
|
|
|
java.io.PrintStream ps = new java.io.PrintStream(fos);
|
|
|
|
ps.println(f.getAbsolutePath());
|
|
|
|
ps.close();
|
|
|
|
}
|
|
|
|
} catch (Exception _) {
|
|
|
|
} finally {
|
|
|
|
LOG_SEMAPHORE.release();
|
|
|
|
return f;
|
|
|
|
}
|
2012-06-11 18:49:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private File findArtifactImpl(Artifact artifact) {
|
2011-06-10 08:33:20 +00:00
|
|
|
MavenJPackageDepmap.debug("=============JAVADIRREADER-FIND_ARTIFACT: "
|
|
|
|
+ artifact.getArtifactId());
|
2010-12-21 14:25:37 +00:00
|
|
|
StringBuffer path = new StringBuffer();
|
2011-07-04 12:25:05 +00:00
|
|
|
File ret = new File("");
|
2010-12-21 14:25:37 +00:00
|
|
|
String artifactId = artifact.getArtifactId();
|
|
|
|
String groupId = artifact.getGroupId();
|
|
|
|
String version = artifact.getVersion();
|
2012-07-25 07:59:34 +00:00
|
|
|
String wantedVersion = new String(version);
|
2010-12-21 14:25:37 +00:00
|
|
|
|
2012-10-18 07:40:36 +00:00
|
|
|
// let's check out local repo first
|
|
|
|
String m2_path = System.getProperty("maven.repo.local");
|
|
|
|
String gid_path = groupId.replace(".", File.separator);
|
2012-10-18 13:51:02 +00:00
|
|
|
String art_path = m2_path + File.separator + gid_path + File.separator
|
|
|
|
+ artifactId + File.separator + version + File.separator
|
|
|
|
+ artifactId + "-" + version + "." + artifact.getExtension();
|
2012-10-18 07:40:36 +00:00
|
|
|
|
|
|
|
ret = new File(art_path);
|
|
|
|
if (ret.isFile()) {
|
|
|
|
MavenJPackageDepmap.debug("Returning " + art_path.toString());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-10-18 13:51:02 +00:00
|
|
|
// maven.repo.local does not have needed GAV (that's normal), so let's
|
|
|
|
// just continue with system packages
|
2010-12-21 14:25:37 +00:00
|
|
|
MavenJPackageDepmap.debug("Wanted GROUPID=" + groupId);
|
|
|
|
MavenJPackageDepmap.debug("Wanted ARTIFACTID=" + artifactId);
|
2012-01-31 14:52:38 +00:00
|
|
|
MavenJPackageDepmap.debug("Wanted VERSION=" + version);
|
2012-10-18 13:51:02 +00:00
|
|
|
ArrayList<Hashtable<String, String>> maps = new ArrayList<Hashtable<String, String>>();
|
2011-05-10 11:40:59 +00:00
|
|
|
|
2010-12-21 14:25:37 +00:00
|
|
|
if (!groupId.startsWith("JPP")) {
|
|
|
|
MavenJPackageDepmap map = MavenJPackageDepmap.getInstance();
|
2012-10-18 13:51:02 +00:00
|
|
|
// let's try to get exact GAV first
|
2011-06-10 08:33:20 +00:00
|
|
|
Hashtable<String, String> newInfo = map.getMappedInfo(groupId,
|
|
|
|
artifactId, version);
|
2012-10-18 13:51:02 +00:00
|
|
|
if (newInfo == null) {
|
|
|
|
// exact GAV does not exist in our mapping so let's just get all
|
|
|
|
// GAs and iterate until we find one that exists. Note that only
|
|
|
|
// one non-versioned jar/pom for given GA should exist in order
|
|
|
|
// to ensure reproducibility
|
|
|
|
|
|
|
|
maps = map.getUnversionedMappedInfo(groupId, artifactId,
|
|
|
|
version);
|
|
|
|
} else {
|
|
|
|
maps.add(newInfo);
|
|
|
|
}
|
2010-12-21 14:25:37 +00:00
|
|
|
}
|
2012-01-31 14:52:38 +00:00
|
|
|
|
2012-10-18 13:51:02 +00:00
|
|
|
for (Hashtable<String, String> map : maps) {
|
|
|
|
groupId = map.get("group");
|
|
|
|
artifactId = map.get("artifact");
|
|
|
|
version = map.get("version");
|
|
|
|
|
|
|
|
MavenJPackageDepmap.debug("Resolved GROUPID=" + groupId);
|
|
|
|
MavenJPackageDepmap.debug("Resolved ARTIFACTID=" + artifactId);
|
|
|
|
MavenJPackageDepmap.debug("Resolved VERSION=" + version);
|
|
|
|
|
|
|
|
if (artifact.getExtension().equals("pom")) {
|
2012-10-19 07:39:08 +00:00
|
|
|
path = getPOMPath(groupId, artifactId, wantedVersion);
|
2011-07-04 12:25:05 +00:00
|
|
|
ret = new File(path.toString());
|
|
|
|
if (ret.isFile()) {
|
2012-10-18 13:51:02 +00:00
|
|
|
MavenJPackageDepmap.debug("Returning " + path.toString());
|
2011-07-04 12:25:05 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2012-10-18 13:51:02 +00:00
|
|
|
} else {
|
|
|
|
String repos[] = { "/usr/share/maven/repository/",
|
|
|
|
"/usr/share/maven/repository-java-jni/",
|
|
|
|
"/usr/share/maven/repository-jni/" };
|
|
|
|
String verRelativeArtifactPath = groupId + "/" + artifactId
|
|
|
|
+ "-" + wantedVersion + "." + artifact.getExtension();
|
|
|
|
String relativeArtifactPath = groupId + "/" + artifactId + "."
|
|
|
|
+ artifact.getExtension();
|
|
|
|
for (String repo : repos) {
|
|
|
|
path = new StringBuffer(repo + verRelativeArtifactPath);
|
|
|
|
ret = new File(path.toString());
|
|
|
|
if (ret.isFile()) {
|
|
|
|
MavenJPackageDepmap.debug("Returning " + repo
|
|
|
|
+ verRelativeArtifactPath);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = new StringBuffer(repo + relativeArtifactPath);
|
|
|
|
ret = new File(path.toString());
|
|
|
|
if (ret.isFile()) {
|
|
|
|
MavenJPackageDepmap.debug("Returning " + repo
|
|
|
|
+ relativeArtifactPath);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2011-07-04 12:25:05 +00:00
|
|
|
}
|
2010-12-21 14:25:37 +00:00
|
|
|
|
2012-10-18 13:51:02 +00:00
|
|
|
}
|
2011-01-11 15:40:20 +00:00
|
|
|
// if file doesn't exist return null to delegate to other
|
|
|
|
// resolvers (reactor/local repo)
|
2012-10-18 13:51:02 +00:00
|
|
|
MavenJPackageDepmap.debug("Returning null for gid:aid =>" + groupId
|
|
|
|
+ ":" + artifactId);
|
|
|
|
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>();
|
2012-01-31 13:11:08 +00:00
|
|
|
ret.add("LATEST");
|
2010-12-21 14:25:37 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-10-18 13:51:02 +00:00
|
|
|
private StringBuffer getPOMPath(String groupId, String artifactId,
|
|
|
|
String version) {
|
2011-06-10 08:33:20 +00:00
|
|
|
String fName = groupId.replace(PATH_SEPARATOR, GROUP_SEPARATOR) + "-"
|
|
|
|
+ artifactId + ".pom";
|
2012-10-18 13:51:02 +00:00
|
|
|
String verfName = groupId.replace(PATH_SEPARATOR, GROUP_SEPARATOR)
|
|
|
|
+ "-" + artifactId + "-" + version + ".pom";
|
2011-05-10 11:40:59 +00:00
|
|
|
File f;
|
2011-07-04 12:25:05 +00:00
|
|
|
String[] pomRepos = { "/usr/share/maven2/poms/",
|
|
|
|
"/usr/share/maven/poms/", "/usr/share/maven-poms/" };
|
|
|
|
|
|
|
|
for (String pomRepo : pomRepos) {
|
2012-01-31 14:52:38 +00:00
|
|
|
f = new File(pomRepo + verfName);
|
|
|
|
if (f.exists()) {
|
|
|
|
return new StringBuffer(f.getPath());
|
|
|
|
}
|
|
|
|
|
2011-07-04 12:25:05 +00:00
|
|
|
f = new File(pomRepo + fName);
|
|
|
|
if (f.exists()) {
|
|
|
|
return new StringBuffer(f.getPath());
|
|
|
|
}
|
2011-06-10 09:17:07 +00:00
|
|
|
}
|
|
|
|
|
2011-05-10 11:40:59 +00:00
|
|
|
// final fallback to m2 default poms
|
2011-06-22 09:56:09 +00:00
|
|
|
return new StringBuffer("/usr/share/maven2/default_poms/" + fName);
|
2010-12-21 14:25:37 +00:00
|
|
|
}
|
|
|
|
}
|