KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > sun > verification > SourceScan


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

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 JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.List JavaDoc;
33
34 /**
35  * This is the implementation for running source scan through Ant task.
36  * This task runs the following two classses -
37  * Invokes IASMTMain by passing the appropriate arguments,
38  * Invokes the org.apache.xalan.xslt.Process class for transformation.
39  * <p>
40  * The attributes of this task are: <br>
41  * srcDir ="REQUIRED" <br>
42  * srcServer ="REQUIRED" (Options are: sunone, weblogic5, weblogic6, websphere, jboss)<br>
43  * jvmArgs ="OPTIONAL" (default: "-hotspot -ms96m -mx512m") <br>
44  * failOnError="OPTIONAL" (default: true) <br>
45  * <p>
46  *
47  * @author Vikas Awasthi.
48  */

49 public class SourceScan extends AVKTasks {
50     
51     private File JavaDoc srcDir = null;
52     private String JavaDoc srcServer = null;
53
54     public void setSrcDir(File JavaDoc srcDir) {
55         this.srcDir = srcDir;
56     }
57
58     public void setSrcServer(String JavaDoc srcServer) {
59         this.srcServer = srcServer;
60     }
61
62     /**
63      * This is called by the ant framework.
64      * @throws BuildException
65      */

66     public void execute() throws BuildException {
67
68         checkArgs();
69         getInstallHomes();
70
71 // temporary until migration code has CLIP interface as default
72
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     /**
86      * Invokes the sun.iasmt.user.IASMTMain
87      * @return integer denoting the return status of the command. 1 is failure
88      */

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     /**
109      * Invokes the com.sun.enterprise.appverification.tools.GenReportTool
110      * @return integer denoting the return status of the command. 1 is failure
111      */

112     private int invokeGenReportTool() {
113         Java java = createJavaTask();
114         List JavaDoc<String JavaDoc> list = new ArrayList JavaDoc<String JavaDoc>();
115
116         list.add(resultDir + File.separator + "result.xml");
117         list.add(resultDir);
118         list.add("codeSummary");
119         String JavaDoc[] args = (String JavaDoc[])list.toArray(new String JavaDoc[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 JavaDoc j2ee_lib=j2ee_home + File.separator+"lib";
129         StringBuffer JavaDoc classPathBuffer = new StringBuffer JavaDoc();
130         String JavaDoc[] 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 JavaDoc(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     /**
155      * Parse the source server argument. Throw exception if invalid
156      * option is found.
157      * @throws BuildException
158      */

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