1 23 package org.apache.tools.ant.taskdefs.optional.sun.verification; 24 25 import org.apache.tools.ant.BuildException; 26 import org.apache.tools.ant.types.Path; 27 import org.apache.tools.ant.types.Environment; 28 import org.apache.tools.ant.taskdefs.Java; 29 30 import java.io.File ; 31 import java.util.ArrayList ; 32 import java.util.List ; 33 34 35 49 public class TranslateRuntimeDD extends AVKTasks { 50 51 private File archiveName = null; 52 private String srcServer = null; 53 54 public void setArchiveName(File archiveName) { 55 this.archiveName = archiveName; 56 } 57 58 public void setSrcServer(String srcServer) { 59 this.srcServer = srcServer; 60 } 61 62 66 public void execute() throws BuildException { 67 68 checkArgs(); 69 getInstallHomes(); 70 71 jvmArgs = "-hotspot -ms96m -mx512m -DENABLE_CLIP=true -Dasmt.home="+avk_home+" -DPACKAGE_PROPERTY_FILE="+avk_home+"/config/package.properties "; 73 74 if(invokeIASMT() != 0 && failOnError) 75 throw new BuildException("Problem in executing java command"); 76 77 if(invokeGenReportTool() != 0 && failOnError) 78 throw new BuildException("Problem in executing java command"); 79 80 echo.setMessage("See \""+resultDir+File.separator+"translationSummary.html\" for results."); 82 echo.execute(); 83 echo.setMessage("We attempted to create an ear file even if minor errors occurred. The application with translated deployment descriptors is in a new .ear file located in "+resultDir+File.separator+"Input_Archives"+File.separator+"asmtbuild "); 84 echo.execute(); 85 } 86 87 88 92 private int invokeIASMT() { 93 Java java = (Java)project.createTask("java"); 94 java.setClassname("sun.iasmt.user.IASMTMain"); 95 setCommonVMSettings(java); 96 java.setClasspath(constructPath()); 97 Environment.Variable sysp = new Environment.Variable(); 98 sysp.setKey("asmt.home"); 99 sysp.setValue(avk_home); 100 101 createResultDir("translate"); 102 java.addSysproperty(sysp); 103 java.createArg().setLine("-c -t "+resultDir+ 104 " -S "+srcServer+ 105 " -x "+resultDir+File.separator+"result.xml "+ 106 "-n -q -T sjs80PE "+ archiveName); 107 108 int returnCode = java.executeJava(); 109 110 createEar(); 113 114 return returnCode; 115 } 116 117 124 125 private void createEar() { 126 String archivePath = resultDir + File.separator + "Input_Archives"; 127 File earFile = new File (archivePath + File.separator + "asmtbuild", 128 archiveName.getName()); 129 String buildFile = archivePath+File.separator+"build_ear.xml"; 130 if(!earFile.exists() && new File (buildFile).exists()) { 131 echo.setMessage("Some xml files may not have translated correctly."); 132 echo.execute(); 133 Java java = (Java)project.createTask("java"); 134 135 java.setClassname("org.apache.tools.ant.Main"); 136 setCommonVMSettings(java); 137 java.setClasspath(getPathForCreateEar()); 138 addEnvVariablesForCreateEar(java); 139 java.createArg().setLine("-buildfile "+buildFile+" -quiet"); 140 int returnStatus = java.executeJava(); 141 if(returnStatus==1) { 142 echo.setMessage("Some errors occurred while building the ear. You can find " + 143 "the generated code at ["+archivePath+"]"); 144 echo.execute(); 145 }else 146 echo.setMessage( "The EAR file may not deploy successfully in "+ 147 "the Application Server. Please check the " + 148 "runtime descriptors before deploying."); 149 150 } 151 } 152 153 private Path getPathForCreateEar() { 155 String j2ee_lib = j2ee_home + File.separator + "lib"; 156 StringBuffer classPathBuffer = new StringBuffer (); 157 String [] CLASSPATH_ELEMENTS = { "lib"+File.separator+"asmt-rt.jar", 158 "lib"+File.separator+"ant.jar"}; 159 classPathBuffer.append(java_home+"lib" + File.separator+ 160 "tools.jar"+File.pathSeparator); 161 classPathBuffer.append(j2ee_lib + File.separator+ 162 "javaee.jar"+File.pathSeparator); 163 for(int i=0;i<CLASSPATH_ELEMENTS.length;i++) { 167 classPathBuffer.append((new File (avk_home,CLASSPATH_ELEMENTS[i])).getPath()); 168 classPathBuffer.append(File.pathSeparator); 169 } 170 return new Path(getProject(),classPathBuffer.toString()); 171 } 172 173 private void addEnvVariablesForCreateEar(Java java) { 175 Environment.Variable asmt = new Environment.Variable(); 176 asmt.setKey("asmt.home"); 177 asmt.setValue(avk_home); 178 java.addSysproperty(asmt); 179 180 Environment.Variable vml = new Environment.Variable(); 181 vml.setKey("vml"); 182 vml.setValue("true"); 183 java.addSysproperty(vml); 184 185 Environment.Variable javahome = new Environment.Variable(); 186 javahome.setKey("javahome"); 187 javahome.setValue(java_home); 188 java.addSysproperty(javahome); 189 190 Environment.Variable iashome = new Environment.Variable(); 191 iashome.setKey("ias.home"); 192 iashome.setValue(j2ee_home); 193 java.addSysproperty(iashome); 194 } 195 196 200 private int invokeGenReportTool() { 201 Java java = createJavaTask(); 202 List <String > list = new ArrayList <String >(); 203 204 list.add(resultDir + File.separator + "result.xml"); 205 list.add(resultDir); 206 list.add("translationSummary"); 207 String [] args = (String [])list.toArray(new String [1]); 208 209 java.setClassname("com.sun.enterprise.appverification.tools.GenReportTool"); 210 setArgs(java, args); 211 212 return java.executeJava(); 213 } 214 215 216 private Path constructPath() { 217 String j2ee_lib = j2ee_home + File.separator + "lib"; 218 StringBuffer classPathBuffer = new StringBuffer (); 219 220 221 String [] CLASSPATH_ELEMENTS = {"lib"+File.separator+"xalan.jar", 222 "lib"+File.separator +"ant.jar", 223 "lib"+File.separator+"dom4j.jar", 224 "lib"+File.separator+"namespace.jar", 225 "lib"+File.separator+"asmt.jar", 226 "lib"+File.separator+"relaxngDatatype.jar", 227 "lib"+File.separator+"jaxb-api.jar", 228 "lib"+File.separator+"jaxb-impl.jar", 229 "lib"+File.separator+"jaxb-libs.jar", 230 "lib"+File.separator+"jax-qname.jar", 231 "lib"+File.separator+"jhall.jar", 232 "lib"+File.separator+"asmt_en.jar"}; 233 classPathBuffer.append(java_home+"lib" +File.separator+ 234 "tools.jar"+File.pathSeparator); 235 236 for(int i=0;i<CLASSPATH_ELEMENTS.length;i++) { 237 classPathBuffer.append((new File (avk_home,CLASSPATH_ELEMENTS[i])).getPath()); 238 classPathBuffer.append(File.pathSeparator); 239 } 240 classPathBuffer.append(j2ee_lib+File.separator+ 241 "j2ee.jar"+File.pathSeparator); 242 return new Path(getProject(),classPathBuffer.toString()); 243 } 244 245 250 private void checkArgs() throws BuildException { 251 if(archiveName == null || !archiveName.exists()) 252 throw new BuildException("Provide a valid fully qualified " + 253 "path of the archive to be translated: archiveName = "+archiveName); 254 255 if( !archiveName.isFile()) 256 throw new BuildException("Provide a valid fullly qualified " + 257 "archive be translated: archiveName = "+archiveName); 258 259 if(srcServer == null) 260 throw new BuildException("Must specify which app server was used to create the application"); 261 else if(srcServer.equalsIgnoreCase("sunone65")) 262 srcServer = "as65"; 263 else if(srcServer.equalsIgnoreCase("sjsappserver7")) 264 srcServer = "as70"; 265 else if(srcServer.equalsIgnoreCase("weblogic5")) 266 srcServer = "wl51"; 267 else if(srcServer.equalsIgnoreCase("weblogic6")) 268 srcServer = "wl60"; 269 else if(srcServer.equalsIgnoreCase("weblogic61")) 270 srcServer = "wl61"; 271 else if(srcServer.equalsIgnoreCase("weblogic81")) 272 srcServer = "wl81"; 273 else if(srcServer.equalsIgnoreCase("websphere4")) 274 srcServer = "ws40"; 275 else if(srcServer.equalsIgnoreCase("websphere51")) 276 srcServer = "ws50"; 277 else if(srcServer.equalsIgnoreCase("tomcat")) 278 srcServer = "tc41"; 279 else if(srcServer.equalsIgnoreCase("J2EESDK13")) 280 srcServer = "ri13"; 281 else if(srcServer.equalsIgnoreCase("J2EESDK14")) 282 srcServer = "ri14"; 283 else if(srcServer.equalsIgnoreCase("JBoss3")) 284 srcServer = "jb30"; 285 else 286 throw new BuildException("srcServer = "+srcServer+" is not one of " + 287 "(sunone65, sjsappserver7, weblogic5, weblogic6, weblogic61, weblogic81, websphere4, websphere51, j2eesdk13, j2eesdk14, jboss3 and tomcat)"); 288 289 } 290 } 291 | Popular Tags |