Skip to content

Commit ad09d02

Browse files
committed
using Executor class for determining the current version
1 parent 8353f0f commit ad09d02

File tree

2 files changed

+8
-44
lines changed

2 files changed

+8
-44
lines changed

src/org/opensolaris/opengrok/history/GitRepository.java

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import java.util.List;
4242
import java.util.Locale;
4343
import java.util.TreeSet;
44-
import java.util.concurrent.TimeUnit;
4544
import java.util.logging.Level;
4645
import java.util.logging.Logger;
4746
import java.util.regex.Matcher;
@@ -677,28 +676,11 @@ String determineCurrentVersion() throws IOException {
677676
cmd.add("--pretty=%cd: %h %an %s");
678677
cmd.add("--date=format:%Y-%m-%d %H:%M");
679678

680-
ProcessBuilder pb = new ProcessBuilder(cmd);
681-
pb.directory(directory);
682-
Process process = pb.start();
683-
684-
try {
685-
process.waitFor(15, TimeUnit.SECONDS);
686-
687-
if (process.exitValue() != 0) {
688-
throw new IOException("Process exited with non zero exit code");
689-
}
690-
691-
try (BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
692-
if ((line = in.readLine()) != null) {
693-
line = line.trim();
694-
}
695-
}
696-
} catch (InterruptedException ex) {
697-
LOGGER.log(Level.FINE, "Unable to determine current version for {} - process timeouted", getDirectoryName());
698-
} catch (IOException ex) {
699-
LOGGER.log(Level.FINE, "Unable to determine current version for {} - bad exit code", getDirectoryName());
679+
Executor executor = new Executor(cmd, directory);
680+
if (executor.exec(false) != 0) {
681+
throw new IOException(executor.getErrorString());
700682
}
701683

702-
return line;
684+
return executor.getOutputString().trim();
703685
}
704686
}

src/org/opensolaris/opengrok/history/MercurialRepository.java

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.util.HashMap;
3434
import java.util.List;
3535
import java.util.TreeSet;
36-
import java.util.concurrent.TimeUnit;
3736
import java.util.logging.Level;
3837
import java.util.logging.Logger;
3938
import java.util.regex.Matcher;
@@ -696,28 +695,11 @@ String determineCurrentVersion() throws IOException {
696695
cmd.add("--template");
697696
cmd.add("{date|isodate}: {node|short} {author} {desc|strip}");
698697

699-
ProcessBuilder pb = new ProcessBuilder(cmd);
700-
pb.directory(directory);
701-
Process process = pb.start();
702-
703-
try {
704-
process.waitFor(15, TimeUnit.SECONDS);
705-
706-
if (process.exitValue() != 0) {
707-
throw new IOException("Process exited with non zero exit code");
708-
}
709-
710-
try (BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
711-
if ((line = in.readLine()) != null) {
712-
line = line.trim();
713-
}
714-
}
715-
} catch (InterruptedException ex) {
716-
LOGGER.log(Level.FINE, "Unable to determine current version for {} - process timeouted", getDirectoryName());
717-
} catch (IOException ex) {
718-
LOGGER.log(Level.FINE, "Unable to determine current version for {} - bad exit code", getDirectoryName());
698+
Executor executor = new Executor(cmd, directory);
699+
if (executor.exec(false) != 0) {
700+
throw new IOException(executor.getErrorString());
719701
}
720702

721-
return line;
703+
return executor.getOutputString().trim();
722704
}
723705
}

0 commit comments

Comments
 (0)