diff options
author | Henrik Rentz-Reichert | 2014-02-17 11:58:15 +0000 |
---|---|---|
committer | Henrik Rentz-Reichert | 2014-02-17 12:08:13 +0000 |
commit | 481de78e5b6df259f576d45f00c69145fa3fb5f6 (patch) | |
tree | 7c2d8bf4ca12d27cd3c9421c49cdea2b58fcdf4e | |
parent | 3e64fd11a10dd2ba88748358285e38851e12249b (diff) | |
download | org.eclipse.etrice-481de78e5b6df259f576d45f00c69145fa3fb5f6.tar.gz org.eclipse.etrice-481de78e5b6df259f576d45f00c69145fa3fb5f6.tar.xz org.eclipse.etrice-481de78e5b6df259f576d45f00c69145fa3fb5f6.zip |
Bug 428344: [core.room] introduce an extension point that allows clients to locate models
https://bugs.eclipse.org/428344
introduced an extension that allows clients to hook in
before the path is canonicalized and matched against workspace locations.
6 files changed, 218 insertions, 1 deletions
diff --git a/plugins/org.eclipse.etrice.core.room/plugin.xml b/plugins/org.eclipse.etrice.core.room/plugin.xml index cc1cf541e..7fbdd6922 100644 --- a/plugins/org.eclipse.etrice.core.room/plugin.xml +++ b/plugins/org.eclipse.etrice.core.room/plugin.xml @@ -3,6 +3,7 @@ <plugin> <extension-point id="validation" name="Room Validator" schema="schema/validation.exsd"/> + <extension-point id="modellocator" name="Model Locator" schema="schema/modellocator.exsd"/> <extension point="org.eclipse.emf.ecore.generated_package"> <package diff --git a/plugins/org.eclipse.etrice.core.room/schema/modellocator.exsd b/plugins/org.eclipse.etrice.core.room/schema/modellocator.exsd new file mode 100644 index 000000000..0324ed41b --- /dev/null +++ b/plugins/org.eclipse.etrice.core.room/schema/modellocator.exsd @@ -0,0 +1,102 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="org.eclipse.etrice.core.room" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appInfo> + <meta.schema plugin="org.eclipse.etrice.core.room" id="modellocator" name="Model Locator"/> + </appInfo> + <documentation> + [Enter description of this extension point.] + </documentation> + </annotation> + + <element name="extension"> + <annotation> + <appInfo> + <meta.element /> + </appInfo> + </annotation> + <complexType> + <choice minOccurs="1" maxOccurs="unbounded"> + <element ref="locator"/> + </choice> + <attribute name="point" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="id" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute translatable="true"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="locator"> + <complexType> + <attribute name="class" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute kind="java" basedOn=":org.eclipse.etrice.core.scoping.IModelLocator"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appInfo> + <meta.section type="since"/> + </appInfo> + <documentation> + [Enter the first release in which this extension point appears.] + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="examples"/> + </appInfo> + <documentation> + [Enter extension point usage example here.] + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="apiinfo"/> + </appInfo> + <documentation> + [Enter API information here.] + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="implementation"/> + </appInfo> + <documentation> + [Enter information about supplied implementation of this extension point.] + </documentation> + </annotation> + + +</schema> diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/RoomActivator.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/RoomActivator.java index 6144705cf..d45efae44 100644 --- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/RoomActivator.java +++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/RoomActivator.java @@ -1,6 +1,7 @@ package org.eclipse.etrice.core; import org.eclipse.core.runtime.Plugin; +import org.eclipse.etrice.core.scoping.ModelLocator; import org.eclipse.etrice.core.validation.ValidatorExtensionManager; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; @@ -15,5 +16,6 @@ public class RoomActivator extends Plugin implements BundleActivator { super.start(context); ValidatorExtensionManager.Registry.getInstance().loadValidatorExtensions(); + ModelLocator.getInstance().loadExtensions(); } } diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/scoping/IModelLocator.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/scoping/IModelLocator.java new file mode 100644 index 000000000..5a3766a76 --- /dev/null +++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/scoping/IModelLocator.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2014 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 v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.core.scoping; + +import java.io.File; + +/** + * @author Henrik Rentz-Reichert + * + */ +public interface IModelLocator { + + File locateModel(File path); +} diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/scoping/ModelLocator.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/scoping/ModelLocator.java new file mode 100644 index 000000000..a51645721 --- /dev/null +++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/scoping/ModelLocator.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2014 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 v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.core.scoping; + +import java.io.File; +import java.util.ArrayList; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.Platform; + +/** + * @author Henrik Rentz-Reichert + * + */ +public class ModelLocator { + private static final String IMODEL_LOCATOR_ID = "org.eclipse.etrice.core.room.modellocator"; + + private static ModelLocator instance = null; + private ArrayList<IModelLocator> locators = new ArrayList<IModelLocator>(); + + private ModelLocator() { + } + + public void loadExtensions() { + IConfigurationElement[] config = Platform.getExtensionRegistry() + .getConfigurationElementsFor(IMODEL_LOCATOR_ID); + + for (IConfigurationElement e : config) { + try { + final Object ext = e.createExecutableExtension("class"); + if (ext instanceof IModelLocator) { + IModelLocator locator = (IModelLocator) ext; + locators.add(locator); + } + } + catch (CoreException ex) { + System.out.println(ex.getMessage()); + } + } + } + + public static ModelLocator getInstance() { + if (instance==null) { + instance = new ModelLocator(); + } + + return instance; + } + + public File locateModel(File path) { + for (IModelLocator locator : locators) { + File result = locator.locateModel(path); + if (result!=null) + return result; + } + + return path; + } + +} diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/scoping/PlatformRelativeUriResolver.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/scoping/PlatformRelativeUriResolver.java index 0f85065e3..f268ed102 100644 --- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/scoping/PlatformRelativeUriResolver.java +++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/scoping/PlatformRelativeUriResolver.java @@ -45,12 +45,23 @@ public class PlatformRelativeUriResolver extends ImportUriResolver { @Override public String resolve(EObject object) { String resolve = super.resolve(object); + + // can't do anything about empty URIs if (resolve==null || resolve.trim().isEmpty()) return null; return resolve(resolve, object.eResource()); } + /** + * resolves a URI against the URI of a resource (usually that of the import). + * The URI is resolved against a base URI (if given), environment variables are replaced + * and the path is normalized. If possible the URI is converted into a platform URI. + * + * @param resolve the URI to resolve + * @param resource the resource against which to resolve (or @code{null}) + * @return the resolved URI as string + */ public String resolve(String resolve, Resource resource) { URI baseUri = resource==null? null : resource.getURI(); resolve = resolve(resolve, baseUri); @@ -73,6 +84,8 @@ public class PlatformRelativeUriResolver extends ImportUriResolver { private String resolve(String resolve, URI baseUri) { resolve = substituteEnvVars(resolve); + + // replace (double) slashes and backslashes with single slashes resolve = resolve.replaceAll("\\\\", "/"); resolve = resolve.replaceAll("//", "/"); @@ -135,7 +148,7 @@ public class PlatformRelativeUriResolver extends ImportUriResolver { return resolve; } - public URI getCanonicalFileURI(String uriString, URIConverter uriConverter) throws IOException { + private URI getCanonicalFileURI(String uriString, URIConverter uriConverter) throws IOException { URI uri; if (uriString.startsWith("classpath:/") || uriString.startsWith("platform:/") || uriString.startsWith("file:/")) { uri = URI.createURI(uriString); @@ -150,6 +163,10 @@ public class PlatformRelativeUriResolver extends ImportUriResolver { String can = normalized.toFileString(); File f = new File(can); + + // now we give extensions a chance to locate the model file + f = ModelLocator.getInstance().locateModel(f); + can = f.getCanonicalPath(); // e.g. remove embedded ../ URI canonical = URI.createFileURI(can); if (EMFPlugin.IS_ECLIPSE_RUNNING) { |