%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
nl.toolforge.karma.core.scm.maven.MavenDependencyReader |
|
|
1 | /* |
|
2 | Karma core - Core of the Karma application |
|
3 | Copyright (C) 2004 Toolforge <www.toolforge.nl> |
|
4 | ||
5 | This library is free software; you can redistribute it and/or |
|
6 | modify it under the terms of the GNU Lesser General Public |
|
7 | License as published by the Free Software Foundation; either |
|
8 | version 2.1 of the License, or (at your option) any later version. |
|
9 | ||
10 | This library is distributed in the hope that it will be useful, |
|
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 | Lesser General Public License for more details. |
|
14 | ||
15 | You should have received a copy of the GNU Lesser General Public |
|
16 | License along with this library; if not, write to the Free Software |
|
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | */ |
|
19 | package nl.toolforge.karma.core.scm.maven; |
|
20 | ||
21 | import nl.toolforge.karma.core.KarmaException; |
|
22 | import org.apache.commons.digester.Digester; |
|
23 | import org.xml.sax.SAXException; |
|
24 | ||
25 | import java.io.File; |
|
26 | import java.io.FileInputStream; |
|
27 | import java.io.FileNotFoundException; |
|
28 | import java.io.IOException; |
|
29 | import java.io.InputStream; |
|
30 | import java.util.List; |
|
31 | ||
32 | ||
33 | /** |
|
34 | * This class is a lightweight reader for Maven project.xml's. Using the Maven stuff itself sucks, as it |
|
35 | * is very heavy stuff for the purpose of reading the project's dependencies only. |
|
36 | * |
|
37 | * @author D.A. Smedes |
|
38 | */ |
|
39 | 0 | public class MavenDependencyReader { |
40 | ||
41 | // todo name the correct maven dependency |
|
42 | // |
|
43 | /** |
|
44 | * Parses a Maven project.xml file and stores all <code><dependency></code>-elements in a <code>List</code>. |
|
45 | * |
|
46 | * @param dependencyFileIs |
|
47 | * @return A <code>List</code>, containing <code>org.apache.maven.project.Dependency</code> instances. |
|
48 | */ |
|
49 | public List parse(InputStream dependencyFileIs) throws KarmaException { |
|
50 | ||
51 | 0 | Digester digester = new Digester(); |
52 | ||
53 | 0 | digester.addObjectCreate("project", "java.template.ArrayList"); |
54 | 0 | digester.addObjectCreate("project/dependencies/dependency", "org.apache.maven.project.Dependency"); |
55 | ||
56 | 0 | digester.addCallMethod("project/dependencies/dependency/Id", "setId", 1); |
57 | 0 | digester.addCallParam("project/dependencies/dependency/Id", 0); |
58 | 0 | digester.addCallMethod("project/dependencies/dependency/groupId", "setGroupId", 1); |
59 | 0 | digester.addCallParam("project/dependencies/dependency/groupId", 0); |
60 | 0 | digester.addCallMethod("project/dependencies/dependency/artifactId", "setArtifactId", 1); |
61 | 0 | digester.addCallParam("project/dependencies/dependency/artifactId", 0); |
62 | 0 | digester.addCallMethod("project/dependencies/dependency/version", "setVersion", 1); |
63 | 0 | digester.addCallParam("project/dependencies/dependency/version", 0); |
64 | 0 | digester.addCallMethod("project/dependencies/dependency/jar", "setJar", 1); |
65 | 0 | digester.addCallParam("project/dependencies/dependency/jar", 0); |
66 | ||
67 | // Call List.add(Dependency) |
|
68 | // |
|
69 | 0 | digester.addSetNext("project/dependencies/dependency", "add", "org.apache.maven.project.Dependency"); |
70 | ||
71 | 0 | List deps = null; |
72 | try { |
|
73 | 0 | deps = (List) digester.parse(dependencyFileIs); |
74 | 0 | } catch (IOException e) { |
75 | 0 | e.printStackTrace(); |
76 | // throw new KarmaException(KarmaException.LAZY_BASTARD); |
|
77 | 0 | } catch (SAXException e) { |
78 | 0 | e.printStackTrace(); |
79 | // throw new KarmaException(KarmaException.LAZY_BASTARD); |
|
80 | 0 | } |
81 | ||
82 | 0 | return deps; |
83 | } |
|
84 | ||
85 | public List parse(File projectXmlFile) throws KarmaException { |
|
86 | try { |
|
87 | 0 | return parse(new FileInputStream(projectXmlFile)); |
88 | 0 | } catch (FileNotFoundException e) { |
89 | 0 | throw new KarmaException(KarmaException.NO_MAVEN_PROJECT_XML); |
90 | } |
|
91 | } |
|
92 | } |
|
93 |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |