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

Commit

Permalink
LANG: addendum to previous BuildManager changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed Jul 2, 2015
1 parent 0044dec commit 8ed2f3e
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 167 deletions.
Expand Up @@ -21,6 +21,7 @@
import melnorme.lang.ide.core.ILangOperationsListener;
import melnorme.lang.ide.core.LangCore;
import melnorme.lang.ide.core.utils.EclipseUtils;
import melnorme.lang.ide.core.utils.ResourceUtils;
import melnorme.lang.ide.core.utils.process.AbstractRunProcessTask;
import melnorme.lang.ide.core.utils.process.EclipseCancelMonitor;
import melnorme.lang.tooling.data.PathValidator;
Expand Down Expand Up @@ -85,6 +86,13 @@ protected PathValidator getPathValidator() {

/* ----------------- ----------------- */

public ProcessBuilder createSDKProcessBuilder(IProject project, String... sdkOptions)
throws CoreException, CommonException {
Location projectLocation = ResourceUtils.getProjectLocation(project);
Path sdkToolPath = getSDKToolPath();
return createToolProcessBuilder(sdkToolPath, projectLocation, sdkOptions);
}

public ProcessBuilder createToolProcessBuilder(Path buildToolCmdPath, Location workingDir,
String... arguments) {
return ProcessUtils.createProcessBuilder(buildToolCmdPath, workingDir, true, arguments);
Expand Down
Expand Up @@ -10,8 +10,6 @@
*******************************************************************************/
package melnorme.lang.ide.core.operations;

import java.nio.file.Path;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;

Expand All @@ -36,10 +34,6 @@ protected AbstractToolManager getToolManager() {
return LangCore.getToolManager();
}

protected Path getBuildToolPath() throws CommonException {
return getToolManager().getSDKToolPath();
}

protected ExternalProcessResult runBuildTool(IProgressMonitor monitor, ProcessBuilder pb)
throws CommonException, OperationCancellation {
return getToolManager().newRunToolTask(pb, getProject(), monitor).runProcess();
Expand Down
@@ -0,0 +1,148 @@
/*******************************************************************************
* Copyright (c) 2015, 2015 IBM Corporation and others.
* 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:
* Bruno Medeiros - initial API and implementation
*******************************************************************************/
package melnorme.lang.ide.core.operations;

import static melnorme.utilbox.core.Assert.AssertNamespace.assertFail;

import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.core.filebuffers.ITextFileBufferManager;
import org.eclipse.core.filebuffers.LocationKind;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;

import melnorme.lang.ide.core.LangCore;
import melnorme.lang.ide.core.LangCore_Actual;
import melnorme.lang.ide.core.utils.ResourceUtils;
import melnorme.lang.tooling.ast.SourceRange;
import melnorme.lang.tooling.data.StatusLevel;
import melnorme.lang.tooling.ops.SourceLineColumnRange;
import melnorme.lang.tooling.ops.ToolSourceMessage;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.Location;

public class BuildMarkersUtil {

public static void addErrorMarkers(Iterable<ToolSourceMessage> buildErrors, Location rootPath) throws CoreException {

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

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

}

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

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

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

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

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

IFile file = (IFile) resource;

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

SourceLineColumnRange range = buildmessage.range;

SourceRange messageSR;

ITextFileBufferManager fileBufferManager = FileBuffers.getTextFileBufferManager();
fileBufferManager.connect(file.getFullPath(), LocationKind.IFILE, null);

try {
ITextFileBuffer tfb = fileBufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
messageSR = getMessageRangeUsingDocInfo(range, tfb.getDocument());
} finally {
fileBufferManager.disconnect(file.getFullPath(), LocationKind.IFILE, null);
}

if(messageSR != null) {
try {
marker.setAttribute(IMarker.CHAR_START, messageSR.getStartPos());
marker.setAttribute(IMarker.CHAR_END, messageSR.getEndPos());
} catch (CoreException ce) {
LangCore.logStatus(ce);
}
}

}

protected static SourceRange getMessageRangeUsingDocInfo(SourceLineColumnRange range, IDocument doc) {

int charStart;
int charEnd;

int startLine;
int startColumn;

try {
try {
startLine = range.getValidLineIndex();
startColumn = range.getValidColumnIndex();

charStart = doc.getLineOffset(startLine) + startColumn;
} catch (CommonException ce) {
return null;
}

int endLine;
int endColumn;
try {
endLine = range.getValidEndLineIndex();
endColumn = range.getValidEndColumnIndex();

charEnd = doc.getLineOffset(endLine) + endColumn;

} catch (CommonException e) {
charEnd = charStart + 1;
}
} catch(BadLocationException e ) {
return null;
}

return SourceRange.srStartToEnd(charStart, charEnd);
}

public static int severityFrom(StatusLevel statusLevel) {
switch (statusLevel) {
case ERROR: return IMarker.SEVERITY_ERROR;
case WARNING: return IMarker.SEVERITY_WARNING;
case INFO: return IMarker.SEVERITY_INFO;
case OK: return IMarker.SEVERITY_INFO; // Shouldn't happen
}
throw assertFail();
}

}
Expand Up @@ -14,11 +14,9 @@
import static melnorme.lang.ide.core.utils.TextMessageUtils.headerBIG;
import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull;

import java.nio.file.Path;
import java.util.concurrent.Callable;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

import melnorme.lang.ide.core.LangCore;
Expand All @@ -27,7 +25,6 @@
import melnorme.lang.ide.core.project_model.BuildManagerMessages;
import melnorme.lang.ide.core.project_model.ProjectBuildInfo;
import melnorme.utilbox.collections.ArrayList2;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;

public class BuildOperationCreator implements BuildManagerMessages {
Expand Down Expand Up @@ -104,30 +101,4 @@ public OperationInfo call() throws RuntimeException {
}
}

public static abstract class CommonBuildTargetOperation implements IBuildTargetOperation {

protected final OperationInfo parentOperationInfo;
protected final BuildTarget buildTarget;
protected final Path buildToolPath;

public CommonBuildTargetOperation(OperationInfo parentOperationInfo, Path buildToolPath,
BuildTarget buildTarget) {
this.buildToolPath = buildToolPath;
this.parentOperationInfo = assertNotNull(parentOperationInfo);
this.buildTarget = assertNotNull(buildTarget);
}

protected Path getBuildToolPath() throws CommonException {
return buildToolPath;
}

protected String getBuildTargetName() {
return buildTarget.getTargetName();
}

@Override
public abstract void execute(IProgressMonitor pm) throws CoreException, CommonException, OperationCancellation;

}

}
Expand Up @@ -17,11 +17,11 @@
import org.eclipse.core.resources.IProject;

import melnorme.lang.ide.core.LangCore;
import melnorme.lang.ide.core.operations.BuildOperationCreator.CommonBuildTargetOperation;
import melnorme.lang.ide.core.project_model.BuildManager;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.HashcodeUtil;

public abstract class BuildTarget {
public class BuildTarget {

protected final boolean enabled;
protected final String targetName;
Expand Down Expand Up @@ -66,7 +66,11 @@ public AbstractToolManager getToolManager() {
return LangCore.getToolManager();
}

public abstract CommonBuildTargetOperation newBuildTargetOperation(OperationInfo parentOpInfo, IProject project,
boolean fullBuild) throws CommonException;
public CommonBuildTargetOperation newBuildTargetOperation(OperationInfo parentOpInfo, IProject project,
boolean fullBuild) throws CommonException {
Path buildToolPath = getToolManager().getSDKToolPath();
BuildManager buildMgr = LangCore.getBuildManager();
return buildMgr.createBuildTargetOperation(parentOpInfo, project, buildToolPath, this, fullBuild);
}

}
@@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright (c) 2015, 2015 IBM Corporation and others.
* 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:
* Bruno Medeiros - initial API and implementation
*******************************************************************************/
package melnorme.lang.ide.core.operations;

import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull;

import java.nio.file.Path;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;

public abstract class CommonBuildTargetOperation extends AbstractToolManagerOperation {

protected final OperationInfo parentOperationInfo;
protected final BuildTarget buildTarget;
protected final Path buildToolPath;
protected final boolean fullBuild;

public CommonBuildTargetOperation(OperationInfo parentOpInfo, IProject project,
Path buildToolPath, BuildTarget buildTarget, boolean fullBuild) {
super(project);
this.buildToolPath = buildToolPath;
this.fullBuild = fullBuild;
this.parentOperationInfo = assertNotNull(parentOpInfo);
this.buildTarget = assertNotNull(buildTarget);
}

protected Path getBuildToolPath2() throws CommonException {
return buildToolPath;
}

protected String getBuildTargetName() {
return buildTarget.getTargetName();
}

@Override
public abstract void execute(IProgressMonitor pm) throws CoreException, CommonException, OperationCancellation;

}

0 comments on commit 8ed2f3e

Please sign in to comment.