Search in sources :

Example 86 with Commandline

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

the class VssCheckOutCommand 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);
    // Ignore: Do not touch local writable files.
    command.createArg().setValue(VssConstants.FLAG_REPLACE_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 87 with Commandline

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

the class VssCheckOutCommand method executeCheckOutCommand.

/**
 * {@inheritDoc}
 */
protected CheckOutScmResult executeCheckOutCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion version, boolean recursive, boolean shallow) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("executing checkout command...");
    }
    VssScmProviderRepository repo = (VssScmProviderRepository) repository;
    Commandline cl = buildCmdLine(repo, fileSet, version);
    VssCheckOutConsumer consumer = new VssCheckOutConsumer(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 CheckOutScmResult(cl.toString(), "The vss command failed.", error, false);
        }
        // print out the writable copy for manual handling
        if (getLogger().isWarnEnabled()) {
            getLogger().warn(error);
        }
    }
    return new CheckOutScmResult(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) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult)

Example 88 with Commandline

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

the class VssEditCommand method buildCmdLine.

public List<Commandline> buildCmdLine(VssScmProviderRepository repo, ScmFileSet fileSet) throws ScmException {
    List<File> files = fileSet.getFileList();
    List<Commandline> commands = new ArrayList<Commandline>();
    if (files.size() > 0) {
        String base;
        try {
            base = fileSet.getBasedir().getCanonicalPath();
        } catch (IOException e) {
            throw new ScmException("Invalid canonical path", e);
        }
        for (File file : files) {
            Commandline command = new Commandline();
            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_CHECKOUT);
            String absolute;
            try {
                absolute = file.getCanonicalPath();
                String relative;
                int index = absolute.indexOf(base);
                if (index >= 0) {
                    relative = absolute.substring(index + base.length());
                } else {
                    relative = file.getPath();
                }
                relative = relative.replace('\\', '/');
                if (!relative.startsWith("/")) {
                    relative = '/' + relative;
                }
                String relativeFolder = relative.substring(0, relative.lastIndexOf('/'));
                command.setWorkingDirectory(new File(fileSet.getBasedir().getAbsolutePath() + File.separatorChar + relativeFolder).getCanonicalPath());
                command.createArg().setValue(VssConstants.PROJECT_PREFIX + repo.getProject() + relative);
            } catch (IOException e) {
                throw new ScmException("Invalid canonical path", e);
            }
            // 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);
            commands.add(command);
        }
    } else {
        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_CHECKOUT);
        command.createArg().setValue(VssConstants.PROJECT_PREFIX + repo.getProject());
        // Display the history of an entire project list
        command.createArg().setValue(VssConstants.FLAG_RECURSION);
        // 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);
        commands.add(command);
    }
    return commands;
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) IOException(java.io.IOException) ScmException(org.apache.maven.scm.ScmException)

Example 89 with Commandline

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

the class VssStatusCommand method buildCmdLine.

public Commandline buildCmdLine(VssScmProviderRepository repo, ScmFileSet fileSet) 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_DIFF);
    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);
    return command;
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) ScmException(org.apache.maven.scm.ScmException)

Example 90 with Commandline

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

the class VssStatusCommand method executeStatusCommand.

/**
 * {@inheritDoc}
 */
protected StatusScmResult executeStatusCommand(ScmProviderRepository repository, ScmFileSet fileSet) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("executing status command...");
    }
    VssScmProviderRepository repo = (VssScmProviderRepository) repository;
    Commandline cl = buildCmdLine(repo, fileSet);
    VssStatusConsumer consumer = new VssStatusConsumer(repo, getLogger(), fileSet);
    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 + "]");
        }
        return new StatusScmResult(cl.toString(), "The vss command failed.", error, false);
    }
    return new StatusScmResult(cl.toString(), consumer.getUpdatedFiles());
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) 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)

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