Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Charles David2016-03-21 15:28:37 +0000
committerPierre-Charles David2016-03-22 08:06:07 +0000
commit23dd4943ab8acb3ca78f66a9921dc8484bf4a7cf (patch)
treeac8d2f3aa643d6f8851629c8f376a8adc1508286
parent00ce23becafae50c841968b7952c9a282e9b9e69 (diff)
downloadorg.eclipse.sirius-23dd4943ab8acb3ca78f66a9921dc8484bf4a7cf.tar.gz
org.eclipse.sirius-23dd4943ab8acb3ca78f66a9921dc8484bf4a7cf.tar.xz
org.eclipse.sirius-23dd4943ab8acb3ca78f66a9921dc8484bf4a7cf.zip
[458751] Make the Xtext integration dependency on the JDT optional
Bug: 458751 Change-Id: I9b8c76587b9567906818cddb8b8bea73573f9aef Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.common.xtext/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.sirius.common.xtext/src/org/eclipse/sirius/common/xtext/internal/ResourceSetClasspathConfigurator.java101
-rw-r--r--plugins/org.eclipse.sirius.common.xtext/src/org/eclipse/sirius/common/xtext/internal/XTextResourceSetFactory.java84
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/Release_Notes.html13
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile6
5 files changed, 123 insertions, 83 deletions
diff --git a/plugins/org.eclipse.sirius.common.xtext/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.common.xtext/META-INF/MANIFEST.MF
index 6c80ab0200..0d794f2529 100644
--- a/plugins/org.eclipse.sirius.common.xtext/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.sirius.common.xtext/META-INF/MANIFEST.MF
@@ -7,7 +7,7 @@ Bundle-Vendor: %providerName
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle: org.eclipse.xtext.ui;bundle-version="2.1.1",
org.eclipse.sirius.common;bundle-version="2.0.0",
- org.eclipse.jdt.core;bundle-version="3.8.1",
+ org.eclipse.jdt.core;bundle-version="3.8.1";resolution:=optional,
org.eclipse.sirius;bundle-version="2.0.0",
org.eclipse.emf.transaction;bundle-version="1.4.0"
Bundle-Localization: plugin
diff --git a/plugins/org.eclipse.sirius.common.xtext/src/org/eclipse/sirius/common/xtext/internal/ResourceSetClasspathConfigurator.java b/plugins/org.eclipse.sirius.common.xtext/src/org/eclipse/sirius/common/xtext/internal/ResourceSetClasspathConfigurator.java
new file mode 100644
index 0000000000..f1c4d7acb2
--- /dev/null
+++ b/plugins/org.eclipse.sirius.common.xtext/src/org/eclipse/sirius/common/xtext/internal/ResourceSetClasspathConfigurator.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.sirius.common.xtext.internal;
+
+import static com.google.common.collect.Maps.newHashMap;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.plugin.EcorePlugin;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.sirius.common.tools.DslCommonPlugin;
+import org.eclipse.xtext.resource.XtextResourceSet;
+import org.eclipse.xtext.ui.util.JdtClasspathUriResolver;
+import org.osgi.framework.Constants;
+
+/**
+ * Configures an Xtext ResourceSet for Java integration if we are inside a Java
+ * project.
+ */
+public class ResourceSetClasspathConfigurator {
+ /**
+ * Configures an Xtext ResourceSet for Java integration if we are inside a
+ * Java project.
+ */
+ public ResourceSet configure(XtextResourceSet set, IProject project) {
+ IJavaProject javaProject = JavaCore.create(project);
+ if (javaProject != null && javaProject.exists()) {
+ set.getURIConverter().getURIMap().putAll(computePlatformURIMap(javaProject));
+ set.setClasspathURIContext(javaProject);
+ set.setClasspathUriResolver(new JdtClasspathUriResolver());
+ }
+ return set;
+ }
+
+ private Map<URI, URI> computePlatformURIMap(IJavaProject javaProject) {
+ HashMap<URI, URI> hashMap = newHashMap(EcorePlugin.computePlatformURIMap());
+ try {
+ if (!javaProject.exists())
+ return hashMap;
+ IClasspathEntry[] classpath = javaProject.getResolvedClasspath(true);
+ for (IClasspathEntry classPathEntry : classpath) {
+ IPath path = classPathEntry.getPath();
+ if (path != null && "jar".equals(path.getFileExtension())) { //$NON-NLS-1$
+ try {
+ final File file = path.toFile();
+ if (file != null && file.exists()) {
+ try (JarFile jarFile = new JarFile(file)) {
+ Manifest manifest = jarFile.getManifest();
+ if (manifest != null) {
+ handleManifest(hashMap, file, manifest);
+ }
+ }
+ }
+ } catch (IOException e) {
+ DslCommonPlugin.getDefault().error(e.getMessage(), e);
+ }
+ }
+ }
+ } catch (JavaModelException e) {
+ DslCommonPlugin.getDefault().error(e.getMessage(), e);
+ }
+ return hashMap;
+ }
+
+ private void handleManifest(HashMap<URI, URI> hashMap, final File file, Manifest manifest) {
+ String name = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE);
+ if (name != null) {
+ final int indexOf = name.indexOf(';');
+ if (indexOf > 0)
+ name = name.substring(0, indexOf);
+ if (!EcorePlugin.getPlatformResourceMap().containsKey(name)) {
+ String p = "archive:" + file.toURI() + "!/"; //$NON-NLS-1$ //$NON-NLS-2$
+ URI uri = URI.createURI(p);
+ final URI platformResourceKey = URI.createPlatformResourceURI(name + "/", false); //$NON-NLS-1$
+ final URI platformPluginKey = URI.createPlatformPluginURI(name + "/", false); //$NON-NLS-1$
+ hashMap.put(platformResourceKey, uri);
+ hashMap.put(platformPluginKey, uri);
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.sirius.common.xtext/src/org/eclipse/sirius/common/xtext/internal/XTextResourceSetFactory.java b/plugins/org.eclipse.sirius.common.xtext/src/org/eclipse/sirius/common/xtext/internal/XTextResourceSetFactory.java
index 49ed64490f..3d3c870509 100644
--- a/plugins/org.eclipse.sirius.common.xtext/src/org/eclipse/sirius/common/xtext/internal/XTextResourceSetFactory.java
+++ b/plugins/org.eclipse.sirius.common.xtext/src/org/eclipse/sirius/common/xtext/internal/XTextResourceSetFactory.java
@@ -10,29 +10,11 @@
*******************************************************************************/
package org.eclipse.sirius.common.xtext.internal;
-import static com.google.common.collect.Maps.newHashMap;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
-
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.sirius.common.tools.DslCommonPlugin;
import org.eclipse.xtext.resource.XtextResourceSet;
-import org.eclipse.xtext.ui.util.JdtClasspathUriResolver;
-import org.osgi.framework.Constants;
/**
* Class overriding the default {@link ResourceSet} factory to correctly setup
@@ -43,15 +25,16 @@ import org.osgi.framework.Constants;
*/
public class XTextResourceSetFactory extends org.eclipse.sirius.common.tools.api.resource.ResourceSetFactory {
- /**
- * {@inheritDoc}
- */
@Override
public ResourceSet createResourceSet(URI resourceURI) {
XtextResourceSet set = new XtextResourceSet();
IProject prj = findProjectFromURI(resourceURI);
if (prj != null) {
- configure(set, prj);
+ try {
+ new ResourceSetClasspathConfigurator().configure(set, prj);
+ } catch (NoClassDefFoundError ncdfe) {
+ // The JDT is not present, but it's OK.
+ }
}
/*
@@ -71,61 +54,4 @@ public class XTextResourceSetFactory extends org.eclipse.sirius.common.tools.api
}
return null;
}
-
- private ResourceSet configure(XtextResourceSet set, IProject project) {
- IJavaProject javaProject = JavaCore.create(project);
- if (javaProject != null && javaProject.exists()) {
- set.getURIConverter().getURIMap().putAll(computePlatformURIMap(javaProject));
- set.setClasspathURIContext(javaProject);
- set.setClasspathUriResolver(new JdtClasspathUriResolver());
- }
- return set;
- }
-
- private Map<URI, URI> computePlatformURIMap(IJavaProject javaProject) {
- HashMap<URI, URI> hashMap = newHashMap(EcorePlugin.computePlatformURIMap());
- try {
- if (!javaProject.exists())
- return hashMap;
- IClasspathEntry[] classpath = javaProject.getResolvedClasspath(true);
- for (IClasspathEntry classPathEntry : classpath) {
- IPath path = classPathEntry.getPath();
- if (path != null && "jar".equals(path.getFileExtension())) { //$NON-NLS-1$
- try {
- final File file = path.toFile();
- if (file != null && file.exists()) {
- try (JarFile jarFile = new JarFile(file)) {
- Manifest manifest = jarFile.getManifest();
- if (manifest != null) {
- handleManifest(hashMap, file, manifest);
- }
- }
- }
- } catch (IOException e) {
- DslCommonPlugin.getDefault().error(e.getMessage(), e);
- }
- }
- }
- } catch (JavaModelException e) {
- DslCommonPlugin.getDefault().error(e.getMessage(), e);
- }
- return hashMap;
- }
-
- private void handleManifest(HashMap<URI, URI> hashMap, final File file, Manifest manifest) {
- String name = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE);
- if (name != null) {
- final int indexOf = name.indexOf(';');
- if (indexOf > 0)
- name = name.substring(0, indexOf);
- if (!EcorePlugin.getPlatformResourceMap().containsKey(name)) {
- String p = "archive:" + file.toURI() + "!/"; //$NON-NLS-1$ //$NON-NLS-2$
- URI uri = URI.createURI(p);
- final URI platformResourceKey = URI.createPlatformResourceURI(name + "/", false); //$NON-NLS-1$
- final URI platformPluginKey = URI.createPlatformPluginURI(name + "/", false); //$NON-NLS-1$
- hashMap.put(platformResourceKey, uri);
- hashMap.put(platformPluginKey, uri);
- }
- }
- }
}
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
index 750e389074..28a24b50df 100644
--- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
+++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
@@ -262,8 +262,7 @@
<li><span class="label label-danger">Removed</span> The
<code>org.eclipse.sirius.ui</code>, and thus the whole
<code>org.eclipse.sirius.runtime</code> feature no longer depends on the JDT (technically the dependency towards
- <code>org.eclipse.jdt.core</code> has been removed). If you need the JDT Core in your environment, you will need to add the dependency explicitly. The
- <code>org.eclipse.sirius.common.xtext</code> plug-in (which is optional) still depends on the JDT, and the Sirius specification environment (
+ <code>org.eclipse.jdt.core</code> has been removed). If you need the JDT Core in your environment, you will need to add the dependency explicitly. The Sirius specification environment (
<code>org.eclipse.sirius.editor</code>) still depends on PDE (and thus indirectly the JDT too).
</li>
</ul>
@@ -278,6 +277,16 @@
<code>SWTBotTreeItem</code> array.
</li>
</ul>
+ <h4 id="Changesinorg.eclipse.sirius.common.xtext">Changes in
+ <code>org.eclipse.sirius.common.xtext</code>
+ </h4>
+ <ul>
+ <li><span class="label label-info">Modified</span> The dependency from
+ <code>org.eclipse.sirius.common.xtext</code> to the JDT plug-in
+ <code>org.eclipse.jdt.core</code> is now optional. If you need the JDT Core in your environment, you will need to add the dependency explicitly. The Sirius specification environment (
+ <code>org.eclipse.sirius.editor</code>) still depends on PDE (and thus indirectly the JDT too).
+ </li>
+ </ul>
<h2 id="sirius3.1.1">Changes in Sirius 3.1.1</h2>
<h3 id="SpecifierVisibleChanges2">Specifier-Visible Changes</h3>
<ul>
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
index 3ec17fab9b..b867c0e05b 100644
--- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
+++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
@@ -73,12 +73,16 @@ h4. Changes in @org.eclipse.sirius.ui@
* <span class="label label-success">Added</span> @org.eclipse.sirius.ui.tools.api.properties.SiriusExtensiblePropertyDescriptor@ has been added to provide a specific @ExtensiblePropertyDescriptor@ which test @IPermissionAuthority@ to make properties view editable or not.
* <span class="label label-info">Modified</span> @org.eclipse.sirius.ui.tools.api.properties.SiriusExtensiblePropertySource@ has been modified to use @SiriusExtensiblePropertyDescriptor@ to provide not editable properties view when the object, selected from the Model Explorer view, cannot be modified.
-* <span class="label label-danger">Removed</span> The @org.eclipse.sirius.ui@, and thus the whole @org.eclipse.sirius.runtime@ feature no longer depends on the JDT (technically the dependency towards @org.eclipse.jdt.core@ has been removed). If you need the JDT Core in your environment, you will need to add the dependency explicitly. The @org.eclipse.sirius.common.xtext@ plug-in (which is optional) still depends on the JDT, and the Sirius specification environment (@org.eclipse.sirius.editor@) still depends on PDE (and thus indirectly the JDT too).
+* <span class="label label-danger">Removed</span> The @org.eclipse.sirius.ui@, and thus the whole @org.eclipse.sirius.runtime@ feature no longer depends on the JDT (technically the dependency towards @org.eclipse.jdt.core@ has been removed). If you need the JDT Core in your environment, you will need to add the dependency explicitly. The Sirius specification environment (@org.eclipse.sirius.editor@) still depends on PDE (and thus indirectly the JDT too).
h4. Changes in @org.eclipse.sirius.tests.swtbot.support@
* <span class="label label-success">Added</span> The method @getTreeItem(final SWTBotTreeItem[], final String)@ has been added in @org.eclipse.sirius.tests.swtbot.support.utils@ to retrieve recursively a @SWTBotTreeItem@ in a @SWTBotTreeItem@ array.
+h4. Changes in @org.eclipse.sirius.common.xtext@
+
+* <span class="label label-info">Modified</span> The dependency from @org.eclipse.sirius.common.xtext@ to the JDT plug-in @org.eclipse.jdt.core@ is now optional. If you need the JDT Core in your environment, you will need to add the dependency explicitly. The Sirius specification environment (@org.eclipse.sirius.editor@) still depends on PDE (and thus indirectly the JDT too).
+
h2(#sirius3.1.1). Changes in Sirius 3.1.1
h3. Specifier-Visible Changes

Back to the top