1 23 package org.apache.tools.ant.taskdefs.optional.sun.verification; 24 25 import org.apache.tools.ant.Task; 26 import org.apache.tools.ant.BuildException; 27 import org.apache.tools.ant.types.Environment; 28 import org.apache.tools.ant.taskdefs.Java; 29 import org.apache.tools.ant.taskdefs.Echo; 30 import org.apache.tools.ant.taskdefs.Delete; 31 import org.apache.tools.ant.types.Path; 32 33 import java.io.File ; 34 import java.io.IOException ; 35 import java.io.FileInputStream ; 36 import java.util.Properties ; 37 43 44 50 public class AVKTasks extends Task { 51 52 protected String jvmArgs = null; 53 protected boolean failOnError = true; 54 protected String j2ee_home = null; 55 protected String avk_home = null; 56 protected String java_home = null; 57 protected String resultDir = null; 58 protected Echo echo = null; 59 60 public AVKTasks() { 61 java_home = System.getProperty("java.home")+"/../"; } 63 64 public void setJvmArgs(String jvmArgs) { 65 this.jvmArgs = jvmArgs; 66 } 67 68 public void setFailOnError(boolean failOnError) { 69 this.failOnError = failOnError; 70 } 71 72 protected void setResultDir(String resultDir) { 73 this.resultDir = resultDir.trim(); 74 } 75 76 private void createEchoTask () { 77 echo = (Echo)getProject().createTask("echo"); 78 } 79 80 84 protected Java createJavaTask() { 85 Java java = (Java)project.createTask("java"); 86 java.setClasspath(constructJVMPath()); 87 if(jvmArgs == null) 88 jvmArgs = "-Xss512k -Xms128m -Xmx256m"; 89 setCommonVMSettings(java); 90 setSystemProperties(java); 91 return java; 92 } 93 94 protected void setSystemProperties(Java java) { 95 Environment.Variable j2ee_app_home = new Environment.Variable(); 96 j2ee_app_home.setKey("j2ee.appverification.home"); 97 j2ee_app_home.setValue(avk_home); 98 java.addSysproperty(j2ee_app_home); 99 100 Environment.Variable java_ext_dir = new Environment.Variable(); 101 java_ext_dir.setKey("java.ext.dirs"); 102 java_ext_dir.setValue(System.getProperty("java.ext.dirs") + 103 File.pathSeparator + j2ee_home + 104 File.separator + "domains" + 105 File.separator + "domain1" + 106 File.separator + "lib" + 107 File.separator + "ext"); 108 java.addSysproperty(java_ext_dir); 109 110 Environment.Variable installRoot = new Environment.Variable(); 111 installRoot.setKey("com.sun.aas.installRoot"); 112 installRoot.setValue(j2ee_home); 113 java.addSysproperty(installRoot); 114 115 Environment.Variable j2eeHome = new Environment.Variable(); 117 j2eeHome.setKey("j2ee.home"); 118 j2eeHome.setValue(j2ee_home); 119 java.addSysproperty(j2eeHome); 120 121 Environment.Variable javaHome = new Environment.Variable(); 122 javaHome.setKey("as.java"); 123 javaHome.setValue(java_home); 124 java.addSysproperty(javaHome); 125 126 Environment.Variable endorsedDir = new Environment.Variable(); 127 endorsedDir.setKey("java.endorsed.dirs"); 128 endorsedDir.setValue(j2ee_home+File.separator + "lib" + File.separator + "endorsed"); 129 java.addSysproperty(endorsedDir); 130 131 Environment.Variable xsl = new Environment.Variable(); 132 xsl.setKey("com.sun.aas.verifier.xsl"); 133 xsl.setValue(avk_home + File.separator + "xsl"); 134 java.addSysproperty(xsl); 135 } 136 137 protected Path constructJVMPath() { 138 StringBuffer classPathBuffer = new StringBuffer (); 139 classPathBuffer.append(avk_home+"/lib/javke.jar:"); 140 classPathBuffer.append(j2ee_home+"/lib/appserv-rt.jar:"); 141 classPathBuffer.append(j2ee_home+"/lib/javaee.jar:"); 142 classPathBuffer.append(j2ee_home+"/lib/appserv-ext.jar:"); 143 classPathBuffer.append(j2ee_home+"/lib/appserv-cmp.jar:"); 144 classPathBuffer.append(j2ee_home+"/lib/appserv-admin.jar:"); 145 classPathBuffer.append(j2ee_home+"/lib/install/applications/jmsra/imqjmsra.jar:"); 146 classPathBuffer.append(j2ee_home+"/lib/jhall.jar:"); 147 148 return new Path(getProject(),classPathBuffer.toString()); 150 } 151 152 protected void getInstallHomes() throws BuildException { 153 createEchoTask(); 155 156 if(avk_home == null) 157 try { 158 avk_home = new File (getProject().getProperty("avk.home")).getCanonicalPath(); 159 } catch (IOException e) { avk_home = new File (getProject().getProperty("avk.home")).getAbsolutePath(); 161 } 162 163 try { 164 File avkENV = new File (avk_home+File.separatorChar+"config", "avkenv.conf"); 165 Properties props = new Properties (); 166 props.load(new FileInputStream (avkENV)); 167 if(j2ee_home == null) 168 try { 169 j2ee_home = new File (props.getProperty("J2EE_HOME")).getCanonicalPath(); 170 } catch (IOException e) { j2ee_home = new File (props.getProperty("J2EE_HOME")).getAbsolutePath(); 172 } 173 } catch (IOException e) { 174 echo.setMessage("Problem in getting J2EE_HOME. Please ensure that avkenv.conf " + 175 "is kept in the config directory. "+e.getMessage()); 176 echo.execute(); 177 } 178 } 179 180 protected void setCommonVMSettings(Java java) { 181 java.setFork(true); 182 java.setFailonerror(failOnError); 183 java.createJvmarg().setLine(jvmArgs); 185 } 186 187 192 protected void createResultDir(String dirName) { 193 if(resultDir == null) 194 resultDir = avk_home+File.separator + "reporttool"; 195 resultDir = resultDir + File.separator +dirName; 196 File file = new File (resultDir); 197 try { 198 cleanDir(resultDir); 199 if ( file.getParent() !=null) { 200 (new File (file.getParent())).mkdirs(); 201 file.mkdir(); 202 } 203 }catch( Exception e) { 204 throw new BuildException("Could not create output directory "+resultDir); 205 } 206 } 207 208 protected void setArgs(Java java, String [] args) { 209 for (int i = 0; i < args.length; i++) { 210 java.createArg().setLine(args[i] + " "); 211 } 212 } 213 214 protected void cleanDir(String resultDir) { 215 Delete delete = (Delete)getProject().createTask("delete"); 216 delete.setDir(new File (resultDir)); 217 delete.setQuiet(true); 218 delete.setIncludeEmptyDirs(true); 219 delete.execute(); 220 } 221 222 } 223 | Popular Tags |