Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #118 from Shan1024/run-config-update
Browse files Browse the repository at this point in the history
Update run configurations
  • Loading branch information
sameerajayasoma authored Feb 19, 2017
2 parents 6c67437 + 26a1fe7 commit 8b8795f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
import org.ballerinalang.plugins.idea.sdk.BallerinaSdkUtil;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.ballerinalang.plugins.idea.run.configuration.BallerinaRunUtil.PARAMETER_REGEX;

public class BallerinaApplicationRunningState extends BallerinaRunningState {

public BallerinaApplicationRunningState(Project project, String params, ExecutionEnvironment environment) {
Expand All @@ -36,22 +43,33 @@ public BallerinaApplicationRunningState(Project project, String params, Executio

@Override
public String getCommand() {
return "run";
return "main";
}

@NotNull
@Override
protected ProcessHandler startProcess() throws ExecutionException {
GeneralCommandLine commandLine = new GeneralCommandLine();
commandLine.setExePath(ObjectUtils.notNull(BallerinaSdkUtil.getBallerinaExecutablePath(getProject())));
commandLine.addParameter("run");
commandLine.addParameter(getCommand());
commandLine.addParameter(BallerinaRunUtil.getOpenFilePath(getProject()));
commandLine.withCharset(CharsetToolkit.UTF8_CHARSET);
// Add program arguments
commandLine.addParameter(getParams());
getArguments(getParams()).forEach(commandLine::addParameter);

KillableColoredProcessHandler handler = new KillableColoredProcessHandler(commandLine, true);
ProcessTerminatedListener.attach(handler);
return handler;
}

private List<String> getArguments(String params) {
List<String> results = new ArrayList<>();
Pattern pattern = Pattern.compile(PARAMETER_REGEX);
Matcher matcher = pattern.matcher(params);
while (matcher.find()) {
results.add(matcher.group(0));
}
return results;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

public class BallerinaRunUtil {

public static String PARAMETER_REGEX = "\".+?(?<!\\\\)\"|\\w+";

private BallerinaRunUtil() {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public String getCommand() {
protected ProcessHandler startProcess() throws ExecutionException {
GeneralCommandLine commandLine = new GeneralCommandLine();
commandLine.setExePath(ObjectUtils.notNull(BallerinaSdkUtil.getBallerinaExecutablePath(getProject())));
commandLine.addParameter("run");
commandLine.addParameter(getCommand());
commandLine.addParameter(BallerinaRunUtil.getOpenFilePath(getProject()));
commandLine.withCharset(CharsetToolkit.UTF8_CHARSET);
Expand Down

0 comments on commit 8b8795f

Please sign in to comment.