Search in sources :

Example 26 with Commandline

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

the class SvnExeExportCommand method executeExportCommand.

/**
 * {@inheritDoc}
 */
protected ExportScmResult executeExportCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version, String outputDirectory) throws ScmException {
    if (outputDirectory == null) {
        outputDirectory = fileSet.getBasedir().getAbsolutePath();
    }
    SvnScmProviderRepository repository = (SvnScmProviderRepository) repo;
    String url = repository.getUrl();
    if (version != null && StringUtils.isNotEmpty(version.getName())) {
        if (version instanceof ScmTag) {
            url = SvnTagBranchUtils.resolveTagUrl(repository, (ScmTag) version);
        } else if (version instanceof ScmBranch) {
            url = SvnTagBranchUtils.resolveBranchUrl(repository, (ScmBranch) version);
        }
    }
    url = SvnCommandUtils.fixUrl(url, repository.getUser());
    Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet.getBasedir(), version, url, outputDirectory);
    SvnUpdateConsumer consumer = new SvnUpdateConsumer(getLogger(), fileSet.getBasedir());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
        if (cl.getWorkingDirectory() != null && 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 ExportScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    return new ExportScmResultWithRevision(cl.toString(), consumer.getUpdatedFiles(), String.valueOf(consumer.getRevision()));
}
Also used : ScmBranch(org.apache.maven.scm.ScmBranch) ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) SvnUpdateConsumer(org.apache.maven.scm.provider.svn.svnexe.command.update.SvnUpdateConsumer) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) ScmTag(org.apache.maven.scm.ScmTag) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) ExportScmResult(org.apache.maven.scm.command.export.ExportScmResult) SvnScmProviderRepository(org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository) ExportScmResultWithRevision(org.apache.maven.scm.command.export.ExportScmResultWithRevision)

Example 27 with Commandline

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

the class SvnMkdirCommand method executeMkdirCommand.

/**
 * {@inheritDoc}
 */
protected MkdirScmResult executeMkdirCommand(ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean createInLocal) throws ScmException {
    File messageFile = FileUtils.createTempFile("maven-scm-", ".commit", null);
    try {
        FileUtils.fileWrite(messageFile.getAbsolutePath(), message);
    } catch (IOException ex) {
        return new MkdirScmResult(null, "Error while making a temporary file for the mkdir message: " + ex.getMessage(), null, false);
    }
    Commandline cl = createCommandLine((SvnScmProviderRepository) repository, fileSet, messageFile, createInLocal);
    SvnMkdirConsumer consumer = new SvnMkdirConsumer(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);
    } finally {
        try {
            FileUtils.forceDelete(messageFile);
        } catch (IOException ex) {
        // ignore
        }
    }
    if (exitCode != 0) {
        return new MkdirScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    if (createInLocal) {
        return new MkdirScmResult(cl.toString(), consumer.getCreatedDirs());
    } else {
        return new MkdirScmResult(cl.toString(), Integer.toString(consumer.getRevision()));
    }
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) MkdirScmResult(org.apache.maven.scm.command.mkdir.MkdirScmResult) 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) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 28 with Commandline

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

the class SvnMkdirCommand method createCommandLine.

protected static Commandline createCommandLine(SvnScmProviderRepository repository, ScmFileSet fileSet, File messageFile, boolean createInLocal) {
    if (!fileSet.getBasedir().exists() && !createInLocal) {
        fileSet.getBasedir().mkdirs();
    }
    Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine(fileSet.getBasedir(), repository);
    cl.createArg().setValue("mkdir");
    cl.createArg().setValue("--parents");
    Iterator<File> it = fileSet.getFileList().iterator();
    String dirPath = it.next().getPath();
    // replacing \ with / for windauze
    if (dirPath != null && Os.isFamily(Os.FAMILY_DOS)) {
        dirPath = StringUtils.replace(dirPath, "\\", "/");
    }
    if (!createInLocal) {
        cl.createArg().setValue(repository.getUrl() + "/" + dirPath);
        if (messageFile != null) {
            cl.createArg().setValue("--file");
            cl.createArg().setValue(messageFile.getAbsolutePath());
        }
    } else {
        cl.createArg().setValue(dirPath);
    }
    return cl;
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) File(java.io.File)

Example 29 with Commandline

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

the class SvnRemoteInfoCommand method executeRemoteInfoCommand.

@Override
public RemoteInfoScmResult executeRemoteInfoCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    String url = ((SvnScmProviderRepository) repository).getUrl();
    // use a default svn layout, url is here http://svn.apache.org/repos/asf/maven/maven-3/trunk
    // so as we presume we have good users using standard svn layout, we calculate tags and branches url
    String baseUrl = StringUtils.endsWith(url, "/") ? StringUtils.substringAfter(StringUtils.removeEnd(url, "/"), "/") : StringUtils.substringBeforeLast(url, "/");
    Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine(fileSet == null ? null : fileSet.getBasedir(), (SvnScmProviderRepository) repository);
    cl.createArg().setValue("ls");
    cl.createArg().setValue(baseUrl + "/tags");
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    LsConsumer consumer = new LsConsumer(getLogger(), baseUrl);
    int exitCode = 0;
    Map<String, String> tagsInfos = null;
    try {
        exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
        tagsInfos = consumer.infos;
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing svn command.", ex);
    }
    if (exitCode != 0) {
        return new RemoteInfoScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    cl = SvnCommandLineUtils.getBaseSvnCommandLine(fileSet == null ? null : fileSet.getBasedir(), (SvnScmProviderRepository) repository);
    cl.createArg().setValue("ls");
    cl.createArg().setValue(baseUrl + "/tags");
    stderr = new CommandLineUtils.StringStreamConsumer();
    consumer = new LsConsumer(getLogger(), baseUrl);
    Map<String, String> branchesInfos = null;
    try {
        exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
        branchesInfos = consumer.infos;
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing svn command.", ex);
    }
    if (exitCode != 0) {
        return new RemoteInfoScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    return new RemoteInfoScmResult(cl.toString(), branchesInfos, tagsInfos);
}
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) SvnScmProviderRepository(org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) RemoteInfoScmResult(org.apache.maven.scm.command.remoteinfo.RemoteInfoScmResult)

Example 30 with Commandline

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

the class SvnScmTestUtils method loadSvnDump.

private static void loadSvnDump(File repositoryRoot, InputStream dumpStream) throws Exception {
    Commandline cl = new Commandline();
    cl.setExecutable(SVNADMIN_COMMAND_LINE);
    cl.setWorkingDirectory(repositoryRoot.getParentFile().getAbsolutePath());
    cl.createArg().setValue("load");
    cl.createArg().setValue(repositoryRoot.getAbsolutePath());
    CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitValue = CommandLineUtils.executeCommandLine(cl, dumpStream, stdout, stderr);
    if (exitValue != 0) {
        System.err.println("-----------------------------------------");
        System.err.println("Command line: " + cl);
        System.err.println("Working directory: " + cl.getWorkingDirectory());
        System.err.println("-----------------------------------------");
        System.err.println("Standard output: ");
        System.err.println("-----------------------------------------");
        System.err.println(stdout.getOutput());
        System.err.println("-----------------------------------------");
        System.err.println("Standard error: ");
        System.err.println("-----------------------------------------");
        System.err.println(stderr.getOutput());
        System.err.println("-----------------------------------------");
    }
    if (exitValue != 0) {
        Assert.fail("Exit value wasn't 0, was:" + exitValue);
    }
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils)

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