List of usage examples for org.apache.maven.project MavenProject getName
public String getName()
From source file:org.openspaces.maven.plugin.Utils.java
License:Apache License
/** * Gets a list of projects and returns only those that are PU. * * @param projects a list of projects.//from ww w. j a v a 2 s. com * @return a list of projects and returns only those that are PU. */ static List getProjectsToExecute(List projects, String moduleName) { List puProjects = new ArrayList(); Iterator i = projects.iterator(); while (i.hasNext()) { MavenProject proj = (MavenProject) i.next(); if (Utils.isPUType(proj) && (moduleName == null || moduleName.equals(proj.getName()))) { puProjects.add(proj); } } return puProjects; }
From source file:org.ops4j.pax.construct.project.ImportBundleMojo.java
License:Apache License
/** * Add bundle as a dependency to the provisioning POM and the local bundle POM, as appropriate * /* www.j a va 2s.com*/ * @param project bundle project */ private void importBundle(MavenProject project) { Dependency dependency = new Dependency(); dependency.setGroupId(project.getGroupId()); dependency.setArtifactId(project.getArtifactId()); dependency.setVersion(project.getVersion()); dependency.setOptional(!deploy); // only add non-local bundles to the provisioning POM if (m_provisionPom != null && project.getFile() == null) { getLog().info("Importing " + project.getName() + " to " + m_provisionPom); m_provisionPom.addDependency(dependency, overwrite); } if (m_localBundlePom != null) { // use provided scope when adding to bundle pom dependency.setScope(Artifact.SCOPE_PROVIDED); getLog().info("Adding " + project.getName() + " as dependency to " + m_localBundlePom); m_localBundlePom.addDependency(dependency, overwrite); } }
From source file:org.overlord.commons.maven.plugin.GenerateFeaturesXmlMojo.java
License:Apache License
/** * Format the given artifact as a bundle string with the appropriate syntax * used by the karaf features.xml file. For example: * //from w ww . java 2 s . co m * mvn:commons-configuration/commons-configuration/1.6 * * @param artifact */ private String formatArtifactAsBundle(Artifact artifact) throws Exception { StringBuilder builder = new StringBuilder(); // If it's a bundle already, awesome. If not, we need to wrap it // and include some useful meta-data. if (isBundle(artifact)) { // Example: mvn:commons-configuration/commons-configuration/1.6 builder.append("mvn:"); //$NON-NLS-1$ builder.append(artifact.getGroupId()); builder.append("/"); //$NON-NLS-1$ builder.append(artifact.getArtifactId()); builder.append("/"); //$NON-NLS-1$ builder.append(artifact.getBaseVersion()); if (!"jar".equalsIgnoreCase(artifact.getType())) { //$NON-NLS-1$ builder.append("/"); //$NON-NLS-1$ builder.append(artifact.getType()); } } else { // Example: wrap:mvn:log4j/log4j/1.2.14$Bundle-SymbolicName=log4j.log4j&Bundle-Version=1.2.14&Bundle-Name=Log4j builder.append("wrap:mvn:"); //$NON-NLS-1$ builder.append(artifact.getGroupId()); builder.append("/"); //$NON-NLS-1$ builder.append(artifact.getArtifactId()); builder.append("/"); //$NON-NLS-1$ builder.append(artifact.getBaseVersion()); if (!"jar".equalsIgnoreCase(artifact.getType())) { //$NON-NLS-1$ builder.append("/"); //$NON-NLS-1$ builder.append(artifact.getType()); } MavenProject project = resolveProject(artifact); builder.append("$Bundle-SymbolicName="); //$NON-NLS-1$ builder.append(artifact.getGroupId()); builder.append("."); //$NON-NLS-1$ builder.append(artifact.getArtifactId()); builder.append("&Bundle-Version="); //$NON-NLS-1$ builder.append(sanitizeVersionForOsgi(artifact.getBaseVersion())); if (project.getName() != null && project.getName().trim().length() > 0) { builder.append("&Bundle-Name="); //$NON-NLS-1$ builder.append(project.getName()); } } return builder.toString(); }
From source file:org.overlord.sramp.integration.java.artifactbuilder.MavenPomArtifactBuilder.java
License:Apache License
@Override public ArtifactBuilder buildArtifacts(BaseArtifactType primaryArtifact, ArtifactContent artifactContent) throws IOException { super.buildArtifacts(primaryArtifact, artifactContent); try {//www . j a va 2 s . c om Model model = new MavenXpp3Reader().read(getContentStream()); MavenProject project = new MavenProject(model); ((ExtendedDocument) primaryArtifact).setExtendedType(JavaModel.TYPE_MAVEN_POM_XML); for (String key : project.getProperties().stringPropertyNames()) { String value = project.getProperties().getProperty(key); SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PROPERTY + key, value); } //set core properties when not specified on the request if (primaryArtifact.getDescription() == null) primaryArtifact.setDescription(project.getDescription()); if (primaryArtifact.getName() == null) primaryArtifact.setName(project.getName()); if (primaryArtifact.getVersion() == null) primaryArtifact.setVersion(project.getVersion()); //set the GAV and packaging info SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_ARTIFACT_ID, model.getArtifactId()); SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_GROUP_ID, model.getGroupId()); SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_VERSION, model.getVersion()); SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PACKAGING, model.getPackaging()); //set the parent GAV info if (model.getParent() != null) { SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PARENT_ARTIFACT_ID, model.getParent().getArtifactId()); SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PARENT_GROUP_ID, model.getParent().getGroupId()); SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PARENT_VERSION, model.getParent().getVersion()); } return this; } catch (XmlPullParserException e) { throw new IOException(e.getMessage(), e); } }
From source file:org.overlord.sramp.integration.java.deriver.MavenPomDeriver.java
License:Apache License
/** * @see org.overlord.sramp.common.derived.ArtifactDeriver#derive(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.BaseArtifactType, java.io.InputStream) *//*from ww w .j a v a 2 s .c o m*/ @Override public Collection<BaseArtifactType> derive(BaseArtifactType artifact, InputStream contentStream) throws IOException { List<BaseArtifactType> derivedArtifacts = new ArrayList<BaseArtifactType>(); try { Model model = new MavenXpp3Reader().read(contentStream); MavenProject project = new MavenProject(model); ((ExtendedDocument) artifact).setExtendedType(JavaModel.TYPE_MAVEN_POM_XML); for (String key : project.getProperties().stringPropertyNames()) { String value = project.getProperties().getProperty(key); SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_PROPERTY + key, value); } //set core properties when not specified on the request if (artifact.getDescription() == null) artifact.setDescription(project.getDescription()); if (artifact.getName() == null) artifact.setName(project.getName()); if (artifact.getVersion() == null) artifact.setVersion(project.getVersion()); //set the GAV and packaging info SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_ARTIFACT_ID, model.getArtifactId()); SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_GROUP_ID, model.getGroupId()); SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_VERSION, model.getVersion()); SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_PACKAGING, model.getPackaging()); //set the parent GAV info if (model.getParent() != null) { SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_PARENT_ARTIFACT_ID, model.getParent().getArtifactId()); SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_PARENT_GROUP_ID, model.getParent().getGroupId()); SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_PARENT_VERSION, model.getParent().getVersion()); } } catch (XmlPullParserException e) { throw new IOException(e.getMessage(), e); } return derivedArtifacts; }
From source file:org.owasp.dependencycheck.maven.AggregateMojo.java
License:Apache License
/** * Returns a set containing all the descendant projects of the given * project.// w w w.ja v a2 s. co m * * @param project the project for which all descendants will be returned * @return the set of descendant projects */ protected Set<MavenProject> getDescendants(MavenProject project) { if (project == null) { return Collections.emptySet(); } final Set<MavenProject> descendants = new HashSet<>(); int size; if (getLog().isDebugEnabled()) { getLog().debug(String.format("Collecting descendants of %s", project.getName())); } for (String m : project.getModules()) { for (MavenProject mod : getReactorProjects()) { try { File mpp = new File(project.getBasedir(), m); mpp = mpp.getCanonicalFile(); if (mpp.compareTo(mod.getBasedir()) == 0 && descendants.add(mod) && getLog().isDebugEnabled()) { getLog().debug(String.format("Descendant module %s added", mod.getName())); } } catch (IOException ex) { if (getLog().isDebugEnabled()) { getLog().debug("Unable to determine module path", ex); } } } } do { size = descendants.size(); for (MavenProject p : getReactorProjects()) { if (project.equals(p.getParent()) || descendants.contains(p.getParent())) { if (descendants.add(p) && getLog().isDebugEnabled()) { getLog().debug(String.format("Descendant %s added", p.getName())); } for (MavenProject modTest : getReactorProjects()) { if (p.getModules() != null && p.getModules().contains(modTest.getName()) && descendants.add(modTest) && getLog().isDebugEnabled()) { getLog().debug(String.format("Descendant %s added", modTest.getName())); } } } final Set<MavenProject> addedDescendants = new HashSet<>(); for (MavenProject dec : descendants) { for (String mod : dec.getModules()) { try { File mpp = new File(dec.getBasedir(), mod); mpp = mpp.getCanonicalFile(); if (mpp.compareTo(p.getBasedir()) == 0) { addedDescendants.add(p); } } catch (IOException ex) { if (getLog().isDebugEnabled()) { getLog().debug("Unable to determine module path", ex); } } } } for (MavenProject addedDescendant : addedDescendants) { if (descendants.add(addedDescendant) && getLog().isDebugEnabled()) { getLog().debug(String.format("Descendant module %s added", addedDescendant.getName())); } } } } while (size != 0 && size != descendants.size()); if (getLog().isDebugEnabled()) { getLog().debug(String.format("%s has %d children", project, descendants.size())); } return descendants; }
From source file:org.owasp.dependencycheck.maven.BaseDependencyCheckMojo.java
License:Apache License
/** * Scans the project's artifacts and adds them to the engine's dependency * list./*from w ww . j a v a 2s.c o m*/ * * @param project the project to scan the dependencies of * @param engine the engine to use to scan the dependencies * @return a collection of exceptions that may have occurred while resolving * and scanning the dependencies */ protected ExceptionCollection scanArtifacts(MavenProject project, Engine engine) { try { final DependencyNode dn = dependencyGraphBuilder.buildDependencyGraph(project, null, reactorProjects); final ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest(); return collectDependencies(engine, project, dn.getChildren(), buildingRequest); } catch (DependencyGraphBuilderException ex) { final String msg = String.format("Unable to build dependency graph on project %s", project.getName()); getLog().debug(msg, ex); return new ExceptionCollection(msg, ex); } }
From source file:org.owasp.dependencycheck.maven.BaseDependencyCheckMojo.java
License:Apache License
/** * Resolves the projects artifacts using Aether and scans the resulting * dependencies.//from ww w .j a va2s . co m * * @param engine the core dependency-check engine * @param project the project being scanned * @param nodes the list of dependency nodes, generally obtained via the * DependencyGraphBuilder * @param buildingRequest the Maven project building request * @return a collection of exceptions that may have occurred while resolving * and scanning the dependencies */ private ExceptionCollection collectDependencies(Engine engine, MavenProject project, List<DependencyNode> nodes, ProjectBuildingRequest buildingRequest) { ExceptionCollection exCol = null; for (DependencyNode dependencyNode : nodes) { exCol = collectDependencies(engine, project, dependencyNode.getChildren(), buildingRequest); if (excludeFromScan(dependencyNode.getArtifact().getScope())) { continue; } try { final ArtifactCoordinate coordinate = TransferUtils .toArtifactCoordinate(dependencyNode.getArtifact()); final Artifact result = artifactResolver.resolveArtifact(buildingRequest, coordinate).getArtifact(); if (result.isResolved() && result.getFile() != null) { final List<Dependency> deps = engine.scan(result.getFile().getAbsoluteFile(), project.getName() + ":" + dependencyNode.getArtifact().getScope()); if (deps != null) { if (deps.size() == 1) { final Dependency d = deps.get(0); if (d != null) { final MavenArtifact ma = new MavenArtifact(result.getGroupId(), result.getArtifactId(), result.getVersion()); d.addAsEvidence("pom", ma, Confidence.HIGHEST); if (getLog().isDebugEnabled()) { getLog().debug(String.format("Adding project reference %s on dependency %s", project.getName(), d.getDisplayFileName())); } } } else if (getLog().isDebugEnabled()) { final String msg = String.format( "More than 1 dependency was identified in first pass scan of '%s' in project %s", dependencyNode.getArtifact().getId(), project.getName()); getLog().debug(msg); } } else { final String msg = String.format("Error resolving '%s' in project %s", dependencyNode.getArtifact().getId(), project.getName()); if (exCol == null) { exCol = new ExceptionCollection(); } getLog().error(msg); } } else { final String msg = String.format("Unable to resolve '%s' in project %s", dependencyNode.getArtifact().getId(), project.getName()); getLog().debug(msg); if (exCol == null) { exCol = new ExceptionCollection(); } } } catch (ArtifactResolverException ex) { if (exCol == null) { exCol = new ExceptionCollection(); } exCol.addException(ex); } } return exCol; }
From source file:org.owasp.dependencycheck.maven.BaseDependencyCheckMojo.java
License:Apache License
/** * Generates the reports for a given dependency-check engine. * * @param engine a dependency-check engine * @param p the Maven project//from w w w . jav a2s.co m * @param outputDir the directory path to write the report(s) * @throws ReportException thrown if there is an error writing the report */ protected void writeReports(Engine engine, MavenProject p, File outputDir) throws ReportException { DatabaseProperties prop = null; try (CveDB cve = CveDB.getInstance()) { prop = cve.getDatabaseProperties(); } catch (DatabaseException ex) { //TODO shouldn't this throw an exception? if (getLog().isDebugEnabled()) { getLog().debug("Unable to retrieve DB Properties", ex); } } final ReportGenerator r = new ReportGenerator(p.getName(), p.getVersion(), p.getArtifactId(), p.getGroupId(), engine.getDependencies(), engine.getAnalyzers(), prop); try { r.generateReports(outputDir.getAbsolutePath(), format); } catch (ReportException ex) { final String msg = String.format("Error generating the report for %s", p.getName()); throw new ReportException(msg, ex); } }
From source file:org.owasp.dependencycheck.maven.BaseDependencyCheckMojo.java
License:Apache License
/** * Generates a warning message listing a summary of dependencies and their * associated CPE and CVE entries./*from ww w. j ava2s . c o m*/ * * @param mp the Maven project for which the summary is shown * @param dependencies a list of dependency objects */ protected void showSummary(MavenProject mp, List<Dependency> dependencies) { if (showSummary) { final StringBuilder summary = new StringBuilder(); for (Dependency d : dependencies) { boolean firstEntry = true; final StringBuilder ids = new StringBuilder(); for (Vulnerability v : d.getVulnerabilities()) { if (firstEntry) { firstEntry = false; } else { ids.append(", "); } ids.append(v.getName()); } if (ids.length() > 0) { summary.append(d.getFileName()).append(" ("); firstEntry = true; for (Identifier id : d.getIdentifiers()) { if (firstEntry) { firstEntry = false; } else { summary.append(", "); } summary.append(id.getValue()); } summary.append(") : ").append(ids).append(NEW_LINE); } } if (summary.length() > 0) { final String msg = String.format( "%n%n" + "One or more dependencies were identified with known vulnerabilities in %s:%n%n%s" + "%n%nSee the dependency-check report for more details.%n%n", mp.getName(), summary.toString()); getLog().warn(msg); } } }