]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/BundleTestScriptRunnable.java
migrated to svn revision 33108
[simantics/platform.git] / bundles / org.simantics.scl.osgi / src / org / simantics / scl / osgi / internal / BundleTestScriptRunnable.java
1 package org.simantics.scl.osgi.internal;
2
3 import java.io.BufferedReader;
4 import java.io.InputStream;
5 import java.io.InputStreamReader;
6 import java.net.URL;
7
8 import org.simantics.scl.compiler.commands.CommandSession;
9 import org.simantics.scl.compiler.commands.TestScriptExecutor;
10 import org.simantics.scl.compiler.testing.TestRunnable;
11 import org.simantics.scl.osgi.SCLOsgi;
12 import org.simantics.scl.runtime.SCLContext;
13 import org.simantics.scl.runtime.reporting.SCLReportingHandler;
14
15 public class BundleTestScriptRunnable implements TestRunnable {
16
17     private final String name;
18     private final URL url;
19     
20     public BundleTestScriptRunnable(String name, URL url) {
21         this.name = name;
22         this.url = url;
23     }
24
25     @Override
26     public String getName() {
27         return name;
28     }
29
30     @Override
31     public void run() throws Exception {
32         InputStream stream = url.openStream();
33         BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
34         
35         SCLContext context = SCLContext.getCurrent();
36         SCLReportingHandler printer = (SCLReportingHandler)context.get(SCLReportingHandler.REPORTING_HANDLER);
37         SCLReportingHandler handler;
38         if(printer instanceof SCLReportingHandler)
39             handler = (SCLReportingHandler)printer;
40         else
41             handler = SCLReportingHandler.DEFAULT;
42         
43         try {
44             CommandSession session = new CommandSession(SCLOsgi.MODULE_REPOSITORY, handler);
45             new TestScriptExecutor(session, reader, handler).execute();
46         } finally {
47             reader.close();
48         }
49     }
50
51     @Override
52     public String toString() {
53         return getName() + " (" + url + ")";
54     }
55 }