Search in sources :

Example 61 with CommandLineException

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

the class ClearCaseUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion version) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("executing update command...");
    }
    Commandline cl = createCommandLine(fileSet);
    ClearCaseUpdateConsumer consumer = new ClearCaseUpdateConsumer(getLogger());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    try {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString());
        }
        exitCode = CommandLineUtils.executeCommandLine(cl, consumer, stderr);
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing clearcase command.", ex);
    }
    if (exitCode != 0) {
        return new UpdateScmResult(cl.toString(), "The cleartool command failed.", stderr.getOutput(), false);
    }
    return new UpdateScmResult(cl.toString(), consumer.getUpdatedFiles());
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 62 with CommandLineException

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

the class ClearCaseAddCommand method executeAddCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeAddCommand(ScmProviderRepository scmProviderRepository, ScmFileSet scmFileSet, String string, boolean b) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("executing add command...");
    }
    Commandline cl = createCommandLine(scmFileSet);
    ClearCaseAddConsumer consumer = new ClearCaseAddConsumer(getLogger());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    try {
        // First we need to 'check out' the current directory
        Commandline checkoutCurrentDirCommandLine = ClearCaseEditCommand.createCheckoutCurrentDirCommandLine(scmFileSet);
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Executing: " + checkoutCurrentDirCommandLine.getWorkingDirectory().getAbsolutePath() + ">>" + checkoutCurrentDirCommandLine.toString());
        }
        exitCode = CommandLineUtils.executeCommandLine(checkoutCurrentDirCommandLine, new CommandLineUtils.StringStreamConsumer(), stderr);
        if (exitCode == 0) {
            // Then we add the file
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString());
            }
            exitCode = CommandLineUtils.executeCommandLine(cl, consumer, stderr);
            if (exitCode == 0) {
                // Then we check in the current directory again.
                Commandline checkinCurrentDirCommandLine = ClearCaseEditCommand.createCheckinCurrentDirCommandLine(scmFileSet);
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("Executing: " + checkinCurrentDirCommandLine.getWorkingDirectory().getAbsolutePath() + ">>" + checkinCurrentDirCommandLine.toString());
                }
                exitCode = CommandLineUtils.executeCommandLine(checkinCurrentDirCommandLine, new CommandLineUtils.StringStreamConsumer(), stderr);
            }
        }
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing clearcase command.", ex);
    }
    if (exitCode != 0) {
        return new StatusScmResult(cl.toString(), "The cleartool command failed.", stderr.getOutput(), false);
    }
    return new StatusScmResult(cl.toString(), consumer.getAddedFiles());
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 63 with CommandLineException

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

the class ClearCaseCheckOutCommand method executeCheckOutCommand.

// ----------------------------------------------------------------------
// AbstractCheckOutCommand Implementation
// ----------------------------------------------------------------------
/**
 * {@inheritDoc}
 */
protected CheckOutScmResult executeCheckOutCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion version, boolean recursive, boolean shallow) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("executing checkout command...");
    }
    ClearCaseScmProviderRepository repo = (ClearCaseScmProviderRepository) repository;
    File workingDirectory = fileSet.getBasedir();
    if (version != null && getLogger().isDebugEnabled()) {
        getLogger().debug(version.getType() + ": " + version.getName());
    }
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Running with CLEARCASE " + settings.getClearcaseType());
    }
    ClearCaseCheckOutConsumer consumer = new ClearCaseCheckOutConsumer(getLogger());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    Commandline cl;
    String projectDirectory = "";
    try {
        // Since clearcase only wants to checkout to a non-existent directory, first delete the working dir
        // if it already exists
        FileUtils.deleteDirectory(workingDirectory);
        // First create the view
        String viewName = getUniqueViewName(repo, workingDirectory.getAbsolutePath());
        String streamIdentifier = getStreamIdentifier(repo.getStreamName(), repo.getVobName());
        cl = createCreateViewCommandLine(workingDirectory, viewName, streamIdentifier);
        if (getLogger().isInfoEnabled()) {
            getLogger().info("Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString());
        }
        exitCode = CommandLineUtils.executeCommandLine(cl, new CommandLineUtils.StringStreamConsumer(), stderr);
        if (exitCode == 0) {
            File configSpecLocation;
            if (!repo.isAutoConfigSpec()) {
                configSpecLocation = repo.getConfigSpec();
                if (version != null && StringUtils.isNotEmpty(version.getName())) {
                    // 
                    throw new UnsupportedOperationException("Building on a label not supported with user-specified config specs");
                }
            } else {
                // write config spec to temp file
                String configSpec;
                if (!repo.hasElements()) {
                    configSpec = createConfigSpec(repo.getLoadDirectory(), version);
                } else {
                    configSpec = createConfigSpec(repo.getLoadDirectory(), repo.getElementName(), version);
                }
                if (getLogger().isInfoEnabled()) {
                    getLogger().info("Created config spec for view '" + viewName + "':\n" + configSpec);
                }
                configSpecLocation = writeTemporaryConfigSpecFile(configSpec, viewName);
                // When checking out from ClearCase, the directory structure of the
                // SCM system is repeated within the checkout directory. E.g. if you check out the
                // project "my/project" to "/some/dir", the project sources are actually checked out
                // to "my/project/some/dir".
                projectDirectory = repo.getLoadDirectory();
                // strip off leading / to make the path relative
                if (projectDirectory.startsWith("/")) {
                    projectDirectory = projectDirectory.substring(1);
                }
            }
            cl = createUpdateConfigSpecCommandLine(workingDirectory, configSpecLocation, viewName);
            if (getLogger().isInfoEnabled()) {
                getLogger().info("Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString());
            }
            exitCode = CommandLineUtils.executeCommandLine(cl, consumer, stderr);
        }
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing clearcase command.", ex);
    } catch (IOException ex) {
        throw new ScmException("Error while deleting working directory.", ex);
    }
    if (exitCode != 0) {
        return new CheckOutScmResult(cl.toString(), "The cleartool command failed.", stderr.getOutput(), false);
    }
    return new CheckOutScmResult(cl.toString(), consumer.getCheckedOutFiles(), projectDirectory);
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) IOException(java.io.IOException) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) File(java.io.File) ClearCaseScmProviderRepository(org.apache.maven.scm.provider.clearcase.repository.ClearCaseScmProviderRepository)

Example 64 with CommandLineException

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

the class CvsExeBlameCommand method executeCvsCommand.

/**
 * {@inheritDoc}
 */
protected BlameScmResult executeCvsCommand(Commandline cl, CvsScmProviderRepository repository) throws ScmException {
    CvsBlameConsumer consumer = new CvsBlameConsumer(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 cvs command.", ex);
    }
    if (exitCode != 0) {
        return new BlameScmResult(cl.toString(), "The cvs command failed.", stderr.getOutput(), false);
    }
    return new BlameScmResult(cl.toString(), consumer.getLines());
}
Also used : ScmException(org.apache.maven.scm.ScmException) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) BlameScmResult(org.apache.maven.scm.command.blame.BlameScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) CvsBlameConsumer(org.apache.maven.scm.provider.cvslib.command.blame.CvsBlameConsumer)

Example 65 with CommandLineException

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

the class CvsExeCheckOutCommand method executeCvsCommand.

/**
 * {@inheritDoc}
 */
protected CheckOutScmResult executeCvsCommand(Commandline cl) throws ScmException {
    CvsCheckOutConsumer consumer = new CvsCheckOutConsumer(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 CheckOutScmResult(cl.toString(), "The cvs command failed.", stderr.getOutput(), false);
    }
    return new CheckOutScmResult(cl.toString(), consumer.getCheckedOutFiles());
}
Also used : ScmException(org.apache.maven.scm.ScmException) CvsCheckOutConsumer(org.apache.maven.scm.provider.cvslib.command.checkout.CvsCheckOutConsumer) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) 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