KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > tools > analyser > JarModuleFinder


1 package fr.jayasoft.ivy.tools.analyser;
2
3 import java.io.File JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import java.util.List JavaDoc;
6
7 import fr.jayasoft.ivy.ModuleRevisionId;
8 import fr.jayasoft.ivy.resolver.FileURLLister;
9 import fr.jayasoft.ivy.resolver.ResolverHelper;
10 import fr.jayasoft.ivy.resolver.URLLister;
11 import fr.jayasoft.ivy.util.IvyPatternHelper;
12
13 public class JarModuleFinder {
14     private String JavaDoc _pattern;
15     private String JavaDoc _filePattern;
16     
17     public JarModuleFinder(String JavaDoc pattern) {
18         _pattern = "file:///"+pattern;
19         _filePattern = pattern;
20     }
21
22     public JarModule[] findJarModules() {
23         List JavaDoc ret = new ArrayList JavaDoc();
24         URLLister lister = new FileURLLister();
25         try {
26             String JavaDoc[] orgs = ResolverHelper.listTokenValues(lister, _pattern, "organisation");
27             for (int i = 0; i < orgs.length; i++) {
28                 String JavaDoc orgPattern = IvyPatternHelper.substituteToken(_pattern, IvyPatternHelper.ORGANISATION_KEY, orgs[i]);
29                 String JavaDoc[] modules = ResolverHelper.listTokenValues(lister, orgPattern, "module");
30                 for (int j = 0; j < modules.length; j++) {
31                     String JavaDoc modPattern = IvyPatternHelper.substituteToken(orgPattern, IvyPatternHelper.MODULE_KEY, modules[j]);
32                     String JavaDoc [] revs = ResolverHelper.listTokenValues(lister, modPattern, "revision");
33                     for (int k = 0; k < revs.length; k++) {
34                         File JavaDoc jar = new File JavaDoc(IvyPatternHelper.substitute(_filePattern, orgs[i], modules[j], revs[k], modules[j], "jar", "jar"));
35                         if (jar.exists()) {
36                             ret.add(new JarModule(ModuleRevisionId.newInstance(orgs[i], modules[j], revs[k]), jar));
37                         }
38                     }
39                 }
40             }
41
42         } catch (Exception JavaDoc e) {
43             // TODO: handle exception
44
}
45         return (JarModule[]) ret.toArray(new JarModule[ret.size()]);
46     }
47
48     public static void main(String JavaDoc[] args) {
49         JarModule[] mods = new JarModuleFinder("D:/temp/test2/ivyrep/[organisation]/[module]/[revision]/[artifact].[ext]").findJarModules();
50         for (int i = 0; i < mods.length; i++) {
51             System.out.println(mods[i]);
52         }
53     }
54 }
55
Popular Tags