Index: editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/builder/DartBuilder.java |
=================================================================== |
--- editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/builder/DartBuilder.java (revision 15619) |
+++ editor/tools/plugins/com.google.dart.tools.core/src/com/google/dart/tools/core/internal/builder/DartBuilder.java (working copy) |
@@ -14,32 +14,20 @@ |
package com.google.dart.tools.core.internal.builder; |
import com.google.dart.tools.core.DartCore; |
-import com.google.dart.tools.core.analysis.AnalysisServer; |
-import com.google.dart.tools.core.analysis.ScanCallback; |
import com.google.dart.tools.core.builder.BuildEvent; |
import com.google.dart.tools.core.builder.BuildParticipant; |
import com.google.dart.tools.core.builder.CleanEvent; |
-import com.google.dart.tools.core.internal.index.impl.InMemoryIndex; |
-import com.google.dart.tools.core.internal.model.PackageLibraryManagerProvider; |
-import com.google.dart.tools.core.internal.util.Extensions; |
import org.eclipse.core.resources.IProject; |
-import org.eclipse.core.resources.IResource; |
import org.eclipse.core.resources.IResourceDelta; |
-import org.eclipse.core.resources.IResourceDeltaVisitor; |
-import org.eclipse.core.resources.IWorkspace; |
-import org.eclipse.core.resources.IWorkspaceRoot; |
import org.eclipse.core.resources.IncrementalProjectBuilder; |
-import org.eclipse.core.resources.ResourcesPlugin; |
import org.eclipse.core.runtime.CoreException; |
-import org.eclipse.core.runtime.IPath; |
import org.eclipse.core.runtime.IProgressMonitor; |
import org.eclipse.core.runtime.ISafeRunnable; |
import org.eclipse.core.runtime.OperationCanceledException; |
import org.eclipse.core.runtime.SafeRunner; |
import org.eclipse.core.runtime.SubMonitor; |
-import java.io.File; |
import java.util.Map; |
/** |
@@ -48,8 +36,6 @@ |
*/ |
public class DartBuilder extends IncrementalProjectBuilder { |
- private final AnalysisServer server = PackageLibraryManagerProvider.getDefaultAnalysisServer(); |
- |
/** |
* The participants associated with this builder or {@code null} if not initialized. This field is |
* lazily initialized by calling {@link #getParticipants()}. |
@@ -61,119 +47,85 @@ |
*/ |
private boolean cleaned; |
+ public DartBuilder() { |
+ } |
+ |
+ public DartBuilder(BuildParticipant participant) { |
+ participants = new BuildParticipant[] {participant}; |
+ } |
+ |
@Override |
- protected IProject[] build(final int kind, final Map<String, String> args, |
+ public IProject[] build(final int kind, final Map<String, String> args, |
final IProgressMonitor monitor) throws CoreException { |
+ return build(getProject(), kind, args, monitor); |
+ } |
- int totalProgress = (getParticipants().length + 1) * 10; |
- final SubMonitor subMonitor = SubMonitor.convert(monitor, totalProgress); |
+ public IProject[] build(IProject project, int kind, Map<String, String> args, |
+ final IProgressMonitor monitor) { |
- final IResourceDelta delta = cleaned ? null : getDelta(getProject()); |
- final BuildEvent event = new BuildEvent(getProject(), delta, subMonitor); |
+ final SubMonitor subMonitor = SubMonitor.convert( |
+ monitor, |
+ project.getName(), |
+ getParticipants().length); |
+ |
+ final IResourceDelta delta = cleaned ? null : getDelta(project); |
+ final BuildEvent event = new BuildEvent(project, delta, subMonitor); |
cleaned = false; |
- // notify participants |
- for (final BuildParticipant participant : getParticipants()) { |
- if (subMonitor.isCanceled()) { |
- throw new OperationCanceledException(); |
- } |
+ try { |
+ for (final BuildParticipant participant : getParticipants()) { |
- SafeRunner.run(new ISafeRunnable() { |
- @Override |
- public void handleException(Throwable exception) { |
- if (!(exception instanceof OperationCanceledException)) { |
- DartCore.logError("Error notifying build participant", exception); |
- } |
+ // Check if the operation has been canceled |
+ if (subMonitor.isCanceled()) { |
+ throw new OperationCanceledException(); |
} |
- @Override |
- public void run() throws Exception { |
- participant.build(event, subMonitor.newChild(10)); |
- } |
- }); |
- } |
- |
- if (subMonitor.isCanceled()) { |
- throw new OperationCanceledException(); |
- } |
- |
- // If delta is null, then building a new project |
- |
- if (delta == null) { |
- IPath location = getProject().getLocation(); |
- if (location != null) { |
- ScanCallbackProvider provider = ScanCallbackProvider.getProvider(getProject().getName()); |
- ScanCallback callback = provider != null ? provider.newCallback() : null; |
- server.scan(location.toFile(), callback); |
- } |
- } else { |
- // Recursively process the resource delta |
- delta.accept(new IResourceDeltaVisitor() { |
- @Override |
- public boolean visit(IResourceDelta delta) { |
- IResource resource = delta.getResource(); |
- IPath location = resource.getLocation(); |
- if (location == null) { |
- return false; |
- } |
- File file = location.toFile(); |
- |
- // Process folder |
- if (resource.getType() != IResource.FILE) { |
- switch (delta.getKind()) { |
- case IResourceDelta.ADDED: |
- server.scan(file, null); |
- return false; |
- case IResourceDelta.REMOVED: |
- server.discard(file); |
- return false; |
- case IResourceDelta.CHANGED: |
- // recurse child deltas |
- return true; |
+ SafeRunner.run(new ISafeRunnable() { |
+ @Override |
+ public void handleException(Throwable exception) { |
+ if (!(exception instanceof OperationCanceledException)) { |
+ DartCore.logError("Error notifying build participant", exception); |
} |
- return false; |
} |
- // Process file |
- if (resource.getName().endsWith(Extensions.DOT_DART)) { |
- switch (delta.getKind()) { |
- case IResourceDelta.ADDED: |
- server.scan(file, null); |
- return false; |
- case IResourceDelta.REMOVED: |
- server.discard(file); |
- return false; |
- case IResourceDelta.CHANGED: |
- server.changed(file); |
- return false; |
- } |
- return false; |
- } else { |
- try { |
- resource.deleteMarkers(DartCore.DART_PROBLEM_MARKER_TYPE, true, IResource.DEPTH_ZERO); |
- } catch (CoreException e) { |
- // do nothing |
- } |
+ @Override |
+ public void run() throws Exception { |
+ SubMonitor childMonitor = subMonitor.newChild(1); |
+ participant.build(event, childMonitor); |
+ childMonitor.done(); |
} |
- |
- return false; |
- } |
- }); |
+ }); |
+ } |
+ } finally { |
+ if (monitor != null) { |
+ monitor.done(); |
+ } |
} |
- |
return null; |
} |
@Override |
- protected void clean(IProgressMonitor monitor) throws CoreException { |
+ public void clean(IProgressMonitor monitor) throws CoreException { |
+ clean(getProject(), monitor); |
+ } |
+ |
+ public void clean(IProject project, IProgressMonitor monitor) { |
+ final SubMonitor subMonitor = SubMonitor.convert( |
+ monitor, |
+ project.getName(), |
+ getParticipants().length); |
+ |
+ final CleanEvent event = new CleanEvent(project, subMonitor); |
cleaned = true; |
- final SubMonitor subMonitor = SubMonitor.convert(monitor, getParticipants().length + 3); |
- final CleanEvent event = new CleanEvent(getProject(), subMonitor); |
- try { |
- //notify participants |
- subMonitor.beginTask(getProject().getName(), getParticipants().length + 3); |
+ try { |
for (final BuildParticipant participant : getParticipants()) { |
+ |
+ // Check if the operation has been canceled |
+ if (subMonitor.isCanceled()) { |
+ throw new OperationCanceledException(); |
+ } |
+ |
SafeRunner.run(new ISafeRunnable() { |
@Override |
public void handleException(Throwable exception) { |
@@ -184,24 +136,12 @@ |
@Override |
public void run() throws Exception { |
- participant.clean(event, subMonitor.newChild(1)); |
+ SubMonitor childMonitor = subMonitor.newChild(1); |
+ participant.clean(event, childMonitor); |
+ childMonitor.done(); |
} |
}); |
} |
- |
- // Clear the index before triggering reanalyze so that updates from re-analysis |
- // will be included in the rebuilt index |
- InMemoryIndex.getInstance().clear(); |
- subMonitor.worked(1); |
- |
- IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
- IWorkspaceRoot root = workspace.getRoot(); |
- |
- root.deleteMarkers(DartCore.DART_PROBLEM_MARKER_TYPE, true, IResource.DEPTH_INFINITE); |
- |
- AnalysisServer server = PackageLibraryManagerProvider.getDefaultAnalysisServer(); |
- server.reanalyze(); |
- |
} finally { |
if (monitor != null) { |
monitor.done(); |