From: jsimomaa Date: Fri, 12 May 2017 07:22:52 +0000 (+0300) Subject: Minor SCL enhancements and fixes for logging and test executing X-Git-Tag: v1.29.0~56^2~1 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F12%2F512%2F2;p=simantics%2Fplatform.git Minor SCL enhancements and fixes for logging and test executing Also fixing Simantics/Misc getSystemProperty to return Maybe String refs #7217 Change-Id: I238948da90f95b1b7e16d35112acb41eecb75d61 --- diff --git a/bundles/org.simantics.modeling/scl/Simantics/Misc.scl b/bundles/org.simantics.modeling/scl/Simantics/Misc.scl index e3c797715..c00c564e8 100644 --- a/bundles/org.simantics.modeling/scl/Simantics/Misc.scl +++ b/bundles/org.simantics.modeling/scl/Simantics/Misc.scl @@ -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 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/commands/TestScriptExecutor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/commands/TestScriptExecutor.java index ab39d538a..4afeef91c 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/commands/TestScriptExecutor.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/commands/TestScriptExecutor.java @@ -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 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java index fa5059626..45596c570 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java @@ -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; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/ValueFromMethod.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/ValueFromMethod.java index 4efd2a8d4..70160dee2 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/ValueFromMethod.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/ValueFromMethod.java @@ -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); } } diff --git a/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/SCLOsgi.java b/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/SCLOsgi.java index 9deb81124..59f8e5fd8 100644 --- a/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/SCLOsgi.java +++ b/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/SCLOsgi.java @@ -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 modulesWithErrors = new ArrayList(); + SCLOsgi.SOURCE_REPOSITORY.forAllModules(new TObjectProcedure() { + @Override + public boolean execute(String moduleName) { + System.out.print(moduleName); + System.out.print(" - "); + Failable 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; + } } diff --git a/tests/org.simantics.scl.osgi.tests/src/org/simantics/scl/osgi/tests/TestSCLOsgi.java b/tests/org.simantics.scl.osgi.tests/src/org/simantics/scl/osgi/tests/TestSCLOsgi.java index 455429427..8daf95832 100644 --- a/tests/org.simantics.scl.osgi.tests/src/org/simantics/scl/osgi/tests/TestSCLOsgi.java +++ b/tests/org.simantics.scl.osgi.tests/src/org/simantics/scl/osgi/tests/TestSCLOsgi.java @@ -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 modulesWithErrors = new ArrayList(); - SCLOsgi.SOURCE_REPOSITORY.forAllModules(new TObjectProcedure() { - @Override - public boolean execute(String moduleName) { - System.out.print(moduleName); - System.out.print(" - "); - Failable 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); } } }