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.universAAL.support.directives.checks.DependencyManagementCheckFix.java

License:Apache License

private boolean passNoRootCheck(MavenProject mavenProject2) {
    // check that the pom (not the model) hasn't any versions in it.
    DependencyManagement dm = mavenProject2.getParent().getDependencyManagement();
    if (dm == null) // no dependency management -> no fixing
        return true;
    List<Dependency> depMan = dm.getDependencies();
    Map<DependencyID, String> depIDMan = new TreeMap<DependencyID, String>();
    // grather DependencyIDs form parent
    for (Dependency dep : depMan) {
        depIDMan.put(new DependencyID(dep), dep.getVersion());
    }/*w  w  w .  jav a2  s.  c o m*/
    try {
        for (Object o : PomWriter.readPOMFile(mavenProject2).getDependencies()) {
            Dependency dep = (Dependency) o;
            DependencyID depID = new DependencyID(dep);
            getLog().debug("***.1 " + dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getVersion());
            getLog().debug("***.1 " + depID.getGID() + ":" + depID.getAID());
            if (depIDMan.containsKey(depID) && dep.getVersion() != null) {
                getLog().debug("in DepManagement. Declared Version: " + dep.getVersion() + "Managed Version: "
                        + depIDMan.get(depID));
                toBeFixed.put(depID, null);
            }
        }
    } catch (Exception e) {
    }
    return toBeFixed.isEmpty();
}

From source file:org.universAAL.support.directives.checks.ParentGForgePropertyCheck.java

License:Apache License

public static boolean isParentRootPOM(MavenProject mavenProject2) {
    MavenProject parent = mavenProject2.getParent();
    if (parent == null)
        return false;
    String parentID = parent.getArtifactId();
    return (parent.getGroupId().equals(UAAL_GID) && parentID.endsWith(UAAL_AID));
}

From source file:org.wildfly.swarm.plugin.AbstractFractionsMojo.java

License:Apache License

protected MavenProject findRoot(MavenProject current) {
    if (current.getArtifactId().equals("wildfly-swarm")) {
        return current;
    }//from  w  ww. jav a 2 s.c  o  m
    return findRoot(current.getParent());
}

From source file:org.wso2.siddhi.doc.gen.core.ExtensionsIndexGenerationMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    // Finding the root maven project
    MavenProject rootMavenProject = mavenProject;
    while (rootMavenProject.getParent().getBasedir() != null) {
        rootMavenProject = rootMavenProject.getParent();
    }//ww  w .  jav  a  2  s .  c  o m

    // Checking if extension repositories and repository owner had been added in the configuration
    if (extensionRepositories == null || extensionRepositories.size() == 0) {
        throw new MojoExecutionException(
                "extensionRepositories configuration is required to use goal " + "generate-extensions-index");
    }

    // Setting the extension repository owner if not set by the user
    if (extensionRepositoryOwner == null) {
        extensionRepositoryOwner = Constants.GITHUB_OWNER_WSO2_EXTENSIONS;
    }

    // Setting the documentation output directory if not set by user
    String docGenBasePath;
    if (docGenBaseDirectory != null) {
        docGenBasePath = docGenBaseDirectory.getAbsolutePath();
    } else {
        docGenBasePath = rootMavenProject.getBasedir() + File.separator + Constants.DOCS_DIRECTORY;
    }

    // Setting the extension index output file name if not set by user
    if (indexGenFileName == null) {
        indexGenFileName = Constants.MARKDOWN_EXTENSIONS_INDEX_TEMPLATE;
    }

    // Creating a extensions index
    DocumentationUtils.createExtensionsIndex(extensionRepositories, extensionRepositoryOwner, docGenBasePath,
            indexGenFileName);
}

From source file:org.wso2.siddhi.doc.gen.core.MarkdownDocumentationGenerationMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    // Finding the root maven project
    MavenProject rootMavenProject = mavenProject;
    while (rootMavenProject.getParent().getBasedir() != null) {
        rootMavenProject = rootMavenProject.getParent();
    }/*from   w  ww . j a  v a 2 s  . c o m*/

    // Setting the relevant modules target directory if not set by user
    String moduleTargetPath;
    if (moduleTargetDirectory != null) {
        moduleTargetPath = moduleTargetDirectory.getAbsolutePath();
    } else {
        moduleTargetPath = mavenProject.getBuild().getDirectory();
    }

    // Setting the documentation output directory if not set by user
    String docGenBasePath;
    if (docGenBaseDirectory != null) {
        docGenBasePath = docGenBaseDirectory.getAbsolutePath();
    } else {
        docGenBasePath = rootMavenProject.getBasedir() + File.separator + Constants.DOCS_DIRECTORY;
    }

    //        // Setting the home page template file path if not set by user
    //        if (homePageTemplateFile == null) {
    //            homePageTemplateFile = new File(rootMavenProject.getBasedir() + File.separator
    //                    + Constants.README_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION);
    //        }

    // Setting the mkdocs config file path if not set by user
    if (mkdocsConfigFile == null) {
        mkdocsConfigFile = new File(rootMavenProject.getBasedir() + File.separator
                + Constants.MKDOCS_CONFIG_FILE_NAME + Constants.YAML_FILE_EXTENSION);
    }
    //
    //        // Setting the home page file name if not set by user
    //        File homePageFile;
    //        if (homePageFileName == null) {
    //            homePageFile = new File(docGenBasePath + File.separator
    //                    + Constants.HOMEPAGE_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION);
    //        } else {
    //            homePageFile = new File(docGenBasePath + File.separator + homePageFileName);
    //        }

    // Setting the readme file name if not set by user
    if (readmeFile == null) {
        readmeFile = new File(rootMavenProject.getBasedir() + File.separator + Constants.README_FILE_NAME
                + Constants.MARKDOWN_FILE_EXTENSION);
    }

    // Retrieving metadata
    List<NamespaceMetaData> namespaceMetaDataList;
    try {
        namespaceMetaDataList = DocumentationUtils.getExtensionMetaData(moduleTargetPath,
                mavenProject.getRuntimeClasspathElements(), getLog());
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoFailureException("Unable to resolve dependencies of the project", e);
    }

    // Generating the documentation
    if (namespaceMetaDataList.size() > 0) {
        DocumentationUtils.generateDocumentation(namespaceMetaDataList, docGenBasePath,
                mavenProject.getVersion(), getLog());
        //            DocumentationUtils.updateHeadingsInMarkdownFile(homePageTemplateFile, homePageFile,
        //                    rootMavenProject.getArtifactId(), mavenProject.getVersion(), namespaceMetaDataList);
        //            DocumentationUtils.updateHeadingsInMarkdownFile(readmeFile, readmeFile, rootMavenProject.getArtifactId(),
        //                    mavenProject.getVersion(), namespaceMetaDataList);
    }
}

From source file:org.wso2.siddhi.doc.gen.core.MkdocsGitHubPagesDeployMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    // Finding the root maven project
    MavenProject rootMavenProject = mavenProject;
    while (rootMavenProject.getParent().getBasedir() != null) {
        rootMavenProject = rootMavenProject.getParent();
    }//from  www . j  a  va  2 s  . co  m

    // Setting the relevant modules target directory if not set by user
    String moduleTargetPath;
    if (moduleTargetDirectory != null) {
        moduleTargetPath = moduleTargetDirectory.getAbsolutePath();
    } else {
        moduleTargetPath = mavenProject.getBuild().getDirectory();
    }

    // Setting the mkdocs config file path if not set by user
    if (mkdocsConfigFile == null) {
        mkdocsConfigFile = new File(rootMavenProject.getBasedir() + File.separator
                + Constants.MKDOCS_CONFIG_FILE_NAME + Constants.YAML_FILE_EXTENSION);
    }

    // Setting the documentation output directory if not set by user
    String docGenBasePath;
    if (docGenBaseDirectory != null) {
        docGenBasePath = docGenBaseDirectory.getAbsolutePath();
    } else {
        docGenBasePath = rootMavenProject.getBasedir() + File.separator + Constants.DOCS_DIRECTORY;
    }

    // Setting the home page file name if not set by user
    File homePageFile;
    if (homePageFileName == null) {
        homePageFile = new File(docGenBasePath + File.separator + Constants.HOMEPAGE_FILE_NAME
                + Constants.MARKDOWN_FILE_EXTENSION);
    } else {
        homePageFile = new File(docGenBasePath + File.separator + homePageFileName);
    }

    // Setting the readme file name if not set by user
    if (readmeFile == null) {
        readmeFile = new File(rootMavenProject.getBasedir() + File.separator + Constants.README_FILE_NAME
                + Constants.MARKDOWN_FILE_EXTENSION);
    }

    // Setting the home page template file path if not set by user
    if (homePageTemplateFile == null) {
        homePageTemplateFile = new File(rootMavenProject.getBasedir() + File.separator
                + Constants.README_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION);
    }

    // Retrieving metadata
    List<NamespaceMetaData> namespaceMetaDataList;
    try {
        namespaceMetaDataList = DocumentationUtils.getExtensionMetaData(moduleTargetPath,
                mavenProject.getRuntimeClasspathElements(), getLog());
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoFailureException("Unable to resolve dependencies of the project", e);
    }

    // Generating the documentation
    if (namespaceMetaDataList.size() > 0) {
        DocumentationUtils.generateDocumentation(namespaceMetaDataList, docGenBasePath,
                mavenProject.getVersion(), getLog());
        DocumentationUtils.updateHeadingsInMarkdownFile(homePageTemplateFile, homePageFile,
                rootMavenProject.getArtifactId(), mavenProject.getVersion(), namespaceMetaDataList);
        DocumentationUtils.updateHeadingsInMarkdownFile(readmeFile, readmeFile,
                rootMavenProject.getArtifactId(), mavenProject.getVersion(), namespaceMetaDataList);
    }

    // Delete snapshot files
    DocumentationUtils.removeSnapshotAPIDocs(mkdocsConfigFile, docGenBasePath, getLog());

    // Updating the links in the home page to the mkdocs config
    try {
        updateAPIPagesInMkdocsConfig(mkdocsConfigFile, docGenBasePath);
    } catch (FileNotFoundException e) {
        getLog().warn("Unable to find mkdocs configuration file: " + mkdocsConfigFile.getAbsolutePath()
                + ". Mkdocs configuration file not updated.");
    }
    // Deploying the documentation
    if (DocumentationUtils.generateMkdocsSite(mkdocsConfigFile, getLog())) {
        // Creating the credential provider fot Git
        String scmUsername = System.getenv(Constants.SYSTEM_PROPERTY_SCM_USERNAME_KEY);
        String scmPassword = System.getenv(Constants.SYSTEM_PROPERTY_SCM_PASSWORD_KEY);

        if (scmUsername == null && scmPassword == null) {
            getLog().info("SCM_USERNAME and SCM_PASSWORD not defined!");
        }
        String url = null;
        Scm scm = rootMavenProject.getScm();
        if (scm != null) {
            url = scm.getUrl();
        }
        // Deploying documentation
        DocumentationUtils.updateDocumentationOnGitHub(docGenBasePath, mkdocsConfigFile, readmeFile,
                mavenProject.getVersion(), getLog());
        DocumentationUtils.deployMkdocsOnGitHubPages(mavenProject.getVersion(), rootMavenProject.getBasedir(),
                url, scmUsername, scmPassword, getLog());
    } else {
        getLog().warn("Unable to generate documentation. Skipping documentation deployment.");
    }
}

From source file:org_scala_tools_maven.ScalaDocMojo.java

License:Apache License

@SuppressWarnings("unchecked")
protected void tryAggregateUpper(MavenProject prj) throws Exception {
    if (prj != null && prj.hasParent() && canAggregate()) {
        MavenProject parent = prj.getParent();
        List<MavenProject> modules = parent.getCollectedProjects();
        if ((modules.size() > 1) && prj.equals(modules.get(modules.size() - 1))) {
            aggregate(parent);//from   ww w . j  av  a2 s .  c om
        }
    }
}

From source file:org_scala_tools_maven.ScalaDocMojo.java

License:Apache License

@SuppressWarnings("unchecked")
protected void aggregate(MavenProject parent) throws Exception {
    List<MavenProject> modules = parent.getCollectedProjects();
    File dest = new File(parent.getReporting().getOutputDirectory() + "/" + outputDirectory);
    getLog().info("start aggregation into " + dest);
    StringBuilder mpath = new StringBuilder();
    for (MavenProject module : modules) {
        if ("pom".equals(module.getPackaging().toLowerCase())) {
            continue;
        }// w  ww  . j  av a 2 s .  c  o  m
        if (aggregateDirectOnly && module.getParent() != parent) {
            continue;
        }
        File subScaladocPath = new File(module.getReporting().getOutputDirectory() + "/" + outputDirectory)
                .getAbsoluteFile();
        //System.out.println(" -> " + project.getModulePathAdjustment(module)  +" // " + subScaladocPath + " // " + module.getBasedir() );
        if (subScaladocPath.exists()) {
            mpath.append(subScaladocPath).append(File.pathSeparatorChar);
        }
    }
    if (mpath.length() != 0) {
        getLog().info("aggregate vscaladoc from : " + mpath);
        JavaMainCaller jcmd = getScalaCommand();
        jcmd.addOption("-d", dest.getAbsolutePath());
        jcmd.addOption("-aggregate", mpath.toString());
        jcmd.run(displayCmd);
    } else {
        getLog().warn("no vscaladoc to aggregate");
    }
    tryAggregateUpper(parent);
}

From source file:pl.project13.maven.git.GitDirLocator.java

License:Open Source License

/**
 * Search up all the maven parent project heirarchy until a .git
 * directory is found./*ww  w .  java  2  s  .  c o  m*/
 *
 * @return File which represents the location of the .git directory or NULL if none found.
 */
@Nullable
private File findProjectGitDirectory() {
    MavenProject currentProject = this.mavenProject;

    while (currentProject != null) {
        File dir = getProjectGitDir(currentProject);

        if (isExistingDirectory(dir)) {
            return dir;
        }
        // If the path exists but is not a directory it might be a git submodule "gitdir" link.
        File gitDirLinkPath = processGitDirFile(dir);

        // If the linkPath was found from the file and it exists then use it.
        if (isExistingDirectory(gitDirLinkPath)) {
            return gitDirLinkPath;
        }

        /**
         * project.getParent always returns NULL for me, but if getParentArtifact returns
         * not null then there is actually a parent - seems like a bug in maven to me.
         */
        if (currentProject.getParent() == null && currentProject.getParentArtifact() != null) {
            Optional<MavenProject> maybeFoundParentProject = getReactorParentProject(currentProject);

            if (maybeFoundParentProject.isPresent())
                currentProject = maybeFoundParentProject.get();

        } else {
            // Get the parent, or NULL if no parent AND no parentArtifact.
            currentProject = currentProject.getParent();
        }
    }

    return null;
}

From source file:se.jguru.nazgul.tools.plugin.checkstyle.exec.DefaultCheckstyleExecutor.java

License:Apache License

/**
 * Configures search paths in the resource locator.
 * This method should only be called once per execution.
 *
 * @param request executor request data.
 *//*from ww w .ja v a 2 s  .  com*/
private void configureResourceLocator(final ResourceManager resourceManager,
        final CheckstyleExecutorRequest request, final List<Artifact> additionalArtifacts) {
    final MavenProject project = request.getProject();
    resourceManager.setOutputDirectory(new File(project.getBuild().getDirectory()));

    // Recurse up the parent hierarchy and add project directories to the search roots
    MavenProject parent = project;
    while (parent != null && parent.getFile() != null) {
        // MCHECKSTYLE-131 ( olamy ) I don't like this hack.
        // (dkulp) Me either.   It really pollutes the location stuff
        // by allowing searches of stuff outside the current module.
        File dir = parent.getFile().getParentFile();
        resourceManager.addSearchPath(FileResourceLoader.ID, dir.getAbsolutePath());
        parent = parent.getParent();
    }
    resourceManager.addSearchPath("url", "");

    // MCHECKSTYLE-225: load licenses from additional artifacts, not from classpath
    if (additionalArtifacts != null) {
        for (Artifact licenseArtifact : additionalArtifacts) {
            try {
                // MCHECKSTYLE-287, MCHECKSTYLE-294: Ignore null licenseArtifacts ...
                if (licenseArtifact != null) {
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug("Adding licenceArtifact [" + licenseArtifact.getGroupId() + ":"
                                + licenseArtifact.getArtifactId() + ":" + licenseArtifact.getVersion()
                                + "] to resourceManager.");
                    }
                    resourceManager.addSearchPath("jar", "jar:" + licenseArtifact.getFile().toURI().toURL());
                }
            } catch (MalformedURLException e) {
                // noop
            }
        }
    }
}