01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.ivy.tools.analyser;
19:
20: import java.io.File;
21: import java.util.ArrayList;
22: import java.util.List;
23:
24: import org.apache.ivy.core.IvyPatternHelper;
25: import org.apache.ivy.core.module.id.ModuleRevisionId;
26: import org.apache.ivy.plugins.resolver.util.FileURLLister;
27: import org.apache.ivy.plugins.resolver.util.ResolverHelper;
28: import org.apache.ivy.plugins.resolver.util.URLLister;
29:
30: public class JarModuleFinder {
31: private String _pattern;
32:
33: private String _filePattern;
34:
35: public JarModuleFinder(String pattern) {
36: _pattern = "file:///" + pattern;
37: _filePattern = pattern;
38: }
39:
40: public JarModule[] findJarModules() {
41: List ret = new ArrayList();
42: URLLister lister = new FileURLLister();
43: try {
44: String[] orgs = ResolverHelper.listTokenValues(lister,
45: _pattern, "organisation");
46: for (int i = 0; i < orgs.length; i++) {
47: String orgPattern = IvyPatternHelper.substituteToken(
48: _pattern, IvyPatternHelper.ORGANISATION_KEY,
49: orgs[i]);
50: String[] modules = ResolverHelper.listTokenValues(
51: lister, orgPattern, "module");
52: for (int j = 0; j < modules.length; j++) {
53: String modPattern = IvyPatternHelper
54: .substituteToken(orgPattern,
55: IvyPatternHelper.MODULE_KEY,
56: modules[j]);
57: String[] revs = ResolverHelper.listTokenValues(
58: lister, modPattern, "revision");
59: for (int k = 0; k < revs.length; k++) {
60: File jar = new File(IvyPatternHelper
61: .substitute(_filePattern, orgs[i],
62: modules[j], revs[k],
63: modules[j], "jar", "jar"));
64: if (jar.exists()) {
65: ret.add(new JarModule(ModuleRevisionId
66: .newInstance(orgs[i], modules[j],
67: revs[k]), jar));
68: }
69: }
70: }
71: }
72:
73: } catch (Exception e) {
74: // TODO: handle exception
75: }
76: return (JarModule[]) ret.toArray(new JarModule[ret.size()]);
77: }
78:
79: public static void main(String[] args) {
80: JarModule[] mods = new JarModuleFinder(
81: "D:/temp/test2/ivyrep/[organisation]/[module]/[revision]/[artifact].[ext]")
82: .findJarModules();
83: for (int i = 0; i < mods.length; i++) {
84: System.out.println(mods[i]);
85: }
86: }
87: }
|