Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2015-06-04 13:33:56 +0000
committerCamille Letavernier2015-06-05 08:25:19 +0000
commitd2dc2fd8777bbd50aa0ac10845b156d64be5695d (patch)
tree7c39ae39f95ff2040c17b9225bee3e2201485fa8 /tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils
parentd5706b93beee4419dc3634b24b6e6300441c9659 (diff)
downloadorg.eclipse.papyrus-d2dc2fd8777bbd50aa0ac10845b156d64be5695d.tar.gz
org.eclipse.papyrus-d2dc2fd8777bbd50aa0ac10845b156d64be5695d.tar.xz
org.eclipse.papyrus-d2dc2fd8777bbd50aa0ac10845b156d64be5695d.zip
Bug 468030: [Papyrus Core] Papyrus DI Model should support the notion of Language
https://bugs.eclipse.org/bugs/show_bug.cgi?id=468030 Implement a Language Service for configuration of the Papyrus ModelSet to support custom implementations of UML and other modeling languages. Includes: * language service providing languages before the ModelSet loads any resources * hooks for languages to configure and unconfigure a ModelSet * implementation of a language provider that maps applied profiles to languages * addition of a profile index service that provides the URIs of profiles applied to model resources without having to load them in a resource set * a stub of a UML-RT language with placeholder for configuration of the ModelSet * a standard UML language * implementation of the profile index service using an enhanced DecoratorModelIndex that now also index the normal profile applications in user models Papyrus Service Registry changes: * fix the explicit starting of lazy services * new AbstractServiceUtils API for requesting optional or defaultable services Also includes the very barest of JUnit tests covering: * the new profile index service * using the language service to query content-type-based languages * UML languages: UML models have the UML language, itself, and proper matching and installation of profile languages Change-Id: I9d5175cfbefbe40864f04ea4215e18556e3739df Reviewed-on: https://git.eclipse.org/r/49152 Tested-by: Hudson CI Reviewed-by: Camille Letavernier <camille.letavernier@cea.fr>
Diffstat (limited to 'tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils')
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ProjectFixture.java81
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ProjectFixture.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ProjectFixture.java
index 9d10afe09f5..dd726710dbc 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ProjectFixture.java
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/ProjectFixture.java
@@ -9,6 +9,7 @@
* Contributors:
* Christian W. Damus (CEA) - Initial API and implementation
* Christian W. Damus - bug 451230
+ * Christian W. Damus - bug 468030
*
*/
package org.eclipse.papyrus.junit.utils.rules;
@@ -17,7 +18,12 @@ import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.fail;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
@@ -32,6 +38,8 @@ import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.FrameworkUtil;
/**
@@ -61,6 +69,78 @@ public class ProjectFixture implements TestRule {
return !uri.isPlatformResource() ? null : project.getWorkspace().getRoot().getFile(new Path(uri.toPlatformString(true)));
}
+ /**
+ * Creates a new file at the specified project-relative path with the contents of a bundle resource.
+ *
+ * @param relativeFilePath
+ * the project-relative path of the file to create
+ * @param classFromBundle
+ * the bundle in which its content is to be found
+ * @param resourcePath
+ * the path in the context bundle of the resource to copy
+ *
+ * @return the new file
+ *
+ * @throws IOException
+ * on any problem in creating the file
+ */
+ public IFile createFile(String relativeFilePath, Class<?> classFromBundle, String resourcePath) throws IOException {
+ IFile result;
+
+ Bundle bundle = FrameworkUtil.getBundle(classFromBundle);
+ URL resource = (bundle == null) ? null : bundle.getResource(resourcePath);
+ if (resource == null) {
+ throw new IOException("No such bundle resource: " + resourcePath);
+ }
+
+ IPath path = new Path(relativeFilePath);
+
+ try (InputStream input = resource.openStream()) {
+ createFolders(path.removeLastSegments(1));
+ result = project.getFile(path);
+ result.create(input, false, null);
+ } catch (CoreException e) {
+ if (e.getStatus().getException() instanceof IOException) {
+ throw (IOException) e.getStatus().getException();
+ } else if (e.getCause() instanceof IOException) {
+ throw (IOException) e.getCause();
+ }
+ throw new IOException("Failed to create file", e);
+ }
+
+ return result;
+ }
+
+ private void createFolders(IPath folderPath) throws CoreException {
+ if ((folderPath.segmentCount() > 0) && !folderPath.lastSegment().isEmpty()) {
+ createFolders(folderPath.removeLastSegments(1));
+ IFolder folder = project.getFolder(folderPath);
+ if (!folder.isAccessible()) {
+ folder.create(false, true, null);
+ }
+ }
+ }
+
+ /**
+ * Creates a new file in my project with the contents of a bundle resource.
+ *
+ * @param classFromBundle
+ * the bundle in which its content is to be found
+ * @param resourcePath
+ * the path in the context bundle of the resource to copy
+ *
+ * @return the new file, which will have the same name as the bundle resource and will be at the top level of the project
+ *
+ * @throws IOException
+ * on any problem in creating the file
+ *
+ * @see #createFile(String, Class, String)
+ */
+ public IFile createFile(Class<?> classFromBundle, String resourcePath) throws IOException {
+ return createFile(new Path(resourcePath).lastSegment(), classFromBundle, resourcePath);
+ }
+
+ @Override
public Statement apply(final Statement base, Description description) {
String name = description.getMethodName();
if (name == null) {
@@ -113,6 +193,7 @@ public class ProjectFixture implements TestRule {
// Make sure that we can delete everything
project.accept(new IResourceVisitor() {
+ @Override
public boolean visit(IResource resource) throws CoreException {
switch (resource.getType()) {
case IResource.FILE:

Back to the top