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

Commit

Permalink
LANG: Improved ProgressMonitor task messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed Aug 12, 2015
1 parent c153123 commit 472729c
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ public class LangCoreMessages implements ProcessHelperMessages {
public static String error_notAValidProject
= "Not a valid project.";

/* ----------------- Build ----------------- */

public static final String BUILD_ClearingProblemMarkers = "Clearing problem markers";

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import org.eclipse.core.runtime.IProgressMonitor;

import melnorme.lang.ide.core.LangCore;
import melnorme.lang.ide.core.LangCoreMessages;
import melnorme.lang.ide.core.LangCore_Actual;
import melnorme.lang.ide.core.operations.MessageEventInfo;
import melnorme.lang.ide.core.operations.OperationInfo;
import melnorme.lang.ide.core.operations.build.BuildManager.BuildType;
import melnorme.lang.ide.core.utils.ProgressSubTaskHelper;
import melnorme.lang.ide.core.utils.TextMessageUtils;
import melnorme.utilbox.collections.ArrayList2;
import melnorme.utilbox.collections.Collection2;
Expand Down Expand Up @@ -104,16 +106,20 @@ protected IToolOperation doCreateClearBuildMarkersOperation() {
};
}

@SuppressWarnings("unused")
protected boolean doDeleteProjectMarkers(String markerType, IProgressMonitor pm) {
try {
IMarker[] findMarkers = project.findMarkers(markerType, true, IResource.DEPTH_INFINITE);
if(findMarkers.length != 0) {
project.deleteMarkers(markerType, true, IResource.DEPTH_INFINITE);
return true;
protected boolean doDeleteProjectMarkers(String markerType, IProgressMonitor parentPM) {

try(ProgressSubTaskHelper pm
= new ProgressSubTaskHelper(parentPM, LangCoreMessages.BUILD_ClearingProblemMarkers)) {

try {
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) {
LangCore.logStatus(ce);
}
} catch (CoreException ce) {
LangCore.logStatus(ce);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import melnorme.lang.ide.core.operations.OperationInfo;
import melnorme.lang.ide.core.operations.build.BuildManager.BuildConfiguration;
import melnorme.lang.ide.core.operations.build.BuildManager.BuildType;
import melnorme.lang.ide.core.utils.ProgressSubTaskHelper;
import melnorme.utilbox.collections.ArrayList2;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;
Expand All @@ -45,23 +46,31 @@ public CommonBuildTargetOperation(BuildManager buildManager, ValidatedBuildTarge
this.opInfo = assertNotNull(opInfo);

assertNotNull(validatedBuildTarget);
this.buildConfiguration = validatedBuildTarget.getBuildConfiguration();
this.buildType = validatedBuildTarget.getBuildType();
this.buildConfiguration = assertNotNull(validatedBuildTarget.getBuildConfiguration());
this.buildType = assertNotNull(validatedBuildTarget.getBuildType());
this.effectiveBuildArguments = validatedBuildTarget.getEffectiveBuildArguments();
}

protected BuildConfiguration getConfiguration() {
public BuildConfiguration getConfiguration() {
return buildConfiguration;
}

protected String getConfigurationName() {
public String getConfigurationName() {
return buildConfiguration.getName();
}

protected BuildType getBuildType() {
public BuildType getBuildType() {
return buildType;
}

public String getBuildTypeName() {
return buildType.getName();
}

public String getBuildTargetName() {
return buildManager.getBuildTargetName(getConfigurationName(), getBuildTypeName());
}

protected Path getBuildToolPath() throws CommonException {
return buildToolPath;
}
Expand All @@ -71,9 +80,15 @@ protected String getEffectiveBuildArguments() throws CommonException, CoreExcept
}

@Override
public void execute(IProgressMonitor pm) throws CoreException, CommonException, OperationCancellation {
ProcessBuilder pb = getToolProcessBuilder();
runBuildToolAndProcessOutput(pb, pm);
public void execute(IProgressMonitor parentPM) throws CoreException, CommonException, OperationCancellation {
try(ProgressSubTaskHelper pm = new ProgressSubTaskHelper(parentPM, getBuildOperationName())) {
ProcessBuilder pb = getToolProcessBuilder();
runBuildToolAndProcessOutput(pb, pm);
}
}

protected String getBuildOperationName() {
return "Building " + getBuildTargetName();
}

protected ProcessBuilder getToolProcessBuilder() throws CoreException, CommonException, OperationCancellation {
Expand Down
Original file line number 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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2015 Bruno Medeiros and other Contributors.
* 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.utils;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.ProgressMonitorWrapper;
import org.eclipse.core.runtime.SubProgressMonitor;

public class ProgressSubTaskHelper extends ProgressMonitorWrapper implements AutoCloseable, IProgressMonitor {

public ProgressSubTaskHelper(IProgressMonitor parentMonitor, String subTaskMessage) {
super(new SubProgressMonitor(parentMonitor, 0));
getWrappedProgressMonitor().subTask(subTaskMessage);
}

@Override
public void close() {
getWrappedProgressMonitor().subTask("");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static String getFormattedString(String message, Object... args) {
public static String ExceptionDialog_seeErrorLogMessage =
"See error log for more details.";

/* ----------------- Fields ----------------- */

public static String mainLaunchTab_title =
"Main";
Expand All @@ -38,8 +39,6 @@ public static String getFormattedString(String message, Object... args) {
public static String projectField_chooseProject_title = "Project selection";
public static String projectField_chooseProject_message = "Select a project";

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

public static final String BuildTargetField_title =
"Build Target:";

Expand Down

0 comments on commit 472729c

Please sign in to comment.