org.eclipse.emf.mwe.core.WorkflowContext Java Examples

The following examples show how to use org.eclipse.emf.mwe.core.WorkflowContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReaderTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testLoadOne() throws Exception {
	Reader reader = getReader();
	reader.addPath(pathTo("emptyFolder"));
	reader.addPath(pathTo("nonemptyFolder"));
	reader.addRegister(new IndexTestLanguageStandaloneSetup());

	SlotEntry entry = createSlotEntry();
	entry.setName("foo:bar:Person");
	entry.setFirstOnly(true);
	entry.setNamespaceDelimiter(":");

	reader.addLoad(entry);
	WorkflowContext ctx = ctx();
	reader.invoke(ctx, monitor(), issues());
	assertEquals("Person", ((Entity) ctx.get("model")).getName());
}
 
Example #2
Source File: Reader.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor, Issues issues) {
	ResourceSet resourceSet = getResourceSet();
	Multimap<String, URI> uris = getPathTraverser().resolvePathes(pathes, new Predicate<URI>() {
		@Override
		public boolean apply(URI input) {
			boolean result = true;
			if (getUriFilter() != null)
				result = getUriFilter().matches(input);
			if (result)
				result = getRegistry().getResourceServiceProvider(input) != null;
			return result;
		}
	});
	IAllContainersState containersState = containersStateFactory.getContainersState(pathes, uris);
	installAsAdapter(resourceSet, containersState);
	populateResourceSet(resourceSet, uris);
	getValidator().validate(resourceSet, getRegistry(), issues);
	addModelElementsToContext(ctx, resourceSet);
}
 
Example #3
Source File: AbstractReaderTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testLoadByType_withUnkownNsURI() throws Exception {
	Reader reader = getReader();
	reader.addPath(pathTo("emptyFolder"));
	reader.addPath(pathTo("nonemptyFolder"));
	reader.addRegister(new IndexTestLanguageStandaloneSetup());
	SlotEntry entry = createSlotEntry();
	entry.setType("Entity");
	entry.setNsURI("unknown ns uri");
	reader.addLoad(entry);

	WorkflowContext ctx = ctx();
	try {
		reader.invoke(ctx, monitor(), issues());
		fail("workflow interuption expected.");
	} catch (WorkflowInterruptedException e) {
		//expected
	}
}
 
Example #4
Source File: AbstractReaderTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test public void testLoadByType_withNsURI() throws Exception {
	Reader reader = getReader();
	reader.addPath(pathTo("emptyFolder"));
	reader.addPath(pathTo("nonemptyFolder"));
	reader.addRegister(new IndexTestLanguageStandaloneSetup());
	SlotEntry entry = createSlotEntry();
	entry.setType("Entity");
	entry.setNsURI(IndexTestLanguagePackage.eNS_URI);
	reader.addLoad(entry);

	WorkflowContext ctx = ctx();
	reader.invoke(ctx, monitor(), issues());
	List<Entity> entities = (List<Entity>) ctx.get("model");
	assertEquals(2, entities.size());
}
 
Example #5
Source File: AbstractReaderTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testLoadMatchAll() throws Exception {
	Reader reader = getReader();
	reader.addPath(pathTo("emptyFolder"));
	reader.addPath(pathTo("nonemptyFolder"));
	reader.addRegister(new IndexTestLanguageStandaloneSetup());

	SlotEntry entry = createSlotEntry();
	entry.setType("Type");
	reader.addLoad(entry);
	
	reader.setUriFilter(new UriFilter() {
		@Override
		public boolean matches(URI uri) {
			return true;
		}
	});
	WorkflowContext ctx = ctx();
	reader.invoke(ctx, monitor(), issues());
	Collection<?> slotContent = (Collection<?>) ctx.get("model");
	assertNotNull(slotContent);
	// Foo, Person, String
	assertEquals(3, slotContent.size());
}
 
Example #6
Source File: AbstractReaderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test public void testLoadBySuperType() throws Exception {
	Reader reader = getReader();
	reader.addPath(pathTo("emptyFolder"));
	reader.addPath(pathTo("nonemptyFolder"));
	reader.addRegister(new IndexTestLanguageStandaloneSetup());
	SlotEntry entry = createSlotEntry();
	entry.setType("Type");
	reader.addLoad(entry);
	
	WorkflowContext ctx = ctx();
	reader.invoke(ctx, monitor(), issues());
	List<Entity> entities = (List<Entity>) ctx.get("model");
	assertEquals(3, entities.size());
}
 
Example #7
Source File: LazyStandaloneSetup.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor, Issues issues) {
    for (String generatedEPackage : allgeneratedEPackages) {
        addRegisterGeneratedEPackage(generatedEPackage);
    }
    for (String genModelFile : allGenModelFiles) {
        addRegisterGenModelFile(genModelFile);
    }
    for (String ecoreFile : allEcoreFiles) {
        addRegisterEcoreFile(ecoreFile);
    }
}
 
Example #8
Source File: LazyStandaloneSetup.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor, Issues issues) {
    for (String generatedEPackage : allgeneratedEPackages) {
        addRegisterGeneratedEPackage(generatedEPackage);
    }
    for (String genModelFile : allGenModelFiles) {
        addRegisterGenModelFile(genModelFile);
    }
    for (String ecoreFile : allEcoreFiles) {
        addRegisterEcoreFile(ecoreFile);
    }
}
 
Example #9
Source File: ReaderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test public void testLoadAll() throws Exception {
	Reader reader = getReader();
	reader.addPath(pathTo("emptyFolder"));
	reader.addPath(pathTo("nonemptyFolder"));
	reader.addRegister(new IndexTestLanguageStandaloneSetup());
	SlotEntry entry = createSlotEntry();
	reader.addLoad(entry);
	
	WorkflowContext ctx = ctx();
	reader.invoke(ctx, monitor(), issues());
	List<EObject> elements = (List<EObject>) ctx.get("model");
	assertEquals(8,elements.size());
}
 
Example #10
Source File: ReaderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testLoadTwo() throws Exception {
	Reader reader = getReader();
	reader.addPath(pathTo("emptyFolder"));
	reader.addPath(pathTo("nonemptyFolder"));
	reader.addRegister(new IndexTestLanguageStandaloneSetup());
	SlotEntry entry = createSlotEntry();
	entry.setSlot("person");
	entry.setName("foo.bar.Person");
	entry.setNamespaceDelimiter(".");
	entry.setFirstOnly(true);
	SlotEntry entry2 = createSlotEntry();
	entry2.setSlot("string");
	entry2.setName("foo.bar.sub.String");
	entry2.setNamespaceDelimiter(".");
	entry2.setFirstOnly(true);
	reader.addLoad(entry);
	reader.addLoad(entry2);
	WorkflowContext ctx = ctx();
	Issues issues = issues();
	try {
		reader.invoke(ctx, monitor(), issues);
	} catch (Exception e) {
		System.out.println(issues);
		throw e;
	}
	assertEquals("Person", ((Entity) ctx.get("person")).getName());
	assertEquals("String", ((Datatype) ctx.get("string")).getName());
}
 
Example #11
Source File: UriBasedReaderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test public void testTransitiveReferences() throws Exception {
	UriBasedReader reader = new UriBasedReader();
	reader.addRegister(new ImportUriTestLanguageStandaloneSetup());
	reader.addUri(pathTo2("importUriSubfolder/Start.importuritestlanguage"));

	SlotEntry slotEntry = new SlotEntry();
	slotEntry.setType("Type");
	reader.addLoad(slotEntry);

	WorkflowContext ctx = new WorkflowContextDefaultImpl();
	IssuesImpl issues = new IssuesImpl();
	reader.checkConfiguration(issues);
	try {
		reader.invoke(ctx, new NullProgressMonitor(), issues);
	} catch (Exception e) {
		System.out.println(issues);
		throw e;
	}

	List<Type> types = (List<Type>) ctx.get(slotEntry.getSlot());
	assertEquals(3, types.size());
	for (Type type : types) {
		if (type.getName().equals("Foo")) {
			assertEquals("Bar", type.getExtends().getName());
		} else if (type.getName().equals("Bar")) {
			assertEquals("Baz", type.getExtends().getName());
		} else {
			assertNull(type.getExtends());
		}
	}
}
 
Example #12
Source File: AbstractReaderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testLoadByType_FirstOnly() throws Exception {
	Reader reader = getReader();
	reader.addPath(pathTo("emptyFolder"));
	reader.addPath(pathTo("nonemptyFolder"));
	reader.addRegister(new IndexTestLanguageStandaloneSetup());
	SlotEntry entry = createSlotEntry();
	entry.setType("Entity");
	entry.setFirstOnly(true);
	reader.addLoad(entry);
	
	WorkflowContext ctx = ctx();
	reader.invoke(ctx, monitor(), issues());
	assertEquals("Person", ((Entity) ctx.get("model")).getName());
}
 
Example #13
Source File: XcoreReader.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor,
		Issues issues) {
	ResourceSet resourceSet = getResourceSet();

	// due to some Xcore peculiarity we have to access the IAllContainerState here
	// to trigger some lazy init logic
	IAllContainersState allContainerState = (IAllContainersState) EcoreUtil.getAdapter(resourceSet.eAdapters(),
			IAllContainersState.class);
	allContainerState.isEmpty("");

	Multimap<String, URI> uris = getPathTraverser().resolvePathes(pathes,
			new Predicate<URI>() {
		@Override
		public boolean apply(URI input) {
			return input.fileExtension().equals(XCORE_FILE_EXT);
		}
	});
	List<Resource> resources = new ArrayList<>();
	for (URI uri : uris.values()) {
		LOGGER.info(uri);
		try {
			resources.add(parse(uri, resourceSet));
		} catch (Exception e) {
			LOGGER.error("Problem during loading of resource @ " + uri, e);
		}
	}
	installIndex(resourceSet);
	for (Resource r : resources) {
		EcoreUtil.resolveAll(r);
		for (Diagnostic x : r.getErrors()) {
			issues.addError(x.getMessage(), x);
		}

	}
	ctx.set(slot, resources);
}
 
Example #14
Source File: AbstractReaderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test public void testLoadByType() throws Exception {
	Reader reader = getReader();
	reader.addPath(pathTo("emptyFolder"));
	reader.addPath(pathTo("nonemptyFolder"));
	reader.addRegister(new IndexTestLanguageStandaloneSetup());
	SlotEntry entry = createSlotEntry();
	entry.setType("Entity");
	reader.addLoad(entry);

	WorkflowContext ctx = ctx();
	reader.invoke(ctx, monitor(), issues());
	List<Entity> entities = (List<Entity>) ctx.get("model");
	assertEquals(2, entities.size());
}
 
Example #15
Source File: AbstractReaderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testLoadMatchNone() throws Exception {
	final Reader reader = getReader();
	reader.addPath(pathTo("emptyFolder"));
	reader.addPath(pathTo("nonemptyFolder"));
	reader.addRegister(new IndexTestLanguageStandaloneSetup());

	SlotEntry entry = createSlotEntry();
	entry.setType("Type");
	reader.addLoad(entry);
	
	reader.setUriFilter(new UriFilter() {
		@Override
		public boolean matches(URI uri) {
			return false;
		}
	});
	final WorkflowContext ctx = ctx();
	LoggingTester.captureLogging(Level.WARN, SlotEntry.class, new Runnable() {

		@Override
		public void run() {
			reader.invoke(ctx, monitor(), issues());
		}
		
	}).assertLogEntry("Could not find any exported element of type 'Type' -> Slot 'model' is empty.");
	Collection<?> slotContent = (Collection<?>) ctx.get("model");
	assertNotNull(slotContent);
	assertTrue(slotContent.isEmpty());
}
 
Example #16
Source File: ResourceSetBasedSlotEntryReaderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test public void testLoadFileElements() throws Exception {
	Reader reader = getReader();
	reader.addPath(pathTo("emptyFolder"));
	reader.addPath(pathTo("nonemptyFolder"));
	reader.addRegister(new IndexTestLanguageStandaloneSetup());
	SlotEntry entry = createSlotEntry();
	entry.setType("File");
	reader.addLoad(entry);
	
	WorkflowContext ctx = ctx();
	reader.invoke(ctx, monitor(), issues());
	List<EObject> elements = (List<EObject>) ctx.get("model");
	assertEquals(2,elements.size());
}
 
Example #17
Source File: ResourceSetBasedSlotEntryReaderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test public void testLoadAll() throws Exception {
	Reader reader = getReader();
	reader.addPath(pathTo("emptyFolder"));
	reader.addPath(pathTo("nonemptyFolder"));
	reader.addRegister(new IndexTestLanguageStandaloneSetup());
	SlotEntry entry = createSlotEntry();
	reader.addLoad(entry);
	
	WorkflowContext ctx = ctx();
	reader.invoke(ctx, monitor(), issues());
	List<EObject> elements = (List<EObject>) ctx.get("model");
	assertEquals(11,elements.size());
}
 
Example #18
Source File: ResourceLoadingSlotEntry.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void put(WorkflowContext ctx, IResourceDescriptions descriptions, ResourceSet resourceSet) {
	EList<Resource> resources = resourceSet.getResources();
	List<Resource> result = newArrayList();
	for (Resource resource : resources) {
		if (isMatch(resource))
			result.add(resource);
	}
	ctx.set(slot, result);
}
 
Example #19
Source File: UriBasedReader.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor, Issues issues) {
	ResourceSet resourceSet = getResourceSet();
	for (URI uri : uris2) {
		Resource resource = resourceSet.getResource(uri, true);
		int numberResources;
		do {
			numberResources = resourceSet.getResources().size();
			EcoreUtil.resolveAll(resource);
		} while (numberResources!=resourceSet.getResources().size());
	}
	getValidator().validate(resourceSet, getRegistry(), issues);
	addModelElementsToContext(ctx, resourceSet);
}
 
Example #20
Source File: SlotEntry.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void put(WorkflowContext ctx, IResourceDescriptions resourceDescriptions, ResourceSet resourceSet) {
	Set<EClass> eClasses = findEClasses(resourceSet, nsURI, type);
	List<EObject> elements = findEObjectsOfType(eClasses, resourceDescriptions, resourceSet);
	if (elements.isEmpty()) {
		log.warn("Could not find any exported element of type '" + type + "' -> Slot '" + slot + "' is empty.");
		ctx.set(slot, Collections.emptyList());
	} else if (firstOnly) {
		ctx.set(slot, elements.get(0));
	} else {
		ctx.set(slot, elements);
	}
}
 
Example #21
Source File: Ecore2XtextGenerator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void invokeInternal(final WorkflowContext ctx, ProgressMonitor monitor, final Issues issues) {
	createXtextProjectInfo(issues);
	CharSequence grammar = xtextProjectInfo.getRuntimeProject().grammar();
	try {
		Files.asCharSink(new File(genPath, xtextProjectInfo.getRuntimeProject().getGrammarFilePath()), Charsets.ISO_8859_1).write(grammar);
	} catch (IOException e) {
		String message = "Can't create grammar file";
		log.error(message, e);
		issues.addError(Ecore2XtextGenerator.this, message, this, e, null);
	}
}
 
Example #22
Source File: AbstractReaderTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected WorkflowContext ctx() {
	return new WorkflowContextDefaultImpl();
}
 
Example #23
Source File: AbstractReader.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void addModelElementsToContext(WorkflowContext ctx, ResourceSet resourceSet) {
	IResourceDescriptions descriptions = resourceDescriptionsProvider.get(resourceSet);
	for (ISlotEntry entries : this.slotEntries) {
		entries.put(ctx, descriptions, resourceSet);
	}
}
 
Example #24
Source File: ReaderTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test public void testShadowingPathes() throws Exception {
	Reader reader = getReader();
	// also test adding multiple paths as comma-separated list, see bug#356750
	reader.addPath(
		       pathTo("shadowingtest/folder 1")
		+","  +pathTo("shadowingtest/folder 2")
		+" , "+pathTo("shadowingtest/folder 3"));
	reader.addRegister(new IndexTestLanguageStandaloneSetup());
	SlotEntry entry = createSlotEntry();
	entry.setType("Entity");
	reader.addLoad(entry);
	SlotEntry entry2 = createSlotEntry();
	entry2.setType("Datatype");
	entry2.setSlot("stringTypes");
	entry2.setName("String");
	reader.addLoad(entry2);
	SlotEntry entry3 = createSlotEntry();
	entry3.setType("Datatype");
	entry3.setSlot("booleanTypes");
	entry3.setName("Boolean");
	reader.addLoad(entry3);
	
	WorkflowContext ctx = ctx();
	Issues issues = issues();
	try {
		reader.invoke(ctx, monitor(), issues);
	} catch (Exception e) {
		System.out.println(issues);
		throw e;
	}
	List<Entity> entities = (List<Entity>) ctx.get(entry.getSlot());
	List<Datatype> stringTypes = (List<Datatype>) ctx.get(entry2.getSlot());
	List<Datatype> booleanTypes = (List<Datatype>) ctx.get(entry3.getSlot());
	
	assertEquals(3,entities.size());
	assertEquals(2,stringTypes.size());
	assertEquals(2,booleanTypes.size());
	
	Entity ent1 = Iterables.find(entities, getPredicate("1"));
	Entity ent2 = Iterables.find(entities, getPredicate("2"));
	Entity ent3 = Iterables.find(entities, getPredicate("3"));
	Datatype string2 = Iterables.find(stringTypes, getPredicate("2"));
	Datatype string3 = Iterables.find(stringTypes, getPredicate("3"));
	Datatype bool1 = Iterables.find(booleanTypes, getPredicate("1"));
	Datatype bool2 = Iterables.find(booleanTypes, getPredicate("2"));
	
	assertEquals(string2,ent1.getProperties().get(0).getType());
	assertEquals(bool1, ent1.getProperties().get(1).getType());
	assertEquals(ent1,ent1.getProperties().get(2).getType());

	assertEquals(string2,ent2.getProperties().get(0).getType());
	assertEquals(bool2, ent2.getProperties().get(1).getType());
	assertEquals(ent2,ent2.getProperties().get(2).getType());
	
	assertEquals(string3,ent3.getProperties().get(0).getType());
	assertEquals(bool1, ent3.getProperties().get(1).getType());
	assertEquals(ent3,ent3.getProperties().get(2).getType());
	
}
 
Example #25
Source File: LazyGenerator.java    From openhab-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor, Issues issues) {
    super.checkConfigurationInternal(issues);
    super.invokeInternal(ctx, monitor, issues);
}
 
Example #26
Source File: LazyGenerator.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor, Issues issues) {
    super.checkConfigurationInternal(issues);
    super.invokeInternal(ctx, monitor, issues);
}
 
Example #27
Source File: ISlotEntry.java    From xtext-core with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * implementers can modify the ctx (i.e. add new entries based on the configuration)
 * @param ctx - the workflow context to modify
 * @param descriptions - the index state
 * @param resourceSet - the resource set containing the loaded resources
 */
void put(WorkflowContext ctx, IResourceDescriptions descriptions, ResourceSet resourceSet);