Search in sources :

Example 96 with Commandline

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

the class AbstractCvsCheckOutCommand method executeCommand.

@Override
public ScmResult executeCommand(ScmProviderRepository repo, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    ScmVersion version = parameters.getScmVersion(CommandParameter.SCM_VERSION, null);
    boolean binary = parameters.getBoolean(CommandParameter.BINARY, false);
    if (fileSet.getBasedir().exists()) {
        try {
            FileUtils.deleteDirectory(fileSet.getBasedir());
        } catch (IOException e) {
            if (getLogger().isWarnEnabled()) {
                getLogger().warn("Can't delete " + fileSet.getBasedir().getAbsolutePath(), e);
            }
        }
    }
    CvsScmProviderRepository repository = (CvsScmProviderRepository) repo;
    Commandline cl = CvsCommandUtils.getBaseCommand("checkout", repository, fileSet);
    cl.setWorkingDirectory(fileSet.getBasedir().getParentFile().getAbsolutePath());
    if (binary) {
        cl.createArg().setValue("-kb");
    }
    if (version != null && !StringUtils.isEmpty(version.getName())) {
        cl.createArg().setValue("-r");
        cl.createArg().setValue(version.getName());
    }
    cl.createArg().setValue("-d");
    cl.createArg().setValue(fileSet.getBasedir().getName());
    cl.createArg().setValue(repository.getModule());
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Executing: " + cl);
        getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
    }
    return executeCvsCommand(cl);
}
Also used : CvsScmProviderRepository(org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository) Commandline(org.codehaus.plexus.util.cli.Commandline) IOException(java.io.IOException) ScmVersion(org.apache.maven.scm.ScmVersion)

Example 97 with Commandline

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

the class VssTagCommand method buildCmdLine.

public Commandline buildCmdLine(VssScmProviderRepository repo, ScmFileSet fileSet, String tagName, String message) throws ScmException {
    Commandline command = new Commandline();
    command.setWorkingDirectory(fileSet.getBasedir().getAbsolutePath());
    try {
        command.addSystemEnvironment();
    } catch (Exception e) {
        throw new ScmException("Can't add system environment.", e);
    }
    command.addEnvironment("SSDIR", repo.getVssdir());
    String ssDir = VssCommandLineUtils.getSsDir();
    command.setExecutable(ssDir + VssConstants.SS_EXE);
    command.createArg().setValue(VssConstants.COMMAND_LABEL);
    command.createArg().setValue(VssConstants.PROJECT_PREFIX + repo.getProject());
    // User identification to get access to vss repository
    if (repo.getUserPassword() != null) {
        command.createArg().setValue(VssConstants.FLAG_LOGIN + repo.getUserPassword());
    }
    // Ignore: Do not ask for input under any circumstances.
    command.createArg().setValue(VssConstants.FLAG_AUTORESPONSE_DEF);
    command.createArg().setValue(VssConstants.FLAG_LABEL + tagName);
    return command;
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) ScmException(org.apache.maven.scm.ScmException)

Example 98 with Commandline

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

the class VssTagCommand method executeTagCommand.

/**
 * @see org.apache.maven.scm.command.tag.AbstractTagCommand#executeTagCommand(org.apache.maven.scm.provider.ScmProviderRepository, org.apache.maven.scm.ScmFileSet, java.lang.String, java.lang.String)
 */
protected ScmResult executeTagCommand(ScmProviderRepository repository, ScmFileSet fileSet, String tagName, String message) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("executing tag command...");
    }
    VssScmProviderRepository repo = (VssScmProviderRepository) repository;
    Commandline cl = buildCmdLine(repo, fileSet, tagName, message);
    VssTagConsumer consumer = new VssTagConsumer(repo, getLogger());
    // TODO handle deleted files from VSS
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString());
    }
    exitCode = VssCommandLineUtils.executeCommandline(cl, consumer, stderr, getLogger());
    if (exitCode != 0) {
        String error = stderr.getOutput();
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("VSS returns error: [" + error + "] return code: [" + exitCode + "]");
        }
        if (error.indexOf("A writable copy of") < 0) {
            return new TagScmResult(cl.toString(), "The vss command failed.", error, false);
        }
        // print out the writable copy for manual handling
        if (getLogger().isWarnEnabled()) {
            getLogger().warn(error);
        }
    }
    return new TagScmResult(cl.toString(), consumer.getUpdatedFiles());
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) VssScmProviderRepository(org.apache.maven.scm.provider.vss.repository.VssScmProviderRepository) VssCommandLineUtils(org.apache.maven.scm.provider.vss.commands.VssCommandLineUtils) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult)

Example 99 with Commandline

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

the class VssUpdateCommand method buildCmdLine.

public Commandline buildCmdLine(VssScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
    Commandline command = new Commandline();
    command.setWorkingDirectory(fileSet.getBasedir().getAbsolutePath());
    try {
        command.addSystemEnvironment();
    } catch (Exception e) {
        throw new ScmException("Can't add system environment.", e);
    }
    command.addEnvironment("SSDIR", repo.getVssdir());
    String ssDir = VssCommandLineUtils.getSsDir();
    command.setExecutable(ssDir + VssConstants.SS_EXE);
    command.createArg().setValue(VssConstants.COMMAND_GET);
    command.createArg().setValue(VssConstants.PROJECT_PREFIX + repo.getProject());
    // User identification to get access to vss repository
    if (repo.getUserPassword() != null) {
        command.createArg().setValue(VssConstants.FLAG_LOGIN + repo.getUserPassword());
    }
    // Display the history of an entire project list
    command.createArg().setValue(VssConstants.FLAG_RECURSION);
    // Ignore: Do not ask for input under any circumstances.
    command.createArg().setValue(VssConstants.FLAG_AUTORESPONSE_DEF);
    // FIXME Update command only works if there is no file checked out
    // or no file is dirty locally. It's better than overwriting
    // checked out files
    // Ignore: Do not touch local writable files.
    command.createArg().setValue(VssConstants.FLAG_SKIP_WRITABLE);
    if (version != null) {
        command.createArg().setValue(VssConstants.FLAG_VERSION_LABEL + version);
    }
    return command;
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) ScmException(org.apache.maven.scm.ScmException)

Example 100 with Commandline

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

the class VssAddCommandTest method testBuildCmdLine.

public void testBuildCmdLine() throws Exception {
    ScmRepository repository = scmManager.makeScmRepository("scm:vss|username|password@C:/Program File/Visual Source Safe|D:/myProject");
    File dir = getTestFile("target");
    ScmFileSet fileSet = new ScmFileSet(dir);
    VssAddCommand command = new VssAddCommand();
    Commandline cl = command.buildCmdLine((VssScmProviderRepository) repository.getProviderRepository(), fileSet);
    String ssPath = VssCommandLineUtils.getSsDir().replace('/', File.separatorChar);
    assertCommandLine(ssPath + "ss Add -Yusername,password -I-", dir, cl);
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) Commandline(org.codehaus.plexus.util.cli.Commandline) File(java.io.File)

Aggregations

Commandline (org.codehaus.plexus.util.cli.Commandline)446 File (java.io.File)133 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)117 ScmException (org.apache.maven.scm.ScmException)84 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)70 ScmRepository (org.apache.maven.scm.repository.ScmRepository)51 IOException (java.io.IOException)48 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 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)18 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 ScmFile (org.apache.maven.scm.ScmFile)13 CvsScmProviderRepository (org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository)13