diff --git a/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/AbstractToolManager.java b/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/AbstractToolManager.java index 084c829e7..0a33ffb93 100644 --- a/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/AbstractToolManager.java +++ b/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/AbstractToolManager.java @@ -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; @@ -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); diff --git a/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/AbstractToolManagerOperation.java b/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/AbstractToolManagerOperation.java index 571b3b26a..3dc6250fa 100644 --- a/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/AbstractToolManagerOperation.java +++ b/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/AbstractToolManagerOperation.java @@ -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; @@ -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(); diff --git a/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/BuildMarkersUtil.java b/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/BuildMarkersUtil.java new file mode 100644 index 000000000..ff0047269 --- /dev/null +++ b/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/BuildMarkersUtil.java @@ -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 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(); + } + +} \ No newline at end of file diff --git a/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/BuildOperationCreator.java b/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/BuildOperationCreator.java index 5f73df896..f807ea214 100644 --- a/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/BuildOperationCreator.java +++ b/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/BuildOperationCreator.java @@ -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; @@ -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 { @@ -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; - - } - } \ No newline at end of file diff --git a/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/BuildTarget.java b/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/BuildTarget.java index 6d4cf9a5c..501e593a0 100644 --- a/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/BuildTarget.java +++ b/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/BuildTarget.java @@ -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; @@ -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); + } } \ No newline at end of file diff --git a/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/CommonBuildTargetOperation.java b/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/CommonBuildTargetOperation.java new file mode 100644 index 000000000..a6836e8a5 --- /dev/null +++ b/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/CommonBuildTargetOperation.java @@ -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; + +} \ No newline at end of file diff --git a/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/LangProjectBuilder.java b/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/LangProjectBuilder.java index b9e10406b..ee9f8a5a3 100644 --- a/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/LangProjectBuilder.java +++ b/plugin_ide.core/src-lang/melnorme/lang/ide/core/operations/LangProjectBuilder.java @@ -13,36 +13,23 @@ import static melnorme.lang.ide.core.project_model.BuildManagerMessages.MSG_Starting_LANG_Build; import static melnorme.lang.ide.core.utils.TextMessageUtils.headerVeryBig; -import static melnorme.utilbox.core.Assert.AssertNamespace.assertFail; import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull; import static melnorme.utilbox.core.Assert.AssertNamespace.assertTrue; import java.text.MessageFormat; import java.util.Map; -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.IBuildConfiguration; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -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.EclipseUtils; 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.concurrency.OperationCancellation; import melnorme.utilbox.core.CommonException; import melnorme.utilbox.misc.Location; @@ -61,7 +48,7 @@ protected Location getProjectLocation() throws CoreException { protected void deleteProjectBuildMarkers() { try { - getProject().deleteMarkers(getBuildProblemId(), true, IResource.DEPTH_INFINITE); + getProject().deleteMarkers(LangCore_Actual.BUILD_PROBLEM_ID, true, IResource.DEPTH_INFINITE); } catch (CoreException ce) { LangCore.logStatus(ce); } @@ -228,116 +215,4 @@ protected void processToolResult(ExternalProcessResult buildAllResult) } - /* ----------------- Problem markers handling ----------------- */ - - protected void addErrorMarkers(Iterable 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, getBuildProblemId()); - } - } - - } - - protected 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(); - } - -} +} \ No newline at end of file diff --git a/plugin_ide.core/src-lang/melnorme/lang/ide/core/project_model/BuildManager.java b/plugin_ide.core/src-lang/melnorme/lang/ide/core/project_model/BuildManager.java index 981fc18fe..7698c617b 100644 --- a/plugin_ide.core/src-lang/melnorme/lang/ide/core/project_model/BuildManager.java +++ b/plugin_ide.core/src-lang/melnorme/lang/ide/core/project_model/BuildManager.java @@ -10,11 +10,15 @@ *******************************************************************************/ package melnorme.lang.ide.core.project_model; +import java.nio.file.Path; + import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.Platform; import melnorme.lang.ide.core.LangCore; import melnorme.lang.ide.core.operations.BuildTarget; +import melnorme.lang.ide.core.operations.CommonBuildTargetOperation; +import melnorme.lang.ide.core.operations.OperationInfo; import melnorme.lang.ide.core.utils.prefs.StringPreference; import melnorme.utilbox.collections.ArrayList2; import melnorme.utilbox.core.CommonException; @@ -61,7 +65,12 @@ protected SimpleLogger getLog() { } - protected abstract BuildTarget createBuildTarget(boolean enabled, String targetName); + protected BuildTarget createBuildTarget(boolean enabled, String targetName) { + return new BuildTarget(enabled, targetName); + } + + public abstract CommonBuildTargetOperation createBuildTargetOperation(OperationInfo parentOpInfo, + IProject project, Path buildToolPath, BuildTarget buildTarget, boolean fullBuild); /* ----------------- ----------------- */