当前位置: 首页>>代码示例>>Java>>正文


Java InvocationRequest类代码示例

本文整理汇总了Java中org.apache.maven.shared.invoker.InvocationRequest的典型用法代码示例。如果您正苦于以下问题:Java InvocationRequest类的具体用法?Java InvocationRequest怎么用?Java InvocationRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


InvocationRequest类属于org.apache.maven.shared.invoker包,在下文中一共展示了InvocationRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.apache.maven.shared.invoker.InvocationRequest; //导入依赖的package包/类
/**
 * Run the build, push, and generate dockerrun.aws.json file goals sequentially.
 * @throws MojoExecutionException if execution fails.
 */
public void execute() throws MojoExecutionException {
  final Properties properties = initializePropertiesForGoals();
  final List<String> goals = Arrays.asList(
      "magic-beanstalk:build",
      "magic-beanstalk:push",
      "magic-beanstalk:genCustomDockerrun",
      "magic-beanstalk:zip");
  final InvocationRequest invocationRequest = createInvocationRequestWithGoals(goals, properties);
  final Invoker invoker = new DefaultInvoker();
  setupInvokerLogger(invoker);

  try {
    final InvocationResult invocationResult = invoker.execute(invocationRequest);
    if (invocationResult.getExitCode() != 0) {
      String msg = "Invocation Exception";
      if (invocationResult.getExecutionException() != null) {
        msg = invocationResult.getExecutionException().getMessage();
      }
      throw new CommandLineException(msg);
    }
  } catch (MavenInvocationException | CommandLineException e) {
    throw new MojoExecutionException("Failed to execute goals", e);
  }

}
 
开发者ID:tsiq,项目名称:magic-beanstalk,代码行数:30,代码来源:AllGoalsMojo.java

示例2: executeMavenBuild

import org.apache.maven.shared.invoker.InvocationRequest; //导入依赖的package包/类
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);
	}
}
 
开发者ID:swissquote,项目名称:carnotzet,代码行数:24,代码来源:MavenDependencyResolver.java

示例3: getArtifactJar

import org.apache.maven.shared.invoker.InvocationRequest; //导入依赖的package包/类
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);
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:26,代码来源:ProjectGenerator.java

示例4: runMavenGoals

import org.apache.maven.shared.invoker.InvocationRequest; //导入依赖的package包/类
protected void runMavenGoals(File outputDir, String... goals) throws MavenInvocationException {
    List<String> goalList = Arrays.asList(goals);
    LOG.info("Invoking maven with goals: " + goalList + " in folder: " + outputDir);
    File pomFile = new File(outputDir, "pom.xml");

    InvocationRequest request = new DefaultInvocationRequest();
    request.setLocalRepositoryDirectory(localMavenRepo);
    request.setInteractive(false);
    request.setPomFile(pomFile);
    request.setGoals(goalList);

    // lets use a dummy service name to avoid it being too long
    request.setMavenOpts("-Dfabric8.service.name=dummy-name");

    Invoker invoker = new DefaultInvoker();
    InvocationResult result = invoker.execute(request);
    int exitCode = result.getExitCode();
    LOG.info("maven result " + exitCode + " exception: " + result.getExecutionException());
    if (exitCode != 0) {
        LOG.error("Failed to invoke maven goals: " + goalList + " in folder: " + outputDir + ". Exit Code: " + exitCode);
        failedFolders.add(outputDir);
    }
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:24,代码来源:ProjectGenerator.java

示例5: execute

import org.apache.maven.shared.invoker.InvocationRequest; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:shillner,项目名称:unleash-maven-plugin,代码行数:23,代码来源:BuildProject.java

示例6: createIfAvailable

import org.apache.maven.shared.invoker.InvocationRequest; //导入依赖的package包/类
public static Optional<MavenRunnerFactory> createIfAvailable(Config config) {
    HomeProvider homeProvider = config.javaHomeProvider();

    StringBuffer out = new StringBuffer();
    InvocationRequest request = new DefaultInvocationRequest()
        .setOutputHandler((str) -> out.append(str).append(" - "))
        .setErrorHandler((str) -> out.append(str).append(" - "))
        .setShowVersion(true)
        .setGoals(Collections.singletonList("--version"))
        .setBaseDirectory(new File("."));
    MavenRunner.runRequest(request, homeProvider);
    try {
        String versionInfo = StringUtils.removeEndIgnoreCase(out.toString(), " - ");
        return Optional.of(new MavenRunnerFactory(homeProvider, versionInfo));
    } catch (ProjectCannotStartException e) {
        return Optional.empty();
    }
}
 
开发者ID:danielflower,项目名称:app-runner,代码行数:19,代码来源:MavenRunnerFactory.java

示例7: invokeMaven

import org.apache.maven.shared.invoker.InvocationRequest; //导入依赖的package包/类
private void invokeMaven(File pomFile, String goal) throws CommandLineException, MavenInvocationException
{
    InvocationRequest request = new DefaultInvocationRequest();
    request.setPomFile(pomFile);
    request.setGoals(Collections.singletonList(goal));
    request.setJavaHome(javaHome);
    request.setShowErrors(true);

    Invoker invoker = new DefaultInvoker();
    invoker.setMavenHome(mavenHome);

    InvocationResult result = invoker.execute(request);

    // check status
    CommandLineException executionException = result.getExecutionException();
    if (executionException != null)
    {
        throw executionException;
    }

    assertEquals(0, result.getExitCode());
}
 
开发者ID:mytaxi,项目名称:phrase-maven-plugin,代码行数:23,代码来源:IntegrationTest.java

示例8: runMaven

import org.apache.maven.shared.invoker.InvocationRequest; //导入依赖的package包/类
public List<String> runMaven(final File workingDir, final String... arguments) throws IOException {
	final InvocationRequest request = createRequest();

	request.setGoals(asList(arguments));
	request.setBaseDirectory(workingDir);

	final Invoker invoker = new DefaultInvoker();
	invoker.setMavenHome(mvnHome);
	final CollectingLogOutputStream logOutput = new CollectingLogOutputStream(false);
	invoker.setOutputHandler(new PrintStreamHandler(new PrintStream(logOutput), true));

	int exitCode;
	try {
		final InvocationResult result = invoker.execute(request);
		exitCode = result.getExitCode();
	} catch (final Exception e) {
		throw new MavenExecutionException(1, logOutput.getLines());
	}
	final List<String> output = logOutput.getLines();

	if (exitCode != 0) {
		throw new MavenExecutionException(exitCode, output);
	}

	return output;
}
 
开发者ID:SourcePond,项目名称:release-maven-plugin-parent,代码行数:27,代码来源:MvnRunner.java

示例9: generate

import org.apache.maven.shared.invoker.InvocationRequest; //导入依赖的package包/类
public String generate() throws MavenInvocationException, IOException {
    InvocationRequest request = new DefaultInvocationRequest();

    Path pomPath = Files.createTempFile("pom", ".xml");
    Files.copy(getClass().getClassLoader().getResourceAsStream(POM_PATH),
            pomPath, StandardCopyOption.REPLACE_EXISTING);

    request.setPomFile(pomPath.toFile());
    request.setProperties(config.asJaxb2Properties());
    request.setGoals(Arrays.asList("clean", "generate-sources"));

    InvocationResult result = new DefaultInvoker().execute(request);

    if(result.getExitCode() != 0) {
        LOG.info("Xmlgen failed: {}", result.getExecutionException());
    }

    pomPath.toFile().delete();

    return capitalize(sanitize(XmlPath.from(new File(config.getInputPath()))
            .getNode("schema").getNode("element").getAttribute("name"))) + "Type";
}
 
开发者ID:qameta,项目名称:rarc,代码行数:23,代码来源:XmlCodegen.java

示例10: install

import org.apache.maven.shared.invoker.InvocationRequest; //导入依赖的package包/类
private void install(Pom pom, GitDependency dependency) throws MojoExecutionException {
	final GitDependencyHandler dependencyHandler = new GitDependencyHandler(dependency);
	final String version = dependencyHandler.getDependencyVersion(pom);
	final String tempDirectory = Directory.getTempDirectoryString(dependency.getLocation(), version);
	final InvocationRequest request = new DefaultInvocationRequest();
	final Invoker invoker = new DefaultInvoker();

	request.setPomFile(new File(tempDirectory + "/pom.xml"));
	request.setGoals(Collections.singletonList("install"));



	try {
		final InvocationResult result = invoker.execute(request);
		final int exitCode = result.getExitCode();

		if (exitCode != 0) {
			throw new MojoExecutionException(String.format("Build failed with exit code %d.", exitCode));
		}
	} catch (MavenInvocationException ex) {
		throw new MojoExecutionException(String.format("Invocation of install goal failed on '%s'.",
			request.getPomFileName()), ex);
	}
}
 
开发者ID:ejwa,项目名称:gitdep-maven-plugin,代码行数:25,代码来源:InstallerMojo.java

示例11: executeLicenseProject

import org.apache.maven.shared.invoker.InvocationRequest; //导入依赖的package包/类
private void executeLicenseProject(File pomFile, File repoDir) throws Exception {
    InvocationRequest mavenRequest = new DefaultInvocationRequest();
    mavenRequest.setPomFile(pomFile);
    mavenRequest.setBaseDirectory(pomFile.getParentFile());
    mavenRequest.setUserSettingsFile(userSettings);
    mavenRequest.setLocalRepositoryDirectory(repoDir);
    mavenRequest.setGoals(Arrays.asList("clean", "package"));

    Invoker invoker = new DefaultInvoker();
    try {
        InvocationResult result = invoker.execute(mavenRequest);
        if (result.getExitCode() != 0) {
            throw result.getExecutionException() != null ? result.getExecutionException()
                    : new IllegalStateException("Build failure: " + result.getExitCode());
        }
        getLog().info("Licenses POM executed: " + pomFile.getAbsolutePath());
    } catch (Exception e) {
        getLog().error("Error when executing " + pomFile.getAbsolutePath(), e);
    }
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm-fraction-plugin,代码行数:21,代码来源:LicenseMojo.java

示例12: backGroundBuild

import org.apache.maven.shared.invoker.InvocationRequest; //导入依赖的package包/类
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);
    }
}
 
开发者ID:sundrio,项目名称:sundrio,代码行数:23,代码来源:AbstractSundrioMojo.java

示例13: install

import org.apache.maven.shared.invoker.InvocationRequest; //导入依赖的package包/类
private void install(POM pom, GitDependency dependency) {

		final GitDependencyHandler dependencyHandler = new GitDependencyHandler(dependency);
		final String version = dependencyHandler.getDependencyVersion(pom);
		
		final String tempDirectory = Directory.getTempDirectoryString(dependency.getLocation(), version);
		final InvocationRequest request = new DefaultInvocationRequest();
		final Invoker invoker = new DefaultInvoker();

		request.setPomFile(new File(tempDirectory + "/pom.xml"));
		request.setGoals(Collections.singletonList("install"));

		try {
			final InvocationResult result = invoker.execute(request);

			if (result.getExitCode() != 0) {
				throw new IllegalStateException("Build failed.");
			}
		} catch (MavenInvocationException ex) {
			getLog().debug(ex);
		}
	}
 
开发者ID:jr9999,项目名称:maven-gitdep-plugin,代码行数:23,代码来源:InstallerMojo.java

示例14: main

import org.apache.maven.shared.invoker.InvocationRequest; //导入依赖的package包/类
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();
	}
}
 
开发者ID:edx,项目名称:edx-app-android,代码行数:25,代码来源:MavenRun.java

示例15: mvnCleanPackageWithProperties

import org.apache.maven.shared.invoker.InvocationRequest; //导入依赖的package包/类
public void mvnCleanPackageWithProperties(
        final String path, final Properties properties, final File customSettingsFile) {

    final InvocationRequest request = new DefaultInvocationRequest();
    request.setProperties(properties);
    if (customSettingsFile != null && FileUtils.sizeOf(customSettingsFile) > 0) {
        request.setUserSettingsFile(customSettingsFile);
    }
    final List<String> mavenGoals = new ArrayList<>();
    mavenGoals.add("clean");
    mavenGoals.add("package");
    request.setGoals(mavenGoals);
    logToHandler(request.getGoals(), properties);
    logToFile(request.getGoals(), properties);
    invoke(request, path);
}
 
开发者ID:apache,项目名称:syncope,代码行数:17,代码来源:MavenUtils.java


注:本文中的org.apache.maven.shared.invoker.InvocationRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。