Search in sources :

Example 26 with ChangeSet

use of org.apache.maven.scm.ChangeSet in project maven-plugins by apache.

the class ChangeLogReport method filter.

private void filter(List<ChangeSet> sets, List<Pattern> includes, List<Pattern> excludes) {
    Iterator<ChangeSet> it = sets.iterator();
    while (it.hasNext()) {
        ChangeSet changeSet = it.next();
        List<ChangeFile> files = changeSet.getFiles();
        Iterator<ChangeFile> iterator = files.iterator();
        while (iterator.hasNext()) {
            ChangeFile changeFile = iterator.next();
            String name = changeFile.getName();
            if (!isIncluded(includes, name) || isExcluded(excludes, name)) {
                iterator.remove();
            }
        }
        if (files.isEmpty()) {
            it.remove();
        }
    }
}
Also used : ChangeFile(org.apache.maven.scm.ChangeFile) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 27 with ChangeSet

use of org.apache.maven.scm.ChangeSet in project maven-plugins by apache.

the class ChangeLogHandler method startElement.

/**
 * {@inheritDoc}
 */
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    bufData = "";
    if ("file".equals(qName)) {
        bufFile = new ChangeFile("");
    } else if ("changelog-entry".equals(qName)) {
        bufEntry = new ChangeSet();
    } else if ("date".equals(qName)) {
        currentPattern = attributes.getValue("pattern");
        if (currentPattern == null) {
            currentPattern = "yyyy-MM-dd";
        }
    } else if ("time".equals(qName)) {
        currentPattern = attributes.getValue("pattern");
        if (currentPattern == null) {
            currentPattern = "HH:mm:ss";
        }
    } else if ("changeset".equals(qName)) {
        bufEntries = new LinkedList<ChangeSet>();
        currentPattern = attributes.getValue("datePattern");
        if (currentPattern == null) {
            currentPattern = "yyyy-MM-dd";
        }
        SimpleDateFormat formatter = new SimpleDateFormat(currentPattern);
        String start = attributes.getValue("start");
        String end = attributes.getValue("end");
        Date startDate = null;
        Date endDate = null;
        if (start != null) {
            try {
                startDate = formatter.parse(start);
            } catch (ParseException e) {
                throw new SAXException("Can't parse start date '" + start + "'.", e);
            }
        }
        if (end != null) {
            try {
                endDate = formatter.parse(end);
            } catch (ParseException e) {
                throw new SAXException("Can't parse end date '" + end + "'.", e);
            }
        }
        bufSet = new ChangeLogSet(bufEntries, startDate, endDate);
        String startVersion = attributes.getValue("startVersion");
        if (startVersion != null) {
            bufSet.setStartVersion(new ScmTag(startVersion));
        }
        String endVersion = attributes.getValue("endVersion");
        if (endVersion != null) {
            bufSet.setEndVersion(new ScmTag(endVersion));
        }
    }
}
Also used : ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) ChangeFile(org.apache.maven.scm.ChangeFile) ScmTag(org.apache.maven.scm.ScmTag) ParseException(java.text.ParseException) ChangeSet(org.apache.maven.scm.ChangeSet) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) SAXException(org.xml.sax.SAXException)

Example 28 with ChangeSet

use of org.apache.maven.scm.ChangeSet in project maven-plugins by apache.

the class DeveloperActivityReport method countDevFiles.

/**
 * counts the number of files changed by each developer
 *
 * @param entries the change log entries used to search and count file changes
 */
private void countDevFiles(Collection<ChangeSet> entries) {
    for (ChangeSet entry : entries) {
        String developer = entry.getAuthor();
        Map<String, ChangeFile> filesMap = files.get(developer);
        if (filesMap == null) {
            filesMap = new HashMap<String, ChangeFile>();
            files.put(developer, filesMap);
        }
        for (ChangeFile file : entry.getFiles()) {
            filesMap.put(file.getName(), file);
        }
    }
}
Also used : ChangeFile(org.apache.maven.scm.ChangeFile) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 29 with ChangeSet

use of org.apache.maven.scm.ChangeSet in project maven-scm by apache.

the class AbstractUpdateCommand method executeCommand.

/**
 * {@inheritDoc}
 */
public ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    ScmVersion scmVersion = parameters.getScmVersion(CommandParameter.SCM_VERSION, null);
    boolean runChangelog = Boolean.valueOf(parameters.getString(CommandParameter.RUN_CHANGELOG_WITH_UPDATE, "true")).booleanValue();
    UpdateScmResult updateScmResult = executeUpdateCommand(repository, fileSet, scmVersion);
    List<ScmFile> filesList = updateScmResult.getUpdatedFiles();
    if (!runChangelog) {
        return updateScmResult;
    }
    ChangeLogCommand changeLogCmd = getChangeLogCommand();
    if (filesList != null && filesList.size() > 0 && changeLogCmd != null) {
        ChangeLogScmResult changeLogScmResult = (ChangeLogScmResult) changeLogCmd.executeCommand(repository, fileSet, parameters);
        List<ChangeSet> changes = new ArrayList<ChangeSet>();
        ChangeLogSet changeLogSet = changeLogScmResult.getChangeLog();
        if (changeLogSet != null) {
            Date startDate = null;
            try {
                startDate = parameters.getDate(CommandParameter.START_DATE);
            } catch (ScmException e) {
            // Do nothing, startDate isn't define.
            }
            for (ChangeSet change : changeLogSet.getChangeSets()) {
                if (startDate != null && change.getDate() != null) {
                    if (startDate.after(change.getDate())) {
                        continue;
                    }
                }
                for (ScmFile currentFile : filesList) {
                    if (change.containsFilename(currentFile.getPath())) {
                        changes.add(change);
                        break;
                    }
                }
            }
        }
        updateScmResult.setChanges(changes);
    }
    return updateScmResult;
}
Also used : ScmException(org.apache.maven.scm.ScmException) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) ArrayList(java.util.ArrayList) Date(java.util.Date) ScmVersion(org.apache.maven.scm.ScmVersion) ScmFile(org.apache.maven.scm.ScmFile) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) ChangeLogCommand(org.apache.maven.scm.command.changelog.ChangeLogCommand) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 30 with ChangeSet

use of org.apache.maven.scm.ChangeSet in project maven-scm by apache.

the class AccuRevChangeLogCommandTest method testWorkspaceChangelog.

@Test
public void testWorkspaceChangelog() throws Exception {
    final ScmFileSet testFileSet = new ScmFileSet(new File(basedir, "project/dir"));
    final Date keepWhen = getDate(2009, 0, 2, 9, 0, 0, null);
    final Date promoteWhen = getDate(2009, 0, 4, 23, 0, 0, null);
    final Date fromDate = getDate(2009, 0, 1, 0, 0, 0, null);
    final Date toDate = getDate(2009, 0, 5, 1, 0, 0, null);
    // start tran (35)
    List<Transaction> startTransaction = Collections.singletonList(new Transaction(35L, fromDate, "sometran", "anyone"));
    when(accurev.history("workspace5", "35", null, 1, true, true)).thenReturn(startTransaction);
    // end tran (42)
    List<Transaction> endTransaction = Collections.singletonList(new Transaction(42L, toDate, "sometran", "anyone"));
    when(accurev.history("workspace5", "42", null, 1, true, true)).thenReturn(endTransaction);
    // Stream hierarchy
    // S2 < S4, S2 < WS3, S4 < WS5, S4 << WS7
    // 
    // Changelog(WS5,35,42) involves
    // -- diff(S4,35,42)
    // -- hist(WS5,36-42)
    // -- hist(S4,36-42)
    // 
    // Promote S4 to S2 - not in diffS4, not in histS4, not in hist WS5 -
    // not in changeset
    // Promote WS3 to S2 - in diffS4, not hist histS4, not in hist WS5 - in
    // "upstream changes"
    // Promote WS5 to S4 - in diffS4, in histS4, not in hist WS5 - not in
    // changeset (real version from WS5)
    // Promote WS7 to S4 - in diffS4, in histS4, not in hist WS5 - in
    // changeset as a promote transaction
    // Keep WS5 - not in diffS4, not in histS4, in histWS5 - in changeset as
    // a keep transaction
    // This workspace is stream 5, attached to basis mystream 5
    Stream workspaceStream = new Stream("workspace5", 5, "stream4", 4, "myDepot", getDate(2008, 10, 1, 10, 0, 0, null), "workspace");
    when(accurev.showStream("workspace5")).thenReturn(workspaceStream);
    Stream basisStream = new Stream("stream4", 4, "myDepot", 1, "myDepot", getDate(2008, 1, 1), "normal");
    when(accurev.showStream("stream4")).thenReturn(basisStream);
    // now we call diff between the tran ids - 35 to 42
    FileDifference diffWS3toS2 = new FileDifference(32L, "/promoted/WS3toS2", "3/2", "/promoted/WS3toS2", "6/1");
    FileDifference diffWS5toS4 = new FileDifference(54L, "/promoted/WS5toS4", "5/3", "/promoted/WS5toS4", "8/1");
    FileDifference diffWS7toS4 = new FileDifference(74L, "/promoted/WS7toS4", "7/12", "/promoted/WS7toS4", "3/13");
    when(accurev.diff("stream4", "35", "42")).thenReturn(Arrays.asList(diffWS3toS2, diffWS5toS4, diffWS7toS4));
    // and we call hist for tranid + 1 to end trand ii
    Transaction promoteWS5toS4 = new Transaction(37L, promoteWhen, "promote", "aUser");
    promoteWS5toS4.setComment("WS5toS4");
    promoteWS5toS4.addVersion(54L, "/./promoted/WS5toS4", "4/5", "5/3", "3/2");
    Transaction promoteWS7toS4 = new Transaction(38L, promoteWhen, "promote", "aUser");
    promoteWS7toS4.setComment("WS7toS4");
    promoteWS7toS4.addVersion(74L, "/./promoted/WS7toS4", "4/11", "7/12", "3/2");
    when(accurev.history("stream4", "36", "42", 0, false, false)).thenReturn(Arrays.asList(promoteWS5toS4, promoteWS7toS4));
    Transaction keepWS5 = new Transaction(39L, keepWhen, "keep", "anOther");
    keepWS5.addVersion(5L, "/./kept/WS5", "5/7", "5/7", "7/21");
    keepWS5.setComment("keepWS5");
    when(accurev.history("workspace5", "36", "42", 0, false, false)).thenReturn(Collections.singletonList(keepWS5));
    AccuRevChangeLogCommand command = new AccuRevChangeLogCommand(getLogger());
    CommandParameters commandParameters = new CommandParameters();
    commandParameters.setScmVersion(CommandParameter.START_SCM_VERSION, new ScmRevision("workspace5/35"));
    commandParameters.setScmVersion(CommandParameter.END_SCM_VERSION, new ScmRevision("workspace5/42"));
    ChangeLogScmResult result = command.changelog(repo, testFileSet, commandParameters);
    assertThat(result.isSuccess(), is(true));
    ChangeLogSet changelog = result.getChangeLog();
    assertThat(changelog.getStartVersion().getName(), is("workspace5/35"));
    assertThat(changelog.getEndVersion().getName(), is("workspace5/42"));
    List<ChangeSet> changesets = changelog.getChangeSets();
    assertThat(changesets.size(), is(3));
    for (ChangeSet changeSet : changesets) {
        assertThat(changeSet.getComment(), isOneOf("Upstream changes", "WS7toS4", "keepWS5"));
        if ("Upstream changes".equals(changeSet.getComment())) {
            assertThat(changeSet.getFiles().size(), is(1));
            ChangeFile changeFile = (ChangeFile) changeSet.getFiles().get(0);
            assertThat(changeFile, is(changeFile("/promoted/WS3toS2")));
        }
    }
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) ScmRevision(org.apache.maven.scm.ScmRevision) Date(java.util.Date) Transaction(org.apache.maven.scm.provider.accurev.Transaction) ChangeFile(org.apache.maven.scm.ChangeFile) Stream(org.apache.maven.scm.provider.accurev.Stream) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) FileDifference(org.apache.maven.scm.provider.accurev.FileDifference) CommandParameters(org.apache.maven.scm.CommandParameters) ChangeFile(org.apache.maven.scm.ChangeFile) ChangeFileMatcher.changeFile(org.apache.maven.scm.ChangeFileMatcher.changeFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet) Test(org.junit.Test) AbstractAccuRevCommandTest(org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)

Aggregations

ChangeSet (org.apache.maven.scm.ChangeSet)62 ChangeFile (org.apache.maven.scm.ChangeFile)34 ArrayList (java.util.ArrayList)21 Date (java.util.Date)18 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)16 File (java.io.File)15 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)15 Matcher (java.util.regex.Matcher)8 ScmException (org.apache.maven.scm.ScmException)8 BufferedReader (java.io.BufferedReader)7 SimpleDateFormat (java.text.SimpleDateFormat)7 ScmFile (org.apache.maven.scm.ScmFile)6 ScmFileSet (org.apache.maven.scm.ScmFileSet)5 ScmResult (org.apache.maven.scm.ScmResult)5 DefaultLog (org.apache.maven.scm.log.DefaultLog)5 FileReader (java.io.FileReader)4 List (java.util.List)4 ScmFileStatus (org.apache.maven.scm.ScmFileStatus)4 FileInputStream (java.io.FileInputStream)3 InputStreamReader (java.io.InputStreamReader)3