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.debian.dependency.sources.SCMSourceRetrieval.java

License:Apache License

@Override
public String retrieveSource(final Artifact artifact, final File directory, final MavenSession session)
        throws SourceRetrievalException {
    MavenProject project = findProjectRoot(constructProject(artifact, session));
    Scm scm = project.getScm();
    if (scm == null) {
        return null;
    }/*from  ww  w  . j a v  a2s .  c  om*/

    SettingsDecryptionResult decryptionResult = settingsDecrypter
            .decrypt(new DefaultSettingsDecryptionRequest(session.getSettings()));
    for (SettingsProblem problem : decryptionResult.getProblems()) {
        getLogger().warn("Error decrypting settings (" + problem.getLocation() + ") : " + problem.getMessage(),
                problem.getException());
    }

    try {
        // first we check developer connection
        CheckOutScmResult checkoutResult = null;
        String connection = scm.getDeveloperConnection();
        try {
            checkoutResult = performCheckout(connection, determineVersion(scm), directory,
                    decryptionResult.getServers());
        } catch (ScmException e) {
            // we don't really care about the exception here because we will try the regular connection next
            getLogger().debug(
                    "Unable to checkout sources using developer connection, trying standard connection", e);
        }

        // now the regular connection if it wasn't successful
        if (checkoutResult == null || !checkoutResult.isSuccess()) {
            connection = scm.getConnection();
            checkoutResult = performCheckout(connection, determineVersion(scm), directory,
                    decryptionResult.getServers());
        }

        if (checkoutResult == null) {
            throw new SourceRetrievalException("No scm information available");
        } else if (!checkoutResult.isSuccess()) {
            getLogger().error("Provider Message:");
            getLogger().error(StringUtils.defaultString(checkoutResult.getProviderMessage()));
            getLogger().error("Commandline:");
            getLogger().error(StringUtils.defaultString(checkoutResult.getCommandOutput()));
            throw new SourceRetrievalException("Unable to checkout files: "
                    + StringUtils.defaultString(checkoutResult.getProviderMessage()));
        }
        return connection;
    } catch (ScmException e) {
        throw new SourceRetrievalException("Unable to checkout project", e);
    }
}

From source file:org.eclipse.m2e.core.ui.internal.actions.OpenUrlAction.java

License:Open Source License

private static String getUrl(String actionId, MavenProject mavenProject) {
    String url = null;/* ww  w.j  a v  a  2s  . c o  m*/
    if (ID_PROJECT.equals(actionId)) {
        url = mavenProject.getUrl();
        if (url == null) {
            openDialog(Messages.OpenUrlAction_error_no_url);
        }
    } else if (ID_ISSUES.equals(actionId)) {
        IssueManagement issueManagement = mavenProject.getIssueManagement();
        if (issueManagement != null) {
            url = issueManagement.getUrl();
        }
        if (url == null) {
            openDialog(Messages.OpenUrlAction_error_no_issues);
        }
    } else if (ID_SCM.equals(actionId)) {
        Scm scm = mavenProject.getScm();
        if (scm != null) {
            url = scm.getUrl();
        }
        if (url == null) {
            openDialog(Messages.OpenUrlAction_error_no_scm);
        }
    } else if (ID_CI.equals(actionId)) {
        CiManagement ciManagement = mavenProject.getCiManagement();
        if (ciManagement != null) {
            url = ciManagement.getUrl();
        }
        if (url == null) {
            openDialog(Messages.OpenUrlAction_error_no_ci);
        }
    }
    return url;
}

From source file:org.gephi.maven.MetadataUtils.java

License:Apache License

/**
 * Lookup source code configuration or default to SCM.
 *
 * @param project project//from w w w  . j  a  v  a 2s .co  m
 * @param log log
 * @return source code url or null
 */
protected static String getSourceCode(MavenProject project, Log log) {
    Plugin nbmPlugin = lookupNbmPlugin(project);
    if (nbmPlugin != null) {
        Xpp3Dom config = (Xpp3Dom) nbmPlugin.getConfiguration();
        if (config != null && config.getChild("sourceCodeUrl") != null) {
            return config.getChild("sourceCodeUrl").getValue();
        }
    }

    Scm scm = project.getScm();
    if (scm != null && scm.getUrl() != null && !scm.getUrl().isEmpty()) {
        log.debug("SCM configuration found, with url = '" + scm.getUrl() + "'");
        return scm.getUrl();
    } else {

    }
    return null;
}

From source file:org.hardisonbrewing.maven.svn.PrepareExternalsMojo.java

License:Open Source License

@Override
public final void execute() throws MojoExecutionException, MojoFailureException {

    String propertiesPath = PropertiesService.getExternalsPropertiesPath();
    FileUtils.ensureParentExists(propertiesPath);

    MavenProject project = getProject();
    Scm scm = project.getScm();

    Properties properties = new Properties();
    properties.put(PropertiesService.SCM_URL, scm.getUrl());
    PropertiesService.storeProperties(properties, propertiesPath);
}

From source file:org.hardisonbrewing.maven.svn.UpdateExternalsMojo.java

License:Open Source License

private void updateExternal(List<Entry> properties, External external) throws Exception {

    Dependency dependency = external.dependency;

    if (dependency == null) {
        getLog().error("Must specify external dependency!");
        throw new IllegalStateException();
    }/* www .  j  a v a  2 s.c  o  m*/

    StringBuffer dependencyStr = new StringBuffer();
    dependencyStr.append(dependency.getGroupId());
    dependencyStr.append(":");
    dependencyStr.append(dependency.getArtifactId());
    dependencyStr.append(":");
    dependencyStr.append(dependency.getVersion());
    dependencyStr.append(":");
    dependencyStr.append(dependency.getType());

    if (external.path == null) {
        getLog().error("No path specified for external: " + dependencyStr);
        throw new IllegalStateException();
    }

    Artifact artifact = DependencyService.createResolvedArtifact(dependency);
    MavenProject project = ProjectService.getProject(artifact);
    Scm scm = project.getScm();

    if (scm == null) {
        getLog().error("No SCM specified for " + dependencyStr);
        throw new IllegalStateException();
    }

    String url = scm.getUrl();

    if (url == null || url.length() == 0) {
        getLog().error("No SCM Url specified for " + dependencyStr);
        throw new IllegalStateException();
    }

    getLog().error("Setting svn:externals for " + dependencyStr + " to '" + url + " " + external.path + "'");

    Entry entry = findEntry(properties, external.path);

    if (entry == null) {
        entry = new Entry();
        properties.add(entry);
    }

    entry.first = url;
    entry.second = external.path;
}

From source file:org.kriand.warpdrive.versioning.VersionProvider.java

License:Apache License

/**
 * Checks if a project is using SVN by inspecting the scm element of the pom.
 * Projects using SVN should use {@linkplain org.kriand.warpdrive.versioning.SvnRevNumberGenerator}
 *
 * @param mojo The WarpDrive plugin//w  w w . j ava2  s  .c o m
 * @return True if the project is configured to use SVN, false otherwise.
 */
private boolean isProjectUsingSvn(final WarpDriveMojo mojo) {
    MavenProject project = mojo.getProject();
    if (project != null && project.getScm() != null && project.getScm().getConnection() != null
            && project.getScm().getConnection().startsWith("scm:svn")) {
        return true;
    }
    return false;
}

From source file:org.mule.devkit.maven.RepositoryUtils.java

License:Open Source License

/**
 * Get repository//  w  w w  . ja v  a2 s  . c om
 *
 * @param project
 * @param owner
 * @param name
 * @return repository id or null if none configured
 */
public static RepositoryId getRepository(final MavenProject project, final String owner, final String name) {
    // Use owner and name if specified
    if (!StringUtils.isEmpty(owner) && !StringUtils.isEmpty(name)) {
        return RepositoryId.create(owner, name);
    }

    if (project == null) {
        return null;
    }

    RepositoryId repo = null;

    // Extract repository from SCM URLs if present
    final Scm scm = project.getScm();
    if (scm == null) {
        return null;
    }
    if (!StringUtils.isEmpty(scm.getUrl())) {
        repo = RepositoryId.createFromUrl(scm.getUrl());
    }
    if (repo == null) {
        repo = extractRepositoryFromScmUrl(scm.getConnection());
    }
    if (repo == null) {
        repo = extractRepositoryFromScmUrl(scm.getDeveloperConnection());
    }
    return repo;
}

From source file:org.openmrs.maven.plugins.bintray.OpenmrsBintray.java

public BintrayPackage createPackage(MavenProject mavenProject, String repository) {
    CreatePackageRequest request = new CreatePackageRequest();
    request.setName(mavenProject.getArtifactId());
    request.setDescription(mavenProject.getDescription());

    String githubUrl = mavenProject.getScm().getUrl();
    if (githubUrl.endsWith("/"))
        githubUrl = StringUtils.stripEnd(githubUrl, "/");
    String githubRepo = githubUrl.substring(githubUrl.lastIndexOf("/")).replace(".git", "");
    request.setVcsUrl(githubUrl + (githubUrl.endsWith(".git") ? "" : ".git"));
    request.setGithubRepo(OPENMRS_USERNAME + githubRepo);
    request.setWebsiteUrl("http://openmrs.org/");

    request.setIssueTrackerUrl(new DefaultJira().getJiraUrl());
    //so far all OpenMRS projects have MPL-2.0 license
    request.setLicenses(Arrays.asList("MPL-2.0"));
    return createPackage(OPENMRS_USERNAME, repository, request);
}

From source file:org.sonar.batch.maven.MavenProjectConverter.java

License:Open Source License

/**
 * For SONAR-3676//from www.  j  a  v  a2  s.c  om
 */
private static void convertMavenLinksToProperties(ProjectDefinition definition, MavenProject pom) {
    setPropertyIfNotAlreadyExists(definition, CoreProperties.LINKS_HOME_PAGE, pom.getUrl());

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

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

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

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  w w. jav a2s .c o  m*/
                        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;
}