Skip to content

Commit

Permalink
Update to M2E 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Aug 14, 2022
1 parent bd3439c commit 39d6819
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
9 changes: 3 additions & 6 deletions org.eclipse.xtend.m2e/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<MojoExecution> executions = getMojoExecutions(request, monitor);
SubMonitor progress = SubMonitor.convert(monitor, executions.size());
Expand All @@ -63,7 +64,7 @@ public void configure(ProjectConfigurationRequest request,
}
}

writePreferences(config, request.getProject());
writePreferences(config, getProject(request));
}

private void writePreferences(OutputConfiguration configuration,
Expand Down Expand Up @@ -98,7 +99,7 @@ private void writePreferences(OutputConfiguration configuration,

private void readCompileConfig(OutputConfiguration config, ProjectConfigurationRequest request,
MojoExecution execution, SubMonitor progress) throws CoreException {
List<String> roots = request.getMavenProject().getCompileSourceRoots();
List<String> roots = getMavenProject(request).getCompileSourceRoots();
progress = SubMonitor.convert(progress, roots.size());
for (String source : roots) {
SourceMapping mapping = new SourceMapping(makeProjectRelative(source, request));
Expand All @@ -110,7 +111,7 @@ private void readCompileConfig(OutputConfiguration config, ProjectConfigurationR

private void readTestCompileConfig(OutputConfiguration config, ProjectConfigurationRequest request,
MojoExecution execution, SubMonitor progress) throws CoreException {
List<String> roots = request.getMavenProject().getTestCompileSourceRoots();
List<String> roots = getMavenProject(request).getTestCompileSourceRoots();
progress = SubMonitor.convert(progress, roots.size());
for (String source : roots) {
SourceMapping mapping = new SourceMapping(makeProjectRelative(source, request));
Expand All @@ -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()) {
Expand Down Expand Up @@ -150,10 +151,33 @@ private void readTestDebugInfoConfig(OutputConfiguration config, ProjectConfigur
config.setInstallDslAsPrimarySource(
mojoParameterValue("xtendAsPrimaryDebugSource", Boolean.class, request, execution, progress));
}

private <T> T mojoParameterValue(String paramName, Class<T> 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 <T, R> R call(T obj, Function<T, R> 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);
}
}
}
}

0 comments on commit 39d6819

Please sign in to comment.