Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2013-06-16 12:38:55 +0000
committerIgor Fedorenko2013-06-16 14:00:14 +0000
commit83f6d238b62f35d5be5f4f58c01bd6af33ecef39 (patch)
tree24eea3348a7b815ec66746dc7ddc12f4c2c67c12
parentd3d72dd5f8f7b003c6619d18cb1b98d7ea6df932 (diff)
downloadm2e-core-83f6d238b62f35d5be5f4f58c01bd6af33ecef39.tar.gz
m2e-core-83f6d238b62f35d5be5f4f58c01bd6af33ecef39.tar.xz
m2e-core-83f6d238b62f35d5be5f4f58c01bd6af33ecef39.zip
Fixed missing error marker when builder can't read pom.xml
Also reworked MavenBuilder to reconsile code paths used during build() and clean() methods. Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilder.java256
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java2
2 files changed, 125 insertions, 133 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilder.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilder.java
index f5643858..2fb8e8ec 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilder.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilder.java
@@ -34,194 +34,184 @@ import org.apache.maven.project.MavenProject;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.ICallable;
-import org.eclipse.m2e.core.embedder.IMavenConfiguration;
import org.eclipse.m2e.core.embedder.IMavenExecutionContext;
import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.internal.M2EUtils;
import org.eclipse.m2e.core.internal.MavenPluginActivator;
-import org.eclipse.m2e.core.internal.embedder.MavenImpl;
+import org.eclipse.m2e.core.internal.embedder.MavenExecutionContext;
import org.eclipse.m2e.core.internal.markers.IMavenMarkerManager;
+import org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
-import org.eclipse.m2e.core.project.IMavenProjectRegistry;
import org.eclipse.m2e.core.project.IProjectConfigurationManager;
+import org.eclipse.m2e.core.project.ResolverConfiguration;
import org.eclipse.m2e.core.project.configurator.AbstractBuildParticipant;
import org.eclipse.m2e.core.project.configurator.ILifecycleMapping;
import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
public class MavenBuilder extends IncrementalProjectBuilder implements DeltaProvider {
- /*package*/static Logger log = LoggerFactory.getLogger(MavenBuilder.class);
+ static final Logger log = LoggerFactory.getLogger(MavenBuilder.class);
- /*package*/final MavenBuilderImpl builder = new MavenBuilderImpl(this);
+ final MavenBuilderImpl builder = new MavenBuilderImpl(this);
- /*package*/final MavenImpl maven = MavenPluginActivator.getDefault().getMaven();
+ private abstract class BuildMethod<T> {
+ final ProjectRegistryManager projectManager = MavenPluginActivator.getDefault().getMavenProjectManagerImpl();
- /*package*/final IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();
+ final IProjectConfigurationManager configurationManager = MavenPlugin.getProjectConfigurationManager();
- /*package*/final IProjectConfigurationManager configurationManager = MavenPlugin.getProjectConfigurationManager();
+ final IMavenMarkerManager markerManager = MavenPluginActivator.getDefault().getMavenMarkerManager();
- /*package*/final IMavenConfiguration mavenConfiguration = MavenPlugin.getMavenConfiguration();
+ public BuildMethod() {
- /*package*/final IMavenMarkerManager markerManager = MavenPluginActivator.getDefault().getMavenMarkerManager();
+ }
- /*
- * @see org.eclipse.core.internal.events.InternalBuilder#build(int,
- * java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
- */
- protected IProject[] build(final int kind, final Map<String, String> args, final IProgressMonitor monitor)
- throws CoreException {
- final IProject project = getProject();
- log.debug("Building project {}", project.getName()); //$NON-NLS-1$
- final long start = System.currentTimeMillis();
+ public final T execute(final int kind, final Map<String, String> args, IProgressMonitor monitor)
+ throws CoreException {
+ final IProject project = getProject();
+ markerManager.deleteMarkers(project, kind == FULL_BUILD || kind == CLEAN_BUILD, IMavenConstants.MARKER_BUILD_ID);
+ final IFile pomResource = project.getFile(IMavenConstants.POM_FILE_NAME);
+ if(pomResource == null) {
+ return null;
+ }
- markerManager.deleteMarkers(project, kind == FULL_BUILD, IMavenConstants.MARKER_BUILD_ID);
+ ResolverConfiguration resolverConfiguration = configurationManager.getResolverConfiguration(project);
- if(!project.hasNature(IMavenConstants.NATURE_ID)) {
- return null;
- }
+ if(resolverConfiguration == null) {
+ // TODO unit test me
+ return null;
+ }
- final IFile pomResource = project.getFile(IMavenConstants.POM_FILE_NAME);
- if(pomResource == null) {
- log.error("Project {} does not have pom.xml", project.getName());
- return null;
- }
+ final MavenExecutionContext context = projectManager.createExecutionContext(pomResource, resolverConfiguration);
- return maven.execute(new ICallable<IProject[]>() {
- public IProject[] call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
- final IMavenProjectFacade projectFacade = getProjectFacade(pomResource, project, monitor);
+ return context.execute(new ICallable<T>() {
+ @Override
+ public T call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
+ final IMavenProjectFacade projectFacade = getProjectFacade(project, monitor);
- if(projectFacade == null) {
- // TODO unit test me
- return null;
- }
+ if(projectFacade == null) {
+ return null;
+ }
- return projectManager.execute(projectFacade, new ICallable<IProject[]>() {
- public IProject[] call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
- try {
- // make sure projectFacade has MavenProject instance loaded
- projectFacade.getMavenProject(monitor);
- } catch(CoreException ce) {
- //unable to read the project facade
- addErrorMarker(project, ce);
- monitor.done();
- return null;
- }
+ MavenProject mavenProject;
+ try {
+ // make sure projectFacade has MavenProject instance loaded
+ mavenProject = projectFacade.getMavenProject(monitor);
+ } catch(CoreException ce) {
+ //unable to read the project facade
+ addErrorMarker(project, ce);
+ return null;
+ }
- ILifecycleMapping lifecycleMapping = configurationManager.getLifecycleMapping(projectFacade);
- if(lifecycleMapping == null) {
- return null;
- }
- Map<MojoExecutionKey, List<AbstractBuildParticipant>> buildParticipantsByMojoExecutionKey = lifecycleMapping
- .getBuildParticipants(projectFacade, monitor);
+ return context.execute(mavenProject, new ICallable<T>() {
+ public T call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
+ ILifecycleMapping lifecycleMapping = configurationManager.getLifecycleMapping(projectFacade);
+ if(lifecycleMapping == null) {
+ return null;
+ }
- Set<IProject> dependencies = builder.build(context.getSession(), projectFacade, kind, args,
- buildParticipantsByMojoExecutionKey, monitor);
+ Map<MojoExecutionKey, List<AbstractBuildParticipant>> buildParticipantsByMojoExecutionKey = lifecycleMapping
+ .getBuildParticipants(projectFacade, monitor);
- log.debug("Built project {} in {} ms", project.getName(), System.currentTimeMillis() - start); //$NON-NLS-1$
- if(dependencies.isEmpty()) {
- return null;
+ return method(context, projectFacade, buildParticipantsByMojoExecutionKey, kind, args, monitor);
}
- return dependencies.toArray(new IProject[dependencies.size()]);
- }
- }, monitor);
- }
- }, monitor);
-
- }
+ }, monitor);
+ }
+ }, monitor);
+ }
- protected void clean(final IProgressMonitor monitor) throws CoreException {
- final IProject project = getProject();
+ abstract T method(IMavenExecutionContext context, IMavenProjectFacade projectFacade,
+ Map<MojoExecutionKey, List<AbstractBuildParticipant>> buildParticipantsByMojoExecutionKey, int kind,
+ Map<String, String> args, IProgressMonitor monitor) throws CoreException;
- markerManager.deleteMarkers(project, IMavenConstants.MARKER_BUILD_ID);
+ void addErrorMarker(IProject project, Exception e) {
+ String msg = e.getMessage();
+ String rootCause = M2EUtils.getRootCauseMessage(e);
+ if(!e.equals(msg)) {
+ msg = msg + ": " + rootCause; //$NON-NLS-1$
+ }
- if(!project.hasNature(IMavenConstants.NATURE_ID)) {
- return;
+ markerManager.addMarker(project, IMavenConstants.MARKER_BUILD_ID, msg, 1, IMarker.SEVERITY_ERROR);
}
- final IFile pomResource = project.getFile(IMavenConstants.POM_FILE_NAME);
- if(pomResource == null) {
- return;
- }
+ IMavenProjectFacade getProjectFacade(final IProject project, final IProgressMonitor monitor) throws CoreException {
+ final IFile pomResource = project.getFile(IMavenConstants.POM_FILE_NAME);
+
+ // facade refresh should be forced whenever pom.xml has changed
+ // there is no delta info for full builds
+ // but these are usually forced from Project/Clean
+ // so assume pom did not change
+ boolean force = false;
+
+ IResourceDelta delta = getDelta(project);
+ if(delta != null) {
+ delta = delta.findMember(pomResource.getFullPath());
+ force = delta != null && delta.getKind() == IResourceDelta.CHANGED;
+ }
- maven.execute(new ICallable<Void>() {
- public Void call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
- final IMavenProjectFacade projectFacade = projectManager.create(getProject(), monitor);
+ IMavenProjectFacade projectFacade = projectManager.getProject(project);
+ if(force || projectFacade == null || projectFacade.isStale()) {
+ projectManager.refresh(Collections.singleton(pomResource), monitor);
+ projectFacade = projectManager.getProject(project);
if(projectFacade == null) {
+ // error marker should have been created
return null;
}
+ }
- return projectManager.execute(projectFacade, new ICallable<Void>() {
- public Void call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
-
- // 380096 make sure facade.getMavenProject() is not null
- if(projectFacade.getMavenProject(monitor) == null) {
- return null;
- }
-
- ILifecycleMapping lifecycleMapping = configurationManager.getLifecycleMapping(projectFacade);
- if(lifecycleMapping == null) {
- return null;
- }
+ return projectFacade;
+ }
+ }
- Map<MojoExecutionKey, List<AbstractBuildParticipant>> buildParticipantsByMojoExecutionKey = lifecycleMapping
- .getBuildParticipants(projectFacade, monitor);
+ private BuildMethod<IProject[]> methodBuild = new BuildMethod<IProject[]>() {
+ @Override
+ protected IProject[] method(IMavenExecutionContext context, IMavenProjectFacade projectFacade,
+ Map<MojoExecutionKey, List<AbstractBuildParticipant>> buildParticipantsByMojoExecutionKey, int kind,
+ Map<String, String> args, IProgressMonitor monitor) throws CoreException {
- MavenProject mavenProject = null;
- try {
- mavenProject = projectFacade.getMavenProject(monitor);
- } catch(CoreException ce) {
- //the pom cannot be read. don't fill the log full of junk, just add an error marker
- addErrorMarker(project, ce);
- return null;
- }
+ Set<IProject> dependencies = builder.build(context.getSession(), projectFacade, kind, args,
+ buildParticipantsByMojoExecutionKey, monitor);
- builder.clean(context.getSession(), projectFacade, buildParticipantsByMojoExecutionKey, monitor);
- return null;
- }
- }, monitor);
+ if(dependencies.isEmpty()) {
+ return null;
}
- }, monitor);
- }
- /*package*/void addErrorMarker(IProject project, Exception e) {
- String msg = e.getMessage();
- String rootCause = M2EUtils.getRootCauseMessage(e);
- if(!e.equals(msg)) {
- msg = msg + ": " + rootCause; //$NON-NLS-1$
+ return dependencies.toArray(new IProject[dependencies.size()]);
}
+ };
- IMavenMarkerManager markerManager = MavenPluginActivator.getDefault().getMavenMarkerManager();
- markerManager.addMarker(project, IMavenConstants.MARKER_BUILD_ID, msg, 1, IMarker.SEVERITY_ERROR);
- }
+ private BuildMethod<Void> methodClean = new BuildMethod<Void>() {
+ @Override
+ protected Void method(IMavenExecutionContext context, IMavenProjectFacade projectFacade,
+ Map<MojoExecutionKey, List<AbstractBuildParticipant>> buildParticipantsByMojoExecutionKey, int kind,
+ Map<String, String> args, IProgressMonitor monitor) throws CoreException {
- /*package*/IMavenProjectFacade getProjectFacade(final IFile pomResource, final IProject project,
- final IProgressMonitor monitor) throws CoreException {
+ builder.clean(context.getSession(), projectFacade, buildParticipantsByMojoExecutionKey, monitor);
- // facade refresh should be forced whenever pom.xml has changed
- // there is no delta info for full builds
- // but these are usually forced from Project/Clean
- // so assume pom did not change
- boolean force = false;
+ return null;
+ }
+ };
- IResourceDelta delta = getDelta(project);
- if(delta != null) {
- delta = delta.findMember(pomResource.getFullPath());
- force = delta != null && delta.getKind() == IResourceDelta.CHANGED;
+ protected IProject[] build(final int kind, final Map<String, String> args, final IProgressMonitor monitor)
+ throws CoreException {
+ log.debug("Building project {}", getProject().getName()); //$NON-NLS-1$
+ final long start = System.currentTimeMillis();
+ try {
+ return methodBuild.execute(kind, args, monitor);
+ } finally {
+ log.debug("Built project {} in {} ms", getProject().getName(), System.currentTimeMillis() - start); //$NON-NLS-1$
}
+ }
- IMavenProjectFacade projectFacade = projectManager.create(getProject(), monitor);
+ protected void clean(final IProgressMonitor monitor) throws CoreException {
+ log.debug("Cleaning project {}", getProject().getName()); //$NON-NLS-1$
+ final long start = System.currentTimeMillis();
- if(force || projectFacade == null || projectFacade.isStale()) {
- projectManager.refresh(Collections.singleton(pomResource), monitor);
- projectFacade = projectManager.create(project, monitor);
- if(projectFacade == null) {
- // error marker should have been created
- return null;
- }
+ try {
+ methodClean.execute(CLEAN_BUILD, Collections.<String, String> emptyMap(), monitor);
+ } finally {
+ log.debug("Cleaned project {} in {} ms", getProject().getName(), System.currentTimeMillis() - start); //$NON-NLS-1$
}
-
- return projectFacade;
}
private static final List<BuildDebugHook> debugHooks = new ArrayList<BuildDebugHook>();
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java
index e9910685..81dc71ca 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java
@@ -628,6 +628,8 @@ public class MavenImpl implements IMaven, IMavenConfigurationChangeListener {
result.setDependencyResolutionResult(projectBuildingResult.getDependencyResolutionResult());
}
result.addException(ex);
+ } catch(RuntimeException e) {
+ result.addException(e);
} finally {
log.debug("Read Maven project: {} in {} ms", pomFile.getAbsoluteFile(), System.currentTimeMillis() - start); //$NON-NLS-1$
}

Back to the top