Search in sources :

Example 66 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.

the class CvsExeExportCommand method executeCvsCommand.

/**
 * {@inheritDoc}
 */
protected ExportScmResult executeCvsCommand(Commandline cl) throws ScmException {
    CvsUpdateConsumer consumer = new CvsUpdateConsumer(getLogger());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    try {
        exitCode = CommandLineUtils.executeCommandLine(cl, consumer, stderr);
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    if (exitCode != 0) {
        return new ExportScmResult(cl.toString(), "The cvs command failed.", stderr.getOutput(), false);
    }
    return new ExportScmResult(cl.toString(), consumer.getUpdatedFiles());
}
Also used : CvsUpdateConsumer(org.apache.maven.scm.provider.cvslib.command.update.CvsUpdateConsumer) ScmException(org.apache.maven.scm.ScmException) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) ExportScmResult(org.apache.maven.scm.command.export.ExportScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 67 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException 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 68 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException 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 69 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.

the class SvnBranchCommand method executeBranchCommand.

public ScmResult executeBranchCommand(ScmProviderRepository repo, ScmFileSet fileSet, String branch, ScmBranchParameters scmBranchParameters) throws ScmException {
    if (branch == null || StringUtils.isEmpty(branch.trim())) {
        throw new ScmException("branch name must be specified");
    }
    if (!fileSet.getFileList().isEmpty()) {
        throw new ScmException("This provider doesn't support branching subsets of a directory");
    }
    SvnScmProviderRepository repository = (SvnScmProviderRepository) repo;
    File messageFile = FileUtils.createTempFile("maven-scm-", ".commit", null);
    try {
        FileUtils.fileWrite(messageFile.getAbsolutePath(), scmBranchParameters.getMessage());
    } catch (IOException ex) {
        return new BranchScmResult(null, "Error while making a temporary file for the commit message: " + ex.getMessage(), null, false);
    }
    Commandline cl = createCommandLine(repository, fileSet.getBasedir(), branch, messageFile, scmBranchParameters);
    CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
        }
    }
    int exitCode;
    try {
        exitCode = SvnCommandLineUtils.execute(cl, stdout, stderr, getLogger());
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    } finally {
        try {
            FileUtils.forceDelete(messageFile);
        } catch (IOException ex) {
        // ignore
        }
    }
    if (exitCode != 0) {
        return new BranchScmResult(cl.toString(), "The svn branch command failed.", stderr.getOutput(), false);
    }
    List<ScmFile> fileList = new ArrayList<ScmFile>();
    List<File> files = null;
    try {
        @SuppressWarnings("unchecked") List<File> listFiles = FileUtils.getFiles(fileSet.getBasedir(), "**", "**/.svn/**", false);
        files = listFiles;
    } catch (IOException e) {
        throw new ScmException("Error while executing command.", e);
    }
    for (File f : files) {
        fileList.add(new ScmFile(f.getPath(), ScmFileStatus.TAGGED));
    }
    return new BranchScmResult(cl.toString(), fileList);
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) ScmFile(org.apache.maven.scm.ScmFile) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) SvnScmProviderRepository(org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File)

Example 70 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.

the class SvnChangeLogCommand method executeChangeLogCommand.

private ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern, ScmVersion startVersion, ScmVersion endVersion, Integer limit) throws ScmException {
    Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet.getBasedir(), branch, startDate, endDate, startVersion, endVersion, limit);
    SvnChangeLogConsumer consumer = new SvnChangeLogConsumer(getLogger(), datePattern);
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
        }
    }
    int exitCode;
    try {
        exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing svn command.", ex);
    }
    if (exitCode != 0) {
        return new ChangeLogScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    ChangeLogSet changeLogSet = new ChangeLogSet(consumer.getModifications(), startDate, endDate);
    changeLogSet.setStartVersion(startVersion);
    changeLogSet.setEndVersion(endVersion);
    return new ChangeLogScmResult(cl.toString(), changeLogSet);
}
Also used : ScmException(org.apache.maven.scm.ScmException) ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Aggregations

CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)94 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)76 Commandline (org.codehaus.plexus.util.cli.Commandline)67 ScmException (org.apache.maven.scm.ScmException)56 IOException (java.io.IOException)20 SvnCommandLineUtils (org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils)18 File (java.io.File)14 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)13 BufferedReader (java.io.BufferedReader)6 BlameScmResult (org.apache.maven.scm.command.blame.BlameScmResult)6 StatusScmResult (org.apache.maven.scm.command.status.StatusScmResult)6 SvnScmProviderRepository (org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository)6 InputStreamReader (java.io.InputStreamReader)5 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)5 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)5 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)5 StreamConsumer (org.codehaus.plexus.util.cli.StreamConsumer)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 StringTokenizer (java.util.StringTokenizer)4 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)4