List of usage examples for org.apache.maven.plugin MojoExecution MojoExecution
public MojoExecution(MojoDescriptor mojoDescriptor)
From source file:com.github.shyiko.sme.ServersExtension.java
License:Apache License
@Override public void afterProjectsRead(MavenSession session) throws MavenExecutionException { MojoExecution mojoExecution = new MojoExecution(new MojoDescriptor()); ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(session, mojoExecution); Properties userProperties = session.getUserProperties(); boolean exportAsSysProp = isExtensionProperty(session, "servers.exportAsSysProp"); Map<String, String> properties = new HashMap<String, String>(); try {//w w w .ja v a 2s . c o m for (Server server : session.getSettings().getServers()) { String serverId = server.getId(); for (String field : FIELDS) { String[] aliases = getAliases(serverId, field); String fieldNameWithFirstLetterCapitalized = upperCaseFirstLetter(field); String fieldValue = (String) Server.class.getMethod("get" + fieldNameWithFirstLetterCapitalized) .invoke(server); if (fieldValue != null) { fieldValue = decryptInlinePasswords(fieldValue); } for (String alias : aliases) { String userPropertyValue = userProperties.getProperty(alias); if (userPropertyValue != null) { fieldValue = userPropertyValue; break; } } String resolvedValue = (String) expressionEvaluator.evaluate(fieldValue); Server.class .getMethod("set" + fieldNameWithFirstLetterCapitalized, new Class[] { String.class }) .invoke(server, resolvedValue); if (resolvedValue != null) { for (String alias : aliases) { properties.put(alias, resolvedValue); } } } } if (exportAsSysProp) { System.getProperties().putAll(properties); } else { for (MavenProject project : session.getProjects()) { Properties projectProperties = project.getProperties(); projectProperties.putAll(properties); } } } catch (Exception e) { throw new MavenExecutionException("Failed to expose settings.servers.*", e); } }
From source file:com.github.spyhunter99.pdf.plugin.PdfMojo.java
License:Apache License
/** * @param mojoDescriptor not null// w w w. j a v a2s . co m * @return the MavenReport instance for the given mojoDescriptor. * @throws MojoExecutionException if any * @since 1.1 */ private MavenReport getMavenReport(MojoDescriptor mojoDescriptor) throws MojoExecutionException { ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread() .setContextClassLoader(mojoDescriptor.getPluginDescriptor().getClassRealm().getClassLoader()); MojoExecution mojoExecution = new MojoExecution(mojoDescriptor); return pluginManager.getReport(project, mojoExecution, session); } catch (ArtifactNotFoundException e) { throw new MojoExecutionException("ArtifactNotFoundException: " + e.getMessage(), e); } catch (ArtifactResolutionException e) { throw new MojoExecutionException("ArtifactResolutionException: " + e.getMessage(), e); } catch (PluginConfigurationException e) { throw new MojoExecutionException("PluginConfigurationException: " + e.getMessage(), e); } catch (PluginManagerException e) { throw new MojoExecutionException("PluginManagerException: " + e.getMessage(), e); } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } }
From source file:com.photon.maven.plugins.android.AbstractAndroidMojoTestCase.java
License:Apache License
/** * Copy the project specified into a temporary testing directory. Create the {@link MavenProject} and * {@link ManifestUpdateMojo}, configure it from the <code>plugin-config.xml</code> and return the created Mojo. * <p>/*from www .j a v a 2s . c o m*/ * Note: only configuration entries supplied in the plugin-config.xml are presently configured in the mojo returned. * That means and 'default-value' settings are not automatically injected by this testing framework (or plexus * underneath that is suppling this functionality) * * @param resourceProject * the name of the goal to look for in the <code>plugin-config.xml</code> that the configuration will be * pulled from. * @param resourceProject * the resourceProject path (in src/test/resources) to find the example/test project. * @return the created mojo (unexecuted) * @throws Exception * if there was a problem creating the mojo. */ protected T createMojo(String resourceProject) throws Exception { // Establish test details project example String testResourcePath = "src/test/resources/" + resourceProject; testResourcePath = FilenameUtils.separatorsToSystem(testResourcePath); File exampleDir = new File(getBasedir(), testResourcePath); Assert.assertTrue("Path should exist: " + exampleDir, exampleDir.exists()); // Establish the temporary testing directory. String testingPath = "target/tests/" + this.getClass().getSimpleName() + "." + getName(); testingPath = FilenameUtils.separatorsToSystem(testingPath); File testingDir = new File(getBasedir(), testingPath); if (testingDir.exists()) { FileUtils.cleanDirectory(testingDir); } else { Assert.assertTrue("Could not create directory: " + testingDir, testingDir.mkdirs()); } // Copy project example into temporary testing directory // to avoid messing up the good source copy, as mojo can change // the AndroidManifest.xml file. FileUtils.copyDirectory(exampleDir, testingDir); // Prepare MavenProject final MavenProject project = new MojoProjectStub(testingDir); // Setup Mojo PlexusConfiguration config = extractPluginConfiguration("android-maven-plugin", project.getFile()); @SuppressWarnings("unchecked") final T mojo = (T) lookupMojo(getPluginGoalName(), project.getFile()); // Inject project itself setVariableValueToObject(mojo, "project", project); // Configure the rest of the pieces via the PluginParameterExpressionEvaluator // - used for ${plugin.*} MojoDescriptor mojoDesc = new MojoDescriptor(); // - used for error messages in PluginParameterExpressionEvaluator mojoDesc.setGoal(getPluginGoalName()); MojoExecution mojoExec = new MojoExecution(mojoDesc); // - Only needed if we start to use expressions like ${settings.*}, ${localRepository}, ${reactorProjects} // MavenSession context = null; // Messy to declare, would rather avoid using it. // - Used for ${basedir} relative paths PathTranslator pathTranslator = new DefaultPathTranslator(); // - Declared to prevent NPE from logging events in maven core Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, mojo.getClass().getName()); MavenSession context = createMock(MavenSession.class); expect(context.getExecutionProperties()).andReturn(project.getProperties()); expect(context.getCurrentProject()).andReturn(project); replay(context); // Declare evalator that maven itself uses. ExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator(context, mojoExec, pathTranslator, logger, project, project.getProperties()); // Lookup plexus configuration component ComponentConfigurator configurator = (ComponentConfigurator) lookup(ComponentConfigurator.ROLE, "basic"); // Configure mojo using above ConfigurationListener listener = new DebugConfigurationListener(logger); configurator.configureComponent(mojo, config, evaluator, getContainer().getContainerRealm(), listener); return mojo; }
From source file:com.puppetlabs.geppetto.forge.maven.plugin.AbstractForgeTestMojo.java
License:Open Source License
protected MojoExecution newMojoExecution(String goal) { MojoDescriptor mojoDescriptor = getMojoDescriptors().get(goal); assertNotNull(mojoDescriptor);/* ww w. j a va 2 s. co m*/ MojoExecution execution = new MojoExecution(mojoDescriptor); finalizeMojoConfiguration(execution); return execution; }
From source file:io.takari.maven.testing.Maven30xRuntime.java
License:Open Source License
@Override public MojoExecution newMojoExecution(String goal) { MojoDescriptor mojoDescriptor = mojoDescriptors.get(goal); assertNotNull(String.format("The MojoDescriptor for the goal %s cannot be null.", goal), mojoDescriptor); MojoExecution execution = new MojoExecution(mojoDescriptor); execution.setConfiguration(new Xpp3Dom("configuration")); return execution; }
From source file:io.wcm.maven.plugins.cq.InstallMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException, MojoFailureException { Plugin plugin = new Plugin(); plugin.setGroupId("org.apache.sling"); plugin.setArtifactId("maven-sling-plugin"); plugin.setVersion(this.slingPluginVersion); try {//from w w w .j a v a 2 s .c om PluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptor(plugin, project.getRemotePluginRepositories(), session.getRepositorySession()); MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("install"); MojoExecution mojoExecution = new MojoExecution(pluginDescriptor.getMojo("install")); Xpp3Dom config = convertConfiguration(mojoDescriptor.getMojoConfiguration()); config.getChild("slingUrl").setValue(this.slingConsoleUrl); config.getChild("user").setValue(this.slingConsoleUser); config.getChild("password").setValue(this.slingConsolePassword); config.getChild("mountByFS").setValue("false"); mojoExecution.setConfiguration(config); buildPluginManager.executeMojo(session, mojoExecution); } catch (Throwable ex) { throw new MojoExecutionException("Faild to execute plugin: " + plugin, ex); } }
From source file:org.codehaus.gmaven.plugin.execute.ExpressionEvaluatorImpl.java
License:Apache License
public ExpressionEvaluatorImpl(final MavenSession context, final MavenProject project) { this.context = context; this.mojoExecution = new MojoExecution(new MojoDescriptor()); this.pathTranslator = lookupPathTranslator(); this.project = project; this.basedir = lookupBasedir(); }
From source file:org.codehaus.mojo.hibernate3.util.HibernateExpressionEvaluator.java
License:Apache License
public HibernateExpressionEvaluator(MavenSession session) { super(session, new MojoExecution(new MojoDescriptor()), new DefaultPathTranslator(), null, session.getCurrentProject(), session.getExecutionProperties()); }
From source file:org.dthume.maven.xpom.impl.XPOMUtil.java
License:Apache License
public static ExpressionEvaluator expressionEvaluatorForSession(final MavenSession session) { final MojoExecution execution = new MojoExecution(new MojoDescriptor()); final PluginParameterExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator(session, execution);/*from ww w . j a va 2 s. c o m*/ return new DefaultExpressionEvaluator(evaluator); }
From source file:org.dthume.maven.xpom.mojo.AbstractXPOMMojo.java
License:Apache License
protected final ExpressionEvaluator getExpressionEvaluator() { final MojoExecution execution = new MojoExecution(new MojoDescriptor()); final PluginParameterExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator(session, execution);//from w ww . j a v a 2 s .c o m return new DefaultExpressionEvaluator(evaluator); }