1 17 18 package org.apache.geronimo.maven.xpom; 19 20 import java.io.File ; 21 import java.util.List ; 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 combinedProperty) { 42 if (combinedProperty == null) { 43 return; 44 } 45 dependency.addProperty("property:" + combinedProperty); 46 } 47 48 public void setProperties(String combinedProperties) { 49 50 if (combinedProperties == null) { 51 return; 52 } 53 54 String [] 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 s) { 61 if (s == null) { 62 return; 63 } 64 dependency.setGroupId(s); 65 } 66 67 public void setArtifactId(String s) { 68 if (s == null) { 69 return; 70 } 71 dependency.setArtifactId(s); 72 } 73 74 public void setVersion(String s) { 75 if (s == null) { 76 return; 77 } 78 dependency.setVersion(s); 79 } 80 81 public void setType(String s) { 82 if (s == null) { 83 return; 84 } 85 dependency.setType(s); 86 } 87 88 public void setJar(String s) { 89 if (s == null) { 90 return; 91 } 92 dependency.setJar(s); 93 } 94 95 public void setUrl(String s) { 96 if (s == null) { 97 return; 98 } 99 dependency.setUrl(s); 100 } 101 102 public void setId(String s) { 103 if (s == null) { 104 return; 105 } 106 107 dependency.setId(s); 108 } 109 110 public String getGroupId() { 111 return dependency.getGroupId(); 112 } 113 114 public String getId() throws IllegalStateException { 115 return dependency.getId(); 116 } 117 118 public String getArtifactId() { 119 return dependency.getArtifactId(); 120 } 121 122 public String getVersion() { 123 return dependency.getVersion(); 124 } 125 126 public String getJar() { 127 return dependency.getJar(); 128 } 129 130 public String 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 File jarFile = new File (dependency.getJar()); 140 artifact.setPath(jarFile.getAbsolutePath()); 141 dependency.setJar(jarFile.getName()); 142 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 e) { 152 throw new JellyTagException(e); 153 } 154 } 155 } 156 | Popular Tags |