|
18 | 18 | */
|
19 | 19 |
|
20 | 20 | /*
|
21 |
| - * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. |
| 21 | + * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved. |
22 | 22 | */
|
23 | 23 | package org.opensolaris.opengrok.history;
|
24 | 24 |
|
|
33 | 33 | import java.util.HashMap;
|
34 | 34 | import java.util.List;
|
35 | 35 | import java.util.TreeSet;
|
| 36 | +import java.util.concurrent.TimeUnit; |
36 | 37 | import java.util.logging.Level;
|
37 | 38 | import java.util.logging.Logger;
|
38 | 39 | import java.util.regex.Matcher;
|
39 | 40 | import java.util.regex.Pattern;
|
40 |
| - |
41 | 41 | import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
|
42 | 42 | import org.opensolaris.opengrok.logger.LoggerFactory;
|
43 | 43 | import org.opensolaris.opengrok.util.Executor;
|
@@ -681,4 +681,43 @@ String determineParent() throws IOException {
|
681 | 681 |
|
682 | 682 | return executor.getOutputString().trim();
|
683 | 683 | }
|
| 684 | + |
| 685 | + @Override |
| 686 | + String determineCurrentVersion() throws IOException { |
| 687 | + String line = null; |
| 688 | + File directory = new File(directoryName); |
| 689 | + |
| 690 | + List<String> cmd = new ArrayList<>(); |
| 691 | + ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK); |
| 692 | + cmd.add(RepoCommand); |
| 693 | + cmd.add("log"); |
| 694 | + cmd.add("-l"); |
| 695 | + cmd.add("1"); |
| 696 | + cmd.add("--template"); |
| 697 | + cmd.add("{date|isodate}: {node|short} {author} {desc|strip}"); |
| 698 | + |
| 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()); |
| 719 | + } |
| 720 | + |
| 721 | + return line; |
| 722 | + } |
684 | 723 | }
|
0 commit comments