Search in sources :

Example 76 with CommandLineException

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

the class SvnTagCommand method executeTagCommand.

/**
 * {@inheritDoc}
 */
public ScmResult executeTagCommand(ScmProviderRepository repo, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters) throws ScmException {
    // NPE free
    if (scmTagParameters == null) {
        getLogger().debug("SvnTagCommand :: scmTagParameters is null create an empty one");
        scmTagParameters = new ScmTagParameters();
        scmTagParameters.setRemoteTagging(false);
    } else {
        getLogger().debug("SvnTagCommand :: scmTagParameters.remoteTagging : " + scmTagParameters.isRemoteTagging());
    }
    if (tag == null || StringUtils.isEmpty(tag.trim())) {
        throw new ScmException("tag must be specified");
    }
    if (!fileSet.getFileList().isEmpty()) {
        throw new ScmException("This provider doesn't support tagging subsets of a directory");
    }
    SvnScmProviderRepository repository = (SvnScmProviderRepository) repo;
    File messageFile = FileUtils.createTempFile("maven-scm-", ".commit", null);
    try {
        FileUtils.fileWrite(messageFile.getAbsolutePath(), scmTagParameters == null ? "" : scmTagParameters.getMessage());
    } catch (IOException ex) {
        return new TagScmResult(null, "Error while making a temporary file for the commit message: " + ex.getMessage(), null, false);
    }
    Commandline cl = createCommandLine(repository, fileSet.getBasedir(), tag, messageFile, scmTagParameters);
    CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
    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, stdout, 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) {
        // TODO: Improve this error message
        return new TagScmResult(cl.toString(), "The svn tag command failed.", stderr.getOutput(), false);
    }
    List<ScmFile> fileList = new ArrayList<ScmFile>();
    List<File> files = null;
    try {
        if (StringUtils.isNotEmpty(fileSet.getExcludes())) {
            @SuppressWarnings("unchecked") List<File> list = FileUtils.getFiles(fileSet.getBasedir(), (StringUtils.isEmpty(fileSet.getIncludes()) ? "**" : fileSet.getIncludes()), fileSet.getExcludes() + ",**/.svn/**", false);
            files = list;
        } else {
            @SuppressWarnings("unchecked") List<File> list = FileUtils.getFiles(fileSet.getBasedir(), (StringUtils.isEmpty(fileSet.getIncludes()) ? "**" : fileSet.getIncludes()), "**/.svn/**", false);
            files = list;
        }
    } catch (IOException e) {
        throw new ScmException("Error while executing command.", e);
    }
    for (Iterator<File> i = files.iterator(); i.hasNext(); ) {
        File f = i.next();
        fileList.add(new ScmFile(f.getPath(), ScmFileStatus.TAGGED));
    }
    return new TagScmResult(cl.toString(), fileList);
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) ScmTagParameters(org.apache.maven.scm.ScmTagParameters) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) ScmFile(org.apache.maven.scm.ScmFile) 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) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File)

Example 77 with CommandLineException

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

the class SvnRemoteInfoCommand method remoteUrlExist.

public boolean remoteUrlExist(ScmProviderRepository repository, CommandParameters parameters) throws ScmException {
    String url = ((SvnScmProviderRepository) repository).getUrl();
    Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine(null, (SvnScmProviderRepository) repository);
    cl.createArg().setValue("ls");
    cl.createArg().setValue(url);
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    LsConsumer consumer = new LsConsumer(getLogger(), url);
    int exitCode = 0;
    try {
        exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing svn command.", ex);
    }
    if (exitCode != 0) {
        String output = stderr.getOutput();
        // trying to parse error from svn cli which indicate no remote path
        if (output.indexOf("W160013") >= 0 || output.indexOf("svn: URL") >= 0) {
            return false;
        }
        throw new ScmException(cl.toString() + ".The svn command failed:" + stderr.getOutput());
    }
    return true;
}
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)

Example 78 with CommandLineException

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

the class SvnUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
    Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet.getBasedir(), version);
    SvnUpdateConsumer consumer = new SvnUpdateConsumer(getLogger(), fileSet.getBasedir());
    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 UpdateScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    UpdateScmResultWithRevision result = new UpdateScmResultWithRevision(cl.toString(), consumer.getUpdatedFiles(), String.valueOf(consumer.getRevision()));
    result.setChanges(consumer.getChangeSets());
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("changeSets " + consumer.getChangeSets());
    }
    return result;
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) UpdateScmResultWithRevision(org.apache.maven.scm.command.update.UpdateScmResultWithRevision) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 79 with CommandLineException

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

the class SvnScmTestUtils method getScmUrl.

public static String getScmUrl(File repositoryRootFile) throws CommandLineException {
    String repositoryRoot = repositoryRootFile.getAbsolutePath();
    // TODO: some way without a custom cygwin sys property?
    if ("true".equals(System.getProperty("cygwin"))) {
        Commandline cl = new Commandline();
        cl.setExecutable("cygpath");
        cl.createArg().setValue("--unix");
        cl.createArg().setValue(repositoryRoot);
        CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
        int exitValue = CommandLineUtils.executeCommandLine(cl, stdout, null);
        if (exitValue != 0) {
            throw new CommandLineException("Unable to convert cygwin path, exit code = " + exitValue);
        }
        repositoryRoot = stdout.getOutput().trim();
    } else if (Os.isFamily("windows")) {
        repositoryRoot = "/" + StringUtils.replace(repositoryRoot, "\\", "/");
    }
    return "scm:svn:file://" + repositoryRoot;
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 80 with CommandLineException

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

the class AccuRevCommandLine method executeCommandLine.

private int executeCommandLine(InputStream stdin, StreamConsumer stdout) throws AccuRevException {
    commandLines.append(cl.toString());
    commandLines.append(';');
    if (getLogger().isDebugEnabled()) {
        getLogger().debug(cl.toString());
    }
    try {
        int result = executeCommandLine(cl, stdin, new CommandOutputConsumer(getLogger(), stdout), systemErr);
        if (result != 0) {
            getLogger().debug("Non zero result - " + result);
        }
        return result;
    } catch (CommandLineException ex) {
        throw new AccuRevException("Error executing command " + cl.toString(), ex);
    }
}
Also used : AccuRevException(org.apache.maven.scm.provider.accurev.AccuRevException) 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