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

Commit

Permalink
Command Invocation: actually modify environment
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed Apr 29, 2016
1 parent 042a1ca commit e561eb3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,15 @@ protected void testBuildOperation_Vars(ProjectBuildInfo buildInfo, BuildTarget b

}

protected Indexable<String> getBuildOperation(ProjectBuildInfo buildInfo, BuildTarget btB, String buildArguments)
protected Iterable<String> getBuildOperation(ProjectBuildInfo buildInfo, BuildTarget btB, String buildArguments)
throws CommonException {
BuildTargetData dataCopy = btB.getDataCopy();
dataCopy.buildCommand = new CommandInvocation(buildArguments);
BuildTarget newBuildTarget = buildInfo.buildMgr.createBuildTarget(buildInfo.project, dataCopy);

ToolManager toolMgr = buildInfo.buildMgr.getToolManager();
BuildTargetOperation buildOperation = newBuildTarget.getBuildOperation(toolMgr, opMonitor);
return buildOperation.getEffectiveProccessCommandLine();
return buildOperation.getConfiguredProcessBuilder().command();
}

/* ----------------- ----------------- */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ public final ProcessBuilder createToolProcessBuilder(IProject project, Path tool
}

public ProcessBuilder createToolProcessBuilder(Indexable<String> commandLine, Location workingDir) {
return ProcessUtils.createProcessBuilder(commandLine, workingDir);
return modifyToolProcessBuilder(ProcessUtils.createProcessBuilder(commandLine, workingDir));
}

public ProcessBuilder modifyToolProcessBuilder(ProcessBuilder pb) {
return pb;
}

public ProcessBuilder createSimpleProcessBuilder(IProject project, String... commands)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import melnorme.lang.ide.core.operations.ILangOperationsListener_Default.IOperationMonitor;
import melnorme.lang.ide.core.operations.ToolManager;
import melnorme.lang.ide.core.utils.ProgressSubTaskHelper;
import melnorme.lang.tooling.data.StatusException;
import melnorme.utilbox.collections.Indexable;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;
Expand Down Expand Up @@ -75,16 +76,16 @@ protected String getBuildOperationName() {

public Indexable<String> getEffectiveProccessCommandLine() throws CommonException {
VariablesResolver variablesManager = toolManager.getVariablesManager(option(getProject()));
return buildCommand.getValidatedCommandArguments(variablesManager).getValidatedValue();
return buildCommand.validateCommandArguments(variablesManager);
}

public ProcessBuilder getToolProcessBuilder() throws CommonException, OperationCancellation {
return getProcessBuilder3(getEffectiveProccessCommandLine());
public ProcessBuilder getConfiguredProcessBuilder() throws StatusException {
VariablesResolver variablesManager = toolManager.getVariablesManager(option(getProject()));
return buildCommand.getProcessBuilder(variablesManager);
}

protected ProcessBuilder getProcessBuilder3(Indexable<String> commandLine)
throws CommonException, OperationCancellation {
return getToolManager().createToolProcessBuilder(commandLine, getProjectLocation());
public ProcessBuilder getToolProcessBuilder() throws CommonException, OperationCancellation {
return getToolManager().modifyToolProcessBuilder(getConfiguredProcessBuilder());
}

public void runBuildToolAndProcessOutput(ProcessBuilder pb, IProgressMonitor pm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull;
import static melnorme.utilbox.core.CoreUtil.areEqual;

import java.util.Map;
import java.util.Map.Entry;

import org.eclipse.debug.core.DebugPlugin;

import melnorme.lang.tooling.data.Severity;
import melnorme.lang.tooling.data.StatusException;
import melnorme.lang.tooling.data.validation.ValidatedValueSource;
import melnorme.lang.utils.ProcessUtils;
import melnorme.utilbox.collections.ArrayList2;
import melnorme.utilbox.collections.HashMap2;
import melnorme.utilbox.collections.Indexable;
Expand Down Expand Up @@ -73,8 +77,31 @@ public boolean isAppendEnvironment() {

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

public ProcessBuilder getProcessBuilder(VariablesResolver variablesResolver) throws StatusException {
Indexable<String> CommandLine = validateCommandArguments(variablesResolver);

ProcessBuilder pb = ProcessUtils.createProcessBuilder(CommandLine, null);

setupEnvironment(pb.environment());

return pb;
}

public void setupEnvironment(Map<String, String> environment) {
if(!isAppendEnvironment()) {
environment.clear();
}
for (Entry<String, String> envVar : getEnvironmentVars()) {
environment.put(envVar.getKey(), envVar.getValue());
}
}

public void validate(VariablesResolver variablesResolver) throws StatusException {
getValidatedCommandArguments(variablesResolver).validate();
validateCommandArguments(variablesResolver);
}

public Indexable<String> validateCommandArguments(VariablesResolver variablesResolver) throws StatusException {
return getValidatedCommandArguments(variablesResolver).getValidatedValue();
}

public ValidatedCommandArgumentsSource getValidatedCommandArguments(VariablesResolver variablesResolver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

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

import java.io.File;
import java.nio.file.Path;

import melnorme.lang.tooling.ToolingMessages;
Expand All @@ -24,16 +23,11 @@
public class ProcessUtils {

public static ProcessBuilder createProcessBuilder(Indexable<String> commandLine, Location workingDir) {
File file = workingDir == null ? null : workingDir.toFile();
return createProcessBuilder(commandLine, file);
}

public static ProcessBuilder createProcessBuilder(Indexable<String> commandLine, File workingDir) {
assertTrue(commandLine.size() > 0);

ProcessBuilder pb = new ProcessBuilder(commandLine.toArrayList());
if(workingDir != null) {
pb.directory(workingDir);
pb.directory(workingDir.toFile());
}
return pb;
}
Expand Down

0 comments on commit e561eb3

Please sign in to comment.