2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package gov.nasa.jpf.tool;
21 import gov.nasa.jpf.Config;
22 import gov.nasa.jpf.JPFClassLoader;
23 import gov.nasa.jpf.util.FileUtils;
24 import gov.nasa.jpf.util.JPFSiteUtils;
25 import gov.nasa.jpf.util.event.EventTree;
29 * very simple tool to print .util.script.EventTrees
31 * <2do> this should use native_classpath / JPFClassLoader to load the EventTree
33 public class PrintEvents {
35 static boolean printTree;
36 static boolean printPaths;
37 static String clsName;
39 static void showUsage () {
40 System.out.println("usage: 'PrintEvents [<option>..] <className>'");
41 System.out.println("options: -t : print tree");
42 System.out.println(" -p : print paths");
45 static boolean readOptions (String[] args) {
46 for (int i = 0; i < args.length; i++) {
49 if ("-t".equals(arg)) {
51 } else if ("-p".equals(arg)) {
53 } else if (arg.charAt(0) != '-') {
55 if (clsName.charAt(0) == '.'){
56 clsName = "gov.nasa.jpf" + clsName;
59 System.err.println("unknown option: " + arg);
66 return (clsName != null);
69 static String[] getTestPathElements (Config config){
70 String projectId = JPFSiteUtils.getCurrentProjectId();
72 if (projectId != null) {
73 String testCpKey = projectId + ".test_classpath";
74 return config.getCompactTrimmedStringArray(testCpKey);
81 static void addTestClassPath (JPFClassLoader cl, String[] testPathElements){
82 if (testPathElements != null) {
83 for (String pe : testPathElements) {
85 cl.addURL(FileUtils.getURL(pe));
86 } catch (Throwable x) {
87 System.err.println("malformed test_classpath URL: " + pe);
93 public static void main (String[] args){
94 if ((args.length == 0) || !readOptions(args)) {
98 Config config = new Config(args);
99 String[] testPathElements = getTestPathElements(config);
100 JPFClassLoader cl = config.initClassLoader(RunTest.class.getClassLoader());
101 addTestClassPath( cl, testPathElements);
104 Class<EventTree> cls = (Class<EventTree>)cl.loadClass(clsName);
105 EventTree et = cls.newInstance();
108 System.out.println("---------------- event tree of " + clsName);
113 System.out.println("---------------- event paths of " + clsName);
116 } catch (ClassNotFoundException cnfx){
117 System.err.println("class not found: " + clsName);
118 } catch (NoClassDefFoundError ncdf){
119 System.err.println("class does not load: " + ncdf.getMessage());
120 } catch (InstantiationException ex) {
121 System.err.println("cannot instantiate: " + ex.getMessage());
122 } catch (IllegalAccessException ex) {
123 System.err.println("cannot instantiate: " + ex.getMessage());