1 19 package org.java.plugin.tools.ant; 20 21 import java.io.File ; 22 import java.net.MalformedURLException ; 23 import java.net.URL ; 24 25 import org.apache.tools.ant.BuildException; 26 import org.apache.tools.ant.Task; 27 import org.java.plugin.ObjectFactory; 28 import org.java.plugin.registry.ManifestProcessingException; 29 import org.java.plugin.registry.Version; 30 import org.java.plugin.registry.PluginRegistry.ManifestInfo; 31 import org.java.plugin.util.IoUtil; 32 33 40 public class PluginInfoTask extends Task { 41 private File manifest; 42 private String propertyId; 43 private String propertyVersion; 44 private String propertyVendor; 45 private String propertyPluginId; 46 private String propertyPluginVersion; 47 private String propertyMatchingRule; 48 49 52 public void setManifest(final File aManifest) { 53 manifest = aManifest; 54 } 55 56 62 public void setPropertyId(String propertyName) { 63 propertyId = propertyName; 64 } 65 66 72 public void setPropertyVersion(String propertyName) { 73 propertyVersion = propertyName; 74 } 75 76 82 public void setPropertyVendor(String propertyName) { 83 propertyVendor = propertyName; 84 } 85 86 91 public void setPropertyPluginId(String propertyName) { 92 propertyPluginId = propertyName; 93 } 94 95 100 public void setPropertyPluginVersion(String propertyName) { 101 propertyPluginVersion = propertyName; 102 } 103 104 110 public void setPropertyMatchingRule(String propertyName) { 111 this.propertyMatchingRule = propertyName; 112 } 113 114 117 public void execute() throws BuildException { 118 if (manifest == null) { 119 throw new BuildException("manifest attribute must be set!", getLocation()); 121 } 122 URL url; 123 try { 124 url = IoUtil.file2url(manifest); 125 } catch (MalformedURLException mue) { 126 throw new BuildException("failed converting file " + manifest + " to URL", mue, getLocation()); } 129 ManifestInfo manifestInfo; 130 try { 131 manifestInfo = ObjectFactory.newInstance().createRegistry() 132 .readManifestInfo(url); 133 log("Data read from manifest " + manifest); } catch (ManifestProcessingException mpe) { 135 throw new BuildException("failed reading data from manifest " + url, mpe, getLocation()); 137 } 138 if (propertyId != null) { 139 getProject().setProperty(propertyId, manifestInfo.getId()); 140 } 141 if (propertyVersion != null) { 142 Version version = manifestInfo.getVersion(); 143 getProject().setProperty(propertyVersion, 144 (version != null) ? version.toString() : ""); } 146 if (propertyVendor != null) { 147 String value = manifestInfo.getVendor(); 148 getProject().setProperty(propertyVendor, 149 (value != null) ? value : ""); } 151 if (propertyPluginId != null) { 152 String value = manifestInfo.getPluginId(); 153 getProject().setProperty(propertyPluginId, 154 (value != null) ? value : ""); } 156 if (propertyPluginVersion != null) { 157 Version version = manifestInfo.getPluginVersion(); 158 getProject().setProperty(propertyPluginVersion, 159 (version != null) ? version.toString() : ""); } 161 if (propertyMatchingRule != null) { 162 String value = manifestInfo.getMatchingRule(); 163 getProject().setProperty(propertyMatchingRule, 164 (value != null) ? value : ""); } 166 } 167 } 168 | Popular Tags |