Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Belle2018-10-11 10:15:37 +0000
committerJan Belle2019-03-08 16:12:05 +0000
commitd47fab84d8d7df4b9d2270d8d153ee57b92f4a83 (patch)
tree58f0001cf31425426070eca41913be8b62a7ad0f /plugins/org.eclipse.etrice.ui.common.base
parentc511bcf1062cc5d8af65be5092a164d62cc017f3 (diff)
downloadorg.eclipse.etrice-d47fab84d8d7df4b9d2270d8d153ee57b92f4a83.tar.gz
org.eclipse.etrice-d47fab84d8d7df4b9d2270d8d153ee57b92f4a83.tar.xz
org.eclipse.etrice-d47fab84d8d7df4b9d2270d8d153ee57b92f4a83.zip
[core] Implement uri independent import system
Diffstat (limited to 'plugins/org.eclipse.etrice.ui.common.base')
-rw-r--r--plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomResourceSetProvider.java126
-rw-r--r--plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomUpdateBehavior.java6
2 files changed, 4 insertions, 128 deletions
diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomResourceSetProvider.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomResourceSetProvider.java
deleted file mode 100644
index 5df3a897b..000000000
--- a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomResourceSetProvider.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * CONTRIBUTORS:
- * Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.common.base.editor;
-
-import static com.google.common.collect.Maps.newHashMap;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IStorage;
-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.IJavaProject;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.xtext.resource.XtextResourceSet;
-import org.eclipse.xtext.ui.resource.IResourceSetProvider;
-import org.eclipse.xtext.ui.resource.IStorage2UriMapperJdtExtensions;
-import org.eclipse.xtext.ui.util.JdtClasspathUriResolver;
-import org.eclipse.xtext.util.Pair;
-
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-
-/**
- * This class is copied from XtextResourceSetProvider with the only modification that we skip our own project in
- * the platform project mappings (marked with <b>[HRR]</b>)
- *
- * @author Henrik Rentz-Reichert
- */
-public class CustomResourceSetProvider implements IResourceSetProvider {
-
- private final static Logger LOG = Logger.getLogger(CustomResourceSetProvider.class);
-
- @Inject
- private Provider<XtextResourceSet> resourceSetProvider;
-
- @Inject
- private IStorage2UriMapperJdtExtensions storage2UriMapper;
-
- public ResourceSet get(IProject project) {
- XtextResourceSet set = resourceSetProvider.get();
- 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;
- }
-
- protected Map<URI, URI> computePlatformURIMap(IJavaProject javaProject) {
- HashMap<URI, URI> hashMap = newHashMap();
- try {
- hashMap.putAll(EcorePlugin.computePlatformURIMap(false));
- } catch (Exception e) {
- LOG.error(e.getMessage(), e);
- }
- if (!javaProject.exists())
- return hashMap;
- try {
- IPackageFragmentRoot[] roots = javaProject.getAllPackageFragmentRoots();
- for (IPackageFragmentRoot root : roots) {
- Pair<URI, URI> uriMapping = storage2UriMapper.getURIMapping(root);
- if (uriMapping != null) {
-
- // we could just install the prefix mapping, i.e. platform:resource/my.project/ -> file:/my/path/to/my.project/
- // but then we wouldn't be able to load resources when using hosted bundles, because the target path points to the bin folder.
- // so instead we install qualified file mappings, which also makes normalization faster (i.e. just a lookup in a map instead of testing prefix URIs)
- //
- Map<URI, IStorage> mapping = storage2UriMapper.getAllEntries(root);
- for (URI key : mapping.keySet()) {
- IStorage storage = mapping.get(key);
- URI physicalURI = null;
- if (storage instanceof IFile) {
- physicalURI = URI.createPlatformResourceURI(storage.getFullPath().toString(), true);
- } else {
- physicalURI = key.replacePrefix(uriMapping.getFirst(), uriMapping.getSecond());
- }
- hashMap.put(key, physicalURI);
- if (key.isPlatformResource()) {
- URI pluginURI = URI.createPlatformPluginURI(key.toPlatformString(false), false);
- hashMap.put(pluginURI, physicalURI);
- }
- }
- }
- }
- /*
- */
- final IProject project = javaProject.getProject();
- for (IProject iProject : project.getWorkspace().getRoot().getProjects()) {
- // [HRR]: following line was:
- // if (iProject.isAccessible()) {
- if (iProject!=project && iProject.isAccessible()) {
- IPath location = iProject.getLocation();
- if (location != null) {
- // append a trailing slash so that URI.isPrefix is true.
- hashMap.put(URI.createPlatformResourceURI(iProject.getName()+"/", true), URI.createFileURI(location.toFile().getPath()+"/"));
- }
- }
- }
- } catch (JavaModelException e) {
- LOG.error(e.getMessage(), e);
- }
- return hashMap;
- }
-
- }
diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomUpdateBehavior.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomUpdateBehavior.java
index afca52e2b..ff82569c4 100644
--- a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomUpdateBehavior.java
+++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/CustomUpdateBehavior.java
@@ -33,6 +33,7 @@ import org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandStackImpl;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.ui.resource.IResourceSetProvider;
+import com.google.inject.Inject;
import com.google.inject.Injector;
/**
@@ -42,7 +43,8 @@ import com.google.inject.Injector;
@SuppressWarnings("restriction")
public class CustomUpdateBehavior extends DefaultUpdateBehavior {
- private IResourceSetProvider resourceSetProvider = new CustomResourceSetProvider();
+ @Inject
+ private IResourceSetProvider resourceSetProvider;
/**
* @param diagramBehavior
@@ -51,7 +53,7 @@ public class CustomUpdateBehavior extends DefaultUpdateBehavior {
super(diagramBehavior);
Injector injector = FSMUiModule.getInjector();
- injector.injectMembers(resourceSetProvider);
+ injector.injectMembers(this);
}
/* (non-Javadoc)

Back to the top