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.io.IOException;
22:
23: import org.apache.ivy.core.IvyPatternHelper;
24: import org.apache.ivy.core.module.descriptor.DefaultArtifact;
25: import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
26: import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter;
27: import org.apache.ivy.util.Message;
28:
29: public class RepositoryAnalyser {
30: public void analyse(String pattern, DependencyAnalyser depAnalyser) {
31: JarModuleFinder finder = new JarModuleFinder(pattern);
32: ModuleDescriptor[] mds = depAnalyser.analyze(finder
33: .findJarModules());
34: Message.info("found " + mds.length + " modules");
35: for (int i = 0; i < mds.length; i++) {
36: File ivyFile = new File(IvyPatternHelper.substitute(
37: pattern, DefaultArtifact.newIvyArtifact(mds[i]
38: .getModuleRevisionId(), mds[i]
39: .getPublicationDate())));
40: try {
41: Message.info("generating " + ivyFile);
42: XmlModuleDescriptorWriter.write(mds[i], ivyFile);
43: } catch (IOException e) {
44: // TODO Auto-generated catch block
45: e.printStackTrace();
46: }
47: }
48: }
49:
50: public static void main(String[] args) {
51: if (args.length != 2) {
52: System.out
53: .println("usage: ivyanalyser path/to/jarjar.jar absolute-ivy-repository-pattern");
54: return;
55: }
56: String jarjarLocation = args[0];
57: String pattern = args[1];
58:
59: JarJarDependencyAnalyser a = new JarJarDependencyAnalyser(
60: new File(jarjarLocation));
61: new RepositoryAnalyser().analyse(pattern, a);
62: }
63: }
|