1 18 package org.apache.tools.ant.taskdefs.optional.jlink; 19 20 import java.io.File ; 21 import org.apache.tools.ant.BuildException; 22 import org.apache.tools.ant.Project; 23 import org.apache.tools.ant.taskdefs.MatchingTask; 24 import org.apache.tools.ant.types.Path; 25 26 54 public class JlinkTask extends MatchingTask { 55 56 60 public void setOutfile(File outfile) { 61 this.outfile = outfile; 62 } 63 64 69 public Path createMergefiles() { 70 if (this.mergefiles == null) { 71 this.mergefiles = new Path(getProject()); 72 } 73 return this.mergefiles.createPath(); 74 } 75 76 80 public void setMergefiles(Path mergefiles) { 81 if (this.mergefiles == null) { 82 this.mergefiles = mergefiles; 83 } else { 84 this.mergefiles.append(mergefiles); 85 } 86 } 87 88 93 public Path createAddfiles() { 94 if (this.addfiles == null) { 95 this.addfiles = new Path(getProject()); 96 } 97 return this.addfiles.createPath(); 98 } 99 100 104 public void setAddfiles(Path addfiles) { 105 if (this.addfiles == null) { 106 this.addfiles = addfiles; 107 } else { 108 this.addfiles.append(addfiles); 109 } 110 } 111 112 116 public void setCompress(boolean compress) { 117 this.compress = compress; 118 } 119 120 124 public void execute() throws BuildException { 125 if (outfile == null) { 127 throw new BuildException("outfile attribute is required! " 128 + "Please set."); 129 } 130 if (!haveAddFiles() && !haveMergeFiles()) { 131 throw new BuildException("addfiles or mergefiles required! " 132 + "Please set."); 133 } 134 log("linking: " + outfile.getPath()); 135 log("compression: " + compress, Project.MSG_VERBOSE); 136 jlink linker = new jlink(); 137 linker.setOutfile(outfile.getPath()); 138 linker.setCompression(compress); 139 if (haveMergeFiles()) { 140 log("merge files: " + mergefiles.toString(), Project.MSG_VERBOSE); 141 linker.addMergeFiles(mergefiles.list()); 142 } 143 if (haveAddFiles()) { 144 log("add files: " + addfiles.toString(), Project.MSG_VERBOSE); 145 linker.addAddFiles(addfiles.list()); 146 } 147 try { 148 linker.link(); 149 } catch (Exception ex) { 150 throw new BuildException(ex, getLocation()); 151 } 152 } 153 154 private boolean haveAddFiles() { 155 return haveEntries(addfiles); 156 } 157 158 private boolean haveMergeFiles() { 159 return haveEntries(mergefiles); 160 } 161 162 private boolean haveEntries(Path p) { 163 if (p == null) { 164 return false; 165 } 166 if (p.size() > 0) { 167 return true; 168 } 169 return false; 170 } 171 172 private File outfile = null; 173 174 private Path mergefiles = null; 175 176 private Path addfiles = null; 177 178 private boolean compress = false; 179 180 } 181 182 183 | Popular Tags |