1 18 package org.apache.tools.ant.taskdefs.optional.junit; 19 20 import java.io.BufferedOutputStream ; 21 import java.io.ByteArrayOutputStream ; 22 import java.io.File ; 23 import java.io.FileOutputStream ; 24 import java.io.IOException ; 25 import java.io.OutputStream ; 26 import java.lang.reflect.Field ; 27 import org.apache.tools.ant.BuildException; 28 import org.apache.tools.ant.Project; 29 30 36 abstract class XalanExecutor { 37 private static final String PACKAGE = 38 "org.apache.tools.ant.taskdefs.optional.junit."; 39 40 42 protected AggregateTransformer caller; 43 45 46 private void setCaller(AggregateTransformer caller) { 47 this.caller = caller; 48 } 49 50 51 protected final OutputStream getOutputStream() throws IOException { 52 if (AggregateTransformer.FRAMES.equals(caller.format)) { 53 return new ByteArrayOutputStream (); 56 } else { 57 return new BufferedOutputStream ( 58 new FileOutputStream (new File (caller.toDir, "junit-noframes.html"))); 59 } 60 } 61 62 63 abstract void execute() throws Exception ; 64 65 72 static XalanExecutor newInstance(AggregateTransformer caller) 73 throws BuildException { 74 XalanExecutor executor = null; 75 try { 76 Class clazz = Class.forName(PACKAGE + "Xalan2Executor"); 77 executor = (XalanExecutor) clazz.newInstance(); 78 } catch (Exception xsltcApacheMissing) { 79 caller.task.log(xsltcApacheMissing.toString()); 80 throw new BuildException("Could not find xstlc nor xalan2 " 81 + "in the classpath. Check " 82 + "http://xml.apache.org/xalan-j"); 83 } 84 String classNameImpl = executor.getImplementation(); 85 String version = executor.getProcVersion(classNameImpl); 86 caller.task.log("Using " + version, Project.MSG_VERBOSE); 87 executor.setCaller(caller); 88 return executor; 89 } 90 91 98 protected abstract String getImplementation(); 99 100 109 protected abstract String getProcVersion(String classNameImpl) 110 throws BuildException; 111 112 113 protected final String getXSLTCVersion(String procVersionClassName) 114 throws ClassNotFoundException { 115 Class procVersion = Class.forName(procVersionClassName); 118 Package pkg = procVersion.getPackage(); 119 return pkg.getName() + " " + pkg.getImplementationTitle() 120 + " " + pkg.getImplementationVersion(); 121 } 122 123 124 protected final String getXalanVersion(String procVersionClassName) 125 throws ClassNotFoundException { 126 Class procVersion = Class.forName(procVersionClassName); 127 String pkg = procVersion.getPackage().getName(); 128 try { 129 Field f = procVersion.getField("S_VERSION"); 130 return pkg + " " + f.get(null).toString(); 131 } catch (Exception e) { 132 return pkg + " ?.?"; 133 } 134 } 135 } 136 | Popular Tags |