Search in sources :

Example 21 with Commandline

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

the class SvnExeBranchCommandTckTest method testCommandLine.

private void testCommandLine(String scmUrl, String branch, File messageFile, String user, String commandLine, ScmBranchParameters scmBranchParameters) throws Exception {
    File workingDirectory = getTestFile("target/svn-update-command-test");
    ScmRepository repository = getScmManager().makeScmRepository(scmUrl);
    SvnScmProviderRepository svnRepository = (SvnScmProviderRepository) repository.getProviderRepository();
    svnRepository.setUser(user);
    Commandline cl = null;
    if (scmBranchParameters == null) {
        cl = SvnBranchCommand.createCommandLine(svnRepository, workingDirectory, branch, messageFile);
    } else {
        cl = SvnBranchCommand.createCommandLine(svnRepository, workingDirectory, branch, messageFile, scmBranchParameters);
    }
    assertCommandLine(commandLine, workingDirectory, cl);
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) Commandline(org.codehaus.plexus.util.cli.Commandline) SvnScmProviderRepository(org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository) File(java.io.File)

Example 22 with Commandline

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

the class SvnCheckInCommand method executeCheckInCommand.

/**
 * {@inheritDoc}
 */
protected CheckInScmResult executeCheckInCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message, ScmVersion version) throws ScmException {
    if (version != null && StringUtils.isNotEmpty(version.getName())) {
        throw new ScmException("This provider command can't handle tags.");
    }
    File messageFile = FileUtils.createTempFile("maven-scm-", ".commit", null);
    try {
        FileUtils.fileWrite(messageFile.getAbsolutePath(), message);
    } catch (IOException ex) {
        return new CheckInScmResult(null, "Error while making a temporary file for the commit message: " + ex.getMessage(), null, false);
    }
    Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet, messageFile);
    SvnCheckInConsumer consumer = new SvnCheckInConsumer(getLogger(), fileSet.getBasedir());
    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 command.", ex);
    } finally {
        try {
            FileUtils.forceDelete(messageFile);
        } catch (IOException ex) {
        // ignore
        }
    }
    if (exitCode != 0) {
        return new CheckInScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    return new CheckInScmResult(cl.toString(), consumer.getCheckedInFiles(), Integer.toString(consumer.getRevision()));
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) IOException(java.io.IOException) File(java.io.File) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 23 with Commandline

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

the class SvnAddCommand method executeAddCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeAddCommand(ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean binary) throws ScmException {
    // TODO: could do this with propset?
    if (binary) {
        throw new ScmException("This provider does not yet support binary files");
    }
    if (fileSet.getFileList().isEmpty()) {
        throw new ScmException("You must provide at least one file/directory to add");
    }
    Commandline cl = createCommandLine(fileSet.getBasedir(), fileSet.getFileList());
    SvnAddConsumer consumer = new SvnAddConsumer(getLogger());
    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 command.", ex);
    }
    if (exitCode != 0) {
        return new AddScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    return new AddScmResult(cl.toString(), consumer.getAddedFiles());
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 24 with Commandline

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

the class SvnBlameCommand method executeBlameCommand.

/**
 * {@inheritDoc}
 */
public BlameScmResult executeBlameCommand(ScmProviderRepository repo, ScmFileSet workingDirectory, String filename) throws ScmException {
    Commandline cl = createCommandLine((SvnScmProviderRepository) repo, workingDirectory.getBasedir(), filename);
    SvnBlameConsumer consumer = new SvnBlameConsumer(getLogger());
    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 command.", ex);
    }
    if (exitCode != 0) {
        return new BlameScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    return new BlameScmResult(cl.toString(), consumer.getLines());
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) BlameScmResult(org.apache.maven.scm.command.blame.BlameScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 25 with Commandline

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

the class SvnBlameCommand method createCommandLine.

public static Commandline createCommandLine(SvnScmProviderRepository repository, File workingDirectory, String filename) {
    Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine(workingDirectory, repository);
    cl.createArg().setValue("blame");
    cl.createArg().setValue("--xml");
    cl.createArg().setValue(filename);
    return cl;
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline)

Aggregations

Commandline (org.codehaus.plexus.util.cli.Commandline)443 File (java.io.File)131 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)116 ScmException (org.apache.maven.scm.ScmException)84 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)67 ScmRepository (org.apache.maven.scm.repository.ScmRepository)51 IOException (java.io.IOException)45 ScmFileSet (org.apache.maven.scm.ScmFileSet)34 Test (org.junit.Test)28 StringStreamConsumer (org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer)26 ArrayList (java.util.ArrayList)22 StarteamScmProviderRepository (org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository)22 PerforceScmProviderRepository (org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository)19 SvnCommandLineUtils (org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils)17 GitCommandLineUtils (org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils)16 GitScmProviderRepository (org.apache.maven.scm.provider.git.repository.GitScmProviderRepository)16 SvnScmProviderRepository (org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository)16 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)15 ScmFile (org.apache.maven.scm.ScmFile)13 CvsScmProviderRepository (org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository)13