Example usage for org.apache.maven.project MavenProject setContextValue

List of usage examples for org.apache.maven.project MavenProject setContextValue

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject setContextValue.

Prototype

public void setContextValue(String key, Object value) 

Source Link

Document

Sets the value of the context value of this project identified by the given key.

Usage

From source file:org.eclipse.tycho.core.resolver.DefaultTychoDependencyResolver.java

License:Open Source License

public void setupProject(MavenSession session, MavenProject project, ReactorProject reactorProject) {
    AbstractTychoProject dr = (AbstractTychoProject) projectTypes.get(project.getPackaging());
    if (dr == null) {
        return;/*  www .j  a  va2 s. c  o m*/
    }

    // generic Eclipse/OSGi metadata

    dr.setupProject(session, project);

    // p2 metadata

    Properties properties = new Properties();
    properties.putAll(project.getProperties());
    properties.putAll(session.getSystemProperties()); // session wins
    properties.putAll(session.getUserProperties());
    project.setContextValue(TychoConstants.CTX_MERGED_PROPERTIES, properties);

    TargetPlatformConfiguration configuration = configurationReader.getTargetPlatformConfiguration(session,
            project);
    project.setContextValue(TychoConstants.CTX_TARGET_PLATFORM_CONFIGURATION, configuration);

    TargetPlatformResolver resolver = targetPlatformResolverLocator.lookupPlatformResolver(project);

    resolver.setupProjects(session, project, reactorProject);
}

From source file:org.eclipse.tycho.core.resolver.DefaultTychoResolver.java

License:Open Source License

@Override
public void setupProject(MavenSession session, MavenProject project, ReactorProject reactorProject) {
    AbstractTychoProject dr = (AbstractTychoProject) projectTypes.get(project.getPackaging());
    if (dr == null) {
        return;//w w w . j a  v  a 2s  .  c  om
    }

    // skip if setup was already done
    if (project.getContextValue(TychoConstants.CTX_MERGED_PROPERTIES) != null) {
        return;
    }

    // generic Eclipse/OSGi metadata

    dr.setupProject(session, project);

    // p2 metadata

    Properties properties = new Properties();
    properties.putAll(project.getProperties());
    properties.putAll(session.getSystemProperties()); // session wins
    properties.putAll(session.getUserProperties());
    project.setContextValue(TychoConstants.CTX_MERGED_PROPERTIES, properties);

    setTychoEnvironmentProperties(properties, project);

    TargetPlatformConfiguration configuration = configurationReader.getTargetPlatformConfiguration(session,
            project);
    project.setContextValue(TychoConstants.CTX_TARGET_PLATFORM_CONFIGURATION, configuration);

    ExecutionEnvironmentConfiguration eeConfiguration = new ExecutionEnvironmentConfigurationImpl(logger,
            !configuration.isResolveWithEEConstraints());
    dr.readExecutionEnvironmentConfiguration(project, eeConfiguration);
    project.setContextValue(TychoConstants.CTX_EXECUTION_ENVIRONMENT_CONFIGURATION, eeConfiguration);

    DependencyResolver resolver = dependencyResolverLocator.lookupDependencyResolver(project);
    resolver.setupProjects(session, project, reactorProject);
}

From source file:org.eclipse.tycho.plugins.p2.publisher.AbstractPublishMojo.java

License:Open Source License

/**
 * Adds the just published installable units into a shared list. The assemble-repository goal
 * eventually uses the units in that list as entry-points for mirroring content into the
 * assembly p2 repository./*from  ww  w. j a  v  a  2 s.c  o  m*/
 */
private void postPublishedIUs(Collection<?> units) {
    final MavenProject project = getProject();
    // TODO use own type for this
    List<Object> publishedIUs = (List<Object>) project.getContextValue(TychoConstants.CTX_PUBLISHED_ROOT_IUS);
    if (publishedIUs == null) {
        publishedIUs = new ArrayList<Object>();
        project.setContextValue(TychoConstants.CTX_PUBLISHED_ROOT_IUS, publishedIUs);
    }
    publishedIUs.addAll(units);
}

From source file:org.owasp.dependencycheck.maven.Engine.java

License:Apache License

/**
 * Runs the analyzers against all of the dependencies.
 *///w ww .j a v  a 2 s. c o m
@Override
public void analyzeDependencies() {
    final MavenProject root = getExecutionRoot();
    if (root != null) {
        LOGGER.debug("Checking root project, {}, if updates have already been completed", root.getArtifactId());
    } else {
        LOGGER.debug("Checking root project, null, if updates have already been completed");
    }
    if (root != null && root.getContextValue(UPDATE_EXECUTED_FLAG) != null) {
        System.setProperty(Settings.KEYS.AUTO_UPDATE, Boolean.FALSE.toString());
    }
    super.analyzeDependencies();
    if (root != null) {
        root.setContextValue(UPDATE_EXECUTED_FLAG, Boolean.TRUE);
    }
}

From source file:org.owasp.dependencycheck.maven.Engine.java

License:Apache License

/**
 * Stores a CPEAnalyzer in the root Maven Project.
 *
 * @param cpe the CPEAnalyzer to store/*from   w w w .j a  v  a2  s.c  o m*/
 */
private void storeCPEAnalyzer(CPEAnalyzer cpe) {
    final MavenProject p = getExecutionRoot();
    if (p != null) {
        p.setContextValue(CPE_ANALYZER_KEY, cpe);
    }
}

From source file:org.owasp.dependencycheck.maven.MavenEngine.java

License:Apache License

/**
 * Runs the analyzers against all of the dependencies.
 *
 * @throws ExceptionCollection thrown if an exception occurred; contains a
 * collection of exceptions that occurred during analysis.
 *//* w  w w  .ja va  2  s . c o m*/
@Override
public void analyzeDependencies() throws ExceptionCollection {
    final MavenProject root = getExecutionRoot();
    if (root != null) {
        LOGGER.debug("Checking root project, {}, if updates have already been completed", root.getArtifactId());
    } else {
        LOGGER.debug("Checking root project, null, if updates have already been completed");
    }
    if (root != null && root.getContextValue(UPDATE_EXECUTED_FLAG) != null) {
        System.setProperty(Settings.KEYS.AUTO_UPDATE, Boolean.FALSE.toString());
    }
    super.analyzeDependencies();
    if (root != null) {
        root.setContextValue(UPDATE_EXECUTED_FLAG, Boolean.TRUE);
    }
}

From source file:org.reficio.p2.TychoFeatureBuilder.java

License:Open Source License

public void execute() throws MojoExecutionException, IOException {
    MavenProject mp = new MavenProject();
    mp.getModel().setGroupId(this.mavenProject.getGroupId());
    mp.getModel().setArtifactId(featureId);
    mp.getModel().setVersion(featureVersion);
    mp.getModel().setPackaging("eclipse-feature");
    mp.setPluginArtifactRepositories(this.mavenProject.getPluginArtifactRepositories());
    mp.setFile(featureFile); //sets the basedir for the MavenProject
    org.eclipse.tycho.artifacts.DependencyArtifacts da = new DefaultTargetPlatform();
    mp.setContextValue(TychoConstants.CTX_DEPENDENCY_ARTIFACTS, da);
    mavenSession.setCurrentProject(mp);/* w  w w .j av a2s . co m*/
    executeMojo(
            plugin(groupId("org.eclipse.tycho"), artifactId("tycho-packaging-plugin"), version(TYCHO_VERSION)),
            goal("package-feature"),
            configuration(element(name("finalName"), this.featureId + "_" + this.featureVersion + ".jar"),
                    element(name("basedir"), this.featureFile.getParent()),
                    element(name("outputDirectory"), outputDirectory)),
            executionEnvironment(mp, mavenSession, buildPluginManager));

}

From source file:org.sourcepit.b2.internal.maven.B2BootstrapParticipant.java

License:Apache License

public void beforeBuild(MavenSession bootSession, final MavenProject bootProject, MavenSession actualSession) {
    LOGGER.info("");
    LOGGER.info("------------------------------------------------------------------------");
    LOGGER.info("Bootstrapping " + bootProject.getName() + " " + bootProject.getVersion());
    LOGGER.info("------------------------------------------------------------------------");

    final List<File> projectDirs = new ArrayList<File>();
    for (MavenProject project : bootSession.getProjects()) {
        projectDirs.add(project.getBasedir());
    }//w ww  .j  av  a  2s  .c o  m

    final int idx = bootSession.getProjects().indexOf(bootProject);
    checkState(idx > -1);

    final B2Request b2Request = b2RequestFactory.newRequest(projectDirs, idx);

    final AbstractModule module = b2LifecycleRunner.prepareNext(projectDirs, idx, b2Request);
    bootProject.setContextValue(AbstractModule.class.getName(), module);
    bootProject.setContextValue(ModuleDirectory.class.getName(), b2Request.getModuleDirectory());
}

From source file:org.sourcepit.b2.internal.maven.MavenB2LifecycleParticipant.java

License:Apache License

public void postPrepareProject(File project, B2Request request, AbstractModule module, ThrowablePipe errors) {
    final ModuleDirectory moduleDirectory = request.getModuleDirectory();
    ModuleDirectory.save(moduleDirectory, newFile(module, "moduleDirectory.properties"));

    final MavenProject bootProject = legacySupport.getSession().getCurrentProject();

    final ModelContext modelContext = ModelContextAdapterFactory.get(bootProject);
    final ResourceSet resourceSet = modelContext.getResourceSet();

    Resource moduleResource = resourceSet.createResource(modelContext.getModuleUri());
    moduleResource.getContents().add(module);
    try {/* w w  w .  ja v a 2  s .  co  m*/
        moduleResource.save(null);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }

    final File pomFile = new File(
            module.getAnnotationData(AbstractPomGenerator.SOURCE_MAVEN, AbstractPomGenerator.KEY_POM_FILE));

    bootProject.setContextValue("pom", pomFile);

    PropertiesMap uriMap = new LinkedPropertiesMap();
    for (Entry<URI, URI> entry : resourceSet.getURIConverter().getURIMap().entrySet()) {
        uriMap.put(entry.getKey().toString(), entry.getValue().toString());
    }
    uriMap.store(newFile(module, "uriMap.properties"));

    final URI fileURI = resourceSet.getURIConverter().normalize(modelContext.getModuleUri());
    projectHelper.attachArtifact(bootProject, "module", null, new File(fileURI.toFileString()));

    processAttachments(bootProject, pomFile);
}

From source file:org.sourcepit.b2.internal.maven.MavenB2RequestFactory.java

License:Apache License

private void processDependencies(ResourceSet resourceSet, MavenSession mavenSession,
        final MavenProject wrapperProject) {
    final ModelContext modelContext = ModelContextAdapterFactory.get(wrapperProject);

    SetMultimap<AbstractModule, FeatureProject> foo = LinkedHashMultimap.create();
    foo.putAll(modelContext.getMainScope());
    foo.putAll(modelContext.getTestScope());

    final Map<String, String> sites = new LinkedHashMap<String, String>();

    for (Entry<AbstractModule, Collection<FeatureProject>> entry : foo.asMap().entrySet()) {
        ArtifactIdentifier id = toArtifactId(entry.getKey().eResource().getURI());

        MavenProject mavenProject = findMavenProject(mavenSession, entry.getKey().getDirectory());
        if (mavenProject == null) {
            // TODO move test sites to test projects
            for (FeatureProject featureProject : entry.getValue()) {
                List<String> classifiers = B2MetadataUtils.getAssemblyClassifiers(featureProject);
                for (String classifier : classifiers) {
                    final Artifact siteArtifact = resolveSiteZip(wrapperProject, id, classifier);
                    final File zipFile = siteArtifact.getFile();

                    final String path = zipFile.getAbsolutePath().replace('\\', '/');
                    final String siteUrl = "jar:file:" + path + "!/";

                    final ArtifactIdentifier uniqueId = new ArtifactIdentifier(id.getGroupId(),
                            id.getArtifactId(), id.getVersion(), classifier, id.getType());

                    sites.put(uniqueId.toString().replace(':', '_'), siteUrl);

                    LOGGER.info("Using site " + siteUrl);
                }/*  w ww  .j  a va2  s .c om*/
            }
        }
    }

    wrapperProject.setContextValue("b2.resolvedSites", sites);
}