1 16 package org.apache.cocoon.components.language.programming.java; 17 18 import org.apache.avalon.framework.logger.AbstractLogEnabled; 19 import org.apache.avalon.excalibur.pool.Recyclable; 20 import org.apache.cocoon.components.language.programming.LanguageCompiler; 21 22 import java.io.BufferedReader ; 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 import java.io.InputStreamReader ; 26 import java.util.List ; 27 28 34 public abstract class AbstractJavaCompiler extends AbstractLogEnabled implements LanguageCompiler, Recyclable { 35 36 39 protected String file; 40 41 44 protected String srcDir; 45 46 49 protected String destDir; 50 51 54 protected String classpath; 55 56 60 protected String encoding = null; 61 62 66 protected int compilerComplianceLevel; 67 68 71 protected InputStream errors; 72 73 78 public void setFile(String file) { 79 this.file = file; 80 } 81 82 87 public void setSource(String srcDir) { 88 this.srcDir = srcDir; 89 } 90 91 97 public void setDestination(String destDir) { 98 this.destDir = destDir; 99 } 100 101 106 public void setClasspath(String classpath) { 107 this.classpath = classpath; 108 } 109 110 117 public void setEncoding(String encoding) { 118 this.encoding = encoding; 119 } 120 121 129 public void setCompilerComplianceLevel(int compilerComplianceLevel) { 130 this.compilerComplianceLevel = compilerComplianceLevel; 131 } 132 133 139 public List getErrors() throws IOException { 140 return parseStream(new BufferedReader (new InputStreamReader (errors))); 141 } 142 143 151 protected abstract List parseStream(BufferedReader errors) 152 throws IOException ; 153 154 160 161 protected List fillArguments(List arguments) { 162 176 arguments.add("-d"); 178 arguments.add(destDir); 179 180 arguments.add("-classpath"); 182 arguments.add(classpath); 183 184 arguments.add("-sourcepath"); 186 arguments.add(srcDir); 187 188 arguments.add("-O"); 190 191 if (encoding != null) { 193 arguments.add("-encoding"); 194 arguments.add(encoding); 195 } 196 return arguments; 197 } 198 199 205 protected String [] toStringArray(List arguments) { 206 int i; 207 String [] args = new String [arguments.size() + 1]; 208 209 for (i = 0; i < arguments.size(); i++) { 210 args[i] = (String )arguments.get(i); 211 } 212 213 args[i] = file; 214 215 return args; 216 } 217 218 222 public void recycle() { 223 file = null; 224 srcDir = null; 225 destDir = null; 226 classpath = null; 227 encoding = null; 228 errors = null; 229 } 230 } 231 | Popular Tags |