diff --git a/org.eclipse.xtend.m2e/META-INF/MANIFEST.MF b/org.eclipse.xtend.m2e/META-INF/MANIFEST.MF index 19b114e64d9..47acaf3c03e 100644 --- a/org.eclipse.xtend.m2e/META-INF/MANIFEST.MF +++ b/org.eclipse.xtend.m2e/META-INF/MANIFEST.MF @@ -5,15 +5,12 @@ Bundle-SymbolicName: org.eclipse.xtend.m2e;singleton:=true Bundle-Version: 2.28.0.qualifier Bundle-Localization: plugin Bundle-Vendor: %providerName -Require-Bundle: org.eclipse.m2e.core;bundle-version="[1.8.3,2.0.0)";resolution:=optional, - org.eclipse.core.resources;bundle-version="3.12.0", - org.eclipse.equinox.registry;bundle-version="3.7.0", +Require-Bundle: org.eclipse.m2e.core;bundle-version="[1.8.3,3.0.0)";resolution:=optional, org.eclipse.xtext.ui, org.eclipse.xtext.builder, org.eclipse.xtend.core, - org.eclipse.m2e.maven.runtime;bundle-version="[1.8.3,2.0.0)";resolution:=optional + org.eclipse.m2e.maven.runtime;bundle-version="[1.8.3,4.0.0)";resolution:=optional Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: org.eclipse.xtend.m2e;x-internal:=true -Import-Package: org.apache.maven.plugin;provider=m2e;resolution:=optional, - org.apache.maven.project;provider=m2e;resolution:=optional +Import-Package: org.apache.maven.plugin;provider=m2e;resolution:=optional Automatic-Module-Name: org.eclipse.xtend.m2e diff --git a/org.eclipse.xtend.m2e/src/org/eclipse/xtend/m2e/XtendProjectConfigurator.java b/org.eclipse.xtend.m2e/src/org/eclipse/xtend/m2e/XtendProjectConfigurator.java index e2ce898ddb0..399fe7a258a 100644 --- a/org.eclipse.xtend.m2e/src/org/eclipse/xtend/m2e/XtendProjectConfigurator.java +++ b/org.eclipse.xtend.m2e/src/org/eclipse/xtend/m2e/XtendProjectConfigurator.java @@ -15,9 +15,12 @@ import static org.eclipse.xtext.builder.preferences.BuilderPreferenceAccess.getOutputForSourceFolderKey; import java.io.File; +import java.lang.reflect.Method; import java.util.List; +import java.util.function.Function; import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.project.MavenProject; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ProjectScope; import org.eclipse.core.runtime.CoreException; @@ -41,12 +44,10 @@ public class XtendProjectConfigurator extends AbstractProjectConfigurator { @Override - public void configure(ProjectConfigurationRequest request, - IProgressMonitor monitor) throws CoreException { - addNature(request.getProject(), XtextProjectHelper.NATURE_ID, monitor); + public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException { + addNature(getProject(request), XtextProjectHelper.NATURE_ID, monitor); - OutputConfiguration config = new XtendOutputConfigurationProvider() - .getOutputConfigurations().iterator().next(); + OutputConfiguration config = new XtendOutputConfigurationProvider().getOutputConfigurations().iterator().next(); List executions = getMojoExecutions(request, monitor); SubMonitor progress = SubMonitor.convert(monitor, executions.size()); @@ -63,7 +64,7 @@ public void configure(ProjectConfigurationRequest request, } } - writePreferences(config, request.getProject()); + writePreferences(config, getProject(request)); } private void writePreferences(OutputConfiguration configuration, @@ -98,7 +99,7 @@ private void writePreferences(OutputConfiguration configuration, private void readCompileConfig(OutputConfiguration config, ProjectConfigurationRequest request, MojoExecution execution, SubMonitor progress) throws CoreException { - List roots = request.getMavenProject().getCompileSourceRoots(); + List roots = getMavenProject(request).getCompileSourceRoots(); progress = SubMonitor.convert(progress, roots.size()); for (String source : roots) { SourceMapping mapping = new SourceMapping(makeProjectRelative(source, request)); @@ -110,7 +111,7 @@ private void readCompileConfig(OutputConfiguration config, ProjectConfigurationR private void readTestCompileConfig(OutputConfiguration config, ProjectConfigurationRequest request, MojoExecution execution, SubMonitor progress) throws CoreException { - List roots = request.getMavenProject().getTestCompileSourceRoots(); + List roots = getMavenProject(request).getTestCompileSourceRoots(); progress = SubMonitor.convert(progress, roots.size()); for (String source : roots) { SourceMapping mapping = new SourceMapping(makeProjectRelative(source, request)); @@ -121,7 +122,7 @@ private void readTestCompileConfig(OutputConfiguration config, ProjectConfigurat } private String makeProjectRelative(String fileName, ProjectConfigurationRequest request) { - File baseDir = request.getMavenProject().getBasedir(); + File baseDir = getMavenProject(request).getBasedir(); File file = new File(fileName); String relativePath; if (file.isAbsolute()) { @@ -150,10 +151,33 @@ private void readTestDebugInfoConfig(OutputConfiguration config, ProjectConfigur config.setInstallDslAsPrimarySource( mojoParameterValue("xtendAsPrimaryDebugSource", Boolean.class, request, execution, progress)); } - + private T mojoParameterValue(String paramName, Class paramType, ProjectConfigurationRequest request, MojoExecution execution, SubMonitor progress) throws CoreException { - return maven.getMojoParameterValue(request.getMavenProject(), execution, paramName, paramType, - progress.split(1)); + return maven.getMojoParameterValue(getMavenProject(request), execution, paramName, paramType, progress.split(1)); + } + + static IProject getProject(ProjectConfigurationRequest request) { + // DO NOT USE A METHOD REFERENCE! + return call(request, r -> r.getMavenProjectFacade(), "mavenProjectFacade").getProject(); + } + + static MavenProject getMavenProject(ProjectConfigurationRequest request) { + // DO NOT USE A METHOD REFERENCE! + return call(request, r -> r.getMavenProject(), "mavenProject"); + } + + @SuppressWarnings("unchecked") + private static R call(T obj, Function getter, String newMethodName) { + try { + return getter.apply(obj); + } catch (Error er) { + try { // We are probably running with M2E >= 2.0 try the new method name + Method method = obj.getClass().getMethod(newMethodName); + return (R) method.invoke(obj); + } catch (ReflectiveOperationException e) { + throw new IllegalStateException(e); + } + } } } \ No newline at end of file