List of usage examples for org.apache.maven.execution MavenExecutionRequest setPom
MavenExecutionRequest setPom(File pom);
From source file:com.carrotgarden.m2e.config.LaunchDelegate.java
License:BSD License
private void launchMaven(final File pomFile, final List<String> commandList, final IProgressMonitor monitor) throws CoreException { final IMaven maven = MavenPlugin.getMaven(); final Model mavenModel = maven.readModel(pomFile); final MavenProject mavenProject = new MavenProject(mavenModel); final Properties mavenProps = mavenProject.getProperties(); for (final Map.Entry<?, ?> entry : mavenProps.entrySet()) { final String key = entry.getKey().toString(); final String value = entry.getValue().toString(); // ConfigPlugin.logInfo("key= " + key + " value=" + value); }/* w ww . j a v a 2 s .com*/ // final List<String> goalList = new LinkedList<String>(); final List<String> profileActiveList = new LinkedList<String>(); final List<String> profileInactiveList = new LinkedList<String>(); for (final String command : commandList) { if (command.startsWith("-")) { /** command line options */ if (command.startsWith("--activate-profiles")) { ConfigPlugin.log(IStatus.ERROR, "TODO : " + command); } else { ConfigPlugin.log(IStatus.ERROR, "not supported : " + command); } } else { /** maven execution goals */ goalList.add(command); } } // final MavenExecutionRequest request = maven.createExecutionRequest(monitor); request.setPom(pomFile); request.setGoals(goalList); // TODO // request.setActiveProfiles(profileActiveList); // request.setInactiveProfiles(profileInactiveList); // final String id = mavenProject.getId(); ConfigPlugin.log(IStatus.INFO, "maven execute : " + mavenProject.getId() + " " + MojoUtil.join(commandList, ",")); // final Job job = new Job(id) { // { // setSystem(true); // setPriority(BUILD); // } // @Override // protected IStatus run(final IProgressMonitor monitor) { // return null; // } // }; final MavenExecutionResult result = maven.execute(request, monitor); if (result.hasExceptions()) { throw new CoreException(new Status(IStatus.ERROR, ConfigPlugin.ID, "maven execution failed", result.getExceptions().get(0))); } }
From source file:com.cloudbees.eclipse.m2e.CBMavenUtils.java
License:Open Source License
public static IFile runMaven(IProject project, IProgressMonitor monitor, String[] goals) throws CloudBeesException { boolean pomExists = project.exists(new Path("/pom.xml")); if (!pomExists) { return null; }//from w w w .java 2s. c om IMaven maven = MavenPlugin.getMaven(); String version = MavenPlugin.getMavenRuntimeManager().getDefaultRuntime().getVersion(); MavenExecutionRequest request; IMavenProjectFacade mpr = MavenPlugin.getMavenProjectRegistry().getProject(project); try { if (mpr == null) { // maven not configured for the project. But as pom.xml existed, let's configure. NatureUtil.addNatures(project, new String[] { CloudBeesNature.NATURE_ID, JavaCore.NATURE_ID, "org.eclipse.m2e.core.maven2Nature" }, monitor); project.refreshLocal(IProject.DEPTH_INFINITE, monitor); mpr = MavenPlugin.getMavenProjectRegistry().getProject(project); } request = maven.createExecutionRequest(monitor); } catch (CoreException e) { throw new CloudBeesException("Failed to prepare maven war preparation request", e); } //IMavenProjectFacade facade = projectManager.create(pomFile, true, new SubProgressMonitor(monitor, 1)); //ResolverConfiguration config = mpr.getResolverConfiguration(); request.setPom(project.getFile(new Path("/pom.xml")).getRawLocation().toFile()); //request.setBaseDirectory(project.getRawLocation().toFile()); request.getSystemProperties().put("maven.test.skip", "true"); //MavenExecutionRequest request = projectManager.createExecutionRequest(pomFile, config, new SubProgressMonitor(monitor, 1)); //request.getUserProperties().setProperty("m2e.version", MavenPlugin.getVersion()); //goals.add("package"); //goals.add("eclipse:eclipse"); request.setGoals(Arrays.asList(goals)); //MavenPlugin.getConsole().showConsole(); MavenExecutionResult result = maven.execute(request, monitor); if (result.hasExceptions()) { // Throw CoreException //System.out.println("Got exceptions while running!"); Iterator<Throwable> it = result.getExceptions().iterator(); Throwable e = null; while (it.hasNext()) { Throwable throwable = (Throwable) it.next(); throwable.printStackTrace(); e = throwable; } throw new CloudBeesException("Maven build failed!", e); } BuildSummary summary = result.getBuildSummary(result.getProject()); MavenProject proj = summary.getProject(); Artifact artifact = proj.getArtifact(); File f = artifact.getFile(); //System.out.println("Artifact: " + f); //System.out.println("Artifact name: " + f.getName()); if (f == null) { return null; } if (BeesSDK.hasSupportedExtension(f.getName())) { String apath = f.getAbsolutePath().substring(project.getLocation().toFile().getAbsolutePath().length()); //System.out.println("APATH: " + apath); return project.getFile(apath); } return null; }
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); request.setGoals(Arrays.asList(new String[] { "deploy:deploy-file" })); request.setSystemProperties(properties); Maven maven = EmbeddedMaven.get();/*from w w w.j a va 2s.c o m*/ 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.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 a v a 2 s . co 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:ead.exporter.ApkExporter.java
License:Open Source License
@Override public void export(String gameBaseDir, String outputfolder) { if (packageName == null) { logger.error("app name is not set or is invalid. Apk exportation failed."); return;// w w w . j a va2s . co m } // Create a temp folder to generate de apk File gameFolder = new File(gameBaseDir); String tempFolder = System.getProperty("java.io.tmpdir"); File apkTemp = new File( tempFolder + File.separator + "eAdventureApkTemp" + Math.round(Math.random() * 1000)); apkTemp.mkdirs(); File manifestFile = createManifest(apkTemp); File apkAssets = createAssetsFolder(apkTemp, gameFolder); File apkResources = createResourcesFolder(apkTemp); // Copy native libs folder try { FileUtils.copyDirectoryStructure(new File("../../resources/nativelibs"), apkTemp); } catch (IOException e) { } // Copy and load pom file File pomFile = createPomFile(apkTemp); MavenExecutionRequest request = new DefaultMavenExecutionRequest(); // Goals File f = new File(apkTemp, "/target/classes"); f.mkdirs(); ArrayList<String> goals = new ArrayList<String>(); goals.add("clean"); goals.add("install"); if (runInDevice) { goals.add("android:deploy"); goals.add("android:run"); } request.setGoals(goals); // Properties Properties userProperties = new Properties(); userProperties.setProperty("game.basedir", gameBaseDir); userProperties.setProperty("game.outputfolder", outputfolder); userProperties.setProperty("game.name", appName); userProperties.setProperty("ead.packagename", packageName); userProperties.setProperty("eadmanifestdir", manifestFile.getAbsolutePath()); userProperties.setProperty("ead.tempfile", apkTemp.getAbsolutePath()); userProperties.setProperty("ead.assets", apkAssets.getAbsolutePath()); userProperties.setProperty("ead.resources", apkResources.getAbsolutePath()); request.setUserProperties(userProperties); // Set files request.setBaseDirectory(apkTemp); request.setPom(pomFile); // Execute maven request.setLoggingLevel(org.codehaus.plexus.logging.Logger.LEVEL_ERROR); MavenExecutionResult result = maven.execute(request); for (Throwable e : result.getExceptions()) { logger.warn("{}", e); } // Copy apk to destination File apk = new File(apkTemp, "target/" + packageName + ".apk"); File apkDst = new File(outputfolder, packageName + ".apk"); try { FileUtils.copyFile(apk, apkDst); } catch (IOException e1) { } // Delete temp folder try { FileUtils.deleteDirectory(apkTemp); } catch (IOException e) { logger.warn("Apk assets temp folder was not deleted {}", e); } }
From source file:ead.exporter.JarExporter.java
License:Open Source License
public void export(String gameBaseDir, String outputfolder) { String tempFolder = System.getProperty("java.io.tmpdir"); File jarTemp = new File( tempFolder + File.separator + "eAdventureJarTemp" + Math.round(Math.random() * 1000)); jarTemp.mkdirs();/*from w w w . j av a 2 s . c om*/ // Load pom file File pomFile = new File(jarTemp, "pom.xml"); try { FileUtils.copyStreamToFile( new RawInputStreamFacade(ClassLoader.getSystemResourceAsStream("pom/desktoppom.xml")), pomFile); } catch (IOException e1) { } MavenExecutionRequest request = new DefaultMavenExecutionRequest(); // Goals ArrayList<String> goals = new ArrayList<String>(); goals.add("package"); request.setGoals(goals); // Properties Properties userProperties = new Properties(); userProperties.setProperty("game.basedir", gameBaseDir); userProperties.setProperty("game.outputfolder", outputfolder); userProperties.setProperty("game.name", name); request.setUserProperties(userProperties); // Set files request.setBaseDirectory(jarTemp); request.setPom(pomFile); // Execute maven MavenExecutionResult result = maven.execute(request); for (Throwable e : result.getExceptions()) { e.printStackTrace(); } // Copy to output folder File jarFile = new File(jarTemp, "target/desktop-game-1.0-unified.jar"); File dstFile = new File(outputfolder, name + ".jar"); try { FileUtils.copyFile(jarFile, dstFile); } catch (IOException e2) { } try { FileUtils.deleteDirectory(jarTemp); } catch (IOException e1) { } }
From source file:hudson.maven.MavenEmbedder.java
License:Apache License
protected MavenExecutionRequest buildMavenExecutionRequest(MavenRequest mavenRequest) throws MavenEmbedderException, ComponentLookupException { MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest(); if (mavenRequest.getGlobalSettingsFile() != null) { mavenExecutionRequest.setGlobalSettingsFile(new File(mavenRequest.getGlobalSettingsFile())); }/*www .ja v a 2 s.com*/ if (mavenExecutionRequest.getUserSettingsFile() != null) { mavenExecutionRequest.setUserSettingsFile(new File(mavenRequest.getUserSettingsFile())); } try { lookup(MavenExecutionRequestPopulator.class).populateFromSettings(mavenExecutionRequest, getSettings()); lookup(MavenExecutionRequestPopulator.class).populateDefaults(mavenExecutionRequest); } catch (MavenExecutionRequestPopulationException e) { throw new MavenEmbedderException(e.getMessage(), e); } ArtifactRepository localRepository = getLocalRepository(); mavenExecutionRequest.setLocalRepository(localRepository); mavenExecutionRequest.setLocalRepositoryPath(localRepository.getBasedir()); mavenExecutionRequest.setOffline(mavenRequest.isOffline()); mavenExecutionRequest.setUpdateSnapshots(mavenRequest.isUpdateSnapshots()); // TODO check null and create a console one ? mavenExecutionRequest.setTransferListener(mavenRequest.getTransferListener()); mavenExecutionRequest.setCacheNotFound(mavenRequest.isCacheNotFound()); mavenExecutionRequest.setCacheTransferError(true); mavenExecutionRequest.setUserProperties(mavenRequest.getUserProperties()); mavenExecutionRequest.getSystemProperties().putAll(System.getProperties()); if (mavenRequest.getSystemProperties() != null) { mavenExecutionRequest.getSystemProperties().putAll(mavenRequest.getSystemProperties()); } mavenExecutionRequest.getSystemProperties().putAll(getEnvVars()); if (this.mavenHome != null) { mavenExecutionRequest.getSystemProperties().put("maven.home", this.mavenHome.getAbsolutePath()); } if (mavenRequest.getProfiles() != null && !mavenRequest.getProfiles().isEmpty()) { for (String id : mavenRequest.getProfiles()) { Profile p = new Profile(); p.setId(id); p.setSource("cli"); mavenExecutionRequest.addProfile(p); mavenExecutionRequest.addActiveProfile(id); } } mavenExecutionRequest.setLoggingLevel(mavenRequest.getLoggingLevel()); lookup(Logger.class).setThreshold(mavenRequest.getLoggingLevel()); mavenExecutionRequest.setExecutionListener(mavenRequest.getExecutionListener()) .setInteractiveMode(mavenRequest.isInteractive()) .setGlobalChecksumPolicy(mavenRequest.getGlobalChecksumPolicy()).setGoals(mavenRequest.getGoals()); if (mavenRequest.getPom() != null) { mavenExecutionRequest.setPom(new File(mavenRequest.getPom())); } if (mavenRequest.getWorkspaceReader() != null) { mavenExecutionRequest.setWorkspaceReader(mavenRequest.getWorkspaceReader()); } // FIXME inactive profiles //this.mavenExecutionRequest.set return mavenExecutionRequest; }
From source file:net.oneandone.maven.plugins.prerelease.util.Maven.java
License:Apache License
/** * Creates an DefaultMaven instance, initializes it form parentRequest (in Maven, this is done by MavenCli - also by * loading settings)./*from www . j a v a 2 s . co m*/ */ public void build(FileNode basedir, Map<String, String> userProperties, ExecutionListener theExecutionListener, FilteringMojoExecutor.Filter filter, String... goals) throws BuildException { DefaultPlexusContainer container; org.apache.maven.Maven maven; MavenExecutionRequest request; MavenExecutionResult result; BuildException exception; FilteringMojoExecutor mojoExecutor; request = DefaultMavenExecutionRequest.copy(parentSession.getRequest()); container = (DefaultPlexusContainer) parentSession.getContainer(); try { maven = container.lookup(org.apache.maven.Maven.class); } catch (ComponentLookupException e) { throw new IllegalStateException(e); } request.setPom(basedir.join("pom.xml").toPath().toFile()); request.setProjectPresent(true); request.setGoals(Arrays.asList(goals)); request.setBaseDirectory(basedir.toPath().toFile()); request.setUserProperties(merged(request.getUserProperties(), userProperties)); request.setExecutionListener(theExecutionListener); mojoExecutor = FilteringMojoExecutor.install(container, filter); log.info("[" + basedir + " " + filter + "] mvn " + props(request.getUserProperties()) + Separator.SPACE.join(goals)); nestedOutputOn(); try { result = maven.execute(request); } finally { nestedOutputOff(); mojoExecutor.uninstall(); } exception = null; for (Throwable e : result.getExceptions()) { if (exception == null) { exception = new BuildException("build failed: " + e, e); } else { exception.addSuppressed(e); } } if (exception != null) { throw exception; } }
From source file:org.appformer.maven.integration.embedder.MavenEmbedder.java
License:Apache License
protected MavenExecutionRequest buildMavenExecutionRequest(MavenRequest mavenRequest) throws MavenEmbedderException, ComponentLookupException { MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest(); if (mavenRequest.getGlobalSettingsFile() != null) { mavenExecutionRequest.setGlobalSettingsFile(new File(mavenRequest.getGlobalSettingsFile())); }/*from w w w . j av a2s. c o m*/ SettingsSource userSettings = mavenRequest.getUserSettingsSource(); if (userSettings != null) { if (userSettings instanceof FileSettingsSource) { mavenExecutionRequest.setUserSettingsFile(((FileSettingsSource) userSettings).getSettingsFile()); } else { try { mavenExecutionRequest.setUserSettingsFile(copyInTempFile(userSettings.getInputStream(), "xml")); } catch (IOException ioe) { log.warn("Unable to use maven settings defined in " + userSettings, ioe); } } } try { componentProvider.lookup(MavenExecutionRequestPopulator.class) .populateFromSettings(mavenExecutionRequest, getSettings()); componentProvider.lookup(MavenExecutionRequestPopulator.class).populateDefaults(mavenExecutionRequest); } catch (MavenExecutionRequestPopulationException e) { throw new MavenEmbedderException(e.getMessage(), e); } ArtifactRepository localRepository = getLocalRepository(); mavenExecutionRequest.setLocalRepository(localRepository); mavenExecutionRequest.setLocalRepositoryPath(localRepository.getBasedir()); mavenExecutionRequest.setOffline(mavenRequest.isOffline()); mavenExecutionRequest.setUpdateSnapshots(mavenRequest.isUpdateSnapshots()); // TODO check null and create a console one ? mavenExecutionRequest.setTransferListener(mavenRequest.getTransferListener()); mavenExecutionRequest.setCacheNotFound(mavenRequest.isCacheNotFound()); mavenExecutionRequest.setCacheTransferError(true); mavenExecutionRequest.setUserProperties(mavenRequest.getUserProperties()); mavenExecutionRequest.getSystemProperties().putAll(System.getProperties()); if (mavenRequest.getSystemProperties() != null) { mavenExecutionRequest.getSystemProperties().putAll(mavenRequest.getSystemProperties()); } mavenExecutionRequest.getSystemProperties().putAll(getEnvVars()); if (mavenRequest.getProfiles() != null && !mavenRequest.getProfiles().isEmpty()) { for (String id : mavenRequest.getProfiles()) { Profile p = new Profile(); p.setId(id); p.setSource("cli"); mavenExecutionRequest.addProfile(p); mavenExecutionRequest.addActiveProfile(id); } } MavenRepositoryConfiguration mavenRepoConf = getMavenRepositoryConfiguration(); //DROOLS-899: Copy repositories defined in settings to execution request for (ArtifactRepository artifactRepository : mavenRepoConf.getArtifactRepositoriesForRequest()) { mavenExecutionRequest.addRemoteRepository(artifactRepository); } mavenExecutionRequest.setProxies(mavenRepoConf.getProxies()); mavenExecutionRequest.setLoggingLevel(mavenRequest.getLoggingLevel()); componentProvider.lookup(Logger.class).setThreshold(mavenRequest.getLoggingLevel()); mavenExecutionRequest.setExecutionListener(mavenRequest.getExecutionListener()) .setInteractiveMode(mavenRequest.isInteractive()) .setGlobalChecksumPolicy(mavenRequest.getGlobalChecksumPolicy()).setGoals(mavenRequest.getGoals()); if (mavenRequest.getPom() != null) { mavenExecutionRequest.setPom(new File(mavenRequest.getPom())); } if (mavenRequest.getWorkspaceReader() != null) { mavenExecutionRequest.setWorkspaceReader(mavenRequest.getWorkspaceReader()); } return mavenExecutionRequest; }
From source file:org.eclipse.che.maven.server.MavenServerImpl.java
License:Open Source License
public MavenExecutionRequest newMavenRequest(File pom, List<String> activeProfiles, List<String> inactiveProfiles, List<String> goals) { MavenExecutionRequest request = new DefaultMavenExecutionRequest(); try {//ww w . j a v a 2 s. c o m getMavenComponent(MavenExecutionRequestPopulator.class).populateFromSettings(request, settings); request.setGoals(goals); request.setPom(pom); getMavenComponent(MavenExecutionRequestPopulator.class).populateDefaults(request); request.setSystemProperties(properties); request.setActiveProfiles(activeProfiles); request.setInactiveProfiles(inactiveProfiles); request.setStartTime(buildDate); return request; } catch (MavenExecutionRequestPopulationException e) { throw new RuntimeException(e); } }