Search in sources :

Example 21 with ChangeSet

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

the class JazzChangeLogCommand method executeChangeLogCommand.

/**
 * {@inheritDoc}
 */
protected ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern) throws ScmException {
    if (branch != null && StringUtils.isNotEmpty(branch.getName())) {
        throw new ScmException("This SCM provider doesn't support branches.");
    }
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Executing changelog command...");
    }
    // This acts as a two phase operation.
    // The first pass is to call the "scm history" command to get a list
    // of the changeSets from Jazz SCM. It is stored in the revision of the
    // changeSets array.
    List<ChangeSet> changeSets = new ArrayList<ChangeSet>();
    JazzScmCommand historyCommand = createHistoryCommand(repo, fileSet);
    JazzHistoryConsumer changeLogConsumer = new JazzHistoryConsumer(repo, getLogger(), changeSets);
    ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
    int status = historyCommand.execute(changeLogConsumer, errConsumer);
    if (status != 0) {
        return new ChangeLogScmResult(historyCommand.getCommandString(), "Error code for Jazz SCM history command - " + status, errConsumer.getOutput(), false);
    }
    // Now, call the "scm list changesets" command, passing in the list of changesets from the first pass.
    JazzScmCommand listChangesetsCommand = createListChangesetCommand(repo, fileSet, changeSets);
    JazzListChangesetConsumer listChangesetConsumer = new JazzListChangesetConsumer(repo, getLogger(), changeSets, datePattern);
    errConsumer = new ErrorConsumer(getLogger());
    status = listChangesetsCommand.execute(listChangesetConsumer, errConsumer);
    if (status != 0) {
        return new ChangeLogScmResult(listChangesetsCommand.getCommandString(), "Error code for Jazz SCM list changesets command - " + status, errConsumer.getOutput(), false);
    }
    // Build the result and return it.
    ChangeLogSet changeLogSet = new ChangeLogSet(changeSets, startDate, endDate);
    // Return the "main" command used, namely "scm history"
    return new ChangeLogScmResult(historyCommand.getCommandString(), changeLogSet);
}
Also used : ScmException(org.apache.maven.scm.ScmException) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) ErrorConsumer(org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer) ArrayList(java.util.ArrayList) JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 22 with ChangeSet

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

the class JazzHistoryConsumer method consumeLine.

/**
 * Process one line of output from the execution of the "scm xxxx" command.
 *
 * @param line The line of output from the external command that has been pumped to us.
 * @see org.codehaus.plexus.util.cli.StreamConsumer#consumeLine(java.lang.String)
 */
public void consumeLine(String line) {
    super.consumeLine(line);
    Matcher matcher = CHANGESET_PATTERN.matcher(line);
    if (matcher.find()) {
        String changesetAlias = matcher.group(1);
        ChangeSet changeSet = new ChangeSet();
        changeSet.setRevision(changesetAlias);
        entries.add(changeSet);
    }
}
Also used : Matcher(java.util.regex.Matcher) ChangeSet(org.apache.maven.scm.ChangeSet)

Example 23 with ChangeSet

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

the class JazzListChangesetConsumer method processModifiedLine.

private void processModifiedLine(String line) {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("  Parsing Modified Line : " + line);
    }
    int colonPos = line.indexOf(":");
    int parenPos = line.indexOf("(");
    String date = null;
    if (colonPos != -1 && parenPos != -1) {
        date = line.substring(colonPos + 2, parenPos - 1);
    } else {
        if (colonPos != -1 && parenPos == -1) {
            // No trailing bracket
            date = line.substring(colonPos + 2);
        }
    }
    if (date != null) {
        Date changesetDate = parseDate(date.toString(), userDateFormat, JAZZ_TIMESTAMP_PATTERN);
        // try again forcing en locale
        if (changesetDate == null) {
            changesetDate = parseDate(date.toString(), userDateFormat, JAZZ_TIMESTAMP_PATTERN, Locale.ENGLISH);
        }
        // changesetDate will be null when the date is not given, it only has just the time. The date is today.
        if (changesetDate == null) {
            changesetDate = parseDate(date.toString(), userDateFormat, JAZZ_TIMESTAMP_PATTERN_TIME);
            // try again forcing en locale
            if (changesetDate == null) {
                changesetDate = parseDate(date.toString(), userDateFormat, JAZZ_TIMESTAMP_PATTERN_TIME, Locale.ENGLISH);
            }
            // Get today's time/date. Used to get the date.
            Calendar today = Calendar.getInstance();
            // Get a working one.
            Calendar changesetCal = Calendar.getInstance();
            // Set the date/time. Used to set the time.
            changesetCal.setTimeInMillis(changesetDate.getTime());
            // Now set the date (today).
            changesetCal.set(today.get(Calendar.YEAR), today.get(Calendar.MONTH), today.get(Calendar.DAY_OF_MONTH));
            // Now get the date of the combined results.
            changesetDate = changesetCal.getTime();
        }
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("    date           : " + date);
            getLogger().debug("    changesetDate  : " + changesetDate);
        }
        ChangeSet currentChangeSet = entries.get(currentChangeSetIndex);
        currentChangeSet.setDate(changesetDate);
    }
}
Also used : Calendar(java.util.Calendar) ChangeSet(org.apache.maven.scm.ChangeSet) Date(java.util.Date)

Example 24 with ChangeSet

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

the class UpdateCommandTckTest method testUpdateCommand.

public void testUpdateCommand() throws Exception {
    deleteDirectory(getUpdatingCopy());
    assertFalse(getUpdatingCopy().exists());
    // deleteDirectory( getWorkingCopy() );
    // assertFalse( getUpdatingCopy().exists() );
    ScmRepository repository = makeScmRepository(getScmUrl());
    checkOut(getUpdatingCopy(), repository);
    // ----------------------------------------------------------------------
    // Change the files
    // ----------------------------------------------------------------------
    /*
         * readme.txt is changed (changed file in the root directory)
         * project.xml is added (added file in the root directory)
         * src/test/resources is untouched (a empty directory is left untouched)
         * src/test/java is untouched (a non empty directory is left untouched)
         * src/test/java/org (a empty directory is added)
         * src/main/java/org/Foo.java (a non empty directory is added)
         */
    // /readme.txt
    this.edit(getWorkingCopy(), "readme.txt", null, getScmRepository());
    ScmTestCase.makeFile(getWorkingCopy(), "/readme.txt", "changed readme.txt");
    // /project.xml
    ScmTestCase.makeFile(getWorkingCopy(), "/project.xml", "changed project.xml");
    addToWorkingTree(getWorkingCopy(), new File("project.xml"), getScmRepository());
    // /src/test/java/org
    ScmTestCase.makeDirectory(getWorkingCopy(), "/src/test/java/org");
    addToWorkingTree(getWorkingCopy(), new File("src/test/java/org"), getScmRepository());
    // /src/main/java/org/Foo.java
    ScmTestCase.makeFile(getWorkingCopy(), "/src/main/java/org/Foo.java");
    addToWorkingTree(getWorkingCopy(), new File("src/main/java/org"), getScmRepository());
    // src/main/java/org/Foo.java
    addToWorkingTree(getWorkingCopy(), new File("src/main/java/org/Foo.java"), getScmRepository());
    ScmManager scmManager = getScmManager();
    Date lastUpdate = new Date(System.currentTimeMillis() - 1000000);
    commit(getWorkingCopy(), getScmRepository());
    Thread.sleep(5000);
    // ----------------------------------------------------------------------
    // Update the project
    // ----------------------------------------------------------------------
    UpdateScmResult result = scmManager.update(repository, new ScmFileSet(getUpdatingCopy()), lastUpdate);
    assertNotNull("The command returned a null result.", result);
    assertResultIsSuccess(result);
    List<ScmFile> updatedFiles = result.getUpdatedFiles();
    List<ChangeSet> changedSets = result.getChanges();
    assertEquals("Expected 3 files in the updated files list " + updatedFiles, 3, updatedFiles.size());
    assertNotNull("The changed files list is null", changedSets);
    assertFalse("The changed files list is empty ", changedSets.isEmpty());
    for (ChangeSet changeSet : changedSets) {
        System.out.println(changeSet.toXML());
    }
    // ----------------------------------------------------------------------
    // Assert the files in the updated files list
    // ----------------------------------------------------------------------
    Iterator<ScmFile> files = new TreeSet<ScmFile>(updatedFiles).iterator();
    // Foo.java
    ScmFile file = files.next();
    assertPath("/src/main/java/org/Foo.java", file.getPath());
    // TODO : Consolidate file status so that we can remove "|| ADDED" term
    assertTrue(file.getStatus().isUpdate() || file.getStatus() == ScmFileStatus.ADDED);
    // readme.txt
    file = files.next();
    assertPath("/readme.txt", file.getPath());
    assertTrue(file.getStatus().isUpdate());
    // project.xml
    file = files.next();
    assertPath("/project.xml", file.getPath());
    // TODO : Consolidate file status so that we can remove "|| ADDED" term
    assertTrue(file.getStatus().isUpdate() || file.getStatus() == ScmFileStatus.ADDED);
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmManager(org.apache.maven.scm.manager.ScmManager) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ChangeSet(org.apache.maven.scm.ChangeSet) Date(java.util.Date) ScmFile(org.apache.maven.scm.ScmFile)

Example 25 with ChangeSet

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

the class JGitChangeLogCommand method executeChangeLogCommand.

protected ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern, ScmVersion startVersion, ScmVersion endVersion) throws ScmException {
    Git git = null;
    try {
        git = JGitUtils.openRepo(fileSet.getBasedir());
        String startRev = startVersion != null ? startVersion.getName() : null;
        String endRev = endVersion != null ? endVersion.getName() : null;
        List<ChangeEntry> gitChanges = this.whatchanged(git.getRepository(), null, startRev, endRev, startDate, endDate, -1);
        List<ChangeSet> modifications = new ArrayList<ChangeSet>(gitChanges.size());
        for (ChangeEntry change : gitChanges) {
            ChangeSet scmChange = new ChangeSet();
            scmChange.setAuthor(change.getAuthorName());
            scmChange.setComment(change.getBody());
            scmChange.setDate(change.getAuthorDate());
            scmChange.setRevision(change.getCommitHash());
            // X TODO scmChange.setFiles( change.get )
            modifications.add(scmChange);
        }
        ChangeLogSet changeLogSet = new ChangeLogSet(modifications, startDate, endDate);
        changeLogSet.setStartVersion(startVersion);
        changeLogSet.setEndVersion(endVersion);
        return new ChangeLogScmResult("JGit changelog", changeLogSet);
    } catch (Exception e) {
        throw new ScmException("JGit changelog failure!", e);
    } finally {
        JGitUtils.closeRepo(git);
    }
}
Also used : ScmException(org.apache.maven.scm.ScmException) Git(org.eclipse.jgit.api.Git) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) ArrayList(java.util.ArrayList) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) ChangeSet(org.apache.maven.scm.ChangeSet) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) IOException(java.io.IOException) ScmException(org.apache.maven.scm.ScmException)

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