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 49 public class SourceScan extends AVKTasks { 50 51 private File srcDir = null; 52 private String srcServer = null; 53 54 public void setSrcDir(File srcDir) { 55 this.srcDir = srcDir; 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 if(jvmArgs == null) 73 jvmArgs = "-hotspot -ms96m -mx512m -Dasmt.home="+avk_home+" -DPACKAGE_PROPERTY_FILE="+avk_home+"/config/package.properties -DENABLE_CLIP=true"; 74 75 if(invokeIASMT() !=0 && failOnError) 76 throw new BuildException("Problem in scanning source code"); 77 78 if(invokeGenReportTool() !=0 && failOnError) 79 throw new BuildException("Problem in generating reports"); 80 81 echo.setMessage("See \""+resultDir+File.separator+"codeSummary.html\" for results."); 82 echo.execute(); 83 } 84 85 89 private int invokeIASMT() { 90 Java java = (Java)project.createTask("java"); 91 java.setClassname("sun.iasmt.user.IASMTMain"); 92 setCommonVMSettings(java); 93 java.setClasspath(constructPath()); 94 Environment.Variable sysp = new Environment.Variable(); 95 sysp.setKey("asmt.home"); 96 sysp.setValue(avk_home); 97 createResultDir("scan"); 98 99 java.addSysproperty(sysp); 100 java.createArg().setLine("-c -t "+resultDir+ 101 " -S "+srcServer+ 102 " -s "+srcDir+ 103 " -T sjs80PE -n -q"+ 104 " -x "+resultDir+File.separator+"result.xml"); 105 106 return java.executeJava(); 107 } 108 112 private int invokeGenReportTool() { 113 Java java = createJavaTask(); 114 List <String > list = new ArrayList <String >(); 115 116 list.add(resultDir + File.separator + "result.xml"); 117 list.add(resultDir); 118 list.add("codeSummary"); 119 String [] args = (String [])list.toArray(new String [1]); 120 121 java.setClassname("com.sun.enterprise.appverification.tools.GenReportTool"); 122 setArgs(java, args); 123 124 return java.executeJava(); 125 } 126 127 private Path constructPath() { 128 String j2ee_lib=j2ee_home + File.separator+"lib"; 129 StringBuffer classPathBuffer = new StringBuffer (); 130 String [] CLASSPATH_ELEMENTS = { 131 "lib"+File.separator +"ant.jar", 132 "lib"+File.separator +"xalan.jar", 133 "lib"+File.separator +"jhall.jar", 134 "lib"+File.separator +"dom4j.jar", 135 "lib"+File.separator +"asmt.jar", 136 "lib"+File.separator +"jaxb-api.jar", 137 "lib"+File.separator +"jaxb-impl.jar", 138 "lib"+File.separator +"jaxb-libs.jar", 139 "lib"+File.separator +"namespace.jar", 140 "lib"+File.separator +"asmt_en.jar", 141 "lib"+File.separator +"jax-qname.jar", 142 "lib"+File.separator +"relaxngDatatype.jar"}; 143 classPathBuffer.append(java_home+"lib"+File.separator + 144 "tools.jar"+File.pathSeparator); 145 for(int i=0;i<CLASSPATH_ELEMENTS.length;i++) { 146 classPathBuffer.append((new File (avk_home,CLASSPATH_ELEMENTS[i])).getPath()); 147 classPathBuffer.append(File.pathSeparator); 148 } 149 classPathBuffer.append(j2ee_lib+File.separator+ 150 "javaee.jar"+File.pathSeparator); 151 return new Path(getProject(),classPathBuffer.toString()); 152 } 153 154 159 private void checkArgs() throws BuildException { 160 if(srcDir == null || !srcDir.exists()) 161 throw new BuildException("Provide a valid fullly qualified " + 162 "path of the source directory to be scanned: srcDir = "+srcDir); 163 164 if(srcServer == null) 165 throw new BuildException("Must specify which app server was used to create the application"); 166 else if(srcServer.equalsIgnoreCase("sunone")) 167 srcServer = "as70"; 168 else if(srcServer.equalsIgnoreCase("weblogic5")) 169 srcServer = "wl51"; 170 else if(srcServer.equalsIgnoreCase("weblogic6")) 171 srcServer = "wl60"; 172 else if(srcServer.equalsIgnoreCase("weblogic8")) 173 srcServer = "wl81"; 174 else if(srcServer.equalsIgnoreCase("websphere4")) 175 srcServer = "ws40"; 176 else if(srcServer.equalsIgnoreCase("websphere50")) 177 srcServer = "ws50"; 178 else if(srcServer.equalsIgnoreCase("tomcat")) 179 srcServer = "tc41"; 180 else if(srcServer.equalsIgnoreCase("JBoss")) 181 srcServer = "jb30"; 182 else 183 throw new BuildException("srcServer = "+srcServer+" is not one of " + 184 "(sunone, weblogic5, weblogic6, weblogic8, websphere4, websphere50 and jboss )"); 185 186 } 187 } 188 | Popular Tags |