@Test public void testDetermineCurrentVersion() throws Exception { File root = new File(repository.getSourceRoot(), "git"); GitRepository gitrepo = (GitRepository) RepositoryFactory.getRepository(root); String ver = gitrepo.determineCurrentVersion(); Assert.assertNotNull(ver); }
@Override public String determineCurrentVersion(CommandTimeoutType cmdType) throws IOException { File directory = new File(getDirectoryName()); List<String> cmd = new ArrayList<>(); String delim = "#"; ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK); cmd.add(RepoCommand); cmd.add("log"); cmd.add("-1"); cmd.add("--pretty=%cd" + delim + "%h %an %s"); cmd.add(GIT_DATE_OPT); Executor executor = new Executor(cmd, directory, RuntimeEnvironment.getInstance().getInteractiveCommandTimeout()); if (executor.exec(false) != 0) { throw new IOException(executor.getErrorString()); } String output = executor.getOutputString().trim(); int indexOf = StringUtils.nthIndexOf(output, delim, 1); if (indexOf < 0) { throw new IOException( String.format("Couldn't extract date from \"%s\".", output)); } try { Date date = parse(output.substring(0, indexOf)); return String.format("%s %s", format(date), output.substring(indexOf + 1)); } catch (ParseException ex) { throw new IOException(ex); } }
GitRepository extends Repository { @Override public String determineCurrentVersion(CommandTimeoutType cmdType) throws IOException { File directory = new File(getDirectoryName()); List<String> cmd = new ArrayList<>(); String delim = "#"; ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK); cmd.add(RepoCommand); cmd.add("log"); cmd.add("-1"); cmd.add("--pretty=%cd" + delim + "%h %an %s"); cmd.add(GIT_DATE_OPT); Executor executor = new Executor(cmd, directory, RuntimeEnvironment.getInstance().getInteractiveCommandTimeout()); if (executor.exec(false) != 0) { throw new IOException(executor.getErrorString()); } String output = executor.getOutputString().trim(); int indexOf = StringUtils.nthIndexOf(output, delim, 1); if (indexOf < 0) { throw new IOException( String.format("Couldn't extract date from \"%s\".", output)); } try { Date date = parse(output.substring(0, indexOf)); return String.format("%s %s", format(date), output.substring(indexOf + 1)); } catch (ParseException ex) { throw new IOException(ex); } } }
GitRepository extends Repository { @Override public String determineCurrentVersion(CommandTimeoutType cmdType) throws IOException { File directory = new File(getDirectoryName()); List<String> cmd = new ArrayList<>(); String delim = "#"; ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK); cmd.add(RepoCommand); cmd.add("log"); cmd.add("-1"); cmd.add("--pretty=%cd" + delim + "%h %an %s"); cmd.add(GIT_DATE_OPT); Executor executor = new Executor(cmd, directory, RuntimeEnvironment.getInstance().getInteractiveCommandTimeout()); if (executor.exec(false) != 0) { throw new IOException(executor.getErrorString()); } String output = executor.getOutputString().trim(); int indexOf = StringUtils.nthIndexOf(output, delim, 1); if (indexOf < 0) { throw new IOException( String.format("Couldn't extract date from \"%s\".", output)); } try { Date date = parse(output.substring(0, indexOf)); return String.format("%s %s", format(date), output.substring(indexOf + 1)); } catch (ParseException ex) { throw new IOException(ex); } } GitRepository(); }
GitRepository extends Repository { @Override public String determineCurrentVersion(CommandTimeoutType cmdType) throws IOException { File directory = new File(getDirectoryName()); List<String> cmd = new ArrayList<>(); String delim = "#"; ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK); cmd.add(RepoCommand); cmd.add("log"); cmd.add("-1"); cmd.add("--pretty=%cd" + delim + "%h %an %s"); cmd.add(GIT_DATE_OPT); Executor executor = new Executor(cmd, directory, RuntimeEnvironment.getInstance().getInteractiveCommandTimeout()); if (executor.exec(false) != 0) { throw new IOException(executor.getErrorString()); } String output = executor.getOutputString().trim(); int indexOf = StringUtils.nthIndexOf(output, delim, 1); if (indexOf < 0) { throw new IOException( String.format("Couldn't extract date from \"%s\".", output)); } try { Date date = parse(output.substring(0, indexOf)); return String.format("%s %s", format(date), output.substring(indexOf + 1)); } catch (ParseException ex) { throw new IOException(ex); } } GitRepository(); @Override Annotation annotate(File file, String revision); @Override boolean fileHasAnnotation(File file); @Override boolean fileHasHistory(File file); @Override boolean isWorking(); @Override String determineCurrentVersion(CommandTimeoutType cmdType); }
GitRepository extends Repository { @Override public String determineCurrentVersion(CommandTimeoutType cmdType) throws IOException { File directory = new File(getDirectoryName()); List<String> cmd = new ArrayList<>(); String delim = "#"; ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK); cmd.add(RepoCommand); cmd.add("log"); cmd.add("-1"); cmd.add("--pretty=%cd" + delim + "%h %an %s"); cmd.add(GIT_DATE_OPT); Executor executor = new Executor(cmd, directory, RuntimeEnvironment.getInstance().getInteractiveCommandTimeout()); if (executor.exec(false) != 0) { throw new IOException(executor.getErrorString()); } String output = executor.getOutputString().trim(); int indexOf = StringUtils.nthIndexOf(output, delim, 1); if (indexOf < 0) { throw new IOException( String.format("Couldn't extract date from \"%s\".", output)); } try { Date date = parse(output.substring(0, indexOf)); return String.format("%s %s", format(date), output.substring(indexOf + 1)); } catch (ParseException ex) { throw new IOException(ex); } } GitRepository(); @Override Annotation annotate(File file, String revision); @Override boolean fileHasAnnotation(File file); @Override boolean fileHasHistory(File file); @Override boolean isWorking(); @Override String determineCurrentVersion(CommandTimeoutType cmdType); static final String CMD_PROPERTY_KEY; static final String CMD_FALLBACK; }