Package: TraceRunnerMain$1

TraceRunnerMain$1

nameinstructionbranchcomplexitylinemethod
run()
M: 6 C: 47
89%
M: 3 C: 5
63%
M: 3 C: 2
40%
M: 3 C: 9
75%
M: 0 C: 1
100%
{...}
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * #%~
3: * Combinatorial Testing Runtime
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ct.ctruntime;
23:
24: import java.io.File;
25: import java.io.IOException;
26: import java.io.InputStream;
27: import java.io.OutputStream;
28: import java.io.PrintWriter;
29: import java.lang.Thread.UncaughtExceptionHandler;
30: import java.net.InetAddress;
31: import java.net.Socket;
32: import java.net.URI;
33: import java.net.URISyntaxException;
34: import java.nio.charset.Charset;
35: import java.util.Arrays;
36: import java.util.Iterator;
37: import java.util.List;
38: import java.util.Map;
39: import java.util.Vector;
40:
41: import org.overture.ast.lex.Dialect;
42: import org.overture.config.Release;
43: import org.overture.config.Settings;
44: import org.overture.ct.utils.TraceXmlWrapper;
45: import org.overture.interpreter.VDMJ;
46: import org.overture.interpreter.VDMPP;
47: import org.overture.interpreter.VDMRT;
48: import org.overture.interpreter.VDMSL;
49: import org.overture.interpreter.messages.Console;
50: import org.overture.interpreter.messages.rtlog.RTLogger;
51: import org.overture.interpreter.messages.rtlog.RTTextLogger;
52: import org.overture.interpreter.messages.rtlog.nextgen.NextGenRTLogger;
53: import org.overture.interpreter.runtime.ContextException;
54: import org.overture.interpreter.runtime.Interpreter;
55: import org.overture.interpreter.runtime.SourceFile;
56: import org.overture.interpreter.runtime.ValueException;
57: import org.overture.interpreter.traces.TraceReductionType;
58: import org.overture.interpreter.util.ExitStatus;
59: import org.overture.parser.config.Properties;
60: import org.overture.parser.lex.LexTokenReader;
61: import org.overture.typechecker.TypeChecker;
62: import org.overture.typechecker.assistant.TypeCheckerAssistantFactory;
63: import org.overture.util.Base64;
64:
65: public class TraceRunnerMain implements IProgressMonitor
66: {
67:         public static boolean USE_SYSTEM_EXIT = true;
68:         private final static boolean DEBUG = false;
69:         
70:         protected final String host;
71:         protected final int port;
72:         protected final String ideKey;
73:         protected final String moduleName;
74:         protected final String traceName;
75:         protected final File traceFolder;
76:         protected Socket socket;
77:         protected InputStream input;
78:         protected OutputStream output;
79:         protected final Interpreter interpreter;
80:
81:         protected int sessionId = 0;
82:         protected String transaction = "";
83:         protected byte separator = '\0';
84:
85:         protected boolean connected = false;
86:
87:         protected boolean completed = false;
88:
89:         float subset = 1.0F;
90:         TraceReductionType reductionType = TraceReductionType.NONE;
91:         long seed = 999;
92:
93:         public TraceRunnerMain(String host, int port, String ideKey,
94:                         Interpreter interpreter, String moduleName, String traceName,
95:                         File traceFolder, float subset,
96:                         TraceReductionType traceReductionType, long seed)
97:         {
98:                 this.host = host;
99:                 this.port = port;
100:                 this.ideKey = ideKey;
101:                 this.moduleName = moduleName;
102:                 this.interpreter = interpreter;
103:                 this.traceName = traceName;
104:                 this.traceFolder = traceFolder;
105:
106:                 this.seed = seed;
107:                 this.reductionType = traceReductionType;
108:                 this.subset = subset;
109:         }
110:
111:         /**
112:          * @param args
113:          * the args
114:          */
115:         public static void main(String[] args)
116:         {
117:                 Settings.usingDBGP = false;
118:
119:                 String host = null;
120:                 int port = -1;
121:                 String ideKey = null;
122:                 Settings.dialect = null;
123:                 String moduleName = null;
124:                 List<File> files = new Vector<File>();
125:                 List<String> largs = Arrays.asList(args);
126:                 VDMJ controller = null;
127:                 boolean warnings = true;
128:                 boolean quiet = false;
129:                 String logfile = null;
130:                 boolean expBase64 = false;
131:                 boolean traceNameBase64 = false;
132:                 File coverage = null;
133:                 String defaultName = null;
134:                 String traceName = null;
135:                 String traceReductionPattern = null;
136:                 // String remoteName = null;
137:                 // Class<RemoteControl> remoteClass = null;
138:                 File traceFolder = null;
139:
140:                 Properties.init(); // Read properties file, if any
141:
142:                 Properties.parser_tabstop = 1;
143:
144:                 for (Iterator<String> i = largs.iterator(); i.hasNext();)
145:                 {
146:                         String arg = i.next();
147:
148:                         if (arg.equals("-vdmsl"))
149:                         {
150:                                 controller = new VDMSL();
151:                         } else if (arg.equals("-vdmpp"))
152:                         {
153:                                 controller = new VDMPP();
154:                         } else if (arg.equals("-vdmrt"))
155:                         {
156:                                 controller = new VDMRT();
157:                         } else if (arg.equals("-h"))
158:                         {
159:                                 if (i.hasNext())
160:                                 {
161:                                         host = i.next();
162:                                 } else
163:                                 {
164:                                         usage("-h option requires a hostname");
165:                                 }
166:                         } else if (arg.equals("-p"))
167:                         {
168:                                 try
169:                                 {
170:                                         port = Integer.parseInt(i.next());
171:                                 } catch (Exception e)
172:                                 {
173:                                         usage("-p option requires a port");
174:                                 }
175:                         } else if (arg.equals("-k"))
176:                         {
177:                                 if (i.hasNext())
178:                                 {
179:                                         ideKey = i.next();
180:                                 } else
181:                                 {
182:                                         usage("-k option requires a key");
183:                                 }
184:                         } else if (arg.equals("-e"))
185:                         {
186:                                 if (i.hasNext())
187:                                 {
188:                                         moduleName = i.next();
189:                                 } else
190:                                 {
191:                                         usage("-e option requires an expression");
192:                                 }
193:                         } else if (arg.equals("-e64"))
194:                         {
195:                                 if (i.hasNext())
196:                                 {
197:                                         moduleName = i.next();
198:                                         expBase64 = true;
199:                                 } else
200:                                 {
201:                                         usage("-e64 option requires an expression");
202:                                 }
203:                         } else if (arg.equals("-c"))
204:                         {
205:                                 if (i.hasNext())
206:                                 {
207:                                         if (controller == null)
208:                                         {
209:                                                 usage("-c must come after <-vdmpp|-vdmsl|-vdmrt>");
210:                                         }
211:
212:                                         controller.setCharset(validateCharset(i.next()));
213:                                 } else
214:                                 {
215:                                         usage("-c option requires a charset name");
216:                                 }
217:                         } else if (arg.equals("-r"))
218:                         {
219:                                 if (i.hasNext())
220:                                 {
221:                                         Settings.release = Release.lookup(i.next());
222:
223:                                         if (Settings.release == null)
224:                                         {
225:                                                 usage("-r option must be " + Release.list());
226:                                         }
227:                                 } else
228:                                 {
229:                                         usage("-r option requires a VDM release");
230:                                 }
231:                         } else if (arg.equals("-log"))
232:                         {
233:                                 if (i.hasNext())
234:                                 {
235:                                         try
236:                                         {
237:                                                 logfile = new URI(i.next()).getPath();
238:                                         } catch (URISyntaxException e)
239:                                         {
240:                                                 usage(e.getMessage() + ": " + arg);
241:                                         } catch (IllegalArgumentException e)
242:                                         {
243:                                                 usage(e.getMessage() + ": " + arg);
244:                                         }
245:                                 } else
246:                                 {
247:                                         usage("-log option requires a filename");
248:                                 }
249:                         } else if (arg.equals("-w"))
250:                         {
251:                                 warnings = false;
252:                         } else if (arg.equals("-q"))
253:                         {
254:                                 quiet = true;
255:                         } else if (arg.equals("-coverage"))
256:                         {
257:                                 if (i.hasNext())
258:                                 {
259:                                         try
260:                                         {
261:                                                 coverage = new File(new URI(i.next()));
262:
263:                                                 if (!coverage.isDirectory())
264:                                                 {
265:                                                         usage("Coverage location is not a directory");
266:                                                 }
267:                                         } catch (URISyntaxException e)
268:                                         {
269:                                                 usage(e.getMessage() + ": " + arg);
270:                                         } catch (IllegalArgumentException e)
271:                                         {
272:                                                 usage(e.getMessage() + ": " + arg);
273:                                         }
274:                                 } else
275:                                 {
276:                                         usage("-coverage option requires a directory name");
277:                                 }
278:                         } else if (arg.equals("-default64"))
279:                         {
280:                                 if (i.hasNext())
281:                                 {
282:                                         defaultName = i.next();
283:                                 } else
284:                                 {
285:                                         usage("-default64 option requires a name");
286:                                 }
287:                         }
288:                         // else if (arg.equals("-remote"))
289:                         // {
290:                         // if (i.hasNext())
291:                         // {
292:                         // remoteName = i.next();
293:                         // }
294:                         // else
295:                         // {
296:                         // usage("-remote option requires a Java classname");
297:                         // }
298:                         // }
299:                         else if (arg.equals("-t"))
300:                         {
301:                                 if (i.hasNext())
302:                                 {
303:                                         traceName = i.next();
304:                                 } else
305:                                 {
306:                                         usage("-t option requires a Trace Name");
307:                                 }
308:                         } else if (arg.equals("-t64"))
309:                         {
310:                                 if (i.hasNext())
311:                                 {
312:                                         traceName = i.next();
313:                                         traceNameBase64 = true;
314:                                 } else
315:                                 {
316:                                         usage("-t option requires a Trace Name");
317:                                 }
318:                         } else if (arg.equals("-tracefolder"))
319:                         {
320:                                 if (i.hasNext())
321:                                 {
322:                                         try
323:                                         {
324:                                                 traceFolder = new File(new URI(i.next()));
325:
326:                                                 if (!traceFolder.isDirectory())
327:                                                 {
328:                                                         usage("Tracefolder location is not a directory");
329:                                                 }
330:                                         } catch (URISyntaxException e)
331:                                         {
332:                                                 usage(e.getMessage() + ": " + arg);
333:                                         } catch (IllegalArgumentException e)
334:                                         {
335:                                                 usage(e.getMessage() + ": " + arg);
336:                                         }
337:                                 } else
338:                                 {
339:                                         usage("-tracefolder option requires a directory name");
340:                                 }
341:                         } else if (arg.equals("-traceReduction"))
342:                         {
343:                                 if (i.hasNext())
344:                                 {
345:                                         try
346:                                         {
347:                                                 traceReductionPattern = i.next();
348:                                         } catch (IllegalArgumentException e)
349:                                         {
350:                                                 usage(e.getMessage() + ": " + arg);
351:                                         }
352:                                 } else
353:                                 {
354:                                         usage("-traceReduction option requires a pattern");
355:                                 }
356:                         } else if (arg.equals("-consoleName"))
357:                         {
358:                                 if (i.hasNext())
359:                                 {
360:                                         LexTokenReader.consoleFileName = i.next();
361:                                 } else
362:                                 {
363:                                         usage("-consoleName option requires a console name");
364:                                 }
365:                         } else if (arg.startsWith("-"))
366:                         {
367:                                 usage("Unknown option " + arg);
368:                         } else
369:                         {
370:                                 try
371:                                 {
372:                                         File dir = new File(new URI(arg));
373:
374:                                         if (dir.isDirectory())
375:                                         {
376:                                                 for (File file : dir.listFiles(Settings.dialect.getFilter()))
377:                                                 {
378:                                                         if (file.isFile())
379:                                                         {
380:                                                                 files.add(file);
381:                                                         }
382:                                                 }
383:                                         } else
384:                                         {
385:                                                 files.add(dir);
386:                                         }
387:                                 } catch (URISyntaxException e)
388:                                 {
389:                                         usage(e.getMessage() + ": " + arg);
390:                                 } catch (IllegalArgumentException e)
391:                                 {
392:                                         usage(e.getMessage() + ": " + arg);
393:                                 }
394:                         }
395:                 }
396:
397:                 if (host == null || port == -1 || controller == null || ideKey == null
398:                                 || moduleName == null || Settings.dialect == null
399:                                 || traceFolder == null || files.isEmpty())
400:                 {
401:                         usage("Missing mandatory arguments");
402:                 }
403:
404:                 if (Settings.dialect != Dialect.VDM_RT && logfile != null)
405:                 {
406:                         usage("-log can only be used with -vdmrt");
407:                 }
408:
409:                 if (expBase64)
410:                 {
411:                         try
412:                         {
413:                                 byte[] bytes = Base64.decode(moduleName);
414:                                 moduleName = new String(bytes, VDMJ.filecharset);
415:                         } catch (Exception e)
416:                         {
417:                                 usage("Malformed -e64 base64 expression");
418:                         }
419:                 }
420:                 if (traceNameBase64)
421:                 {
422:                         try
423:                         {
424:                                 byte[] bytes = Base64.decode(traceName);
425:                                 traceName = new String(bytes, VDMJ.filecharset);
426:                         } catch (Exception e)
427:                         {
428:                                 usage("Malformed -t64 base64 trace name");
429:                         }
430:                 }
431:
432:                 if (defaultName != null)
433:                 {
434:                         try
435:                         {
436:                                 byte[] bytes = Base64.decode(defaultName);
437:                                 defaultName = new String(bytes, VDMJ.filecharset);
438:                         } catch (Exception e)
439:                         {
440:                                 usage("Malformed -default64 base64 name");
441:                         }
442:                 }
443:
444:                 // if (remoteName != null)
445:                 // {
446:                 // try
447:                 // {
448:                 // Class<?> cls = ClassLoader.getSystemClassLoader().loadClass(remoteName);
449:                 // remoteClass = (Class<RemoteControl>)cls;
450:                 // }
451:                 // catch (ClassNotFoundException e)
452:                 // {
453:                 // usage("Cannot locate " + remoteName + " on the CLASSPATH");
454:                 // }
455:                 // }
456:
457:                 controller.setWarnings(warnings);
458:                 controller.setQuiet(quiet);
459:                 Console.disableStdout();
460:
461:                 if (controller.parse(files) == ExitStatus.EXIT_OK)
462:                 {
463:                         if (controller.typeCheck() == ExitStatus.EXIT_OK)
464:                         {
465:                                 try
466:                                 {
467:                                         if (logfile != null)
468:                                         {
469:                                                 RTLogger.setLogfile(RTTextLogger.class, new File(logfile));
470:                                                 RTLogger.setLogfile(NextGenRTLogger.class, new File(logfile));
471:                                         }
472:
473:                                         Interpreter i = controller.getInterpreter();
474:
475:                                         if (defaultName != null)
476:                                         {
477:                                                 i.setDefaultName(defaultName);
478:                                         }
479:
480:                                         // RemoteControl r emote =
481:                                         // (remoteClass == null) ? null : remoteClass.newInstance();
482:
483:                                         // new ConnectionListener(port).start();
484:
485:                                         // String[] parts = traceReductionPattern.split("\\s+");
486:                                         // int testNo = 0;
487:                                         float subset = 1.0F;
488:                                         TraceReductionType reductionType = TraceReductionType.NONE;
489:                                         long seed = 999;
490:                                         // {subset,reduction,seed}
491:
492:                                         if (traceReductionPattern != null
493:                                                         && traceReductionPattern.startsWith("{"))
494:                                         {
495:                                                 try
496:                                                 {
497:                                                         String settings = traceReductionPattern;
498:                                                         String[] tmp = settings.substring(1, settings.length() - 1).split(",");
499:                                                         if (tmp.length == 3)
500:                                                         {
501:                                                                 subset = Float.parseFloat(tmp[0]);
502:                                                                 reductionType = TraceReductionType.valueOf(tmp[1]);
503:                                                                 seed = Long.parseLong(tmp[2]);
504:                                                         }
505:                                                 } catch (NumberFormatException e)
506:                                                 {
507:                                                         usage(traceReductionPattern
508:                                                                         + " <name> [test number]");
509:                                                         return;
510:                                                 }
511:                                         }
512:
513:                                         TraceRunnerMain runner = new TraceRunnerMain(host, port, ideKey, i, moduleName, traceName, traceFolder, subset, reductionType, seed);
514:                                         runner.startup();
515:
516:                                         if (coverage != null)
517:                                         {
518:                                                 writeCoverage(i, coverage);
519:                                         }
520:
521:                                         RTLogger.dump(true);
522:
523:                                         // runner.progressTerminating();
524:                                         exit(0);
525:                                 } catch (ContextException e)
526:                                 {
527:                                         System.err.println("Initialization: " + e);
528:                                         e.ctxt.printStackTrace(Console.out, true);
529:                                         RTLogger.dump(true);
530:                                         exit(3);
531:                                 } catch (ValueException e)
532:                                 {
533:                                         System.err.println("Initialization: " + e);
534:                                         e.ctxt.printStackTrace(Console.out, true);
535:                                         RTLogger.dump(true);
536:                                         exit(3);
537:                                 } catch (Exception e)
538:
539:                                 {
540:                                         System.err.println("Initialization: " + e);
541:                                         e.printStackTrace();
542:                                         RTLogger.dump(true);
543:                                         exit(3);
544:                                 }
545:                         } else
546:                         {
547:                                 final PrintWriter out = new PrintWriter(System.err);
548:                                 TypeChecker.printErrors(out);
549:                                 out.flush();
550:                                 exit(2);
551:                         }
552:                 } else
553:                 {
554:                         exit(1);
555:                 }
556:
557:         }
558:
559:         private static void exit(int code)
560:         {
561:                 if (USE_SYSTEM_EXIT)
562:                 {
563:                         System.exit(code);
564:                 }
565:         }
566:
567:         private void startup() throws Exception
568:         {
569:                 connect();
570:         }
571:
572:         protected static void usage(String string)
573:         {
574:                 System.err.println(string);
575:                 System.err.println("Usage: -h <host> -p <port> -k <ide key> <-vdmpp|-vdmsl|-vdmrt>"
576:                                 + " -e <expression> | -e64 <base64 expression>"
577:                                 + " [-w] [-q] [-log <logfile URL>] [-c <charset>] [-r <release>]"
578:                                 + " [-coverage <dir URL>] [-default64 <base64 name>]"
579:                                 + " [-remote <class>] [-consoleName <console>] {<filename URLs>}");
580:
581:                 System.exit(1);
582:         }
583:
584:         protected static String validateCharset(String cs)
585:         {
586:                 if (!Charset.isSupported(cs))
587:                 {
588:                         System.err.println("Charset " + cs + " is not supported\n");
589:                         System.err.println("Available charsets:");
590:                         System.err.println("Default = " + Charset.defaultCharset());
591:                         Map<String, Charset> available = Charset.availableCharsets();
592:
593:                         for (String name : available.keySet())
594:                         {
595:                                 System.err.println(name + " " + available.get(name).aliases());
596:                         }
597:
598:                         System.err.println("");
599:                         usage("Charset " + cs + " is not supported");
600:                 }
601:
602:                 return cs;
603:         }
604:
605:         protected static void writeCoverage(Interpreter interpreter, File coverage)
606:                         throws IOException
607:         {
608:                 for (File f : interpreter.getSourceFiles())
609:                 {
610:                         SourceFile source = interpreter.getSourceFile(f);
611:
612:                         File data = new File(coverage.getPath() + File.separator
613:                                         + f.getName() + ".covtbl");
614:                         PrintWriter pw = new PrintWriter(data);
615:                         source.writeCoverage(pw);
616:                         pw.close();
617:                 }
618:         }
619:
620:         protected void connect() throws Exception
621:         {
622:                 if (!connected)
623:                 {
624:                         if (port > 0)
625:                         {
626:                                 if (DEBUG)
627:                                 {
628:                                         System.out.println("Trying to connect to CT IDE");
629:                                 }
630:                                 
631:                                 try
632:                                 {
633:                                         InetAddress server = InetAddress.getByName(host);
634:                                         socket = new Socket(server, port);
635:                                         input = socket.getInputStream();
636:                                         output = socket.getOutputStream();
637:                                 } catch (Exception e)
638:                                 {
639:                                         e.printStackTrace();
640:                                 }
641:                         } else
642:                         {
643:                                 System.err.println("Something wrong no port");
644:                                 socket = null;
645:                                 input = System.in;
646:                                 output = System.out;
647:                                 separator = ' ';
648:                         }
649:
650:                         connected = true;
651:                         init();
652:                         run(); // New threads wait for a "run -i"
653:                 }
654:         }
655:
656:         private void run() throws Exception
657:         {
658:                 Thread t = new Thread(new Runnable()
659:                 {
660:
661:                         public void run()
662:                         {
663:                                 String tmp = "";
664:•                                while (input != null && !socket.isClosed())
665:                                 {
666:                                         int b;
667:                                         try
668:                                         {
669:                                                 b = input.read();
670:•                                                if (b == -1)
671:                                                 {
672:
673:                                                 } else
674:                                                 {
675:                                                         tmp += new String(new byte[] { (byte) b });
676:                                                 }
677:
678:•                                                if (tmp.equals("exit"))
679:                                                 {
680:                                                         completed = true;
681:                                                         return;
682:                                                 }
683:                                         } catch (IOException e)
684:                                         {
685:                                                 // TODO Auto-generated catch block
686:                                                 e.printStackTrace();
687:                                         }
688:
689:                                 }
690:                         }
691:                 });
692:                 t.setDaemon(true);
693:                 t.start();
694:                 t.setUncaughtExceptionHandler(new UncaughtExceptionHandler()
695:                 {
696:
697:                         @Override
698:                         public void uncaughtException(Thread t, Throwable e)
699:                         {
700:                                 e.printStackTrace();
701:
702:                         }
703:                 });
704:
705:                 TraceXmlWrapper storage = new TraceXmlWrapper(new File(traceFolder, moduleName
706:                                 + "-" + traceName + ".xml"));
707:
708:                 new TraceInterpreter(this, subset, reductionType, seed, new TypeCheckerAssistantFactory()).run(moduleName, traceName, interpreter, storage);
709:
710:                 while (!completed)
711:                 {
712:                         try
713:                         {
714:                                 Thread.sleep(500);
715:                         } catch (InterruptedException e)
716:                         {
717:                         }
718:                 }
719:
720:                 try
721:                 {
722:                         if (DEBUG)
723:                         {
724:                                 System.out.println("Closing socket");
725:                         }
726:                         socket.close();
727:                 } catch (IOException e)
728:                 {
729:
730:                 }
731:
732:         }
733:
734:         private void init() throws IOException
735:         {
736:                 if (DEBUG)
737:                 {
738:                         System.out.println("Connected");
739:                 }
740:                 
741:                 StringBuilder sb = new StringBuilder();
742:                 // interpreter.init(null);
743:                 sb.append("<init ");
744:                 sb.append("module=\"" + moduleName + "\" ");
745:                 sb.append("/>\n");
746:
747:                 write(sb);
748:                 
749:                 if (DEBUG)
750:                 {
751:                         System.out.println("Wrote init");
752:                 }
753:         }
754:
755:         private String currentTraceName = "";
756:
757:         /*
758:          * (non-Javadoc)
759:          * @see org.overture.traces.vdmj.IProgressMonitor#progress(java.lang.Integer)
760:          */
761:         public void progress(Integer procentage) throws IOException
762:         {
763:                 StringBuilder sb = new StringBuilder();
764:                 // interpreter.init(null);
765:                 sb.append("<response ");
766:                 sb.append("status=\"progress\" ");
767:                 sb.append("progress=\"" + procentage + "\" ");
768:                 sb.append("tracename=\"" + currentTraceName + "\" ");
769:                 sb.append("/>\n");
770:
771:                 write(sb);
772:         }
773:
774:         /*
775:          * (non-Javadoc)
776:          * @see org.overture.traces.vdmj.IProgressMonitor#progressStartTrace(java.lang.String)
777:          */
778:         public void progressStartTrace(String traceName) throws IOException
779:         {
780:                 this.currentTraceName = traceName;
781:                 StringBuilder sb = new StringBuilder();
782:                 // interpreter.init(null);
783:                 sb.append("<response ");
784:                 sb.append("status=\"tracestart\" ");
785:                 sb.append("tracename=\"" + traceName + "\" ");
786:                 sb.append("progress=\"" + 0 + "\" ");
787:                 sb.append("/>\n");
788:
789:                 write(sb);
790:         }
791:
792:         public void progressCompleted() throws IOException
793:         {
794:                 StringBuilder sb = new StringBuilder();
795:                 sb.append("<response ");
796:                 sb.append("status=\"completed\" ");
797:                 sb.append("progress=\"" + 100 + "\" ");
798:                 sb.append("/>\n");
799:
800:                 write(sb);
801:
802:         }
803:
804:         public void progressTerminating() throws IOException
805:         {
806:                 StringBuilder sb = new StringBuilder();
807:                 sb.append("<response ");
808:                 sb.append("status=\"terminating\" ");
809:                 sb.append("/>\n");
810:
811:                 write(sb);
812:
813:         }
814:
815:         public void progressError(String message) throws IOException
816:         {
817:
818:                 StringBuilder sb = new StringBuilder();
819:                 // interpreter.init(null);
820:                 sb.append("<response ");
821:                 sb.append("status=\"error\" ");
822:                 sb.append("message=\"" + message + "\" ");
823:                 // sb.append("progress=\"" + 100 + "\" ");
824:                 sb.append("/>\n");
825:
826:                 write(sb);
827:
828:         }
829:
830:         protected void write(StringBuilder data) throws IOException
831:         {
832:                 if (output == null)
833:                 {
834:                         // TODO: Handle the error in VDMJ, terminate?
835:                         System.err.println("Socket to IDE not valid.");
836:                         return;
837:                 }
838:                 byte[] header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>".getBytes("UTF-8");
839:                 byte[] body = data.toString().getBytes("UTF-8");
840:                 byte[] size = Integer.toString(header.length + body.length).getBytes("UTF-8");
841:
842:                 output.write(size);
843:                 output.write(separator);
844:                 output.write(header);
845:                 output.write(body);
846:                 output.write(separator);
847:
848:                 output.flush();
849:         }
850:
851: }