mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
splitCommandInParameters method moved to common code in Executor
This commit is contained in:
@@ -25,6 +25,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@@ -147,6 +148,47 @@ public class Executor {
|
||||
return stdout;
|
||||
}
|
||||
|
||||
protected static List<String> splitCommandInParameters(String command) {
|
||||
List<String> split = new ArrayList<String>();
|
||||
|
||||
boolean insideParam = false;
|
||||
StringBuilder currentParam = new StringBuilder();
|
||||
for (char c : command.toCharArray()) {
|
||||
boolean flush = false;
|
||||
if (insideParam) {
|
||||
if (c == '\'') {
|
||||
insideParam = false;
|
||||
flush = true;
|
||||
}
|
||||
else {
|
||||
currentParam.append(c);
|
||||
}
|
||||
}
|
||||
else if (c == '\'') {
|
||||
insideParam = true;
|
||||
}
|
||||
else if (c == ' ') {
|
||||
flush = true;
|
||||
}
|
||||
else {
|
||||
currentParam.append(c);
|
||||
}
|
||||
|
||||
if (flush) {
|
||||
if (!StringUtil.isEmptyOrSpaces(currentParam.toString())) {
|
||||
split.add(currentParam.toString());
|
||||
}
|
||||
currentParam = new StringBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
// last flush
|
||||
if (!StringUtil.isEmptyOrSpaces(currentParam.toString())) {
|
||||
split.add(currentParam.toString());
|
||||
}
|
||||
return split;
|
||||
}
|
||||
|
||||
protected static String findExecutable(String programName, String unixExec, String winExec, Collection<String> pathEnvs) {
|
||||
String exec = findInPathEnvs(programName, pathEnvs);
|
||||
if (exec != null) {
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
package git4idea.test;
|
||||
|
||||
import com.intellij.dvcs.test.Executor;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import git4idea.repo.GitRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -59,46 +57,6 @@ public class GitExecutor extends Executor {
|
||||
throw new RuntimeException("fatal error during execution of Git command: $command");
|
||||
}
|
||||
|
||||
private static List<String> splitCommandInParameters(String command) {
|
||||
List<String> split = new ArrayList<String>();
|
||||
|
||||
boolean insideParam = false;
|
||||
StringBuilder currentParam = new StringBuilder();
|
||||
for (char c : command.toCharArray()) {
|
||||
boolean flush = false;
|
||||
if (insideParam) {
|
||||
if (c == '\'') {
|
||||
insideParam = false;
|
||||
flush = true;
|
||||
}
|
||||
else {
|
||||
currentParam.append(c);
|
||||
}
|
||||
}
|
||||
else if (c == '\'') {
|
||||
insideParam = true;
|
||||
}
|
||||
else if (c == ' ') {
|
||||
flush = true;
|
||||
}
|
||||
else {
|
||||
currentParam.append(c);
|
||||
}
|
||||
|
||||
if (flush) {
|
||||
if (!StringUtil.isEmptyOrSpaces(currentParam.toString())) {
|
||||
split.add(currentParam.toString());
|
||||
}
|
||||
currentParam = new StringBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
// last flush
|
||||
if (!StringUtil.isEmptyOrSpaces(currentParam.toString())) {
|
||||
split.add(currentParam.toString());
|
||||
}
|
||||
return split;
|
||||
}
|
||||
|
||||
public static String git(GitRepository repository, String command) {
|
||||
if (repository != null) {
|
||||
|
||||
Reference in New Issue
Block a user