Java Code Examples for org.apache.maven.shared.invoker.InvocationRequest#setShowErrors()

The following examples show how to use org.apache.maven.shared.invoker.InvocationRequest#setShowErrors() . 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: CreateProjectMojoIT.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private InvocationResult setup(Properties params)
        throws MavenInvocationException, FileNotFoundException, UnsupportedEncodingException {

    params.setProperty("platformGroupId", ToolsConstants.IO_QUARKUS);
    params.setProperty("platformArtifactId", "quarkus-bom");
    params.setProperty("platformVersion", getPluginVersion());

    InvocationRequest request = new DefaultInvocationRequest();
    request.setBatchMode(true);
    request.setGoals(Collections.singletonList(
            getPluginGroupId() + ":" + getPluginArtifactId() + ":" + getPluginVersion() + ":create"));
    request.setDebug(false);
    request.setShowErrors(false);
    request.setProperties(params);
    getEnv().forEach(request::addShellEnvironment);
    File log = new File(testDir, "build-create-" + testDir.getName() + ".log");
    PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(log), false, "UTF-8"),
            InvokerLogger.DEBUG);
    invoker.setLogger(logger);
    return invoker.execute(request);
}
 
Example 2
Source File: RunnableMavenInvoker.java    From repairnator with MIT License 5 votes vote down vote up
@Override
public void run() {
    InvocationRequest request = new DefaultInvocationRequest();
    request.setPomFile(new File(this.mavenHelper.getPomFile()));
    request.setGoals(Arrays.asList(this.mavenHelper.getGoal()));
    Properties props = this.mavenHelper.getProperties();
    if (System.getenv("M2_HOME") == null) {
        // sensible value
        // https://stackoverflow.com/questions/14793015/programmatically-launch-m2e-maven-command
        String mavenHome = RepairnatorConfig.getInstance().getMavenHome();
        System.out.println("M2_HOME not found, using provided input value instead - " + mavenHome);
        System.setProperty("maven.home", mavenHome);
    } else if ( System.getProperty("maven.home") == null ) {
        System.setProperty("maven.home", System.getenv("M2_HOME"));
    }
    request.setProperties(props);
    request.setBatchMode(true);
    request.setShowErrors(true);

    Invoker invoker = new DefaultInvoker();

    if (this.mavenHelper.getErrorHandler() != null) {
        invoker.setErrorHandler(this.mavenHelper.getErrorHandler());
    }
    invoker.setOutputHandler(this.mavenHelper.getOutputHandler());

    try {
        InvocationResult result = invoker.execute(request);
        this.exitCode = result.getExitCode();
    } catch (MavenInvocationException e) {
        this.logger.error("Error while executing goal " + this.mavenHelper.getGoal()
                + " on the following pom file: " + this.mavenHelper.getPomFile()
                + ". Properties: " + this.mavenHelper.getProperties());
        this.logger.error(e.getMessage());
        this.mavenHelper.getInspector().getJobStatus().addStepError(this.mavenHelper.getName(), e.getMessage());
        this.exitCode = MavenHelper.MAVEN_ERROR;
    }
}
 
Example 3
Source File: BuildProject.java    From unleash-maven-plugin with Eclipse Public License 1.0 4 votes vote down vote up
private InvocationRequest setupInvocationRequest() throws MojoExecutionException {
  InvocationRequest request = new DefaultInvocationRequest();
  request.setPomFile(this.project.getFile());
  // installation and deployment are performed in a later step. We first need to ensure that there are no changes in
  // the scm, ...
  request.setGoals(this.goals);

  if (this.releaseArgs.containsKey("-X") || this.releaseArgs.containsKey("--debug")) {
    this.releaseArgs.remove("-X");
    this.releaseArgs.remove("--debug");
    request.setDebug(true);
  }

  if (this.releaseArgs.containsKey("-e") || this.releaseArgs.containsKey("--errors")) {
    this.releaseArgs.remove("-e");
    this.releaseArgs.remove("--errors");
    request.setShowErrors(true);
  }

  request.setProperties(this.releaseArgs);
  request.setProfiles(this.profiles);
  request.setShellEnvironmentInherited(true);
  for (String key : this.releaseEnvironmentVariables.keySet()) {
    request.addShellEnvironment(key, this.releaseEnvironmentVariables.get(key));
  }
  request.addShellEnvironment("isUnleashBuild", "true");
  request.setOffline(this.settings.isOffline());
  request.setInteractive(this.settings.isInteractiveMode());

  MavenExecutionRequest originalRequest = this.session.getRequest();
  File globalSettingsFile = originalRequest.getGlobalSettingsFile();
  if (globalSettingsFile != null && globalSettingsFile.exists() && globalSettingsFile.isFile()) {
    request.setGlobalSettingsFile(globalSettingsFile);
  }
  File userSettingsFile = originalRequest.getUserSettingsFile();
  if (userSettingsFile != null && userSettingsFile.exists() && userSettingsFile.isFile()) {
    request.setUserSettingsFile(userSettingsFile);
  }
  File toolchainsFile = originalRequest.getUserToolchainsFile();
  if (toolchainsFile.exists() && toolchainsFile.isFile()) {
    request.setToolchainsFile(toolchainsFile);
  }
  return request;
}
 
Example 4
Source File: AbstractInvokerMojo.java    From iterator-maven-plugin with Apache License 2.0 4 votes vote down vote up
protected InvocationRequest createAndConfigureAnInvocationRequest( ItemWithProperties currentValue )
    {
        InvocationRequest request = new DefaultInvocationRequest();

        request.setAlsoMake( isAlsoMake() );
        request.setAlsoMakeDependents( isAlsoMakeDependents() );
        request.setDebug( isDebug() );
        request.setFailureBehavior( getFailureBehaviour() );
        request.setGlobalChecksumPolicy( getGlobalChecksumPolicy() );
        request.setGlobalSettingsFile( getGlobalSettingsFile() );
        request.setInteractive( isInteractive() );

        request.setLocalRepositoryDirectory( getLocalRepositoryDirectory() );
        request.setMavenOpts( getMavenOpts() );
        request.setNonPluginUpdates( isNonPluginUpdates() );
        request.setOffline( isOffline() );

//        request.setProperties( properties )
//        ;
        // @TODO: Think about it.
        // request.setPomFile(pomFile);
        // @TODO: Think about it.
        // request.setPomFileName(pomFilename);

        // The following parameter do make sense to use a placeholder
        // base directory
        // cd @item@
        // mvn clean package
        request.setBaseDirectory( getBaseDirectoryAfterPlaceHolderIsReplaced( currentValue.getName() ) );
        // goals:
        // mvn plugin-name:@item@
        //
        request.setGoals( getGoalsAfterPlaceHolderIsReplaced( currentValue.getName() ) );
        // Profiles:
        // mvn -Pxyz-@item@ clean package
        // mvn -P@item@
        request.setProfiles( getProfilesAfterPlaceHolderIsReplaced( currentValue.getName() ) );
        // Projects:
        // mvn -pl xyz-@item@ clean package
        request.setProjects( getProjectsAfterPlaceHolderIsReplaced( currentValue.getName() ) );

        Properties props = getMergedProperties(currentValue );
        request.setProperties( props );

        request.setRecursive( isRecursive() );
        request.setResumeFrom( getResumeFrom() );
        request.setShellEnvironmentInherited( isShellEnvironmentInherited() );
        request.setShowErrors( isShowErrors() );
        request.setShowVersion( isShowVersion() );
        request.setThreads( getThreads() );
        request.setToolchainsFile( getToolchains() );
        request.setUpdateSnapshots( isUpdateSnapshots() );
        request.setUserSettingsFile( getUserSettings() );
        
        return request;
    }