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

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

Introduction

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

Prototype

public File getBasedir() 

Source Link

Usage

From source file:org.wso2.maven.pckg.prepare.PackagePrepareSystemScopeMojo.java

License:Open Source License

private boolean updatePomFile(MavenProject cappMavenProject) {
    @SuppressWarnings("unchecked")
    List<Dependency> dependencies = cappMavenProject.getDependencies();
    for (Dependency dependency : dependencies) {
        dependency.setScope(Artifact.SCOPE_SYSTEM);
        String absoluteSystemPath = resolveDependencySystemPath(dependency);
        if (StringUtils.isNotEmpty(absoluteSystemPath)) {
            // Derive system path relative to this CAPP project
            StringBuilder systemPathBuilder = new StringBuilder();
            systemPathBuilder.append(MavenConstants.MAVEN_BASE_DIR_PREFIX);
            systemPathBuilder.append(File.separator);
            systemPathBuilder.append(FileUtils.getRelativePath(
                    new File(cappMavenProject.getBasedir().toString()), new File(absoluteSystemPath)));

            dependency.setSystemPath(systemPathBuilder.toString());
        } else {/*ww  w  . j ava  2 s .  c om*/
            // Reason is logged in a previous step
            return false;
        }
    }
    try {
        MavenUtils.saveMavenProject(cappMavenProject, cappMavenProject.getFile());
    } catch (Exception e) {
        log.error("Failed to save the pom file", e);
        return false;
    }
    log.info("All dependencies were converted to system scope");
    return true;
}

From source file:org.wso2.maven.pckg.prepare.util.PackagePrepareUtils.java

License:Open Source License

/**
 * Returns system paths of artifacts listed under a given project
 * // ww w.j  a v  a2 s . com
 * @param project
 * @return
 * @throws FactoryConfigurationError
 * @throws Exception
 */
public static Map<String, String> getArtifactsSystemPathMap(MavenProject project)
        throws FactoryConfigurationError, Exception {
    Map<String, String> dependencyData = new HashMap<>();

    StringBuilder artifactXMLPathBuilder = new StringBuilder();
    artifactXMLPathBuilder.append(project.getBasedir().toString());
    artifactXMLPathBuilder.append(File.separator);
    artifactXMLPathBuilder.append(MavenConstants.ARTIFACT_XML_NAME);

    File artifactXMLFile = new File(artifactXMLPathBuilder.toString());

    /*
     * ATM, System path can only be defined for ESB and Registry projects only. Hence filtered by artifact.xml
     */
    if (artifactXMLFile.exists()) {
        ESBProjectArtifact artifactXMLDoc = new ESBProjectArtifact();
        artifactXMLDoc.fromFile(artifactXMLFile);

        List<ESBArtifact> artifacts = artifactXMLDoc.getAllESBArtifacts();
        for (ESBArtifact artifact : artifacts) {
            // Key to uniquely identify the dependency
            String dependencyString = getDependencyString(project, artifact);

            // Post fix defines the sub directory for this artifact
            String artifactPostFix = getArtifactPostFix(artifact);

            // Output directory of all artifacts
            StringBuilder systemPathBuilder = new StringBuilder();
            systemPathBuilder.append(project.getBasedir().toString());
            systemPathBuilder.append(File.separator);
            systemPathBuilder.append(MavenConstants.ESB_PROJECT_TARGET_CAPP);
            String outputDirPath = systemPathBuilder.toString();

            // Absolute path of the artifact
            systemPathBuilder = new StringBuilder();
            systemPathBuilder.append(outputDirPath);
            systemPathBuilder.append(File.separator);
            systemPathBuilder.append(artifactPostFix);
            systemPathBuilder.append(File.separator);
            systemPathBuilder.append(artifact.getName());
            systemPathBuilder.append(File.separator);
            systemPathBuilder.append(MavenConstants.POM_FILE_NAME);
            String systemPath = systemPathBuilder.toString();

            dependencyData.put(dependencyString, systemPath);
        }
    }
    return dependencyData;
}

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();
    }/*from  w ww .j a  va2s . 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();
    }//w  ww.  j  a va2s  .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 ww w  .j ava2s  .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 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:pl.project13.maven.git.GitDirLocator.java

License:Open Source License

@NotNull
private static File getProjectGitDir(@NotNull MavenProject mavenProject) {
    // FIXME Shouldn't this look at the dotGitDirectory property (if set) for the given project?
    return new File(mavenProject.getBasedir(), Constants.DOT_GIT);
}

From source file:plugin.MyMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    for (Iterator it = reactorProjects.iterator(); it.hasNext();) {
        MavenProject project = (MavenProject) it.next();

        String basedir = project.getBasedir().getAbsolutePath();
        List compileSourceRoots = project.getCompileSourceRoots();

        System.out.println(/*from   w ww.jav a  2s.  com*/
                " Compile-source roots for project: " + project + " are: " + project.getCompileSourceRoots());
        for (Iterator srcIt = compileSourceRoots.iterator(); srcIt.hasNext();) {
            String srcRoot = (String) srcIt.next();

            if (!srcRoot.startsWith(basedir)) {
                throw new MojoExecutionException(
                        "Source root: " + srcRoot + " doesn't begin with project basedir: " + basedir);
            }
        }
    }
}

From source file:se.jiderhamn.promote.maven.plugin.PromoteArtifactsMojo.java

License:Apache License

/** Read release descriptor to find the release version of the given artifact */
private String getReleasedVersion(MavenProject project, Artifact artifact) throws MojoExecutionException {
    if (project == null || project.getBasedir() == null)
        throw new MojoExecutionException("Basedir must be provided for project " + project);

    final String key = ArtifactUtils.versionlessKey(artifact);
    try {//from  w  w w.  ja va  2 s  .c o  m
        PropertiesReleaseDescriptorStore descriptorStore = new PropertiesReleaseDescriptorStore();
        ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
        releaseDescriptor.setWorkingDirectory(project.getBasedir().getAbsolutePath());
        releaseDescriptor = descriptorStore.read(releaseDescriptor);

        // "groupId:artifactId" -> version
        final Map<String, String> releaseVersions = releaseDescriptor.getReleaseVersions();
        getLog().debug("Read versions from " + project.getBasedir() + ": " + releaseVersions);

        if (releaseVersions.containsKey(key))
            return releaseVersions.get(key);
    } catch (ReleaseDescriptorStoreException e) {
        throw new MojoExecutionException("Error parsing release descriptor", e);
    } catch (NullPointerException e) { // No release.properties found
        getLog().debug("Error finding release descriptor", e);
    }

    if (project.hasParent() && project.getParent().getBasedir() != null) {
        getLog().debug("No version for " + key + " found in " + project + "; looking in parent ");
        return getReleasedVersion(project.getParent(), artifact);
    } else
        return null;
}