List of usage examples for org.apache.maven.plugin PluginParameterExpressionEvaluator PluginParameterExpressionEvaluator
@Deprecated
public PluginParameterExpressionEvaluator(MavenSession session, MojoExecution mojoExecution,
PathTranslator pathTranslator, Logger logger, MavenProject project, Properties properties)
From source file:com.google.code.configprocessor.ConfigProcessorMojo.java
License:Apache License
/** * Creates a expression resolver to replace placeholders. * * @param replacePlaceholders True if placeholders must be replaced on output files. * @param additionalProperties//www .j a v a 2 s .c o m * @return Created ExpressionResolver. * @throws MojoExecutionException If processing cannot be performed. */ protected MavenExpressionResolver getExpressionResolver(boolean replacePlaceholders, Properties additionalProperties) throws MojoExecutionException { return new MavenExpressionResolver(new PluginParameterExpressionEvaluator(mavenSession, mojoExecution, new DefaultPathTranslator(), new ConsoleLogger(Logger.LEVEL_INFO, "ConfigProcessorMojo"), mavenProject, additionalProperties), replacePlaceholders); }
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 w w w .ja v a 2 s. com*/ * 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:org.sonatype.flexmojos.compiler.AbstractCompilerMojo.java
License:Apache License
@SuppressWarnings("deprecation") @FlexCompatibility(minVersion = "3") @IgnoreJRERequirement//from w w w. j a v a 2 s. c om private void addDefines() throws MojoExecutionException { ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(context, execution, null, null, project, project.getProperties()); if (defines != null) { if (definesDeclaration == null) { definesDeclaration = new Properties(); } definesDeclaration.putAll(defines); } if (definesDeclaration != null) { for (Object definekey : definesDeclaration.keySet()) { String defineName = definekey.toString(); String value = definesDeclaration.getProperty(defineName); if (value.contains("${")) { // Fix bug in maven which doesn't always evaluate ${} constructions try { value = (String) expressionEvaluator.evaluate(value); } catch (ExpressionEvaluationException e) { throw new MojoExecutionException("Expression error in " + defineName, e); } } getLog().debug("define " + defineName + " = " + value); configuration.addDefineDirective(defineName, value); } } }
From source file:org.sonatype.flexmojos.flexbuilder.FlexbuilderMojo.java
License:Open Source License
/** * Some compiler parameters don't work will or at all in the .actionScriptProperties. Rather than clutter up the * additionalCompilerAreguments more lets just write stuff to a config file. * //from www . j av a 2 s . c o m * @param packaging * @param ideDependencies * @throws MojoExecutionException */ protected VelocityContext getFlexConfigContext(ProjectType type, Collection<FbIdeDependency> ideDependencies) throws MojoExecutionException { VelocityContext context = new VelocityContext(); context.put("namespaces", namespaces); if (definesDeclaration != null) { ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(sessionContext, execution, null, null, project, project.getProperties()); for (Object definekey : definesDeclaration.keySet()) { String defineName = definekey.toString(); String value = definesDeclaration.getProperty(defineName); if (value.contains("${")) { // Fix bug in maven which doesn't always evaluate ${} // constructions try { value = (String) expressionEvaluator.evaluate(value); } catch (ExpressionEvaluationException e) { throw new MojoExecutionException("Expression error in " + defineName, e); } definesDeclaration.setProperty(defineName, value); } } context.put("defines", definesDeclaration); } context.put("metadatas", keepAs3Metadatas); if (SWF.equals(packaging) || AIR.equals(packaging)) { if (services != null) context.put("services", services.getAbsolutePath()); if (compatibilityVersion != null) context.put("compatibilityVersion", compatibilityVersion); if (keepAllTypeSelectors) context.put("keepAllTypeSelectors", keepAllTypeSelectors); context.put("defaultSizeWidth", defaultSizeWidth); context.put("defaultSizeHeight", defaultSizeHeight); List<String> dependentThemes = getThemes(ideDependencies); context.put("themes", dependentThemes); } // Locales need to be available in SWC projects so merge them in. context.put("locales", getLocales()); List<File> includedLibraries = getIncludedLibraries(ideDependencies); context.put("includeLibraries", includedLibraries); if (configFiles == null) configFiles = new ArrayList<File>(); configFiles.add(new File(this.project.getBasedir() + "/.flexConfig.xml")); return context; }
From source file:org.sonatype.flexmojos.flexbuilder.FlexbuilderMojo.java
License:Open Source License
protected void cleanDefinesDeclaration() throws MojoExecutionException { Properties clean = new Properties(); ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator(sessionContext, execution, null, null, project, project.getProperties()); for (Object definekey : definesDeclaration.keySet()) { String defineName = definekey.toString(); String value = definesDeclaration.getProperty(defineName); if (value.contains("${")) { // Fix bug in maven which doesn't always evaluate ${} // constructions try { value = (String) expressionEvaluator.evaluate(value); } catch (ExpressionEvaluationException e) { throw new MojoExecutionException("Expression error in " + defineName, e); }// www .j a v a 2 s. c o m } // Definition values should ben quoted if necessary, so not adding additional quoting here. clean.put(defineName, value); } definesDeclaration = clean; }