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

The following examples show how to use org.apache.maven.shared.invoker.InvocationRequest#setOffline() . 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: MavenExecutorImpl.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
public boolean executeMavenGoal(File projectPath, List<String> goals,
		boolean isOffline) {
	InvocationRequest request = new DefaultInvocationRequest();

	if (!projectPath.exists()) {
		projectPath.mkdirs();
	}

	request.setPomFile(new File(projectPath, POM_XML));

	if (goals == null) {
		goals = getDefaultMavenGoals();
	}
	request.setGoals(goals);
	Invoker invoker = new DefaultInvoker();
	request.setOffline(isOffline);

	try {
		InvocationResult result = invoker.execute(request);
		if (result.getExecutionException() == null) {
			if (result.getExitCode() != 0) {
				request.setOffline(!isOffline);
				result = invoker.execute(request);
				if (result.getExitCode() == 0) {
					return true;
				} else {
					final String errorMessage = "No maven Project found at "
							+ projectPath;
					log.error(errorMessage);
					throw new MavenInvocationException(errorMessage);
				}
			}
			return true;
		}
	} catch (MavenInvocationException e) {
		log.error("Maven invocation failed", e);
	}
	return false;
}
 
Example 2
Source File: MavenJarResolver.java    From beakerx with Apache License 2.0 5 votes vote down vote up
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 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;
    }