1 15 package org.apache.hivemind.ant; 16 17 import java.io.File ; 18 19 import org.apache.tools.ant.BuildException; 20 import org.apache.tools.ant.Task; 21 import org.apache.tools.ant.types.Path; 22 23 35 public class ManifestClassPath extends Task 36 { 37 private String _property; 38 private Path _classpath; 39 private File _directory; 40 41 public Path createClasspath() 42 { 43 _classpath = new Path(getProject()); 44 45 return _classpath; 46 } 47 48 public String getProperty() 49 { 50 return _property; 51 } 52 53 public void setProperty(String string) 54 { 55 _property = string; 56 } 57 58 public void execute() 59 { 60 if (_classpath == null) 61 throw new BuildException("You must specify a classpath to generate the manifest entry from"); 62 63 if (_property == null) 64 throw new BuildException("You must specify a property to assign the manifest classpath to"); 65 66 StringBuffer buffer = new StringBuffer (); 67 68 String [] paths = _classpath.list(); 69 70 String stripPrefix = null; 71 72 if (_directory != null) 73 stripPrefix = _directory.getPath(); 74 75 77 boolean needSep = false; 78 79 for (int i = 0; i < paths.length; i++) 80 { 81 String path = paths[i]; 82 83 if (stripPrefix != null) 84 { 85 if (!path.startsWith(stripPrefix)) 86 continue; 87 88 92 if (path.length() == stripPrefix.length()) 93 continue; 94 95 if (needSep) 96 buffer.append(' '); 97 98 101 buffer.append(filter(path.substring(stripPrefix.length() + 1))); 102 103 needSep = true; 104 105 } 106 else 107 { 108 if (needSep) 109 buffer.append(' '); 110 111 File f = new File (path); 112 113 buffer.append(f.getName()); 114 115 needSep = true; 116 } 117 } 118 119 getProject().setProperty(_property, buffer.toString()); 120 } 121 122 public File getDirectory() 123 { 124 return _directory; 125 } 126 127 135 public void setDirectory(File file) 136 { 137 _directory = file; 138 } 139 140 144 protected String filter(String value) 145 { 146 if (File.separatorChar == '/') 147 return value; 148 149 return value.replace(File.separatorChar, '/'); 150 } 151 } 152 | Popular Tags |