Search in sources :

Example 81 with Commandline

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

the class AbstractCvsAddCommand method executeAddCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeAddCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message, boolean binary) throws ScmException {
    CvsScmProviderRepository repository = (CvsScmProviderRepository) repo;
    Commandline cl = CvsCommandUtils.getBaseCommand("add", repository, fileSet);
    if (binary) {
        cl.createArg().setValue("-kb");
    }
    if (message != null && message.length() > 0) {
        cl.createArg().setValue("-m");
        cl.createArg().setValue("\"" + message + "\"");
    }
    List<ScmFile> addedFiles = new ArrayList<ScmFile>(fileSet.getFileList().size());
    for (File file : fileSet.getFileList()) {
        String path = file.getPath().replace('\\', '/');
        cl.createArg().setValue(path);
        addedFiles.add(new ScmFile(path, ScmFileStatus.ADDED));
    }
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Executing: " + cl);
        getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
    }
    return executeCvsCommand(cl, addedFiles);
}
Also used : CvsScmProviderRepository(org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository) Commandline(org.codehaus.plexus.util.cli.Commandline) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 82 with Commandline

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

the class BootstrapMojo method runGoals.

/**
 * @param relativePathProjectDirectory the project directory's path relative to the checkout
 *                                     directory; or "" if they are the same
 * @throws MojoExecutionException if any
 */
private void runGoals(String relativePathProjectDirectory) throws MojoExecutionException {
    Commandline cl = new Commandline();
    try {
        cl.addSystemEnvironment();
    } catch (Exception e) {
        throw new MojoExecutionException("Can't add system environment variables to mvn command line.", e);
    }
    cl.addEnvironment("MAVEN_TERMINATE_CMD", "on");
    if (this.mavenHome == null) {
        // none windows only
        cl.setExecutable("mvn");
    } else {
        String mvnPath = this.mavenHome.getAbsolutePath() + "/bin/mvn";
        if (Os.isFamily("windows")) {
            String winMvnPath = mvnPath + ".cmd";
            if (!new File(winMvnPath).exists()) {
                winMvnPath = mvnPath + ".bat";
            }
            mvnPath = winMvnPath;
        }
        cl.setExecutable(mvnPath);
    }
    cl.setWorkingDirectory(determineWorkingDirectoryPath(// 
    this.getCheckoutDirectory(), relativePathProjectDirectory, goalsDirectory));
    if (this.goals != null) {
        String[] tokens = StringUtils.split(this.goals, ", ");
        for (int i = 0; i < tokens.length; ++i) {
            cl.createArg().setValue(tokens[i]);
        }
    }
    if (!StringUtils.isEmpty(this.profiles)) {
        cl.createArg().setValue("-P" + this.profiles);
    }
    StreamConsumer consumer = new DefaultConsumer();
    try {
        int result = CommandLineUtils.executeCommandLine(cl, consumer, consumer);
        if (result != 0) {
            throw new MojoExecutionException("Result of mvn execution is: \'" + result + "\'. Release failed.");
        }
    } catch (CommandLineException e) {
        throw new MojoExecutionException("Can't run goal " + goals, e);
    }
}
Also used : StreamConsumer(org.codehaus.plexus.util.cli.StreamConsumer) Commandline(org.codehaus.plexus.util.cli.Commandline) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultConsumer(org.codehaus.plexus.util.cli.DefaultConsumer) File(java.io.File) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 83 with Commandline

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

the class VssHistoryCommand method executeChangeLogCommand.

/**
 * {@inheritDoc}
 */
protected ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repository, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern) throws ScmException {
    VssScmProviderRepository repo = (VssScmProviderRepository) repository;
    Commandline cl = buildCmdLine(repo, fileSet, startDate, endDate);
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Executing: " + cl);
        getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
    }
    VssChangeLogConsumer consumer = new VssChangeLogConsumer(repo, datePattern, getLogger());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode = VssCommandLineUtils.executeCommandline(cl, consumer, stderr, getLogger());
    if (exitCode != 0) {
        return new ChangeLogScmResult(cl.toString(), "The vss command failed.", stderr.getOutput(), false);
    }
    return new ChangeLogScmResult(cl.toString(), new ChangeLogSet(consumer.getModifications(), startDate, endDate));
}
Also used : ChangeLogSet(org.apache.maven.scm.command.changelog.ChangeLogSet) 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) ChangeLogScmResult(org.apache.maven.scm.command.changelog.ChangeLogScmResult)

Example 84 with Commandline

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

the class VssHistoryCommand method buildCmdLine.

public Commandline buildCmdLine(VssScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate) 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_HISTORY);
    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);
    // Display only versions that fall within specified data range.
    if (startDate != null) {
        if (endDate == null) {
            // = now
            endDate = new Date();
        }
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH);
        String dateRange = sdf.format(endDate) + "~" + sdf.format(startDate);
        command.createArg().setValue(VssConstants.FLAG_VERSION_DATE + dateRange);
    }
    return command;
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) SimpleDateFormat(java.text.SimpleDateFormat) ScmException(org.apache.maven.scm.ScmException) Date(java.util.Date)

Example 85 with Commandline

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

the class VssCheckInCommand method buildCmdLine.

public List<Commandline> buildCmdLine(VssScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) 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_CHECKIN);
            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);
            // Ignore: Do not touch local writable files.
            command.createArg().setValue(VssConstants.FLAG_REPLACE_WRITABLE);
            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_CHECKIN);
        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);
        // Ignore: Do not touch local writable files.
        command.createArg().setValue(VssConstants.FLAG_REPLACE_WRITABLE);
        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)

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