diff options
author | sboyko | 2015-04-29 13:52:14 +0000 |
---|---|---|
committer | sboyko | 2015-04-29 13:52:14 +0000 |
commit | ed23ca0662f64fd3092355713a9e5ed745903bec (patch) | |
tree | 2eeff1fc876100eb6d017374ade1f87c2fda3606 /plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m | |
parent | 3270f915769723b6170d5a7ca55ddc29407e3591 (diff) | |
download | org.eclipse.qvto-ed23ca0662f64fd3092355713a9e5ed745903bec.tar.gz org.eclipse.qvto-ed23ca0662f64fd3092355713a9e5ed745903bec.tar.xz org.eclipse.qvto-ed23ca0662f64fd3092355713a9e5ed745903bec.zip |
[319076] - org.eclipse.m2m.qvt.oml.runtime.qvtTransformation extension
point not explained in documentation
[465184] - Make DeployedImportResolver aware of plugin source containers
Cherry picked from 'cgerking/319076'
Diffstat (limited to 'plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m')
5 files changed, 31 insertions, 226 deletions
diff --git a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/DeployedImportResolver.java b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/DeployedImportResolver.java index 196118e82..d1ea3477d 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/DeployedImportResolver.java +++ b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/DeployedImportResolver.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2014 Borland Software Corporation and others. + * Copyright (c) 2007, 2015 Borland Software Corporation and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,238 +8,47 @@ * * Contributors: * Borland Software Corporation - initial API and implementation + * Christopher Gerking - bugs 319076, 465184 *******************************************************************************/ package org.eclipse.m2m.internal.qvt.oml.runtime.project; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl; -import org.eclipse.m2m.internal.qvt.oml.common.MDAConstants; -import org.eclipse.m2m.internal.qvt.oml.common.io.CFile; -import org.eclipse.m2m.internal.qvt.oml.common.io.CFolder; -import org.eclipse.m2m.internal.qvt.oml.common.io.eclipse.BundleFile; -import org.eclipse.m2m.internal.qvt.oml.common.io.eclipse.BundleModuleRegistry; -import org.eclipse.m2m.internal.qvt.oml.common.project.IRegistryConstants; +import org.eclipse.m2m.internal.qvt.oml.common.project.CompiledTransformation; import org.eclipse.m2m.internal.qvt.oml.common.project.TransformationRegistry; import org.eclipse.m2m.internal.qvt.oml.compiler.BlackboxUnitResolver; import org.eclipse.m2m.internal.qvt.oml.compiler.DelegatingUnitResolver; -import org.eclipse.m2m.internal.qvt.oml.compiler.LegacyResolverSupport; -import org.eclipse.m2m.internal.qvt.oml.compiler.ResolverUtils; -import org.eclipse.m2m.internal.qvt.oml.compiler.UnitContents; import org.eclipse.m2m.internal.qvt.oml.compiler.UnitProxy; -import org.eclipse.m2m.internal.qvt.oml.compiler.UnitResolver; +import org.eclipse.m2m.internal.qvt.oml.compiler.UnitResolverFactory; -public class DeployedImportResolver extends DelegatingUnitResolver implements LegacyResolverSupport { +public class DeployedImportResolver extends DelegatingUnitResolver { /** * A single instance registry including all bundles with registered QVT * modules in the platform. */ - public static DeployedImportResolver INSTANCE = new DeployedImportResolver(createModulesRegistry()); - - private List<BundleModuleRegistry> bundleModules; + public static final DeployedImportResolver INSTANCE = new DeployedImportResolver(QvtTransformationRegistry.getInstance()); + + private TransformationRegistry transformationRegistry; + /** - * Constructs resolver based on the given list of bundle registries. + * Constructs a resolver based on the given transformation registry. * - * @param bundleRegistryList - * a list registries of QVT module files per installed bundle + * @param transformationRegistry + * a registry of deployed QVT transformations */ - protected DeployedImportResolver(List<BundleModuleRegistry> bundleRegistryList) { - if(bundleRegistryList == null) { + private DeployedImportResolver(TransformationRegistry transformationRegistry) { + if(transformationRegistry == null) { throw new IllegalArgumentException(); } - bundleModules = bundleRegistryList; + this.transformationRegistry = transformationRegistry; setParent(BlackboxUnitResolver.DEFAULT); } - - protected List<BundleModuleRegistry> getBundleModules() { - return bundleModules; - } - - public String getPackageName(CFolder folder) { - if(folder == null) { - return ""; //$NON-NLS-1$ - } - return ResolverUtils.toQualifiedName(folder.getFullPath().replace('\\', IPath.SEPARATOR)); - } - - public CFile resolveImport(String importedUnitName) { - if(importedUnitName == null || importedUnitName.length() == 0) { - return null; - } - - IPath fullPath = new Path(ResolverUtils.toNamespaceRelativeUnitFilePath(importedUnitName)); - - for (BundleModuleRegistry nextRegistry : bundleModules) { - if (nextRegistry.fileExists(fullPath)) { - return new BundleFile(fullPath, nextRegistry); - } - } - - return resolveResourcePluginPath(importedUnitName); - } - - private CFile resolveResourcePluginPath(String importedUnitName) { - try { - URI uri = URI.createURI(importedUnitName); - String[] segments = uri.segments(); - if (segments.length > 0 - && Platform.getBundle(segments[0]) != null - && MDAConstants.QVTO_FILE_EXTENSION.equals(uri.fileExtension())) { - URI pathUri = URI.createURI(""); //$NON-NLS-1$ - for (int i = 1; i < segments.length; ++i) { - pathUri = pathUri.appendSegment(segments[i]); - } - IPath ipath = new Path(pathUri.toFileString()); - BundleModuleRegistry newBundle = new BundleModuleRegistry(segments[0], Collections.singletonList(ipath)); - bundleModules.add(newBundle); - return new BundleFile(ipath, newBundle); - } - } - catch (Exception e) { - } - return null; - } - - private static List<BundleModuleRegistry> createModulesRegistry() { - // collect transformation plugins - final Map<String, List<IPath>> allQvtFilesMap = new HashMap<String, List<IPath>>(); - - QvtTransformationRegistry.getInstance().getTransformations( - new TransformationRegistry.Filter() { - public boolean accept(IConfigurationElement element) { - String namespaceID = element.getNamespaceIdentifier(); - List<IPath> filesValue = allQvtFilesMap.get(namespaceID); - if(filesValue == null) { - filesValue = new ArrayList<IPath>(); - allQvtFilesMap.put(namespaceID, filesValue); - } - String qvtFilePath = element.getAttribute(IRegistryConstants.FILE); - if(qvtFilePath != null) { - filesValue.add(new Path(qvtFilePath)); - } - - return false; - } - } - ); - - List<BundleModuleRegistry> registryEntries = new ArrayList<BundleModuleRegistry>(); - for (String nextID : allQvtFilesMap.keySet()) { - List<IPath> qvtFiles = allQvtFilesMap.get(nextID); - registryEntries.add(new BundleModuleRegistry(nextID, qvtFiles)); - } - return registryEntries; - } @Override protected UnitProxy doResolveUnit(String qualifiedName) { - CFile resolved = resolveImport(qualifiedName); - if(resolved == null) { - return null; - } - - BundleFile bundleFile = (BundleFile) resolved; - return createUnit(qualifiedName, createBundFileURI(bundleFile)); - } - - /** - * Legacy support for imports from deployed transformations - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=240192 - * <p> - * The logic has been taken from {@link #resolveImport(CFile, String)} - */ - public UnitProxy resolveUnit(UnitProxy fromUnit, String qualifiedName) { - ExtensibleURIConverterImpl uriConverter = new ExtensibleURIConverterImpl(); - - /** - * Resolving algorithm is unified with the workspace resolver. So the following steps are performed: - * - * 1. Try resolving against source container (which is plug-in's root in case of deployed resolver) - * - * In case passed name is "short" then additionally do: - * - * 2. Try same folder as parent unit - * - */ - - URI parentURI = fromUnit.getURI().trimSegments(1); - if (parentURI.isPlatform()) { - parentURI = parentURI.trimSegments(parentURI.segmentCount()-2); - } - - { - IPath path = new Path(parentURI.toPlatformString(true)).append(ResolverUtils.toNamespaceRelativeUnitFilePath(qualifiedName)); - URI uri = URI.createPlatformPluginURI(path.toString(), false); - - if(uriConverter.exists(uri, Collections.emptyMap())) { - return createUnit(qualifiedName, uri); - } - } - - String namespace = fromUnit.getNamespace(); - if (namespace != null && qualifiedName.contains(String.valueOf(UnitProxy.NAMESPACE_SEP)) == false) { - qualifiedName = namespace + String.valueOf(UnitProxy.NAMESPACE_SEP) + qualifiedName; - - IPath path = new Path(parentURI.toPlatformString(true)).append(qualifiedName.replace('.', '/')); - URI uri = URI.createPlatformPluginURI(path.toString(), false).appendFileExtension(MDAConstants.QVTO_FILE_EXTENSION); - - if(uriConverter.exists(uri, Collections.emptyMap())) { - return createUnit(qualifiedName, uri); - } - } - - return null; - } - - private static URI createBundFileURI(BundleFile bundleFile) { - return URI.createPlatformPluginURI(bundleFile.getBundleSymbolicName() + "/" + //$NON-NLS-1$ - bundleFile.getFullPath(), false); - } - - public UnitProxy createUnit(final String qualifiedName, final URI uri) { - String name = uri.trimFileExtension().lastSegment(); - String namespace = null; - - if(qualifiedName.length() > name.length()) { - namespace = qualifiedName.substring(0, qualifiedName.length() - name.length() - 1); - } - - return new UnitProxy(namespace, name, uri) { - @Override - public int getContentType() { - return UnitProxy.TYPE_CST_STREAM; - } - - @Override - public UnitResolver getResolver() { - return DeployedImportResolver.this; - } - - @Override - public UnitContents getContents() throws IOException { - return new UnitContents.CSTContents() { - public Reader getContents() throws IOException { - return new InputStreamReader(new ExtensibleURIConverterImpl() - .createInputStream(uri), ResourcesPlugin.getEncoding()); - } - }; - } - }; + CompiledTransformation transformation = transformationRegistry.getSingleTransformationById(qualifiedName); + + return transformation == null ? null : UnitResolverFactory.Registry.INSTANCE.getUnit(transformation.getUri()); } } diff --git a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/PlatformPluginUnitResolver.java b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/PlatformPluginUnitResolver.java index 1d47aef66..b99fea722 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/PlatformPluginUnitResolver.java +++ b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/PlatformPluginUnitResolver.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2014 Borland Software Corporation and others. + * Copyright (c) 2009, 2015 Borland Software Corporation and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -37,6 +37,7 @@ import org.eclipse.m2m.internal.qvt.oml.compiler.ResolverUtils; import org.eclipse.m2m.internal.qvt.oml.compiler.UnitContents; import org.eclipse.m2m.internal.qvt.oml.compiler.UnitProxy; import org.eclipse.m2m.internal.qvt.oml.compiler.UnitResolver; +import org.eclipse.m2m.internal.qvt.oml.runtime.QvtRuntimePlugin; import org.osgi.framework.Bundle; /** @@ -44,7 +45,7 @@ import org.osgi.framework.Bundle; */ public class PlatformPluginUnitResolver extends DelegatingUnitResolver { - private static final String SOURCE_CONTAINER_POINT = "org.eclipse.m2m.qvt.oml.runtime.qvtTransformationContainer"; //$NON-NLS-1$ + private static final String SOURCE_CONTAINER_POINT = QvtRuntimePlugin.ID + ".qvtTransformationContainer"; //$NON-NLS-1$ private static final String SOURCE_CONTAINER = "sourceContainer"; //$NON-NLS-1$ private static final String CONTAINER_PATH = "path"; //$NON-NLS-1$ @@ -139,7 +140,8 @@ public class PlatformPluginUnitResolver extends DelegatingUnitResolver { if (containers != null) { return containers.toArray(new IPath[containers.size()]); } - return new IPath[] { new Path("/") }; //$NON-NLS-1$ + + return new IPath[] { Path.ROOT }; } diff --git a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/PlatformPluginUnitResolverFactory.java b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/PlatformPluginUnitResolverFactory.java index bc468b444..570bc6976 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/PlatformPluginUnitResolverFactory.java +++ b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/PlatformPluginUnitResolverFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 Borland Software Corporation and others. + * Copyright (c) 2015 Borland Software Corporation and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -45,8 +45,8 @@ public class PlatformPluginUnitResolverFactory extends UnitResolverFactory { URI sourceFolderURI = ResolverUtils.getSourceFolderURI(uri); if(sourceFolderURI != null && sourceFolderURI.segmentCount() > 2) { - IPath plugingRelativePath = new Path(sourceFolderURI.toPlatformString(true)).removeFirstSegments(1); - resolver = new PlatformPluginUnitResolver(bundle, plugingRelativePath); + IPath pluginRelativePath = new Path(sourceFolderURI.toPlatformString(true)).removeFirstSegments(1); + resolver = new PlatformPluginUnitResolver(bundle, pluginRelativePath); } else { resolver = new PlatformPluginUnitResolver(bundle); } diff --git a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/QvtCompiledTransformation.java b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/QvtCompiledTransformation.java index d628ebfa9..bcbc0a310 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/QvtCompiledTransformation.java +++ b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/QvtCompiledTransformation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2014 Borland Software Corporation and others. + * Copyright (c) 2007, 2015 Borland Software Corporation and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -26,10 +26,8 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.m2m.internal.qvt.oml.common.MdaException; -import org.eclipse.m2m.internal.qvt.oml.common.io.CFile; import org.eclipse.m2m.internal.qvt.oml.common.project.CompiledTransformation; import org.eclipse.m2m.internal.qvt.oml.compiler.ResolverUtils; -import org.eclipse.m2m.internal.qvt.oml.emf.util.EmfUtil; import org.eclipse.m2m.internal.qvt.oml.emf.util.ModelContent; import org.eclipse.m2m.internal.qvt.oml.runtime.generator.TransformationRunner; import org.eclipse.m2m.internal.qvt.oml.runtime.project.config.QvtConfigurationProperty; @@ -80,12 +78,7 @@ public class QvtCompiledTransformation implements QvtTransformation, CompiledTra } public URI getUri() { - DeployedImportResolver importResolver = DeployedImportResolver.INSTANCE; - CFile srcFile = importResolver.resolveImport(myId); - if (srcFile != null) { - return EmfUtil.makeUri(srcFile.toString()); - } - return URI.createPlatformPluginURI(myId, false); + return URI.createPlatformPluginURI(myNamespace, false).appendSegments(transformationFilePath.segments()); } public String getNamespace() { diff --git a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/QvtTransformationRegistry.java b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/QvtTransformationRegistry.java index a451eb8c3..0e05e895b 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/QvtTransformationRegistry.java +++ b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/project/QvtTransformationRegistry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Borland Software Corporation and others. + * Copyright (c) 2007, 2015 Borland Software Corporation and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -16,6 +16,7 @@ import org.eclipse.m2m.internal.qvt.oml.common.MdaException; import org.eclipse.m2m.internal.qvt.oml.common.project.CompiledTransformation; import org.eclipse.m2m.internal.qvt.oml.common.project.IRegistryConstants; import org.eclipse.m2m.internal.qvt.oml.common.project.TransformationRegistry; +import org.eclipse.m2m.internal.qvt.oml.runtime.QvtRuntimePlugin; public class QvtTransformationRegistry extends TransformationRegistry { private QvtTransformationRegistry() { @@ -41,5 +42,5 @@ public class QvtTransformationRegistry extends TransformationRegistry { private static final QvtTransformationRegistry ourInstance = new QvtTransformationRegistry(); - public static final String POINT = "org.eclipse.m2m.qvt.oml.runtime.qvtTransformation"; //$NON-NLS-1$ + public static final String POINT = QvtRuntimePlugin.ID + ".qvtTransformation"; //$NON-NLS-1$ } |