*******************************************************************************/
package org.simantics.db.layer0.migration;
-import gnu.trove.set.hash.TIntHashSet;
-
import java.util.ArrayList;
import org.eclipse.core.runtime.IProgressMonitor;
import org.simantics.graph.refactoring.GraphRefactoringUtils;
import org.simantics.graph.refactoring.MappingSpecification;
import org.simantics.graph.refactoring.MappingSpecification.MappingRule;
+import org.simantics.graph.representation.Identity;
+import org.simantics.graph.representation.Internal;
import org.simantics.graph.representation.TransferableGraph1;
import org.simantics.graph.store.IdentityStore;
import org.simantics.layer0.Layer0;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import gnu.trove.set.hash.TIntHashSet;
public class NamespaceMigrationStep implements MigrationStep {
-
+ private static final Logger LOGGER = LoggerFactory.getLogger(NamespaceMigrationStep.class);
+
final ArrayList<MappingRule> rules;
public NamespaceMigrationStep(ReadGraph graph, Resource step) throws DatabaseException {
if(fromURI != null && toURI != null)
rules.add(new MappingRule(fromURI, toURI));
else
- System.err.println("Namespace migration uri formation error: base " + base + " from " + from + " to " + to);
+ LOGGER.error("Namespace migration uri formation error: base " + base + " from " + from + " to " + to);
}
}
}
try {
MappingSpecification mappingSpec = new MappingSpecification(rules);
boolean fixed = GraphRefactoringUtils.fixIncorrectRoot(tg.identities);
- System.err.println("fixed=" + fixed);
+ LOGGER.info("fixed=" + fixed);
IdentityStore idStore = TransferableGraphConversion.extractIdentities(tg);
- idStore.printChildMap();
+ // Mark internal identities new
+ for(Identity id : tg.identities)
+ if(id.definition instanceof Internal)
+ idStore.markNew(id.resource);
+// idStore.printChildMap();
// System.err.println("ids: " + idStore);
// System.err.println("rc: " + tg.resourceCount);
// System.err.println("idStore: " + idStore.toArray().length);
if(fixed)
GraphRefactoringUtils.unfixIncorrectRoot(tg.identities);
- System.err.println("rc2: " + tg.resourceCount);
+ LOGGER.info("rc2: " + tg.resourceCount);
// System.err.println("idStore2: " + idStore.toArray().length);
} catch (GraphRefactoringException e) {
gnu.trove3;bundle-version="3.0.3",
org.simantics.layer0;bundle-version="1.0.0",
org.slf4j.api;bundle-version="1.7.2"
-Export-Package: org.simantics.graph.db,
- org.simantics.graph.db.old
+Export-Package: org.simantics.graph.db
Bundle-Vendor: VTT Technical Research Centre of Finland
+++ /dev/null
-package org.simantics.graph.db.old;
-
-import java.util.Set;
-
-import org.simantics.db.exception.DatabaseException;
-
-public class OldMissingDependencyException extends DatabaseException {
-
- private static final long serialVersionUID = -1579450497603555931L;
-
- private final OldTransferableGraphImportProcess1 process;
-
- public OldMissingDependencyException(OldTransferableGraphImportProcess1 process) {
- super(createMessage(process));
- this.process = process;
- }
-
- private static String createMessage(OldTransferableGraphImportProcess1 process) {
- StringBuilder b = new StringBuilder();
- b.append("The following references were not found:\r\n");
- for(String missing : process.missingExternals) {
- b.append(" -" + missing + "\r\n");
- }
- return b.toString();
- }
-
- public Set<String> getMissingURIs() {
- return process.missingExternals;
- }
-
-}
+++ /dev/null
-package org.simantics.graph.db.old;
-
-import java.io.DataOutput;
-import java.io.DataOutputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.simantics.databoard.Bindings;
-import org.simantics.databoard.adapter.AdaptException;
-import org.simantics.databoard.binding.mutable.Variant;
-import org.simantics.db.ReadGraph;
-import org.simantics.db.Resource;
-import org.simantics.db.VirtualGraph;
-import org.simantics.db.WriteOnlyGraph;
-import org.simantics.db.common.WriteBindings;
-import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
-import org.simantics.db.common.uri.UnescapedChildMapOfResource;
-import org.simantics.db.common.utils.Logger;
-import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.exception.ResourceNotFoundException;
-import org.simantics.db.service.ClusterBuilder;
-import org.simantics.db.service.ClusterBuilder.ResourceHandle;
-import org.simantics.db.service.SerialisationSupport;
-import org.simantics.db.service.TransferableGraphSupport;
-import org.simantics.graph.db.CoreInitialization;
-import org.simantics.graph.db.IImportAdvisor;
-import org.simantics.graph.representation.Extensions;
-import org.simantics.graph.representation.External;
-import org.simantics.graph.representation.Identity;
-import org.simantics.graph.representation.IdentityDefinition;
-import org.simantics.graph.representation.Internal;
-import org.simantics.graph.representation.Optional;
-import org.simantics.graph.representation.Root;
-import org.simantics.graph.representation.TransferableGraphUtils;
-import org.simantics.graph.representation.old.OldTransferableGraph1;
-import org.simantics.graph.representation.old.OldValue1;
-
-public class OldTransferableGraphImportProcess1 {
-
- public static String LOG_FILE = "transferableGraphs.log";
- final static private boolean LOG = false;
-
- static DataOutput log;
-
- static {
-
- if (LOG) {
- try {
- FileOutputStream stream = new FileOutputStream(LOG_FILE);
- log = new DataOutputStream(stream);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
-
- }
-
- private static void log(String line) {
- if (LOG) {
- try {
- log.writeUTF(line + "\n");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
- OldTransferableGraph1 tg;
- IImportAdvisor advisor;
-
- Resource[] resources;
- ResourceHandle[] handles;
-
- Set<String> missingExternals = new HashSet<String>();
-
- // Builtins
- Resource RootLibrary;
- Resource String;
- Resource Library;
-
- Resource InstanceOf;
- Resource ConsistsOf;
- Resource PartOf;
- Resource HasName;
- Resource NameOf;
-
- public OldTransferableGraphImportProcess1(OldTransferableGraph1 tg, IImportAdvisor advisor) {
- this.tg = tg;
- this.advisor = advisor;
- /*System.out.println("Transferable graph identities:");
- for(Identity id : tg.identities) {
- if(id.definition instanceof Internal) {
- Internal def = (Internal)id.definition;
- System.out.println(" internal " + def.name);
- }
- else if(id.definition instanceof External) {
- External def = (External)id.definition;
- System.out.println(" external " + def.name);
- }
- }*/
- }
-
- public void findBuiltins(WriteOnlyGraph g) throws DatabaseException {
- RootLibrary = g.getBuiltin("http:/");
- String = g.getBuiltin(CoreInitialization.LAYER0 + "String");
- Library = g.getBuiltin(CoreInitialization.LAYER0 + "Library");
- InstanceOf = g.getBuiltin(CoreInitialization.LAYER0 + "InstanceOf");
- ConsistsOf = g.getBuiltin(CoreInitialization.LAYER0 + "ConsistsOf");
- PartOf = g.getBuiltin(CoreInitialization.LAYER0 + "PartOf");
- HasName = g.getBuiltin(CoreInitialization.LAYER0 + "HasName");
- NameOf = g.getBuiltin(CoreInitialization.LAYER0 + "NameOf");
- }
-
- public void findBuiltins(ReadGraph g) throws DatabaseException {
- RootLibrary = g.getBuiltin("http:/");
- String = g.getBuiltin(CoreInitialization.LAYER0 + "String");
- Library = g.getBuiltin(CoreInitialization.LAYER0 + "Library");
- InstanceOf = g.getBuiltin(CoreInitialization.LAYER0 + "InstanceOf");
- ConsistsOf = g.getBuiltin(CoreInitialization.LAYER0 + "ConsistsOf");
- PartOf = g.getBuiltin(CoreInitialization.LAYER0 + "PartOf");
- HasName = g.getBuiltin(CoreInitialization.LAYER0 + "HasName");
- NameOf = g.getBuiltin(CoreInitialization.LAYER0 + "NameOf");
- }
-
- /* Preparation that is used when the core is empty.
- */
- void initialPrepare(WriteOnlyGraph graph) throws DatabaseException {
- findBuiltins(graph);
-
- resources = new Resource[tg.resourceCount];
-
- int Root = -1;
- int SimanticsDomain = -1;
- int Layer0 = -1;
-
- for(Identity identity : tg.identities) {
- if(identity.definition instanceof Internal) {
- Internal def = (Internal)identity.definition;
- Resource res = null;
- if(def.parent == Layer0) {
- try {
- res = graph.getBuiltin(CoreInitialization.LAYER0 + def.name);
- } catch(ResourceNotFoundException e) {
- }
- }
- else if(def.parent == SimanticsDomain) {
- if(def.name.equals("Layer0-1.1"))
- Layer0 = identity.resource;
- }
- else if(def.parent == Root) {
- if(def.name.equals("www.simantics.org"))
- SimanticsDomain = identity.resource;
- }
-
- if(res == null)
- res = createChild(graph, resources[def.parent], def.name);
- else
- createChild(graph, res, resources[def.parent], def.name);
- resources[identity.resource] = res;
- }
- else if(identity.definition instanceof Root) {
- Root = identity.resource;
- resources[identity.resource] = RootLibrary;
- }
- }
- }
-
- void addMissing(String external) {
- Set<String> removals = new HashSet<String>();
- for(String ext : missingExternals) if(ext.startsWith(external)) return;
- for(String ext : missingExternals) if(external.startsWith(ext)) removals.add(ext);
- missingExternals.removeAll(removals);
- missingExternals.add(external);
- }
-
- void prepare(ReadGraph graph) throws DatabaseException {
- findBuiltins(graph);
-
- Resource[] resources = new Resource[tg.resourceCount];
-
- for(Identity identity : tg.identities) {
- IdentityDefinition definition = identity.definition;
- if(definition instanceof External) {
- External def = (External)definition;
- if(def.parent == -1) {
- resources[identity.resource] = RootLibrary;
- } else {
- if("@inverse".equals(def.name)) {
- Resource parent = resources[def.parent];
- Resource child = graph.getInverse(parent);
- resources[identity.resource] = child;
- } else {
- Resource parent = resources[def.parent];
- // TODO: escape should be removed when names become well-behaving
- if(parent != null) {
- Resource child = graph
- .syncRequest(new UnescapedChildMapOfResource(parent),
- new TransientCacheAsyncListener<Map<String, Resource>>())
- .get(def.name);
- if(child == null) {
- addMissing(graph.getURI(parent) + "/" + def.name);
- }
- resources[identity.resource] = child;
- } else {
- addMissing(TransferableGraphUtils.getURI(tg.resourceCount, tg.identities, def.parent) + "/" + def.name);
- }
- }
- }
- }
- else if(definition instanceof Internal) {
- // Do not do anything for now
- }
- else if(definition instanceof Root) {
- Root root = (Root)definition;
- if(root.name.equals(""))
- resources[identity.resource] = RootLibrary;
- else
- advisor.analyzeRoot(graph, root);
- }
- else if(definition instanceof Optional) {
- External def = (External)definition;
- Resource parent = resources[def.parent];
- if(parent != null)
- resources[identity.resource] =
- graph.syncRequest(new UnescapedChildMapOfResource(parent)).get(def.name);
- }
- }
-
- this.resources = resources;
-
- if(!missingExternals.isEmpty()) throw new OldMissingDependencyException(this);
-
- }
-
- Resource createChild(WriteOnlyGraph graph, Resource parent, String name) throws DatabaseException {
- Resource child = graph.newResource();
- graph.claim(parent, ConsistsOf, PartOf, child);
- Resource nameResource = graph.newResource();
- graph.claim(nameResource, InstanceOf, null, String);
- graph.claimValue(nameResource, name, WriteBindings.STRING);
- graph.claim(child, HasName, NameOf, nameResource);
- return child;
- }
-
- void createChild(WriteOnlyGraph graph, Resource child, Resource parent, String name) throws DatabaseException {
- graph.claim(parent, ConsistsOf, PartOf, child);
- Resource nameResource = graph.newResource();
- graph.claim(nameResource, InstanceOf, null, String);
- graph.claimValue(nameResource, name, WriteBindings.STRING);
- graph.claim(child, HasName, NameOf, nameResource);
- }
-
- int[] getClustering() {
- Variant v = tg.extensions.get(Extensions.CLUSTERING);
- if(v == null) return null;
- try {
- return (int[])v.getValue(Bindings.INT_ARRAY);
- } catch (AdaptException e) {
- Logger.defaultLogError(e);
- return null;
- }
- }
-
- void write(WriteOnlyGraph graph) throws DatabaseException {
-
- Resource[] resources = this.resources;
-
- this.handles = new ResourceHandle[resources.length];
-
- ResourceHandle[] handles = this.handles;
-
- int[] clustering = getClustering();
-
- // Internal identities
- for(Identity identity : tg.identities) {
- IdentityDefinition definition = identity.definition;
- if(resources[identity.resource] != null)
- continue;
- if(definition instanceof External) {
- // Already done everything
- }
- else if(definition instanceof Internal) {
- Internal def = (Internal)definition;
- resources[identity.resource] =
- createChild(graph, resources[def.parent], def.name);
- }
- else if(definition instanceof Root) {
- Root root = (Root)definition;
- resources[identity.resource] = advisor.createRoot(graph, root);
- }
- else if(definition instanceof Optional) {
- Optional def = (Optional)definition;
- Resource child = createChild(graph, resources[def.parent], def.name);
- graph.claim(child, InstanceOf, null, Library); // ???
- resources[identity.resource] = child;
- }
- }
-
- ClusterBuilder builder = graph.getService(ClusterBuilder.class);
- SerialisationSupport ss = graph.getService(SerialisationSupport.class);
-
- if(clustering != null) {
-
- int i = 0;
- for(int c : clustering) {
- builder.newCluster();
- for(int r=0;r<c;r++, i++)
- if(resources[i] == null)
- handles[i] = builder.newResource();
- else
- handles[i] = builder.resource(resources[i]);
-
- }
-
- for(;i<resources.length;++i)
- if(resources[i] == null)
- handles[i] = builder.newResource();
- else
- handles[i] = builder.resource(resources[i]);
-
- } else {
-
- // Create blank resources
- for(int i=0;i<resources.length;++i)
- if(resources[i] == null)
- handles[i] = builder.newResource();
- else
- handles[i] = builder.resource(resources[i]);
-
- }
-
- // Write statements
- int[] statements = tg.statements;
-
- int internals = tg.resourceCount - tg.identities.length;
-
- for(int i=0;i<statements.length;i+=4) {
-
- int sub = statements[i];
- int pred = statements[i+1];
- int inv = statements[i+2];
- int obj = statements[i+3];
-
- ResourceHandle subject = handles[sub];
- ResourceHandle predicate = handles[pred];
- ResourceHandle object = handles[obj];
-
- if(resources[sub] == null) {
- subject.addStatement(graph, predicate, object);
- } else {
- graph.claim(
- handles[sub].resource(ss),
- handles[pred].resource(ss),
- null, handles[obj].resource(ss));
- }
-
- if(inv >= 0) {
-
- if(resources[obj] == null) {
- ResourceHandle inverse = handles[inv];
- object.addStatement(graph, inverse, subject);
- } else {
- graph.claim(
- handles[obj].resource(ss),
- handles[inv].resource(ss),
- null, handles[sub].resource(ss));
- }
-
- }
-
- if(LOG) {
- log("[STATEMENT] " + resources[statements[i]].getResourceId() + ", " + resources[statements[i+1]].getResourceId() + ", " + resources[statements[i+3]].getResourceId());
- }
-
- }
-
- // Write values
- TransferableGraphSupport tgSupport =
- graph.getService(TransferableGraphSupport.class);
- VirtualGraph vg = graph.getProvider();
- for(OldValue1 value : tg.values) {
- int file = value.resource & 0x80000000;
- int resource = value.resource & 0x7FFFFFFF;
- if (file != 0) {
- graph.claimValue(handles[resource].resource(ss), value.value, Bindings.BYTE_ARRAY);
- } else {
- if(resource < internals) {
- handles[resource].addValue(graph, value.value);
- } else {
- tgSupport.setValue(graph, handles[resource].resource(ss), vg, value.value);
- }
- //tgSupport.setValue(resources[resource], vg, value.value);
- }
- }
- }
-
- void write2(WriteOnlyGraph graph) throws DatabaseException {
- Resource[] resources = this.resources;
-
- // Internal identities
- for(Identity identity : tg.identities) {
- IdentityDefinition definition = identity.definition;
- if(resources[identity.resource] != null)
- continue;
- if(definition instanceof External) {
- // Already done everything
- }
- else if(definition instanceof Internal) {
- Internal def = (Internal)definition;
- resources[identity.resource] =
- createChild(graph, resources[def.parent], def.name);
- }
- else if(definition instanceof Root) {
- Root root = (Root)definition;
- resources[identity.resource] = advisor.createRoot(graph, root);
- }
- else if(definition instanceof Optional) {
- Optional def = (Optional)definition;
- Resource child = createChild(graph, resources[def.parent], def.name);
- graph.claim(child, InstanceOf, null, Library); // ???
- resources[identity.resource] = child;
- }
- }
-
- // Create blank resources
- for(int i=0;i<resources.length;++i)
- if(resources[i] == null)
- resources[i] = graph.newResource();
-
- // Write statements
- int[] statements = tg.statements;
-
- for(int i=0;i<statements.length;i+=4) {
- int inv = statements[i+2];
- graph.claim(
- resources[statements[i]],
- resources[statements[i+1]],
- inv < 0 ? null : resources[inv],
- resources[statements[i+3]]
- );
- if(LOG) {
- log("[STATEMENT] " + resources[statements[i]].getResourceId() + ", " + resources[statements[i+1]].getResourceId() + ", " + resources[statements[i+3]].getResourceId());
- }
- }
-
- // Write values
- TransferableGraphSupport tgSupport =
- graph.getService(TransferableGraphSupport.class);
- VirtualGraph vg = graph.getProvider();
- for(OldValue1 value : tg.values) {
- int file = value.resource & 0x80000000;
- int resource = value.resource & 0x7FFFFFFF;
- if (file != 0) {
- graph.claimValue(resources[resource], value.value, Bindings.BYTE_ARRAY);
- } else {
- tgSupport.setValue(graph, resources[resource], vg, value.value);
- }
- }
- }
-
-
- public long[] getResourceIds(SerialisationSupport serializer) throws DatabaseException {
- final int count = resources.length;
- long[] resourceIds = new long[count];
- if(handles != null) {
- for(int i=0;i<count;++i)
- resourceIds[i] = serializer.getRandomAccessId(handles[i].resource(serializer));
- } else {
- for(int i=0;i<count;++i)
- resourceIds[i] = serializer.getRandomAccessId(resources[i]);
- }
- return resourceIds;
- }
-
-}
\ No newline at end of file
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
- * in Industry THTH ry.
- * 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:
- * VTT Technical Research Centre of Finland - initial API and implementation
- *******************************************************************************/
-package org.simantics.graph.db.old;
-
-import java.util.function.BiFunction;
-
-import org.simantics.db.ReadGraph;
-import org.simantics.db.Session;
-import org.simantics.db.WriteGraph;
-import org.simantics.db.WriteOnlyGraph;
-import org.simantics.db.common.request.ReadRequest;
-import org.simantics.db.common.request.WriteOnlyRequest;
-import org.simantics.db.exception.DatabaseException;
-import org.simantics.graph.db.IImportAdvisor;
-import org.simantics.graph.db.ImportAdvisor;
-import org.simantics.graph.db.TransferableGraphException;
-import org.simantics.graph.representation.old.OldTransferableGraph1;
-
-public class OldTransferableGraphs {
-
- public static void importGraph1(Session session, final OldTransferableGraph1 tg, IImportAdvisor advisor, final BiFunction<WriteOnlyGraph, OldTransferableGraphImportProcess1, Boolean> callback) throws DatabaseException, TransferableGraphException {
- final OldTransferableGraphImportProcess1 process = new OldTransferableGraphImportProcess1(tg,
- advisor == null ? new ImportAdvisor() : advisor);
- session.syncRequest(new ReadRequest() {
- @Override
- public void run(ReadGraph graph) throws DatabaseException {
- process.prepare(graph);
- }
- });
- session.syncRequest(new WriteOnlyRequest() {
- @Override
- public void perform(WriteOnlyGraph graph) throws DatabaseException {
- process.write(graph);
- if(callback != null)
- callback.apply(graph, process);
- }
- });
- }
-
- public static void importGraph1(WriteGraph graph, final OldTransferableGraph1 tg, IImportAdvisor advisor) throws DatabaseException {
- final OldTransferableGraphImportProcess1 process = new OldTransferableGraphImportProcess1(tg,
- advisor == null ? new ImportAdvisor() : advisor);
- process.prepare(graph);
- process.write2(graph);
-
- }
-
-}
org.simantics.graph.query,
org.simantics.graph.refactoring,
org.simantics.graph.representation,
- org.simantics.graph.representation.old,
org.simantics.graph.store,
org.simantics.graph.tests.conversion,
org.simantics.graph.utils
Bundle-ClassPath: .
Bundle-Vendor: VTT Technical Research Centre of Finland
+Import-Package: org.slf4j
import org.simantics.graph.representation.Root;
import org.simantics.graph.representation.TransferableGraph1;
import org.simantics.graph.representation.Value;
-import org.simantics.graph.representation.old.OldTransferableGraph1;
import org.simantics.graph.store.GraphStore;
import org.simantics.graph.store.IStore;
import org.simantics.graph.store.IdentityStore;
return extractIdentities(tg.resourceCount, tg.identities);
}
- public static IdentityStore extractIdentities(OldTransferableGraph1 tg) {
- return extractIdentities(tg.resourceCount, tg.identities);
- }
-
private static IdentityStore extractIdentities(int resourceCount, Identity[] ids) {
IdentityStore identities = new IdentityStore();
identities.setResourceCount(resourceCount);
package org.simantics.graph.refactoring;
-import java.util.ArrayList;
import java.util.Arrays;
import org.simantics.databoard.util.URIStringUtils;
import org.simantics.graph.refactoring.MappingSpecification.MappingRule;
import org.simantics.graph.representation.External;
import org.simantics.graph.representation.Identity;
-import org.simantics.graph.representation.IdentityDefinition;
import org.simantics.graph.representation.Internal;
-import org.simantics.graph.representation.Optional;
import org.simantics.graph.representation.Root;
import org.simantics.graph.representation.TransferableGraph1;
import org.simantics.graph.representation.TransferableGraphUtils;
-import org.simantics.graph.representation.old.OldTransferableGraph1;
-import org.simantics.graph.representation.old.OldValue1;
import org.simantics.graph.store.GraphStore;
import org.simantics.graph.store.IdentityStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import gnu.trove.list.array.TIntArrayList;
-import gnu.trove.map.hash.TIntIntHashMap;
import gnu.trove.set.hash.TIntHashSet;
public class GraphRefactoringUtils {
-
+ private static final Logger LOGGER = LoggerFactory.getLogger(GraphRefactoringUtils.class);
/**
* Moves an external resource. Returns true if did something.
* @param parentsAffected
// Find parent id
int toParentId = ids.createPathToId(to.parent);
if(ids.hasChild(toParentId, to.name)) {
- System.err.println("refactor statements from " + from + " to " + to);
+ LOGGER.info("refactor statements from " + from + " to " + to);
//throw new GraphRefactoringException("External reference to " + to + " already exists.");
int toId = ids.pathToId(to);
int[] statements = tg.statements;
if(!(rule.to instanceof PathChild))
throw new GraphRefactoringException("Invalid target URI " + rule.to);
if(!moveExternal(tg, ids, rule.from, (PathChild)rule.to, parentsAffected))
- System.err.println("Didn't find " + rule.from);
+ LOGGER.warn("Didn't find " + rule.from);
}
}
}
}
- public static void compactify(OldTransferableGraph1 tg,
- TIntHashSet removed) {
- // Filter removed set
- for(Identity id : tg.identities) {
- IdentityDefinition def = id.definition;
- if(def instanceof Root)
- removed.remove(id.resource);
- else if(def instanceof External)
- removed.remove(((External)def).parent);
- else if(def instanceof Internal)
- removed.remove(((Internal)def).parent);
- else if(def instanceof Optional)
- removed.remove(((Optional)def).parent);
- }
- for(int r : tg.statements)
- removed.remove(r);
- for(OldValue1 value : tg.values)
- removed.remove(value.resource);
-
- // Compactify
- if(!removed.isEmpty()) {
- // create map
- int resourceCount = tg.resourceCount;
- int[] map = new int[resourceCount];
- for(int i=0;i<resourceCount;++i)
- map[i] = i;
- for(int r : removed.toArray()) {
- map[--resourceCount] = map[r];
- }
-
- // map
- ArrayList<Identity> newIdentities = new ArrayList<Identity>(tg.identities.length);
- for(Identity id : tg.identities) {
- if(removed.contains(id.resource))
- continue;
- else
- newIdentities.add(id);
- id.resource = map[id.resource];
- IdentityDefinition def = id.definition;
- if(def instanceof External) {
- External d = (External)def;
- d.parent = map[d.parent];
- }
- else if(def instanceof Internal) {
- External d = (External)def;
- d.parent = map[d.parent];
- }
- else if(def instanceof Optional) {
- External d = (External)def;
- d.parent = map[d.parent];
- }
- }
- tg.identities = newIdentities.toArray(new Identity[newIdentities.size()]);
- int[] statements = tg.statements;
- for(int i=0;i<statements.length;++i) {
- int r = statements[i];
- if(r >= 0)
- statements[i] = map[r];
- }
- for(OldValue1 value : tg.values)
- value.resource = map[value.resource];
- tg.resourceCount = resourceCount;
- }
- }
-
}
+++ /dev/null
-package org.simantics.graph.refactoring;
-
-import gnu.trove.map.hash.THashMap;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-
-import org.simantics.databoard.Files;
-import org.simantics.graph.query.TransferableGraphConversion;
-import org.simantics.graph.representation.old.OldTransferableGraph1;
-import org.simantics.graph.store.IdentityStore;
-import org.simantics.graph.store.IdentityStore.ConsistsOf;
-
-public class PrintReferencesTool {
-
- public static void main(String[] args) throws Exception {
- print(new File(args[0]));
- }
-
- public static void print(File input) throws IOException {
- OldTransferableGraph1 tg = (OldTransferableGraph1)
- Files.readFile(input, OldTransferableGraph1.BINDING);
- GraphRefactoringUtils.fixIncorrectRoot(tg.identities);
- IdentityStore idStore = TransferableGraphConversion.extractIdentities(tg);
- printExternals(idStore, idStore.getRoot(""), 0);
- }
-
- private static void printExternals(IdentityStore idStore, int cur, int indentation) {
- THashMap<String, ConsistsOf> map = idStore.getChildMap(cur);
- if(map == null)
- return;
- ArrayList<String> names = new ArrayList<String>(map.keySet());
- Collections.sort(names);
- for(String name : names) {
- ConsistsOf co = map.get(name);
- if(!idStore.isNewResource(co.child)) {
- for(int i=0;i<indentation;++i)
- System.out.print(" ");
- System.out.println(name);
- printExternals(idStore, co.child, indentation+1);
- }
- }
- }
-
-}
+++ /dev/null
-package org.simantics.graph.refactoring;
-
-import gnu.trove.set.hash.TIntHashSet;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.ArrayList;
-
-import org.simantics.databoard.Files;
-import org.simantics.graph.query.Path;
-import org.simantics.graph.query.TransferableGraphConversion;
-import org.simantics.graph.query.UriUtils;
-import org.simantics.graph.refactoring.MappingSpecification.MappingRule;
-import org.simantics.graph.representation.old.OldTransferableGraph1;
-import org.simantics.graph.store.IdentityStore;
-
-
-public class RefactoringTool {
-
- public static void main(String[] args) throws Exception {
- if(args.length != 3)
- System.out.println("Usage: java " + RefactoringTool.class.getCanonicalName() + " mappingSpec input.tg ouput.tg");
- refactor(new File(args[0]), new File(args[1]), new File(args[2]));
- }
-
- public static void refactor(File mappingSpec, File input, File output) throws IOException, GraphRefactoringException {
- if(!mappingSpec.exists()) {
- System.out.println("Mapping specification " + mappingSpec + " does not exist.");
- return;
- }
- if(!input.exists()) {
- System.out.println("Input tg " + input + " does not exist.");
- return;
- }
-
- MappingSpecification spec = readMappingSpec(mappingSpec);
-
- // Refactor old format
- OldTransferableGraph1 tg = (OldTransferableGraph1)
- Files.readFile(input, OldTransferableGraph1.BINDING);
- boolean fixed = GraphRefactoringUtils.fixIncorrectRoot(tg.identities);
- IdentityStore idStore = TransferableGraphConversion.extractIdentities(tg);
- TIntHashSet parentsAffected = new TIntHashSet();
- GraphRefactoringUtils.refactor(null, idStore, spec, parentsAffected);
- tg.resourceCount = idStore.getResourceCount();
- tg.identities = idStore.toArray();
- GraphRefactoringUtils.compactify(tg, parentsAffected);
- if(fixed)
- GraphRefactoringUtils.unfixIncorrectRoot(tg.identities);
-
- // Write to output file
- Files.writeFile(output, OldTransferableGraph1.BINDING, tg);
- }
-
- private static MappingSpecification readMappingSpec(File mappingSpec) throws IOException {
- BufferedReader reader = new BufferedReader(new FileReader(mappingSpec));
- ArrayList<MappingRule> rules = new ArrayList<MappingRule>();
- while(true) {
- String line = reader.readLine();
- if(line == null)
- break;
- line = line.trim();
- if(line.isEmpty())
- continue;
- String[] parts = line.trim().split(" ");
- if(parts.length != 2)
- throw new IOException("Invalid mapping spec format. Every non-empty line should contain two URIs.");
-
- Path from = UriUtils.uriToPath(parts[0]);
- Path to = UriUtils.uriToPath(parts[1]);
-
- rules.add(new MappingRule(from, to));
- }
- reader.close();
-
- return new MappingSpecification(rules);
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
- * in Industry THTH ry.
- * 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:
- * VTT Technical Research Centre of Finland - initial API and implementation
- *******************************************************************************/
-package org.simantics.graph.representation.old;
-
-import java.util.TreeMap;
-
-import org.simantics.databoard.Bindings;
-import org.simantics.databoard.binding.Binding;
-import org.simantics.databoard.binding.mutable.Variant;
-import org.simantics.databoard.serialization.Serializer;
-import org.simantics.graph.representation.External;
-import org.simantics.graph.representation.Identity;
-import org.simantics.graph.representation.Internal;
-import org.simantics.graph.representation.Root;
-import org.simantics.graph.tests.conversion.TransferableGraph0;
-
-
-/**
- * Transferable graph datatype.
- * See <a href="https://www.simantics.org/wiki/index.php/Graph_exchange_format">specification</a>.
- * @author Hannu Niemist�
- *
- * @deprecated superceded by {@link TransferableGraph0}
- */
-@Deprecated
-public class OldTransferableGraph1 {
- public static Binding BINDING = Bindings.getBindingUnchecked(OldTransferableGraph1.class);
- public static Serializer SERIALIZER = Bindings.getSerializerUnchecked(BINDING);
-
- public int resourceCount;
- public Identity[] identities;
- public int[] statements;
- public OldValue1[] values;
- public TreeMap<String, Variant> extensions;
-
- public OldTransferableGraph1() {}
-
- public OldTransferableGraph1(int resourceCount, Identity[] identities,
- int[] statements, OldValue1[] values) {
- this(resourceCount, identities, statements, values,
- new TreeMap<String, Variant>());
- }
-
- public OldTransferableGraph1(int resourceCount, Identity[] identities,
- int[] statements, OldValue1[] values, TreeMap<String, Variant> extensions) {
- this.resourceCount = resourceCount;
- this.identities = identities;
- this.statements = statements;
- this.values = values;
- this.extensions = extensions;
- }
-
- public void print() {
- System.out.println("Identities");
- for(Identity id : identities) {
- System.out.print(" " + id.resource + " = ");
- if(id.definition instanceof Root) {
- Root def = (Root)id.definition;
- System.out.println("ROOT(" + def.name + ")");
- }
- else if(id.definition instanceof External) {
- External def = (External)id.definition;
- System.out.println("EXTERNAL(" + def.parent + ", " + def.name + ")");
- }
- else if(id.definition instanceof Internal) {
- Internal def = (Internal)id.definition;
- System.out.println("INTERNAL(" + def.parent + ", " + def.name + ")");
- }
- }
- System.out.println("Statements:");
- for(int i=0;i<statements.length;i+=4)
- System.out.println(" " +
- statements[i] + " " +
- statements[i+1] + " " +
- statements[i+2] + " " +
- statements[i+3]
- );
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
- * in Industry THTH ry.
- * 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:
- * VTT Technical Research Centre of Finland - initial API and implementation
- *******************************************************************************/
-package org.simantics.graph.representation.old;
-
-
-/**
- * A part of TransferableGraph data structure.
- * Says that the resource has a literal with given value.
- * @author Hannu Niemist�
- */
-public class OldValue1 {
- public int resource;
- public byte[] value;
-
- public OldValue1() {
- }
-
- public OldValue1(int resource, byte[] value) {
- this.resource = resource;
- this.value = value;
- }
-}
+++ /dev/null
-package org.simantics.graph.tests.refactoring;
-
-import java.io.File;
-import java.net.URLDecoder;
-
-import org.simantics.graph.refactoring.PrintReferencesTool;
-import org.simantics.graph.refactoring.RefactoringTool;
-
-public class TestRefactoring {
-
- public static void main(String[] args) throws Exception {
- File dir = new File(URLDecoder.decode(TestRefactoring.class.getResource(".").getPath(), "UTF-8")).getAbsoluteFile();// new File(TestRefactoring.class.getResource(".").getFile());
- System.out.println(dir);
- File input = new File(dir, "xor5.aprosSymbol");
- File mappingSpec = new File(dir, "mappingSpec.txt");
- File output = new File(dir, "xor5_refactored.aprosSymbol");
-
- System.out.println("-- Before refactoring");
- System.out.println("------------------------------------------");
- PrintReferencesTool.print(input);
-
- RefactoringTool.refactor(mappingSpec, input, output);
-
- System.out.println("-- After refactoring");
- System.out.println("------------------------------------------");
- PrintReferencesTool.print(output);
- }
-
-}
+++ /dev/null
-package org.simantics.graph.tests.refactoring;
-
-import java.io.File;
-import java.net.URLDecoder;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.simantics.graph.refactoring.RefactoringTool;
-
-public class TestRefactoring2 {
-
- public static void main(String[] args) throws Exception {
- File dir = new File(URLDecoder.decode(TestRefactoring2.class.getResource(".").getPath(), "UTF-8")).getAbsoluteFile();// new File(TestRefactoring.class.getResource(".").getFile());
- System.out.println(dir);
- File allFiles[] = dir.listFiles();
- List<File> inputFiles = new ArrayList<File>();
- List<File> outputFiles = new ArrayList<File>();
- String ext = ".aprosSymbol";
- File outDir = new File(dir,"out");
- if (!outDir.exists())
- outDir.mkdir();
- for (File f: allFiles) {
- if (!f.isFile())
- continue;
- if (!f.getName().endsWith(ext))
- continue;
- inputFiles.add(f);
- String outputName = f.getName();
- outputFiles.add(new File(outDir,outputName));
- }
-
- File mappingSpec = new File(dir, "mappingSpec.txt");
- for (int i = 0; i < inputFiles.size() ; i++) {
-
- File input = inputFiles.get(i);
- File output = outputFiles.get(i);
-
- System.out.println(input + " -> " + output);
-
- RefactoringTool.refactor(mappingSpec, input, output);
- }
- }
-
-}
+++ /dev/null
-http://www.apros.fi/AprosStatic-6.0 http://www.apros.fi/Combustion/Configuration-6.0
-http://www.apros.fi/AprosDiagram-6.0/Terminals http://www.apros.fi/Apros-6.1/Terminals
-http://www.apros.fi/AprosDiagram-6.0/Relations http://www.apros.fi/Combustion/Diagram-6.0/Relations
-http://www.apros.fi/AprosDiagram-6.0/Symbols http://www.apros.fi/Combustion/Diagram-6.0/Symbols
-http://www.apros.fi/AprosDiagram-6.0/AnalogSignalOutputRelation http://www.apros.fi/Combustion/Diagram-6.0/AnalogSignalOutputRelation
-http://www.apros.fi/AprosDiagram-6.0/BinarySignalOutputRelation http://www.apros.fi/Combustion/Diagram-6.0/BinarySignalOutputRelation
\ No newline at end of file
importJava "java.lang.System" where
@JavaName "getProperty"
- getSystemProperty :: String -> String
+ getSystemProperty :: String -> Maybe String
importJava "org.simantics.modeling.LifeCycleContext" where
data LifeCycleContext
}
@Override
public void removeListener(UpdateListener listener) {
- listener = null;
+ this.listener = null;
}
@Override
public boolean isDisposed() {
private final CommandSession session;
private final BufferedReader reader;
private final SCLReportingHandler handler;
+ private boolean ignorePrints;
public TestScriptExecutor(CommandSession session, BufferedReader reader, SCLReportingHandler handler) {
+ this(session, reader, handler, false);
+ }
+
+ public TestScriptExecutor(CommandSession session, BufferedReader reader, SCLReportingHandler handler, boolean ignorePrints) {
this.session = session;
this.reader = reader;
this.handler = handler == null ? SCLReportingHandler.DEFAULT : handler;
+ this.ignorePrints = ignorePrints;
}
public void execute() throws IOException {
@Override
public void print(String text) {
handler.print(text);
- actualResponse.append(text).append('\n');
+ if (!ignorePrints)
+ actualResponse.append(text).append('\n');
}
@Override
import org.cojen.classfile.TypeDesc;
import org.osgi.service.component.annotations.Component;
+import org.simantics.scl.compiler.commands.CommandSession;
import org.simantics.scl.compiler.common.names.Name;
import org.simantics.scl.compiler.constants.JavaMethod;
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
@Override
public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) {
ConcreteModule module = context.getCompilationContext().module;
+ String identifier;
+ if (module != null)
+ identifier = module.getName().replaceAll("/", ".");
+ else
+ identifier = CommandSession.class.getName();
apply.set(new ELiteral(javaMethod), new Expression[] {
- new EExternalConstant(LoggerFactory.getLogger(module.getName().replaceAll("/", ".")), Logger),
+ new EExternalConstant(LoggerFactory.getLogger(identifier), Logger),
apply.parameters[0]
});
return apply;
package org.simantics.scl.compiler.internal.codegen.ssa.exits;
import java.util.ArrayList;
+import java.util.Arrays;
import org.objectweb.asm.Label;
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.Types;
+import gnu.trove.map.hash.TIntObjectHashMap;
+
public class Switch extends SSAExit implements ValRefBinder {
ValRef scrutinee;
int defaultId;
for(defaultId=0;defaultId<branches.length-1&&branches[defaultId].constructor!=null;++defaultId);
int[] values = new int[defaultId];
- Label[] labels = new Label[defaultId];
Cont[] continuations = new Cont[defaultId+1];
+ TIntObjectHashMap<Label> labelMap = new TIntObjectHashMap<Label>(defaultId);
for(int i=0;i<defaultId;++i) {
- values[i] = ((IntegerConstant)branches[i].constructor).getValue();
+ int value = ((IntegerConstant)branches[i].constructor).getValue();
+ values[i] = value;
Cont cont = branches[i].cont.getBinding();
- labels[i] = mb.getLabel(cont);
+ labelMap.put(value, mb.getLabel(cont));
continuations[i] = cont;
}
+ Arrays.sort(values);
+ Label[] labels = new Label[defaultId];
+ for(int i=0;i<defaultId;++i)
+ labels[i] = labelMap.get(values[i]);
Label defaultLabel;
{
Cont cont = branches[defaultId].cont.getBinding();
package org.simantics.scl.compiler.internal.codegen.utils;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.simantics.scl.runtime.function.FunctionImpl1;
Object ret = method.invoke(null, p0);
return returnsVoid ? Tuple0.INSTANCE : ret;
} catch (ReflectiveOperationException e) {
+ if (e instanceof InvocationTargetException)
+ throw new RuntimeException(e.getCause());
throw new RuntimeException(e);
}
}
}
public static void resetCoverage(Collection<Module> modules) {
- modules.forEach(module -> resetCoverage(module));
+ modules.forEach(CoverageUtils::resetCoverage);
}
public static void resetCoverage(Module module) {
package org.simantics.scl.osgi;
+import java.util.ArrayList;
+
+import org.simantics.scl.compiler.errors.DoesNotExist;
+import org.simantics.scl.compiler.errors.Failable;
+import org.simantics.scl.compiler.module.Module;
import org.simantics.scl.compiler.module.repository.ModuleRepository;
import org.simantics.scl.compiler.source.repository.ModuleSourceRepository;
import org.simantics.scl.compiler.testing.repository.TestRepository;
import org.simantics.scl.osgi.internal.ServiceBasedModuleSourceRepository;
import org.simantics.scl.osgi.internal.ServiceBasedTestRepository;
+import gnu.trove.procedure.TObjectProcedure;
+
public class SCLOsgi {
public static ModuleRepository MODULE_REPOSITORY = new ModuleRepository(SOURCE_REPOSITORY);
public static TestRepository TEST_REPOSITORY = new ServiceBasedTestRepository(Activator.getContext());
+
+ public static String compileAllModules() {
+ ArrayList<String> modulesWithErrors = new ArrayList<String>();
+ SCLOsgi.SOURCE_REPOSITORY.forAllModules(new TObjectProcedure<String>() {
+ @Override
+ public boolean execute(String moduleName) {
+ System.out.print(moduleName);
+ System.out.print(" - ");
+ Failable<Module> module = SCLOsgi.MODULE_REPOSITORY.getModule(moduleName);
+ if(module.didSucceed())
+ System.out.println("succeeded");
+ else if(module == DoesNotExist.INSTANCE)
+ System.out.println("does not exist"); // should not happen
+ else {
+ System.out.println("error");
+ modulesWithErrors.add(moduleName);
+ }
+ return true;
+ }
+ });
+ if(!modulesWithErrors.isEmpty()) {
+ StringBuilder b = new StringBuilder();
+ b.append("Some SCL modules failed to compile:");
+ for(String module : modulesWithErrors)
+ b.append(' ').append(module);
+ return b.toString();
+ }
+ return null;
+ }
}
--- /dev/null
+importJava "org.junit.Assert" where
+ @JavaName assertEquals
+ @private
+ assertDoublesEquals :: String -> Double -> Double -> Double -> <Proc> ()
+ @JavaName assertEquals
+ @private
+ assertLongsEquals :: String -> Long -> Long -> <Proc> ()
+
+ assertTrue :: String -> Boolean -> <Proc> ()
+ assertFalse :: String -> Boolean -> <Proc> ()
+
+class AssertEquals a where
+ assertEquals :: String -> a -> a -> <Proc> ()
+instance AssertEquals Long where
+ assertEquals = assertLongsEquals
+
+class AssertEqualsTolerance a where
+ assertEqualsTolerance :: String -> a -> a -> a -> <Proc> ()
+instance AssertEqualsTolerance Double where
+ assertEqualsTolerance = assertDoublesEquals
public class SCLModuleEditor2 extends TextEditor {
private boolean disposed = false;
- ResourceManager resourceManager;
+ protected ResourceManager resourceManager;
public SCLModuleEditor2() {
super();
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
+Require-Bundle: org.simantics.layer0,
+ org.simantics.selectionview.ontology;bundle-version="1.2.0",
+ org.simantics.modeling.ontology;bundle-version="1.2.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.simantics.tests.modelled.ontology
Bundle-Vendor: Semantum Oy
L0 = <http://www.simantics.org/Layer0-1.1>
-
+SEL = <http://www.simantics.org/SelectionView-1.2>
+MOD = <http://www.simantics.org/Modeling-1.2>
TESTS = <http://www.simantics.org/Tests-1.0> : L0.Ontology
@L0.new
L0.SCLModule.definition _ : L0.String
@L0.loadString "scl/SCLMain.scl"
+TESTS.STSTest.definition <R L0.HasProperty : L0.TotalFunction : SEL.GenericParameterType
+ L0.HasRange L0.String
+ L0.HasLabel "Test definition"
+
+TESTS.STSTest.executionPriority <R L0.HasProperty : L0.TotalFunction : SEL.GenericParameterType
+ L0.HasRange L0.Integer
+ L0.HasLabel "Execution priority"
+
+TESTS.ignore <R L0.HasProperty : L0.TotalFunction : SEL.GenericParameterType
+ L0.HasRange L0.Boolean
+ L0.HasLabel "Ignore"
+
+TESTS.ignoreReason <R L0.HasProperty : L0.TotalFunction : SEL.GenericParameterType
+ L0.HasRange L0.String
+ L0.HasLabel "Ignore reason"
+
TESTS.STSTest <T L0.Entity
- >-- TESTS.STSTest.definition --> L0.String <R L0.HasProperty : L0.TotalFunction
- >-- TESTS.STSTest.executionPriority --> L0.Integer <R L0.HasProperty : L0.TotalFunction
@L0.assert TESTS.STSTest.definition ""
@L0.assert TESTS.STSTest.executionPriority -1
+ @L0.assert TESTS.ignore false
+ @L0.assert TESTS.ignoreReason ""
+
+TESTS.STSTest : MOD.TypeWithChangeInformation
+TESTS.STSTest : L0.TypeWithIdentifier
TESTS.STSSuite <T L0.Entity
- >-- TESTS.STSSuite.moduleNameFilter --> L0.String <R L0.HasProperty : L0.TotalFunction
- @L0.assert TESTS.STSSuite.moduleNameFilter ""
\ No newline at end of file
+ >-- TESTS.STSSuite.moduleNameFilter --> L0.String <R L0.HasProperty : L0.TotalFunction : SEL.GenericParameterType
+ @L0.assert TESTS.STSSuite.moduleNameFilter ""
+ @L0.assert TESTS.ignore false
+
+TESTS.STSSuite : MOD.TypeWithChangeInformation
+TESTS.STSSuite : L0.TypeWithIdentifier
\ No newline at end of file
org.simantics.image2.ontology;bundle-version="1.2.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Vendor: Semantum Oy
+Export-Package: org.simantics.tests.modelled.ui.ontology
TestsUI.testImage : IMAGE.PngImage
@L0.loadBytes "images/test.png"
+TestsUI.testIgnoredImage : IMAGE.PngImage
+ @L0.loadBytes "images/testignored.gif"
+
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.TestImageRule : VP.ImageRule
+
MBC
- @VP.namedRelationChildRule TestsUI.Contributions.STSSuites L0.Entity L0.ConsistsOf TESTS.STSSuite
- @VP.namedConstantImageRule TestsUI.Contributions.SuiteImage TESTS.STSSuite TestsUI.testSuiteImage
- @VP.namedRelationChildRule TestsUI.Contributions.STSTests L0.Entity L0.ConsistsOf TESTS.STSTest
- @VP.namedConstantImageRule TestsUI.Contributions.TestImage TESTS.STSTest TestsUI.testImage
+ @VP.namedRelationChildRule TestsUI.Contributions.STSSuites L0.Entity L0.ConsistsOf TESTS.STSSuite
+ @VP.namedConstantImageRule TestsUI.Contributions.SuiteImage TESTS.STSSuite TestsUI.testSuiteImage
+ @VP.namedRelationChildRule TestsUI.Contributions.STSTests L0.Entity L0.ConsistsOf TESTS.STSTest
+ @VP.customImageRule TESTS.STSTest MBC.TestImageRule
MBC
VP.BrowseContext.HasVisualsContribution _ : VP.VisualsContribution
org.simantics.tests.modelled;bundle-version="1.0.0",
org.eclipse.e4.ui.model.workbench,
org.simantics.scl.osgi,
- org.simantics.browsing.ui.model
+ org.simantics.browsing.ui.model,
+ org.slf4j.api
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-Vendor: Semantum Oy
<?xml version="1.0" encoding="UTF-8"?>
<adapters>
-
- <target interface="org.simantics.browsing.ui.model.visuals.VisualsRule">
- <resource
- uri="http://www.simantics.org/TestsUI-0.0/BrowseContext/STSSuiteSorterRule"
- class="org.simantics.tests.modelled.ui.STSSuiteSorterRule" />
- </target>
-
+ <target interface="org.simantics.browsing.ui.model.visuals.VisualsRule">
+ <resource
+ uri="http://www.simantics.org/TestsUI-0.0/BrowseContext/STSSuiteSorterRule"
+ class="org.simantics.tests.modelled.ui.STSSuiteSorterRule" />
+ <resource
+ uri="http://www.simantics.org/TestsUI-0.0/BrowseContext/TestImageRule"
+ class="org.simantics.tests.modelled.ui.rules.TestImageRule">
+ <graph/>
+ </resource>
+ </target>
</adapters>
\ No newline at end of file
</extension>
<extension
point="org.simantics.ui.resourceEditorAdapter">
- <adapter
- label="STS Test Editor"
- priority="1"
- editorId="org.simantics.tests.ui.stsTestEditor"
- type_uris="http://www.simantics.org/Tests-1.0/STSTest">
- </adapter>
+ <adapterClass
+ class="org.simantics.tests.modelled.ui.STSEditorAdapter"
+ id="org.simantics.tests.ui.stsTestEditor"
+ priority="10">
+ </adapterClass>
+ </extension>
+ <extension
+ point="org.eclipse.ui.elementFactories">
+ <factory
+ class="org.simantics.tests.modelled.ui.STSEditorInputFactory"
+ id="org.simantics.tests.modelled.ui.stseditor.inputFactory">
+ </factory>
</extension>
<extension
point="org.eclipse.ui.views">
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Resource;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
- for (Image image : imagesToDispose)
- image.dispose();
+ imagesToDispose.forEach(Resource::dispose);
super.stop(context);
}
--- /dev/null
+package org.simantics.tests.modelled.ui;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.simantics.Simantics;
+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.tests.modelled.ontology.TestsResource;
+import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter;
+import org.simantics.ui.workbench.editor.EditorAdapter;
+import org.simantics.utils.ui.workbench.WorkbenchUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class STSEditorAdapter extends AbstractResourceEditorAdapter implements EditorAdapter {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(STSEditorAdapter.class);
+
+ public STSEditorAdapter() {
+ super("SCL Module Editor", null, 20);
+ }
+
+ @Override
+ public boolean canHandle(ReadGraph g, Object input)
+ throws DatabaseException {
+ if(input instanceof IStructuredSelection)
+ input = ((IStructuredSelection)input).getFirstElement();
+ if(!(input instanceof Resource)) {
+ if(input instanceof IAdaptable) {
+ input = ((IAdaptable)input).getAdapter(Resource.class);
+ if(input == null)
+ return false;
+ }
+ else
+ return false;
+ }
+ Resource resource = (Resource)input;
+ return g.isInstanceOf(resource, TestsResource.getInstance(g).STSTest);
+ }
+
+ protected void openEditor(Resource input) throws Exception {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ if(page == null)
+ return;
+ Simantics.getSession().asyncRequest(new ReadRequest() {
+ @Override
+ public void run(ReadGraph graph) throws DatabaseException {
+ String uri = graph.getURI(input);
+ PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ WorkbenchUtils.openEditor("org.simantics.tests.ui.stsTestEditor", new STSTestEditorInput(uri));
+ } catch (PartInitException e) {
+ LOGGER.error("Could not initialize part", e);
+ }
+ }
+ });
+ }
+ });
+ }
+
+}
--- /dev/null
+package org.simantics.tests.modelled.ui;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.ui.IElementFactory;
+import org.eclipse.ui.IMemento;
+
+public class STSEditorInputFactory implements IElementFactory {
+
+ @Override
+ public IAdaptable createElement(IMemento memento) {
+ return new STSTestEditorInput(memento.getTextData());
+ }
+
+}
package org.simantics.tests.modelled.ui;
-import org.simantics.modeling.ui.componentTypeEditor.SCLModuleEditor;
-import org.simantics.scl.ui.editor.SCLSourceViewerConfigurationNew;
+import org.simantics.scl.ui.editor2.SCLModuleEditor2;
+
+public class STSTestEditor extends SCLModuleEditor2 {
-public class STSTestEditor extends SCLModuleEditor {
-
-
-
- @Override
- protected void preInitialize() {
- SCLSourceViewerConfigurationNew sourceViewerConfiguration = new SCLSourceViewerConfigurationNew(resourceManager);
- setDocumentProvider(new STSTestEditorDocumentProvider(sourceViewerConfiguration));
- setSourceViewerConfiguration(sourceViewerConfiguration);
- }
}
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.ui.workbench.ResourceEditorInput;
import org.simantics.utils.logging.TimeLogger;
+@Deprecated
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;
--- /dev/null
+package org.simantics.tests.modelled.ui;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+
+import org.eclipse.ui.IPersistableElement;
+import org.simantics.Simantics;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.UnaryRead;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.scl.compiler.errors.Failable;
+import org.simantics.scl.compiler.module.Module;
+import org.simantics.scl.compiler.module.options.ModuleCompilationOptions;
+import org.simantics.scl.compiler.module.repository.ModuleRepository;
+import org.simantics.scl.compiler.module.repository.UpdateListener;
+import org.simantics.scl.compiler.source.ModuleSource;
+import org.simantics.scl.compiler.source.TextualModuleSource;
+import org.simantics.scl.ui.editor2.StandardSCLModuleEditorInput;
+import org.simantics.tests.modelled.ontology.TestsResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class STSTestEditorInput extends StandardSCLModuleEditorInput {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(STSTestEditorInput.class);
+
+ public STSTestEditorInput(String moduleName) {
+ super(moduleName);
+ }
+
+ @Override
+ public boolean exists() {
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T getAdapter(Class<T> adapter) {
+ if(adapter.equals(ModuleSource.class))
+ try {
+ return (T) Simantics.getSession().syncRequest(new ReadSTSModuleSource(getModuleName()));
+ } catch (DatabaseException e) {
+ e.printStackTrace();
+ }
+ if(adapter.equals(IPersistableElement.class))
+ return (T)this;
+ return null;
+ }
+
+
+ private static class STSTextualModuleSource extends TextualModuleSource {
+
+ private String moduleText;
+
+ public STSTextualModuleSource(String stsModuleURI, String moduleText) {
+ super(stsModuleURI);
+ this.moduleText = moduleText;
+ }
+
+ @Override
+ public void update(String newSourceText) {
+ try {
+ Simantics.getSession().syncRequest(new WriteSTSModuleSource(getModuleName(), newSourceText));
+ } catch (DatabaseException e) {
+ LOGGER.error("", e);
+ }
+ }
+
+ @Override
+ public Failable<Module> compileModule(ModuleRepository environment, UpdateListener listener, ModuleCompilationOptions options) {
+ return super.compileModule(environment, listener, options);
+ }
+
+ @Override
+ public boolean isUpdateable() {
+ return true;
+ }
+
+ @Override
+ protected Reader getSourceReader(UpdateListener listener) throws IOException {
+ return new StringReader(moduleText);
+ }
+ }
+
+ static class ReadSTSModuleSource extends UnaryRead<String, ModuleSource> {
+
+ public ReadSTSModuleSource(String moduleName) {
+ super(moduleName);
+ }
+
+ @Override
+ public ModuleSource perform(ReadGraph graph) throws DatabaseException {
+ Resource moduleResource = graph.getPossibleResource(parameter);
+ if(moduleResource == null)
+ return null;
+ TestsResource TESTS = TestsResource.getInstance(graph);
+ if(!graph.isInstanceOf(moduleResource, TESTS.STSTest))
+ return null;
+ String text = graph.getRelatedValue(moduleResource, TESTS.STSTest_definition);
+ return new STSTextualModuleSource(parameter, text);
+ }
+ }
+
+ static class WriteSTSModuleSource extends WriteRequest {
+ private final String moduleURI;
+ private final String sourceText;
+
+ public WriteSTSModuleSource(String moduleURI, String sourceText) {
+ this.moduleURI = moduleURI;
+ this.sourceText = sourceText;
+ }
+
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ Resource moduleResource = graph.getPossibleResource(moduleURI);
+ if(moduleResource == null)
+ return;
+ TestsResource TESTS = TestsResource.getInstance(graph);
+ if(!graph.isInstanceOf(moduleResource, TESTS.STSTest))
+ return;
+ graph.claimLiteral(moduleResource, TESTS.STSTest_definition, sourceText);
+ }
+ }
+
+ @Override
+ public String getFactoryId() {
+ return "org.simantics.tests.modelled.ui.stseditor.inputFactory";
+ }
+
+}
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 java.util.stream.Collectors;
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.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;
-import org.simantics.utils.strings.AlphanumComparator;
+import org.simantics.tests.modelled.utils.ModelledSTSSuite;
+import org.simantics.tests.modelled.utils.ModelledSTSTest;
+import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
public class STSTestSuiteModel {
static class STSTest {
- private final Resource test;
+ private final ModelledSTSTest 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<String> output = new ArrayList<>();
- private CombinedCoverage coverage;
- private int priority;
- public STSTest(Resource test, STSSuite parent, String definition, String name, int executionPrioprity) {
+ public STSTest(ModelledSTSTest test, STSSuite parent) {
this.test = test;
this.parent = parent;
- this.definition = definition;
- this.name = name;
- this.priority = executionPrioprity;
}
public String getName() {
- return name;
+ return test.getName();
}
public String getLabel() {
StringBuilder sb = new StringBuilder();
- sb.append(name);
+ sb.append(getName());
if (executed || failed)
sb.append(" (").append(duration).append(" ms)");
return sb.toString();
}
public String getDefinition() {
- return definition;
+ return test.getCode();
}
public STSSuite getParent() {
public void execute(CommandSession session) {
isRunning = true;
- TestScriptExecutor executor = new TestScriptExecutor(session, new BufferedReader(new StringReader(definition)), new AbstractSCLReportingHandler() {
+ TestScriptExecutor executor = new TestScriptExecutor(session, new BufferedReader(new StringReader(getDefinition())), new AbstractSCLReportingHandler() {
@Override
public void print(String text) {
public void printError(String error) {
appendOutput(error + "\n");
}
- });
+ }, true);
long start = System.currentTimeMillis();
try {
if (parent != null)
}
public void setCoverage(CombinedCoverage coverage) {
- this.coverage = coverage;
+ test.setCoverage(coverage);
}
public CombinedCoverage getCoverage() {
- return coverage;
+ return test.getCoverage();
}
-
+
+ public int getPriority() {
+ return test.getPriority();
+ }
+
@Override
public String toString() {
- return name + " [priority=" + priority + ", executed=" + executed + ", duration=" + duration + "]";
+ return getName() + " [priority=" + getPriority() + ", executed=" + executed + ", duration=" + duration + "]";
+ }
+
+ public boolean isIgnored() {
+ return test.isIgnored();
}
}
static class STSSuite {
-
- private List<Pattern> moduleNameFilterPatterns = new ArrayList<>();
- private final Resource suite;
- private final String name;
+
+ private ModelledSTSSuite suite;
private STSTest[] children;
private int startedCount;
private int errorCount;
private int failureCount;
- private CoverageBuilder coverageBuilder;
+ public int ignoredCount;
- public STSSuite(Resource suite, String name, String moduleNameFilter) {
+ public STSSuite(ModelledSTSSuite suite) {
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() {
+ if (children == null)
+ children = suite.getSortedChildren().stream().map(modelledTest -> new STSTest(modelledTest, this)).collect(Collectors.toList()).toArray(new STSTest[suite.getChildren().size()]);
return children;
}
public String getName() {
- return name;
+ return suite.getName();
}
public String getLabel() {
StringBuilder sb = new StringBuilder();
- sb.append(name);
+ sb.append(getName());
long totalTime = 0;
- if (children != null) {
- for (STSTest test : children) {
+ if (getChildren() != null) {
+ for (STSTest test : getChildren()) {
if (test.executed || test.failed) {
totalTime += test.duration;
}
}
public boolean isRunning() {
- boolean running = false;
- if (children != null) {
- for (STSTest test: children) {
+ if (getChildren() != null) {
+ for (STSTest test: getChildren()) {
if (test.isRunning) {
- running = true;
- break;
+ return true;
}
}
}
- return running;
+ return false;
}
public boolean executed() {
- boolean executed = true;
- if (children != null) {
- for (STSTest test: children) {
+ if (getChildren() != null) {
+ for (STSTest test: getChildren()) {
if (!test.executed) {
- executed = false;
- break;
+ return false;
}
}
}
- return executed;
+ return true;
}
public boolean failed() {
- boolean failed = false;
- if (children != null) {
- for (STSTest test: children) {
+ if (getChildren() != null) {
+ for (STSTest test: getChildren()) {
if (test.failed) {
- failed = true;
- break;
+ return true;
}
}
}
- return failed;
- }
-
- public void addCoverage(List<Module> modules) {
- if (coverageBuilder == null) {
- coverageBuilder = new CoverageBuilder();
- }
- for (Module module : modules)
- coverageBuilder.addCoverage(module, true);
+ return false;
}
public CombinedCoverage getCoverage() {
- if (coverageBuilder == null)
- return null;
- return coverageBuilder.getCoverage();
+ return suite.getCoverage();
}
}
@Override
public ModuleCompilationOptions getOptions(String moduleName) {
boolean coverage = false;
- for (Pattern p : suite.moduleNameFilterPatterns) {
+ for (Pattern p : suite.suite.getModuleNameFilterPatterns()) {
if (p.matcher(moduleName.toLowerCase()).find()) {
coverage = true;
break;
}
private void executeSuite(CommandSession session) {
-
for (STSTest test : suite.getChildren()) {
- test.execute(session);
-
- Collection<RuntimeModule> runtimeModules = session.getRuntimeEnvironment().getRuntimeModules();
- List<Module> 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());
- }
- }
+ if (test.isIgnored()) {
+ testExecuted();
+ test.getParent().ignoredCount++;
+ continue;
}
- test.setCoverage(CoverageUtils.getCoverage(modules));
- suite.addCoverage(modules);
-
- CoverageUtils.resetCoverage(modules);
-
+ test.execute(session);
+ STSSuiteTestCollector.setSuiteCoverage(test.test, suite.suite, session);
testExecuted();
}
-
}
-
+
private void executeTest(CommandSession session) {
-
test.execute(session);
testExecuted();
-
- Collection<RuntimeModule> runtimeModules = session.getRuntimeEnvironment().getRuntimeModules();
- List<Module> modules = new ArrayList<>(runtimeModules.size());
- for (RuntimeModule module : runtimeModules) {
- modules.add(module.getModule());
- }
- test.setCoverage(CoverageUtils.getCoverage(modules));
-
- CoverageUtils.resetCoverage(modules);
-
+ STSSuiteTestCollector.setTestCoverage(test.test, session);
}
-
public boolean hasChildren(Object element) {
if (element instanceof STSTest) {
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);
+ test = new STSTest(STSSuiteTestCollector.toModelledTest(graph, root), null);
} 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<STSTest> 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;
- else if (o1.priority > o2.priority)
- return 1;
- else return AlphanumComparator.COMPARATOR.compare(o1.name, o2.name);
- });
- suite.children(tests.toArray(new STSTest[tests.size()]));
+ List<ModelledSTSTest> tests = new ArrayList<>();
+ for (Resource test : graph.getObjects(root, L0.ConsistsOf))
+ tests.add(STSSuiteTestCollector.toModelledTest(graph, test));
+
+ suite = new STSSuite(STSSuiteTestCollector.toModelledSuite(graph, root, tests));
} else {
throw new IllegalArgumentException(root.toString());
}
}
public int getIgnoredCount() {
+ if (suite != null)
+ return suite.ignoredCount;
return 0;
}
--- /dev/null
+package org.simantics.tests.modelled.ui.adapters;
+
+import java.util.Map;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.simantics.browsing.ui.model.images.ImageRule;
+import org.simantics.browsing.ui.model.tests.Test;
+import org.simantics.browsing.ui.model.visuals.VisualsRule;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.tests.modelled.ontology.TestsResource;
+
+public enum IsTestIgnored implements Test, VisualsRule, ImageRule {
+
+ INSTANCE;
+
+ public static IsTestIgnored get() {
+ return INSTANCE;
+ }
+
+ @Override
+ public boolean isCompatible(Class<?> contentType) {
+ return Resource.class.equals(contentType);
+ }
+
+ @Override
+ public boolean test(ReadGraph graph, Object content) throws DatabaseException {
+ if (content instanceof Resource) {
+ Resource resource = (Resource) content;
+ TestsResource TESTS = TestsResource.getInstance(graph);
+ return graph.getPossibleRelatedValue2(resource, TESTS.ignore, Bindings.BOOLEAN);
+ }
+ return false;
+ }
+
+ @Override
+ public Map<String, ImageDescriptor> getImage(ReadGraph graph, Object content) throws DatabaseException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
--- /dev/null
+package org.simantics.tests.modelled.ui.rules;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.simantics.browsing.ui.common.ColumnKeys;
+import org.simantics.browsing.ui.model.images.ImageRule;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.tests.modelled.ontology.TestsResource;
+import org.simantics.tests.modelled.ui.ontology.TestsUIResource;
+
+public class TestImageRule implements ImageRule {
+
+ private ImageDescriptor testImage;
+ private ImageDescriptor testIgnoredImage;
+
+ public TestImageRule(ReadGraph graph) throws DatabaseException {
+ TestsUIResource TESTS = TestsUIResource.getInstance(graph);
+ testImage = graph.adapt(TESTS.testImage, ImageDescriptor.class);
+ testIgnoredImage = graph.adapt(TESTS.testIgnoredImage, ImageDescriptor.class);
+ }
+
+ @Override
+ public boolean isCompatible(Class<?> contentType) {
+ return Resource.class.equals(contentType);
+ }
+
+ @Override
+ public Map<String, ImageDescriptor> getImage(ReadGraph graph, Object content) throws DatabaseException {
+ Resource resource = (Resource) content;
+ Boolean ignored = graph.getPossibleRelatedValue2(resource, TestsResource.getInstance(graph).ignore,
+ Bindings.BOOLEAN);
+ if (ignored != null && ignored)
+ return Collections.singletonMap(ColumnKeys.SINGLE, testIgnoredImage);
+ return Collections.singletonMap(ColumnKeys.SINGLE, testImage);
+ }
+
+}
org.simantics.scl.osgi,
org.simantics,
org.junit,
- org.simantics.modeling;bundle-version="1.1.1"
+ org.simantics.modeling;bundle-version="1.1.1",
+ org.slf4j.api,
+ org.simantics.db.testing
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: org.simantics.tests.modelled,
- org.simantics.tests.modelled.junit
+ org.simantics.tests.modelled.junit,
+ org.simantics.tests.modelled.junit.v2,
+ org.simantics.tests.modelled.utils
Bundle-Vendor: Semantum Oy
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ in Industry THTH ry.
+ 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:
+ VTT Technical Research Centre of Finland - initial API and implementation
+ Semantum Oy - issue #4190
+ -->
+<adapters>
+ <target
+ interface="org.simantics.db.layer0.adapter.PasteHandler">
+ <type
+ uri="http://www.simantics.org/Tests-1.0/STSTest"
+ class="org.simantics.db.layer0.adapter.impl.DefaultPasteHandler">
+ <this />
+ </type>
+ <type
+ uri="http://www.simantics.org/Tests-1.0/STSSuite"
+ class="org.simantics.db.layer0.adapter.impl.DefaultPasteHandler">
+ <this />
+ </type>
+ </target>
+</adapters>
output.. = bin/
bin.includes = META-INF/,\
.,\
- scl/
+ scl/,\
+ adapters.xml
src.includes = scl/
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.ParentRunner;
+@Deprecated
public abstract class RuntimeSTSRunner<T extends Runner> extends ParentRunner<T> {
public RuntimeSTSRunner(Class<?> testClass) throws Exception {
import org.simantics.scl.compiler.commands.CommandSession;
import org.simantics.scl.osgi.SCLOsgi;
+@Deprecated
public class RuntimeSTSSuiteRunner extends RuntimeSTSRunner<RuntimeSTSTestRunner> {
private final List<RuntimeSTSTestRunner> children = new ArrayList<>();
testChildren.forEach(c -> c.setCommandSession(session));
children.addAll(testChildren);
}
+
+ @Override
+ protected boolean isIgnored(RuntimeSTSTestRunner child) {
+ // TODO Auto-generated method stub
+ return super.isIgnored(child);
+ }
@Override
public List<RuntimeSTSTestRunner> getChildren() {
@Override
public void initialize() throws Exception {
}
-
+
@Override
public void deinitialize() throws Exception {
}
import org.simantics.scl.runtime.SCLContext;
import org.simantics.scl.runtime.reporting.SCLReportingHandler;
+@Deprecated
public class RuntimeSTSTestRunner extends Runner {
private final String name;
import org.simantics.scl.runtime.tuple.Tuple0;
import org.simantics.tests.modelled.ontology.TestsResource;
import org.simantics.utils.strings.AlphanumComparator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+@Deprecated
public class RuntimeTestCollector {
+ private static final Logger LOGGER = LoggerFactory.getLogger(RuntimeTestCollector.class);
/**
* TODO: The idea of this class was to collect all the tests from shared libraries and construct
public Collection<RuntimeSTSSuiteRunner> perform(ReadGraph graph) throws DatabaseException {
List<Resource> sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE);
-
+ if (LOGGER.isInfoEnabled())
+ LOGGER.info("Found {} shared ontologies from graph", sharedOntologies.size());
Set<RuntimeSTSSuiteRunner> suites = new HashSet<>();
TestsResource TESTS = TestsResource.getInstance(graph);
Layer0 L0 = Layer0.getInstance(graph);
for (Resource sharedOntology : sharedOntologies) {
+ if (LOGGER.isInfoEnabled())
+ LOGGER.info("Searching {} for modelled tests", graph.getURI(sharedOntology));
List<Resource> stsSuites = ModelingUtils.searchByType(graph, sharedOntology, TESTS.STSSuite);
for (Resource stsSuite : stsSuites) {
try {
--- /dev/null
+package org.simantics.tests.modelled.junit.v2;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.junit.runner.Description;
+import org.junit.runner.Result;
+import org.junit.runner.notification.RunListener;
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.ParentRunner;
+import org.junit.runners.model.InitializationError;
+import org.simantics.Simantics;
+import org.simantics.db.testing.common.AcornTests;
+import org.simantics.scl.compiler.commands.CommandSession;
+import org.simantics.scl.osgi.SCLOsgi;
+import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
+
+public class ModelledSTSRunner extends ParentRunner<ModelledSTSSuiteRunner> {
+
+ private CommandSession commandSession;
+
+ public ModelledSTSRunner(Class<?> testClass) throws Exception {
+ super(testClass);
+ initialize0();
+ }
+
+ @Override
+ protected List<ModelledSTSSuiteRunner> getChildren() {
+ return STSSuiteTestCollector.collectTests().stream().map(suite -> {
+ try {
+ return new ModelledSTSSuiteRunner(suite);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }).collect(Collectors.toList());
+ }
+
+ @Override
+ protected Description describeChild(ModelledSTSSuiteRunner child) {
+ return child.getDescription();
+ }
+
+ @Override
+ public void run(RunNotifier notifier) {
+ notifier.addListener(new RunListener() {
+
+ @Override
+ public void testRunFinished(Result result) throws Exception {
+ deinitialize0();
+ }
+ });
+ super.run(notifier);
+ }
+
+ @Override
+ protected void runChild(ModelledSTSSuiteRunner child, RunNotifier notifier) {
+ child.setCommandSesssion(commandSession);
+ child.run(notifier);
+ // TODO: Add coverage reporting to ModelledSTSRunner
+// CombinedCoverage cover = child.getCoverage();
+// CoverageBuilder b = new CoverageBuilder();
+ }
+
+ public void initialize() throws InitializationError {
+ }
+
+ public void deinitialize() throws Exception {
+ }
+
+ private void initialize0() throws Exception {
+ AcornTests.newSimanticsWorkspace(null, null);
+ this.commandSession = new CommandSession(SCLOsgi.MODULE_REPOSITORY, null);
+ initialize();
+ }
+
+ private void deinitialize0() throws Exception {
+ deinitialize();
+ Simantics.shutdown(new NullProgressMonitor());
+ }
+}
--- /dev/null
+package org.simantics.tests.modelled.junit.v2;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.junit.runner.Description;
+import org.junit.runner.notification.Failure;
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.ParentRunner;
+import org.simantics.scl.compiler.commands.CommandSession;
+import org.simantics.scl.compiler.module.coverage.CombinedCoverage;
+import org.simantics.scl.osgi.SCLOsgi;
+import org.simantics.tests.modelled.utils.ModelledSTSSuite;
+import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
+
+public class ModelledSTSSuiteRunner extends ParentRunner<ModelledSTSTestRunner> {
+
+ private final ModelledSTSSuite suite;
+ private CommandSession commandSession;
+
+ public ModelledSTSSuiteRunner(ModelledSTSSuite suite) throws Exception {
+ super(ModelledSTSSuiteRunner.class);
+ this.suite = suite;
+ }
+
+ @Override
+ protected String getName() {
+ return suite.getName();
+ }
+
+ @Override
+ protected List<ModelledSTSTestRunner> getChildren() {
+ return suite.getChildren().stream().map(test -> new ModelledSTSTestRunner(test)).collect(Collectors.toList());
+ }
+
+ @Override
+ protected Description describeChild(ModelledSTSTestRunner child) {
+ return child.getDescription();
+ }
+
+ @Override
+ protected void runChild(ModelledSTSTestRunner child, RunNotifier notifier) {
+ Description description = describeChild(child);
+ if (isIgnored(child)) {
+ notifier.fireTestIgnored(description);
+ } else {
+ notifier.fireTestStarted(description);
+ try {
+ child.run(getCommandSession());
+ notifier.fireTestFinished(description);
+ STSSuiteTestCollector.setSuiteCoverage(child.getTest(), suite, getCommandSession());
+ } catch (Throwable e) {
+ notifier.fireTestFailure(new Failure(description, e));
+ }
+ }
+ }
+
+ @Override
+ protected boolean isIgnored(ModelledSTSTestRunner child) {
+ return child.isIgnored();
+ }
+
+ public void setCommandSesssion(CommandSession commandSession) {
+ this.commandSession = commandSession;
+ }
+
+ public CommandSession getCommandSession() {
+ if (commandSession == null)
+ commandSession = new CommandSession(SCLOsgi.MODULE_REPOSITORY, null);
+ return commandSession;
+ }
+
+ public CombinedCoverage getCoverage() {
+ return suite.getCoverage();
+ }
+
+}
--- /dev/null
+package org.simantics.tests.modelled.junit.v2;
+
+import java.io.BufferedReader;
+import java.io.StringReader;
+
+import org.junit.runner.Description;
+import org.junit.runner.Runner;
+import org.junit.runner.notification.RunNotifier;
+import org.simantics.scl.compiler.commands.CommandSession;
+import org.simantics.scl.compiler.commands.TestScriptExecutor;
+import org.simantics.scl.osgi.SCLOsgi;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.reporting.SCLReportingHandler;
+import org.simantics.tests.modelled.utils.ModelledSTSTest;
+import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
+
+public class ModelledSTSTestRunner extends Runner {
+
+ private Description description;
+ private ModelledSTSTest test;
+
+ public ModelledSTSTestRunner(ModelledSTSTest test) {
+ this.test = test;
+ }
+
+ public String getName() {
+ return test.getName();
+ }
+
+ @Override
+ public Description getDescription() {
+ if (description == null)
+ description = Description.createTestDescription(ModelledSTSTestRunner.class, getName());
+ return description;
+ }
+
+ /**
+ * This method is called from ModelledSTSSuite (ParentRunner) with the same
+ * CommandSession
+ *
+ * @param session
+ */
+ public void run(CommandSession session) {
+ try (BufferedReader reader = new BufferedReader(new StringReader(test.getCode()))) {
+ SCLReportingHandler handler = (SCLReportingHandler) SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER);
+ new TestScriptExecutor(session, reader, handler, true).execute();
+ STSSuiteTestCollector.setTestCoverage(test, session);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void run(RunNotifier notifier) {
+ notifier.fireTestStarted(getDescription());
+ try {
+ run(new CommandSession(SCLOsgi.MODULE_REPOSITORY, null));
+ } finally {
+ notifier.fireTestFinished(getDescription());
+ }
+ }
+
+ public boolean isIgnored() {
+ return test.isIgnored();
+ }
+
+ public int getPriority() {
+ return test.getPriority();
+ }
+
+ public ModelledSTSTest getTest() {
+ return test;
+ }
+}
--- /dev/null
+package org.simantics.tests.modelled.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+import java.util.stream.Collectors;
+
+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.utils.strings.AlphanumComparator;
+
+public class ModelledSTSSuite {
+
+ private String name;
+ private List<ModelledSTSTest> children;
+ private String moduleNameFilter;
+ private List<Pattern> moduleNameFilterPatterns = new ArrayList<>();
+
+ private CoverageBuilder coverageBuilder;
+
+ ModelledSTSSuite(String name, List<ModelledSTSTest> children, String moduleNameFilter) {
+ this.name = name;
+ this.children = children;
+ this.moduleNameFilter = moduleNameFilter;
+ for (String s : moduleNameFilter.split(",")) {
+ try {
+ s = s.trim().replaceAll("\\*", "\\\\w*").toLowerCase();
+ getModuleNameFilterPatterns().add(Pattern.compile(s));
+ } catch (PatternSyntaxException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public List<ModelledSTSTest> getChildren() {
+ return children;
+ }
+
+ public List<ModelledSTSTest> getSortedChildren() {
+ return new ArrayList<>(children).stream().sorted(ModelledSTSSuite::compareTests).collect(Collectors.toList());
+ }
+
+ private static int compareTests(ModelledSTSTest test1, ModelledSTSTest test2) {
+ if (test1.getPriority() < test2.getPriority())
+ return -1;
+ else if (test1.getPriority() > test2.getPriority())
+ return 1;
+ else
+ return AlphanumComparator.COMPARATOR.compare(test1.getName(), test2.getName());
+ }
+
+ public String getModuleNameFilter() {
+ return moduleNameFilter;
+ }
+
+ public void addCoverage(List<Module> 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();
+ }
+
+ public List<Pattern> getModuleNameFilterPatterns() {
+ return moduleNameFilterPatterns;
+ }
+
+}
--- /dev/null
+package org.simantics.tests.modelled.utils;
+
+import org.simantics.scl.compiler.module.coverage.CombinedCoverage;
+
+public class ModelledSTSTest {
+
+ private final String name;
+ private final String code;
+ private final int priority;
+ private final boolean ignored;
+
+ private CombinedCoverage coverage;
+
+ ModelledSTSTest(String name, String code, int priority, boolean ignored) {
+ this.name = name;
+ this.code = code;
+ this.priority = priority;
+ this.ignored = ignored;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public int getPriority() {
+ return priority;
+ }
+
+ public boolean isIgnored() {
+ return ignored;
+ }
+
+ public void setCoverage(CombinedCoverage coverage) {
+ this.coverage = coverage;
+ }
+
+ public CombinedCoverage getCoverage() {
+ return coverage;
+ }
+}
--- /dev/null
+package org.simantics.tests.modelled.utils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.regex.Pattern;
+
+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.ObjectsWithType;
+import org.simantics.db.common.request.UniqueRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.layer0.Layer0;
+import org.simantics.modeling.ModelingUtils;
+import org.simantics.scl.compiler.commands.CommandSession;
+import org.simantics.scl.compiler.module.Module;
+import org.simantics.scl.compiler.module.coverage.CoverageUtils;
+import org.simantics.scl.compiler.runtime.RuntimeModule;
+import org.simantics.scl.runtime.tuple.Tuple0;
+import org.simantics.tests.modelled.ontology.TestsResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class STSSuiteTestCollector {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(STSSuiteTestCollector.class);
+
+ /**
+ * TODO: The idea of this class was to collect all the tests from shared libraries and construct
+ * JUnit tests out of them programmatically and then run them with JUnit to get results
+ *
+ */
+ private static Collection<ModelledSTSSuite> collectTestsFromGraph() {
+ try {
+ Collection<ModelledSTSSuite> suitess = Simantics.getSession().syncRequest(new UniqueRead<Collection<ModelledSTSSuite>>() {
+
+ @Override
+ public Collection<ModelledSTSSuite> perform(ReadGraph graph) throws DatabaseException {
+
+ List<Resource> sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE);
+ if (LOGGER.isInfoEnabled())
+ LOGGER.info("Found {} shared ontologies from graph", sharedOntologies.size());
+ Collection<ModelledSTSSuite> suites = new HashSet<>();
+ TestsResource TESTS = TestsResource.getInstance(graph);
+ Layer0 L0 = Layer0.getInstance(graph);
+ for (Resource sharedOntology : sharedOntologies) {
+ if (LOGGER.isInfoEnabled())
+ LOGGER.info("Searching {} for modelled tests", graph.getURI(sharedOntology));
+ List<Resource> stsSuites = ModelingUtils.searchByType(graph, sharedOntology, TESTS.STSSuite);
+ for (Resource stsSuite : stsSuites) {
+ try {
+ Collection<Resource> tests = graph.syncRequest(new ObjectsWithType(stsSuite, L0.ConsistsOf, TESTS.STSTest));
+ if (tests.isEmpty())
+ continue;
+
+ List<ModelledSTSTest> testRunners = new ArrayList<>(tests.size());
+ for (Resource test : tests)
+ testRunners.add(toModelledTest(graph, test));
+
+ suites.add(toModelledSuite(graph, stsSuite, testRunners));
+ } catch (Exception e) {
+ LOGGER.error("", e);
+ }
+ }
+ }
+ return suites;
+ }
+ });
+ return suitess;
+ } catch (DatabaseException e) {
+ LOGGER.error("Could not find modelled tests", e);
+ return Collections.emptyList();
+ }
+ }
+
+
+ public static ModelledSTSTest toModelledTest(ReadGraph graph, Resource test) throws DatabaseException {
+ TestsResource TESTS = TestsResource.getInstance(graph);
+ String testName = graph.getRelatedValue(test, Layer0.getInstance(graph).HasName, Bindings.STRING);
+ String code = graph.getRelatedValue(test, TESTS.STSTest_definition, Bindings.STRING);
+ Integer priority = graph.getPossibleRelatedValue(test, TESTS.STSTest_executionPriority, Bindings.INTEGER);
+ Boolean ignored = graph.getPossibleRelatedValue(test, TESTS.ignore, Bindings.BOOLEAN);
+ return new ModelledSTSTest(testName, code, priority != null ? priority : -1, ignored != null ? ignored : false);
+ }
+
+ public static ModelledSTSSuite toModelledSuite(ReadGraph graph, Resource suite, List<ModelledSTSTest> children) throws DatabaseException {
+ TestsResource TESTS = TestsResource.getInstance(graph);
+ String suiteName = graph.getURI(suite);
+ String moduleNameFilter = graph.getPossibleRelatedValue2(suite, TESTS.STSSuite_moduleNameFilter, Bindings.STRING);
+ return new ModelledSTSSuite(suiteName, children, moduleNameFilter);
+ }
+
+ public static void setTestCoverage(ModelledSTSTest test, CommandSession session) {
+ Collection<RuntimeModule> runtimeModules = session.getRuntimeEnvironment().getRuntimeModules();
+ List<Module> modules = new ArrayList<>(runtimeModules.size());
+ for (RuntimeModule module : runtimeModules)
+ modules.add(module.getModule());
+ test.setCoverage(CoverageUtils.getCoverage(modules));
+ CoverageUtils.resetCoverage(modules);
+ }
+
+ public static List<ModelledSTSSuite> collectTests() {
+ return new ArrayList<>(collectTestsFromGraph());
+ }
+
+
+ public static void setSuiteCoverage(ModelledSTSTest test, ModelledSTSSuite suite, CommandSession session) {
+ Collection<RuntimeModule> runtimeModules = session.getRuntimeEnvironment().getRuntimeModules();
+ List<Module> modules = new ArrayList<>(runtimeModules.size());
+ for (RuntimeModule module : runtimeModules) {
+ for (Pattern p : suite.getModuleNameFilterPatterns()) {
+ if (p.matcher(module.getModule().getName().toLowerCase()).find()) {
+ modules.add(module.getModule());
+ }
+ }
+ }
+ test.setCoverage(CoverageUtils.getCoverage(modules));
+ suite.addCoverage(modules);
+ CoverageUtils.resetCoverage(modules);
+ }
+}
version="0.0.0"
unpack="false"/>
+ <plugin
+ id="org.slf4j.api"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
+ id="ch.qos.logback.classic"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
+ id="org.simantics.db.testing"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
</feature>
@Test public void Matching2() { test(); }
@Test public void Matching4() { test(); }
@Test public void Matching5() { test(); }
+ @Test public void Matching6() { test(); }
@Test public void MatchingWithMissingParameter() { test(); }
@Test public void MatchingWithoutTypeAnnotations() { test(); }
@Test public void MaximumBy() { test(); }
--- /dev/null
+import "Prelude"
+
+main = do
+ match 1+1 :: Integer with
+ 2 -> 2
+ 0 -> 0
+ 1 -> 1
+--
+2
\ No newline at end of file
package org.simantics.scl.osgi.tests;
-import java.util.ArrayList;
-import java.util.concurrent.atomic.AtomicInteger;
-
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.junit.AfterClass;
import org.simantics.application.arguments.IArgumentFactory;
import org.simantics.application.arguments.IArguments;
import org.simantics.application.arguments.SimanticsArguments;
-import org.simantics.scl.compiler.errors.DoesNotExist;
-import org.simantics.scl.compiler.errors.Failable;
-import org.simantics.scl.compiler.module.Module;
import org.simantics.scl.osgi.SCLOsgi;
-import gnu.trove.procedure.TObjectProcedure;
-
-
public class TestSCLOsgi {
private static IProgressMonitor progress = new NullProgressMonitor();
@Test
public void testDataJsonExists() {
- ArrayList<String> modulesWithErrors = new ArrayList<String>();
- SCLOsgi.SOURCE_REPOSITORY.forAllModules(new TObjectProcedure<String>() {
- @Override
- public boolean execute(String moduleName) {
- System.out.print(moduleName);
- System.out.print(" - ");
- Failable<Module> module = SCLOsgi.MODULE_REPOSITORY.getModule(moduleName);
- if(module.didSucceed())
- System.out.println("succeeded");
- else if(module == DoesNotExist.INSTANCE)
- System.out.println("does not exist"); // should not happen
- else {
- System.out.println("error");
- modulesWithErrors.add(moduleName);
- }
- return true;
- }
- });
- if(!modulesWithErrors.isEmpty()) {
- StringBuilder b = new StringBuilder();
- b.append("Some SCL modules failed to compile:");
- for(String module : modulesWithErrors)
- b.append(' ').append(module);
- Assert.fail(b.toString());
+ String possibleError = SCLOsgi.compileAllModules();
+ if(possibleError != null) {
+ Assert.fail(possibleError);
}
}
}