From: Tuukka Lehtonen Date: Fri, 30 Sep 2016 13:28:29 +0000 (+0300) Subject: Sync git svn branch with SVN repository r33290. X-Git-Tag: v1.25.0~76^2~1 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=3b5069d;p=simantics%2Fplatform.git Sync git svn branch with SVN repository r33290. refs #6726 --- diff --git a/bundles/org.simantics.tests.modelled.ontology/.classpath b/bundles/org.simantics.tests.modelled.ontology/.classpath new file mode 100644 index 000000000..b862a296d --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ontology/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/org.simantics.tests.modelled.ontology/.project b/bundles/org.simantics.tests.modelled.ontology/.project new file mode 100644 index 000000000..a3e0b7a51 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ontology/.project @@ -0,0 +1,34 @@ + + + org.simantics.tests.modelled.ontology + + + + + + org.simantics.graph.builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.simantics.graph.nature + + diff --git a/bundles/org.simantics.tests.modelled.ontology/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.tests.modelled.ontology/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..295926d96 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ontology/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/org.simantics.tests.modelled.ontology/META-INF/MANIFEST.MF b/bundles/org.simantics.tests.modelled.ontology/META-INF/MANIFEST.MF new file mode 100644 index 000000000..2320422c5 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ontology/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: http://www.simantics.org/Tests +Bundle-SymbolicName: org.simantics.tests.modelled.ontology +Bundle-Version: 1.0.0.qualifier +Require-Bundle: org.simantics.layer0 +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: org.simantics.tests.modelled.ontology diff --git a/bundles/org.simantics.tests.modelled.ontology/build.properties b/bundles/org.simantics.tests.modelled.ontology/build.properties new file mode 100644 index 000000000..022de1735 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ontology/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + graph.tg diff --git a/bundles/org.simantics.tests.modelled.ontology/graph.tg b/bundles/org.simantics.tests.modelled.ontology/graph.tg new file mode 100644 index 000000000..6ffc03aa5 Binary files /dev/null and b/bundles/org.simantics.tests.modelled.ontology/graph.tg differ diff --git a/bundles/org.simantics.tests.modelled.ontology/graph/Tests.pgraph b/bundles/org.simantics.tests.modelled.ontology/graph/Tests.pgraph new file mode 100644 index 000000000..11b93d2d4 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ontology/graph/Tests.pgraph @@ -0,0 +1,20 @@ +L0 = + + +TESTS = : L0.Ontology + @L0.new + L0.HasResourceClass "org.simantics.tests.modelled.ontology.TestsResource" + +TESTS.SCLMain : L0.SCLModule + L0.SCLModule.definition _ : L0.String + @L0.loadString "scl/SCLMain.scl" + +TESTS.STSTest -- TESTS.STSTest.definition --> L0.String -- TESTS.STSTest.executionPriority --> L0.Integer -- TESTS.STSSuite.moduleNameFilter --> L0.String () { + public TestsResource perform(ReadGraph graph) throws DatabaseException { + QueryControl qc = graph.getService(QueryControl.class); + return new TestsResource(qc.getIndependentGraph(graph)); + } + }); + session.registerService(TestsResource.class, ret); + } + return ret; + } + +} + diff --git a/bundles/org.simantics.tests.modelled.ui.ontology/.classpath b/bundles/org.simantics.tests.modelled.ui.ontology/.classpath new file mode 100644 index 000000000..b862a296d --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui.ontology/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/org.simantics.tests.modelled.ui.ontology/.project b/bundles/org.simantics.tests.modelled.ui.ontology/.project new file mode 100644 index 000000000..fa169e57d --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui.ontology/.project @@ -0,0 +1,34 @@ + + + org.simantics.tests.modelled.ui.ontology + + + + + + org.simantics.graph.builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.simantics.graph.nature + + diff --git a/bundles/org.simantics.tests.modelled.ui.ontology/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.tests.modelled.ui.ontology/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..295926d96 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui.ontology/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/org.simantics.tests.modelled.ui.ontology/META-INF/MANIFEST.MF b/bundles/org.simantics.tests.modelled.ui.ontology/META-INF/MANIFEST.MF new file mode 100644 index 000000000..4ad1a0df9 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui.ontology/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: http://www.simantics.org/TestsUI +Bundle-SymbolicName: org.simantics.tests.modelled.ui.ontology +Bundle-Version: 1.0.0.qualifier +Require-Bundle: org.simantics.layer0, + org.simantics.tests.modelled.ontology;bundle-version="1.0.0", + org.simantics.viewpoint.ontology;bundle-version="1.2.0", + org.simantics.project.ontology;bundle-version="1.2.0", + org.simantics.modeling.ontology;bundle-version="1.2.0", + org.simantics.silk.ontology;bundle-version="1.1.0", + org.simantics.image2.ontology;bundle-version="1.2.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/bundles/org.simantics.tests.modelled.ui.ontology/build.properties b/bundles/org.simantics.tests.modelled.ui.ontology/build.properties new file mode 100644 index 000000000..815829b35 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui.ontology/build.properties @@ -0,0 +1,8 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + graph.tg,\ + graph/scl/ +src.includes = graph/scl/ diff --git a/bundles/org.simantics.tests.modelled.ui.ontology/graph.tg b/bundles/org.simantics.tests.modelled.ui.ontology/graph.tg new file mode 100644 index 000000000..c8b53e56c Binary files /dev/null and b/bundles/org.simantics.tests.modelled.ui.ontology/graph.tg differ diff --git a/bundles/org.simantics.tests.modelled.ui.ontology/graph/TestsUI.pgraph b/bundles/org.simantics.tests.modelled.ui.ontology/graph/TestsUI.pgraph new file mode 100644 index 000000000..6f7d89c2d --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui.ontology/graph/TestsUI.pgraph @@ -0,0 +1,74 @@ +L0 = +TESTS = +VP = +PROJECT = +MOD = +SILK = +IMAGE = + +TestsUI = : L0.Ontology + @L0.new + L0.HasResourceClass "org.simantics.tests.modelled.ui.ontology.TestsUIResource" + +TestsUI.SCLMain : L0.SCLModule + L0.SCLModule.definition _ : L0.String + @L0.loadString "scl/SCLMain.scl" + +TestsUI.testImage : IMAGE.PngImage + @L0.loadBytes "images/test.png" + +TestsUI.testSuiteImage : IMAGE.PngImage + @L0.loadBytes "images/tsuite.png" + +// Library containing all testing viewpoint contributions +TestsUI.Contributions : L0.Library + + +MBC = TestsUI.BrowseContext : VP.BrowseContext + VP.BrowseContext.IsIncludedIn PROJECT.ProjectBrowseContext + +MBC + @VP.namedRelationChildRule TestsUI.Contributions.STSSuites L0.Entity L0.ConsistsOf TESTS.STSSuite + @VP.namedConstantImageRule TestsUI.Contributions.ModuleImage TESTS.STSSuite TestsUI.testSuiteImage + @VP.namedRelationChildRule TestsUI.Contributions.STSTests L0.Entity L0.ConsistsOf TESTS.STSTest + @VP.namedConstantImageRule TestsUI.Contributions.ModuleImage TESTS.STSTest TestsUI.testImage + +MAC = TestsUI.ModelingActionContext : VP.BrowseContext + VP.BrowseContext.IsIncludedIn PROJECT.ProjectActionContext + +ACTIONS = MAC.Actions : L0.Library + +ACTIONS.NewSTSSuite + @MOD.sclAction "createSTSSuiteAction" +ACTIONS.NewSTSTest + @MOD.sclAction "createSTSTestAction" +ACTIONS.RunSTSTest + @MOD.sclAction "runSTSTestAction" + +MAC + VP.BrowseContext.HasActionContribution TestsUI.Contributions.NewSTSSuite : VP.ActionContribution + L0.HasLabel "STS Suite" + VP.ActionContribution.HasImage TestsUI.testSuiteImage + VP.ActionContribution.HasCategory VP.NewActionCategory + VP.ActionContribution.HasNodeType + L0.Library + VP.ActionContribution.HasAction ACTIONS.NewSTSSuite + VP.BrowseContext.HasActionContribution TestsUI.Contributions.NewSTSTest : VP.ActionContribution + L0.HasLabel "STS Test" + VP.ActionContribution.HasImage TestsUI.testImage + VP.ActionContribution.HasCategory VP.NewActionCategory + VP.ActionContribution.HasNodeType + TESTS.STSSuite + VP.ActionContribution.HasAction ACTIONS.NewSTSTest + VP.BrowseContext.HasActionContribution _ : VP.ActionContribution + L0.HasLabel "Run" + VP.ActionContribution.HasImage SILK.control_play + VP.ActionContribution.HasCategory VP.EditActionCategory + VP.ActionContribution.HasNodeType TESTS.STSSuite + VP.ActionContribution.HasAction ACTIONS.RunSTSTest + VP.BrowseContext.HasActionContribution _ : VP.ActionContribution + L0.HasLabel "Run" + VP.ActionContribution.HasImage SILK.control_play + VP.ActionContribution.HasCategory VP.EditActionCategory + VP.ActionContribution.HasNodeType TESTS.STSTest + VP.ActionContribution.HasAction ACTIONS.RunSTSTest \ No newline at end of file diff --git a/bundles/org.simantics.tests.modelled.ui.ontology/graph/images/test.png b/bundles/org.simantics.tests.modelled.ui.ontology/graph/images/test.png new file mode 100644 index 000000000..b74a9fcaf Binary files /dev/null and b/bundles/org.simantics.tests.modelled.ui.ontology/graph/images/test.png differ diff --git a/bundles/org.simantics.tests.modelled.ui.ontology/graph/images/tsuite.png b/bundles/org.simantics.tests.modelled.ui.ontology/graph/images/tsuite.png new file mode 100644 index 000000000..b7efb0aa5 Binary files /dev/null and b/bundles/org.simantics.tests.modelled.ui.ontology/graph/images/tsuite.png differ diff --git a/bundles/org.simantics.tests.modelled.ui.ontology/graph/scl/SCLMain.scl b/bundles/org.simantics.tests.modelled.ui.ontology/graph/scl/SCLMain.scl new file mode 100644 index 000000000..1e41eb2e1 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui.ontology/graph/scl/SCLMain.scl @@ -0,0 +1 @@ +include "Simantics/TestsUI" \ No newline at end of file diff --git a/bundles/org.simantics.tests.modelled.ui.ontology/src/org/simantics/tests/modelled/ui/ontology/TestsUIResource.java b/bundles/org.simantics.tests.modelled.ui.ontology/src/org/simantics/tests/modelled/ui/ontology/TestsUIResource.java new file mode 100644 index 000000000..4aa14a70a --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui.ontology/src/org/simantics/tests/modelled/ui/ontology/TestsUIResource.java @@ -0,0 +1,100 @@ +package org.simantics.tests.modelled.ui.ontology; + +import org.simantics.db.RequestProcessor; +import org.simantics.db.Resource; +import org.simantics.db.ReadGraph; +import org.simantics.db.request.Read; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.QueryControl; + +public class TestsUIResource { + + public final Resource BrowseContext; + public final Resource Contributions; + public final Resource Contributions_ModuleImage; + public final Resource Contributions_NewSTSSuite; + public final Resource Contributions_NewSTSTest; + public final Resource Contributions_STSSuites; + public final Resource Contributions_STSTests; + public final Resource ModelingActionContext; + public final Resource ModelingActionContext_Actions; + public final Resource ModelingActionContext_Actions_NewSTSSuite; + public final Resource ModelingActionContext_Actions_NewSTSTest; + public final Resource ModelingActionContext_Actions_RunSTSTest; + public final Resource SCLMain; + public final Resource testImage; + public final Resource testSuiteImage; + + public static class URIs { + public static final String BrowseContext = "http://www.simantics.org/TestsUI-1.0/BrowseContext"; + public static final String Contributions = "http://www.simantics.org/TestsUI-1.0/Contributions"; + public static final String Contributions_ModuleImage = "http://www.simantics.org/TestsUI-1.0/Contributions/ModuleImage"; + public static final String Contributions_NewSTSSuite = "http://www.simantics.org/TestsUI-1.0/Contributions/NewSTSSuite"; + public static final String Contributions_NewSTSTest = "http://www.simantics.org/TestsUI-1.0/Contributions/NewSTSTest"; + public static final String Contributions_STSSuites = "http://www.simantics.org/TestsUI-1.0/Contributions/STSSuites"; + public static final String Contributions_STSTests = "http://www.simantics.org/TestsUI-1.0/Contributions/STSTests"; + public static final String ModelingActionContext = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext"; + public static final String ModelingActionContext_Actions = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext/Actions"; + public static final String ModelingActionContext_Actions_NewSTSSuite = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext/Actions/NewSTSSuite"; + public static final String ModelingActionContext_Actions_NewSTSTest = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext/Actions/NewSTSTest"; + public static final String ModelingActionContext_Actions_RunSTSTest = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext/Actions/RunSTSTest"; + public static final String SCLMain = "http://www.simantics.org/TestsUI-1.0/SCLMain"; + public static final String testImage = "http://www.simantics.org/TestsUI-1.0/testImage"; + public static final String testSuiteImage = "http://www.simantics.org/TestsUI-1.0/testSuiteImage"; + } + + public static Resource getResourceOrNull(ReadGraph graph, String uri) { + try { + return graph.getResource(uri); + } catch(DatabaseException e) { + System.err.println(e.getMessage()); + return null; + } + } + + public TestsUIResource(ReadGraph graph) { + BrowseContext = getResourceOrNull(graph, URIs.BrowseContext); + Contributions = getResourceOrNull(graph, URIs.Contributions); + Contributions_ModuleImage = getResourceOrNull(graph, URIs.Contributions_ModuleImage); + Contributions_NewSTSSuite = getResourceOrNull(graph, URIs.Contributions_NewSTSSuite); + Contributions_NewSTSTest = getResourceOrNull(graph, URIs.Contributions_NewSTSTest); + Contributions_STSSuites = getResourceOrNull(graph, URIs.Contributions_STSSuites); + Contributions_STSTests = getResourceOrNull(graph, URIs.Contributions_STSTests); + ModelingActionContext = getResourceOrNull(graph, URIs.ModelingActionContext); + ModelingActionContext_Actions = getResourceOrNull(graph, URIs.ModelingActionContext_Actions); + ModelingActionContext_Actions_NewSTSSuite = getResourceOrNull(graph, URIs.ModelingActionContext_Actions_NewSTSSuite); + ModelingActionContext_Actions_NewSTSTest = getResourceOrNull(graph, URIs.ModelingActionContext_Actions_NewSTSTest); + ModelingActionContext_Actions_RunSTSTest = getResourceOrNull(graph, URIs.ModelingActionContext_Actions_RunSTSTest); + SCLMain = getResourceOrNull(graph, URIs.SCLMain); + testImage = getResourceOrNull(graph, URIs.testImage); + testSuiteImage = getResourceOrNull(graph, URIs.testSuiteImage); + } + + public static TestsUIResource getInstance(ReadGraph graph) { + Session session = graph.getSession(); + TestsUIResource ret = session.peekService(TestsUIResource.class); + if(ret == null) { + QueryControl qc = graph.getService(QueryControl.class); + ret = new TestsUIResource(qc.getIndependentGraph(graph)); + session.registerService(TestsUIResource.class, ret); + } + return ret; + } + + public static TestsUIResource getInstance(RequestProcessor session) throws DatabaseException { + TestsUIResource ret = session.peekService(TestsUIResource.class); + if(ret == null) { + ret = session.syncRequest(new Read() { + public TestsUIResource perform(ReadGraph graph) throws DatabaseException { + QueryControl qc = graph.getService(QueryControl.class); + return new TestsUIResource(qc.getIndependentGraph(graph)); + } + }); + session.registerService(TestsUIResource.class, ret); + } + return ret; + } + +} + diff --git a/bundles/org.simantics.tests.modelled.ui/.classpath b/bundles/org.simantics.tests.modelled.ui/.classpath new file mode 100644 index 000000000..b862a296d --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/org.simantics.tests.modelled.ui/.project b/bundles/org.simantics.tests.modelled.ui/.project new file mode 100644 index 000000000..d0d29d70e --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/.project @@ -0,0 +1,28 @@ + + + org.simantics.tests.modelled.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/org.simantics.tests.modelled.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.tests.modelled.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..295926d96 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/org.simantics.tests.modelled.ui/META-INF/MANIFEST.MF b/bundles/org.simantics.tests.modelled.ui/META-INF/MANIFEST.MF new file mode 100644 index 000000000..e9aba00c1 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Simantics Modelled Tests UI +Bundle-SymbolicName: org.simantics.tests.modelled.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.simantics.tests.modelled.ui.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.ui.editors;bundle-version="3.9.0", + org.eclipse.jface.text;bundle-version="3.10.0", + org.eclipse.core.runtime, + org.simantics.modeling.ui, + org.simantics.scl.ui, + org.simantics.tests.modelled.ontology, + org.eclipse.e4.ui.di, + org.simantics.tests.modelled.ui.ontology;bundle-version="1.0.0", + org.simantics.tests.modelled;bundle-version="1.0.0", + org.eclipse.e4.ui.model.workbench, + org.simantics.scl.osgi +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ActivationPolicy: lazy diff --git a/bundles/org.simantics.tests.modelled.ui/build.properties b/bundles/org.simantics.tests.modelled.ui/build.properties new file mode 100644 index 000000000..c54907f35 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + scl/ +src.includes = scl/ diff --git a/bundles/org.simantics.tests.modelled.ui/icons/greenbar.gif b/bundles/org.simantics.tests.modelled.ui/icons/greenbar.gif new file mode 100644 index 000000000..0ba656725 Binary files /dev/null and b/bundles/org.simantics.tests.modelled.ui/icons/greenbar.gif differ diff --git a/bundles/org.simantics.tests.modelled.ui/icons/redbar.gif b/bundles/org.simantics.tests.modelled.ui/icons/redbar.gif new file mode 100644 index 000000000..c2f71469b Binary files /dev/null and b/bundles/org.simantics.tests.modelled.ui/icons/redbar.gif differ diff --git a/bundles/org.simantics.tests.modelled.ui/icons/test.png b/bundles/org.simantics.tests.modelled.ui/icons/test.png new file mode 100644 index 000000000..b74a9fcaf Binary files /dev/null and b/bundles/org.simantics.tests.modelled.ui/icons/test.png differ diff --git a/bundles/org.simantics.tests.modelled.ui/icons/testerr.png b/bundles/org.simantics.tests.modelled.ui/icons/testerr.png new file mode 100644 index 000000000..e46c8754e Binary files /dev/null and b/bundles/org.simantics.tests.modelled.ui/icons/testerr.png differ diff --git a/bundles/org.simantics.tests.modelled.ui/icons/testfail.png b/bundles/org.simantics.tests.modelled.ui/icons/testfail.png new file mode 100644 index 000000000..057698b79 Binary files /dev/null and b/bundles/org.simantics.tests.modelled.ui/icons/testfail.png differ diff --git a/bundles/org.simantics.tests.modelled.ui/icons/testok.png b/bundles/org.simantics.tests.modelled.ui/icons/testok.png new file mode 100644 index 000000000..597733559 Binary files /dev/null and b/bundles/org.simantics.tests.modelled.ui/icons/testok.png differ diff --git a/bundles/org.simantics.tests.modelled.ui/icons/testrun.png b/bundles/org.simantics.tests.modelled.ui/icons/testrun.png new file mode 100644 index 000000000..8d8d6f5d2 Binary files /dev/null and b/bundles/org.simantics.tests.modelled.ui/icons/testrun.png differ diff --git a/bundles/org.simantics.tests.modelled.ui/icons/tsuite.png b/bundles/org.simantics.tests.modelled.ui/icons/tsuite.png new file mode 100644 index 000000000..b7efb0aa5 Binary files /dev/null and b/bundles/org.simantics.tests.modelled.ui/icons/tsuite.png differ diff --git a/bundles/org.simantics.tests.modelled.ui/icons/tsuiteerror.png b/bundles/org.simantics.tests.modelled.ui/icons/tsuiteerror.png new file mode 100644 index 000000000..14cb1af77 Binary files /dev/null and b/bundles/org.simantics.tests.modelled.ui/icons/tsuiteerror.png differ diff --git a/bundles/org.simantics.tests.modelled.ui/icons/tsuitefail.png b/bundles/org.simantics.tests.modelled.ui/icons/tsuitefail.png new file mode 100644 index 000000000..0dd6ee3b1 Binary files /dev/null and b/bundles/org.simantics.tests.modelled.ui/icons/tsuitefail.png differ diff --git a/bundles/org.simantics.tests.modelled.ui/icons/tsuiteok.png b/bundles/org.simantics.tests.modelled.ui/icons/tsuiteok.png new file mode 100644 index 000000000..f7a602077 Binary files /dev/null and b/bundles/org.simantics.tests.modelled.ui/icons/tsuiteok.png differ diff --git a/bundles/org.simantics.tests.modelled.ui/icons/tsuiterun.png b/bundles/org.simantics.tests.modelled.ui/icons/tsuiterun.png new file mode 100644 index 000000000..e8ddc3097 Binary files /dev/null and b/bundles/org.simantics.tests.modelled.ui/icons/tsuiterun.png differ diff --git a/bundles/org.simantics.tests.modelled.ui/plugin.xml b/bundles/org.simantics.tests.modelled.ui/plugin.xml new file mode 100644 index 000000000..fc04f9ef7 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/plugin.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/org.simantics.tests.modelled.ui/scl/Simantics/TestsUI.scl b/bundles/org.simantics.tests.modelled.ui/scl/Simantics/TestsUI.scl new file mode 100644 index 000000000..428c18f33 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/scl/Simantics/TestsUI.scl @@ -0,0 +1,14 @@ +include "Simantics/Tests" + +createSTSTestAction :: Resource -> () +createSTSTestAction res = do + syncWrite (\() -> createSTSTest res) + () + +importJava "org.simantics.tests.ui.TestsUIUtils" where + runSTSTestAction :: Resource -> () + +createSTSSuiteAction :: Resource -> () +createSTSSuiteAction res = do + syncWrite (\() -> createSTSSuite res) + () \ No newline at end of file diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/Activator.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/Activator.java new file mode 100644 index 000000000..434985292 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/Activator.java @@ -0,0 +1,73 @@ +package org.simantics.tests.modelled.ui; + +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.simantics.tests.modelled.ui"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + for (Image image : imagesToDispose) + image.dispose(); + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + public static ImageDescriptor getImageDescriptor(String relativePath) { + URL url = getDefault().getBundle().getEntry(relativePath); + return ImageDescriptor.createFromURL(url); + } + + private static List imagesToDispose = new ArrayList<>(); + + public static Image createManagedImage(ImageDescriptor descriptor) { + Image image= descriptor.createImage(); + if (image == null) { + image= ImageDescriptor.getMissingImageDescriptor().createImage(); + } + imagesToDispose.add(image); + return image; + } +} diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/CoverageViewSorter.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/CoverageViewSorter.java new file mode 100644 index 000000000..b1a1413b6 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/CoverageViewSorter.java @@ -0,0 +1,97 @@ +package org.simantics.tests.modelled.ui; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.TreeViewerColumn; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.TreeColumn; +import org.simantics.scl.compiler.module.coverage.Coverage; + +class CoverageViewSorter extends ViewerComparator { + + private final TreeViewer viewer; + + public CoverageViewSorter(TreeViewer viewer) { + this.viewer = viewer; + } + + private Map columns = new HashMap<>(); + private int currentDirection; + + void addColumn(final TreeViewerColumn viewerColumn, final int columnidx) { + final TreeColumn column = viewerColumn.getColumn(); + setSortColumnAndDirection(column, SWT.UP); + column.addSelectionListener(new SelectionListener() { + + public void widgetSelected(SelectionEvent e) { + TreeColumn current = column.getParent().getSortColumn(); + if (current.equals(column)) { + int sortDirection = column.getParent().getSortDirection(); + setSortColumnAndDirection(column, sortDirection != SWT.DOWN ? SWT.DOWN : SWT.UP); + } else { + setSortColumnAndDirection(column, SWT.DOWN); + } + viewer.refresh(); + } + + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + columns.put(column, columnidx); + } + + private void setSortColumnAndDirection(TreeColumn sortColumn, int direction) { + currentDirection = direction; + sortColumn.getParent().setSortColumn(sortColumn); + sortColumn.getParent().setSortDirection(direction); + } + + + @Override + public int compare(Viewer viewer, Object e1, Object e2) { + + TreeViewer v = (TreeViewer) viewer; + TreeColumn currentColumn = v.getTree().getSortColumn(); + + int res = 0; + if (e1 instanceof Coverage && e2 instanceof Coverage) { + Coverage c1 = (Coverage) e1; + Coverage c2 = (Coverage) e2; + + int indx = columns.get(currentColumn); + switch (indx) { + case STSTestRunnerView.COLUMN_ELEMENT: + res = c1.getIdentifier().compareToIgnoreCase(c2.getIdentifier()); + break; + case STSTestRunnerView.COLUMN_RATIO: + res = Double.compare(c1.getCoverage(), c2.getCoverage()); + break; + case STSTestRunnerView.COLUMN_COVERED: + res = (int) (c1.getCoveredCodeSize() - c2.getCoveredCodeSize()); + break; + case STSTestRunnerView.COLUMN_MISSED: + res = (int) (c1.getMissedCodeSize()) - c2.getMissedCodeSize(); + break; + case STSTestRunnerView.COLUMN_TOTAL: + res = (int) (c1.getTotalCodeSize() - c2.getTotalCodeSize()); + break; + } + if (res == 0) { + res = c1.getIdentifier().compareTo(c2.getIdentifier()); + } else { + res = isReverseSort() ? -res : res; + } + } + return res; + } + + private boolean isReverseSort() { + return currentDirection == SWT.DOWN; + } +} diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/RedGreenBar.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/RedGreenBar.java new file mode 100644 index 000000000..981254950 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/RedGreenBar.java @@ -0,0 +1,54 @@ +package org.simantics.tests.modelled.ui; + +import java.text.DecimalFormat; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Event; +import org.simantics.scl.compiler.module.coverage.Coverage; + +public final class RedGreenBar { + + private static final int BORDER_LEFT = 2; + private static final int BORDER_RIGHT = 10; + private static final int BORDER_TOP = 3; + private static final int BORDER_BOTTOM = 4; + + private static final String MAX_PERCENTAGE_STRING = new DecimalFormat("0.0 %").format(1.0); + + private static final ImageDescriptor redbar = Activator.getImageDescriptor("icons/redbar.gif"); //$NON-NLS-1$ + private static final ImageDescriptor greenbar = Activator.getImageDescriptor("icons/greenbar.gif"); //$NON-NLS-1$ + private static Image redbarIcon = Activator.createManagedImage(redbar); + private static Image greenbarIcon = Activator.createManagedImage(greenbar); + + private RedGreenBar() { + } + +// public static void draw(Event event, int columnWith, ICounter counter) { +// draw(event, columnWith, counter, counter.getTotalCount()); +// } + + public static void draw(Event event, int columnWith, Coverage coverage) { + int maxTotal = coverage.getTotalCodeSize(); + if (maxTotal == 0) + return; + final int maxWidth = getMaxWidth(event, columnWith); + final int redLength = maxWidth * coverage.getMissedCodeSize() / maxTotal; + bar(event, redbarIcon, 0, redLength); + final int greenLength = maxWidth * coverage.getCoveredCodeSize() / maxTotal; + bar(event, greenbarIcon, redLength, greenLength); + } + + private static void bar(Event event, Image image, int xOffset, int width) { + final int height = event.getBounds().height - BORDER_TOP - BORDER_BOTTOM; + event.gc.drawImage(image, 0, 0, 1, 10, event.x + xOffset + BORDER_LEFT, + event.y + BORDER_TOP, width, height); + } + + private static int getMaxWidth(Event event, int columnWith) { + final int textWidth = event.gc.textExtent(MAX_PERCENTAGE_STRING).x; + final int max = columnWith - BORDER_LEFT - BORDER_RIGHT - textWidth; + return Math.max(0, max); + } + +} \ No newline at end of file diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSCounterPanel.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSCounterPanel.java new file mode 100644 index 000000000..8b04f2f11 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSCounterPanel.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * Copyright (c) 2000, 2013 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.simantics.tests.modelled.ui; + + +import java.text.MessageFormat; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +/** + * A panel with counters for the number of Runs, Errors and Failures. + */ +public class STSCounterPanel extends Composite { + protected Text numberOfErrors; + protected Text numberOfFailures; + protected Text numberOfRuns; + protected int total; + protected int ignoredCount; + protected int assumptionFailedCount; + + private final Image fErrorIcon = null; + private final Image fFailureIcon = null; + + public STSCounterPanel(Composite parent) { + super(parent, SWT.WRAP); + GridLayout gridLayout= new GridLayout(); + gridLayout.numColumns= 9; + gridLayout.makeColumnsEqualWidth= false; + gridLayout.marginWidth= 0; + setLayout(gridLayout); + + numberOfRuns= createLabel("Runs:", null, " 0/0 "); //$NON-NLS-1$ + numberOfErrors= createLabel("Errors:", fErrorIcon, " 0 "); //$NON-NLS-1$ + numberOfFailures= createLabel("Failures:", fFailureIcon, " 0 "); //$NON-NLS-1$ + + addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent e) { + disposeIcons(); + } + }); + } + + private void disposeIcons() { + if (fErrorIcon != null) + fErrorIcon.dispose(); + if (fFailureIcon != null) + fFailureIcon.dispose(); + } + + private Text createLabel(String name, Image image, String init) { + Label label= new Label(this, SWT.NONE); + if (image != null) { + image.setBackground(label.getBackground()); + label.setImage(image); + } + label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); + + label = new Label(this, SWT.NONE); + label.setText(name); + label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); + //label.setFont(JFaceResources.getBannerFont()); + + Text value = new Text(this, SWT.READ_ONLY); + value.setText(init); + // bug: 39661 Junit test counters do not repaint correctly [JUnit] +// SWTUtil.fixReadonlyTextBackground(value); + value.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING)); + return value; + } + + public void reset() { + setErrorValue(0); + setFailureValue(0); + setRunValue(0, 0, 0); + total= 0; + } + + public void setTotal(int value) { + total= value; + } + + public int getTotal(){ + return total; + } + + public void setRunValue(int value, int ignoredCount, int assumptionFailureCount) { + String runString; + String runStringTooltip; + if (ignoredCount == 0 && assumptionFailureCount == 0) { + runString= Messages.format("{0}/{1}", new String[] { Integer.toString(value), Integer.toString(total) }); + runStringTooltip= runString; + } else if (ignoredCount != 0 && assumptionFailureCount == 0) { + runString= Messages.format("Skipped", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount) }); + runStringTooltip= Messages.format("Ignored", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount) }); + } else if (ignoredCount == 0 && assumptionFailureCount != 0) { + runString= Messages.format("Skipped", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(assumptionFailureCount) }); + runStringTooltip= Messages.format("Failed", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(assumptionFailureCount) }); + } else { + runString= Messages.format("Skipped", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount + assumptionFailureCount) }); + runStringTooltip= Messages.format("Failed", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount), Integer.toString(assumptionFailureCount) }); + } + numberOfRuns.setText(runString); + numberOfRuns.setToolTipText(runStringTooltip); + + if (ignoredCount == 0 && ignoredCount > 0 || ignoredCount != 0 && ignoredCount == 0) { + layout(); + } else if (assumptionFailedCount == 0 && assumptionFailureCount > 0 || assumptionFailedCount != 0 && assumptionFailureCount == 0) { + layout(); + } else { + numberOfRuns.redraw(); + redraw(); + } + assumptionFailedCount= assumptionFailureCount; + } + + public void setErrorValue(int value) { + numberOfErrors.setText(Integer.toString(value)); + redraw(); + } + + public void setFailureValue(int value) { + numberOfFailures.setText(Integer.toString(value)); + redraw(); + } + + private static class Messages { + + public static String format(String message, Object object) { + return MessageFormat.format(message, new Object[] { object}); + } + + public static String format(String message, Object[] objects) { + return MessageFormat.format(message, objects); + } + + private Messages() { + // Not for instantiation + } + } +} diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSCoverageProvider.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSCoverageProvider.java new file mode 100644 index 000000000..0ba65ccf8 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSCoverageProvider.java @@ -0,0 +1,118 @@ +package org.simantics.tests.modelled.ui; + +import java.text.DecimalFormat; +import java.util.Collection; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.Viewer; +import org.simantics.scl.compiler.module.coverage.CombinedCoverage; +import org.simantics.scl.compiler.module.coverage.Coverage; +import org.simantics.scl.compiler.module.coverage.FunctionCoverage; +import org.simantics.scl.compiler.module.coverage.ModuleCoverage; +import org.simantics.tests.modelled.ui.STSTestSuiteModel.STSSuite; +import org.simantics.tests.modelled.ui.STSTestSuiteModel.STSTest; + +public class STSCoverageProvider extends LabelProvider implements ITreeContentProvider { + + private Object input; + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + input = newInput; + } + + @Override + public Object[] getElements(Object inputElement) { + CombinedCoverage coverage; + if (input instanceof STSTest) { + STSTest test = (STSTest) input; + coverage = test.getCoverage(); + } else if (input instanceof STSSuite) { + STSSuite suite = (STSSuite) input; + coverage = suite.getCoverage(); + } else { + return new Object[0]; + } + if (coverage == null) + return new Object[0]; + + return new Object[] { coverage }; + +// Collection moduleCoverages = coverage.moduleCoverages.values(); +// return moduleCoverages.toArray(new ModuleCoverage[moduleCoverages.size()]); + } + + @Override + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof CombinedCoverage) { + CombinedCoverage coverage = (CombinedCoverage) parentElement; + Collection moduleCoverages = coverage.moduleCoverages.values(); + return moduleCoverages.toArray(new ModuleCoverage[moduleCoverages.size()]); + } else if (parentElement instanceof ModuleCoverage) { + ModuleCoverage coverage = (ModuleCoverage) parentElement; + Collection coverages = coverage.functionCoverages.values(); + return coverages.toArray(new FunctionCoverage[coverages.size()]); + } else { + return null; + } + } + + @Override + public Object getParent(Object element) { + if (element instanceof FunctionCoverage) { + FunctionCoverage coverage = (FunctionCoverage) element; + return new ModuleCoverage[] { null }; + } else { + return null; + } + } + + @Override + public boolean hasChildren(Object element) { + if (element instanceof CombinedCoverage) + return !((CombinedCoverage) element).moduleCoverages.isEmpty(); + else if (element instanceof ModuleCoverage) + return !((ModuleCoverage)element).functionCoverages.isEmpty(); + else + return false; + } + + @Override + public String getText(Object element) { + if (element instanceof Coverage) + return ((Coverage) element).getIdentifier(); + return super.getText(element); + } + + public String getRatio(Object element) { + if (element instanceof Coverage) + return formatPercentage(((Coverage) element).getCoverage()); + return "unknown " + element; + } + + public String getCovered(Object element) { + if (element instanceof Coverage) + return ((Coverage) element).getCoveredCodeSize() + ""; + return "unknown " + element; + } + + public String getMissed(Object element) { + if (element instanceof Coverage) + return ((Coverage) element).getMissedCodeSize() + ""; + return "unknown " + element; + } + + public String getTotal(Object element) { + if (element instanceof Coverage) + return ((Coverage) element).getTotalCodeSize() + ""; + return "unknown " + element; + } + + private static final DecimalFormat MAX_PERCENTAGE_STRING = new DecimalFormat("0.0 %"); + + private static String formatPercentage(double perc) { + return MAX_PERCENTAGE_STRING.format(perc); + } + +} diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSExecutionListener.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSExecutionListener.java new file mode 100644 index 000000000..29989a931 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSExecutionListener.java @@ -0,0 +1,6 @@ +package org.simantics.tests.modelled.ui; + +public interface STSExecutionListener { + + void testExecuted(); +} diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSProgressBar.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSProgressBar.java new file mode 100644 index 000000000..9a2908802 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSProgressBar.java @@ -0,0 +1,183 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Michels, stephan@apache.org - 104944 [JUnit] Unnecessary code in JUnitProgressBar + *******************************************************************************/ +package org.simantics.tests.modelled.ui; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +/** + * A progress bar with a red/green indication for success or failure. + */ +public class STSProgressBar extends Canvas { + private static final int DEFAULT_WIDTH = 160; + private static final int DEFAULT_HEIGHT = 18; + + private int fCurrentTickCount= 0; + private int fMaxTickCount= 0; + private int fColorBarWidth= 0; + private Color fOKColor; + private Color fFailureColor; + private Color fStoppedColor; + private boolean fError; + private boolean fStopped= false; + + public STSProgressBar(Composite parent) { + super(parent, SWT.NONE); + + addControlListener(new ControlAdapter() { + @Override + public void controlResized(ControlEvent e) { + fColorBarWidth= scale(fCurrentTickCount); + redraw(); + } + }); + addPaintListener(new PaintListener() { + public void paintControl(PaintEvent e) { + paint(e); + } + }); + addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent e) { + fFailureColor.dispose(); + fOKColor.dispose(); + fStoppedColor.dispose(); + } + }); + Display display= parent.getDisplay(); + fFailureColor= new Color(display, 159, 63, 63); + fOKColor= new Color(display, 95, 191, 95); + fStoppedColor= new Color(display, 120, 120, 120); + } + + public void setMaximum(int max) { + fMaxTickCount= max; + } + + public void reset() { + fError= false; + fStopped= false; + fCurrentTickCount= 0; + fMaxTickCount= 0; + fColorBarWidth= 0; + redraw(); + } + + public void reset(boolean hasErrors, boolean stopped, int ticksDone, int maximum) { + boolean noChange= fError == hasErrors && fStopped == stopped && fCurrentTickCount == ticksDone && fMaxTickCount == maximum; + fError= hasErrors; + fStopped= stopped; + fCurrentTickCount= ticksDone; + fMaxTickCount= maximum; + fColorBarWidth= scale(ticksDone); + if (! noChange) + redraw(); + } + + private void paintStep(int startX, int endX) { + GC gc = new GC(this); + setStatusColor(gc); + Rectangle rect= getClientArea(); + startX= Math.max(1, startX); + gc.fillRectangle(startX, 1, endX-startX, rect.height-2); + gc.dispose(); + } + + private void setStatusColor(GC gc) { + if (fStopped) + gc.setBackground(fStoppedColor); + else if (fError) + gc.setBackground(fFailureColor); + else + gc.setBackground(fOKColor); + } + + public void stopped() { + fStopped= true; + redraw(); + } + + private int scale(int value) { + if (fMaxTickCount > 0) { + Rectangle r= getClientArea(); + if (r.width != 0) + return Math.max(0, value*(r.width-2)/fMaxTickCount); + } + return value; + } + + private void drawBevelRect(GC gc, int x, int y, int w, int h, Color topleft, Color bottomright) { + gc.setForeground(topleft); + gc.drawLine(x, y, x+w-1, y); + gc.drawLine(x, y, x, y+h-1); + + gc.setForeground(bottomright); + gc.drawLine(x+w, y, x+w, y+h); + gc.drawLine(x, y+h, x+w, y+h); + } + + private void paint(PaintEvent event) { + GC gc = event.gc; + Display disp= getDisplay(); + + Rectangle rect= getClientArea(); + gc.fillRectangle(rect); + drawBevelRect(gc, rect.x, rect.y, rect.width-1, rect.height-1, + disp.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW), + disp.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW)); + + setStatusColor(gc); + fColorBarWidth= Math.min(rect.width-2, fColorBarWidth); + gc.fillRectangle(1, 1, fColorBarWidth, rect.height-2); + } + + @Override + public Point computeSize(int wHint, int hHint, boolean changed) { + checkWidget(); + Point size= new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT); + if (wHint != SWT.DEFAULT) size.x= wHint; + if (hHint != SWT.DEFAULT) size.y= hHint; + return size; + } + + public void step(int failures) { + fCurrentTickCount++; + int x= fColorBarWidth; + + fColorBarWidth= scale(fCurrentTickCount); + + if (!fError && failures > 0) { + fError= true; + x= 1; + } + if (fCurrentTickCount == fMaxTickCount) + fColorBarWidth= getClientArea().width-1; + paintStep(x, fColorBarWidth); + } + + public void refresh(boolean hasErrors) { + fError= hasErrors; + redraw(); + } + +} diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestEditor.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestEditor.java new file mode 100644 index 000000000..905a148d0 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestEditor.java @@ -0,0 +1,17 @@ +package org.simantics.tests.modelled.ui; + +import org.simantics.modeling.ui.componentTypeEditor.SCLModuleEditor; +import org.simantics.scl.ui.editor.SCLSourceViewerConfigurationNew; + +public class STSTestEditor extends SCLModuleEditor { + + + + @Override + protected void preInitialize() { + SCLSourceViewerConfigurationNew sourceViewerConfiguration = new SCLSourceViewerConfigurationNew(resourceManager); + setDocumentProvider(new STSTestEditorDocumentProvider(sourceViewerConfiguration)); + setSourceViewerConfiguration(sourceViewerConfiguration); + } + +} diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestEditorDocumentProvider.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestEditorDocumentProvider.java new file mode 100644 index 000000000..ed1633c5e --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestEditorDocumentProvider.java @@ -0,0 +1,79 @@ +package org.simantics.tests.modelled.ui; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.simantics.Simantics; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.util.Layer0Utils; +import org.simantics.layer0.Layer0; +import org.simantics.modeling.ui.componentTypeEditor.SCLModuleEditorDocumentProvider; +import org.simantics.scl.ui.editor.SCLSourceViewerConfigurationNew; +import org.simantics.tests.modelled.ontology.TestsResource; +import org.simantics.ui.workbench.ResourceEditorInput; +import org.simantics.utils.logging.TimeLogger; + +public class STSTestEditorDocumentProvider extends SCLModuleEditorDocumentProvider { + + public STSTestEditorDocumentProvider(SCLSourceViewerConfigurationNew sourceViewer) { + super(sourceViewer); + } + + @Override + protected IAnnotationModel createAnnotationModel(Object element) throws CoreException { + return null; + } + + @Override + protected void updateAnnotations() { + } + + @Override + protected IDocument createDocument(Object element) throws CoreException { + ResourceEditorInput input = (ResourceEditorInput)element; + resource = input.getResource(); + try { + return Simantics.getSession().syncRequest(new UniqueRead() { + @Override + public Document perform(ReadGraph graph) throws DatabaseException { + TestsResource TESTS = TestsResource.getInstance(graph); + currentText = graph.getRelatedValue(resource, TESTS.STSTest_definition, Bindings.STRING); + errorHappened = false; + return new Document(currentText != null ? currentText : ""); + } + }); + } catch (DatabaseException e) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + e.printStackTrace(pw); + errorHappened = true; + return new Document(sw.toString()); + } + } + + @Override + protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException { + TimeLogger.resetTimeAndLog("STSTestEditorDocumentProvider.doSaveDocument"); + currentText = document.get(); + Simantics.getSession().asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + TestsResource TESTS = TestsResource.getInstance(graph); + graph.claimLiteral(resource, TESTS.STSTest_definition, currentText, Bindings.STRING); + Layer0Utils.addCommentMetadata(graph, "Saved SCL Module " + graph.getRelatedValue2(resource, Layer0.getInstance(graph).HasName, Bindings.STRING)); + } + }); + } + +} diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestRunnerView.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestRunnerView.java new file mode 100644 index 000000000..09e959929 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestRunnerView.java @@ -0,0 +1,419 @@ +package org.simantics.tests.modelled.ui; + +import java.util.List; +import java.util.concurrent.Executors; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.eclipse.e4.ui.di.Focus; +import org.eclipse.jface.layout.TreeColumnLayout; +import org.eclipse.jface.viewers.CellLabelProvider; +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.OwnerDrawLabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.TreeViewerColumn; +import org.eclipse.jface.viewers.ViewerCell; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CTabFolder; +import org.eclipse.swt.custom.CTabItem; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.custom.ViewForm; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Layout; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.ui.part.PageBook; +import org.simantics.db.Resource; +import org.simantics.scl.compiler.module.coverage.Coverage; + +public class STSTestRunnerView { + + public static final String ID = "org.simantics.tests.modelled.ui.stsTestRunnerView"; + + private Resource test; + private SashForm sashForm; + private PageBook viewerbook; + private TreeViewer treeViewer; +// private ITreeContentProvider treeContentProvider; + private STSTestSuiteProvider provider; + private StyledText output; + private STSCounterPanel counterPanel; + private STSProgressBar progressBar; + private Composite counterComposite; + + @PostConstruct + void createView(Composite parent) { + + GridLayout gridLayout= new GridLayout(); + gridLayout.marginWidth= 0; + gridLayout.marginHeight= 0; + parent.setLayout(gridLayout); + + counterComposite= createProgressCountPanel(parent); + counterComposite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); + counterComposite.pack(); + + SashForm sashForm = createSashForm(parent); + sashForm.setLayoutData(new GridData(GridData.FILL_BOTH)); + } + + private SashForm createSashForm(Composite parent) { + sashForm = new SashForm(parent, SWT.VERTICAL); + + ViewForm top = new ViewForm(sashForm, SWT.NONE); + + Composite empty = new Composite(top, SWT.NONE); + empty.setLayout(new Layout() { + @Override + protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) { + return new Point(1, 1); // (0, 0) does not work with super-intelligent ViewForm + } + @Override + protected void layout(Composite composite, boolean flushCache) { + } + }); + top.setTopLeft(empty); // makes ViewForm draw the horizontal separator line ... +// fTestViewer= new TestViewer(top, fClipboard, this); + createTestViewers(top); + top.setContent(viewerbook); + treeViewer.setInput(test); + + ViewForm bottom = new ViewForm(sashForm, SWT.NONE); + + CTabFolder folder = new CTabFolder(bottom, SWT.BORDER); + folder.setLayoutData(new GridData(GridData.FILL_BOTH)); + + CTabItem item1 = new CTabItem(folder, SWT.NONE); + item1.setText("Execution"); +// PageBook fViewerbook2= new PageBook(bottom, SWT.NULL); + // Upper + output = new StyledText(folder, SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL); +// output.setFont(textFont); + { + FormData formData = new FormData(); + formData.top = new FormAttachment(0); +// formData.bottom = new FormAttachment(sash); + formData.left = new FormAttachment(0); + formData.right = new FormAttachment(100); + output.setLayoutData(formData); + } + item1.setControl(output); +// fViewerbook2.showPage(output); + bottom.setContent(folder); + folder.setSelection(0); + + CTabItem item2 = new CTabItem(folder, SWT.NONE); + item2.setText("Coverage"); + + Composite treeComposite = new Composite(folder, SWT.NONE); + + TreeViewer viewer = createCoverageViewer(treeComposite); + item2.setControl(treeComposite); + + treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + ISelection selection = event.getSelection(); + TreeSelection sel = (TreeSelection) selection; + List testOutput = provider.getModel().getOutput(sel.getFirstElement()); + + viewer.setInput(sel.getFirstElement()); + + StringBuilder sb = new StringBuilder(); + for (String o : testOutput) { + sb.append(o); + } + output.setText(sb.toString()); + } + }); + + sashForm.setWeights(new int[] {50, 50}); + return sashForm; + } + + protected static final int COLUMN_ELEMENT = 0; + protected static final int COLUMN_RATIO = 1; + protected static final int COLUMN_COVERED = 2; + protected static final int COLUMN_MISSED = 3; + protected static final int COLUMN_TOTAL = 4; + + private TreeViewer createCoverageViewer(Composite parent) { + // Composite treeViewerComposite = new Composite(parent, SWT.NONE); + + TreeColumnLayout layout = new TreeColumnLayout(); + parent.setLayout(layout); + + Tree tree = new Tree(parent, SWT.MULTI | SWT.FULL_SELECTION); + tree.setHeaderVisible(true); + tree.setLinesVisible(true); + + STSCoverageProvider provider = new STSCoverageProvider(); + + TreeViewer viewer = new TreeViewer(tree); + + CoverageViewSorter sorter = new CoverageViewSorter(viewer); + + final TreeViewerColumn column0 = new TreeViewerColumn(viewer, SWT.LEFT); + + column0.setLabelProvider(new CellLabelProvider() { + + + @Override + public void update(ViewerCell cell) { + cell.setText(provider.getText(cell.getElement())); + cell.setImage(provider.getImage(cell.getElement())); + } + }); + sorter.addColumn(column0, COLUMN_ELEMENT); + + final TreeViewerColumn column1 = new TreeViewerColumn(viewer, SWT.RIGHT); + column1.setLabelProvider(new OwnerDrawLabelProvider() { + + @Override + public void update(ViewerCell cell) { + cell.setText(provider.getRatio(cell.getElement())); + } + + @Override + protected void erase(Event event, Object element) { + } + + @Override + protected void measure(Event event, Object element) { + } + + @Override + protected void paint(Event event, Object element) { + final Coverage coverage = (Coverage) element; + if (coverage != null) { + RedGreenBar.draw(event, column1.getColumn().getWidth(), coverage); + } + } + }); + sorter.addColumn(column1, COLUMN_RATIO); + + final TreeViewerColumn column2 = new TreeViewerColumn(viewer, SWT.RIGHT); + column2.setLabelProvider(new CellLabelProvider() { + + @Override + public void update(ViewerCell cell) { + cell.setText(provider.getCovered(cell.getElement())); + } + }); + sorter.addColumn(column2, COLUMN_COVERED); + + final TreeViewerColumn column3 = new TreeViewerColumn(viewer, SWT.RIGHT); + column3.setLabelProvider(new CellLabelProvider() { + + @Override + public void update(ViewerCell cell) { + cell.setText(provider.getMissed(cell.getElement())); + } + }); + sorter.addColumn(column3, COLUMN_MISSED); + + final TreeViewerColumn column4 = new TreeViewerColumn(viewer, SWT.RIGHT); + column4.setLabelProvider(new CellLabelProvider() { + + @Override + public void update(ViewerCell cell) { + cell.setText(provider.getTotal(cell.getElement())); + } + }); + sorter.addColumn(column4, COLUMN_TOTAL); + +// viewer.addFilter(new ViewerFilter() { +// public boolean select(Viewer viewer, Object parentElement, Object element) { +// if (element == LOADING_ELEMENT) { +// return true; +// } else { +// final ICoverageNode c = CoverageTools.getCoverageInfo(element); +// if (c == null) { +// return false; +// } +// final ICounter instructions = c.getInstructionCounter(); +// if (instructions.getTotalCount() == 0) { +// return false; +// } +// if (settings.getHideUnusedElements() && instructions.getCoveredCount() == 0) { +// return false; +// } +// return true; +// } +// } +// }); + viewer.setComparator(sorter); + + layout.setColumnData(column0.getColumn(), new ColumnWeightData(0, 50, false)); + layout.setColumnData(column1.getColumn(), new ColumnWeightData(0, 50, false)); + layout.setColumnData(column2.getColumn(), new ColumnWeightData(0, 50, false)); + layout.setColumnData(column3.getColumn(), new ColumnWeightData(0, 50, false)); + layout.setColumnData(column4.getColumn(), new ColumnWeightData(0, 50, false)); + + String[] columns = new String[] {"Module", "Coverage", "Covered Instructions", "Missed Instructions", "Total Instructions"}; + TreeColumn[] columns2 = viewer.getTree().getColumns(); + for (int i = 0; i < columns2.length; i++) { + columns2[i].setText(columns[i]); + } + restoreColumnWidth(viewer); + viewer.setContentProvider(provider); + return viewer; + +// viewer.addOpenListener(new IOpenListener() { +// public void open(OpenEvent event) { +// openAction.run((IStructuredSelection) event.getSelection()); +// } +// }); + +// MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ +// menuMgr.setRemoveAllWhenShown(true); +// tree.setMenu(menuMgr.createContextMenu(tree)); +// getSite().registerContextMenu(menuMgr, viewer); +// +// CoverageTools.getSessionManager().addSessionListener(descriptionUpdater); +// CoverageTools.addJavaCoverageListener(coverageListener); + } + + private static final int[] DEFAULT_COLUMNWIDTH = new int[] { 200, 100, 120, + 120, 120 }; + + public void restoreColumnWidth(TreeViewer viewer) { + final TreeColumn[] columns = viewer.getTree().getColumns(); + for (int i = 0; i < DEFAULT_COLUMNWIDTH.length; i++) { + columns[i].setWidth(DEFAULT_COLUMNWIDTH[i]); + } + } + + protected Composite createProgressCountPanel(Composite parent) { + Composite composite= new Composite(parent, SWT.NONE); + GridLayout layout= new GridLayout(); + composite.setLayout(layout); + layout.numColumns = 1; + + counterPanel = new STSCounterPanel(composite); + counterPanel.setLayoutData( + new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); + progressBar = new STSProgressBar(composite); + progressBar.setLayoutData( + new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); + return composite; + } + + private void createTestViewers(Composite parent) { + viewerbook = new PageBook(parent, SWT.NULL); + + treeViewer = new TreeViewer(viewerbook, SWT.V_SCROLL | SWT.SINGLE); + treeViewer.setUseHashlookup(true); + + STSTestSuiteModel model = new STSTestSuiteModel(); + model.addListener(new STSExecutionListener() { + + @Override + public void testExecuted() { + treeViewer.getControl().getDisplay().syncExec(() -> { + refreshCounters(); + treeViewer.refresh(); + }); + } + }); + + provider = new STSTestSuiteProvider(model); + + treeViewer.setContentProvider(provider); + treeViewer.setLabelProvider(provider); + + + viewerbook.showPage(treeViewer.getTree()); + + } + + + @Focus + void setFocus() { + sashForm.setFocus(); + } + + public void currentTest(Resource test) { + treeViewer.setInput(test); + refreshCounters(); + } + + private void refreshCounters() { + // TODO: Inefficient. Either + // - keep a boolean fHasTestRun and update only on changes, or + // - improve components to only redraw on changes (once!). + + int startedCount; + int ignoredCount; + int totalCount; + int errorCount; + int failureCount; + int assumptionFailureCount; + boolean hasErrorsOrFailures; + boolean stopped; + + STSTestSuiteModel model = provider.getModel(); + if (model != null) { + startedCount= model.getStartedCount(); + ignoredCount= model.getIgnoredCount(); + totalCount= model.getTotalCount(); + errorCount= model.getErrorCount(); + failureCount= model.getFailureCount(); + assumptionFailureCount = model.getAssumptionFailureCount(); + hasErrorsOrFailures= errorCount + failureCount > 0; + stopped= model.isStopped(); + } else { + startedCount= 0; + ignoredCount= 0; + totalCount= 0; + errorCount= 0; + failureCount= 0; + assumptionFailureCount = 0; + hasErrorsOrFailures= false; + stopped= false; + } + + counterPanel.setTotal(totalCount); + counterPanel.setRunValue(startedCount, ignoredCount, assumptionFailureCount); + counterPanel.setErrorValue(errorCount); + counterPanel.setFailureValue(failureCount); + + int ticksDone; + if (startedCount == 0) + ticksDone= 0; + else if (startedCount == totalCount && model.isStopped()) + ticksDone= totalCount; + else + ticksDone= startedCount - 1; + + progressBar.reset(hasErrorsOrFailures, stopped, ticksDone, totalCount); + } + + public void execute() { + Executors.newSingleThreadExecutor().submit(new Runnable() { + + @Override + public void run() { + provider.getModel().execute(); + } + }); + } + + @PreDestroy + public void destroy() { + provider.dispose(); + } +} diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestSuiteModel.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestSuiteModel.java new file mode 100644 index 000000000..188574e54 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestSuiteModel.java @@ -0,0 +1,504 @@ +package org.simantics.tests.modelled.ui; + +import java.io.BufferedReader; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import org.eclipse.swt.graphics.Image; +import org.simantics.Simantics; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.scl.compiler.commands.CommandSession; +import org.simantics.scl.compiler.commands.TestScriptExecutor; +import org.simantics.scl.compiler.module.Module; +import org.simantics.scl.compiler.module.coverage.CombinedCoverage; +import org.simantics.scl.compiler.module.coverage.CoverageBuilder; +import org.simantics.scl.compiler.module.coverage.CoverageUtils; +import org.simantics.scl.compiler.module.options.ModuleCompilationOptions; +import org.simantics.scl.compiler.module.options.ModuleCompilationOptionsAdvisor; +import org.simantics.scl.compiler.module.repository.ModuleRepository; +import org.simantics.scl.compiler.runtime.RuntimeModule; +import org.simantics.scl.osgi.SCLOsgi; +import org.simantics.scl.runtime.reporting.AbstractSCLReportingHandler; +import org.simantics.tests.modelled.ontology.TestsResource; + +public class STSTestSuiteModel { + + static class STSTest { + + private final Resource test; + private final STSSuite parent; + private final String definition; + private final String name; + private boolean executed = false; + private long duration; + private boolean failed = false; + private boolean isRunning = false; + private List output = new ArrayList<>(); + private CombinedCoverage coverage; + private int priority; + + public STSTest(Resource test, STSSuite parent, String definition, String name, int executionPrioprity) { + this.test = test; + this.parent = parent; + this.definition = definition; + this.name = name; + this.priority = executionPrioprity; + } + + public String getName() { + return name; + } + + public String getLabel() { + StringBuilder sb = new StringBuilder(); + sb.append(name); + if (executed || failed) + sb.append(" (").append(duration).append(" ms)"); + return sb.toString(); + } + + public String getDefinition() { + return definition; + } + + public STSSuite getParent() { + return parent; + } + + public void execute(CommandSession session) { + isRunning = true; + + TestScriptExecutor executor = new TestScriptExecutor(session, new BufferedReader(new StringReader(definition)), new AbstractSCLReportingHandler() { + + @Override + public void print(String text) { + appendOutput(text + "\n"); + } + + @Override + public void printCommand(String command) { + appendOutput("> " + command + "\n"); + } + + @Override + public void printError(String error) { + appendOutput(error + "\n"); + } + }); + long start = System.currentTimeMillis(); + try { + if (parent != null) + parent.startedCount++; + executor.execute(); + executed = true; + } catch (Throwable t) { + t.printStackTrace(); + if (parent != null) + parent.failureCount++; + failed = true; + } finally { + isRunning = false; + long end = System.currentTimeMillis(); + duration = end - start; + } + + } + + protected void appendOutput(String text) { + output.add(text); + } + + public List getOutput() { + return output; + } + + public void setCoverage(CombinedCoverage coverage) { + this.coverage = coverage; + } + + public CombinedCoverage getCoverage() { + return coverage; + } + + @Override + public String toString() { + return name + " [priority=" + priority + ", executed=" + executed + ", duration=" + duration + "]"; + } + } + + static class STSSuite { + + private List moduleNameFilterPatterns = new ArrayList<>(); + private final Resource suite; + private final String name; + private STSTest[] children; + private int startedCount; + private int errorCount; + private int failureCount; + private CoverageBuilder coverageBuilder; + + public STSSuite(Resource suite, String name, String moduleNameFilter) { + this.suite = suite; + this.name = name; + for (String s : moduleNameFilter.split(",")) { + try { + s = s.trim().replaceAll("\\*", "\\\\w*").toLowerCase(); + moduleNameFilterPatterns.add(Pattern.compile(s)); + } catch (PatternSyntaxException e) { + e.printStackTrace(); + } + } + } + + public void children(STSTest[] children) { + this.children = children; + } + + public STSTest[] getChildren() { + return children; + } + + public String getName() { + return name; + } + + public String getLabel() { + StringBuilder sb = new StringBuilder(); + sb.append(name); + long totalTime = 0; + if (children != null) { + for (STSTest test : children) { + if (test.executed || test.failed) { + totalTime += test.duration; + } + } + } + if (totalTime != 0) + sb.append(" (").append(totalTime).append(" ms)"); + return sb.toString(); + } + + public boolean isRunning() { + boolean running = false; + if (children != null) { + for (STSTest test: children) { + if (test.isRunning) { + running = true; + break; + } + } + } + return running; + } + + public boolean executed() { + boolean executed = true; + if (children != null) { + for (STSTest test: children) { + if (!test.executed) { + executed = false; + break; + } + } + } + return executed; + } + + public boolean failed() { + boolean failed = false; + if (children != null) { + for (STSTest test: children) { + if (test.failed) { + failed = true; + break; + } + } + } + return failed; + } + + public void addCoverage(List modules) { + if (coverageBuilder == null) { + coverageBuilder = new CoverageBuilder(); + } + for (Module module : modules) + coverageBuilder.addCoverage(module, true); + } + + public CombinedCoverage getCoverage() { + if (coverageBuilder == null) + return null; + return coverageBuilder.getCoverage(); + } + } + + + private STSSuite suite; + private STSTest test; + private final List listeners = new ArrayList<>(); + + public STSTestSuiteModel() { + } + + public void addListener(STSExecutionListener listener) { + listeners.add(listener); + } + + public void removeListener(STSExecutionListener listener) { + listeners.remove(listener); + } + + public Object[] getElements() { + if (suite != null) + return new Object[] {suite}; + else if (test != null) + return new Object[] {test}; + else return null; + } + + public void execute() { + + ModuleRepository repo = new ModuleRepository(SCLOsgi.SOURCE_REPOSITORY); + if (suite != null) { + repo.setAdvisor(new ModuleCompilationOptionsAdvisor() { + + @Override + public ModuleCompilationOptions getOptions(String moduleName) { + boolean coverage = false; + for (Pattern p : suite.moduleNameFilterPatterns) { + if (p.matcher(moduleName.toLowerCase()).find()) { + coverage = true; + break; + } + } + return new ModuleCompilationOptions(coverage); + } + }); + } + CommandSession session = new CommandSession(repo, null); + if (suite != null) { + executeSuite(session); + } else if (test != null) { + executeTest(session); + } + } + + private void testExecuted() { + listeners.forEach(listener -> { + listener.testExecuted(); + }); + } + + private void executeSuite(CommandSession session) { + + for (STSTest test : suite.getChildren()) { + test.execute(session); + + Collection runtimeModules = session.getRuntimeEnvironment().getRuntimeModules(); + List modules = new ArrayList<>(runtimeModules.size()); + for (RuntimeModule module : runtimeModules) { + for (Pattern p : suite.moduleNameFilterPatterns) { + if (p.matcher(module.getModule().getName().toLowerCase()).find()) { + modules.add(module.getModule()); + } + } + } + test.setCoverage(CoverageUtils.getCoverage(modules)); + suite.addCoverage(modules); + + CoverageUtils.resetCoverage(modules); + + testExecuted(); + } + + } + + private void executeTest(CommandSession session) { + + test.execute(session); + testExecuted(); + + Collection runtimeModules = session.getRuntimeEnvironment().getRuntimeModules(); + List modules = new ArrayList<>(runtimeModules.size()); + for (RuntimeModule module : runtimeModules) { + modules.add(module.getModule()); + } + test.setCoverage(CoverageUtils.getCoverage(modules)); + + CoverageUtils.resetCoverage(modules); + + } + + + public boolean hasChildren(Object element) { + if (element instanceof STSTest) { + return false; + } else if (element instanceof STSSuite) { + STSSuite suite = (STSSuite) element; + return (suite.getChildren() != null ? suite.getChildren().length > 0 : false); + } else { + throw new IllegalArgumentException(element.toString()); + } + } + + public Object getParent(Object element) { + if (element instanceof STSTest) { + return ((STSTest) element).getParent(); + } else if (element instanceof STSSuite) { + return null; + } else { + throw new IllegalArgumentException(element.toString()); + } + } + + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof STSTest) { + return null; + } else if (parentElement instanceof STSSuite) { + STSSuite suite = (STSSuite) parentElement; + return suite.getChildren(); + } else { + throw new IllegalArgumentException(parentElement.toString()); + } + } + + public String getText(Object element) { + if (element instanceof STSTest) + return ((STSTest)element).getLabel(); + else if (element instanceof STSSuite) + return ((STSSuite)element).getLabel(); + else + throw new IllegalArgumentException(element.toString()); + } + + public Image getImage(Object element) { + if (element instanceof STSSuite) { + STSSuite suite = (STSSuite) element; + if (suite.isRunning()) + return STSTestSuiteProvider.suiteRunningIcon; + else if (suite.executed()) + return STSTestSuiteProvider.suiteOkIcon; + else if (suite.failed()) + return STSTestSuiteProvider.suiteFailIcon; + else + return STSTestSuiteProvider.suiteIcon; + } else if (element instanceof STSTest) { + STSTest test = (STSTest) element; + if (test.isRunning) + return STSTestSuiteProvider.testRunningIcon; + else if (test.executed) + return STSTestSuiteProvider.testOkIcon; + else if (test.failed) + return STSTestSuiteProvider.testFailIcon; + else + return STSTestSuiteProvider.testIcon; + } + return null; + } + + public void updateInput(Resource root) { + suite = null; + test = null; + try { + Simantics.getSession().syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + TestsResource TESTS = TestsResource.getInstance(graph); + if (graph.isInstanceOf(root, TESTS.STSTest)) { + String testName = graph.getRelatedValue2(root, L0.HasName, Bindings.STRING); + String definition = graph.getRelatedValue2(root, TESTS.STSTest_definition, Bindings.STRING); + Integer executionPrioprity = graph.getRelatedValue2(root, TESTS.STSTest_executionPriority, Bindings.INTEGER); + test = new STSTest(root, null, definition, testName, executionPrioprity); + } else if (graph.isInstanceOf(root, TESTS.STSSuite)) { + String suiteName = graph.getRelatedValue2(root, L0.HasName, Bindings.STRING); + String moduleNameFilter = graph.getPossibleRelatedValue2(root, TESTS.STSSuite_moduleNameFilter, Bindings.STRING); + suite = new STSSuite(root, suiteName, moduleNameFilter); + List tests = new ArrayList<>(); + for (Resource test : graph.getObjects(root, L0.ConsistsOf)) { + String testName = graph.getRelatedValue2(test, L0.HasName, Bindings.STRING); + String definition = graph.getRelatedValue2(test, TESTS.STSTest_definition, Bindings.STRING); + Integer executionPrioprity = graph.getRelatedValue2(test, TESTS.STSTest_executionPriority, Bindings.INTEGER); + tests.add(new STSTest(test, suite, definition, testName, executionPrioprity)); + } + Collections.sort(tests, (o1, o2) -> { + if (o1.priority < o2.priority) + return -1; + if (o1.priority > o2.priority) + return 1; + return 0; + }); + suite.children(tests.toArray(new STSTest[tests.size()])); + } else { + throw new IllegalArgumentException(root.toString()); + } + } + }); + } catch (DatabaseException e) { + e.printStackTrace(); + } + } + + public List getOutput(Object element) { + if (element instanceof STSTest) { + STSTest test = (STSTest) element; + return test.getOutput(); + } + return Collections.emptyList(); + } + + public int getStartedCount() { + if (suite != null) + return suite.startedCount; + else + return 0; + } + + public int getIgnoredCount() { + return 0; + } + + public int getTotalCount() { + if (suite != null && suite.getChildren() != null) + return suite.getChildren().length; + else if (test != null) + return 1; + else + return 0; + } + + public int getErrorCount() { + if (suite != null) + return suite.errorCount; + return 0; + } + + public int getFailureCount() { + if (suite != null) + return suite.failureCount; + return 0; + } + + public int getAssumptionFailureCount() { + return 0; + } + + public boolean isStopped() { + if (suite != null) + return !suite.isRunning(); + else + return test.isRunning; + } +} + diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestSuiteProvider.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestSuiteProvider.java new file mode 100644 index 000000000..a18b39153 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestSuiteProvider.java @@ -0,0 +1,104 @@ +package org.simantics.tests.modelled.ui; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.graphics.Image; +import org.simantics.db.Resource; + +public class STSTestSuiteProvider extends LabelProvider implements ITreeContentProvider, IStyledLabelProvider { + + private static final ImageDescriptor testIconDescriptor = Activator.getImageDescriptor("icons/test.png"); //$NON-NLS-1$ + private static final ImageDescriptor testOkIconDescriptor = Activator.getImageDescriptor("icons/testok.png"); //$NON-NLS-1$ + private static final ImageDescriptor testErrorIconDescriptor = Activator.getImageDescriptor("icons/testerr.png"); //$NON-NLS-1$ + private static final ImageDescriptor testFailIconDescriptor = Activator.getImageDescriptor("icons/testfail.png"); //$NON-NLS-1$ + private static final ImageDescriptor testRunningIconDescriptor = Activator.getImageDescriptor("icons/testrun.png"); //$NON-NLS-1$ + + private static final ImageDescriptor suiteIconDescriptor = Activator.getImageDescriptor("icons/tsuite.png"); //$NON-NLS-1$ + private static final ImageDescriptor suiteOkIconDescriptor = Activator.getImageDescriptor("icons/tsuiteok.png"); //$NON-NLS-1$ + private static final ImageDescriptor suiteErrorIconDescriptor = Activator.getImageDescriptor("icons/tsuiteerror.png"); //$NON-NLS-1$ + private static final ImageDescriptor suiteFailIconDescriptor = Activator.getImageDescriptor("icons/tsuitefail.png"); //$NON-NLS-1$ + private static final ImageDescriptor suiteRunningIconDescriptor = Activator.getImageDescriptor("icons/tsuiterun.png"); //$NON-NLS-1$ + + static Image testIcon; + static Image testOkIcon; + static Image testErrorIcon; + static Image testFailIcon; + static Image testRunningIcon; + + static Image suiteIcon; + static Image suiteOkIcon; + static Image suiteErrorIcon; + static Image suiteFailIcon; + static Image suiteRunningIcon; + + private STSTestSuiteModel model; + + public STSTestSuiteProvider(STSTestSuiteModel model) { + this.model = model; + testIcon = Activator.createManagedImage(testIconDescriptor); + testOkIcon = Activator.createManagedImage(testOkIconDescriptor); + testErrorIcon = Activator.createManagedImage(testErrorIconDescriptor); + testFailIcon = Activator.createManagedImage(testFailIconDescriptor); + testRunningIcon = Activator.createManagedImage(testRunningIconDescriptor); + + suiteIcon = Activator.createManagedImage(suiteIconDescriptor); + suiteOkIcon = Activator.createManagedImage(suiteOkIconDescriptor); + suiteErrorIcon = Activator.createManagedImage(suiteErrorIconDescriptor); + suiteFailIcon = Activator.createManagedImage(suiteFailIconDescriptor); + suiteRunningIcon = Activator.createManagedImage(suiteRunningIconDescriptor); + } + + @Override + public Object[] getElements(Object inputElement) { + return model.getElements(); + } + + @Override + public Object[] getChildren(Object parentElement) { + return model.getChildren(parentElement); + } + + @Override + public Object getParent(Object element) { + return model.getParent(element); + } + + @Override + public boolean hasChildren(Object element) { + return model.hasChildren(element); + } + + @Override + public StyledString getStyledText(Object element) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getText(Object element) { + return model.getText(element); + } + + @Override + public Image getImage(Object element) { + return model.getImage(element); + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + if (newInput != null) { + if (!(newInput instanceof Resource)) + throw new IllegalArgumentException(newInput.toString()); + model.updateInput((Resource)newInput); + } + } + + public STSTestSuiteModel getModel() { + return model; + } + +} diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/TestsUIUtils.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/TestsUIUtils.java new file mode 100644 index 000000000..c6bd1c287 --- /dev/null +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/TestsUIUtils.java @@ -0,0 +1,23 @@ +package org.simantics.tests.modelled.ui; + +import java.io.IOException; + +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.ui.workbench.e4.E4WorkbenchUtils; + +public class TestsUIUtils { + + private TestsUIUtils() { + } + + public static void runSTSTestAction(Resource test) throws DatabaseException, IOException { + MPart part = E4WorkbenchUtils.getMPartById(STSTestRunnerView.ID); + E4WorkbenchUtils.openAndShowPart(part); + Object obj = part.getObject(); + STSTestRunnerView view = (STSTestRunnerView) obj; + view.currentTest(test); + view.execute(); + } +} diff --git a/bundles/org.simantics.tests.modelled/.classpath b/bundles/org.simantics.tests.modelled/.classpath new file mode 100644 index 000000000..b862a296d --- /dev/null +++ b/bundles/org.simantics.tests.modelled/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/org.simantics.tests.modelled/.project b/bundles/org.simantics.tests.modelled/.project new file mode 100644 index 000000000..ca98d6690 --- /dev/null +++ b/bundles/org.simantics.tests.modelled/.project @@ -0,0 +1,28 @@ + + + org.simantics.tests.modelled + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/org.simantics.tests.modelled/.settings/org.eclipse.jdt.core.prefs b/bundles/org.simantics.tests.modelled/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..295926d96 --- /dev/null +++ b/bundles/org.simantics.tests.modelled/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/org.simantics.tests.modelled/META-INF/MANIFEST.MF b/bundles/org.simantics.tests.modelled/META-INF/MANIFEST.MF new file mode 100644 index 000000000..662bca7b7 --- /dev/null +++ b/bundles/org.simantics.tests.modelled/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Simantics Modelled Tests +Bundle-SymbolicName: org.simantics.tests.modelled +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.simantics.tests.modelled.Activator +Require-Bundle: org.eclipse.core.runtime, + org.simantics.db, + org.simantics.db.common, + org.simantics.tests.modelled.ontology, + org.simantics.scl.osgi, + org.simantics, + org.simantics.scl.compiler +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ActivationPolicy: lazy +Export-Package: org.simantics.tests.modelled diff --git a/bundles/org.simantics.tests.modelled/build.properties b/bundles/org.simantics.tests.modelled/build.properties new file mode 100644 index 000000000..0a709036f --- /dev/null +++ b/bundles/org.simantics.tests.modelled/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + scl/ +src.includes = scl/ diff --git a/bundles/org.simantics.tests.modelled/scl/Simantics/Tests.scl b/bundles/org.simantics.tests.modelled/scl/Simantics/Tests.scl new file mode 100644 index 000000000..fb2d4bfc0 --- /dev/null +++ b/bundles/org.simantics.tests.modelled/scl/Simantics/Tests.scl @@ -0,0 +1,5 @@ +include "Simantics/DB" + +importJava "org.simantics.tests.TestsGraphUtils" where + createSTSTest :: Resource -> Resource + createSTSSuite :: Resource -> () diff --git a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/Activator.java b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/Activator.java new file mode 100644 index 000000000..4cc9eceec --- /dev/null +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/Activator.java @@ -0,0 +1,30 @@ +package org.simantics.tests.modelled; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator { + + private static BundleContext context; + + static BundleContext getContext() { + return context; + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext bundleContext) throws Exception { + Activator.context = bundleContext; + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext bundleContext) throws Exception { + Activator.context = null; + } + +} diff --git a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/TestsGraphUtils.java b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/TestsGraphUtils.java new file mode 100644 index 000000000..cf5c8e365 --- /dev/null +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/TestsGraphUtils.java @@ -0,0 +1,98 @@ +package org.simantics.tests.modelled; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.regex.Pattern; + +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.scl.compiler.commands.CommandSession; +import org.simantics.scl.compiler.commands.TestScriptExecutor; +import org.simantics.scl.compiler.module.Module; +import org.simantics.scl.compiler.module.coverage.CombinedCoverage; +import org.simantics.scl.compiler.module.coverage.CoverageUtils; +import org.simantics.scl.compiler.module.options.ModuleCompilationOptions; +import org.simantics.scl.compiler.module.options.ModuleCompilationOptionsAdvisor; +import org.simantics.scl.compiler.module.repository.ModuleRepository; +import org.simantics.scl.compiler.runtime.RuntimeModule; +import org.simantics.scl.osgi.SCLOsgi; +import org.simantics.scl.runtime.reporting.SCLReportingHandler; +import org.simantics.tests.modelled.ontology.TestsResource; + +public class TestsGraphUtils { + + private static final String STS_TEST_PREFIX = "STSTest"; + private static final String STS_SUITE_PREFIX = "STSSuite"; + + private TestsGraphUtils() {} + + public static Resource createSTSTest(WriteGraph graph, Resource parent) throws DatabaseException { + String name = NameUtils.findFreshEscapedName(graph, STS_TEST_PREFIX, parent); + Resource stsTest = graph.newResource(); + + Layer0 L0 = Layer0.getInstance(graph); + TestsResource TESTS = TestsResource.getInstance(graph); + + graph.claim(parent, L0.ConsistsOf, L0.PartOf, stsTest); + graph.claim(stsTest, L0.InstanceOf, TESTS.STSTest); + graph.claimLiteral(stsTest, L0.HasName, name, Bindings.STRING); + graph.claimLiteral(stsTest, TESTS.STSTest_definition, "", Bindings.STRING); + return stsTest; + } + + public static Resource createSTSSuite(WriteGraph graph, Resource parent) throws DatabaseException { + String name = NameUtils.findFreshEscapedName(graph, STS_SUITE_PREFIX, parent); + Resource stsSuite = graph.newResource(); + + Layer0 L0 = Layer0.getInstance(graph); + TestsResource TESTS = TestsResource.getInstance(graph); + + graph.claim(parent, L0.ConsistsOf, L0.PartOf, stsSuite); + graph.claim(stsSuite, L0.InstanceOf, TESTS.STSSuite); + graph.claimLiteral(stsSuite, L0.HasName, name, Bindings.STRING); + return stsSuite; + } + + public static CombinedCoverage runSTSTestDefinition(String definition, List moduleNameFilters, SCLReportingHandler handler) throws IOException { + +// ModuleRepository repo = SCLOsgi.MODULE_REPOSITORY; + ModuleRepository repo = new ModuleRepository(SCLOsgi.SOURCE_REPOSITORY); + repo.setAdvisor(new ModuleCompilationOptionsAdvisor() { + + @Override + public ModuleCompilationOptions getOptions(String moduleName) { + boolean coverage = false; + for (Pattern p : moduleNameFilters) { + if (p.matcher(moduleName.toLowerCase()).find()) { + coverage = true; + break; + } + } + return new ModuleCompilationOptions(coverage); + } + }); + + CommandSession session = new CommandSession(repo, handler); + TestScriptExecutor executor = new TestScriptExecutor(session, new BufferedReader(new StringReader(definition)), handler); + try { + executor.execute(); + } catch (Throwable t) { + t.printStackTrace(); + } + Collection runtimeModules = session.getRuntimeEnvironment().getRuntimeModules(); + List modules = new ArrayList<>(runtimeModules.size()); + for (RuntimeModule module : runtimeModules) { + modules.add(module.getModule()); + } + CombinedCoverage coverage = CoverageUtils.getCoverage(modules); + return coverage; + } +} diff --git a/features/org.simantics.tests.modelled.feature/.project b/features/org.simantics.tests.modelled.feature/.project new file mode 100644 index 000000000..e3686c8a7 --- /dev/null +++ b/features/org.simantics.tests.modelled.feature/.project @@ -0,0 +1,17 @@ + + + org.simantics.tests.modelled.feature + + + + + + org.eclipse.pde.FeatureBuilder + + + + + + org.eclipse.pde.FeatureNature + + diff --git a/features/org.simantics.tests.modelled.feature/build.properties b/features/org.simantics.tests.modelled.feature/build.properties new file mode 100644 index 000000000..82ab19c62 --- /dev/null +++ b/features/org.simantics.tests.modelled.feature/build.properties @@ -0,0 +1 @@ +bin.includes = feature.xml diff --git a/features/org.simantics.tests.modelled.feature/feature.xml b/features/org.simantics.tests.modelled.feature/feature.xml new file mode 100644 index 000000000..780d5dc6c --- /dev/null +++ b/features/org.simantics.tests.modelled.feature/feature.xml @@ -0,0 +1,34 @@ + + + + + [Enter Feature Description here.] + + + + [Enter Copyright Description here.] + + + + [Enter License Description here.] + + + + + + + diff --git a/features/org.simantics.tests.modelled.ui.feature/.project b/features/org.simantics.tests.modelled.ui.feature/.project new file mode 100644 index 000000000..92afdc93d --- /dev/null +++ b/features/org.simantics.tests.modelled.ui.feature/.project @@ -0,0 +1,17 @@ + + + org.simantics.tests.modelled.ui.feature + + + + + + org.eclipse.pde.FeatureBuilder + + + + + + org.eclipse.pde.FeatureNature + + diff --git a/features/org.simantics.tests.modelled.ui.feature/build.properties b/features/org.simantics.tests.modelled.ui.feature/build.properties new file mode 100644 index 000000000..82ab19c62 --- /dev/null +++ b/features/org.simantics.tests.modelled.ui.feature/build.properties @@ -0,0 +1 @@ +bin.includes = feature.xml diff --git a/features/org.simantics.tests.modelled.ui.feature/feature.xml b/features/org.simantics.tests.modelled.ui.feature/feature.xml new file mode 100644 index 000000000..ae4c6981d --- /dev/null +++ b/features/org.simantics.tests.modelled.ui.feature/feature.xml @@ -0,0 +1,33 @@ + + + + + [Enter Feature Description here.] + + + + [Enter Copyright Description here.] + + + + [Enter License Description here.] + + + + + + +