Skip to content

Commit

Permalink
remove m2e reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
cdietrich authored and LorenzoBettini committed Nov 26, 2024
1 parent c5cf5ec commit ccfe593
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import static org.eclipse.xtext.builder.preferences.BuilderPreferenceAccess.getOutputForSourceFolderKey;

import java.io.File;
import java.lang.reflect.Method;
import java.util.List;

import org.apache.maven.plugin.MojoExecution;
Expand All @@ -26,7 +25,6 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator;
import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest;
import org.eclipse.xtend.core.compiler.XtendOutputConfigurationProvider;
Expand Down Expand Up @@ -158,25 +156,10 @@ private <T> T mojoParameterValue(String paramName, Class<T> paramType, ProjectCo
}

static IProject getProject(ProjectConfigurationRequest request) {
return XtendProjectConfigurator.<ProjectConfigurationRequest, IMavenProjectFacade>call(request, "getMavenProjectFacade", "mavenProjectFacade").getProject();
return request.mavenProjectFacade().getProject();
}

static MavenProject getMavenProject(ProjectConfigurationRequest request) {
return call(request, "getMavenProject", "mavenProject");
}

@SuppressWarnings("unchecked")
private static <T, R> R call(T obj, String oldMethodName, String newMethodName) {
try {
Method method = obj.getClass().getMethod(oldMethodName);
return (R) method.invoke(obj);
} catch (ReflectiveOperationException 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);
}
}
return request.mavenProject();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014, 2022 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2014, 2024 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.
Expand All @@ -24,10 +24,8 @@
import static org.eclipse.xtext.builder.preferences.BuilderPreferenceAccess.getIgnoreSourceFolderKey;
import static org.eclipse.xtext.builder.preferences.BuilderPreferenceAccess.getKey;
import static org.eclipse.xtext.builder.preferences.BuilderPreferenceAccess.getOutputForSourceFolderKey;
import org.eclipse.m2e.core.project.IMavenProjectFacade;

import java.io.File;
import java.lang.reflect.Method;
import java.util.List;

import org.apache.maven.plugin.MojoExecution;
Expand Down Expand Up @@ -129,26 +127,10 @@ private String makeProjectRelative(String fileName,
}

static IProject getProject(ProjectConfigurationRequest request) {
return XtextProjectConfigurator.<ProjectConfigurationRequest, IMavenProjectFacade>call(request, "getMavenProjectFacade", "mavenProjectFacade").getProject();
return request.mavenProjectFacade().getProject();
}

static MavenProject getMavenProject(ProjectConfigurationRequest request) {
return call(request, "getMavenProject", "mavenProject");
return request.mavenProject();
}

@SuppressWarnings("unchecked")
private static <T, R> R call(T obj, String oldMethodName, String newMethodName) {
try {
Method method = obj.getClass().getMethod(oldMethodName);
return (R) method.invoke(obj);
} catch (ReflectiveOperationException 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 ccfe593

Please sign in to comment.