I'm trying to write a simple application in java that will clone automatically a whole trunk from TFS to Git repo using git-tfs. To get data from user i'm using some jtextfields. In one of there jtextfields user must write the trunk name. Everything is working but, if trunk name contains spaces the whole git-tfs process doesn't start and git tfs logs say to respect synopsys.
To run git-tfs the synopsys is:
$ git-tfs.exe --username <username> --password <password> <server-url> <trunk-name> <working-folder-path>
es.:
$ git-tfs.exe --username=myusernamename --password=mypassword http://127.0.0.1:8080/DefaultCollection $/TrunkName C:\workingFolder
Here my code:
commands = new ArrayList<String>();
commands.add("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe");
commands.add("/c");
commands.add("git-tfs.exe");
commands.add("--username=" + usernameTextField.getText());
commands.add("--password=" + passwordTextField.getText());
commands.add(serverUrlTextField.getText());
commands.add(trunkTextField.getText());
commands.add(workingFolder.getText());
ProcessBuilder pb = new ProcessBuilder(this.commands);
Process process = pb.start();
Surfing on the net i've found a solution for git-tfs and it's to write the trunk name in quotas like $/"trunk name/some/path". Running git-tfs with quotas from powershell everything works fine but writing the same in jtextfield application can't run saying again about synopsis.
To test the process builder i tried to modify the ArrayList with commands by adding manually the modified string so it appears:
...
this.commands.add("$/\"trunk name\"");
...
not even like this works so i tried:
...
this.commands.add("$/\\\"trunk name\\\"");
..
and it works.
After this i tried to write the same on jtextfield but it can't work. How could i fix the problem and parse text from jTextField and let the processBuilder work?
Thank you!
i solved the issue by changing from ProcessBuilder to Runtime so now my code is:
commands = new ArrayList<String>();
commands.add("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe");
commands.add("/c");
commands.add("git-tfs.exe");
commands.add("--username=" + usernameTextField.getText());
commands.add("--password=" + passwordTextField.getText());
commands.add(serverUrlTextField.getText());
commands.add(trunkTextField.getText());
commands.add(workingFolder.getText());
Runtime runtime = Runtime.getRuntime();
String[] commandsStringArray = commands.toArray(new String[0]);
Process process = runtime.exec(commandsStringArray);
and checking the projectName as follow:
private String fixProjectName(String projectName) {
if (projectName.contains(" ")) {
String correct = "";
correct = projectName.replace("$/", "");
correct = "$/\\\"" + correct + "\\\" ";
this.projectName = correct;
return correct;
}
return projectName;
}
Btw i'd like same to how to let the ProcessBuilder work.
Each better idea is welcome.
Thank you.