1 18 package org.apache.tools.ant.taskdefs.optional.extension.resolvers; 19 20 import java.io.File ; 21 import java.io.IOException ; 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.Project; 24 import org.apache.tools.ant.taskdefs.Ant; 25 import org.apache.tools.ant.taskdefs.optional.extension.Extension; 26 import org.apache.tools.ant.taskdefs.optional.extension.ExtensionResolver; 27 28 32 public class AntResolver implements ExtensionResolver { 33 private File antfile; 34 private File destfile; 35 private String target; 36 37 41 public void setAntfile(final File antfile) { 42 this.antfile = antfile; 43 } 44 45 49 public void setDestfile(final File destfile) { 50 this.destfile = destfile; 51 } 52 53 57 public void setTarget(final String target) { 58 this.target = target; 59 } 60 61 68 public File resolve(final Extension extension, 69 final Project project) throws BuildException { 70 validate(); 71 72 final Ant ant = new Ant(); 73 ant.setProject(project); 74 ant.setInheritAll(false); 75 ant.setAntfile(antfile.getName()); 76 77 try { 78 final File dir = 79 antfile.getParentFile().getCanonicalFile(); 80 ant.setDir(dir); 81 } catch (final IOException ioe) { 82 throw new BuildException(ioe.getMessage(), ioe); 83 } 84 85 if (null != target) { 86 ant.setTarget(target); 87 } 88 89 ant.execute(); 90 91 return destfile; 92 } 93 94 97 private void validate() { 98 if (null == antfile) { 99 final String message = "Must specify Buildfile"; 100 throw new BuildException(message); 101 } 102 103 if (null == destfile) { 104 final String message = "Must specify destination file"; 105 throw new BuildException(message); 106 } 107 } 108 109 113 public String toString() { 114 return "Ant[" + antfile + "==>" + destfile + "]"; 115 } 116 } 117 | Popular Tags |