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

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

Introduction

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

Prototype

public Scm getScm() 

Source Link

Usage

From source file:org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.java

License:Open Source License

/**
 * For SONAR-3676//from www.  jav  a 2  s  . c o m
 */
private static void convertMavenLinksToProperties(Properties props, MavenProject pom) {
    setPropertyIfNotAlreadyExists(props, LINKS_HOME_PAGE, pom.getUrl());

    Scm scm = pom.getScm();
    if (scm == null) {
        scm = new Scm();
    }
    setPropertyIfNotAlreadyExists(props, LINKS_SOURCES, scm.getUrl());
    setPropertyIfNotAlreadyExists(props, LINKS_SOURCES_DEV, scm.getDeveloperConnection());

    CiManagement ci = pom.getCiManagement();
    if (ci == null) {
        ci = new CiManagement();
    }
    setPropertyIfNotAlreadyExists(props, LINKS_CI, ci.getUrl());

    IssueManagement issues = pom.getIssueManagement();
    if (issues == null) {
        issues = new IssueManagement();
    }
    setPropertyIfNotAlreadyExists(props, LINKS_ISSUE_TRACKER, issues.getUrl());
}

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

License:Apache License

public boolean check(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException {
    this.mavenProject = mavenProject;
    log.debug("checking svn for " + mavenProject.getBasedir().getPath());
    try {/*from   w ww .ja v a 2s .  c  om*/
        surl = getSVNURL(mavenProject.getBasedir());

        log.debug("found URL   : " + surl);
        log.debug("comparing with   : " + mavenProject.getScm().getConnection());
        log.debug("comparing with   : " + mavenProject.getScm().getDeveloperConnection());
        if (missMatchURLs(surl) || missMatchURLs(surl.replace(OLD_URL, NEW_URL))) {
            throw new MojoFailureException(SCM_NOT_CONFIGURED);

        } else {
            log.debug("SCM and SVN info are in sync.");
            return true;
        }
    } catch (SVNException e) {
        log.warn("SVN Error.", e);
        log.warn("directory seems not to be a local SVN working copy.");
        throw new MojoExecutionException("Directory seems not to be a local SVN working copy.", e);
    } catch (MojoFailureException e) {
        throw e;
    } catch (MojoExecutionException e) {
        throw e;
    } catch (Exception e1) {
        throw new MojoExecutionException("Unexpected Exception", e1);
    }
}

From source file:org.universAAL.support.directives.procedures.Tag.java

License:Apache License

/** {@inheritDoc} */
public void execute(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException {
    if (baseURL == null) {
        baseURL = mavenProject.getScm().getDeveloperConnection();
    }/*  w  w w . j  a v a  2  s .  co  m*/
    String tagUrl = getTagURL(mavenProject);
    log.info("Tagging: " + baseURL + "  ->  " + tagUrl);
    if (tagRemoteHead) {
        if (!performTag(baseURL, tagUrl, "Automatic tag of " + mavenProject.getArtifactId() + " version: "
                + mavenProject.getVersion())) {
            throw new MojoExecutionException(NOT_TAGGED);
        }
    } else {
        if (!performWCTag(mavenProject.getBasedir(), tagUrl, "Automatic tag of " + mavenProject.getArtifactId()
                + " version: " + mavenProject.getVersion())) {
            throw new MojoExecutionException(NOT_TAGGED);
        }
    }
}

From source file:org.universAAL.support.directives.procedures.Tag.java

License:Apache License

/**
 * parses the scm url to generate an appropiate tag URL, in concordance to
 * T2.3 Directives//from w ww.j a v  a 2  s  .  c o m
 * 
 * @return
 */
public static String getTagURL(MavenProject mavenProject) {
    String scmUrl = mavenProject.getScm().getDeveloperConnection();
    scmUrl = scmUrl.replace("scm:", "").replace("svn:", "");
    String tagUrl = scmUrl.split("trunk")[0];
    tagUrl += "tags/";
    if (AbstractCheckMojo.isSnapshot(mavenProject)) {
        tagUrl += "SNAPSHOT/" + mavenProject.getArtifactId() + "-" + mavenProject.getVersion();
    } else {
        tagUrl += mavenProject.getVersion() + scmUrl.split("trunk")[1];
    }
    return tagUrl;
}

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();
    }/*www .ja v  a  2s  .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.");
    }
}