Search in sources :

Example 11 with StatusScmResult

use of org.apache.maven.scm.command.status.StatusScmResult in project maven-scm by apache.

the class AccuRevStatusCommand method executeAccurevCommand.

@Override
protected ScmResult executeAccurevCommand(AccuRevScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException, AccuRevException {
    AccuRev accuRev = repository.getAccuRev();
    File basedir = fileSet.getBasedir();
    List<File> elements = fileSet.getFileList();
    List<File> defunctElements = accuRev.stat(basedir, elements, AccuRevStat.DEFUNCT);
    if (defunctElements == null) {
        return error(accuRev, "Failed retrieving defunct elements");
    }
    List<File> keptElements = accuRev.stat(basedir, elements, AccuRevStat.KEPT);
    // Defunct elements are also listed as kept (AccuRev 4.7.1), exclude those here.
    if (keptElements == null) {
        return error(accuRev, "Failed retrieving kept elements");
    }
    List<File> modOrAddedElements = new ArrayList<File>();
    for (File file : keptElements) {
        if (!defunctElements.contains(file)) {
            modOrAddedElements.add(file);
        }
    }
    List<File> modifiedElements = accuRev.stat(basedir, elements, AccuRevStat.MODIFIED);
    if (modifiedElements == null) {
        return error(accuRev, "Failed retrieving modified elements");
    }
    modOrAddedElements.addAll(modifiedElements);
    CategorisedElements catElems = accuRev.statBackingStream(basedir, modOrAddedElements);
    if (catElems == null) {
        return error(accuRev, "Failed stat backing stream to split modified and added elements");
    }
    modifiedElements = catElems.getMemberElements();
    List<File> addedElements;
    if (AccuRevCapability.STAT_ADDED_NOT_PROMOTED_BUG.isSupported(accuRev.getClientVersion())) {
        modOrAddedElements.removeAll(modifiedElements);
        addedElements = modOrAddedElements;
    } else {
        addedElements = catElems.getNonMemberElements();
    }
    List<File> missingElements = accuRev.stat(basedir, elements, AccuRevStat.MISSING);
    if (missingElements == null) {
        return error(accuRev, "Failed retrieving missing elements");
    }
    List<File> externalElements = accuRev.stat(basedir, elements, AccuRevStat.EXTERNAL);
    if (externalElements == null) {
        return error(accuRev, "Failed retrieving external elements");
    }
    List<ScmFile> resultFiles = getScmFiles(defunctElements, ScmFileStatus.DELETED);
    resultFiles.addAll(getScmFiles(modifiedElements, ScmFileStatus.MODIFIED));
    resultFiles.addAll(getScmFiles(addedElements, ScmFileStatus.ADDED));
    resultFiles.addAll(getScmFiles(missingElements, ScmFileStatus.MISSING));
    resultFiles.addAll(getScmFiles(externalElements, ScmFileStatus.UNKNOWN));
    return new StatusScmResult(accuRev.getCommandLines(), resultFiles);
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) AccuRev(org.apache.maven.scm.provider.accurev.AccuRev) ArrayList(java.util.ArrayList) CategorisedElements(org.apache.maven.scm.provider.accurev.CategorisedElements) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 12 with StatusScmResult

use of org.apache.maven.scm.command.status.StatusScmResult in project maven-scm by apache.

the class VssStatusCommand method executeStatusCommand.

/**
 * {@inheritDoc}
 */
protected StatusScmResult executeStatusCommand(ScmProviderRepository repository, ScmFileSet fileSet) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("executing status command...");
    }
    VssScmProviderRepository repo = (VssScmProviderRepository) repository;
    Commandline cl = buildCmdLine(repo, fileSet);
    VssStatusConsumer consumer = new VssStatusConsumer(repo, getLogger(), fileSet);
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString());
    }
    exitCode = VssCommandLineUtils.executeCommandline(cl, consumer, stderr, getLogger());
    if (exitCode != 0) {
        String error = stderr.getOutput();
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("VSS returns error: [" + error + "] return code: [" + exitCode + "]");
        }
        return new StatusScmResult(cl.toString(), "The vss command failed.", error, false);
    }
    return new StatusScmResult(cl.toString(), consumer.getUpdatedFiles());
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) Commandline(org.codehaus.plexus.util.cli.Commandline) VssScmProviderRepository(org.apache.maven.scm.provider.vss.repository.VssScmProviderRepository) VssCommandLineUtils(org.apache.maven.scm.provider.vss.commands.VssCommandLineUtils) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils)

Example 13 with StatusScmResult

use of org.apache.maven.scm.command.status.StatusScmResult 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 14 with StatusScmResult

use of org.apache.maven.scm.command.status.StatusScmResult in project maven-scm by apache.

the class IntegrityStatusCommand method executeStatusCommand.

/**
 * {@inheritDoc}
 */
@Override
public StatusScmResult executeStatusCommand(ScmProviderRepository repository, ScmFileSet fileSet) throws ScmException {
    StatusScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    getLogger().info("Status of files changed in sandbox " + fileSet.getBasedir().getAbsolutePath());
    try {
        // Initialize the list of ScmFile objects for the StatusScmResult
        List<ScmFile> scmFileList = new ArrayList<ScmFile>();
        // Get a listing for all the changes in the sandbox
        Sandbox siSandbox = iRepo.getSandbox();
        // Get the excludes and includes list from the configuration
        String excludes = Sandbox.formatFilePatterns(fileSet.getExcludes());
        String includes = Sandbox.formatFilePatterns(fileSet.getIncludes());
        // Get the new members found in the sandbox
        List<ScmFile> newMemberList = siSandbox.getNewMembers(excludes, includes);
        // Update the scmFileList with our updates
        scmFileList.addAll(newMemberList);
        // Get the changed/dropped members from the sandbox
        List<WorkItem> changeList = siSandbox.getChangeList();
        for (Iterator<WorkItem> wit = changeList.iterator(); wit.hasNext(); ) {
            WorkItem wi = wit.next();
            File memberFile = new File(wi.getField("name").getValueAsString());
            // Separate the changes into files that have been updated and deleted files
            if (siSandbox.hasWorkingFile((Item) wi.getField("wfdelta").getValue())) {
                scmFileList.add(new ScmFile(memberFile.getAbsolutePath(), ScmFileStatus.UPDATED));
            } else {
                scmFileList.add(new ScmFile(memberFile.getAbsolutePath(), ScmFileStatus.DELETED));
            }
        }
        if (scmFileList.size() == 0) {
            getLogger().info("No local changes found!");
        }
        result = new StatusScmResult(scmFileList, new ScmResult("si viewsandbox", "", "", true));
    } catch (APIException aex) {
        ExceptionHandler eh = new ExceptionHandler(aex);
        getLogger().error("MKS API Exception: " + eh.getMessage());
        getLogger().debug(eh.getCommand() + " exited with return code " + eh.getExitCode());
        result = new StatusScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
    }
    return result;
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) ScmResult(org.apache.maven.scm.ScmResult) StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) ArrayList(java.util.ArrayList) WorkItem(com.mks.api.response.WorkItem) ScmFile(org.apache.maven.scm.ScmFile) Sandbox(org.apache.maven.scm.provider.integrity.Sandbox) ExceptionHandler(org.apache.maven.scm.provider.integrity.ExceptionHandler) APIException(com.mks.api.response.APIException) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File)

Example 15 with StatusScmResult

use of org.apache.maven.scm.command.status.StatusScmResult 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)

Aggregations

StatusScmResult (org.apache.maven.scm.command.status.StatusScmResult)40 ScmFile (org.apache.maven.scm.ScmFile)15 ScmException (org.apache.maven.scm.ScmException)14 File (java.io.File)12 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)9 Commandline (org.codehaus.plexus.util.cli.Commandline)9 ArrayList (java.util.ArrayList)6 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)6 ScmResult (org.apache.maven.scm.ScmResult)5 ScmFileSet (org.apache.maven.scm.ScmFileSet)4 JazzScmCommand (org.apache.maven.scm.provider.jazz.command.JazzScmCommand)3 ErrorConsumer (org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer)3 JazzStatusCommand (org.apache.maven.scm.provider.jazz.command.status.JazzStatusCommand)3 ScmRepository (org.apache.maven.scm.repository.ScmRepository)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 CommandParameters (org.apache.maven.scm.CommandParameters)2 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)2 CategorisedElements (org.apache.maven.scm.provider.accurev.CategorisedElements)2 AbstractAccuRevCommandTest (org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)2 BazaarStatusCommand (org.apache.maven.scm.provider.bazaar.command.status.BazaarStatusCommand)2