Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.m2e.core')
-rw-r--r--org.eclipse.m2e.core/plugin.xml1
-rw-r--r--org.eclipse.m2e.core/schema/incrementalBuildFrameworks.exsd119
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/ExtensionReader.java28
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/BuildResultCollector.java112
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/IIncrementalBuildFramework.java51
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java109
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/AbstractEclipseBuildContext.java98
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/EclipseBuildContext.java6
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/EclipseEmptyBuildContext.java7
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/EclipseIncrementalBuildContext.java7
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/PlexusBuildAPI.java64
11 files changed, 464 insertions, 138 deletions
diff --git a/org.eclipse.m2e.core/plugin.xml b/org.eclipse.m2e.core/plugin.xml
index 1651122e..4ebc5e64 100644
--- a/org.eclipse.m2e.core/plugin.xml
+++ b/org.eclipse.m2e.core/plugin.xml
@@ -18,6 +18,7 @@
<extension-point id="artifactFilters" name="%extension-point.artifactFilters-name" schema="schema/artifactFilters.exsd"/>
<extension-point id="projectConversionParticipants" name="%extension-point.projectConversionParticipants.name" schema="schema/projectConversionParticipants.exsd"/>
<extension-point id="conversionEnabler" name="%extension-point.conversionEnabler.name" schema="schema/conversionEnabler.exsd"/>
+ <extension-point id="incrementalBuildFrameworks" name="%extension-point.incrementalBuildFrameworks.name" schema="schema/incrementalBuildFrameworks.exsd"/>
<extension point="org.eclipse.core.runtime.contentTypes">
<content-type id="pomFile" name="%content-type.name"
diff --git a/org.eclipse.m2e.core/schema/incrementalBuildFrameworks.exsd b/org.eclipse.m2e.core/schema/incrementalBuildFrameworks.exsd
new file mode 100644
index 00000000..fdee7807
--- /dev/null
+++ b/org.eclipse.m2e.core/schema/incrementalBuildFrameworks.exsd
@@ -0,0 +1,119 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.m2e.core" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.m2e.core" id="incrementalBuildFrameworks" name="%extension-point.incrementalBuildFrameworks.name"/>
+ </appInfo>
+ <documentation>
+ Incremental build framework adapter
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="1" maxOccurs="unbounded">
+ <element ref="framework"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="framework">
+ <annotation>
+ <documentation>
+ This extension is part of work in progress and can be changed or removed without notice.
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.m2e.core.internal.builder.IncrementalBuildFramework"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ 1.6
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiinfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+ Copyright (c) 2014 Takari, Inc.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Eclipse Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/epl-v10.html
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/ExtensionReader.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/ExtensionReader.java
index 9fb1f39f..ae29f6bb 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/ExtensionReader.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/ExtensionReader.java
@@ -28,6 +28,7 @@ import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.m2e.core.internal.archetype.ArchetypeCatalogFactory;
+import org.eclipse.m2e.core.internal.builder.IIncrementalBuildFramework;
import org.eclipse.m2e.core.project.IMavenProjectChangedListener;
@@ -44,6 +45,9 @@ public class ExtensionReader {
public static final String EXTENSION_PROJECT_CHANGED_EVENT_LISTENERS = IMavenConstants.PLUGIN_ID
+ ".mavenProjectChangedListeners"; //$NON-NLS-1$
+ public static final String EXTENSION_INCREMENTAL_BUILD_FRAMEWORKS = IMavenConstants.PLUGIN_ID
+ + ".incrementalBuildFrameworks"; //$NON-NLS-1$
+
private static final String ELEMENT_LOCAL_ARCHETYPE = "local"; //$NON-NLS-1$
private static final String ELEMENT_REMOTE_ARCHETYPE = "remote"; //$NON-NLS-1$
@@ -128,4 +132,28 @@ public class ExtensionReader {
return listeners;
}
+
+ public static List<IIncrementalBuildFramework> readIncrementalBuildFrameworks() {
+ ArrayList<IIncrementalBuildFramework> frameworks = new ArrayList<IIncrementalBuildFramework>();
+
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint mappingsExtensionPoint = registry.getExtensionPoint(EXTENSION_INCREMENTAL_BUILD_FRAMEWORKS);
+ if(mappingsExtensionPoint != null) {
+ IExtension[] mappingsExtensions = mappingsExtensionPoint.getExtensions();
+ for(IExtension extension : mappingsExtensions) {
+ IConfigurationElement[] elements = extension.getConfigurationElements();
+ for(IConfigurationElement element : elements) {
+ if(element.getName().equals("framework")) {
+ try {
+ frameworks.add((IIncrementalBuildFramework) element.createExecutableExtension("class")); //$NON-NLS-1$
+ } catch(CoreException ex) {
+ log.error(ex.getMessage(), ex);
+ }
+ }
+ }
+ }
+ }
+
+ return frameworks;
+ }
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/BuildResultCollector.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/BuildResultCollector.java
new file mode 100644
index 00000000..754141d5
--- /dev/null
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/BuildResultCollector.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Takari, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Takari, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.core.internal.builder;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+
+/**
+ * @since 1.6
+ */
+class BuildResultCollector implements IIncrementalBuildFramework.BuildResultCollector {
+
+ private String currentParticipantId;
+
+ public static class Message {
+ public final File file;
+
+ public final int line;
+
+ public final int column;
+
+ public final String message;
+
+ public final int severity;
+
+ public final Throwable cause;
+
+ Message(File file, int line, int column, String message, int severity, Throwable cause) {
+ this.file = file;
+ this.line = line;
+ this.column = column;
+ if(message == null && cause != null) {
+ message = cause.getMessage();
+ }
+ this.message = message;
+ this.severity = severity;
+ this.cause = cause;
+ }
+ }
+
+ /** Added, changed or removed resources */
+ private final Set<File> refresh = new HashSet<File>();
+
+ /** Messages by build participant id */
+ private final Map<String, List<Message>> messages = new LinkedHashMap<String, List<Message>>();
+
+ /** List of files to cleanup messages for by build participant id */
+ private final Map<String, List<File>> removeMessages = new LinkedHashMap<String, List<File>>();
+
+ public Set<File> getFiles() {
+ return refresh;
+ }
+
+ @Override
+ public void refresh(File file) {
+ refresh.add(file);
+ }
+
+ @Override
+ public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) {
+ if(currentParticipantId == null) {
+ throw new IllegalStateException("currentBuildParticipantId cannot be null or empty");
+ }
+ List<Message> messageList = messages.get(currentParticipantId);
+ if(messageList == null) {
+ messageList = new ArrayList<Message>();
+ messages.put(currentParticipantId, messageList);
+ }
+ messageList.add(new Message(file, line, column, message, severity, cause));
+ }
+
+ @Override
+ public void removeMessages(File file) {
+ if(currentParticipantId == null) {
+ throw new IllegalStateException("currentBuildParticipantId cannot be null or empty");
+ }
+ List<File> files = removeMessages.get(currentParticipantId);
+ if(files == null) {
+ files = new ArrayList<File>();
+ removeMessages.put(currentParticipantId, files);
+ }
+ files.add(file);
+ }
+
+ public Map<String, List<Message>> getMessages() {
+ return messages;
+ }
+
+ public Map<String, List<File>> getRemoveMessages() {
+ return removeMessages;
+ }
+
+ public void setParticipantId(String participantId) {
+ this.currentParticipantId = participantId;
+ }
+
+}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/IIncrementalBuildFramework.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/IIncrementalBuildFramework.java
new file mode 100644
index 00000000..124e659a
--- /dev/null
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/IIncrementalBuildFramework.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Takari, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Takari, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.core.internal.builder;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.runtime.CoreException;
+
+
+/**
+ * @experimental this interface is part of work in progress and can be changed or removed without notice.
+ * @since 1.6
+ */
+public interface IIncrementalBuildFramework {
+
+ /**
+ * @experimental this interface is part of work in progress and can be changed or removed without notice.
+ * @since 1.6
+ */
+ public static interface BuildResultCollector {
+
+ public void refresh(File file);
+
+ public void addMessage(File file, int line, int column, String message, int severity, Throwable cause);
+
+ public void removeMessages(File file);
+ }
+
+ /**
+ * @experimental this interface is part of work in progress and can be changed or removed without notice.
+ * @since 1.6
+ */
+ public static interface BuildContext {
+ public void release();
+ }
+
+ public BuildContext setupProjectBuildContext(IProject project, int kind, IResourceDelta delta,
+ BuildResultCollector results) throws CoreException;
+
+}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java
index 94773c48..d2c49a25 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java
@@ -11,14 +11,12 @@
package org.eclipse.m2e.core.internal.builder;
-import static org.eclipse.core.resources.IncrementalProjectBuilder.AUTO_BUILD;
import static org.eclipse.core.resources.IncrementalProjectBuilder.FULL_BUILD;
-import static org.eclipse.core.resources.IncrementalProjectBuilder.INCREMENTAL_BUILD;
import java.io.File;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@@ -36,6 +34,7 @@ import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -46,22 +45,19 @@ import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
-import org.sonatype.plexus.build.incremental.ThreadBuildContext;
-
+import org.eclipse.m2e.core.internal.ExtensionReader;
import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.internal.MavenPluginActivator;
+import org.eclipse.m2e.core.internal.builder.BuildResultCollector.Message;
+import org.eclipse.m2e.core.internal.builder.IIncrementalBuildFramework.BuildContext;
import org.eclipse.m2e.core.internal.builder.plexusbuildapi.AbstractEclipseBuildContext;
-import org.eclipse.m2e.core.internal.builder.plexusbuildapi.AbstractEclipseBuildContext.Message;
-import org.eclipse.m2e.core.internal.builder.plexusbuildapi.EclipseBuildContext;
-import org.eclipse.m2e.core.internal.builder.plexusbuildapi.EclipseEmptyBuildContext;
-import org.eclipse.m2e.core.internal.builder.plexusbuildapi.EclipseIncrementalBuildContext;
+import org.eclipse.m2e.core.internal.builder.plexusbuildapi.PlexusBuildAPI;
import org.eclipse.m2e.core.internal.embedder.MavenProjectMutableState;
import org.eclipse.m2e.core.internal.markers.IMavenMarkerManager;
import org.eclipse.m2e.core.internal.markers.SourceLocation;
import org.eclipse.m2e.core.internal.markers.SourceLocationHelper;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.configurator.AbstractBuildParticipant;
-import org.eclipse.m2e.core.project.configurator.AbstractBuildParticipant2;
import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
@@ -74,8 +70,18 @@ public class MavenBuilderImpl {
private final DeltaProvider deltaProvider;
+ private final List<IIncrementalBuildFramework> incrementalBuildFrameworks;
+
public MavenBuilderImpl(DeltaProvider deltaProvider) {
this.deltaProvider = deltaProvider;
+ this.incrementalBuildFrameworks = loadIncrementalBuildFrameworks();
+ }
+
+ private List<IIncrementalBuildFramework> loadIncrementalBuildFrameworks() {
+ List<IIncrementalBuildFramework> frameworks = new ArrayList<IIncrementalBuildFramework>();
+ frameworks.add(new PlexusBuildAPI());
+ frameworks.addAll(ExtensionReader.readIncrementalBuildFrameworks());
+ return frameworks;
}
public MavenBuilderImpl() {
@@ -98,41 +104,27 @@ public class MavenBuilderImpl {
IResourceDelta delta = getDeltaProvider().getDelta(project);
- @SuppressWarnings("unchecked")
- Map<String, Object> contextState = (Map<String, Object>) project.getSessionProperty(BUILD_CONTEXT_KEY);
- AbstractEclipseBuildContext buildContext;
- if(delta != null && contextState != null && (INCREMENTAL_BUILD == kind || AUTO_BUILD == kind)) {
- buildContext = new EclipseIncrementalBuildContext(delta, contextState);
- } else {
- contextState = new HashMap<String, Object>();
- project.setSessionProperty(BUILD_CONTEXT_KEY, contextState);
- if(AbstractBuildParticipant2.PRECONFIGURE_BUILD == kind) {
- buildContext = new EclipseEmptyBuildContext(project, contextState);
- } else {
- // must be full build
- buildContext = new EclipseBuildContext(project, contextState);
- }
- }
+ final BuildResultCollector participantResults = new BuildResultCollector();
+ List<BuildContext> incrementalContexts = setupProjectBuildContext(project, kind, delta, participantResults);
debugBuildStart(debugHooks, projectFacade, kind, args, participants, delta, monitor);
Map<Throwable, MojoExecutionKey> buildErrors = new LinkedHashMap<Throwable, MojoExecutionKey>();
- ThreadBuildContext.setThreadBuildContext(buildContext);
MavenProjectMutableState snapshot = MavenProjectMutableState.takeSnapshot(mavenProject);
try {
for(Entry<MojoExecutionKey, List<AbstractBuildParticipant>> entry : participants.entrySet()) {
MojoExecutionKey mojoExecutionKey = entry.getKey();
for(InternalBuildParticipant participant : entry.getValue()) {
- Set<File> debugRefreshFiles = !debugHooks.isEmpty() ? new LinkedHashSet<File>(buildContext.getFiles()) : null;
+ Set<File> debugRefreshFiles = !debugHooks.isEmpty() ? new LinkedHashSet<File>(participantResults.getFiles())
+ : null;
log.debug("Executing build participant {} for plugin execution {}", participant.getClass().getName(),
mojoExecutionKey.toString());
- String stringMojoExecutionKey = mojoExecutionKey.getKeyString();
- buildContext.setCurrentBuildParticipantId(stringMojoExecutionKey + "-" + participant.getClass().getName());
+ participantResults.setParticipantId(mojoExecutionKey.getKeyString() + "-" + participant.getClass().getName());
participant.setMavenProjectFacade(projectFacade);
participant.setGetDeltaCallback(getDeltaProvider());
participant.setSession(session);
- participant.setBuildContext(buildContext);
+ participant.setBuildContext((AbstractEclipseBuildContext) incrementalContexts.get(0));
if(participant instanceof InternalBuildParticipant2) {
((InternalBuildParticipant2) participant).setArgs(args);
}
@@ -163,28 +155,37 @@ public class MavenBuilderImpl {
}
debugBuildParticipant(debugHooks, projectFacade, mojoExecutionKey, (AbstractBuildParticipant) participant,
- diff(debugRefreshFiles, buildContext.getFiles()), monitor);
+ diff(debugRefreshFiles, participantResults.getFiles()), monitor);
}
}
} catch(Exception e) {
buildErrors.put(e, null);
} finally {
snapshot.restore(mavenProject);
- ThreadBuildContext.setThreadBuildContext(null);
+ for(IIncrementalBuildFramework.BuildContext context : incrementalContexts) {
+ context.release();
+ }
}
// Refresh files modified by build participants/maven plugins
- refreshResources(project, buildContext, monitor);
+ refreshResources(project, participantResults.getFiles(), monitor);
// Process errors and warnings
MavenExecutionResult result = session.getResult();
- processBuildResults(project, mavenProject, result, buildContext, buildErrors);
-
- debugBuildEnd(debugHooks, projectFacade, buildContext, monitor);
+ processBuildResults(project, mavenProject, result, participantResults, buildErrors);
return dependencies;
}
+ private List<IIncrementalBuildFramework.BuildContext> setupProjectBuildContext(IProject project, int kind,
+ IResourceDelta delta, IIncrementalBuildFramework.BuildResultCollector results) throws CoreException {
+ List<IIncrementalBuildFramework.BuildContext> contexts = new ArrayList<IIncrementalBuildFramework.BuildContext>();
+ for(IIncrementalBuildFramework framework : incrementalBuildFrameworks) {
+ contexts.add(framework.setupProjectBuildContext(project, kind, delta, results));
+ }
+ return contexts;
+ }
+
private void debugBuildParticipant(Collection<BuildDebugHook> hooks, IMavenProjectFacade projectFacade,
MojoExecutionKey mojoExecutionKey, AbstractBuildParticipant participant, Set<File> files, IProgressMonitor monitor) {
for(BuildDebugHook hook : hooks) {
@@ -209,12 +210,6 @@ public class MavenBuilderImpl {
}
}
- private void debugBuildEnd(Collection<BuildDebugHook> hooks, IMavenProjectFacade projectFacade,
- AbstractEclipseBuildContext buildContext, IProgressMonitor monitor) {
- for(BuildDebugHook hook : hooks) {
- }
- }
-
protected boolean isApplicable(InternalBuildParticipant participant, int kind, IResourceDelta delta) {
return FULL_BUILD == kind || delta != null || participant.callOnEmptyDelta();
}
@@ -230,9 +225,9 @@ public class MavenBuilderImpl {
}
}
- private void refreshResources(IProject project, AbstractEclipseBuildContext buildContext, IProgressMonitor monitor)
+ private void refreshResources(IProject project, Collection<File> resources, IProgressMonitor monitor)
throws CoreException {
- for(File file : buildContext.getFiles()) {
+ for(File file : resources) {
IPath path = getProjectRelativePath(project, file);
if(path == null) {
log.debug("Could not get relative path for file: ", file.getAbsoluteFile());
@@ -287,11 +282,11 @@ public class MavenBuilderImpl {
}
private void processBuildResults(IProject project, MavenProject mavenProject, MavenExecutionResult result,
- AbstractEclipseBuildContext buildContext, Map<Throwable, MojoExecutionKey> buildErrors) {
+ BuildResultCollector results, Map<Throwable, MojoExecutionKey> buildErrors) {
IMavenMarkerManager markerManager = MavenPluginActivator.getDefault().getMavenMarkerManager();
// Remove obsolete markers for problems reported by build participants
- for(Entry<String, List<File>> entry : buildContext.getRemoveMessages().entrySet()) {
+ for(Entry<String, List<File>> entry : results.getRemoveMessages().entrySet()) {
String buildParticipantId = entry.getKey();
for(File file : entry.getValue()) {
deleteBuildParticipantMarkers(project, markerManager, file, buildParticipantId);
@@ -299,7 +294,7 @@ public class MavenBuilderImpl {
}
// Create new markers for problems reported by build participants
- for(Entry<String, List<Message>> messageEntry : buildContext.getMessages().entrySet()) {
+ for(Entry<String, List<Message>> messageEntry : results.getMessages().entrySet()) {
String buildParticipantId = messageEntry.getKey();
for(Message buildMessage : messageEntry.getValue()) {
addBuildParticipantMarker(project, markerManager, buildMessage, buildParticipantId);
@@ -378,22 +373,20 @@ public class MavenBuilderImpl {
// TODO flush relevant caches
- project.setSessionProperty(BUILD_CONTEXT_KEY, null); // clean context state
+ final BuildResultCollector participantResults = new BuildResultCollector();
+ List<BuildContext> incrementalContexts = setupProjectBuildContext(project, IncrementalProjectBuilder.CLEAN_BUILD,
+ null, participantResults);
Map<Throwable, MojoExecutionKey> buildErrors = new LinkedHashMap<Throwable, MojoExecutionKey>();
- Map<String, Object> contextState = new HashMap<String, Object>();
- EclipseBuildContext buildContext = new EclipseBuildContext(project, contextState);
- ThreadBuildContext.setThreadBuildContext(buildContext);
try {
for(Entry<MojoExecutionKey, List<AbstractBuildParticipant>> entry : participants.entrySet()) {
MojoExecutionKey mojoExecutionKey = entry.getKey();
for(InternalBuildParticipant participant : entry.getValue()) {
- String stringMojoExecutionKey = mojoExecutionKey.getKeyString();
- buildContext.setCurrentBuildParticipantId(stringMojoExecutionKey + "-" + participant.getClass().getName());
+ participantResults.setParticipantId(mojoExecutionKey.getKeyString() + "-" + participant.getClass().getName());
participant.setMavenProjectFacade(projectFacade);
participant.setGetDeltaCallback(getDeltaProvider());
participant.setSession(session);
- participant.setBuildContext(buildContext);
+ participant.setBuildContext((AbstractEclipseBuildContext) incrementalContexts.get(0));
try {
participant.clean(monitor);
} catch(Exception e) {
@@ -412,14 +405,16 @@ public class MavenBuilderImpl {
} catch(Exception e) {
buildErrors.put(e, null);
} finally {
- ThreadBuildContext.setThreadBuildContext(null);
+ for(IIncrementalBuildFramework.BuildContext context : incrementalContexts) {
+ context.release();
+ }
}
// Refresh files modified by build participants/maven plugins
- refreshResources(project, buildContext, monitor);
+ refreshResources(project, participantResults.getFiles(), monitor);
MavenExecutionResult result = session.getResult();
- processBuildResults(project, mavenProject, result, buildContext, buildErrors);
+ processBuildResults(project, mavenProject, result, participantResults, buildErrors);
}
DeltaProvider getDeltaProvider() {
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/AbstractEclipseBuildContext.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/AbstractEclipseBuildContext.java
index 5321533a..f9dbc802 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/AbstractEclipseBuildContext.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/AbstractEclipseBuildContext.java
@@ -14,12 +14,7 @@ package org.eclipse.m2e.core.internal.builder.plexusbuildapi;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.List;
import java.util.Map;
-import java.util.Set;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
@@ -27,63 +22,32 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.sonatype.plexus.build.incremental.BuildContext;
+import org.sonatype.plexus.build.incremental.ThreadBuildContext;
+
+import org.eclipse.m2e.core.internal.builder.IIncrementalBuildFramework;
/**
* @author igor
*/
-public abstract class AbstractEclipseBuildContext implements BuildContext {
-
- public static class Message {
- public final File file;
-
- public final int line;
-
- public final int column;
-
- public final String message;
-
- public final int severity;
-
- public final Throwable cause;
-
- Message(File file, int line, int column, String message, int severity, Throwable cause) {
- this.file = file;
- this.line = line;
- this.column = column;
- if(message == null && cause != null) {
- message = cause.getMessage();
- }
- this.message = message;
- this.severity = severity;
- this.cause = cause;
- }
- }
-
- private final Set<File> refresh = new HashSet<File>();
+public abstract class AbstractEclipseBuildContext implements BuildContext, IIncrementalBuildFramework.BuildContext {
protected final Map<String, Object> context;
- private String currentBuildParticipantId;
-
- /** Messages by build participant id */
- private final Map<String, List<Message>> messages = new LinkedHashMap<String, List<Message>>();
+ private final IIncrementalBuildFramework.BuildResultCollector results;
- /** List of files to cleanup messages for by build participant id */
- private final Map<String, List<File>> removeMessages = new LinkedHashMap<String, List<File>>();
-
- protected AbstractEclipseBuildContext(Map<String, Object> context) {
+ protected AbstractEclipseBuildContext(Map<String, Object> context,
+ IIncrementalBuildFramework.BuildResultCollector results) {
this.context = context;
+ this.results = results;
}
+ @Override
public void refresh(File file) {
- refresh.add(file);
- }
-
- public Set<File> getFiles() {
- return refresh;
+ results.refresh(file);
}
+ @Override
public OutputStream newFileOutputStream(File file) throws IOException {
return new ChangedFileOutputStream(file, this);
}
@@ -116,10 +80,12 @@ public abstract class AbstractEclipseBuildContext implements BuildContext {
protected abstract IResource getBaseResource();
+ @Override
public void setValue(String key, Object value) {
context.put(key, value);
}
+ @Override
public Object getValue(String key) {
return context.get(key);
}
@@ -127,6 +93,7 @@ public abstract class AbstractEclipseBuildContext implements BuildContext {
/**
* @deprecated Use addMessage instead
*/
+ @Override
public void addError(File file, int line, int column, String message, Throwable cause) {
addMessage(file, line, column, message, BuildContext.SEVERITY_ERROR, cause);
}
@@ -134,42 +101,22 @@ public abstract class AbstractEclipseBuildContext implements BuildContext {
/**
* @deprecated Use addMessage instead
*/
+ @Override
public void addWarning(File file, int line, int column, String message, Throwable cause) {
addMessage(file, line, column, message, BuildContext.SEVERITY_WARNING, cause);
}
+ @Override
public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) {
- if(currentBuildParticipantId == null) {
- throw new IllegalStateException("currentBuildParticipantId cannot be null or empty");
- }
- List<Message> messageList = messages.get(currentBuildParticipantId);
- if(messageList == null) {
- messageList = new ArrayList<Message>();
- messages.put(currentBuildParticipantId, messageList);
- }
- messageList.add(new Message(file, line, column, message, severity, cause));
+ results.addMessage(file, line, column, message, severity, cause);
}
+ @Override
public void removeMessages(File file) {
- if(currentBuildParticipantId == null) {
- throw new IllegalStateException("currentBuildParticipantId cannot be null or empty");
- }
- List<File> files = removeMessages.get(currentBuildParticipantId);
- if(files == null) {
- files = new ArrayList<File>();
- removeMessages.put(currentBuildParticipantId, files);
- }
- files.add(file);
- }
-
- public Map<String, List<Message>> getMessages() {
- return messages;
- }
-
- public Map<String, List<File>> getRemoveMessages() {
- return removeMessages;
+ results.removeMessages(file);
}
+ @Override
public boolean isUptodate(File target, File source) {
IResource targetResource = getResource(target);
IResource sourceResource = getResource(source);
@@ -178,7 +125,8 @@ public abstract class AbstractEclipseBuildContext implements BuildContext {
&& targetResource.getLocalTimeStamp() >= sourceResource.getLocalTimeStamp();
}
- public void setCurrentBuildParticipantId(String currentBuildParticipantId) {
- this.currentBuildParticipantId = currentBuildParticipantId;
+ @Override
+ public void release() {
+ ThreadBuildContext.setThreadBuildContext(null);
}
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/EclipseBuildContext.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/EclipseBuildContext.java
index 5d7fca17..ea00fe6c 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/EclipseBuildContext.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/EclipseBuildContext.java
@@ -26,6 +26,7 @@ import org.codehaus.plexus.util.Scanner;
import org.sonatype.plexus.build.incremental.EmptyScanner;
import org.eclipse.m2e.core.internal.Messages;
+import org.eclipse.m2e.core.internal.builder.IIncrementalBuildFramework;
/**
@@ -37,8 +38,9 @@ public class EclipseBuildContext extends AbstractEclipseBuildContext {
protected final IProject project;
- public EclipseBuildContext(IProject project, Map<String, Object> context) {
- super(context);
+ public EclipseBuildContext(IProject project, Map<String, Object> context,
+ IIncrementalBuildFramework.BuildResultCollector results) {
+ super(context, results);
this.project = project;
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/EclipseEmptyBuildContext.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/EclipseEmptyBuildContext.java
index ccd3bef1..e57681de 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/EclipseEmptyBuildContext.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/EclipseEmptyBuildContext.java
@@ -22,6 +22,8 @@ import org.codehaus.plexus.util.Scanner;
import org.sonatype.plexus.build.incremental.EmptyScanner;
+import org.eclipse.m2e.core.internal.builder.IIncrementalBuildFramework;
+
public class EclipseEmptyBuildContext extends AbstractEclipseBuildContext {
@@ -29,8 +31,9 @@ public class EclipseEmptyBuildContext extends AbstractEclipseBuildContext {
private final IProject project;
- public EclipseEmptyBuildContext(IProject project, Map<String, Object> context) {
- super(context);
+ public EclipseEmptyBuildContext(IProject project, Map<String, Object> context,
+ IIncrementalBuildFramework.BuildResultCollector results) {
+ super(context, results);
this.project = project;
this.emptyScanner = new EmptyScanner(project.getLocation().toFile());
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/EclipseIncrementalBuildContext.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/EclipseIncrementalBuildContext.java
index c845e84d..d23ee5b5 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/EclipseIncrementalBuildContext.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/EclipseIncrementalBuildContext.java
@@ -26,13 +26,16 @@ import org.codehaus.plexus.util.Scanner;
import org.sonatype.plexus.build.incremental.EmptyScanner;
+import org.eclipse.m2e.core.internal.builder.IIncrementalBuildFramework;
+
public class EclipseIncrementalBuildContext extends AbstractEclipseBuildContext {
private final IResourceDelta delta;
- public EclipseIncrementalBuildContext(IResourceDelta delta, Map<String, Object> context) {
- super(context);
+ public EclipseIncrementalBuildContext(IResourceDelta delta, Map<String, Object> context,
+ IIncrementalBuildFramework.BuildResultCollector results) {
+ super(context, results);
this.delta = delta;
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/PlexusBuildAPI.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/PlexusBuildAPI.java
new file mode 100644
index 00000000..e564aaa4
--- /dev/null
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/PlexusBuildAPI.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Takari, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Takari, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.core.internal.builder.plexusbuildapi;
+
+import static org.eclipse.core.resources.IncrementalProjectBuilder.AUTO_BUILD;
+import static org.eclipse.core.resources.IncrementalProjectBuilder.CLEAN_BUILD;
+import static org.eclipse.core.resources.IncrementalProjectBuilder.INCREMENTAL_BUILD;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.QualifiedName;
+
+import org.sonatype.plexus.build.incremental.ThreadBuildContext;
+
+import org.eclipse.m2e.core.internal.IMavenConstants;
+import org.eclipse.m2e.core.internal.builder.IIncrementalBuildFramework;
+import org.eclipse.m2e.core.project.configurator.AbstractBuildParticipant2;
+
+
+/**
+ * @since 1.6
+ */
+public class PlexusBuildAPI implements IIncrementalBuildFramework {
+ public static QualifiedName BUILD_CONTEXT_KEY = new QualifiedName(IMavenConstants.PLUGIN_ID, "BuildContext"); //$NON-NLS-1$
+
+ @Override
+ public AbstractEclipseBuildContext setupProjectBuildContext(IProject project, int kind, IResourceDelta delta,
+ IIncrementalBuildFramework.BuildResultCollector results) throws CoreException {
+ @SuppressWarnings("unchecked")
+ Map<String, Object> contextState = (Map<String, Object>) project.getSessionProperty(BUILD_CONTEXT_KEY);
+ AbstractEclipseBuildContext buildContext;
+ if(delta != null && contextState != null && (INCREMENTAL_BUILD == kind || AUTO_BUILD == kind)) {
+ buildContext = new EclipseIncrementalBuildContext(delta, contextState, results);
+ } else if(CLEAN_BUILD == kind) {
+ project.setSessionProperty(BUILD_CONTEXT_KEY, null); // clean context state
+ buildContext = new EclipseBuildContext(project, new HashMap<String, Object>(), results);
+ } else {
+ contextState = new HashMap<String, Object>();
+ project.setSessionProperty(BUILD_CONTEXT_KEY, contextState);
+ if(AbstractBuildParticipant2.PRECONFIGURE_BUILD == kind) {
+ buildContext = new EclipseEmptyBuildContext(project, contextState, results);
+ } else {
+ // must be full build
+ buildContext = new EclipseBuildContext(project, contextState, results);
+ }
+ }
+ ThreadBuildContext.setThreadBuildContext(buildContext);
+ return buildContext;
+ }
+
+}

Back to the top