Java Code Examples for org.apache.maven.shared.invoker.InvocationRequest#setGoals()
The following examples show how to use
org.apache.maven.shared.invoker.InvocationRequest#setGoals() .
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 |
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: ListExtensionsIT.java From quarkus with Apache License 2.0 | 6 votes |
private List<String> listExtensions() throws MavenInvocationException, IOException { InvocationRequest request = new DefaultInvocationRequest(); request.setBatchMode(true); request.setGoals(Collections.singletonList( getPluginGroupId() + ":" + getPluginArtifactId() + ":" + getPluginVersion() + ":list-extensions")); getEnv().forEach(request::addShellEnvironment); File outputLog = new File(testDir, "output.log"); InvocationOutputHandler outputHandler = new PrintStreamHandler( new PrintStream(new TeeOutputStream(System.out, Files.newOutputStream(outputLog.toPath())), true, "UTF-8"), true); invoker.setOutputHandler(outputHandler); File invokerLog = new File(testDir, "invoker.log"); PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(invokerLog), false, "UTF-8"), InvokerLogger.DEBUG); invoker.setLogger(logger); invoker.execute(request); return Files.readAllLines(outputLog.toPath()); }
Example 3
Source File: AddExtensionIT.java From quarkus with Apache License 2.0 | 6 votes |
private void addExtension(boolean plural, String ext) throws MavenInvocationException, FileNotFoundException, UnsupportedEncodingException { InvocationRequest request = new DefaultInvocationRequest(); request.setBatchMode(true); request.setGoals(Collections.singletonList( getPluginGroupId() + ":" + getPluginArtifactId() + ":" + getPluginVersion() + ":add-extension")); Properties properties = new Properties(); properties.setProperty("platformGroupId", "io.quarkus"); properties.setProperty("platformArtifactId", "quarkus-bom"); properties.setProperty("platformVersion", getPluginVersion()); if (plural) { properties.setProperty("extensions", ext); } else { properties.setProperty("extension", ext); } request.setProperties(properties); getEnv().forEach(request::addShellEnvironment); File log = new File(testDir, "build-add-extension-" + testDir.getName() + ".log"); PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(log), false, "UTF-8"), InvokerLogger.DEBUG); invoker.setLogger(logger); invoker.execute(request); }
Example 4
Source File: ExecuteUtil.java From quarkus with Apache License 2.0 | 6 votes |
public static void executeMaven(File projectDirectory, CommandInvocation invocation, String buildTarget) { String mvnPath = findExecutable("mvn"); System.setProperty("maven.home", mvnPath); InvocationRequest request = new DefaultInvocationRequest(); request.setPomFile(new File(projectDirectory.getAbsolutePath() + File.separatorChar + "pom.xml")); request.setGoals(Collections.singletonList(buildTarget)); Invoker invoker = new DefaultInvoker(); InvocationResult result = null; try { result = invoker.execute(request); } catch (MavenInvocationException e) { invocation.println("Failed during invocation: " + e.getMessage()); } if (result.getExitCode() != 0) { invocation.println("Build failed."); } }
Example 5
Source File: TestPackager.java From justtestlah with Apache License 2.0 | 6 votes |
/** * Creates a test package for AWS Devicefarm. * * @param logger {@link InvokerLogger} logger to be used for the Maven build output * @param clean true, if the target directory should be cleaned (forcing recompilation) * @return {@link File} of the ZIP package to be used by AWS Devicefarm * @throws MavenInvocationException error during Maven build */ protected File packageProjectForDeviceFarm(InvocationOutputHandler logger, boolean clean) throws MavenInvocationException { InvocationRequest request = new DefaultInvocationRequest(); request.setPomFile( new File(properties.getProperty("aws.demo.path") + File.separator + "pom.xml")); request.setProfiles(List.of("aws")); if (clean) { request.setGoals(List.of("clean", "package")); } else { request.setGoals(List.of("package")); } request.setUpdateSnapshots(true); new DefaultInvoker().setOutputHandler(logger).execute(request); return new File( properties.getProperty("aws.demo.path") + File.separator + "target" + File.separator + properties.getProperty("aws.testpackage.name") + ".zip"); }
Example 6
Source File: MavenDependencyResolver.java From carnotzet with Apache License 2.0 | 6 votes |
private void executeMavenBuild(List<String> goals, InvocationOutputHandler outputHandler) { log.debug("Invoking maven with goals {}", goals); InvocationRequest request = new DefaultInvocationRequest(); request.setBatchMode(true); request.setGoals(goals); // reset MAVEN_DEBUG_OPTS to allow debugging without blocking the invoker calls request.addShellEnvironment("MAVEN_DEBUG_OPTS", ""); InvocationOutputHandler outHandler = outputHandler; if (outHandler == null) { outHandler = log::debug; } request.setOutputHandler(outHandler); try { InvocationResult result = maven.execute(request); if (result.getExitCode() != 0) { throw new MavenInvocationException("Maven process exited with non-zero code [" + result.getExitCode() + "]. " + "Retry with debug log level enabled to see the maven invocation logs"); } } catch (MavenInvocationException e) { throw new CarnotzetDefinitionException("Error invoking mvn " + goals, e); } }
Example 7
Source File: ProjectGenerator.java From fabric8-forge with Apache License 2.0 | 6 votes |
public File getArtifactJar(String groupId, String artifactId, String version) { Properties properties = new Properties(); properties.put("groupId", groupId); properties.put("artifactId", artifactId); properties.put("version", version); InvocationRequest request = new DefaultInvocationRequest(); request.setLocalRepositoryDirectory(localMavenRepo); request.setInteractive(false); List<String> goalList = Arrays.asList("org.apache.maven.plugins:maven-dependency-plugin:2.10:get"); request.setGoals(goalList); request.setProperties(properties); try { Invoker invoker = new DefaultInvoker(); InvocationResult result = invoker.execute(request); int exitCode = result.getExitCode(); LOG.info("maven result " + exitCode + " exception: " + result.getExecutionException()); assertEquals("Failed to invoke maven goals: " + goalList + " with properties: " + properties + ". Exit Code: ", 0, exitCode); } catch (MavenInvocationException e) { fail("Failed to invoke maven goals: " + goalList + " with properties: " + properties + ". Exception " + e, e); } String path = groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + ".jar"; return new File(localMavenRepo, path); }
Example 8
Source File: HookMethodDefTest.java From sahagin-java with Apache License 2.0 | 6 votes |
private String mavenJreVersion() { InvocationRequest versionRequest = new DefaultInvocationRequest(); if (System.getProperty("sahagin.maven.java.home") != null) { versionRequest.setJavaHome(new File(System.getProperty("sahagin.maven.java.home"))); } versionRequest.setGoals(Arrays.asList("-v")); MavenInvokeResult versionResult = mavenInvoke(versionRequest, "version"); for (String stdOut : versionResult.stdOuts) { String[] entries = stdOut.split(","); for (String entry : entries) { String[] keyValue = entry.split(":"); if (keyValue.length != 2) { continue; } if (keyValue[0].trim().equals("Java version")) { return keyValue[1].trim(); } } } versionResult.printStdOutsAndErrs(); throw new RuntimeException(String.format("fails to get JRE verion")); }
Example 9
Source File: MavenRun.java From edx-app-android with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws IOException { InvocationRequest request = new DefaultInvocationRequest(); request.setPomFile(new File("pom.xml")); if (args.length > 0) { if (args[0] != null && args[1] != null) { Properties projectProperties = new Properties(); projectProperties.setProperty("deviceOS", args[0]); projectProperties.setProperty("appPath", args[1]); projectProperties.setProperty("osVersion", args[2]); projectProperties.setProperty("deviceName", args[3]); projectProperties.setProperty("udid", args[4]); request.setProperties(projectProperties); } } request.setGoals(Collections.singletonList("test")); Invoker invoker = new DefaultInvoker(); invoker.setMavenHome(new File(System.getenv("M2_HOME"))); try { invoker.execute(request); } catch (MavenInvocationException e) { e.printStackTrace(); } }
Example 10
Source File: AbstractSundrioMojo.java From sundrio with Apache License 2.0 | 6 votes |
void backGroundBuild(MavenProject project) throws MojoExecutionException { MavenExecutionRequest executionRequest = session.getRequest(); InvocationRequest request = new DefaultInvocationRequest(); request.setBaseDirectory(project.getBasedir()); request.setPomFile(project.getFile()); request.setGoals(executionRequest.getGoals()); request.setRecursive(false); request.setInteractive(false); request.setProfiles(executionRequest.getActiveProfiles()); request.setProperties(executionRequest.getUserProperties()); Invoker invoker = new DefaultInvoker(); try { InvocationResult result = invoker.execute(request); if (result.getExitCode() != 0) { throw new IllegalStateException("Error invoking Maven goals:[" + StringUtils.join(executionRequest.getGoals(), ", ") + "]", result.getExecutionException()); } } catch (MavenInvocationException e) { throw new IllegalStateException("Error invoking Maven goals:[" + StringUtils.join(executionRequest.getGoals(), ", ") + "]", e); } }
Example 11
Source File: HookMethodDefTest.java From sahagin-java with Apache License 2.0 | 5 votes |
private void generateTempJar(String subDirName) { // generate sahagin temp jar for test from the already generated class files InvocationRequest jarGenRequest = new DefaultInvocationRequest(); if (System.getProperty("sahagin.maven.java.home") != null) { jarGenRequest.setJavaHome(new File(System.getProperty("sahagin.maven.java.home"))); } jarGenRequest.setProfiles(Arrays.asList("sahagin-temp-jar-gen")); jarGenRequest.setGoals(Arrays.asList("jar:jar")); MavenInvokeResult jarGenResult = mavenInvoke(jarGenRequest, subDirName + ":jarGen"); if (!jarGenResult.succeeded) { jarGenResult.printStdOutsAndErrs(); fail("fail to generate jar"); } }
Example 12
Source File: ArchetypeTest.java From ipaas-quickstarts with Apache License 2.0 | 5 votes |
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 13
Source File: AbstractSchemaGeneratorMojoTest.java From jpa-schema-maven-plugin with Apache License 2.0 | 5 votes |
protected void compileJpaModelSources(File pomfile) throws MavenInvocationException { Properties properties = new Properties(); properties.setProperty("plugin.version", System.getProperty("plugin.version")); InvocationRequest request = new DefaultInvocationRequest(); request.setPomFile(pomfile); request.setGoals(Collections.singletonList("compile")); request.setProperties(properties); Invoker invoker = new DefaultInvoker(); invoker.execute(request); }
Example 14
Source File: MavenJarResolver.java From beakerx with Apache License 2.0 | 5 votes |
private InvocationRequest createInvocationRequest(File finalPom) { InvocationRequest request = new DefaultInvocationRequest(); request.setGoals(singletonList(GOAL)); request.setOffline(commandParams.getOffline()); request.setPomFile(finalPom); request.setUpdateSnapshots(true); return request; }
Example 15
Source File: MavenDependencyScanner.java From sonarqube-licensecheck with Apache License 2.0 | 5 votes |
private static Stream<Dependency> readDependencyList(File moduleDir, MavenSettings settings) { Path tempFile = createTempFile(); if (tempFile == null) { return Stream.empty(); } InvocationRequest request = new DefaultInvocationRequest(); request.setRecursive(false); request.setPomFile(new File(moduleDir, "pom.xml")); request.setGoals(Collections.singletonList("dependency:list")); if (settings.userSettings != null) { request.setUserSettingsFile(new File(settings.userSettings)); LOGGER.info("Using user settings {}", settings.userSettings); } if (settings.globalSettings != null) { request.setGlobalSettingsFile(new File(settings.globalSettings)); LOGGER.info("Using global settings {}", settings.globalSettings); } Properties properties = new Properties(); properties.setProperty("outputFile", tempFile.toAbsolutePath().toString()); properties.setProperty("outputAbsoluteArtifactFilename", "true"); properties.setProperty("includeScope", "runtime"); // only runtime (scope compile + runtime) if (System.getProperty(MAVEN_REPO_LOCAL) != null) { properties.setProperty(MAVEN_REPO_LOCAL, System.getProperty(MAVEN_REPO_LOCAL)); } request.setProperties(properties); return invokeMaven(request, tempFile); }
Example 16
Source File: RunnableMavenInvoker.java From repairnator with MIT License | 5 votes |
@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 17
Source File: BuildProject.java From unleash-maven-plugin with Eclipse Public License 1.0 | 4 votes |
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 18
Source File: EndpointsGetClientLib.java From appengine-maven-plugin with Apache License 2.0 | 4 votes |
@Override public void execute() throws MojoExecutionException, MojoFailureException { getLog().info(""); getLog().info("Google App Engine Java SDK - Generate endpoints get client lib"); List<String> classNames = getAPIServicesClasses(); if (classNames.isEmpty()) { getLog().info("No Endpoints classes detected."); return; } try { executeEndpointsCommand("get-client-lib", new String[0], classNames.toArray(new String[classNames.size()])); File webInf = new File(outputDirectory + "/WEB-INF"); if (webInf.exists() && webInf.isDirectory()) { File[] files = webInf.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith("-java.zip"); } }); File mavenProjectsDir = new File(clientLibsDirectory); mavenProjectsDir.mkdirs(); for (File source : files) { File pomFile = unjarMavenProject(source, mavenProjectsDir); if (pomFile != null) { getLog().info("BUILDING Endpoints Client Library from: " + pomFile); InvocationRequest request = new DefaultInvocationRequest(); request.setPomFile(pomFile); request.setGoals(Collections.singletonList("install")); Invoker invoker = new DefaultInvoker(); InvocationResult result = invoker.execute(request); if (result.getExitCode() != 0) { throw new IllegalStateException("Build failed."); } getLog().info("Endpoint get client lib generation and compilation done."); } } } } catch (MojoExecutionException e) { getLog().error(e); throw new MojoExecutionException( "Error while generating Google App Engine endpoint get client lib", e); } catch (MavenInvocationException ex) { Logger.getLogger(EndpointsGetClientLib.class.getName()).log(Level.SEVERE, null, ex); } }
Example 19
Source File: EndpointsGetClientLib.java From gcloud-maven-plugin with Apache License 2.0 | 4 votes |
@Override public void execute() throws MojoExecutionException, MojoFailureException { getLog().info(""); getLog().info("Google App Engine Java SDK - Generate endpoints get client lib"); List<String> classNames = getAPIServicesClasses(); if (classNames.isEmpty()) { getLog().info("No Endpoints classes detected."); return; } try { executeEndpointsCommand("get-client-lib", new String[0], classNames.toArray(new String[classNames.size()])); File webInf = new File(output_directory + "/WEB-INF"); if (webInf.exists() && webInf.isDirectory()) { File[] files = webInf.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith("-java.zip"); } }); File mavenProjectsDir = new File(client_libs_directory); mavenProjectsDir.mkdirs(); for (File source : files) { File pomFile = unjarMavenProject(source, mavenProjectsDir); if (pomFile != null) { getLog().info("BUILDING Endpoints Client Library from: " + pomFile); InvocationRequest request = new DefaultInvocationRequest(); request.setPomFile(pomFile); request.setGoals(Collections.singletonList("install")); Invoker invoker = new DefaultInvoker(); InvocationResult result = invoker.execute(request); if (result.getExitCode() != 0) { throw new IllegalStateException("Build failed."); } getLog().info("Endpoint get client lib generation and compilation done."); } } } } catch (MojoExecutionException e) { getLog().error(e); throw new MojoExecutionException( "Error while generating Google App Engine endpoint get client lib", e); } catch (MavenInvocationException ex) { Logger.getLogger(EndpointsGetClientLib.class.getName()).log(Level.SEVERE, null, ex); } }
Example 20
Source File: AbstractInvokerMojo.java From iterator-maven-plugin with Apache License 2.0 | 4 votes |
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; }