List of usage examples for org.apache.maven.project MavenProject getContextValue
public Object getContextValue(String key)
From source file:org.apache.sling.maven.slingstart.ProjectHelper.java
License:Apache License
/** * Get the effective model from the project * @param project The maven projet/* www. j av a 2 s. c om*/ * @return The effective model * @throws MojoExecutionException If reading fails */ public static Model getEffectiveModel(final MavenProject project, ResolverOptions resolverOptions) throws MojoExecutionException { Model result = (Model) project.getContextValue(EFFECTIVE_MODEL_CACHE); if (result == null) { try { final StringReader r = new StringReader((String) project.getContextValue(EFFECTIVE_MODEL_TXT)); result = ModelReader.read(r, project.getId()); result = ModelUtility.getEffectiveModel(result, resolverOptions); project.setContextValue(EFFECTIVE_MODEL_CACHE, result); } catch (final IOException ioe) { throw new MojoExecutionException(ioe.getMessage(), ioe); } } return result; }
From source file:org.apache.sling.maven.slingstart.ProjectHelper.java
License:Apache License
/** * Get the raw model from the project/*from ww w. j a va 2 s. c om*/ * @param project The maven projet * @return The raw local model * @throws MojoExecutionException If reading fails */ public static Model getRawModel(final MavenProject project) throws MojoExecutionException { Model result = (Model) project.getContextValue(RAW_MODEL_CACHE); if (result == null) { try { final StringReader r = new StringReader((String) project.getContextValue(RAW_MODEL_TXT)); result = ModelReader.read(r, project.getId()); project.setContextValue(RAW_MODEL_CACHE, result); } catch (final IOException ioe) { throw new MojoExecutionException(ioe.getMessage(), ioe); } } return result; }
From source file:org.apache.sling.maven.slingstart.ProjectHelper.java
License:Apache License
/** * Get the dependency model from the project * @param project The maven projet/*from w w w. j ava2 s . co m*/ * @return The dependency model * @throws MojoExecutionException If reading fails */ @SuppressWarnings("unchecked") public static Map<String, String> getDependencyModel(final MavenProject project) throws MojoExecutionException { return (Map<String, String>) project.getContextValue(DEPENDENCY_MODEL); }
From source file:org.eclipse.m2e.core.internal.embedder.MavenProjectMutableState.java
License:Open Source License
public static MavenProjectMutableState takeSnapshot(MavenProject project) { MavenProjectMutableState snapshot = new MavenProjectMutableState(); if (project.getContextValue(CTX_SNAPSHOT) == null) { snapshot.compileSourceRoots = new ArrayList<String>(project.getCompileSourceRoots()); snapshot.testCompileSourceRoots = new ArrayList<String>(project.getTestCompileSourceRoots()); snapshot.resources = new ArrayList<Resource>(project.getResources()); snapshot.testResources = new ArrayList<Resource>(project.getTestResources()); snapshot.properties = new Properties(); snapshot.properties.putAll(project.getProperties()); project.setContextValue(CTX_SNAPSHOT, Boolean.TRUE); snapshot.nested = false;//from w w w . j ava2 s. com } return snapshot; }
From source file:org.eclipse.tycho.core.osgitools.AbstractTychoProject.java
License:Open Source License
public TargetPlatform getTargetPlatform(MavenProject project) { return (TargetPlatform) project.getContextValue(TychoConstants.CTX_TARGET_PLATFORM); }
From source file:org.eclipse.tycho.core.osgitools.DefaultReactorProject.java
License:Open Source License
public static ReactorProject adapt(MavenProject project) { if (project == null) { return null; }/* w w w . j ava 2s. com*/ ReactorProject reactorProject = (ReactorProject) project.getContextValue(CTX_REACTOR_PROJECT); if (reactorProject == null) { reactorProject = new DefaultReactorProject(project); project.setContextValue(CTX_REACTOR_PROJECT, reactorProject); } return reactorProject; }
From source file:org.eclipse.tycho.core.osgitools.EquinoxResolver.java
License:Open Source License
protected Properties getPlatformProperties(MavenProject project) { TargetPlatformConfiguration configuration = TychoProjectUtils.getTargetPlatformConfiguration(project); TargetEnvironment environment = configuration.getEnvironments().get(0); Properties properties = new Properties(); properties.putAll((Properties) project.getContextValue(TychoConstants.CTX_MERGED_PROPERTIES)); return getPlatformProperties(properties, environment); }
From source file:org.eclipse.tycho.core.osgitools.OsgiBundleProject.java
License:Open Source License
public List<ClasspathEntry> getClasspath(MavenProject project) { @SuppressWarnings("unchecked") List<ClasspathEntry> classpath = (List<ClasspathEntry>) project .getContextValue(TychoConstants.CTX_ECLIPSE_PLUGIN_CLASSPATH); if (classpath == null) { throw new IllegalStateException(); }//from www.j a va 2s . co m return classpath; }
From source file:org.eclipse.tycho.core.osgitools.OsgiBundleProject.java
License:Open Source License
public List<ClasspathEntry.AccessRule> getBootClasspathExtraAccessRules(MavenProject project) { @SuppressWarnings("unchecked") List<ClasspathEntry.AccessRule> rules = (List<AccessRule>) project .getContextValue(TychoConstants.CTX_ECLIPSE_PLUGIN_BOOTCLASSPATH_EXTRA_ACCESSRULES); if (rules == null) { throw new IllegalStateException(); }/*from w w w. j a v a 2 s .c om*/ return rules; }
From source file:org.eclipse.tycho.core.osgitools.targetplatform.LocalDependencyResolver.java
License:Open Source License
private void addDependencies(MavenSession session, MavenProject project, DefaultDependencyArtifacts platform) { TargetPlatformConfiguration configuration = (TargetPlatformConfiguration) project .getContextValue(TychoConstants.CTX_TARGET_PLATFORM_CONFIGURATION); if (configuration != null && TargetPlatformConfiguration.POM_DEPENDENCIES_CONSIDER .equals(configuration.getPomDependencies())) { Map<String, MavenProject> projectIds = new HashMap<String, MavenProject>( session.getProjects().size() * 2); // make a list of reactor projects for (MavenProject p : session.getProjects()) { String key = ArtifactUtils.key(p.getGroupId(), p.getArtifactId(), p.getVersion()); projectIds.put(key, p);//from w ww. j a va 2s. c om } // handle dependencies that are in reactor for (Dependency dependency : project.getDependencies()) { if (Artifact.SCOPE_COMPILE.equals(dependency.getScope())) { String key = ArtifactUtils.key(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion()); if (projectIds.containsKey(key)) { MavenProject dependent = projectIds.get(key); ArtifactKey artifactKey = getArtifactKey(session, dependent); if (artifactKey != null) { platform.removeAll(artifactKey.getType(), artifactKey.getId()); ReactorProject projectProxy = DefaultReactorProject.adapt(dependent); platform.addReactorArtifact(artifactKey, projectProxy, null, null); if (getLogger().isDebugEnabled()) { getLogger().debug("Add Maven project " + artifactKey); } } } } } // handle rest of dependencies ArrayList<String> scopes = new ArrayList<String>(); scopes.add(Artifact.SCOPE_COMPILE); Collection<Artifact> artifacts; try { artifacts = projectDependenciesResolver.resolve(project, scopes, session); } catch (MultipleArtifactsNotFoundException e) { Collection<Artifact> missing = new HashSet<Artifact>(e.getMissingArtifacts()); for (Iterator<Artifact> it = missing.iterator(); it.hasNext();) { Artifact a = it.next(); String key = ArtifactUtils.key(a.getGroupId(), a.getArtifactId(), a.getBaseVersion()); if (projectIds.containsKey(key)) { it.remove(); } } if (!missing.isEmpty()) { throw new RuntimeException("Could not resolve project dependencies", e); } artifacts = e.getResolvedArtifacts(); artifacts.removeAll(e.getMissingArtifacts()); } catch (AbstractArtifactResolutionException e) { throw new RuntimeException("Could not resolve project dependencies", e); } for (Artifact artifact : artifacts) { String key = ArtifactUtils.key(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion()); if (!projectIds.containsKey(key)) { File plugin = artifact.getFile(); ArtifactKey artifactKey = getArtifactKey(session, plugin); if (artifactKey != null) { platform.addArtifactFile(artifactKey, plugin, null); if (getLogger().isDebugEnabled()) { getLogger().debug("Add Maven artifact " + artifactKey); } } } } } }