diff --git a/org.eclipse.xtext.xtext.ui/src/org/eclipse/xtext/xtext/ecoreInference/ProjectAwareXtendXtext2EcorePostProcessor.java b/org.eclipse.xtext.xtext.ui/src/org/eclipse/xtext/xtext/ecoreInference/ProjectAwareXtendXtext2EcorePostProcessor.java deleted file mode 100644 index a78c9c26504..00000000000 --- a/org.eclipse.xtext.xtext.ui/src/org/eclipse/xtext/xtext/ecoreInference/ProjectAwareXtendXtext2EcorePostProcessor.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2020 Michael Clay and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - * - *******************************************************************************/ -package org.eclipse.xtext.xtext.ecoreInference; - -import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; - -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.List; - -import org.apache.log4j.Logger; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.mwe.core.resources.ResourceLoader; -import org.eclipse.emf.mwe.core.resources.ResourceLoaderImpl; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.xtext.GeneratedMetamodel; -import org.eclipse.xtext.resource.ClasspathUriUtil; - -import com.google.common.collect.Lists; - -/** - * XtendXtext2EcorePostProcessor specialization which enables the xtend post processing file to refer to - * classes and resources which are available from the classpath of the containing {@link IJavaProject}. - * - * @author szarnekow - * @author Dennis Huebner - * @deprecated This class depends on Xpand/Xtend(1) which is dead as a mouse. So don't use this post processor. Switch to a manually maintained metamodel instead. - */ -@SuppressWarnings("restriction") -@Deprecated(forRemoval = true) -public class ProjectAwareXtendXtext2EcorePostProcessor extends XtendXtext2EcorePostProcessor implements - IResourceChangeListener { - - private static final Logger logger = Logger.getLogger(ProjectAwareXtendXtext2EcorePostProcessor.class); - - private ResourceLoader resourceLoader; - - @Override - protected void fireXtendFileLoaded() { - super.fireXtendFileLoaded(); - ResourcesPlugin.getWorkspace().addResourceChangeListener(this); - } - - @Override - protected synchronized ResourceLoader getResourceLoader(GeneratedMetamodel metamodel) { - if (resourceLoader != null) - return resourceLoader; - - URI uri = metamodel.eResource().getURI(); - if (ClasspathUriUtil.isClasspathUri(uri)) { - ResourceSet resourceSet = metamodel.eResource().getResourceSet(); - uri = resourceSet.getURIConverter().normalize(uri); - } - IFile grammarFile = getWorkspace().getRoot().getFile(new Path(uri.toPlatformString(true))); - IJavaProject javaProject = JavaCore.create(grammarFile.getProject()); - try { - if (javaProject.exists()) { - ClassLoader classLoader = createClassLoader(javaProject); - resourceLoader = new ResourceLoaderImpl(classLoader); - return resourceLoader; - } - } catch (CoreException e) { - logger.error("Error creating execution context for java project '" + grammarFile.getProject().getName() - + "'", e); - } - return super.getResourceLoader(metamodel); - } - - protected ClassLoader createClassLoader(IJavaProject javaProject) throws CoreException { - List urls = Lists.newArrayListWithExpectedSize(javaProject.getResolvedClasspath(true).length); - try { - IWorkspaceRoot workspaceRoot = getWorkspace().getRoot(); - urls.addAll(getOutputFolders(javaProject)); - for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) { - IPath path = null; - URL url = null; - switch (entry.getEntryKind()) { - case IClasspathEntry.CPE_SOURCE: - break; - case IClasspathEntry.CPE_PROJECT: - IResource project = workspaceRoot.findMember(entry.getPath()); - urls.addAll(getOutputFolders(JavaCore.create(project.getProject()))); - break; - default: - path = entry.getPath(); - url = path.toFile().toURI().toURL(); - break; - } - if (url != null) { - urls.add(url); - } - } - } catch (MalformedURLException e) { - logger.error("Error creating class loader for java project '" + javaProject.getProject().getName() + "'", e); - } - return new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader()); - } - - private List getOutputFolders(IJavaProject javaProject) throws CoreException, MalformedURLException { - List result = Lists.newArrayListWithExpectedSize(1); - IPath path = javaProject.getOutputLocation().addTrailingSeparator(); - URL url = new URL(URI.createPlatformResourceURI(path.toString(), true).toString()); - result.add(url); - for (IClasspathEntry entry : javaProject.getRawClasspath()) { - switch (entry.getEntryKind()) { - case IClasspathEntry.CPE_SOURCE: - path = entry.getOutputLocation(); - if (path != null) { - url = new URL(URI.createPlatformResourceURI(path.addTrailingSeparator().toString(), true) - .toString()); - result.add(url); - } - break; - default: - break; - } - } - return result; - } - - @Override - public synchronized void resourceChanged(IResourceChangeEvent event) { - super.clearCachedXtendFile(); - resourceLoader = null; - ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); - } -} \ No newline at end of file diff --git a/org.eclipse.xtext.xtext.ui/src/org/eclipse/xtext/xtext/ui/XtextUiModule.java b/org.eclipse.xtext.xtext.ui/src/org/eclipse/xtext/xtext/ui/XtextUiModule.java index abc34813b7e..bbdecba2b7d 100644 --- a/org.eclipse.xtext.xtext.ui/src/org/eclipse/xtext/xtext/ui/XtextUiModule.java +++ b/org.eclipse.xtext.xtext.ui/src/org/eclipse/xtext/xtext/ui/XtextUiModule.java @@ -141,12 +141,6 @@ public void configureFilterTerminalRulesContribution(Binder binder) { @Deprecated(forRemoval = true) public void configureIXtext2EcorePostProcessor(Binder binder) { - try { - Class.forName("org.eclipse.xtend.expression.ExecutionContext"); - binder.bind(org.eclipse.xtext.xtext.ecoreInference.IXtext2EcorePostProcessor.class) - .to(org.eclipse.xtext.xtext.ecoreInference.ProjectAwareXtendXtext2EcorePostProcessor.class); - } catch (ClassNotFoundException e) { - } } public Class bindIXtextEditorCallback() { diff --git a/org.eclipse.xtext/META-INF/MANIFEST.MF b/org.eclipse.xtext/META-INF/MANIFEST.MF index 3dbe6c96c88..849a0968b89 100644 --- a/org.eclipse.xtext/META-INF/MANIFEST.MF +++ b/org.eclipse.xtext/META-INF/MANIFEST.MF @@ -226,8 +226,6 @@ Require-Bundle: org.eclipse.emf.ecore.xmi;bundle-version="2.16.0";visibility:=re org.objectweb.asm;bundle-version="[9.5.0,9.6.0)";resolution:=optional, org.eclipse.emf.mwe.core;bundle-version="1.9.0";resolution:=optional;visibility:=reexport, org.eclipse.emf.mwe.utils;bundle-version="1.9.0";resolution:=optional;visibility:=reexport, - org.eclipse.xtend;bundle-version="2.2.0";resolution:=optional, - org.eclipse.xtend.typesystem.emf;bundle-version="2.2.0";resolution:=optional, org.eclipse.xtext.util;visibility:=reexport, org.eclipse.core.runtime;bundle-version="3.24.100";resolution:=optional;x-installation:=greedy, org.eclipse.xtend.lib;resolution:=optional, diff --git a/org.eclipse.xtext/src/org/eclipse/xtext/XtextRuntimeModule.java b/org.eclipse.xtext/src/org/eclipse/xtext/XtextRuntimeModule.java index 981974d2005..2d4b7509b13 100644 --- a/org.eclipse.xtext/src/org/eclipse/xtext/XtextRuntimeModule.java +++ b/org.eclipse.xtext/src/org/eclipse/xtext/XtextRuntimeModule.java @@ -122,14 +122,8 @@ public Class bindIValueConverterService() { /** * @since 2.9 */ - @SuppressWarnings({"removal","deprecation"}) + @Deprecated public void configureIXtext2EcorePostProcessor(Binder binder) { - try { - Class.forName("org.eclipse.xtend.expression.ExecutionContext"); - binder.bind(org.eclipse.xtext.xtext.ecoreInference.IXtext2EcorePostProcessor.class) - .to(org.eclipse.xtext.xtext.ecoreInference.XtendXtext2EcorePostProcessor.class); - } catch (ClassNotFoundException e) { - } } @Override diff --git a/org.eclipse.xtext/src/org/eclipse/xtext/xtext/ecoreInference/XtendXtext2EcorePostProcessor.java b/org.eclipse.xtext/src/org/eclipse/xtext/xtext/ecoreInference/XtendXtext2EcorePostProcessor.java deleted file mode 100644 index 060759e9015..00000000000 --- a/org.eclipse.xtext/src/org/eclipse/xtext/xtext/ecoreInference/XtendXtext2EcorePostProcessor.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2020 itemis AG (http://www.itemis.eu) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtext.xtext.ecoreInference; - -import static org.eclipse.emf.mwe.core.resources.ResourceLoaderFactory.getCurrentThreadResourceLoader; -import static org.eclipse.emf.mwe.core.resources.ResourceLoaderFactory.setCurrentThreadResourceLoader; - -import java.io.InputStream; -import java.io.InputStreamReader; - -import org.apache.log4j.Logger; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.resource.URIConverter; -import org.eclipse.emf.mwe.core.resources.ResourceLoader; -import org.eclipse.emf.mwe.core.resources.ResourceLoaderFactory; -import org.eclipse.internal.xtend.xtend.XtendFile; -import org.eclipse.internal.xtend.xtend.ast.Extension; -import org.eclipse.xtend.XtendResourceParser; -import org.eclipse.xtend.expression.EvaluationException; -import org.eclipse.xtend.expression.ExecutionContext; -import org.eclipse.xtend.expression.ExecutionContextImpl; -import org.eclipse.xtend.expression.Resource; -import org.eclipse.xtend.type.impl.java.JavaBeansMetaModel; -import org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel; -import org.eclipse.xtext.GeneratedMetamodel; -import org.eclipse.xtext.Grammar; -import org.eclipse.xtext.resource.ClasspathUriResolutionException; -import org.eclipse.xtext.util.Strings; - -/** - * Xtend strategy for interface {@link IXtext2EcorePostProcessor} which delegates the actual post-processing behavior to - * an Xtend based implementation. - * - * @author Knut Wannheden - Initial contribution and API - * @author Michael Clay - * - * @deprecated This class depends on Xpand/Xtend(1) which is dead as a mouse. So don't use this post processor. Switch to a manually maintained metamodel instead. - */ -@Deprecated(forRemoval = true) -public class XtendXtext2EcorePostProcessor implements IXtext2EcorePostProcessor { - - private static final Logger logger = Logger.getLogger(XtendXtext2EcorePostProcessor.class); - private ExecutionContext executionContext; - private Resource xtendFile; - - @Override - public void process(GeneratedMetamodel metamodel) { - Resource xtendFile = loadXtendFile(metamodel); - if (xtendFile != null) { - logger.warn("You are using an old xtend(1)-based IXtext2EcorePostProcessor. This features is deprecated and will be dropped in a future release of Xtext."); - ExecutionContext ctx = getExecutionContext(metamodel); - ctx = ctx.cloneWithResource(xtendFile); - ResourceLoader currentThreadResourceLoader = null; - try { - currentThreadResourceLoader = getCurrentThreadResourceLoader(); - setCurrentThreadResourceLoader(getResourceLoader(metamodel)); - final Object[] params = new Object[] { metamodel }; - Extension extension = ctx.getExtension("process", params); - if (extension != null) { - extension.evaluate(params, ctx); - } - } - catch (EvaluationException e) { - logger.error("Error encountered processing metamodel " + metamodel.getName() + " with " - + xtendFile.getFullyQualifiedName(), e); - } - finally { - setCurrentThreadResourceLoader(currentThreadResourceLoader); - } - } - } - - /** - * @param metamodel - * the metamodel to augment - * @return the resource loader used to load resources during the xtend processing - */ - protected ResourceLoader getResourceLoader(GeneratedMetamodel metamodel) { - return ResourceLoaderFactory.createResourceLoader(); - } - - /** - * @param metamodel - * the metamodel to augment - * @return the executionContext used to perform the xtend processing - */ - protected ExecutionContext getExecutionContext(GeneratedMetamodel metamodel) { - if (executionContext == null) { - ExecutionContextImpl executionContext = new ExecutionContextImpl(); - executionContext.registerMetaModel(new EmfRegistryMetaModel()); - executionContext.registerMetaModel(new JavaBeansMetaModel()); - this.executionContext = executionContext; - } - return executionContext; - } - - /** - * Expects an Xtend file named MyDslPostProcessor.ext with an extension with signature - * process(xtext::GeneratedMetamodel) in the same folder as the grammar file. - * - * @param metamodel - * the metamodel to augment - * @return the xtendFile to execute - */ - protected Resource loadXtendFile(GeneratedMetamodel metamodel) { - if (xtendFile == null) { - final String extension = getExtensionName(metamodel); - try { - URI uri = getXtendFileLocation(metamodel); - if (uri != null) { - URIConverter uriConverter = metamodel.eResource().getResourceSet().getURIConverter(); - if (uriConverter.exists(uri, null)) { - InputStream in = uriConverter.createInputStream(uri); - try { - XtendResourceParser parser = new XtendResourceParser(); - xtendFile = parser.parse(new InputStreamReader(in), extension + '.' - + XtendFile.FILE_EXTENSION); - fireXtendFileLoaded(); - } finally { - if (in != null) - in.close(); - } - } - } - } catch (ClasspathUriResolutionException ignored) { - // no xtend file found - } catch (Exception e) { - logger.error("Could not parse " + extension, e); - } - } - return xtendFile; - } - - /** - * notify subclasses that the xtend file was successfully loaded - */ - protected void fireXtendFileLoaded() { - // Can't make it abstract - public API - } - - /** - * Sets cached Xtend file to null so it can be reloaded in {@link XtendXtext2EcorePostProcessor#loadXtendFile(GeneratedMetamodel)} - */ - protected final void clearCachedXtendFile() { - this.xtendFile = null; - } - - protected String getExtensionName(GeneratedMetamodel metamodel) { - final Grammar grammar = (Grammar) metamodel.eContainer(); - final String extension = grammar.getName().replace(".", "::") + "PostProcessor"; - return extension; - } - - protected URI getXtendFileLocation(GeneratedMetamodel metamodel) { - URI uri = metamodel.eResource().getURI(); - // check if uri can be used for resolve - if (!uri.isHierarchical() || uri.isRelative()) - return null; - uri = URI.createURI(Strings.lastToken(getExtensionName(metamodel), "::")).appendFileExtension( - XtendFile.FILE_EXTENSION).resolve(uri); - return uri; - } - -} \ No newline at end of file