Search in sources :

Example 36 with Scm

use of org.apache.maven.model.Scm in project m2e-core by eclipse-m2e.

the class MavenProjectPomScanner method run.

public void run(IProgressMonitor monitor) throws InterruptedException {
    for (Dependency d : dependencies) {
        if (monitor.isCanceled()) {
            throw new InterruptedException();
        }
        try {
            Model model = resolveModel(d.getGroupId(), d.getArtifactId(), d.getVersion(), monitor);
            if (model == null) {
                String msg = "Can't resolve " + d.getArtifactId();
                Exception error = new Exception(msg);
                log.error(msg, error);
                addError(error);
                continue;
            }
            Scm scm = resolveScm(model, monitor);
            if (scm == null) {
                String msg = "No SCM info for " + d.getArtifactId();
                Exception error = new Exception(msg);
                log.error(msg, error);
                addError(error);
                continue;
            }
            String tag = scm.getTag();
            log.info(d.getArtifactId());
            log.info("Connection: {}", scm.getConnection());
            log.info("       dev: {}", scm.getDeveloperConnection());
            log.info("       url: {}", scm.getUrl());
            log.info("       tag: {}", tag);
            String connection;
            if (developer) {
                connection = scm.getDeveloperConnection();
                if (connection == null) {
                    String msg = d.getArtifactId() + " doesn't specify developer SCM connection";
                    Exception error = new Exception(msg);
                    log.error(msg, error);
                    addError(error);
                    continue;
                }
            } else {
                connection = scm.getConnection();
                if (connection == null) {
                    String msg = d.getArtifactId() + " doesn't specify SCM connection";
                    Exception error = new Exception(msg);
                    log.error(msg, error);
                    addError(error);
                    continue;
                }
            }
            if (connection.endsWith("/")) {
                // $NON-NLS-1$
                connection = connection.substring(0, connection.length() - 1);
            }
            // $NON-NLS-1$
            int n = connection.lastIndexOf("/");
            // $NON-NLS-1$
            String label = (n == -1 ? connection : connection.substring(n)) + "/" + IMavenConstants.POM_FILE_NAME;
            addProject(new MavenProjectScmInfo(label, model, null, tag, connection, connection));
        } catch (Exception ex) {
            addError(ex);
            String msg = "Error reading " + d.getArtifactId();
            log.error(msg, ex);
        }
    }
}
Also used : Model(org.apache.maven.model.Model) Dependency(org.apache.maven.model.Dependency) Scm(org.apache.maven.model.Scm) CoreException(org.eclipse.core.runtime.CoreException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 37 with Scm

use of org.apache.maven.model.Scm in project buck by facebook.

the class Pom method merge.

private Model merge(Model first, @Nullable Model second) {
    if (second == null) {
        return first;
    }
    Model model = first.clone();
    //---- Values from ModelBase
    List<String> modules = second.getModules();
    if (modules != null) {
        for (String module : modules) {
            model.addModule(module);
        }
    }
    DistributionManagement distributionManagement = second.getDistributionManagement();
    if (distributionManagement != null) {
        model.setDistributionManagement(distributionManagement);
    }
    Properties properties = second.getProperties();
    if (properties != null) {
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            model.addProperty((String) entry.getKey(), (String) entry.getValue());
        }
    }
    DependencyManagement dependencyManagement = second.getDependencyManagement();
    if (dependencyManagement != null) {
        model.setDependencyManagement(dependencyManagement);
    }
    List<Dependency> dependencies = second.getDependencies();
    if (dependencies != null) {
        for (Dependency dependency : dependencies) {
            model.addDependency(dependency);
        }
    }
    List<Repository> repositories = second.getRepositories();
    if (repositories != null) {
        for (Repository repository : repositories) {
            model.addRepository(repository);
        }
    }
    List<Repository> pluginRepositories = second.getPluginRepositories();
    if (pluginRepositories != null) {
        for (Repository pluginRepository : pluginRepositories) {
            model.addPluginRepository(pluginRepository);
        }
    }
    // Ignore reports, reporting, and locations
    //----- From Model
    Parent parent = second.getParent();
    if (parent != null) {
        model.setParent(parent);
    }
    Organization organization = second.getOrganization();
    if (organization != null) {
        model.setOrganization(organization);
    }
    List<License> licenses = second.getLicenses();
    Set<String> currentLicenseUrls = new HashSet<>();
    if (model.getLicenses() != null) {
        for (License license : model.getLicenses()) {
            currentLicenseUrls.add(license.getUrl());
        }
    }
    if (licenses != null) {
        for (License license : licenses) {
            if (!currentLicenseUrls.contains(license.getUrl())) {
                model.addLicense(license);
                currentLicenseUrls.add(license.getUrl());
            }
        }
    }
    List<Developer> developers = second.getDevelopers();
    Set<String> currentDevelopers = new HashSet<>();
    if (model.getDevelopers() != null) {
        for (Developer developer : model.getDevelopers()) {
            currentDevelopers.add(developer.getName());
        }
    }
    if (developers != null) {
        for (Developer developer : developers) {
            if (!currentDevelopers.contains(developer.getName())) {
                model.addDeveloper(developer);
                currentDevelopers.add(developer.getName());
            }
        }
    }
    List<Contributor> contributors = second.getContributors();
    Set<String> currentContributors = new HashSet<>();
    if (model.getContributors() != null) {
        for (Contributor contributor : model.getContributors()) {
            currentDevelopers.add(contributor.getName());
        }
    }
    if (contributors != null) {
        for (Contributor contributor : contributors) {
            if (!currentContributors.contains(contributor.getName())) {
                model.addContributor(contributor);
                currentContributors.add(contributor.getName());
            }
        }
    }
    List<MailingList> mailingLists = second.getMailingLists();
    if (mailingLists != null) {
        for (MailingList mailingList : mailingLists) {
            model.addMailingList(mailingList);
        }
    }
    Prerequisites prerequisites = second.getPrerequisites();
    if (prerequisites != null) {
        model.setPrerequisites(prerequisites);
    }
    Scm scm = second.getScm();
    if (scm != null) {
        model.setScm(scm);
    }
    String url = second.getUrl();
    if (url != null) {
        model.setUrl(url);
    }
    String description = second.getDescription();
    if (description != null) {
        model.setDescription(description);
    }
    IssueManagement issueManagement = second.getIssueManagement();
    if (issueManagement != null) {
        model.setIssueManagement(issueManagement);
    }
    CiManagement ciManagement = second.getCiManagement();
    if (ciManagement != null) {
        model.setCiManagement(ciManagement);
    }
    Build build = second.getBuild();
    if (build != null) {
        model.setBuild(build);
    }
    List<Profile> profiles = second.getProfiles();
    Set<String> currentProfileIds = new HashSet<>();
    if (model.getProfiles() != null) {
        for (Profile profile : model.getProfiles()) {
            currentProfileIds.add(profile.getId());
        }
    }
    if (profiles != null) {
        for (Profile profile : profiles) {
            if (!currentProfileIds.contains(profile.getId())) {
                model.addProfile(profile);
                currentProfileIds.add(profile.getId());
            }
        }
    }
    return model;
}
Also used : Organization(org.apache.maven.model.Organization) Parent(org.apache.maven.model.Parent) License(org.apache.maven.model.License) MailingList(org.apache.maven.model.MailingList) Developer(org.apache.maven.model.Developer) Contributor(org.apache.maven.model.Contributor) Properties(java.util.Properties) Profile(org.apache.maven.model.Profile) Prerequisites(org.apache.maven.model.Prerequisites) Build(org.apache.maven.model.Build) DependencyManagement(org.apache.maven.model.DependencyManagement) IssueManagement(org.apache.maven.model.IssueManagement) HashSet(java.util.HashSet) Dependency(org.apache.maven.model.Dependency) Repository(org.apache.maven.model.Repository) Model(org.apache.maven.model.Model) CiManagement(org.apache.maven.model.CiManagement) DistributionManagement(org.apache.maven.model.DistributionManagement) Scm(org.apache.maven.model.Scm) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 38 with Scm

use of org.apache.maven.model.Scm in project fabric8-maven-plugin by fabric8io.

the class MavenScmEnricher method getAnnotations.

@Override
public Map<String, String> getAnnotations(Kind kind) {
    Map<String, String> annotations = new HashMap<>();
    if (kind.isController() || kind == Kind.SERVICE) {
        MavenProject rootProject = getProject();
        if (hasScm(rootProject)) {
            Scm scm = rootProject.getScm();
            String connectionUrl = scm.getConnection();
            String devConnectionUrl = scm.getDeveloperConnection();
            String url = scm.getUrl();
            String tag = scm.getTag();
            if (StringUtils.isNotEmpty(connectionUrl)) {
                annotations.put(SCM_CONNECTION, connectionUrl);
            }
            if (StringUtils.isNotEmpty(devConnectionUrl)) {
                annotations.put(SCM_DEVELOPER_CONNECTION, devConnectionUrl);
            }
            if (StringUtils.isNotEmpty(tag)) {
                annotations.put(SCM_TAG, tag);
            }
            if (StringUtils.isNotEmpty(url)) {
                annotations.put(SCM_URL, url);
            }
        }
    }
    return annotations;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) HashMap(java.util.HashMap) Scm(org.apache.maven.model.Scm)

Example 39 with Scm

use of org.apache.maven.model.Scm in project fabric8-maven-plugin by fabric8io.

the class MavenScmEnricherTest method testMavenScmAll.

@Test
public void testMavenScmAll() {
    final MavenProject project = new MavenProject();
    final Scm scm = new Scm();
    scm.setConnection("scm:git:git://github.com/fabric8io/fabric8-maven-plugin.git");
    scm.setDeveloperConnection("scm:git:git://github.com/fabric8io/fabric8-maven-plugin.git");
    scm.setTag("HEAD");
    scm.setUrl("git://github.com/fabric8io/fabric8-maven-plugin.git");
    project.setScm(scm);
    // Setup mock behaviour
    new Expectations() {

        {
            {
                context.getProject();
                result = project;
            }
        }
    };
    MavenScmEnricher mavenScmEnricher = new MavenScmEnricher(context);
    KubernetesListBuilder builder = new KubernetesListBuilder().withItems(new DeploymentBuilder().withNewMetadata().withName("foo").endMetadata().build());
    mavenScmEnricher.create(PlatformMode.kubernetes, builder);
    Map<String, String> scmAnnotations = builder.buildFirstItem().getMetadata().getAnnotations();
    assertNotNull(scmAnnotations);
    Assert.assertEquals(2, scmAnnotations.size());
    assertEquals("HEAD", scmAnnotations.get(Fabric8Annotations.SCM_TAG.value()));
    assertEquals("git://github.com/fabric8io/fabric8-maven-plugin.git", scmAnnotations.get(Fabric8Annotations.SCM_URL.value()));
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) MavenProject(org.apache.maven.project.MavenProject) Scm(org.apache.maven.model.Scm) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.Test)

Example 40 with Scm

use of org.apache.maven.model.Scm in project fabric8-maven-plugin by fabric8io.

the class MavenScmEnricherTest method testMavenScmOnlyUrl.

@Test
public void testMavenScmOnlyUrl() {
    final MavenProject project = new MavenProject();
    final Scm scm = new Scm();
    scm.setDeveloperConnection("scm:git:git://github.com/fabric8io/fabric8-maven-plugin.git");
    project.setScm(scm);
    // Setup mock behaviour
    new Expectations() {

        {
            {
                context.getProject();
                result = project;
            }
        }
    };
    MavenScmEnricher mavenScmEnricher = new MavenScmEnricher(context);
    KubernetesListBuilder builder = new KubernetesListBuilder().withItems(new DeploymentBuilder().withNewMetadata().withName("foo").endMetadata().build());
    mavenScmEnricher.create(PlatformMode.kubernetes, builder);
    Map<String, String> scmAnnotations = builder.buildFirstItem().getMetadata().getAnnotations();
    assertNotNull(scmAnnotations);
    Assert.assertEquals(1, scmAnnotations.size());
    assertEquals("HEAD", scmAnnotations.get(Fabric8Annotations.SCM_TAG.value()));
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) MavenProject(org.apache.maven.project.MavenProject) Scm(org.apache.maven.model.Scm) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.Test)

Aggregations

Scm (org.apache.maven.model.Scm)64 MavenProject (org.apache.maven.project.MavenProject)21 Model (org.apache.maven.model.Model)14 Test (org.junit.Test)10 File (java.io.File)7 IOException (java.io.IOException)7 Map (java.util.Map)5 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)4 DeploymentBuilder (io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Properties (java.util.Properties)4 Expectations (mockit.Expectations)4 Dependency (org.apache.maven.model.Dependency)4 IssueManagement (org.apache.maven.model.IssueManagement)4 ReleaseDescriptorBuilder (org.apache.maven.shared.release.config.ReleaseDescriptorBuilder)4 DefaultReleaseEnvironment (org.apache.maven.shared.release.env.DefaultReleaseEnvironment)4 Path (java.nio.file.Path)3 License (org.apache.maven.model.License)3 Parent (org.apache.maven.model.Parent)3