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

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

Introduction

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

Prototype

public String getUrl() 

Source Link

Usage

From source file:org.sonar.updatecenter.deprecated.UpdateCenter.java

License:Open Source License

private History<Plugin> resolvePluginHistory(String id) throws Exception {
    String groupId = StringUtils.substringBefore(id, ":");
    String artifactId = StringUtils.substringAfter(id, ":");

    Artifact artifact = artifactFactory.createArtifact(groupId, artifactId, Artifact.LATEST_VERSION,
            Artifact.SCOPE_COMPILE, ARTIFACT_JAR_TYPE);

    List<ArtifactVersion> versions = filterSnapshots(
            metadataSource.retrieveAvailableVersions(artifact, localRepository, remoteRepositories));

    History<Plugin> history = new History<Plugin>();
    for (ArtifactVersion version : versions) {
        Plugin plugin = org.sonar.updatecenter.deprecated.Plugin
                .extractMetadata(resolve(artifact.getGroupId(), artifact.getArtifactId(), version.toString()));
        history.addArtifact(version, plugin);

        MavenProject project = mavenProjectBuilder
                .buildFromRepository(//from  w  ww  . j  a v  a  2 s. c  om
                        artifactFactory.createArtifact(groupId, artifactId, version.toString(),
                                Artifact.SCOPE_COMPILE, ARTIFACT_POM_TYPE),
                        remoteRepositories, localRepository);

        if (plugin.getVersion() == null) {
            // Legacy plugin - set default values
            plugin.setKey(project.getArtifactId());
            plugin.setName(project.getName());
            plugin.setVersion(project.getVersion());

            String sonarVersion = "1.10"; // TODO Is it minimal version for all extension points ?
            for (Dependency dependency : project.getDependencies()) {
                if ("sonar-plugin-api".equals(dependency.getArtifactId())) { // TODO dirty hack
                    sonarVersion = dependency.getVersion();
                }
            }

            plugin.setRequiredSonarVersion(sonarVersion);
            plugin.setHomepage(project.getUrl());
        }
        plugin.setDownloadUrl(getPluginDownloadUrl(groupId, artifactId, plugin.getVersion()));
        // There is no equivalent for following properties in MANIFEST.MF
        if (project.getIssueManagement() != null) {
            plugin.setIssueTracker(project.getIssueManagement().getUrl());
        } else {
            System.out.println("Unknown Issue Management for " + plugin.getKey() + ":" + plugin.getVersion());
        }
        if (project.getScm() != null) {
            String scmUrl = project.getScm().getUrl();
            if (StringUtils.startsWith(scmUrl, "scm:")) {
                scmUrl = StringUtils.substringAfter(StringUtils.substringAfter(scmUrl, ":"), ":");
            }
            plugin.setSources(scmUrl);
        } else {
            System.out.println("Unknown SCM for " + plugin.getKey() + ":" + plugin.getVersion());
        }
        if (project.getLicenses() != null && project.getLicenses().size() > 0) {
            plugin.setLicense(project.getLicenses().get(0).getName());
        } else {
            System.out.println("Unknown License for " + plugin.getKey() + ":" + plugin.getVersion());
        }
        if (project.getDevelopers().size() > 0) {
            plugin.setDevelopers(project.getDevelopers());
        } else {
            System.out.println("Unknown Developers for " + plugin.getKey() + ":" + plugin.getVersion());
        }
    }
    return history;
}

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

License:Open Source License

/**
 * For SONAR-3676//from  w  w  w . j a  v a  2s  . c  om
 */
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());
}