/** * Process the current input line in the GET_FILE state. This state adds each file entry line to * the current change log entry. Note, the revision number for the entire entry is used for the * revision number of each file. * * @param line A line of text from the svn log output */ private void processGetFile(String line) { if (FILE_PATTERN.match(line)) { final String fileinfo = FILE_PATTERN.getParen(2); String name = fileinfo; String originalName = null; String originalRev = null; final int n = fileinfo.indexOf(" ("); if (n > 1 && fileinfo.endsWith(")")) { final String origFileInfo = fileinfo.substring(n); if (ORIG_FILE_PATTERN.match(origFileInfo)) { // if original file is present, we must extract the affected one from the beginning name = fileinfo.substring(0, n); originalName = ORIG_FILE_PATTERN.getParen(1); originalRev = ORIG_FILE_PATTERN.getParen(2); } } final String actionStr = FILE_PATTERN.getParen(1); final ScmFileStatus action; if ("A".equals(actionStr)) { // TODO: this may even change to MOVED if we later explore whole changeset and find matching // DELETED action = originalRev == null ? ScmFileStatus.ADDED : ScmFileStatus.COPIED; } else if ("D".equals(actionStr)) { action = ScmFileStatus.DELETED; } else if ("M".equals(actionStr)) { action = ScmFileStatus.MODIFIED; } else if ("R".equals(actionStr)) { action = ScmFileStatus.UPDATED; // == REPLACED in svn terms } else { action = ScmFileStatus.UNKNOWN; } System.out.println(actionStr + " : " + name); final ChangeFile changeFile = new ChangeFile(name, currentRevision); changeFile.setAction(action); changeFile.setOriginalName(originalName); changeFile.setOriginalRevision(originalRev); currentChange.addFile(changeFile); status = GET_FILE; } else if (line.equals(FILE_END_TOKEN)) { // Create a buffer for the collection of the comment now // that we are leaving the GET_FILE state. currentComment = new StringBuilder(); status = GET_COMMENT; } }
/** * Finds the largest revision number. * * @impl Currently we assume the the largest revision is provided by the last entry of the set. * @param changeLogSet the set of change log entries to compare the revision numbers to find the * largest. * @return the largest revision number from the set or <code>null</code> if no end version can be * found. */ private Revision findEndVersion(final ChangeLogSet changeLogSet) { if (changeLogSet != null) { final ScmVersion endVersion = changeLogSet.getEndVersion(); if (endVersion != null) { if (LOG.isDebugEnabled()) { LOG.debug("End version found."); } return new MavenRevision(endVersion, changeLogSet.getEndDate()); } final List<ChangeSet> changeSets = changeLogSet.getChangeSets(); if (!changeSets.isEmpty()) { final int lastIndex = changeSets.size() - 1; for (int index = lastIndex; index >= 0; index--) { final ChangeSet set = changeSets.get(lastIndex); final List<ChangeFile> changeFiles = set.getFiles(); if (!changeFiles.isEmpty()) { final ChangeFile file = changeFiles.get(0); final String revision = file.getRevision(); if (revision != null) { return new StringRevision(revision, set.getDate()); } } else { if (LOG.isDebugEnabled()) { LOG.debug("No change files found."); } } } } else { if (LOG.isDebugEnabled()) { LOG.debug("No change set found."); } } } else { if (LOG.isDebugEnabled()) { LOG.debug("No change log set found."); } } return null; }
private List<ChangeFile> createChangeFilesList() { List<ChangeFile> files = new ArrayList<ChangeFile>(); ChangeFile changeFile1 = new ChangeFile("ChangeFile1"); changeFile1.setAction(ScmFileStatus.ADDED); ChangeFile changeFile2 = new ChangeFile("ChangeFile2"); changeFile2.setAction(ScmFileStatus.MODIFIED); ChangeFile changeFile3 = new ChangeFile("ChangeFile3"); changeFile3.setAction(ScmFileStatus.DELETED); ChangeFile changeFile4 = new ChangeFile("ChangeFile4"); changeFile4.setAction(ScmFileStatus.DELETED); files.add(changeFile4); files.add(changeFile3); files.add(changeFile2); files.add(changeFile1); return files; }