Search in sources :

Example 6 with CommandLineException

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

the class SvnBlameCommand method executeBlameCommand.

/**
 * {@inheritDoc}
 */
public BlameScmResult executeBlameCommand(ScmProviderRepository repo, ScmFileSet workingDirectory, String filename) throws ScmException {
    Commandline cl = createCommandLine((SvnScmProviderRepository) repo, workingDirectory.getBasedir(), filename);
    SvnBlameConsumer consumer = new SvnBlameConsumer(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);
    }
    if (exitCode != 0) {
        return new BlameScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    return new BlameScmResult(cl.toString(), consumer.getLines());
}
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) BlameScmResult(org.apache.maven.scm.command.blame.BlameScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 7 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException 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 8 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException 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 9 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException 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 10 with CommandLineException

use of org.codehaus.plexus.util.cli.CommandLineException 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)

Aggregations

CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)94 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)76 Commandline (org.codehaus.plexus.util.cli.Commandline)67 ScmException (org.apache.maven.scm.ScmException)56 IOException (java.io.IOException)20 SvnCommandLineUtils (org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils)18 File (java.io.File)14 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)13 BufferedReader (java.io.BufferedReader)6 BlameScmResult (org.apache.maven.scm.command.blame.BlameScmResult)6 StatusScmResult (org.apache.maven.scm.command.status.StatusScmResult)6 SvnScmProviderRepository (org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository)6 InputStreamReader (java.io.InputStreamReader)5 ChangeLogScmResult (org.apache.maven.scm.command.changelog.ChangeLogScmResult)5 ChangeLogSet (org.apache.maven.scm.command.changelog.ChangeLogSet)5 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)5 StreamConsumer (org.codehaus.plexus.util.cli.StreamConsumer)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 StringTokenizer (java.util.StringTokenizer)4 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)4