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

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

Introduction

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

Prototype

public MavenProject getParent() 

Source Link

Document

Returns the project corresponding to a declared parent.

Usage

From source file:org.kloeckner.maven.plugin.util.VersionRangeUtils.java

License:Apache License

public static String rewriteParent(MavenProject project, Element rootElement, Namespace namespace,
        Map<String, String> mappedVersions, Map<String, String> originalVersions)
        throws MojoExecutionException {
    String parentVersion = null;//from w  w w  .j  a  v  a 2 s  .  c  o  m
    if (project.hasParent()) {
        Element parentElement = rootElement.getChild("parent", namespace);
        Element versionElement = parentElement.getChild("version", namespace);
        MavenProject parent = project.getParent();
        String key = ArtifactUtils.versionlessKey(parent.getGroupId(), parent.getArtifactId());
        parentVersion = mappedVersions.get(key);
        //         if (parentVersion == null) {
        //            //MRELEASE-317
        //            parentVersion = getResolvedSnapshotVersion(key, resolvedSnapshotDependencies);
        //         }
        if (parentVersion == null) {
            if (parent.getVersion().equals(originalVersions.get(key))) {
                throw new MojoExecutionException(
                        "Version for parent '" + parent.getName() + "' was not mapped");
            }
        } else {
            rewriteValue(versionElement, parentVersion);
        }
    }
    return parentVersion;
}

From source file:org.m1theo.apt.repo.utils.Utils.java

License:Open Source License

/**
 * Collects all artifacts of the given type.
 * /*ww  w. j av a2  s. c om*/
 * @param project The maven project which should be used.
 * @param type The file type which should be collected.
 * @return A collection of all artifacts with the given type.
 */
@SuppressWarnings("unchecked")
public static Collection<Artifact> getAllArtifacts4Type(MavenProject project, String type, Boolean aggregate) {
    final Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
    List<MavenProject> modules = new ArrayList<MavenProject>();
    modules.add(project);
    List<MavenProject> collectedProjects = project.getCollectedProjects();
    if (collectedProjects != null) {
        modules.addAll(collectedProjects);
    }
    for (MavenProject module : modules) {
        addDebArtifact(module.getArtifact(), artifacts, type);
        for (Object artifact : module.getArtifacts()) {
            if (artifact instanceof Artifact) {
                addDebArtifact((Artifact) artifact, artifacts, type);
            }
        }
        for (Object artifact : module.getAttachedArtifacts()) {
            if (artifact instanceof Artifact) {
                addDebArtifact((Artifact) artifact, artifacts, type);
            }
        }
    }
    if (project.hasParent() && aggregate) {
        artifacts.addAll(getAllArtifacts4Type(project.getParent(), type, aggregate));
    }
    return artifacts;
}

From source file:org.novelang.maven.SourceAggregatorMojo.java

License:Open Source License

private static File findParentRoot(final MavenProject project) {
    MavenProject maybeRoot = project;
    while (true) {
        final MavenProject parent = maybeRoot.getParent();
        if (parent == null) {
            break;
        } else {//  w  w w .  j a v a2s.  com
            maybeRoot = parent;
        }
    }
    return maybeRoot.getBasedir();
}

From source file:org.objectstyle.woproject.maven2.javamonitor.JavaMonitorDeployMojo.java

License:Open Source License

/**
 * Generates the site structure using the project hiearchy (project and its
 * modules) or using the distributionManagement elements from the pom.xml.
 *
 * @param project/*  www . j  a va  2  s.  com*/
 * @param ignoreMissingSiteUrl
 * @return the structure relative path
 * @throws MojoFailureException
 *             if any
 */
protected static String getStructure(MavenProject project, boolean ignoreMissingSiteUrl)
        throws MojoFailureException {
    if (project.getDistributionManagement() == null) {
        String hierarchy = project.getArtifactId();

        MavenProject parent = project.getParent();
        while (parent != null) {
            hierarchy = parent.getArtifactId() + "/" + hierarchy;
            parent = parent.getParent();
        }

        return hierarchy;
    }

    Site site = project.getDistributionManagement().getSite();
    if (site == null) {
        if (!ignoreMissingSiteUrl) {
            throw new MojoFailureException(
                    "Missing site information in the distribution management element in the project: '"
                            + project.getName() + "'.");
        }

        return null;
    }

    if (StringUtils.isEmpty(site.getUrl())) {
        if (!ignoreMissingSiteUrl) {
            throw new MojoFailureException("The URL in the site is missing in the project descriptor.");
        }

        return null;
    }

    Repository repository = new Repository(site.getId(), site.getUrl());
    StringBuffer hierarchy = new StringBuffer(1024);
    hierarchy.append(repository.getHost());
    if (!StringUtils.isEmpty(repository.getBasedir())) {
        if (!repository.getBasedir().startsWith("/")) {
            hierarchy.append('/');
        }
        hierarchy.append(repository.getBasedir());
    }

    return hierarchy.toString().replaceAll("[\\:\\?\\*]", "");
}

From source file:org.opennms.maven.plugins.tgz.AbstractAssemblyMojo.java

License:Apache License

private boolean isProjectModule(String parentId, MavenProject reactorProject, boolean recurse) {
    MavenProject parent = reactorProject.getParent();

    if (parent != null) {
        if (parent.getId().equals(parentId)) {
            return true;
        } else if (recurse) {
            isProjectModule(parentId, parent, true);
        }/*w  ww  . ja v a  2s  .  c om*/
    }

    return false;
}

From source file:org.ops4j.pax.construct.clone.CloneMojo.java

License:Apache License

/**
 * Analyze the position of this project in the tree, as not all projects need their own distinct set of "poms"
 * /*  ww  w  .j a  v  a  2s  .  c  om*/
 * @param project Maven POM project
 * @return true if this project requires a pax-create-project call
 */
private boolean isMajorProject(MavenProject project) {
    if (project.isExecutionRoot()) {
        // top-most project
        return true;
    }

    // disconnected project, or project with its own set of "poms" where settings can be customized
    return (null == project.getParent() || new File(project.getBasedir(), "poms").isDirectory());
}

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

License:Apache License

/**
 * Returns a set containing all the descendant projects of the given
 * project./*from   w ww  .  j a  v a2  s . c  o 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.Engine.java

License:Apache License

/**
 * Returns the root Maven Project./*from   ww  w .ja  v  a2  s  . c  o m*/
 *
 * @return the root Maven Project
 */
private MavenProject getExecutionRoot() {
    if (reactorProjects == null) {
        return null;
    }
    for (MavenProject p : reactorProjects) {
        if (p.isExecutionRoot()) {
            return p;
        }
    }
    //the following should  never run, but leaving it as a failsafe.
    if (this.currentProject == null) {
        return null;
    }
    MavenProject p = this.currentProject;
    while (p.getParent() != null) {
        p = p.getParent();
    }
    return p;
}

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

License:Apache License

/**
 * Returns the root Maven Project.//from w  w w  .  j a va 2s  . co  m
 *
 * @return the root Maven Project
 */
MavenProject getExecutionRoot() {
    if (reactorProjects == null) {
        return null;
    }
    for (MavenProject p : reactorProjects) {
        if (p.isExecutionRoot()) {
            return p;
        }
    }
    //the following should  never run, but leaving it as a failsafe.
    if (this.currentProject == null) {
        return null;
    }
    MavenProject p = this.currentProject;
    while (p.getParent() != null) {
        p = p.getParent();
    }
    return p;
}

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

License:Apache License

/**
 * Collects the information needed for building aggregate reports.
 *///from w ww  .j a va2  s .c o m
private void buildAggregateInfo() {
    // build parent-child map
    for (MavenProject proj : reactorProjects) {
        Set<MavenProject> depList = projectChildren.get(proj.getParent());
        if (depList == null) {
            depList = new HashSet<MavenProject>();
            projectChildren.put(proj.getParent(), depList);
        }
        depList.add(proj);
    }
}