List of usage examples for org.apache.maven.plugin DebugConfigurationListener DebugConfigurationListener
public DebugConfigurationListener(Logger logger)
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>/*ww w . j a v a 2 s.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:org.phpmaven.core.ComponentFactory.java
License:Apache License
/** * Populates the plugin fields by using the given configuration. * @param component the component.//from w ww.j a v a 2 s . com * @param configuration the configuration. * @param expressionEvaluator the expression evaluator. * @param realm the class realm. * @throws PlexusConfigurationException thrown on configuration errors */ private void populatePluginFields(Object component, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator, ClassRealm realm) throws ComponentLookupException, PlexusConfigurationException { ComponentConfigurator configurator = null; try { configurator = this.plexusContainer.lookup(ComponentConfigurator.class, "php-maven"); final ConfigurationListener listener = new DebugConfigurationListener(this.logger); logger.debug( "Configuring component '" + component.getClass().getName() + "' with basic configurator -->"); configurator.configureComponent(component, configuration, expressionEvaluator, realm, listener); logger.debug("-- end configuration --"); } catch (ComponentConfigurationException e) { String message = "Unable to parse configuration of component " + component.getClass().getName(); if (e.getFailedConfiguration() != null) { message += " for parameter " + e.getFailedConfiguration().getName(); } message += ": " + e.getMessage(); throw new PlexusConfigurationException(message, e); } finally { if (configurator != null) { try { this.plexusContainer.release(configurator); } catch (ComponentLifecycleException e) { logger.debug("Failed to release component configurator - ignoring."); } } } }