47 {
48 /**
49 * Run the script, using the parameters set up by the standard initialization
50 * methods.
51 */
52 public void run() {
53
54 PrintWriter trOut = getTestResult().getTestCommentWriter();
55 TestDescription td = getTestDescription();
56
57 for (int i = 0; i < scriptArgs.length; i++) {
58 if (scriptArgs[i].equals("-debug"))
59 debug = true;
60 else {
61 setStatus(Status.error("bad args for script: " + scriptArgs[i]));
62 return;
63 } // else
64 } // for
65
66 String prefix = "script.";
67 Set testKeys = td.getKeywordTable();
68 Vector<String> choices = new Vector<>(); // the set of choices
69 Vector<String> matches = new Vector<>(); // the set of matches
70 int wordsMatchingInMatches = 0;// the number of words matching
71
72 findMatch:
73 for (Iterator iter = env.keys().iterator(); iter.hasNext(); ) {
74 String key = (String) (iter.next());
75
76 // if the key does not begin with the `script.' prefix, ignore key
77 if (!key.startsWith(prefix))
78 continue;
79
80 if (debug)
81 trOut.println("CHECKING " + key);
82
83 String keyList = key.substring(prefix.length()).replace('_', ' ').toLowerCase();
84 String[] keys = StringArray.split(keyList);
85
86 choices.addElement(keyList);
87
88 if (debug)
89 trOut.println("keys: " + StringArray.join(keys));
90
91 // if there are no words after the `script.' prefix,
92 // or if it has fewer words than the best match so far, ignore key
93 if (keys == null || keys.length < wordsMatchingInMatches)
94 continue;
160 String[] command = env.lookup(bestScript);
161 if (command.length == 0) {
162 String s = "INTERNAL ERROR: failed to lookup key: " + bestScript;
163 trOut.println(s);
164 setStatus(Status.error(s));
165 return;
166 }
167
168 trOut.println("test: " + td.getRootRelativeURL());
169 trOut.println("script: " + this.getClass().getName() + " " +
170 StringArray.join(scriptArgs));
171
172 String[] msgs = {
173 "Based on these keywords: " +
174 bestScript.substring(prefix.length()).replace('_', ' ').toLowerCase(),
175 "this script has now been selected: " + " " +
176 StringArray.join(command) };
177 printStrArr(trOut, msgs);
178
179 try {
180 Class c = Class.forName(command[0]);
181
182 Script script = (Script)c.newInstance();
183 String[] scriptArgs = new String[command.length - 1];
184 System.arraycopy(command, 1, scriptArgs, 0, scriptArgs.length);
185 initDelegate(script, scriptArgs);
186
187 script.run();
188 }
189 catch (ClassNotFoundException ex) {
190 setStatus(Status.error("Can't find class `" +
191 command[0] + "' for `" + env.getName() + "'"));
192 }
193 catch (IllegalAccessException ex) {
194 setStatus(Status.error("Illegal access to class `" +
195 command[0] + "' for `" + env.getName() + "'"));
196 }
197 catch (InstantiationException ex) {
198 setStatus(Status.error("Can't instantiate class`" +
199 command[0] + "' for `" + env.getName() + "'"));
200 }
|
47 {
48 /**
49 * Run the script, using the parameters set up by the standard initialization
50 * methods.
51 */
52 public void run() {
53
54 PrintWriter trOut = getTestResult().getTestCommentWriter();
55 TestDescription td = getTestDescription();
56
57 for (int i = 0; i < scriptArgs.length; i++) {
58 if (scriptArgs[i].equals("-debug"))
59 debug = true;
60 else {
61 setStatus(Status.error("bad args for script: " + scriptArgs[i]));
62 return;
63 } // else
64 } // for
65
66 String prefix = "script.";
67 Set<String> testKeys = td.getKeywordTable();
68 Vector<String> choices = new Vector<>(); // the set of choices
69 Vector<String> matches = new Vector<>(); // the set of matches
70 int wordsMatchingInMatches = 0;// the number of words matching
71
72 findMatch:
73 for (Iterator<String> iter = env.keys().iterator(); iter.hasNext(); ) {
74 String key = (iter.next());
75
76 // if the key does not begin with the `script.' prefix, ignore key
77 if (!key.startsWith(prefix))
78 continue;
79
80 if (debug)
81 trOut.println("CHECKING " + key);
82
83 String keyList = key.substring(prefix.length()).replace('_', ' ').toLowerCase();
84 String[] keys = StringArray.split(keyList);
85
86 choices.addElement(keyList);
87
88 if (debug)
89 trOut.println("keys: " + StringArray.join(keys));
90
91 // if there are no words after the `script.' prefix,
92 // or if it has fewer words than the best match so far, ignore key
93 if (keys == null || keys.length < wordsMatchingInMatches)
94 continue;
160 String[] command = env.lookup(bestScript);
161 if (command.length == 0) {
162 String s = "INTERNAL ERROR: failed to lookup key: " + bestScript;
163 trOut.println(s);
164 setStatus(Status.error(s));
165 return;
166 }
167
168 trOut.println("test: " + td.getRootRelativeURL());
169 trOut.println("script: " + this.getClass().getName() + " " +
170 StringArray.join(scriptArgs));
171
172 String[] msgs = {
173 "Based on these keywords: " +
174 bestScript.substring(prefix.length()).replace('_', ' ').toLowerCase(),
175 "this script has now been selected: " + " " +
176 StringArray.join(command) };
177 printStrArr(trOut, msgs);
178
179 try {
180 Class<?> c = Class.forName(command[0]);
181
182 Script script = (Script)c.newInstance();
183 String[] scriptArgs = new String[command.length - 1];
184 System.arraycopy(command, 1, scriptArgs, 0, scriptArgs.length);
185 initDelegate(script, scriptArgs);
186
187 script.run();
188 }
189 catch (ClassNotFoundException ex) {
190 setStatus(Status.error("Can't find class `" +
191 command[0] + "' for `" + env.getName() + "'"));
192 }
193 catch (IllegalAccessException ex) {
194 setStatus(Status.error("Illegal access to class `" +
195 command[0] + "' for `" + env.getName() + "'"));
196 }
197 catch (InstantiationException ex) {
198 setStatus(Status.error("Can't instantiate class`" +
199 command[0] + "' for `" + env.getName() + "'"));
200 }
|