Commit 371c15fb authored by Christian Wulf's avatar Christian Wulf

fixed streamglobber

parent e09b55a8
......@@ -26,7 +26,7 @@ public class CommandLineGitProvider implements GitProvider {
this.GIT_CMD = resolveGitFilename(logger);
}
private String resolveGitFilename(GitLogger logger) {
private String resolveGitFilename(final GitLogger logger) {
File gitFile = EnvironmentVariable.findExecutableOnPath("git.cmd");
if (gitFile == null) {
gitFile = EnvironmentVariable.findExecutableOnPath("git.exe");
......@@ -47,12 +47,13 @@ public class CommandLineGitProvider implements GitProvider {
if (!workingDir.exists()) throw new IllegalStateException("File not found: " + workingDir);
logger.logWorkingDir(workingDir.getAbsolutePath());
logger.logNativeCommand(cmdArray);
Process process = null;
try {
ProcessBuilder processBuilder = new ProcessBuilder(cmdArray).directory(workingDir);
// processBuilder.redirectError(new File("error.txt"));
// processBuilder.redirectInput(new File("input.txt"));
// processBuilder.redirectOutput(new File("output.txt"));
Process process = processBuilder.start();
process = processBuilder.start();
StreamGobbler inputStreamGobbler = new StreamGobbler(process.getInputStream());
inputStreamGobbler.start();
......@@ -72,9 +73,14 @@ public class CommandLineGitProvider implements GitProvider {
}
logger.logExitValue(exitvalue);
} catch (IOException | InterruptedException e) {
} catch (IOException e) {
logger.catching(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
if (process != null) process.destroy();
}
}
@Override
......@@ -90,7 +96,7 @@ public class CommandLineGitProvider implements GitProvider {
}
@Override
public void add(String globPattern) {
public void add(final String globPattern) {
logger.startAdding();
execSynchronously(GIT_CMD, ADD_TO_INDEX_CMD, globPattern);
}
......
......@@ -19,7 +19,7 @@ class StreamGobbler extends Thread {
private final List<String> loggedLines = new LinkedList<>();
private IOException exception;
public StreamGobbler(InputStream is) {
public StreamGobbler(final InputStream is) {
this.is = is;
}
......
......@@ -49,7 +49,7 @@ public class JTextPaneGitLogger extends EmptyGitLogger {
@Override
public void info(final String line) {
// String trimmedLine = line.trim();
// String trimmedLine = line.trim();
if (!line.isEmpty()) {
boolean displayLine = true;
displayLine = displayLine && !line.equals("#");
......@@ -97,7 +97,7 @@ public class JTextPaneGitLogger extends EmptyGitLogger {
@Override
public void catching(final Exception e) {
addErrorToLog(e.getLocalizedMessage());
addErrorToLog("Error while executing action: " + e.getLocalizedMessage());
}
@Override
......
......@@ -8,6 +8,8 @@ public class CommandLineGitProviderTest {
private static final String GITLIB_DIR_NAME = Paths.USER_HOME + "/workspace-test/gitlib";
private static final String GITLIB_GIT_URL = "gitlab@build.se.informatik.uni-kiel.de:chw/gitlib.git";
private static final String COCKPIT_DIR_NAME = Paths.USER_HOME + "/workspace-test/cockpit";
private static final String COCKPIT_GIT_URL = "git@10.20.90.10:cockpit.git";
@Test
public void testClone() throws Exception {
......@@ -26,6 +28,23 @@ public class CommandLineGitProviderTest {
gitProvider.setRepositoryDirName(GITLIB_DIR_NAME);
gitProvider.cloneRepository(GITLIB_GIT_URL);
}
@Test
public void testCloneVPN() throws Exception {
GitLogger logger = new EmptyGitLogger() {
@Override
public void info(final String line) {
System.out.println("i|" + line);
}
@Override
public void error(final String line) {
System.out.println("i|" + line);
}
};
CommandLineGitProvider gitProvider = new CommandLineGitProvider(logger);
gitProvider.setRepositoryDirName(COCKPIT_DIR_NAME);
gitProvider.cloneRepository(COCKPIT_GIT_URL);
}
@Test
public void testStatus() throws Exception {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment