Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
LANG: workspace-wide handling of build markers creation/deletion.
Browse files Browse the repository at this point in the history
Conflicts:
	plugin_ide.ui/src/melnorme/lang/ide/ui/LangUIPlugin_Actual.java
  • Loading branch information
bruno-medeiros committed Aug 10, 2015
1 parent d3e5239 commit 8bcbdca
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 54 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -136,23 +136,23 @@ protected EclipseCancelMonitor cm(IProgressMonitor pm) {
return new EclipseCancelMonitor(pm); return new EclipseCancelMonitor(pm);
} }


public RunProcessTask2 newRunToolOperation2(ProcessBuilder pb, IProgressMonitor pm) { public RunProcessTask newRunToolOperation2(ProcessBuilder pb, IProgressMonitor pm) {
OperationInfo opInfo = startNewToolOperation(); OperationInfo opInfo = startNewToolOperation();
return newRunToolTask(opInfo, pb, cm(pm)); return newRunToolTask(opInfo, pb, cm(pm));
} }


public RunProcessTask2 newRunToolTask(OperationInfo opInfo, ProcessBuilder pb, IProgressMonitor pm) { public RunProcessTask newRunToolTask(OperationInfo opInfo, ProcessBuilder pb, IProgressMonitor pm) {
return newRunToolTask(opInfo, pb, cm(pm)); return newRunToolTask(opInfo, pb, cm(pm));
} }
public RunProcessTask2 newRunToolTask(OperationInfo opInfo, ProcessBuilder pb, ICancelMonitor cm) { public RunProcessTask newRunToolTask(OperationInfo opInfo, ProcessBuilder pb, ICancelMonitor cm) {
return new RunProcessTask2(opInfo, pb, cm); return new RunProcessTask(opInfo, pb, cm);
} }


public class RunProcessTask2 extends AbstractRunProcessTask { public class RunProcessTask extends AbstractRunProcessTask {


protected final OperationInfo opInfo; protected final OperationInfo opInfo;


public RunProcessTask2(OperationInfo opInfo, ProcessBuilder pb, ICancelMonitor cancelMonitor) { public RunProcessTask(OperationInfo opInfo, ProcessBuilder pb, ICancelMonitor cancelMonitor) {
super(pb, cancelMonitor); super(pb, cancelMonitor);
this.opInfo = opInfo; this.opInfo = opInfo;
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ protected void startupOnInitialize() {
protected static HashMap2<String, OperationInfo> workspaceOpInfoMap = new HashMap2<>(); protected static HashMap2<String, OperationInfo> workspaceOpInfoMap = new HashMap2<>();
protected OperationInfo workspaceOpInfo; protected OperationInfo workspaceOpInfo;


protected void prepareForBuild() throws CoreException { protected void prepareForBuild(IProgressMonitor pm) throws CoreException, OperationCancellation {
handleBeginWorkspaceBuild(); handleBeginWorkspaceBuild(pm);


assertTrue(workspaceOpInfo.isStarted()); assertTrue(workspaceOpInfo.isStarted());
} }


protected void handleBeginWorkspaceBuild() { protected void handleBeginWorkspaceBuild(IProgressMonitor pm) throws CoreException, OperationCancellation {
workspaceOpInfo = workspaceOpInfoMap.get(LangCore.NATURE_ID); workspaceOpInfo = workspaceOpInfoMap.get(LangCore.NATURE_ID);


if(workspaceOpInfo != null) { if(workspaceOpInfo != null) {
Expand All @@ -125,6 +125,26 @@ public void resourceChanged(IResourceChangeEvent event) {


getToolManager().notifyMessageEvent(new MessageEventInfo(workspaceOpInfo, getToolManager().notifyMessageEvent(new MessageEventInfo(workspaceOpInfo,
headerVeryBig(MessageFormat.format(MSG_Starting_LANG_Build, LangCore_Actual.LANGUAGE_NAME)))); headerVeryBig(MessageFormat.format(MSG_Starting_LANG_Build, LangCore_Actual.LANGUAGE_NAME))));

clearWorkspaceErrorMarkers(pm);
}

protected void clearWorkspaceErrorMarkers(IProgressMonitor pm) throws CoreException, OperationCancellation {
clearErrorMarkers(getProject(), pm);

for(IBuildConfiguration buildConfig : getContext().getAllReferencingBuildConfigs()) {
clearErrorMarkers(buildConfig.getProject(), pm);
}
}

protected void clearErrorMarkers(IProject project, IProgressMonitor pm)
throws CoreException, OperationCancellation {
IToolOperation clearMarkersOp = buildManager.newProjectClearMarkersOperation(workspaceOpInfo, project);
try {
clearMarkersOp.execute(pm);
} catch (CommonException ce) {
throw LangCore.createCoreException(ce);
}
} }


protected void handleEndWorkspaceBuild2() { protected void handleEndWorkspaceBuild2() {
Expand All @@ -137,15 +157,15 @@ protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor


IProject project = assertNotNull(getProject()); IProject project = assertNotNull(getProject());


prepareForBuild();

try { try {
prepareForBuild(monitor);

return doBuild(project, kind, args, monitor); return doBuild(project, kind, args, monitor);
} }
catch (OperationCancellation cancel) { catch(OperationCancellation cancel) {
forgetLastBuiltState(); forgetLastBuiltState();
return null; return null;
} catch (CoreException ce) { } catch(CoreException ce) {
forgetLastBuiltState(); forgetLastBuiltState();


if(monitor.isCanceled()) { if(monitor.isCanceled()) {
Expand Down Expand Up @@ -178,7 +198,7 @@ protected IProject[] doBuild(final IProject project, int kind, Map<String, Strin
} }


protected IToolOperation createBuildOp(boolean fullBuild) throws CommonException { protected IToolOperation createBuildOp(boolean fullBuild) throws CommonException {
return buildManager.newProjectBuildOperation(workspaceOpInfo, getProject(), fullBuild); return buildManager.newProjectBuildOperation(workspaceOpInfo, getProject(), fullBuild, false);
} }


/* ----------------- Clean ----------------- */ /* ----------------- Clean ----------------- */
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -48,43 +48,50 @@ public void addErrorMarkers(Iterable<ToolSourceMessage> buildErrors, Location ro
throws CoreException { throws CoreException {


for (ToolSourceMessage buildError : buildErrors) { for (ToolSourceMessage buildError : buildErrors) {
Location loc = rootPath.resolve(buildError.getFilePath()); // Absolute paths will remain unchanged. addErrorMarkers(buildError, rootPath);

IFile[] files = ResourceUtils.getWorkspaceRoot().findFilesForLocationURI(loc.toUri());
for (IFile file : files) {
addErrorMarker(file, buildError, LangCore_Actual.BUILD_PROBLEM_ID);
}
} }
}

public void addErrorMarkers(ToolSourceMessage toolMessage, Location rootPath) throws CoreException {
Location loc = rootPath.resolve(toolMessage.getFilePath()); // Absolute paths will remain unchanged.


IFile[] files = ResourceUtils.getWorkspaceRoot().findFilesForLocationURI(loc.toUri());
for(IFile file : files) {
addErrorMarker(file, toolMessage, getMarkerType());
}
}

protected String getMarkerType() {
return LangCore_Actual.BUILD_PROBLEM_ID;
} }


public void addErrorMarker(IResource resource, ToolSourceMessage buildmessage, String markerType) public void addErrorMarker(IResource resource, ToolSourceMessage toolMessage, String markerType)
throws CoreException { throws CoreException {
if(!resource.exists()) if(!resource.exists())
return; return;


if(buildmessage.getMessageKind() == StatusLevel.OK) { if(toolMessage.getMessageKind() == StatusLevel.OK) {
return; // Don't add message as a marker. return; // Don't add message as a marker.
} }


// TODO: check if marker already exists? // TODO: check if marker already exists?
IMarker marker = resource.createMarker(markerType); IMarker marker = resource.createMarker(markerType);


marker.setAttribute(IMarker.SEVERITY, severityFrom(buildmessage.getMessageKind())); marker.setAttribute(IMarker.SEVERITY, severityFrom(toolMessage.getMessageKind()));
marker.setAttribute(IMarker.MESSAGE, buildmessage.getMessage()); marker.setAttribute(IMarker.MESSAGE, toolMessage.getMessage());


if(!(resource instanceof IFile)) { if(!(resource instanceof IFile)) {
return; return;
} }


IFile file = (IFile) resource; IFile file = (IFile) resource;


int line = buildmessage.getFileLineNumber(); int line = toolMessage.getFileLineNumber();
if(line >= 0) { if(line >= 0) {
marker.setAttribute(IMarker.LINE_NUMBER, line); marker.setAttribute(IMarker.LINE_NUMBER, line);
} }


SourceLineColumnRange range = buildmessage.range; SourceLineColumnRange range = toolMessage.range;


SourceRange messageSR; SourceRange messageSR;


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -426,25 +426,26 @@ public BuildTarget getValidBuildTarget(IProject project, String buildTargetName,
/* ----------------- Build operations ----------------- */ /* ----------------- Build operations ----------------- */


public final IToolOperation newProjectBuildOperation(OperationInfo opInfo, IProject project, public final IToolOperation newProjectBuildOperation(OperationInfo opInfo, IProject project,
boolean fullBuild) throws CommonException { boolean fullBuild, boolean clearMarkers) throws CommonException {
ArrayList2<BuildTarget> enabledTargets = getValidBuildInfo(project).getEnabledTargets(); ArrayList2<BuildTarget> enabledTargets = getValidBuildInfo(project).getEnabledTargets();
return createBuildOperationCreator(opInfo, project, fullBuild).newProjectBuildOperation(enabledTargets); return createBuildOperationCreator(opInfo, project, fullBuild)
.newProjectBuildOperation(enabledTargets, clearMarkers);
}

public final IToolOperation newProjectClearMarkersOperation(OperationInfo opInfo, IProject project) {
return createBuildOperationCreator(opInfo, project, false).newClearBuildMarkersOperation();
} }


public final IToolOperation newBuildTargetOperation(IProject project, BuildTarget buildTarget) public final IToolOperation newBuildTargetOperation(IProject project, BuildTarget buildTarget)
throws CommonException { throws CommonException {
return newBuildTargetOperation(project, ArrayList2.create(buildTarget)); return newBuildTargetsOperation(project, ArrayList2.create(buildTarget));
} }


public IToolOperation newBuildTargetOperation(IProject project, Collection2<BuildTarget> targetsToBuild) public IToolOperation newBuildTargetsOperation(IProject project, Collection2<BuildTarget> targetsToBuild)
throws CommonException { throws CommonException {
OperationInfo operationInfo = LangCore.getToolManager().startNewToolOperation(); OperationInfo operationInfo = LangCore.getToolManager().startNewToolOperation();
return newBuildTargetOperation(operationInfo, project, targetsToBuild); return createBuildOperationCreator(operationInfo, project, false)
} .newProjectBuildOperation(targetsToBuild, true);

public IToolOperation newBuildTargetOperation(OperationInfo opInfo, IProject project,
Collection2<BuildTarget> targetsToBuild) throws CommonException {
return createBuildOperationCreator(opInfo, project, false).newProjectBuildOperation(targetsToBuild);
} }


protected BuildOperationCreator createBuildOperationCreator(OperationInfo opInfo, IProject project, protected BuildOperationCreator createBuildOperationCreator(OperationInfo opInfo, IProject project,
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface BuildManagerMessages {
"Could not perform operation, target has changed in the meanwhile"; "Could not perform operation, target has changed in the meanwhile";


public String MSG_BuildingProject = "Building {0} project: {1}"; public String MSG_BuildingProject = "Building {0} project: {1}";
public String MSG_ClearingMarkers = "Cleared problem markers for {0}.";
public String MSG_BuildTerminated = "Build terminated."; public String MSG_BuildTerminated = "Build terminated.";
public String MSG_NoBuildTargetsEnabled = "No build targets enabled."; public String MSG_NoBuildTargetsEnabled = "No build targets enabled.";


Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2015, 2015 IBM Corporation and others. * Copyright (c) 2015 Bruno Medeiros and other Contributors.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
Expand All @@ -17,6 +17,7 @@
import java.nio.file.Path; import java.nio.file.Path;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;


import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
Expand All @@ -34,6 +35,7 @@
public class BuildOperationCreator implements BuildManagerMessages { public class BuildOperationCreator implements BuildManagerMessages {


protected final BuildManager buildMgr = LangCore.getBuildManager(); protected final BuildManager buildMgr = LangCore.getBuildManager();
protected final String buildProblemId = LangCore_Actual.BUILD_PROBLEM_ID;


protected final IProject project; protected final IProject project;
protected final OperationInfo opInfo; protected final OperationInfo opInfo;
Expand All @@ -47,13 +49,19 @@ public BuildOperationCreator(IProject project, OperationInfo opInfo, boolean ful


protected ArrayList2<IToolOperation> operations; protected ArrayList2<IToolOperation> operations;


public IToolOperation newProjectBuildOperation(Collection2<BuildTarget> targetsToBuild) public IToolOperation newClearBuildMarkersOperation() {
return doCreateClearBuildMarkersOperation();
}

public IToolOperation newProjectBuildOperation(Collection2<BuildTarget> targetsToBuild, boolean clearMarkers)
throws CommonException { throws CommonException {
operations = ArrayList2.create(); operations = ArrayList2.create();


addCompositeBuildOperationMessage(); addCompositeBuildOperationMessage();


addMarkerCleanOperation(); if(clearMarkers) {
addOperation(newClearBuildMarkersOperation());
}


if(targetsToBuild.isEmpty()) { if(targetsToBuild.isEmpty()) {
addOperation(newMessageOperation(opInfo, addOperation(newMessageOperation(opInfo,
Expand All @@ -70,25 +78,37 @@ public IToolOperation newProjectBuildOperation(Collection2<BuildTarget> targetsT
return new CompositeBuildOperation(operations); return new CompositeBuildOperation(operations);
} }


protected boolean addOperation(IToolOperation toolOp) {
return operations.add(toolOp);
}

protected void addCompositeBuildOperationMessage() { protected void addCompositeBuildOperationMessage() {
String startMsg = headerBIG(format(MSG_BuildingProject, LangCore_Actual.LANGUAGE_NAME, project.getName())); String startMsg = headerBIG(format(MSG_BuildingProject, LangCore_Actual.LANGUAGE_NAME, project.getName()));
addOperation(newMessageOperation(opInfo, startMsg)); addOperation(newMessageOperation(opInfo, startMsg));
} }


protected boolean addOperation(IToolOperation toolOp) { protected IToolOperation doCreateClearBuildMarkersOperation() {
return operations.add(toolOp); return (pm) -> {
} boolean hadDeletedMarkers = doDeleteProjectMarkers(buildProblemId, pm);

if(hadDeletedMarkers) {
protected void addMarkerCleanOperation() { LangCore.getToolManager().notifyMessageEvent(new MessageEventInfo(opInfo,
addOperation((pm) -> deleteProjectMarkers(LangCore_Actual.BUILD_PROBLEM_ID)); format(MSG_ClearingMarkers, project.getName()) + "\n"));
}
};
} }


protected void deleteProjectMarkers(String markerType) { @SuppressWarnings("unused")
protected boolean doDeleteProjectMarkers(String markerType, IProgressMonitor pm) {
try { try {
project.deleteMarkers(markerType, true, IResource.DEPTH_INFINITE); IMarker[] findMarkers = project.findMarkers(markerType, true, IResource.DEPTH_INFINITE);
if(findMarkers.length != 0) {
project.deleteMarkers(markerType, true, IResource.DEPTH_INFINITE);
return true;
}
} catch (CoreException ce) { } catch (CoreException ce) {
LangCore.logStatus(ce); LangCore.logStatus(ce);
} }
return false;
} }


protected IToolOperation newBuildTargetOperation(IProject project, BuildTarget buildTarget) protected IToolOperation newBuildTargetOperation(IProject project, BuildTarget buildTarget)
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public BuildAllTargetsAction(BuildTargetsContainer buildTargetContainer) {
@Override @Override
protected void doJobRun(IProgressMonitor pm) throws CoreException, CommonException, OperationCancellation { protected void doJobRun(IProgressMonitor pm) throws CoreException, CommonException, OperationCancellation {
Collection2<BuildTarget> enabledTargets = getBuildInfo().getBuildTargets(); Collection2<BuildTarget> enabledTargets = getBuildInfo().getBuildTargets();
getBuildManager().newBuildTargetOperation(getProject(), enabledTargets).execute(pm); getBuildManager().newBuildTargetsOperation(getProject(), enabledTargets).execute(pm);
} }
} }


Expand All @@ -183,7 +183,7 @@ public BuildEnabledTargetsAction(BuildTargetsContainer buildTargetContainer) {
@Override @Override
protected void doJobRun(IProgressMonitor pm) throws CoreException, CommonException, OperationCancellation { protected void doJobRun(IProgressMonitor pm) throws CoreException, CommonException, OperationCancellation {
ArrayList2<BuildTarget> enabledTargets = getBuildInfo().getEnabledTargets(); ArrayList2<BuildTarget> enabledTargets = getBuildInfo().getEnabledTargets();
getBuildManager().newBuildTargetOperation(getProject(), enabledTargets).execute(pm); getBuildManager().newBuildTargetsOperation(getProject(), enabledTargets).execute(pm);
} }
} }


Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2014, 2014 Bruno Medeiros and other Contributors. * Copyright (c) 2014 Bruno Medeiros and other Contributors.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
Expand All @@ -25,13 +25,13 @@
import org.eclipse.ui.console.IOConsoleOutputStream; import org.eclipse.ui.console.IOConsoleOutputStream;


import melnorme.lang.ide.core.ILangOperationsListener; import melnorme.lang.ide.core.ILangOperationsListener;
import melnorme.lang.ide.core.LangCore_Actual;
import melnorme.lang.ide.core.operations.MessageEventInfo; import melnorme.lang.ide.core.operations.MessageEventInfo;
import melnorme.lang.ide.core.operations.OperationInfo; import melnorme.lang.ide.core.operations.OperationInfo;
import melnorme.lang.ide.core.operations.ProcessStartInfo; import melnorme.lang.ide.core.operations.ProcessStartInfo;
import melnorme.lang.ide.core.operations.ToolchainPreferences; import melnorme.lang.ide.core.operations.ToolchainPreferences;
import melnorme.lang.ide.core.utils.process.AbstractRunProcessTask.ProcessStartHelper; import melnorme.lang.ide.core.utils.process.AbstractRunProcessTask.ProcessStartHelper;
import melnorme.lang.ide.ui.LangImages; import melnorme.lang.ide.ui.LangImages;
import melnorme.lang.ide.ui.LangUIPlugin_Actual;
import melnorme.lang.ide.ui.utils.ConsoleUtils; import melnorme.lang.ide.ui.utils.ConsoleUtils;
import melnorme.lang.ide.ui.utils.UIOperationsStatusHandler; import melnorme.lang.ide.ui.utils.UIOperationsStatusHandler;
import melnorme.lang.tooling.data.StatusLevel; import melnorme.lang.tooling.data.StatusLevel;
Expand All @@ -43,8 +43,6 @@


public abstract class AbstractToolsConsoleHandler implements ILangOperationsListener { public abstract class AbstractToolsConsoleHandler implements ILangOperationsListener {


protected static final String BUILD_CONSOLE_NAME = LangCore_Actual.LANGUAGE_NAME + " build";

public AbstractToolsConsoleHandler() { public AbstractToolsConsoleHandler() {
super(); super();
} }
Expand Down Expand Up @@ -93,7 +91,7 @@ protected final String getOperationConsoleName(IProject project) {
} }


protected String getGlobalConsoleName() { protected String getGlobalConsoleName() {
return BUILD_CONSOLE_NAME; return LangUIPlugin_Actual.TOOLS_CONSOLE_NAME;
} }


protected String getProjectNameSuffix(IProject project) { protected String getProjectNameSuffix(IProject project) {
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import java.util.List; import java.util.List;


import melnorme.lang.ide.core.LangCore_Actual;
import melnorme.lang.ide.ui.editor.hover.ILangEditorTextHover; import melnorme.lang.ide.ui.editor.hover.ILangEditorTextHover;
import melnorme.lang.ide.ui.views.StructureElementLabelProvider; import melnorme.lang.ide.ui.views.StructureElementLabelProvider;


Expand Down Expand Up @@ -48,6 +49,8 @@ public static StructureElementLabelProvider getStructureElementLabelProvider() {


/* ----------------- UI messages: ----------------- */ /* ----------------- UI messages: ----------------- */


public static final String TOOLS_CONSOLE_NAME = LangCore_Actual.LANGUAGE_NAME + " build";

public static final String DAEMON_TOOL_Name = "gocode"; public static final String DAEMON_TOOL_Name = "gocode";
public static final String DAEMON_TOOL_ConsoleName = "Oracle/gocode log"; public static final String DAEMON_TOOL_ConsoleName = "Oracle/gocode log";


Expand Down

0 comments on commit 8bcbdca

Please sign in to comment.