Search in sources :

Example 56 with ScmFile

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

the class Sandbox method getNewMembers.

/**
 * Executes a 'si viewnonmembers' command filtering the results using the exclude and include lists
 *
 * @param exclude Pattern containing the exclude file list
 * @param include Pattern containing the include file list
 * @return List of ScmFile objects representing the new files in the Sandbox
 * @throws APIException
 */
public List<ScmFile> getNewMembers(String exclude, String include) throws APIException {
    // Store a list of files that were added to the repository
    List<ScmFile> filesAdded = new ArrayList<ScmFile>();
    Command siViewNonMem = new Command(Command.SI, "viewnonmembers");
    siViewNonMem.addOption(new Option("recurse"));
    if (null != exclude && exclude.length() > 0) {
        siViewNonMem.addOption(new Option("exclude", exclude));
    }
    if (null != include && include.length() > 0) {
        siViewNonMem.addOption(new Option("include", include));
    }
    siViewNonMem.addOption(new Option("noincludeFormers"));
    siViewNonMem.addOption(new Option("cwd", sandboxDir));
    Response response = api.runCommand(siViewNonMem);
    for (WorkItemIterator wit = response.getWorkItems(); wit.hasNext(); ) {
        filesAdded.add(new ScmFile(wit.next().getField("absolutepath").getValueAsString(), ScmFileStatus.ADDED));
    }
    return filesAdded;
}
Also used : Response(com.mks.api.response.Response) Command(com.mks.api.Command) ArrayList(java.util.ArrayList) Option(com.mks.api.Option) WorkItemIterator(com.mks.api.response.WorkItemIterator) ScmFile(org.apache.maven.scm.ScmFile)

Example 57 with ScmFile

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

the class Sandbox method checkInUpdates.

/**
 * Wrapper function to check-in all changes and drop members associated with missing working files
 *
 * @param message Description for the changes
 * @return
 */
public List<ScmFile> checkInUpdates(String message) {
    // Re-initialize the overall ciSuccess to be true for now
    ciSuccess = true;
    // Store a list of files that were changed/removed to the repository
    List<ScmFile> changedFiles = new ArrayList<ScmFile>();
    api.getLogger().debug("Looking for changed and dropped members in sandbox dir: " + sandboxDir);
    try {
        // Let the list of changed files
        List<WorkItem> changeList = getChangeList();
        // Check-in all changed files, drop all members with missing working files
        for (Iterator<WorkItem> wit = changeList.iterator(); wit.hasNext(); ) {
            try {
                WorkItem wi = wit.next();
                File memberFile = new File(wi.getField("name").getValueAsString());
                // Check-in files that have actually changed...
                if (hasWorkingFile((Item) wi.getField("wfdelta").getValue())) {
                    // Lock each member as you go...
                    lock(memberFile, wi.getId());
                    // Commit the changes...
                    checkin(memberFile, wi.getId(), message);
                    // Update the changed file list
                    changedFiles.add(new ScmFile(memberFile.getAbsolutePath(), ScmFileStatus.CHECKED_IN));
                } else {
                    // Drop the member if there is no working file
                    dropMember(memberFile, wi.getId());
                    // Update the changed file list
                    changedFiles.add(new ScmFile(memberFile.getAbsolutePath(), ScmFileStatus.DELETED));
                }
            } catch (APIException aex) {
                // Set the ciSuccess to false, since we ran into a problem
                ciSuccess = false;
                ExceptionHandler eh = new ExceptionHandler(aex);
                api.getLogger().error("MKS API Exception: " + eh.getMessage());
                api.getLogger().debug(eh.getCommand() + " completed with exit Code " + eh.getExitCode());
            }
        }
    } catch (APIException aex) {
        // Set the ciSuccess to false, since we ran into a problem
        ciSuccess = false;
        ExceptionHandler eh = new ExceptionHandler(aex);
        api.getLogger().error("MKS API Exception: " + eh.getMessage());
        api.getLogger().debug(eh.getCommand() + " completed with exit Code " + eh.getExitCode());
    }
    return changedFiles;
}
Also used : APIException(com.mks.api.response.APIException) ArrayList(java.util.ArrayList) WorkItem(com.mks.api.response.WorkItem) ChangeFile(org.apache.maven.scm.ChangeFile) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 58 with ScmFile

use of org.apache.maven.scm.ScmFile 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 59 with ScmFile

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

the class JazzAddConsumer 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);
    if (haveSeenChanges) {
        // We have already seen the "Changes:" line, so we must now be processing files.
        String trimmed = line.trim();
        int spacePos = trimmed.indexOf(" ");
        // NOTE: The second + 1 is to remove the leading slash
        String path = trimmed.substring(spacePos + 1 + 1);
        fCheckedInFiles.add(new ScmFile(path, ScmFileStatus.CHECKED_OUT));
    } else {
        if ("Changes:".equals(line.trim())) {
            haveSeenChanges = true;
        }
    }
}
Also used : ScmFile(org.apache.maven.scm.ScmFile)

Example 60 with ScmFile

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

the class IntegrityExportCommand method executeExportCommand.

/**
 * {@inheritDoc}
 */
@Override
public ExportScmResult executeExportCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion scmVersion, String outputDirectory) throws ScmException {
    // First lets figure out where we need to export files to...
    String exportDir = outputDirectory;
    exportDir = ((null != exportDir && exportDir.length() > 0) ? exportDir : fileSet.getBasedir().getAbsolutePath());
    // Let the user know where we're going to be exporting the files...
    getLogger().info("Attempting to export files to " + exportDir);
    ExportScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    try {
        // Lets set our overall export success flag
        boolean exportSuccess = true;
        // Perform a fresh checkout of each file in the member list...
        List<Member> projectMembers = iRepo.getProject().listFiles(exportDir);
        // Initialize the list of files we actually exported...
        List<ScmFile> scmFileList = new ArrayList<ScmFile>();
        for (Iterator<Member> it = projectMembers.iterator(); it.hasNext(); ) {
            Member siMember = it.next();
            try {
                getLogger().info("Attempting to export file: " + siMember.getTargetFilePath() + " at revision " + siMember.getRevision());
                siMember.checkout(iRepo.getAPISession());
                scmFileList.add(new ScmFile(siMember.getTargetFilePath(), ScmFileStatus.UNKNOWN));
            } catch (APIException ae) {
                exportSuccess = false;
                ExceptionHandler eh = new ExceptionHandler(ae);
                getLogger().error("MKS API Exception: " + eh.getMessage());
                getLogger().debug(eh.getCommand() + " exited with return code " + eh.getExitCode());
            }
        }
        // Lets advice the user that we've checked out all the members
        getLogger().info("Exported " + scmFileList.size() + " files out of a total of " + projectMembers.size() + " files!");
        if (exportSuccess) {
            result = new ExportScmResult("si co", scmFileList);
        } else {
            result = new ExportScmResult("si co", "Failed to export all files!", "", exportSuccess);
        }
    } 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 ExportScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
    }
    return result;
}
Also used : ExceptionHandler(org.apache.maven.scm.provider.integrity.ExceptionHandler) APIException(com.mks.api.response.APIException) ExportScmResult(org.apache.maven.scm.command.export.ExportScmResult) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) ArrayList(java.util.ArrayList) Member(org.apache.maven.scm.provider.integrity.Member) ScmFile(org.apache.maven.scm.ScmFile)

Aggregations

ScmFile (org.apache.maven.scm.ScmFile)198 File (java.io.File)102 ArrayList (java.util.ArrayList)51 ScmException (org.apache.maven.scm.ScmException)34 BufferedReader (java.io.BufferedReader)21 DefaultLog (org.apache.maven.scm.log.DefaultLog)20 ScmFileStatus (org.apache.maven.scm.ScmFileStatus)19 ScmFileSet (org.apache.maven.scm.ScmFileSet)17 InputStreamReader (java.io.InputStreamReader)16 ScmResult (org.apache.maven.scm.ScmResult)15 StatusScmResult (org.apache.maven.scm.command.status.StatusScmResult)15 IOException (java.io.IOException)14 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)13 Matcher (java.util.regex.Matcher)11 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)11 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)10 UpdateScmResult (org.apache.maven.scm.command.update.UpdateScmResult)10 Commandline (org.codehaus.plexus.util.cli.Commandline)10 SynergyScmProviderRepository (org.apache.maven.scm.provider.synergy.repository.SynergyScmProviderRepository)9 FileInputStream (java.io.FileInputStream)8