List of usage examples for org.apache.maven.execution MavenExecutionRequest setUserProperties
MavenExecutionRequest setUserProperties(Properties userProperties);
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 . ja v a 2 s . c om*/ } // 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();/* www.j ava 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())); }/* w ww . j a 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.ja v a 2s .c o 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 ww w .ja v a 2 s . co 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.m2e.core.ui.internal.wizards.MavenInstallFileWizard.java
License:Open Source License
public boolean performFinish() { final Properties properties = new Properties(); // Mandatory Properties for install:install-file properties.setProperty("file", artifactPage.getArtifactFileName()); //$NON-NLS-1$ properties.setProperty("groupId", artifactPage.getGroupId()); //$NON-NLS-1$ properties.setProperty("artifactId", artifactPage.getArtifactId()); //$NON-NLS-1$ properties.setProperty("version", artifactPage.getVersion()); //$NON-NLS-1$ properties.setProperty("packaging", artifactPage.getPackaging()); //$NON-NLS-1$ if (artifactPage.getClassifier().length() > 0) { properties.setProperty("classifier", artifactPage.getClassifier()); //$NON-NLS-1$ }/* w w w.j a va2 s .c o m*/ if (artifactPage.getPomFileName().length() > 0) { properties.setProperty("pomFile", artifactPage.getPomFileName()); //$NON-NLS-1$ } if (artifactPage.isGeneratePom()) { properties.setProperty("generatePom", "true"); //$NON-NLS-1$ //$NON-NLS-2$ } if (artifactPage.isCreateChecksum()) { properties.setProperty("createChecksum", "true"); //$NON-NLS-1$ //$NON-NLS-2$ } new Job(Messages.MavenInstallFileWizard_job) { protected IStatus run(IProgressMonitor monitor) { setProperty(IProgressConstants.ACTION_PROPERTY, new OpenMavenConsoleAction()); try { // Run the install:install-file goal IMaven maven = MavenPlugin.getMaven(); MavenExecutionRequest request = maven.createExecutionRequest(monitor); request.setGoals(Arrays.asList("install:install-file")); //$NON-NLS-1$ request.setUserProperties(properties); MavenExecutionResult executionResult = maven.execute(request, monitor); List<Throwable> exceptions = executionResult.getExceptions(); if (!exceptions.isEmpty()) { for (Throwable exception : exceptions) { String msg = Messages.MavenInstallFileWizard_error; msg += "; " + exception.toString(); //$NON-NLS-1$ log.error(msg, exception); } } // TODO update index for local maven repository } catch (CoreException ex) { log.error("Failed to install artifact:" + ex.getMessage(), ex); } return Status.OK_STATUS; } }.schedule(); return true; }
From source file:org.eclipse.tycho.testing.AbstractTychoMojoTestCase.java
License:Open Source License
protected MavenExecutionRequest newMavenExecutionRequest(File pom) throws Exception { Properties systemProps = new Properties(); systemProps.putAll(System.getProperties()); Properties userProps = new Properties(); userProps.put("tycho-version", "0.0.0"); MavenExecutionRequest request = new DefaultMavenExecutionRequest(); request.setBaseDirectory(pom.getParentFile()); request.setPom(pom);/* w ww. j av a 2 s. c om*/ request.setSystemProperties(systemProps); request.setUserProperties(userProps); request.setLocalRepository(getLocalRepository()); request.setGoals(Arrays.asList("validate")); return request; }
From source file:org.jboss.shrinkwrap.resolver.plugin.PropagateExecutionContextMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException { MavenExecutionRequest request = session.getRequest(); Properties properties = request.getUserProperties(); // set pom file File pom = session.getCurrentProject().getFile(); if (pom != null) { updateUserProperty(properties, "pom-file", pom.getAbsolutePath()); }//from ww w . j a v a 2 s . c o m // set offline flag updateUserProperty(properties, "offline", String.valueOf(session.isOffline())); // set settings.xml files File userSettings = request.getUserSettingsFile(); if (userSettings != null) { updateUserProperty(properties, "user-settings", userSettings.getAbsolutePath()); } File globalSettings = request.getGlobalSettingsFile(); if (globalSettings != null) { updateUserProperty(properties, "global-settings", globalSettings.getAbsolutePath()); } // set active profiles List<Profile> profiles = session.getCurrentProject().getActiveProfiles(); StringBuilder sb = new StringBuilder(); for (Profile p : profiles) { sb.append(p.getId()).append(","); } if (sb.length() > 0) { updateUserProperty(properties, "active-profiles", sb.substring(0, sb.length() - 1).toString()); } request.setUserProperties(properties); }
From source file:org.jboss.tools.maven.polyglot.poc.internal.core.PomTranslatorJob.java
License:Open Source License
protected MavenExecutionResult translate(IFile pom, IFile input, IFile output, IProgressMonitor monitor) throws CoreException { final IMaven maven = MavenPlugin.getMaven(); IMavenExecutionContext context = maven.createExecutionContext(); final MavenExecutionRequest request = context.getExecutionRequest(); File pomFile = pom.getRawLocation().toFile(); request.setBaseDirectory(pomFile.getParentFile()); request.setGoals(Arrays.asList("io.takari.polyglot:polyglot-translate-plugin:translate")); request.setUpdateSnapshots(false);/* w ww . j a v a 2 s . com*/ Properties props = new Properties(); props.put("input", input.getRawLocation().toOSString()); String rawDestination = output.getRawLocation().toOSString(); props.put("output", rawDestination); request.setUserProperties(props); new File(rawDestination).getParentFile().mkdirs(); MavenExecutionResult result = context.execute(new ICallable<MavenExecutionResult>() { public MavenExecutionResult call(IMavenExecutionContext context, IProgressMonitor innerMonitor) throws CoreException { return ((MavenImpl) maven).lookupComponent(Maven.class).execute(request); } }, monitor); output.refreshLocal(IResource.DEPTH_ZERO, monitor); return result; }
From source file:org.kie.scanner.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 ww . ja v a 2s.c o m 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()); } return mavenExecutionRequest; }