1 18 package org.apache.tools.ant.util; 19 20 import org.apache.tools.ant.ProjectComponent; 21 import org.apache.tools.ant.types.Path; 22 import java.io.File ; 23 import org.apache.tools.ant.types.Reference; 24 25 26 30 public class ScriptRunnerHelper { 31 private ClasspathUtils.Delegate cpDelegate = null; 32 private File srcFile; 33 private String manager = "auto"; 34 private String language; 35 private String text; 36 private boolean setBeans = true; 37 private ProjectComponent projectComponent; 38 private ClassLoader scriptLoader = null; 39 40 44 public void setProjectComponent(ProjectComponent component) { 45 this.projectComponent = component; 46 } 47 48 52 public ScriptRunnerBase getScriptRunner() { 53 ScriptRunnerBase runner = getRunner(); 54 if (srcFile != null) { 55 runner.setSrc(srcFile); 56 } 57 if (text != null) { 58 runner.addText(text); 59 } 60 if (setBeans) { 61 runner.bindToComponent(projectComponent); 62 } else { 63 runner.bindToComponentMinimum(projectComponent); 64 } 65 return runner; 66 } 67 68 73 public Path createClasspath() { 74 return getClassPathDelegate().createClasspath(); 75 } 76 77 82 public void setClasspath(Path classpath) { 83 getClassPathDelegate().setClasspath(classpath); 84 } 85 86 92 public void setClasspathRef(Reference r) { 93 getClassPathDelegate().setClasspathref(r); 94 } 95 96 101 public void setSrc(File file) { 102 this.srcFile = file; 103 } 104 105 110 public void addText(String text) { 111 this.text = text; 112 } 113 114 119 public void setManager(String manager) { 120 this.manager = manager; 121 } 122 123 128 public void setLanguage(String language) { 129 this.language = language; 130 } 131 132 136 public String getLanguage() { 137 return language; 138 } 139 140 150 public void setSetBeans(boolean setBeans) { 151 this.setBeans = setBeans; 152 } 153 154 158 public void setClassLoader(ClassLoader loader) { 159 scriptLoader = loader; 160 } 161 162 163 private ClassLoader generateClassLoader() { 164 if (scriptLoader != null) { 165 return scriptLoader; 166 } 167 if (cpDelegate == null) { 168 scriptLoader = getClass().getClassLoader(); 169 return scriptLoader; 170 } 171 172 scriptLoader = cpDelegate.getClassLoader(); 173 return scriptLoader; 174 } 175 176 private ClasspathUtils.Delegate getClassPathDelegate() { 177 if (cpDelegate == null) { 178 cpDelegate = ClasspathUtils.getDelegate(projectComponent); 179 } 180 return cpDelegate; 181 } 182 183 186 private ScriptRunnerBase getRunner() { 187 return new ScriptRunnerCreator( 188 projectComponent.getProject()).createRunner( 189 manager, language, generateClassLoader()); 190 } 191 } 192 | Popular Tags |