blob: 2124a05ea618ce29c9aac26527b25d8bb9bb7604 [file] [log] [blame]
Stuart McCulloch26e7a5a2011-10-17 10:31:43 +00001package aQute.bnd.maven.support;
2
3import java.io.*;
4import java.net.*;
5import java.util.*;
6import java.util.concurrent.*;
7import java.util.regex.*;
8
9/*
10 http://repository.springsource.com/maven/bundles/external/org/apache/coyote/com.springsource.org.apache.coyote/6.0.24/com.springsource.org.apache.coyote-6.0.24.pom
11 http://repository.springsource.com/maven/bundles/external/org/apache/coyote/com.springsource.org.apache.coyote/6.0.24/com.springsource.org.apache.coyote-6.0.24.pom
12 */
13public class Maven {
14 final File userHome = new File(System.getProperty("user.home"));
15 final Map<String, MavenEntry> entries = new ConcurrentHashMap<String, MavenEntry>();
16 final static String[] ALGORITHMS = { "md5", "sha1" };
17 boolean usecache = false;
18 final Executor executor;
19 File m2 = new File(userHome, ".m2");
20 File repository = new File(m2, "repository");
21
22 public Maven(Executor executor) {
23 if ( executor == null)
24 this.executor = Executors.newCachedThreadPool();
25 else
26 this.executor = executor;
27 }
28
29 //http://repo1.maven.org/maven2/junit/junit/maven-metadata.xml
30
31 static Pattern MAVEN_RANGE = Pattern.compile("(\\[|\\()(.+)(,(.+))(\\]|\\))");
32 public CachedPom getPom(String groupId, String artifactId, String version, URI... extra)
33 throws Exception {
34 MavenEntry entry = getEntry(groupId, artifactId, version);
35 return entry.getPom(extra);
36 }
37
38 /**
39 * @param groupId
40 * @param artifactId
41 * @param version
42 * @param extra
43 * @return
44 * @throws Exception
45 */
46 public MavenEntry getEntry(String groupId, String artifactId, String version) throws Exception {
47 String path = path(groupId, artifactId, version);
48
49 MavenEntry entry;
50 synchronized (entries) {
51 entry = entries.get(path);
52 if (entry != null)
53 return entry;
54
55 entry = new MavenEntry(this, path);
56 entries.put(path, entry);
57 }
58 return entry;
59 }
60
61 private String path(String groupId, String artifactId, String version) {
62 return groupId.replace('.', '/') + '/' + artifactId + '/' + version + "/" + artifactId
63 + "-" + version;
64 }
65
66 public void schedule(Runnable runnable) {
67 if (executor == null)
68 runnable.run();
69 else
70 executor.execute(runnable);
71 }
72
73 public ProjectPom createProjectModel(File file) throws Exception {
74 ProjectPom pom = new ProjectPom(this, file);
75 pom.parse();
76 return pom;
77 }
78
79 public MavenEntry getEntry(Pom pom) throws Exception {
80 return getEntry(pom.getGroupId(), pom.getArtifactId(), pom.getVersion());
81 }
82
83 public void setM2(File dir) {
84 this.m2 = dir;
85 this.repository = new File(dir,"repository");
86 }
87
88}