]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Minor SCL enhancements and fixes for logging and test executing 12/512/2
authorjsimomaa <jani.simomaa@gmail.com>
Fri, 12 May 2017 07:22:52 +0000 (10:22 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Fri, 12 May 2017 11:12:35 +0000 (14:12 +0300)
Also fixing Simantics/Misc getSystemProperty to return Maybe String

refs #7217

Change-Id: I238948da90f95b1b7e16d35112acb41eecb75d61

bundles/org.simantics.modeling/scl/Simantics/Misc.scl
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/commands/TestScriptExecutor.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/ValueFromMethod.java
bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/SCLOsgi.java
tests/org.simantics.scl.osgi.tests/src/org/simantics/scl/osgi/tests/TestSCLOsgi.java

index e3c7977155964bea6611bafe067df0d05f277211..c00c564e839fb8d662134c0821e78baaa0f51689 100644 (file)
@@ -140,7 +140,7 @@ loop4 testScan testList found = do
 
 importJava "java.lang.System" where
     @JavaName "getProperty"
-    getSystemProperty :: String -> String
+    getSystemProperty :: String -> Maybe String
     
 importJava "org.simantics.modeling.LifeCycleContext" where
     data LifeCycleContext
index ab39d538a23a4f808440855956ea15a5b8e02d40..4afeef91c69b83f884aaacaa4b3baeb2e965d862 100644 (file)
@@ -12,11 +12,17 @@ public class TestScriptExecutor {
     private final CommandSession session;
     private final BufferedReader reader;
     private final SCLReportingHandler handler;
+    private boolean ignorePrints;
     
     public TestScriptExecutor(CommandSession session, BufferedReader reader, SCLReportingHandler handler) {
+        this(session, reader, handler, false);
+    }
+    
+    public TestScriptExecutor(CommandSession session, BufferedReader reader, SCLReportingHandler handler, boolean ignorePrints) {
         this.session = session;
         this.reader = reader;
         this.handler = handler == null ? SCLReportingHandler.DEFAULT : handler;
+        this.ignorePrints = ignorePrints;
     }
 
     public void execute() throws IOException {
@@ -67,7 +73,8 @@ public class TestScriptExecutor {
                     @Override
                     public void print(String text) {
                         handler.print(text);
-                        actualResponse.append(text).append('\n');
+                        if (!ignorePrints)
+                            actualResponse.append(text).append('\n');
                     }
                     
                     @Override
index fa5059626a12b1b881a2f6d913b74d4ef3bad3bc..45596c5704e5aad359f197e445781cca148509b7 100644 (file)
@@ -2,6 +2,7 @@ package org.simantics.scl.compiler.elaboration.java;
 
 import org.cojen.classfile.TypeDesc;
 import org.osgi.service.component.annotations.Component;
+import org.simantics.scl.compiler.commands.CommandSession;
 import org.simantics.scl.compiler.common.names.Name;
 import org.simantics.scl.compiler.constants.JavaMethod;
 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
@@ -48,8 +49,13 @@ public class LoggingModule extends ConcreteModule {
                 @Override
                 public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) {
                     ConcreteModule module = context.getCompilationContext().module;
+                    String identifier;
+                    if (module != null)
+                        identifier = module.getName().replaceAll("/", ".");
+                    else
+                        identifier = CommandSession.class.getName();
                     apply.set(new ELiteral(javaMethod), new Expression[] {
-                            new EExternalConstant(LoggerFactory.getLogger(module.getName().replaceAll("/", ".")), Logger),
+                            new EExternalConstant(LoggerFactory.getLogger(identifier), Logger),
                             apply.parameters[0]
                     });
                     return apply;
index 4efd2a8d404e7037925fd7d005d782e1fa5c8d3f..70160dee2615b4e284e637134b1efcf7e03e84a5 100644 (file)
@@ -1,5 +1,6 @@
 package org.simantics.scl.compiler.internal.codegen.utils;
 
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 import org.simantics.scl.runtime.function.FunctionImpl1;
@@ -26,6 +27,8 @@ public class ValueFromMethod {
                 Object ret = method.invoke(null, p0);
                 return returnsVoid ? Tuple0.INSTANCE : ret;
             } catch (ReflectiveOperationException e) {
+                if (e instanceof InvocationTargetException)
+                    throw new RuntimeException(e.getCause());
                 throw new RuntimeException(e);
             }
         }
index 9deb81124e2e37b27a1bc79c65f8396c1e9460b2..59f8e5fd804616a59ac705a31563160404206f92 100644 (file)
@@ -1,5 +1,10 @@
 package org.simantics.scl.osgi;
 
+import java.util.ArrayList;
+
+import org.simantics.scl.compiler.errors.DoesNotExist;
+import org.simantics.scl.compiler.errors.Failable;
+import org.simantics.scl.compiler.module.Module;
 import org.simantics.scl.compiler.module.repository.ModuleRepository;
 import org.simantics.scl.compiler.source.repository.ModuleSourceRepository;
 import org.simantics.scl.compiler.testing.repository.TestRepository;
@@ -7,6 +12,8 @@ import org.simantics.scl.osgi.internal.Activator;
 import org.simantics.scl.osgi.internal.ServiceBasedModuleSourceRepository;
 import org.simantics.scl.osgi.internal.ServiceBasedTestRepository;
 
+import gnu.trove.procedure.TObjectProcedure;
+
 
 public class SCLOsgi {
 
@@ -16,4 +23,33 @@ public class SCLOsgi {
     public static ModuleRepository MODULE_REPOSITORY = new ModuleRepository(SOURCE_REPOSITORY);
     public static TestRepository TEST_REPOSITORY = new ServiceBasedTestRepository(Activator.getContext());
 
+    
+    public static String compileAllModules() {
+        ArrayList<String> modulesWithErrors = new ArrayList<String>(); 
+        SCLOsgi.SOURCE_REPOSITORY.forAllModules(new TObjectProcedure<String>() {
+            @Override
+            public boolean execute(String moduleName) {
+                System.out.print(moduleName);
+                System.out.print(" - ");
+                Failable<Module> module = SCLOsgi.MODULE_REPOSITORY.getModule(moduleName);
+                if(module.didSucceed())
+                    System.out.println("succeeded");
+                else if(module == DoesNotExist.INSTANCE)
+                    System.out.println("does not exist"); // should not happen
+                else {
+                    System.out.println("error");
+                    modulesWithErrors.add(moduleName);
+                }
+                return true;
+            }
+        });
+        if(!modulesWithErrors.isEmpty()) {
+            StringBuilder b = new StringBuilder();
+            b.append("Some SCL modules failed to compile:");
+            for(String module : modulesWithErrors)
+                b.append(' ').append(module);
+            return b.toString();
+        }
+        return null;
+    }
 }
index 4554294272ae1b0b07f356477cb44a5d92e06183..8daf95832ecb354e4c1bb0862fed0cfd31d83982 100644 (file)
@@ -1,8 +1,5 @@
 package org.simantics.scl.osgi.tests;
 
-import java.util.ArrayList;
-import java.util.concurrent.atomic.AtomicInteger;
-
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.junit.AfterClass;
@@ -15,14 +12,8 @@ import org.simantics.application.arguments.Arguments;
 import org.simantics.application.arguments.IArgumentFactory;
 import org.simantics.application.arguments.IArguments;
 import org.simantics.application.arguments.SimanticsArguments;
-import org.simantics.scl.compiler.errors.DoesNotExist;
-import org.simantics.scl.compiler.errors.Failable;
-import org.simantics.scl.compiler.module.Module;
 import org.simantics.scl.osgi.SCLOsgi;
 
-import gnu.trove.procedure.TObjectProcedure;
-
-
 public class TestSCLOsgi {
     private static IProgressMonitor progress = new NullProgressMonitor();
     
@@ -47,30 +38,9 @@ public class TestSCLOsgi {
     
     @Test
     public void testDataJsonExists() {
-        ArrayList<String> modulesWithErrors = new ArrayList<String>(); 
-        SCLOsgi.SOURCE_REPOSITORY.forAllModules(new TObjectProcedure<String>() {
-            @Override
-            public boolean execute(String moduleName) {
-                System.out.print(moduleName);
-                System.out.print(" - ");
-                Failable<Module> module = SCLOsgi.MODULE_REPOSITORY.getModule(moduleName);
-                if(module.didSucceed())
-                    System.out.println("succeeded");
-                else if(module == DoesNotExist.INSTANCE)
-                    System.out.println("does not exist"); // should not happen
-                else {
-                    System.out.println("error");
-                    modulesWithErrors.add(moduleName);
-                }
-                return true;
-            }
-        });
-        if(!modulesWithErrors.isEmpty()) {
-            StringBuilder b = new StringBuilder();
-            b.append("Some SCL modules failed to compile:");
-            for(String module : modulesWithErrors)
-                b.append(' ').append(module);
-            Assert.fail(b.toString());
+        String possibleError = SCLOsgi.compileAllModules();
+        if(possibleError != null) {
+            Assert.fail(possibleError);
         }
     }
 }