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:io.fabric8.maven.HelmPushMojo.java

License:Apache License

protected boolean isRootReactorBuild() {
    if (reactorProjects == null || reactorProjects.size() <= 1) {
        return true;
    }//from  w w  w .ja v a 2 s. c om
    MavenProject project = getProject();
    if (project != null) {
        MavenProject parent = project.getParent();
        if (parent != null) {
            if (!containsProject(reactorProjects, parent)) {
                return true;
            }
        }
    }
    return false;
}

From source file:io.fabric8.maven.ZipMojo.java

License:Apache License

protected void generateAggregatedZips() throws IOException, MojoExecutionException {
    List<MavenProject> zipGoalProjects = fabricZipGoalProjects();
    // we want to walk backwards
    Collections.reverse(zipGoalProjects);

    Set<MavenProject> doneParents = new HashSet<>();
    for (MavenProject zipProject : zipGoalProjects) {

        MavenProject parent = zipProject.getParent();
        if (parent == null) {
            continue;
        }/*w  w w.j a v  a2s .  co  m*/

        // are there 2 or more projects with the same parent
        // then we need to aggregate them to their parent (if we have not done so before)
        Set<MavenProject> group = sameParent(parent, zipGoalProjects);
        if (group.size() >= 2 && !doneParents.contains(parent)) {
            doneParents.add(parent);

            // find transitive sub groups
            Set<MavenProject> nested = sameParentTransitive(parent, zipGoalProjects);
            if (!nested.isEmpty()) {
                group.addAll(nested);
            }

            generateAggregatedZip(parent, reactorProjects, group);
        }
    }
}

From source file:io.fabric8.maven.ZipMojo.java

License:Apache License

private Set<MavenProject> sameParent(MavenProject parent, List<MavenProject> projects) {
    Set<MavenProject> answer = new LinkedHashSet<>();
    for (MavenProject zip : projects) {
        if (Objects.equal(parent, zip.getParent())) {
            answer.add(zip);//from  w ww .  j ava 2  s. co  m
        }
    }
    return answer;
}

From source file:io.fabric8.maven.ZipMojo.java

License:Apache License

private static boolean hasAncestor(MavenProject root, MavenProject target) {
    if (target.getParent() == null) {
        return false;
    }/*w w w  . j a v  a2  s.com*/
    if (Objects.equal(root, target.getParent())) {
        return true;
    } else {
        return hasAncestor(root, target.getParent());
    }
}

From source file:io.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() != null && rootMavenProject.getParent().getBasedir() != null) {
        rootMavenProject = rootMavenProject.getParent();
    }//www . j  ava 2s  . co 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,
            mavenProject.getBasedir().toString(), indexGenFileName);
}

From source file:io.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() != null && rootMavenProject.getParent().getBasedir() != null) {
        rootMavenProject = rootMavenProject.getParent();
    }//  ww w . j  a  v a2 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:io.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() != null && rootMavenProject.getParent().getBasedir() != null) {
        rootMavenProject = rootMavenProject.getParent();
    }/*from   w  w  w  .  j ava  2s.c om*/

    // 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:io.sundr.maven.GenerateBomMojo.java

License:Apache License

/**
 * Returns the generated {@link org.apache.maven.project.MavenProject} to build.
 * This version of the project contains all the stuff needed for building (parents, profiles, properties etc).
 *
 * @param project The source {@link org.apache.maven.project.MavenProject}.
 * @param config  The {@link io.sundr.maven.BomConfig}.
 * @return The build {@link org.apache.maven.project.MavenProject}.
 *///from  w  ww.  jav  a 2s. c  o  m
private static MavenProject toBuild(MavenProject project, BomConfig config) {
    File outputDir = new File(project.getBuild().getOutputDirectory());
    File bomDir = new File(outputDir, config.getArtifactId());
    File generatedBom = new File(bomDir, BOM_NAME);

    MavenProject toBuild = project.clone();
    //we want to avoid recursive "generate-bom".
    toBuild.setExecutionRoot(false);
    toBuild.setFile(generatedBom);
    toBuild.getModel().setPomFile(generatedBom);
    toBuild.setModelVersion(project.getModelVersion());

    toBuild.setArtifact(new DefaultArtifact(project.getGroupId(), config.getArtifactId(), project.getVersion(),
            project.getArtifact().getScope(), project.getArtifact().getType(),
            project.getArtifact().getClassifier(), project.getArtifact().getArtifactHandler()));

    toBuild.setParent(project.getParent());
    toBuild.getModel().setParent(project.getModel().getParent());

    toBuild.setGroupId(project.getGroupId());
    toBuild.setArtifactId(config.getArtifactId());
    toBuild.setVersion(project.getVersion());
    toBuild.setPackaging("pom");
    toBuild.setName(config.getName());
    toBuild.setDescription(config.getDescription());

    toBuild.setUrl(project.getUrl());
    toBuild.setLicenses(project.getLicenses());
    toBuild.setScm(project.getScm());
    toBuild.setDevelopers(project.getDevelopers());
    toBuild.setDistributionManagement(project.getDistributionManagement());
    toBuild.getModel().setProfiles(project.getModel().getProfiles());

    //We want to avoid having the generated stuff wiped.
    toBuild.getProperties().put("clean.skip", "true");
    toBuild.getModel().getBuild().setDirectory(bomDir.getAbsolutePath());
    toBuild.getModel().getBuild().setOutputDirectory(new File(bomDir, "target").getAbsolutePath());
    for (String key : config.getProperties().stringPropertyNames()) {
        toBuild.getProperties().put(key, config.getProperties().getProperty(key));
    }
    return toBuild;
}

From source file:kr.motd.maven.os.DetectExtension.java

License:Apache License

private void interpolate(Map<String, String> dict, MavenProject p) {
    if (p == null) {
        return;/*  www . j a v  a2 s .  co  m*/
    }

    interpolate(dict, p.getParent());
    interpolate(dict, p.getModel());
    for (ModelBase model : p.getActiveProfiles()) {
        interpolate(dict, model);
    }
}

From source file:net.oneandone.maven.plugins.prerelease.core.Descriptor.java

License:Apache License

/** @return this */
public Descriptor check(World world, MavenProject mavenProject, boolean allowSnapshots,
        boolean allowPrereleaseSnapshots) throws TagAlreadyExists, VersioningProblem, CannotDeterminTagBase,
        MissingScmTag, CannotBumpVersion, MissingDeveloperConnection {
    List<String> problems;
    MavenProject parent;//from www.  jav a2s  . c  o m

    problems = new ArrayList<>();
    checkSnapshot("project", mavenProject.getVersion(), problems);
    parent = mavenProject.getParent();
    if (parent != null) {
        checkRelease("project parent", parent.getVersion(), problems);
    }
    for (Dependency dependency : mavenProject.getDependencies()) {
        checkRelease(dependency.getGroupId() + ":" + dependency.getArtifactId(), dependency.getVersion(),
                problems);
    }
    for (Artifact artifact : mavenProject.getPluginArtifacts()) {
        if (allowPrereleaseSnapshots && "net.oneandone.maven.plugins".equals(artifact.getGroupId())
                && "prerelease".equals(artifact.getArtifactId())) {
            // skip for integration tests
        } else {
            checkRelease(artifact.getGroupId() + ":" + artifact.getArtifactId(), artifact.getVersion(),
                    problems);
        }
    }
    if (problems.size() > 0 && !allowSnapshots) {
        throw new VersioningProblem(problems);
    }
    if (Subversion.exists(world.getTemp(), svnTag)) {
        throw new TagAlreadyExists(svnTag);
    }
    return this;
}