KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > maven > xpom > AddDependency


1 /* ====================================================================
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  * ====================================================================
16  */

17
18 package org.apache.geronimo.maven.xpom;
19
20 import java.io.File JavaDoc;
21 import java.util.List JavaDoc;
22
23 import org.apache.commons.jelly.JellyTagException;
24 import org.apache.commons.jelly.MissingAttributeException;
25 import org.apache.commons.jelly.XMLOutput;
26 import org.apache.maven.jelly.tags.BaseTagSupport;
27 import org.apache.maven.project.Dependency;
28 import org.apache.maven.project.Project;
29 import org.apache.maven.repository.Artifact;
30 import org.apache.maven.repository.DefaultArtifactFactory;
31
32 public class AddDependency extends BaseTagSupport {
33
34
35     private Dependency dependency;
36
37     public AddDependency() {
38         dependency = new Dependency();
39     }
40
41     public void setProperty(String JavaDoc combinedProperty) {
42         if (combinedProperty == null) {
43             return;
44         }
45         dependency.addProperty("property:" + combinedProperty);
46     }
47
48     public void setProperties(String JavaDoc combinedProperties) {
49
50         if (combinedProperties == null) {
51             return;
52         }
53
54         String JavaDoc[] strings = combinedProperties.split(",");
55         for (int i = 0; i < strings.length; i++) {
56             setProperty(strings[i].trim());
57         }
58     }
59
60     public void setGroupId(String JavaDoc s) {
61         if (s == null) {
62             return;
63         }
64         dependency.setGroupId(s);
65     }
66
67     public void setArtifactId(String JavaDoc s) {
68         if (s == null) {
69             return;
70         }
71         dependency.setArtifactId(s);
72     }
73
74     public void setVersion(String JavaDoc s) {
75         if (s == null) {
76             return;
77         }
78         dependency.setVersion(s);
79     }
80
81     public void setType(String JavaDoc s) {
82         if (s == null) {
83             return;
84         }
85         dependency.setType(s);
86     }
87
88     public void setJar(String JavaDoc s) {
89         if (s == null) {
90             return;
91         }
92         dependency.setJar(s);
93     }
94
95     public void setUrl(String JavaDoc s) {
96         if (s == null) {
97             return;
98         }
99         dependency.setUrl(s);
100     }
101
102     public void setId(String JavaDoc s) {
103         if (s == null) {
104             return;
105         }
106
107         dependency.setId(s);
108     }
109
110     public String JavaDoc getGroupId() {
111         return dependency.getGroupId();
112     }
113
114     public String JavaDoc getId() throws IllegalStateException JavaDoc {
115         return dependency.getId();
116     }
117
118     public String JavaDoc getArtifactId() {
119         return dependency.getArtifactId();
120     }
121
122     public String JavaDoc getVersion() {
123         return dependency.getVersion();
124     }
125
126     public String JavaDoc getJar() {
127         return dependency.getJar();
128     }
129
130     public String JavaDoc getUrl() {
131         return dependency.getUrl();
132     }
133
134     public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
135         try {
136             if (dependency.getJar() != null){
137                 Artifact artifact = DefaultArtifactFactory.createArtifact(dependency);
138                 // Munge the paths
139
File JavaDoc jarFile = new File JavaDoc(dependency.getJar());
140                 artifact.setPath(jarFile.getAbsolutePath());
141                 dependency.setJar(jarFile.getName());
142                 // Add artifact and dependency to project
143
Project project = getMavenContext().getProject();
144                 project.addDependency(dependency);
145                 project.getArtifacts().add(artifact);
146             } else {
147                 Project project = getMavenContext().getProject();
148                 project.addDependency(dependency);
149                 project.buildArtifactList();
150             }
151         } catch (Exception JavaDoc e) {
152             throw new JellyTagException(e);
153         }
154     }
155 }
156
Popular Tags