Search in sources :

Example 11 with JazzScmCommand

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

the class JazzCheckInCommand method createDeliverCommand.

// Create the JazzScmCommand to execute the "scm deliver ..." command
// This will deliver the changes to the flow target (stream or other workspace).
public JazzScmCommand createDeliverCommand(JazzScmProviderRepository repo, ScmFileSet fileSet) {
    JazzScmCommand command = new JazzScmCommand(JazzConstants.CMD_DELIVER, repo, fileSet, getLogger());
    if (repo.getWorkspace() != null && !repo.getWorkspace().equals("")) {
        command.addArgument(JazzConstants.ARG_DELIVER_SOURCE);
        command.addArgument(repo.getWorkspace());
    }
    if (repo.getFlowTarget() != null && !repo.getFlowTarget().equals("")) {
        command.addArgument(JazzConstants.ARG_DELIVER_TARGET);
        command.addArgument(repo.getFlowTarget());
    }
    // This command is needed so that the deliver operation will work.
    // Files that are not under source control (a--) [temp files etc]
    // will cause the deliver operation to fail with the error:
    // "Cannot deliver because there are one or more items that are not checked in.
    // Check in the changes or rerun with --overwrite-uncommitted."
    // However, from the maven perspective, we only need files that are
    // under source control to be delivered. Maven has already checked
    // for this (via the status command).
    // 
    // So we add this argument to allow the deliver to work.
    command.addArgument(JazzConstants.ARG_OVERWRITE_UNCOMMITTED);
    return command;
}
Also used : JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand)

Example 12 with JazzScmCommand

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

the class JazzCheckInCommand method createCheckInCommand.

public JazzScmCommand createCheckInCommand(ScmProviderRepository repo, ScmFileSet fileSet) {
    JazzScmCommand command = new JazzScmCommand(JazzConstants.CMD_CHECKIN, null, repo, false, fileSet, getLogger());
    // TODO, this was taken out to quickly test how the release plugin works.
    // The release plugin has the fileSet.getbaseDir() as the project it is checking in
    // This happens to be a folder under the sandbox root, and so the checkin would fail because it needs
    // to check in at the sandbox root level (not sub folders)
    // The SCM Plugin has a basedir parameter that you can pass it, so everythig works ok from the scm-plugin alone
    // but the release-plugin doesn't look like it lets you do that. (or I didn't have enough time
    // to figure out how to do it properly).
    // if (fileSet != null) {
    // command.addArgument(JazzConstants.LOAD_ROOT_DIRECTORY_ARG);
    // command.addArgument(fileSet.getBasedir().getAbsolutePath());
    // }
    List<File> files = fileSet.getFileList();
    if (files != null && !files.isEmpty()) {
        for (File file : files) {
            // Check in only the files specified
            command.addArgument(file.getPath());
        }
    } else {
        // This will check in all local changes
        command.addArgument(".");
    }
    return command;
}
Also used : JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) File(java.io.File)

Example 13 with JazzScmCommand

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

the class JazzCheckInCommand method executeCheckInCommand.

protected CheckInScmResult executeCheckInCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion scmVersion) throws ScmException {
    // Call the Add command to perform the checkin into the repository workspace.
    JazzAddCommand addCommand = new JazzAddCommand();
    addCommand.setLogger(getLogger());
    AddScmResult addResult = addCommand.executeAddCommand(repo, fileSet);
    // Now, if it has a flow target, deliver it.
    JazzScmProviderRepository jazzRepo = (JazzScmProviderRepository) repo;
    if (jazzRepo.isPushChangesAndHaveFlowTargets()) {
        // Push if we need too
        JazzScmCommand deliverCmd = createDeliverCommand((JazzScmProviderRepository) repo, fileSet);
        StreamConsumer deliverConsumer = // No need for a dedicated consumer for this
        new DebugLoggerConsumer(getLogger());
        ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
        int status = deliverCmd.execute(deliverConsumer, errConsumer);
        if (status != 0) {
            return new CheckInScmResult(deliverCmd.getCommandString(), "Error code for Jazz SCM deliver command - " + status, errConsumer.getOutput(), false);
        }
    }
    // Return what was added.
    return new CheckInScmResult(addResult.getCommandLine(), addResult.getAddedFiles());
}
Also used : StreamConsumer(org.codehaus.plexus.util.cli.StreamConsumer) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ErrorConsumer(org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer) JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) JazzAddCommand(org.apache.maven.scm.provider.jazz.command.add.JazzAddCommand) DebugLoggerConsumer(org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) JazzScmProviderRepository(org.apache.maven.scm.provider.jazz.repository.JazzScmProviderRepository)

Example 14 with JazzScmCommand

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

the class JazzDiffCommand method executeDiffCommand.

/**
 * {@inheritDoc}
 */
protected DiffScmResult executeDiffCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion startRevision, ScmVersion endRevision) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Executing diff command...");
    }
    File baseDir = fileSet.getBasedir();
    File parentFolder = (baseDir.getParentFile() != null) ? baseDir.getParentFile() : baseDir;
    // First execute the status command to get the list of changed files.
    JazzStatusCommand statusCmd = new JazzStatusCommand();
    statusCmd.setLogger(getLogger());
    StatusScmResult statusCmdResult = statusCmd.executeStatusCommand(repo, fileSet);
    List<ScmFile> statusScmFiles = statusCmdResult.getChangedFiles();
    // In this case, we also use it across multiple calls to "scm diff" so that we
    // sum all output into on.
    JazzScmCommand diffCmd = null;
    StringBuilder patch = new StringBuilder();
    Map<String, CharSequence> differences = new HashMap<String, CharSequence>();
    // Now lets iterate through them
    for (ScmFile file : statusScmFiles) {
        if (file.getStatus() == ScmFileStatus.MODIFIED) {
            // The "scm status" command returns files relative to the sandbox root.
            // Whereas the "scm diff" command needs them relative to the working directory.
            File fullPath = new File(parentFolder, file.getPath());
            String relativePath = fullPath.toString().substring(baseDir.toString().length());
            getLogger().debug("Full Path     : '" + fullPath + "'");
            getLogger().debug("Relative Path : '" + relativePath + "'");
            // Now call "scm diff on it"
            // In this case, we use the DebugLoggerConsumer's ability to store captured output
            DebugLoggerConsumer diffConsumer = new DebugLoggerConsumer(getLogger());
            ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
            diffCmd = createDiffCommand(repo, fileSet, relativePath);
            int status = diffCmd.execute(diffConsumer, errConsumer);
            if (status != 0) {
                // Return a false result (not the usual SCMResult)
                return new DiffScmResult(diffCmd.toString(), "The scm diff command failed.", errConsumer.getOutput(), false);
            }
            // Append to patch (all combined)
            patch.append(diffConsumer.getOutput());
            // Set the differences map <File, <CharSequence>
            differences.put(relativePath, diffConsumer.getOutput());
        }
    }
    return new DiffScmResult(diffCmd.toString(), statusCmdResult.getChangedFiles(), differences, patch.toString());
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) HashMap(java.util.HashMap) ErrorConsumer(org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer) JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) ScmFile(org.apache.maven.scm.ScmFile) JazzStatusCommand(org.apache.maven.scm.provider.jazz.command.status.JazzStatusCommand) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) DebugLoggerConsumer(org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult)

Example 15 with JazzScmCommand

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

the class JazzDiffCommand method createDiffCommand.

public JazzScmCommand createDiffCommand(ScmProviderRepository repo, ScmFileSet fileSet, String relativePath) {
    JazzScmCommand command = new JazzScmCommand(JazzConstants.CMD_DIFF, repo, fileSet, getLogger());
    command.addArgument(JazzConstants.ARG_FILE);
    command.addArgument(relativePath);
    return command;
}
Also used : JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand)

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