Search in sources :

Example 1 with JazzScmCommand

use of org.apache.maven.scm.provider.jazz.command.JazzScmCommand in project maven-scm by apache.

the class JazzAddCommand method executeAddCommand.

public AddScmResult executeAddCommand(ScmProviderRepository repo, ScmFileSet fileSet) throws ScmException {
    // NOTE: THIS IS ALSO CALLED DIRECTLY FROM THE CHECKIN COMMAND.
    // 
    // The "checkin" command does not produce consumable output as to which individual files were checked in. (in
    // 2.0.0.2 at least). Since only "locally modified" changes get checked in, we call a "status" command to
    // generate a list of these files.
    File baseDir = fileSet.getBasedir();
    File parentFolder = (baseDir.getParentFile() != null) ? baseDir.getParentFile() : baseDir;
    List<ScmFile> changedScmFiles = new ArrayList<ScmFile>();
    List<File> changedFiles = new ArrayList<File>();
    List<ScmFile> commitedFiles = new ArrayList<ScmFile>();
    JazzStatusCommand statusCmd = new JazzStatusCommand();
    statusCmd.setLogger(getLogger());
    StatusScmResult statusCmdResult = statusCmd.executeStatusCommand(repo, fileSet);
    List<ScmFile> statusScmFiles = statusCmdResult.getChangedFiles();
    for (ScmFile file : statusScmFiles) {
        getLogger().debug("Iterating over statusScmFiles: " + file);
        if (file.getStatus() == ScmFileStatus.ADDED || file.getStatus() == ScmFileStatus.DELETED || file.getStatus() == ScmFileStatus.MODIFIED) {
            changedScmFiles.add(new ScmFile(file.getPath(), ScmFileStatus.CHECKED_IN));
            changedFiles.add(new File(parentFolder, file.getPath()));
        }
    }
    List<File> files = fileSet.getFileList();
    if (files.size() == 0) {
        // Either commit all local changes
        commitedFiles = changedScmFiles;
    } else {
        // Or commit specific files
        for (File file : files) {
            if (fileExistsInFileList(file, changedFiles)) {
                commitedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.CHECKED_IN));
            }
        }
    }
    // Now that we have a list of files to process, we can "add" (scm checkin) them.
    JazzAddConsumer addConsumer = new JazzAddConsumer(repo, getLogger());
    ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
    JazzScmCommand command = createAddCommand(repo, fileSet);
    int status = command.execute(addConsumer, errConsumer);
    if (status != 0) {
        return new AddScmResult(command.getCommandString(), "Error code for Jazz SCM add (checkin) command - " + status, errConsumer.getOutput(), false);
    }
    return new AddScmResult(command.getCommandString(), addConsumer.getFiles());
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) JazzStatusCommand(org.apache.maven.scm.provider.jazz.command.status.JazzStatusCommand) ErrorConsumer(org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ArrayList(java.util.ArrayList) JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 2 with JazzScmCommand

use of org.apache.maven.scm.provider.jazz.command.JazzScmCommand 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 3 with JazzScmCommand

use of org.apache.maven.scm.provider.jazz.command.JazzScmCommand in project maven-scm by apache.

the class JazzChangeLogCommand method createListChangesetCommand.

protected JazzScmCommand createListChangesetCommand(ScmProviderRepository repo, ScmFileSet fileSet, List<ChangeSet> changeSets) {
    JazzScmProviderRepository jazzRepo = (JazzScmProviderRepository) repo;
    JazzScmCommand command = new JazzScmCommand(JazzConstants.CMD_LIST, JazzConstants.CMD_SUB_CHANGESETS, repo, fileSet, getLogger());
    command.addArgument(JazzConstants.ARG_WORKSPACE);
    command.addArgument(jazzRepo.getWorkspace());
    for (int i = 0; i < changeSets.size(); i++) {
        command.addArgument(changeSets.get(i).getRevision());
    }
    return command;
}
Also used : JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) JazzScmProviderRepository(org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository)

Example 4 with JazzScmCommand

use of org.apache.maven.scm.provider.jazz.command.JazzScmCommand in project maven-scm by apache.

the class JazzChangeLogCommand method createHistoryCommand.

protected JazzScmCommand createHistoryCommand(ScmProviderRepository repo, ScmFileSet fileSet) {
    JazzScmCommand command = new JazzScmCommand(JazzConstants.CMD_HISTORY, repo, fileSet, getLogger());
    command.addArgument(JazzConstants.ARG_MAXIMUM);
    // Beyond me as to why they didn't make 0 = all.
    command.addArgument("10000000");
    return command;
}
Also used : JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand)

Example 5 with JazzScmCommand

use of org.apache.maven.scm.provider.jazz.command.JazzScmCommand in project maven-scm by apache.

the class JazzTagCommand method executeTagCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeTagCommand(ScmProviderRepository repo, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Executing tag command...");
    }
    JazzScmProviderRepository jazzRepo = (JazzScmProviderRepository) repo;
    getLogger().debug("Creating Snapshot...");
    StreamConsumer tagConsumer = // No need for a dedicated consumer for this
    new DebugLoggerConsumer(getLogger());
    ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
    JazzScmCommand tagCreateSnapshotCmd = createTagCreateSnapshotCommand(jazzRepo, fileSet, tag, scmTagParameters);
    int status = tagCreateSnapshotCmd.execute(tagConsumer, errConsumer);
    if (status != 0) {
        return new TagScmResult(tagCreateSnapshotCmd.getCommandString(), "Error code for Jazz SCM tag (SNAPSHOT) command - " + status, errConsumer.getOutput(), false);
    }
    // ------------------------------------------------------------------
    // We create the workspace based on the tag here, as the scm tool
    // can not currently check directly out from a snapshot (only a workspace).
    getLogger().debug("Creating Workspace from Snapshot...");
    JazzScmCommand tagCreateWorkspaceCmd = createTagCreateWorkspaceCommand(jazzRepo, fileSet, tag);
    errConsumer = new ErrorConsumer(getLogger());
    status = tagCreateWorkspaceCmd.execute(tagConsumer, errConsumer);
    if (status != 0) {
        return new TagScmResult(tagCreateWorkspaceCmd.getCommandString(), "Error code for Jazz SCM tag (WORKSPACE) command - " + status, errConsumer.getOutput(), false);
    }
    if (jazzRepo.isPushChangesAndHaveFlowTargets()) {
        // isPushChanges = true, and we have something to deliver and promote to.
        getLogger().debug("Promoting and delivering...");
        // So we deliver the code to the target stream (or workspace)
        getLogger().debug("Delivering...");
        JazzScmCommand tagDeliverCommand = createTagDeliverCommand(jazzRepo, fileSet, tag);
        errConsumer = new ErrorConsumer(getLogger());
        status = tagDeliverCommand.execute(tagConsumer, errConsumer);
        if (status != 0) {
            return new TagScmResult(tagDeliverCommand.getCommandString(), "Error code for Jazz SCM deliver command - " + status, errConsumer.getOutput(), false);
        }
        // And now we promote the snapshot to the target stream (or workspace)
        getLogger().debug("Promoting snapshot...");
        JazzScmCommand tagSnapshotPromoteCommand = createTagSnapshotPromoteCommand(jazzRepo, fileSet, tag);
        errConsumer = new ErrorConsumer(getLogger());
        status = tagSnapshotPromoteCommand.execute(tagConsumer, errConsumer);
        if (status != 0) {
            return new TagScmResult(tagSnapshotPromoteCommand.getCommandString(), "Error code for Jazz SCM snapshot promote command - " + status, errConsumer.getOutput(), false);
        }
    }
    // We don't have a JazzTagConsumer so just build up all the files...
    List<ScmFile> taggedFiles = new ArrayList<ScmFile>(fileSet.getFileList().size());
    for (File f : fileSet.getFileList()) {
        taggedFiles.add(new ScmFile(f.getPath(), ScmFileStatus.TAGGED));
    }
    // So we return tagSnapshotCmd and not tagWorkspaceCmd.
    return new TagScmResult(tagCreateSnapshotCmd.getCommandString(), taggedFiles);
}
Also used : StreamConsumer(org.codehaus.plexus.util.cli.StreamConsumer) ErrorConsumer(org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer) ArrayList(java.util.ArrayList) JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) DebugLoggerConsumer(org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) JazzScmProviderRepository(org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository) ScmFile(org.apache.maven.scm.ScmFile)

Aggregations

JazzScmCommand (org.apache.maven.scm.provider.jazz.command.JazzScmCommand)31 ErrorConsumer (org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer)13 File (java.io.File)7 JazzScmProviderRepository (org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository)7 ScmFile (org.apache.maven.scm.ScmFile)6 DebugLoggerConsumer (org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer)6 ArrayList (java.util.ArrayList)3 StatusScmResult (org.apache.maven.scm.command.status.StatusScmResult)3 JazzStatusCommand (org.apache.maven.scm.provider.jazz.command.status.JazzStatusCommand)3 ScmException (org.apache.maven.scm.ScmException)2 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)2 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)2 StreamConsumer (org.codehaus.plexus.util.cli.StreamConsumer)2 HashMap (java.util.HashMap)1 ChangeSet (org.apache.maven.scm.ChangeSet)1 ScmBranch (org.apache.maven.scm.ScmBranch)1 ScmTag (org.apache.maven.scm.ScmTag)1 BlameScmResult (org.apache.maven.scm.command.blame.BlameScmResult)1 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)1 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)1