List of usage examples for org.apache.maven.execution DefaultMavenExecutionRequest DefaultMavenExecutionRequest
public DefaultMavenExecutionRequest()
From source file:com.bluexml.side.util.dependencies.MavenUtil.java
License:Open Source License
public MavenExecutionResult doMavenGoal(File baseDir, List<String> goals, Map<String, String> parameters, List<String> profiles, Boolean offline) throws Exception { System.out.println(baseDir.getAbsolutePath()); DefaultMavenExecutionRequest archetypeCreateRequest = new DefaultMavenExecutionRequest(); archetypeCreateRequest.setBaseDirectory(baseDir); archetypeCreateRequest.setGoals(goals); archetypeCreateRequest.setInteractiveMode(false); archetypeCreateRequest.setProperty("basedir", baseDir.getAbsolutePath().toString()); // set active profile if (profiles != null && !profiles.isEmpty()) { archetypeCreateRequest.addActiveProfiles(profiles); }/*from w ww.j a v a 2 s . c om*/ // set offline if (offline != null) { archetypeCreateRequest.setOffline(offline); } if (parameters != null) { // manage additional parameters for (Map.Entry<String, String> param : parameters.entrySet()) { archetypeCreateRequest.setProperty(param.getKey(), param.getValue()); } } MavenEmbedder embedder = getEmbedder(); archetypeCreateRequest.setUpdateSnapshots(true); //System.out.println("Active profiles :"+archetypeCreateRequest.getActiveProfiles()); if (archetypeCreateRequest.getActiveProfiles().size() == 0) { throw new Exception("No active profile found report this bug to SIDE developers team"); } MavenExecutionResult result = embedder.execute(archetypeCreateRequest); return result; }
From source file:com.github.r351574nc3.maven.instrument.AgentRequest.java
License:Open Source License
AgentRequest(String[] args, ClassWorld classWorld) {
this.args = args;
this.classWorld = classWorld;
this.request = new DefaultMavenExecutionRequest();
}
From source file:com.github.swt_release_fetcher.Artifact.java
License:Apache License
public void runMavenDeploy(File pomFile, File jarFile, File sourcesFile) { Properties properties = new Properties(); properties.put("pomFile", pomFile.getAbsolutePath()); properties.put("file", jarFile.getAbsolutePath()); properties.put("sources", sourcesFile.getAbsolutePath()); properties.put("repositoryId", "googlecode"); properties.put("url", REPOSITORY_URL); MavenExecutionRequest request = new DefaultMavenExecutionRequest(); request.setPom(pomFile);/*from ww w . j a v a2s. c om*/ request.setGoals(Arrays.asList(new String[] { "deploy:deploy-file" })); request.setSystemProperties(properties); Maven maven = EmbeddedMaven.get(); MavenExecutionResult result = maven.execute(request); if (result.hasExceptions()) { System.out.println("Maven deploy failed!"); System.out.println(result.getExceptions()); throw new RuntimeException("Maven deploy failed!", result.getExceptions().get(0)); } else { System.out.println("Maven deploy succeeded!"); } }
From source file:com.google.gdt.eclipse.maven.e35.configurators.GoogleProjectConfigurator.java
License:Open Source License
@Override protected void doConfigure(final MavenProject mavenProject, IProject project, ProjectConfigurationRequest request, final IProgressMonitor monitor) throws CoreException { final IMaven maven = MavenPlugin.getDefault().getMaven(); boolean configureGaeNatureSuccess = configureNature(project, mavenProject, GaeNature.NATURE_ID, true, new NatureCallbackAdapter() { @Override// www. ja va 2 s . c om public void beforeAddingNature() { try { DefaultMavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); executionRequest.setBaseDirectory(mavenProject.getBasedir()); executionRequest.setLocalRepository(maven.getLocalRepository()); executionRequest.setRemoteRepositories(mavenProject.getRemoteArtifactRepositories()); executionRequest .setPluginArtifactRepositories(mavenProject.getPluginArtifactRepositories()); executionRequest.setPom(mavenProject.getFile()); executionRequest.setGoals(GAE_UNPACK_GOAL); MavenExecutionResult result = maven.execute(executionRequest, monitor); if (result.hasExceptions()) { Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error configuring project", result.getExceptions().get(0))); } } catch (CoreException e) { Activator.getDefault().getLog().log( new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error configuring project", e)); } } }, monitor); boolean configureGWTNatureSuccess = configureNature(project, mavenProject, GWTNature.NATURE_ID, true, new NatureCallbackAdapter() { @Override public void beforeAddingNature() { // Get the GWT version from the project pom String gwtVersion = null; List<Dependency> dependencies = mavenProject.getDependencies(); for (Dependency dependency : dependencies) { if (GWTMavenRuntime.MAVEN_GWT_GROUP_ID.equals(dependency.getGroupId()) && (GWTMavenRuntime.MAVEN_GWT_USER_ARTIFACT_ID .equals(dependency.getArtifactId()) || GWTMavenRuntime.MAVEN_GWT_SERVLET_ARTIFACT_ID .equals(dependency.getArtifactId()))) { gwtVersion = dependency.getVersion(); break; } } // Check that the pom.xml has GWT dependencies if (!StringUtilities.isEmpty(gwtVersion)) { try { /* * Download and install the gwt-dev.jar into the local * repository. */ maven.resolve(GWTMavenRuntime.MAVEN_GWT_GROUP_ID, GWTMavenRuntime.MAVEN_GWT_DEV_JAR_ARTIFACT_ID, gwtVersion, "jar", null, mavenProject.getRemoteArtifactRepositories(), monitor); } catch (CoreException e) { Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error configuring project", e)); } } } }, monitor); if (configureGWTNatureSuccess || configureGaeNatureSuccess) { try { // Add GWT Web Application configuration parameters WebAppProjectProperties.setWarSrcDir(project, new Path("src/main/webapp")); WebAppProjectProperties.setWarSrcDirIsOutput(project, false); String artifactId = mavenProject.getArtifactId(); String version = mavenProject.getVersion(); IPath location = (project.getRawLocation() != null ? project.getRawLocation() : project.getLocation()); if (location != null && artifactId != null && version != null) { WebAppProjectProperties.setLastUsedWarOutLocation(project, location.append("target").append(artifactId + "-" + version)); } } catch (BackingStoreException be) { Activator.getDefault().getLog() .log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error configuring project", be)); } } }
From source file:com.googlecode.ounit.executor.MavenRunner.java
License:Open Source License
public MavenExecutionResult execute(File baseDirectory, List<String> goals, String outputDirectory) { baseDirectory = baseDirectory.getAbsoluteFile(); File pom = modelProcessor.locatePom(baseDirectory); MavenExecutionRequest request = new DefaultMavenExecutionRequest(); request.setBaseDirectory(baseDirectory).setPom(pom).setExecutionListener(executionListener) .setTransferListener(transferListener).setSystemProperties(systemProperties) //.setUserProperties( userProperties ) .setLoggingLevel(logLevel).setInteractiveMode(false) //.setOffline( true ) .setCacheNotFound(true).setCacheTransferError(false).setGoals(goals); /* Apply base profiles */ for (Profile p : baseProfiles) request.addProfile(p.clone());// w w w . j av a 2s.c o m // TODO: Implement system specific settings.xml file /* Create a build profile to set outputDirectory */ if (outputDirectory != null) { Build b = new Build(); b.setDirectory(outputDirectory); Activation a = new Activation(); a.setActiveByDefault(true); Profile p = new Profile(); p.setId("ounitExecutorCustomOutputDirectoryProfile"); p.setActivation(a); p.setBuild(b); request.addProfile(p); } container.getLoggerManager().setThresholds(request.getLoggingLevel()); MavenExecutionResult r = maven.execute(request); return r; }
From source file:com.maltera.technologic.maven.mcforge.InstallMojo.java
License:Open Source License
public void execute() throws MojoExecutionException, MojoFailureException { // set up derived paths forgeDir = new File(outputDir, "forge"); jarsDir = new File(forgeDir, "mcp/jars"); // check whether the artifact is already installed if (reinstall) { getLog().info("reinstall flag set; skipping availability check"); } else {/*from w w w.j av a2 s. c o m*/ getLog().info("attempting to resolve Forge artifacts"); if (null != resolveApiArtifact() && null != resolveToolsArtifact()) { getLog().info("artifacts are available; skipping installation"); return; } else { getLog().info("artifacts not available; continuing installation"); } } if (!noExtract) downloadAndExtract(); if (!forgeDir.isDirectory()) throw new MojoFailureException("distribution did not extract to the excpected directory"); // run the install script if (!noInstall) { getLog().info("running install script"); try { final PythonLauncher launcher = new PythonLauncher(getLog(), forgeDir); final int result = launcher.execute(new File(forgeDir, "install.py")); if (0 != result) { throw new MojoFailureException("install script returned " + result); } } catch (IOException caught) { throw new MojoFailureException("error calling install script", caught); } } // load Minecraft's POM final Model minecraft = loadModelFromResouce("minecraft.pom"); minecraft.setVersion(getMinecraftVersion()); // figure out Minecraft's dependencies { getLog().info("detecting Minecraft dependencies"); final Artifact lwjgl = locator.findVersion(new File(jarsDir, "bin/lwjgl.jar"), "org.lwjgl.lwjgl", "lwjgl"); final Artifact lwjgl_util = new DefaultArtifact("org.lwjgl.lwjgl", "lwjgl_util", "jar", lwjgl.getVersion()); // don't include jinput.jar // it's a transitive dependency from LWJGL getLog().info("resolving Minecraft dependencies"); for (Artifact target : new Artifact[] { lwjgl, lwjgl_util }) { getLog().info(" " + target); final Artifact resolved = resolveRemoteArtifact(target); if (null == resolved) throw new MojoFailureException("unable to resolve artifact " + target); minecraft.addDependency(artifactToDependency(resolved)); } } // install Minecraft JAR installJar(minecraft, new File(jarsDir, "bin/minecraft.jar")); // figure out Forge's dependencies // using a Map of coordinates => artifact for deduplication // can't use a Set, Artifact#equals() doesn't behave final Map<String, Dependency> forgeDeps = new HashMap<String, Dependency>(); for (File file : (new File(forgeDir, "mcp/lib")).listFiles()) { final Artifact artifact = locator.locate(file); if (null == artifact) throw new MojoFailureException("no artifact found for dependency " + file.getName()); forgeDeps.put(artifact.toString(), artifactToDependency(artifact)); } // add Minecraft client to Forge dependencies { final Artifact artifact = new DefaultArtifact("net.minecraft", "minecraft", "jar", getMinecraftVersion()); forgeDeps.put(artifact.toString(), artifactToDependency(artifact)); } // extract the Forge POM final File pom = new File(forgeDir, "pom.xml"); { final Model model = loadModelFromResouce("mcforge.pom"); model.setVersion(getApiDependency().getVersion()); model.setDependencies(new ArrayList<Dependency>(forgeDeps.values())); writeModelToFile(model, pom); } // execute a build from the Forge POM getLog().info("executing POM to package and install artifacts"); try { final MavenExecutionRequest request = new DefaultMavenExecutionRequest(); requestPopulator.populateDefaults(request); request.setPom(pom); request.setGoals(Collections.singletonList("install")); final MavenExecutionResult result = maven.execute(request); // check for startup exceptions if (result.hasExceptions()) throw new MojoFailureException("failed to package and install artifacts", result.getExceptions().get(0)); // check for build failure final BuildSummary summary = result.getBuildSummary(result.getProject()); if (summary instanceof BuildFailure) { throw new MojoFailureException("failed to package and install artifacts", ((BuildFailure) summary).getCause()); } } catch (MojoFailureException caught) { throw caught; } catch (Exception caught) { throw new MojoFailureException("failed to package and install artifacts", caught); } }
From source file:com.puppetlabs.geppetto.forge.maven.plugin.AbstractForgeTestMojo.java
License:Open Source License
protected MavenSession newMavenSession(MavenProject project) { MavenExecutionRequest request = new DefaultMavenExecutionRequest(); MavenExecutionResult result = new DefaultMavenExecutionResult(); MavenSession session = new MavenSession(container, new MavenRepositorySystemSession(), request, result); session.setCurrentProject(project);/*from w w w . j a va 2 s .c o m*/ session.setProjects(Arrays.asList(project)); return session; }
From source file:com.puppetlabs.geppetto.forge.maven.plugin.AbstractForgeTestMojo.java
License:Open Source License
@Before public void setUp() throws Exception { pom = new File(ForgeIT.TEST_POM_DIR, "pom.xml"); Assert.assertNotNull(pom);/*from w w w .j a va 2s.c o m*/ Assert.assertTrue(pom.exists()); MavenExecutionRequest request = new DefaultMavenExecutionRequest(); mavenSession = null; buildingRequest = request.getProjectBuildingRequest(); userProps = new Properties(); userProps.put("testForgeServiceURL", System.getProperty("forge.base.url")); FileUtils.rmR(new File(pom.getParent(), "target")); }
From source file:com.redhat.rcm.version.config.DefaultSessionConfigurator.java
License:Open Source License
private void loadSettings(final VersionManagerSession session) { MavenExecutionRequest executionRequest = session.getExecutionRequest(); if (executionRequest == null) { executionRequest = new DefaultMavenExecutionRequest(); }//from w w w .j a v a2 s . c o m File settingsXml; try { settingsXml = getFile(session.getSettingsXml(), session.getDownloads()); } catch (final VManException e) { session.addError(e); return; } final DefaultSettingsBuildingRequest req = new DefaultSettingsBuildingRequest(); req.setUserSettingsFile(settingsXml); req.setSystemProperties(System.getProperties()); try { final SettingsBuildingResult result = settingsBuilder.build(req); final Settings settings = result.getEffectiveSettings(); final String proxyHost = System.getProperty("http.proxyHost"); final String proxyPort = System.getProperty("http.proxyPort", "8080"); final String nonProxyHosts = System.getProperty("http.nonProxyHosts", "localhost"); final String proxyUser = System.getProperty("http.proxyUser"); final String proxyPassword = System.getProperty("http.proxyPassword"); if (proxyHost != null) { final Proxy proxy = new Proxy(); proxy.setActive(true); proxy.setHost(proxyHost); proxy.setId("cli"); proxy.setNonProxyHosts(nonProxyHosts); proxy.setPort(Integer.parseInt(proxyPort)); if (proxyUser != null && proxyPassword != null) { proxy.setUsername(proxyUser); proxy.setPassword(proxyPassword); Authenticator.setDefault(new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(proxyUser, proxyPassword.toCharArray()); } }); } settings.setProxies(Collections.singletonList(proxy)); } executionRequest = requestPopulator.populateFromSettings(executionRequest, settings); session.setExecutionRequest(executionRequest); } catch (final SettingsBuildingException e) { session.addError(new VManException("Failed to build settings from: %s. Reason: %s", e, settingsXml, e.getMessage())); } catch (final MavenExecutionRequestPopulationException e) { session.addError(new VManException("Failed to initialize system using settings from: %s. Reason: %s", e, settingsXml, e.getMessage())); } }
From source file:com.ruleoftech.markdown.page.generator.plugin.BetterAbstractMojoTestCase.java
protected MavenSession newMavenSession() { try {//from w w w . j a v a2 s. com MavenExecutionRequest request = new DefaultMavenExecutionRequest(); MavenExecutionResult result = new DefaultMavenExecutionResult(); // populate sensible defaults, including repository basedir and remote repos MavenExecutionRequestPopulator populator; populator = getContainer().lookup(MavenExecutionRequestPopulator.class); populator.populateDefaults(request); // this is needed to allow java profiles to get resolved; i.e. avoid during project builds: // [ERROR] Failed to determine Java version for profile java-1.5-detected @ org.apache.commons:commons-parent:22, /Users/alex/.m2/repository/org/apache/commons/commons-parent/22/commons-parent-22.pom, line 909, column 14 request.setSystemProperties(System.getProperties()); // and this is needed so that the repo session in the maven session // has a repo manager, and it points at the local repo // (cf MavenRepositorySystemUtils.newSession() which is what is otherwise done) DefaultMaven maven = (DefaultMaven) getContainer().lookup(Maven.class); DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) maven .newRepositorySession(request); repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(repoSession, new LocalRepository(request.getLocalRepository().getBasedir()))); @SuppressWarnings("deprecation") MavenSession session = new MavenSession(getContainer(), repoSession, request, result); return session; } catch (Exception e) { throw new RuntimeException(e); } }