Search in sources :

Example 61 with ScmFile

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

the class IntegrityMkdirCommand method executeMkdirCommand.

/**
 * Creates a subproject in the Integrity repository.
 * <br>However, since the subproject automatically creates a folder in
 * the local sandbox, the createInLocal argument will be ignored
 */
@Override
public MkdirScmResult executeMkdirCommand(ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean createInLocal) throws ScmException {
    String dirPath = "";
    Iterator<File> fit = fileSet.getFileList().iterator();
    if (fit.hasNext()) {
        dirPath = fit.next().getPath().replace('\\', '/');
    }
    if (null == dirPath || dirPath.length() == 0) {
        throw new ScmException("A relative directory path is required to execute this command!");
    }
    getLogger().info("Creating subprojects one per directory, as required for " + dirPath);
    MkdirScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    try {
        Response res = iRepo.getSandbox().createSubproject(dirPath);
        String subProject = res.getWorkItems().next().getResult().getField("resultant").getItem().getDisplayId();
        List<ScmFile> createdDirs = new ArrayList<ScmFile>();
        createdDirs.add(new ScmFile(subProject, ScmFileStatus.ADDED));
        int exitCode = res.getExitCode();
        boolean success = (exitCode == 0 ? true : false);
        getLogger().info("Successfully created subproject " + subProject);
        result = new MkdirScmResult(createdDirs, new ScmResult(res.getCommandString(), "", "Exit Code: " + exitCode, success));
    } catch (APIException aex) {
        ExceptionHandler eh = new ExceptionHandler(aex);
        getLogger().error("MKS API Exception: " + eh.getMessage());
        getLogger().info(eh.getCommand() + " exited with return code " + eh.getExitCode());
        result = new MkdirScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
    }
    return result;
}
Also used : ScmException(org.apache.maven.scm.ScmException) MkdirScmResult(org.apache.maven.scm.command.mkdir.MkdirScmResult) ScmResult(org.apache.maven.scm.ScmResult) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile) Response(com.mks.api.response.Response) ExceptionHandler(org.apache.maven.scm.provider.integrity.ExceptionHandler) APIException(com.mks.api.response.APIException) MkdirScmResult(org.apache.maven.scm.command.mkdir.MkdirScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File)

Example 62 with ScmFile

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

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

the class IntegrityListCommand method executeListCommand.

/**
 * {@inheritDoc}
 */
@Override
public ListScmResult executeListCommand(ScmProviderRepository repository, ScmFileSet fileSet, boolean recursive, ScmVersion scmVersion) throws ScmException {
    ListScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    getLogger().info("Listing all files in project " + iRepo.getConfigruationPath());
    try {
        // Get a listing for all the members in the project...
        List<Member> projectMembers = iRepo.getProject().listFiles(fileSet.getBasedir().getAbsolutePath());
        // Initialize the list of ScmFile objects for the ListScmResult
        List<ScmFile> scmFileList = new ArrayList<ScmFile>();
        for (Iterator<Member> it = projectMembers.iterator(); it.hasNext(); ) {
            Member siMember = it.next();
            scmFileList.add(new ScmFile(siMember.getTargetFilePath(), ScmFileStatus.UNKNOWN));
        }
        result = new ListScmResult(scmFileList, new ScmResult("si viewproject", "", "", 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 ListScmResult(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) ScmResult(org.apache.maven.scm.ScmResult) ListScmResult(org.apache.maven.scm.command.list.ListScmResult) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) ListScmResult(org.apache.maven.scm.command.list.ListScmResult) ArrayList(java.util.ArrayList) Member(org.apache.maven.scm.provider.integrity.Member) ScmFile(org.apache.maven.scm.ScmFile)

Example 64 with ScmFile

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

Example 65 with ScmFile

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

the class JazzUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Executing update command...");
    }
    JazzUpdateConsumer updateConsumer = new JazzUpdateConsumer(repo, getLogger());
    ErrorConsumer errConsumer = new ErrorConsumer(getLogger());
    JazzScmCommand updateCmd = createAcceptCommand(repo, fileSet);
    int status = updateCmd.execute(updateConsumer, errConsumer);
    if (status != 0) {
        return new UpdateScmResult(updateCmd.getCommandString(), "Error code for Jazz SCM update command - " + status, errConsumer.getOutput(), false);
    }
    if (getLogger().isDebugEnabled()) {
        if (!updateConsumer.getUpdatedFiles().isEmpty()) {
            getLogger().debug("Iterating over \"Update\" results");
            for (ScmFile file : updateConsumer.getUpdatedFiles()) {
                getLogger().debug(file.getPath() + " : " + file.getStatus());
            }
        } else {
            getLogger().debug("There are no updated files");
        }
    }
    // We can use the checkout directory for this.
    return new UpdateScmResult(updateCmd.getCommandString(), updateConsumer.getUpdatedFiles());
}
Also used : ErrorConsumer(org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) JazzScmCommand(org.apache.maven.scm.provider.jazz.command.JazzScmCommand) 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