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

Commit

Permalink
Merging [MelnormeLang]
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed Jun 14, 2016
2 parents 14333fd + 39a9d92 commit 0856201
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 131 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
Expand All @@ -35,13 +36,16 @@
import melnorme.lang.ide.core.launch.CompositeBuildTargetSettings;
import melnorme.lang.ide.core.launch.LaunchMessages;
import melnorme.lang.ide.core.launch.ProcessLaunchInfo;
import melnorme.lang.ide.core.launch.ProcessLaunchInfoValidator;
import melnorme.lang.ide.core.operations.build.BuildManager;
import melnorme.lang.ide.core.operations.build.BuildTarget;
import melnorme.lang.ide.core.utils.EclipseUtils;
import melnorme.lang.ide.core.utils.ProjectValidator;
import melnorme.lang.tooling.commands.CommandInvocation;
import melnorme.lang.tooling.common.ops.CommonOperation;
import melnorme.lang.tooling.utils.ArgumentsParser;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.Location;

public abstract class LangLaunchConfigurationDelegate extends LaunchConfigurationDelegate {

Expand All @@ -64,7 +68,7 @@ protected CoreException errorMsg(String messagePattern, Object... arguments) thr
@Override
public final ILaunch getLaunch(ILaunchConfiguration configuration, String mode) throws CoreException {
try {
launchInfo = getLaunchValidator(configuration).getValidProcessLaunchInfo();
launchInfo = getValidLaunchInfo(configuration);
} catch(CommonException ce) {
throw LangCore.createCoreException(ce);
}
Expand Down Expand Up @@ -106,10 +110,9 @@ public final boolean preLaunchCheck(ILaunchConfiguration configuration, String m
return super.preLaunchCheck(configuration, mode, monitor);
}

protected ProcessLaunchInfoValidator getLaunchValidator(ILaunchConfiguration config)
protected ProcessLaunchInfo getValidLaunchInfo(ILaunchConfiguration configuration)
throws CommonException, CoreException {

BuildTargetLaunchCreator launchSettings = new BuildTargetLaunchCreator(config);
BuildTargetLaunchCreator launchSettings = new BuildTargetLaunchCreator(configuration);

BuildTargetSource buildTargetSource = new BuildTargetSource() {
@Override
Expand Down Expand Up @@ -140,13 +143,39 @@ public CommandInvocation getBuildCommand() {
}
};

return new ProcessLaunchInfoValidator(
buildTargetSettings,
evaluateStringVars(config.getAttribute(LaunchConstants.ATTR_PROGRAM_ARGUMENTS, "")),
evaluateStringVars(config.getAttribute(LaunchConstants.ATTR_WORKING_DIRECTORY, "")),
config.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map<String, String>) null),
config.getAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, true)
);
boolean appendEnv = configuration.getAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, true);

String programArguments = evaluateStringVars(configuration.getAttribute(LaunchConstants.ATTR_PROGRAM_ARGUMENTS, ""));

String workingDirectoryString = evaluateStringVars(configuration.getAttribute(LaunchConstants.ATTR_WORKING_DIRECTORY, ""));

BuildManager buildManager = LangCore.getBuildManager();

IProject project = buildTargetSource.getValidProject();
BuildTarget buildTarget = buildTargetSettings.getValidBuildTarget();
CommonOperation buildOperation = buildTarget == null ?
null : buildManager.newBuildTargetOperation(project, buildTarget);

Location programLoc = buildTarget.getValidExecutableLocation(); // not null

String[] processArgs = ArgumentsParser.parse(programArguments).toArray(String.class);

IPath workingDirectory = workingDirectoryString.isEmpty() ? null : new org.eclipse.core.runtime.Path(workingDirectoryString);

if(workingDirectory == null) {
workingDirectory = project.getLocation();
}

Map<String, String> configEnv = configuration.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map<String, String>) null);

return new ProcessLaunchInfo(
project,
buildOperation,
programLoc,
processArgs,
workingDirectory,
configEnv,
appendEnv);
}

protected IStringVariableManager getVariableManager() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,15 @@ public Location getInputLocation() throws CommonException {

@Override
protected void doOperation() throws CommonException, OperationCancellation {
prepareOperation();

super.doOperation();
}

protected void prepareOperation() throws CommonException {
if(!getContext2().getOptionalFileLocation().isPresent()) {
throw new CommonException("No file available for editor contents.");
}

super.doOperation();
}

public void saveEditor(NullProgressMonitor pm) {
Expand Down

0 comments on commit 0856201

Please sign in to comment.