Search in sources :

Example 1 with APISession

use of org.apache.maven.scm.provider.integrity.APISession in project maven-scm by apache.

the class IntegrityDiffCommand method executeDiffCommand.

/**
 * Since we can't arbitrarily apply the same start and end revisions to all files in the sandbox,
 * this command will be adapted to show differences between the local version and the repository
 */
@Override
public DiffScmResult executeDiffCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion startRevision, ScmVersion endRevision) throws ScmException {
    DiffScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    APISession api = iRepo.getAPISession();
    getLogger().info("Showing differences bettween local files in " + fileSet.getBasedir().getAbsolutePath() + " and server project " + iRepo.getConfigruationPath());
    // Since the si diff command is not completely API ready, we will use the CLI for this command
    Commandline shell = new Commandline();
    shell.setWorkingDirectory(fileSet.getBasedir());
    shell.setExecutable("si");
    shell.createArg().setValue("diff");
    shell.createArg().setValue("--hostname=" + api.getHostName());
    shell.createArg().setValue("--port=" + api.getPort());
    shell.createArg().setValue("--user=" + api.getUserName());
    shell.createArg().setValue("-R");
    shell.createArg().setValue("--filter=changed:all");
    shell.createArg().setValue("--filter=format:text");
    IntegrityDiffConsumer shellConsumer = new IntegrityDiffConsumer(getLogger());
    try {
        getLogger().debug("Executing: " + shell.getCommandline());
        int exitCode = CommandLineUtils.executeCommandLine(shell, shellConsumer, new CommandLineUtils.StringStreamConsumer());
        boolean success = (exitCode == 128 ? false : true);
        ScmResult scmResult = new ScmResult(shell.getCommandline().toString(), "", "Exit Code: " + exitCode, success);
        // a NPE in org.codehaus.plexus.util.FileUtils.fileWrite(FileUtils.java:426)
        return new DiffScmResult(new ArrayList<ScmFile>(), new HashMap<String, CharSequence>(), "", scmResult);
    } catch (CommandLineException cle) {
        getLogger().error("Command Line Exception: " + cle.getMessage());
        result = new DiffScmResult(shell.getCommandline().toString(), cle.getMessage(), "", false);
    }
    return result;
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult) ScmResult(org.apache.maven.scm.ScmResult) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) ScmFile(org.apache.maven.scm.ScmFile) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) APISession(org.apache.maven.scm.provider.integrity.APISession) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult)

Example 2 with APISession

use of org.apache.maven.scm.provider.integrity.APISession in project maven-scm by apache.

the class IntegrityFileInfoCommand method executeFileInfoCommand.

/**
 * Even though this command is supported via the MKS JAVA API, since at this time we really don't
 * know what the SCM plugin is looking to get in return for this command, we're simply going to
 * run this command via the CLI and return the output verbatim
 */
@Override
public ScmResult executeFileInfoCommand(ScmProviderRepository repository, File workingDirectory, String filename) throws ScmException {
    getLogger().info("Attempting to display scm file information for file: " + filename);
    if (null == filename || filename.length() == 0) {
        throw new ScmException("A single filename is required to execute the fileinfo command!");
    }
    ScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    APISession api = iRepo.getAPISession();
    Commandline shell = new Commandline();
    shell.setWorkingDirectory(workingDirectory);
    shell.setExecutable("si");
    shell.createArg().setValue("memberinfo");
    shell.createArg().setValue("--hostname=" + api.getHostName());
    shell.createArg().setValue("--port=" + api.getPort());
    shell.createArg().setValue("--user=" + api.getUserName());
    shell.createArg().setValue('"' + filename + '"');
    IntegrityFileInfoConsumer shellConsumer = new IntegrityFileInfoConsumer(getLogger());
    try {
        getLogger().debug("Executing: " + shell.getCommandline());
        int exitCode = CommandLineUtils.executeCommandLine(shell, shellConsumer, new CommandLineUtils.StringStreamConsumer());
        boolean success = (exitCode == 128 ? false : true);
        result = new ScmResult(shell.getCommandline().toString(), "", "Exit Code: " + exitCode, success);
    } catch (CommandLineException cle) {
        getLogger().error("Command Line Exception: " + cle.getMessage());
        result = new ScmResult(shell.getCommandline().toString(), cle.getMessage(), "", false);
    }
    return result;
}
Also used : ScmException(org.apache.maven.scm.ScmException) ScmResult(org.apache.maven.scm.ScmResult) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) APISession(org.apache.maven.scm.provider.integrity.APISession) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 3 with APISession

use of org.apache.maven.scm.provider.integrity.APISession in project maven-scm by apache.

the class IntegrityLoginCommand method executeLoginCommand.

/**
 * {@inheritDoc}
 */
@Override
public LoginScmResult executeLoginCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params) throws ScmException {
    getLogger().info("Attempting to connect with the MKS Integrity Server");
    LoginScmResult result;
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    APISession api = iRepo.getAPISession();
    try {
        // First we will establish a connection to the MKS Integrity Server
        Response res = api.connect(iRepo.getHost(), iRepo.getPort(), iRepo.getUser(), iRepo.getPassword());
        int exitCode = res.getExitCode();
        boolean success = (exitCode == 0 ? true : false);
        result = new LoginScmResult(res.getCommandString(), "", "Exit Code: " + exitCode, success);
        // Next we will prepare the Project and Sandbox for the other commands
        Project siProject = new Project(api, iRepo.getConfigruationPath());
        Sandbox siSandbox = new Sandbox(api, siProject, fileSet.getBasedir().getAbsolutePath());
        iRepo.setProject(siProject);
        iRepo.setSandbox(siSandbox);
    } 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 LoginScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
    }
    return result;
}
Also used : Response(com.mks.api.response.Response) ExceptionHandler(org.apache.maven.scm.provider.integrity.ExceptionHandler) Project(org.apache.maven.scm.provider.integrity.Project) APIException(com.mks.api.response.APIException) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) LoginScmResult(org.apache.maven.scm.command.login.LoginScmResult) APISession(org.apache.maven.scm.provider.integrity.APISession) Sandbox(org.apache.maven.scm.provider.integrity.Sandbox)

Aggregations

APISession (org.apache.maven.scm.provider.integrity.APISession)3 IntegrityScmProviderRepository (org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository)3 ScmResult (org.apache.maven.scm.ScmResult)2 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)2 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)2 Commandline (org.codehaus.plexus.util.cli.Commandline)2 APIException (com.mks.api.response.APIException)1 Response (com.mks.api.response.Response)1 ScmException (org.apache.maven.scm.ScmException)1 ScmFile (org.apache.maven.scm.ScmFile)1 DiffScmResult (org.apache.maven.scm.command.diff.DiffScmResult)1 LoginScmResult (org.apache.maven.scm.command.login.LoginScmResult)1 ExceptionHandler (org.apache.maven.scm.provider.integrity.ExceptionHandler)1 Project (org.apache.maven.scm.provider.integrity.Project)1 Sandbox (org.apache.maven.scm.provider.integrity.Sandbox)1