org.codehaus.plexus.util.cli.CommandLineException Java Examples

The following examples show how to use org.codehaus.plexus.util.cli.CommandLineException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractGitFlowMojo.java    From gitflow-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Executes git for-each-ref with <code>refname:short</code> format.
 * 
 * @param refs
 *            Refs to search.
 * @param branchName
 *            Branch name to find.
 * @param firstMatch
 *            Return first match.
 * @return Branch names which matches <code>{refs}{branchName}*</code>.
 * @throws MojoFailureException
 * @throws CommandLineException
 */
private String gitFindBranches(final String refs, final String branchName,
        final boolean firstMatch) throws MojoFailureException,
        CommandLineException {
    String wildcard = "*";
    if (branchName.endsWith("/")) {
        wildcard = "**";
    }

    String branches;
    if (firstMatch) {
        branches = executeGitCommandReturn("for-each-ref", "--count=1",
                "--format=\"%(refname:short)\"", refs + branchName + wildcard);
    } else {
        branches = executeGitCommandReturn("for-each-ref",
                "--format=\"%(refname:short)\"", refs + branchName + wildcard);
    }

    // on *nix systems return values from git for-each-ref are wrapped in
    // quotes
    // https://github.com/aleksandr-m/gitflow-maven-plugin/issues/3
    branches = removeQuotes(branches);
    branches = StringUtils.strip(branches);

    return branches;
}
 
Example #2
Source File: AbstractGitFlowMojo.java    From gitflow-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Executes git commit -a -m, replacing <code>@{map.key}</code> with
 * <code>map.value</code>.
 * 
 * @param message
 *            Commit message.
 * @param messageProperties
 *            Properties to replace in message.
 * @throws MojoFailureException
 * @throws CommandLineException
 */
protected void gitCommit(String message, Map<String, String> messageProperties)
        throws MojoFailureException, CommandLineException {
    if (StringUtils.isNotBlank(commitMessagePrefix)) {
        message = commitMessagePrefix + message;
    }

    message = replaceProperties(message, messageProperties);

    if (gpgSignCommit) {
        getLog().info("Committing changes. GPG-signed.");

        executeGitCommand("commit", "-a", "-S", "-m", message);
    } else {
        getLog().info("Committing changes.");

        executeGitCommand("commit", "-a", "-m", message);
    }
}
 
Example #3
Source File: DocumentationIntegrationTest.java    From depgraph-maven-plugin with Apache License 2.0 6 votes vote down vote up
private static String getDotExecutable() {
  Commandline cmd = new Commandline();
  String finderExecutable = isWindows() ? "where.exe" : "which";

  cmd.setExecutable(finderExecutable);
  cmd.addArguments(new String[]{"dot"});

  CommandLineUtils.StringStreamConsumer systemOut = new CommandLineUtils.StringStreamConsumer();
  CommandLineUtils.StringStreamConsumer systemErr = new CommandLineUtils.StringStreamConsumer();

  try {
    int exitCode = CommandLineUtils.executeCommandLine(cmd, systemOut, systemErr);
    if (exitCode != 0) {
      return null;
    }
  } catch (CommandLineException e) {
    return null;
  }

  return systemOut.getOutput();
}
 
Example #4
Source File: AbstractGitFlowMojo.java    From gitflow-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Executes git config commands to set Git Flow configuration.
 * 
 * @throws MojoFailureException
 * @throws CommandLineException
 */
protected void initGitFlowConfig() throws MojoFailureException,
        CommandLineException {
    gitSetConfig("gitflow.branch.master",
            gitFlowConfig.getProductionBranch());
    gitSetConfig("gitflow.branch.develop",
            gitFlowConfig.getDevelopmentBranch());

    gitSetConfig("gitflow.prefix.feature",
            gitFlowConfig.getFeatureBranchPrefix());
    gitSetConfig("gitflow.prefix.release",
            gitFlowConfig.getReleaseBranchPrefix());
    gitSetConfig("gitflow.prefix.hotfix",
            gitFlowConfig.getHotfixBranchPrefix());
    gitSetConfig("gitflow.prefix.support",
            gitFlowConfig.getSupportBranchPrefix());
    gitSetConfig("gitflow.prefix.versiontag",
            gitFlowConfig.getVersionTagPrefix());

    gitSetConfig("gitflow.origin", gitFlowConfig.getOrigin());
}
 
Example #5
Source File: BuildNumberMojoTest.java    From buildnumber-maven-plugin with MIT License 6 votes vote down vote up
private static boolean isSvn18()
{
    Commandline cl = new Commandline();
    cl.setExecutable( "svn" );
    cl.createArg().setValue( "--version" );

    StringStreamConsumer stdout = new StringStreamConsumer();
    StringStreamConsumer stderr = new StringStreamConsumer();

    try
    {
        CommandLineUtils.executeCommandLine( cl, stdout, stderr );
        Matcher versionMatcher = SVN_VERSION_PATTERN.matcher( stdout.getOutput() );
        return versionMatcher.find() && ( Integer.parseInt( versionMatcher.group( 1 ) ) > 1
            || Integer.parseInt( versionMatcher.group( 2 ) ) >= 8 );
    }
    catch ( CommandLineException e )
    {
    }

    return false;
}
 
Example #6
Source File: AbstractGitFlowMojo.java    From gitflow-maven-plugin with Apache License 2.0 6 votes vote down vote up
protected void gitPushDelete(final String branchName)
        throws MojoFailureException, CommandLineException {
    getLog().info(
            "Deleting remote branch '" + branchName + "' from '"
                    + gitFlowConfig.getOrigin() + "'.");

    CommandResult result = executeGitCommandExitCode("push", "--delete",
            gitFlowConfig.getOrigin(), branchName);

    if (result.getExitCode() != SUCCESS_EXIT_CODE) {
        getLog().warn(
                "There were some problems deleting remote branch '"
                        + branchName + "' from '"
                        + gitFlowConfig.getOrigin() + "'.");
    }
}
 
Example #7
Source File: CommandLineUtil.java    From maven-native with MIT License 6 votes vote down vote up
public static void execute( Commandline cl, Logger logger )
    throws NativeBuildException
{
    int ok;

    try
    {
        DefaultConsumer stdout = new DefaultConsumer();

        DefaultConsumer stderr = stdout;

        logger.info( cl.toString() );

        ok = CommandLineUtils.executeCommandLine( cl, stdout, stderr );
    }
    catch ( CommandLineException ecx )
    {
        throw new NativeBuildException( "Error executing command line", ecx );
    }

    if ( ok != 0 )
    {
        throw new NativeBuildException( "Error executing command line. Exit code:" + ok );
    }
}
 
Example #8
Source File: AbstractGitFlowMojo.java    From gitflow-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Executes git fetch with specific branch.
 * 
 * @param branchName
 *            Branch name to fetch.
 * @return <code>true</code> if git fetch returned success exit code,
 *         <code>false</code> otherwise.
 * @throws MojoFailureException
 * @throws CommandLineException
 */
private boolean gitFetchRemote(final String branchName)
        throws MojoFailureException, CommandLineException {
    getLog().info(
            "Fetching remote branch '" + gitFlowConfig.getOrigin() + " "
                    + branchName + "'.");

    CommandResult result = executeGitCommandExitCode("fetch", "--quiet",
            gitFlowConfig.getOrigin(), branchName);

    boolean success = result.getExitCode() == SUCCESS_EXIT_CODE;
    if (!success) {
        getLog().warn(
                "There were some problems fetching remote branch '"
                        + gitFlowConfig.getOrigin()
                        + " "
                        + branchName
                        + "'. You can turn off remote branch fetching by setting the 'fetchRemote' parameter to false.");
    }

    return success;
}
 
Example #9
Source File: AbstractGitFlowMojo.java    From gitflow-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Executes git fetch and compares local branch with the remote.
 * 
 * @param branchName
 *            Branch name to fetch and compare.
 * @throws MojoFailureException
 * @throws CommandLineException
 */
protected void gitFetchRemoteAndCompare(final String branchName)
        throws MojoFailureException, CommandLineException {
    if (gitFetchRemote(branchName)) {
        getLog().info(
                "Comparing local branch '" + branchName + "' with remote '"
                        + gitFlowConfig.getOrigin() + "/" + branchName
                        + "'.");
        String revlistout = executeGitCommandReturn("rev-list",
                "--left-right", "--count", branchName + "..."
                        + gitFlowConfig.getOrigin() + "/" + branchName);

        String[] counts = org.apache.commons.lang3.StringUtils.split(
                revlistout, '\t');
        if (counts != null && counts.length > 1) {
            if (!"0".equals(org.apache.commons.lang3.StringUtils
                    .deleteWhitespace(counts[1]))) {
                throw new MojoFailureException("Remote branch '"
                        + gitFlowConfig.getOrigin() + "/" + branchName
                        + "' is ahead of the local branch '" + branchName
                        + "'. Execute git pull.");
            }
        }
    }
}
 
Example #10
Source File: AbstractCommunityEnvFactory.java    From maven-native with MIT License 6 votes vote down vote up
protected Map<String, String> executeCommandLine(Commandline command) throws NativeBuildException
{
    EnvStreamConsumer stdout = new EnvStreamConsumer();
    StreamConsumer stderr = new DefaultConsumer();

    try
    {
        CommandLineUtils.executeCommandLine( command, stdout, stderr );
    }
    catch ( CommandLineException e )
    {
        throw new NativeBuildException( "Failed to execute vcvarsall.bat" );
    }

    return stdout.getParsedEnv();
}
 
Example #11
Source File: BuildProject.java    From unleash-maven-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void execute(ExecutionContext context) throws MojoExecutionException, MojoFailureException {
  this.log.info("Starting release build.");

  try {
    InvocationRequest request = setupInvocationRequest();
    Invoker invoker = setupInvoker();

    InvocationResult result = invoker.execute(request);
    if (result.getExitCode() != 0) {
      CommandLineException executionException = result.getExecutionException();
      if (executionException != null) {
        throw new MojoFailureException("Error during project build: " + executionException.getMessage(),
            executionException);
      } else {
        throw new MojoFailureException("Error during project build: " + result.getExitCode());
      }
    }
  } catch (MavenInvocationException e) {
    throw new MojoFailureException(e.getMessage(), e);
  }
}
 
Example #12
Source File: AbstractGitFlowMojo.java    From gitflow-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Checks uncommitted changes.
 * 
 * @throws MojoFailureException
 * @throws CommandLineException
 */
protected void checkUncommittedChanges() throws MojoFailureException,
        CommandLineException {
    getLog().info("Checking for uncommitted changes.");
    if (executeGitHasUncommitted()) {
        throw new MojoFailureException(
                "You have some uncommitted files. Commit or discard local changes in order to proceed.");
    }
}
 
Example #13
Source File: AbstractGitFlowMojo.java    From gitflow-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Executes git commands to check for uncommitted changes.
 * 
 * @return <code>true</code> when there are uncommitted changes,
 *         <code>false</code> otherwise.
 * @throws CommandLineException
 * @throws MojoFailureException
 */
private boolean executeGitHasUncommitted() throws MojoFailureException,
        CommandLineException {
    boolean uncommited = false;

    // 1 if there were differences and 0 means no differences

    // git diff --no-ext-diff --ignore-submodules --quiet --exit-code
    final CommandResult diffCommandResult = executeGitCommandExitCode(
            "diff", "--no-ext-diff", "--ignore-submodules", "--quiet",
            "--exit-code");

    String error = null;

    if (diffCommandResult.getExitCode() == SUCCESS_EXIT_CODE) {
        // git diff-index --cached --quiet --ignore-submodules HEAD --
        final CommandResult diffIndexCommandResult = executeGitCommandExitCode(
                "diff-index", "--cached", "--quiet", "--ignore-submodules",
                "HEAD", "--");
        if (diffIndexCommandResult.getExitCode() != SUCCESS_EXIT_CODE) {
            error = diffIndexCommandResult.getError();
            uncommited = true;
        }
    } else {
        error = diffCommandResult.getError();
        uncommited = true;
    }

    if (StringUtils.isNotBlank(error)) {
        throw new MojoFailureException(error);
    }

    return uncommited;
}
 
Example #14
Source File: CreateApplicationBundleMojo.java    From appbundle-maven-plugin with Apache License 2.0 5 votes vote down vote up
private void createApplicationsSymlink() throws MojoExecutionException, CommandLineException {
    Commandline symlink = new Commandline();
    symlink.setExecutable("ln");
    symlink.createArgument().setValue("-s");
    symlink.createArgument().setValue("/Applications");
    symlink.createArgument().setValue(buildDirectory.getAbsolutePath());
    try {
        symlink.execute().waitFor();
    } catch (InterruptedException ex) {
        throw new MojoExecutionException("Error preparing bundle disk image while creating symlink" + diskImageFile, ex);
    }
}
 
Example #15
Source File: MavenProcessInvocationResult.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
public MavenProcessInvocationResult setException(CommandLineException exception) {
    // Print the stack trace immediately to give some feedback early
    // In intellij, the used `mvn` executable is not "executable" by default on Mac and probably linux.
    // You need to chmod +x the file.
    exception.printStackTrace();
    this.exception = exception;
    return this;
}
 
Example #16
Source File: CreateApplicationBundleMojo.java    From appbundle-maven-plugin with Apache License 2.0 5 votes vote down vote up
private void removeApplicationsSymlink() throws MojoExecutionException, CommandLineException {
    Commandline remSymlink = new Commandline();
    String symlink = buildDirectory.getAbsolutePath() + "/Applications";
    if (!new File(symlink).exists()) {
        return;
    }
    remSymlink.setExecutable("rm");
    remSymlink.createArgument().setValue(symlink);
    try {
        remSymlink.execute().waitFor();
    } catch (InterruptedException ex) {
        throw new MojoExecutionException("Error cleaning up (while removing " + symlink +
                " symlink.) Please check permissions for that symlink" + diskImageFile, ex);
    }
}
 
Example #17
Source File: MavenProcessInvoker.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private static Process executeCommandLine(Commandline cl, StreamConsumer systemOut, StreamConsumer systemErr)
    throws CommandLineException {
    if (cl == null) {
        throw new IllegalArgumentException("the command line cannot be null.");
    } else {
        final Process p = cl.execute();
        final StreamPumper outputPumper = new StreamPumper(p.getInputStream(), systemOut);
        final StreamPumper errorPumper = new StreamPumper(p.getErrorStream(), systemErr);

        outputPumper.start();
        errorPumper.start();

        new Thread(() -> {
            try {
                // Wait for termination
                p.waitFor();
                outputPumper.waitUntilDone();
                errorPumper.waitUntilDone();
            } catch (Exception e) {
                outputPumper.disable();
                errorPumper.disable();
                e.printStackTrace();
            } finally {
                outputPumper.close();
                errorPumper.close();
            }
        }).start();

        return p;
    }
}
 
Example #18
Source File: ArchetypeTest.java    From ipaas-quickstarts with Apache License 2.0 5 votes vote down vote up
protected static int invokeMaven(String[] args, String outDir, File logFile) {
    List<String> goals = Arrays.asList(args);
    String commandLine = Strings.join(goals, " ");

    InvocationResult result = null;
    try {
        File dir = new File(outDir);

        InvocationRequest request = new DefaultInvocationRequest();
        request.setGoals(goals);

        InvocationOutputHandler outputHandler = new SystemOutAndFileHandler(logFile);
        outputHandler.consumeLine("");
        outputHandler.consumeLine("");
        outputHandler.consumeLine(dir.getName() + " : starting: mvn " + commandLine);
        outputHandler.consumeLine("");
        request.setOutputHandler(outputHandler);
        request.setErrorHandler(outputHandler);

        DefaultInvoker invoker = new DefaultInvoker();
        request.setPomFile(new File(dir, "pom.xml"));
        result = invoker.execute(request);
        CommandLineException executionException = result.getExecutionException();
        if (executionException != null) {
            LOG.error("Failed to invoke maven with: mvn " + commandLine + ". " + executionException, executionException);
        }
    } catch (Exception e) {
        LOG.error("Failed to invoke maven with: mvn " + commandLine + ". " + e, e);
    }
    return result == null ? 1 : result.getExitCode();
}
 
Example #19
Source File: RegQuery.java    From maven-native with MIT License 5 votes vote down vote up
public static String getValue( String valueType, String folderName, String folderKey )
    throws NativeBuildException
{
    Commandline cl = new Commandline();
    cl.setExecutable( "reg" );
    cl.createArg().setValue( "query" );
    cl.createArg().setValue( folderName );
    cl.createArg().setValue( "/v" );
    cl.createArg().setValue( folderKey );

    CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();

    try
    {
        int ok = CommandLineUtils.executeCommandLine( cl, stdout, stderr );

        if ( ok != 0 )
        {
            return null;
        }
    }
    catch ( CommandLineException e )
    {
        throw new NativeBuildException( e.getMessage(), e );
    }

    String result = stdout.getOutput();

    int p = result.indexOf( valueType );

    if ( p == -1 )
    {
        return null;
    }

    return result.substring( p + valueType.length() ).trim();
}
 
Example #20
Source File: AbstractGitFlowMojo.java    From gitflow-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Executes git for-each-ref to get all tags.
 *
 * @return Git tags.
 * @throws MojoFailureException
 * @throws CommandLineException
 */
protected String gitFindTags() throws MojoFailureException, CommandLineException {
    String tags = executeGitCommandReturn("for-each-ref", "--sort=*authordate", "--format=\"%(refname:short)\"",
            "refs/tags/");
    // https://github.com/aleksandr-m/gitflow-maven-plugin/issues/3
    tags = removeQuotes(tags);
    return tags;
}
 
Example #21
Source File: AbstractGitFlowMojo.java    From gitflow-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Executes git for-each-ref to get the last tag.
 *
 * @return Last tag.
 * @throws MojoFailureException
 * @throws CommandLineException
 */
protected String gitFindLastTag() throws MojoFailureException, CommandLineException {
    String tag = executeGitCommandReturn("for-each-ref", "--sort=-*authordate", "--count=1",
            "--format=\"%(refname:short)\"", "refs/tags/");
    // https://github.com/aleksandr-m/gitflow-maven-plugin/issues/3
    tag = removeQuotes(tag);
    tag = tag.replaceAll("\\r?\\n", "");
    return tag;
}
 
Example #22
Source File: AbstractGitFlowMojo.java    From gitflow-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Executes git rebase or git merge --ff-only or git merge --no-ff or git merge.
 * 
 * @param branchName
 *            Branch name to merge.
 * @param rebase
 *            Do rebase.
 * @param noff
 *            Merge with --no-ff.
 * @param ffonly
 *            Merge with --ff-only.
 * @param message
 *            Merge commit message.
 * @param messageProperties
 *            Properties to replace in message.
 * @throws MojoFailureException
 * @throws CommandLineException
 */
protected void gitMerge(final String branchName, boolean rebase, boolean noff, boolean ffonly, String message,
        Map<String, String> messageProperties)
        throws MojoFailureException, CommandLineException {
    String sign = "";
    if (gpgSignCommit) {
        sign = "-S";
    }
    String msgParam = "";
    String msg = "";
    if (StringUtils.isNotBlank(message)) {
        if (StringUtils.isNotBlank(commitMessagePrefix)) {
            message = commitMessagePrefix + message;
        }

        msgParam = "-m";
        msg = replaceProperties(message, messageProperties);
    }
    if (rebase) {
        getLog().info("Rebasing '" + branchName + "' branch.");
        executeGitCommand("rebase", sign, branchName);
    } else if (ffonly) {
        getLog().info("Merging (--ff-only) '" + branchName + "' branch.");
        executeGitCommand("merge", "--ff-only", sign, branchName);
    } else if (noff) {
        getLog().info("Merging (--no-ff) '" + branchName + "' branch.");
        executeGitCommand("merge", "--no-ff", sign, branchName, msgParam, msg);
    } else {
        getLog().info("Merging '" + branchName + "' branch.");
        executeGitCommand("merge", sign, branchName, msgParam, msg);
    }
}
 
Example #23
Source File: AbstractGitFlowMojo.java    From gitflow-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Executes git tag -a [-s] -m.
 * 
 * @param tagName
 *            Name of the tag.
 * @param message
 *            Tag message.
 * @param gpgSignTag
 *            Make a GPG-signed tag.
 * @param messageProperties
 *            Properties to replace in message.
 * @throws MojoFailureException
 * @throws CommandLineException
 */
protected void gitTag(final String tagName, String message, boolean gpgSignTag, Map<String, String> messageProperties)
        throws MojoFailureException, CommandLineException {
    message = replaceProperties(message, messageProperties);

    if (gpgSignTag) {
        getLog().info("Creating GPG-signed '" + tagName + "' tag.");

        executeGitCommand("tag", "-a", "-s", tagName, "-m", message);
    } else {
        getLog().info("Creating '" + tagName + "' tag.");

        executeGitCommand("tag", "-a", tagName, "-m", message);
    }
}
 
Example #24
Source File: AbstractGitFlowMojo.java    From gitflow-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Fetches and checkouts from remote if local branch doesn't exist.
 * 
 * @param branchName
 *            Branch name to check.
 * @throws MojoFailureException
 * @throws CommandLineException
 */
protected void gitFetchRemoteAndCreate(final String branchName)
        throws MojoFailureException, CommandLineException {
    if (!gitCheckBranchExists(branchName)) {
        getLog().info(
                "Local branch '"
                        + branchName
                        + "' doesn't exist. Trying to fetch and check it out from '"
                        + gitFlowConfig.getOrigin() + "'.");
        gitFetchRemote(branchName);
        gitCreateAndCheckout(branchName, gitFlowConfig.getOrigin() + "/"
                + branchName);
    }
}
 
Example #25
Source File: AbstractGitFlowMojo.java    From gitflow-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Executes git push, optionally with the <code>--follow-tags</code>
 * argument.
 * 
 * @param branchName
 *            Branch name to push.
 * @param pushTags
 *            If <code>true</code> adds <code>--follow-tags</code> argument
 *            to the git <code>push</code> command.
 * @throws MojoFailureException
 * @throws CommandLineException
 */
protected void gitPush(final String branchName, boolean pushTags)
        throws MojoFailureException, CommandLineException {
    getLog().info(
            "Pushing '" + branchName + "' branch" + " to '"
                    + gitFlowConfig.getOrigin() + "'.");

    if (pushTags) {
        executeGitCommand("push", "--quiet", "-u", "--follow-tags",
                gitFlowConfig.getOrigin(), branchName);
    } else {
        executeGitCommand("push", "--quiet", "-u",
                gitFlowConfig.getOrigin(), branchName);
    }
}
 
Example #26
Source File: AbstractGitFlowMojo.java    From gitflow-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Executes 'set' goal of versions-maven-plugin or 'set-version' of
 * tycho-versions-plugin in case it is tycho build.
 * 
 * @param version
 *            New version to set.
 * @throws MojoFailureException
 * @throws CommandLineException
 */
protected void mvnSetVersions(final String version) throws MojoFailureException, CommandLineException {
    getLog().info("Updating version(s) to '" + version + "'.");

    String newVersion = "-DnewVersion=" + version;
    String g = "";
    String a = "";
    if (versionsForceUpdate) {
        g = "-DgroupId=";
        a = "-DartifactId=";
    }

    if (tychoBuild) {
        String prop = "";
        if (StringUtils.isNotBlank(versionProperty)) {
            prop = "-Dproperties=" + versionProperty;
            getLog().info("Updating property '" + versionProperty + "' to '" + version + "'.");
        }

        executeMvnCommand(TYCHO_VERSIONS_PLUGIN_SET_GOAL, prop, newVersion, "-Dtycho.mode=maven");
    } else {
        if (!skipUpdateVersion) {
            executeMvnCommand(VERSIONS_MAVEN_PLUGIN_SET_GOAL, g, a, newVersion, "-DgenerateBackupPoms=false");
        }

        if (StringUtils.isNotBlank(versionProperty)) {
            getLog().info("Updating property '" + versionProperty + "' to '" + version + "'.");

            executeMvnCommand(VERSIONS_MAVEN_PLUGIN_SET_PROPERTY_GOAL, newVersion, "-Dproperty=" + versionProperty,
                    "-DgenerateBackupPoms=false");
        }
    }
}
 
Example #27
Source File: AbstractGitFlowMojo.java    From gitflow-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Executes mvn clean test.
 * 
 * @throws MojoFailureException
 * @throws CommandLineException
 */
protected void mvnCleanTest() throws MojoFailureException,
        CommandLineException {
    getLog().info("Cleaning and testing the project.");
    if (tychoBuild) {
        executeMvnCommand("clean", "verify");
    } else {
        executeMvnCommand("clean", "test");
    }
}
 
Example #28
Source File: AbstractGitFlowMojo.java    From gitflow-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Executes mvn clean install.
 * 
 * @throws MojoFailureException
 * @throws CommandLineException
 */
protected void mvnCleanInstall() throws MojoFailureException,
        CommandLineException {
    getLog().info("Cleaning and installing the project.");

    executeMvnCommand("clean", "install");
}
 
Example #29
Source File: MavenCommandLineMojo.java    From dependency-mediator with Apache License 2.0 5 votes vote down vote up
public void copyDependenciesTest(File dependencyFolder) throws MojoFailureException,
        MojoExecutionException {
    getLog().info("Start to copy dependencies");
    Commandline cl = new Commandline();
    cl.setExecutable("mvn");
    cl.createArg().setValue("clean");
    cl.createArg().setValue("dependency:copy-dependencies");
    cl.createArg().setValue("-DoutputDirectory=" + dependencyFolder.getAbsolutePath());
    cl.createArg().setValue("-Dsilent=true");
    String excludedArtifactIds = this.getTestDependencyArtifactIds();
    if (!excludedArtifactIds.isEmpty()) {
        cl.createArg().setValue("-DexcludeArtifactIds=" + excludedArtifactIds);
        getLog().info("====Excluded artifact ids: " + excludedArtifactIds);
    } else {
        getLog().info("====No excluded artifact ids");
    }
    WriterStreamConsumer systemOut = new WriterStreamConsumer(
            new OutputStreamWriter(System.out));
    int result = -1;
    try {
        result = CommandLineUtils.executeCommandLine(cl, systemOut, systemOut);
    } catch (CommandLineException e) {
        String message = "Failed to execute command: " + cl.toString();
        throw new MojoFailureException(message);
    }
    if (result != 0) {
        getLog().error("Failed to copy dependencies");
        System.exit(result);
    }
}
 
Example #30
Source File: Git.java    From opoopress with Apache License 2.0 5 votes vote down vote up
private boolean execute(String command, String... args) throws GitException {
	Commandline cl = new Commandline();
	cl.setExecutable("git");
	cl.createArg().setValue(command);
	cl.setWorkingDirectory(workingDirectory.getAbsolutePath());
	
	//args
	for (int i = 0; i < args.length; i++){
		cl.createArg().setValue(args[i]);
	}
	
	if (log.isInfoEnabled()) {
		log.info("[" + cl.getWorkingDirectory().getAbsolutePath() + "] Executing: " + cl);
	}
	
	int exitCode;
	try {
		exitCode = CommandLineUtils.executeCommandLine(cl, stdout, stderr);
	} catch (CommandLineException e) {
		throw new GitException("Error while executing command.", e);
	}

	if(log.isDebugEnabled()){
		log.debug("Run: " + cl + " / $? = " + exitCode);
	}
	
	return exitCode == 0;
}