1 19 20 package org.apache.tools.ant.module.api; 21 22 import java.io.IOException ; 23 import java.io.OutputStream ; 24 import java.util.Properties ; 25 import org.apache.tools.ant.module.AntSettings; 26 import org.apache.tools.ant.module.run.TargetExecutor; 27 import org.openide.execution.ExecutorTask; 28 import org.openide.util.NbCollections; 29 30 34 final public class AntTargetExecutor { 35 36 private final Env env; 37 38 40 private AntTargetExecutor(Env env) { 41 this.env = env; 42 } 43 44 50 public static AntTargetExecutor createTargetExecutor(Env env) { 51 return new AntTargetExecutor(env); 52 } 53 54 76 public ExecutorTask execute(AntProjectCookie antProject, String [] targets) throws IOException { 77 TargetExecutor te = new TargetExecutor(antProject, targets); 78 te.setVerbosity(env.getVerbosity()); 79 te.setProperties(NbCollections.checkedMapByCopy(env.getProperties(), String .class, String .class, true)); 80 if (env.getLogger() == null) { 81 return te.execute(); 82 } else { 83 return te.execute(env.getLogger()); 84 } 85 } 86 87 91 final public static class Env { 92 93 private int verbosity; 94 private Properties properties; 95 private OutputStream outputStream; 96 97 99 public Env() { 100 verbosity = AntSettings.getVerbosity(); 101 properties = new Properties (); 102 properties.putAll(AntSettings.getProperties()); 103 } 104 105 109 public void setVerbosity(int v) { 110 verbosity = v; 111 } 112 113 116 public int getVerbosity() { 117 return verbosity; 118 } 119 120 123 public synchronized void setProperties(Properties p) { 124 properties = (Properties ) p.clone(); 125 } 126 127 131 public synchronized Properties getProperties() { 132 return (Properties )properties.clone(); 133 } 134 135 143 @Deprecated 144 public void setLogger(OutputStream outputStream) { 145 this.outputStream = outputStream; 146 } 147 148 153 public OutputStream getLogger() { 154 return outputStream; 155 } 156 157 } 158 159 } 160 | Popular Tags |