Example usage for org.apache.maven.execution MavenSession getExecutionProperties

List of usage examples for org.apache.maven.execution MavenSession getExecutionProperties

Introduction

In this page you can find the example usage for org.apache.maven.execution MavenSession getExecutionProperties.

Prototype

@Deprecated
public Properties getExecutionProperties() 

Source Link

Usage

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. java2 s.c  om*/
 * 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:kr.motd.maven.os.DetectExtension.java

License:Apache License

private void injectSession(MavenSession session, Map<String, String> dict) throws MavenExecutionException {
    Properties sessionExecProps = session.getExecutionProperties();
    sessionExecProps.put(Detector.DETECTED_NAME, dict.get(Detector.DETECTED_NAME));
    sessionExecProps.put(Detector.DETECTED_ARCH, dict.get(Detector.DETECTED_ARCH));
    sessionExecProps.put(Detector.DETECTED_CLASSIFIER, dict.get(Detector.DETECTED_CLASSIFIER));

    // Work around the 'NoClassDefFoundError' or 'ClassNotFoundException' related with Aether in IntelliJ IDEA.
    for (StackTraceElement e : new Exception().getStackTrace()) {
        if (String.valueOf(e.getClassName()).startsWith("org.jetbrains.idea.maven")) {
            return;
        }/*from w  w w.ja v a2 s.c  o  m*/
    }

    // Injection of RepositorySession is done in a separate class so that the extension is not impacted by
    // the case where the runtime does not have Aether.
    RepositorySessionInjector.injectRepositorySession(logger, session, dict);
}

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.nanoko.coffee.mill.utils.ReactorUtils.java

License:Apache License

public static void addWatcherToSession(WatchMojo watcher, MavenSession session) {
    List<WatchMojo> watchers = (List<WatchMojo>) session.getExecutionProperties().get("watchers");
    if (watchers == null) {
        watchers = new ArrayList<WatchMojo>();
        session.getExecutionProperties().put("watchers", watchers);
    }/*from  w w w.j  a  va 2s  .  c  o m*/
    watchers.add(watcher);
}

From source file:org.nanoko.coffee.mill.utils.ReactorUtils.java

License:Apache License

public static List<WatchMojo> getWatchersFromSession(MavenSession session) {
    List<WatchMojo> watchers = (List<WatchMojo>) session.getExecutionProperties().get("watchers");
    if (watchers == null) {
        return new ArrayList<WatchMojo>();
    } else {//  w  ww.  ja v a 2s  .  c om
        return watchers;
    }
}

From source file:org.opencredo.maven.plugins.enforcer.EnforcerExpressionEvaluator.java

License:Apache License

/**
 * The Constructor./*  www  .j a  va 2s.  c o  m*/
 *
 * @param theContext the the context
 * @param thePathTranslator the the path translator
 * @param theProject the the project
 */
public EnforcerExpressionEvaluator(MavenSession theContext, PathTranslator thePathTranslator,
        MavenProject theProject) {
    super(theContext, new MojoExecution(new MojoDescriptor()), thePathTranslator, null, theProject,
            theContext.getExecutionProperties());
}

From source file:org.teatrove.maven.plugins.teacompiler.contextclassbuilder.TeaCompilerExpressionEvaluator.java

License:Apache License

/**
 * The Constructor.//from  ww  w. j a va  2s. co m
 *
 * @param context the the context
 * @param pathTranslator the the path translator
 * @param project the the project
 */
public TeaCompilerExpressionEvaluator(MavenSession context, PathTranslator pathTranslator,
        MavenProject project) {
    super(context, new MojoExecution(new MojoDescriptor()), pathTranslator, null, project,
            context.getExecutionProperties());
}

From source file:org.wisdom.maven.pipeline.Watchers.java

License:Apache License

/**
 * Gets the list of watchers from the given MavenSession.
 *
 * @param session the Maven session/*from   w  w w .  j  a v a2 s.  com*/
 * @return the list of watcher, empty if none. Modifying the resulting list, updates the stored list.
 */
static synchronized List<Watcher> get(MavenSession session) {
    List<Watcher> watchers = (List<Watcher>) session.getExecutionProperties().get(WATCHERS_KEY);
    if (watchers == null) {
        watchers = new ArrayList<>();
        session.getExecutionProperties().put(WATCHERS_KEY, watchers);
    }
    return watchers;
}