Search in sources :

Example 31 with Commandline

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

the class SvnChangeLogCommandTest method testCommandLine.

private void testCommandLine(String scmUrl, ScmVersion startVersion, ScmVersion endVersion, String commandLine) throws Exception {
    File workingDirectory = getTestFile("target/svn-update-command-test");
    ScmRepository repository = getScmManager().makeScmRepository(scmUrl);
    SvnScmProviderRepository svnRepository = (SvnScmProviderRepository) repository.getProviderRepository();
    Commandline cl = SvnChangeLogCommand.createCommandLine(svnRepository, workingDirectory, null, null, null, startVersion, endVersion);
    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 32 with Commandline

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

the class SvnExportCommandTest method testCommandLine.

private void testCommandLine(String scmUrl, File workingDirectory, File exportDirectory, String commandLine) throws Exception {
    ScmRepository repository = getScmManager().makeScmRepository(scmUrl);
    SvnScmProviderRepository svnRepository = (SvnScmProviderRepository) repository.getProviderRepository();
    Commandline cl = SvnExeExportCommand.createCommandLine(svnRepository, exportDirectory, null, scmUrl, exportDirectory != null ? exportDirectory.getAbsolutePath() : null);
    assertCommandLine(commandLine, exportDirectory, 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)

Example 33 with Commandline

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

the class PerforceCheckInCommand method createCommandLine.

public static Commandline createCommandLine(PerforceScmProviderRepository repo, File workingDirectory) {
    Commandline command = PerforceScmProvider.createP4Command(repo, workingDirectory);
    command.createArg().setValue("submit");
    command.createArg().setValue("-i");
    return command;
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline)

Example 34 with Commandline

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

the class PerforceCheckOutCommand method getLastChangelist.

private int getLastChangelist(PerforceScmProviderRepository repo, File workingDirectory, String specname) {
    int lastChangelist = 0;
    try {
        Commandline command = PerforceScmProvider.createP4Command(repo, workingDirectory);
        command.createArg().setValue("-c" + specname);
        command.createArg().setValue("changes");
        command.createArg().setValue("-m1");
        command.createArg().setValue("-ssubmitted");
        command.createArg().setValue("//" + specname + "/...");
        getLogger().debug("Executing: " + PerforceScmProvider.clean(command.toString()));
        Process proc = command.execute();
        BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
        String line;
        String lastChangelistStr = "";
        while ((line = br.readLine()) != null) {
            getLogger().debug("Consuming: " + line);
            Pattern changeRegexp = Pattern.compile("Change (\\d+)");
            Matcher matcher = changeRegexp.matcher(line);
            if (matcher.find()) {
                lastChangelistStr = matcher.group(1);
            }
        }
        br.close();
        try {
            lastChangelist = Integer.parseInt(lastChangelistStr);
        } catch (NumberFormatException nfe) {
            getLogger().debug("Could not parse changelist from line " + line);
        }
    } catch (IOException e) {
        getLogger().error(e);
    } catch (CommandLineException e) {
        getLogger().error(e);
    }
    return lastChangelist;
}
Also used : Pattern(java.util.regex.Pattern) Commandline(org.codehaus.plexus.util.cli.Commandline) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 35 with Commandline

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

the class PerforceCheckOutCommand method createCommandLine.

public static Commandline createCommandLine(PerforceScmProviderRepository repo, File workingDirectory, ScmVersion version, String specname) {
    Commandline command = PerforceScmProvider.createP4Command(repo, workingDirectory);
    command.createArg().setValue("-c" + specname);
    command.createArg().setValue("sync");
    // Use a simple heuristic to determine if we should use the Force flag
    // on sync.  Forcing sync is a HUGE performance hit but is required in
    // rare instances where source is somehow deleted.  If the target
    // directory is completely empty, assume a force is required.  If
    // not empty, we assume a previous checkout was already done and a normal
    // sync will suffice.
    // SCM-110
    String[] files = workingDirectory.list();
    if (files == null || files.length == 0) {
        // We need to force so checkout to an empty directory will work.
        command.createArg().setValue("-f");
    }
    // latter until the exact semantics are clearer.
    if (version != null && StringUtils.isNotEmpty(version.getName())) {
        command.createArg().setValue("@" + version.getName());
    }
    return command;
}
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