Search in sources :

Example 41 with SimpleProjectVersionRef

use of org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef in project pom-manipulation-ext by release-engineering.

the class ProjectVersionManipulatorTest method updateEffectiveAndOriginalModelParentVersions.

@Test
public void updateEffectiveAndOriginalModelParentVersions() throws Exception {
    final Model parent = new Model();
    parent.setGroupId("org.foo");
    parent.setArtifactId("bar-parent");
    parent.setVersion("1.0");
    final Model orig = new Model();
    orig.setArtifactId("bar");
    final Parent origParent = new Parent();
    origParent.setGroupId(parent.getGroupId());
    origParent.setArtifactId(parent.getArtifactId());
    origParent.setVersion(parent.getVersion());
    orig.setParent(origParent);
    final Model eff = orig.clone();
    final String suff = "redhat-1";
    final String mv = orig.getVersion() + "." + suff;
    final Map<ProjectVersionRef, String> versionsByGA = new HashMap<>();
    // Not putting original group/artifact/version as they are group & version are null which causes problems with ProjectVersionRef
    versionsByGA.put(new SimpleProjectVersionRef(origParent.getGroupId(), origParent.getArtifactId(), origParent.getVersion()), mv);
    final List<MavenProject> projects = new ArrayList<>();
    MavenProject project = new MavenProject(parent.clone());
    project.setOriginalModel(parent);
    projects.add(project);
    project = new MavenProject(eff);
    project.setOriginalModel(orig);
    projects.add(project);
    final Set<MavenProject> changes = newVersioningModifier().applyVersioningChanges(projects, versionsByGA);
    assertThat(changes.size(), equalTo(2));
    for (final MavenProject p : changes) {
        if (p.getArtifactId().equals("bar")) {
            assertThat(p.getOriginalModel().getParent().getVersion(), equalTo(mv));
            assertThat(p.getModel().getParent().getVersion(), equalTo(mv));
            assertThat(p.getOriginalModel().getVersion(), nullValue());
            assertThat(p.getModel().getVersion(), nullValue());
        } else {
            assertThat(p.getOriginalModel().getVersion(), equalTo(mv));
            assertThat(p.getModel().getVersion(), equalTo(mv));
        }
    }
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Parent(org.apache.maven.model.Parent) HashMap(java.util.HashMap) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Model(org.apache.maven.model.Model) ArrayList(java.util.ArrayList) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Test(org.junit.Test)

Example 42 with SimpleProjectVersionRef

use of org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef in project pom-manipulation-ext by release-engineering.

the class ProjectVersionManipulatorTest method updateEffectiveAndOriginalModelMainVersions.

@Test
public void updateEffectiveAndOriginalModelMainVersions() throws Exception {
    final Model orig = new Model();
    orig.setGroupId("org.foo");
    orig.setArtifactId("bar");
    orig.setVersion("1.0");
    final Model eff = orig.clone();
    final String suff = "redhat-1";
    final String mv = orig.getVersion() + "." + suff;
    final Map<ProjectVersionRef, String> versionsByGAV = new HashMap<>();
    versionsByGAV.put(new SimpleProjectVersionRef(orig.getGroupId(), orig.getArtifactId(), orig.getVersion()), mv);
    final MavenProject project = new MavenProject(eff);
    project.setOriginalModel(orig);
    final Set<MavenProject> changes = newVersioningModifier().applyVersioningChanges(Collections.singletonList(project), versionsByGAV);
    assertThat(changes.size(), equalTo(1));
    assertThat(orig.getVersion(), equalTo(mv));
    assertThat(eff.getVersion(), equalTo(mv));
}
Also used : MavenProject(org.apache.maven.project.MavenProject) HashMap(java.util.HashMap) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Model(org.apache.maven.model.Model) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Test(org.junit.Test)

Example 43 with SimpleProjectVersionRef

use of org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef in project pom-manipulation-ext by release-engineering.

the class ProjectVersionManipulatorTest method updateEffectiveAndOriginalModelDependencyVersions_InProfile.

@Test
public void updateEffectiveAndOriginalModelDependencyVersions_InProfile() throws Exception {
    final Model orig = new Model();
    orig.setGroupId("org.foo");
    orig.setArtifactId("bar");
    orig.setVersion("1.0");
    final Model depModel = new Model();
    depModel.setGroupId("org.foo");
    depModel.setArtifactId("bar-dep");
    depModel.setVersion("1.0");
    final Dependency dep = new Dependency();
    dep.setGroupId(depModel.getGroupId());
    dep.setArtifactId(depModel.getArtifactId());
    dep.setVersion(depModel.getVersion());
    final Profile p = new Profile();
    p.setId("test");
    orig.addProfile(p);
    p.addDependency(dep);
    final DependencyManagement mgmt = new DependencyManagement();
    final Model dmModel = new Model();
    dmModel.setGroupId("org.foo");
    dmModel.setArtifactId("bar-managed-dep");
    dmModel.setVersion("1.0");
    final Dependency managed = new Dependency();
    managed.setGroupId(dmModel.getGroupId());
    managed.setArtifactId(dmModel.getArtifactId());
    managed.setVersion(dmModel.getVersion());
    mgmt.addDependency(managed);
    p.setDependencyManagement(mgmt);
    final String suff = "redhat-1";
    final String mv = orig.getVersion() + "." + suff;
    final Map<ProjectVersionRef, String> versionsByGA = new HashMap<>();
    versionsByGA.put(new SimpleProjectVersionRef(orig.getGroupId(), orig.getArtifactId(), orig.getVersion()), mv);
    versionsByGA.put(new SimpleProjectVersionRef(depModel.getGroupId(), depModel.getArtifactId(), depModel.getVersion()), mv);
    versionsByGA.put(new SimpleProjectVersionRef(dmModel.getGroupId(), dmModel.getArtifactId(), dmModel.getVersion()), mv);
    final List<MavenProject> projects = new ArrayList<>();
    MavenProject project = new MavenProject(depModel.clone());
    project.setOriginalModel(depModel);
    projects.add(project);
    project = new MavenProject(dmModel.clone());
    project.setOriginalModel(dmModel);
    projects.add(project);
    project = new MavenProject(orig.clone());
    project.setOriginalModel(orig);
    projects.add(project);
    final Set<MavenProject> changes = newVersioningModifier().applyVersioningChanges(projects, versionsByGA);
    assertThat(changes.size(), equalTo(3));
    for (final MavenProject proj : changes) {
        final String a = proj.getArtifactId();
        if (a.equals("bar")) {
            assertThat(proj.getOriginalModel().getVersion(), equalTo(mv));
            assertThat(proj.getModel().getVersion(), equalTo(mv));
            final Profile op = proj.getOriginalModel().getProfiles().get(0);
            final Profile ep = proj.getModel().getProfiles().get(0);
            List<Dependency> deps = op.getDependencies();
            assertThat(deps.size(), equalTo(1));
            Dependency d = deps.get(0);
            assertThat(d, notNullValue());
            assertThat(d.getVersion(), equalTo(mv));
            deps = ep.getDependencies();
            assertThat(deps.size(), equalTo(1));
            d = deps.get(0);
            assertThat(d, notNullValue());
            assertThat(d.getVersion(), equalTo(mv));
            deps = op.getDependencyManagement().getDependencies();
            assertThat(deps.size(), equalTo(1));
            d = deps.get(0);
            assertThat(d, notNullValue());
            assertThat(d.getVersion(), equalTo(mv));
            deps = ep.getDependencyManagement().getDependencies();
            assertThat(deps.size(), equalTo(1));
            d = deps.get(0);
            assertThat(d, notNullValue());
            assertThat(d.getVersion(), equalTo(mv));
        } else {
            assertThat(proj.getOriginalModel().getVersion(), equalTo(mv));
            assertThat(proj.getModel().getVersion(), equalTo(mv));
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Profile(org.apache.maven.model.Profile) MavenProject(org.apache.maven.project.MavenProject) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Model(org.apache.maven.model.Model) DependencyManagement(org.apache.maven.model.DependencyManagement) Test(org.junit.Test)

Example 44 with SimpleProjectVersionRef

use of org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef in project pom-manipulation-ext by release-engineering.

the class ProjectVersionManipulatorTest method updateEffectiveAndOriginalModelDependencyVersions_OnlyWhenHasVersion_InProfile.

@Test
public void updateEffectiveAndOriginalModelDependencyVersions_OnlyWhenHasVersion_InProfile() throws Exception {
    final Model orig = new Model();
    orig.setGroupId("org.foo");
    orig.setArtifactId("bar");
    orig.setVersion("1.0");
    final Model depModel = new Model();
    depModel.setGroupId("org.foo");
    depModel.setArtifactId("bar-dep");
    depModel.setVersion("1.0");
    final Dependency dep = new Dependency();
    dep.setGroupId(depModel.getGroupId());
    dep.setArtifactId(depModel.getArtifactId());
    final Profile p = new Profile();
    p.setId("test");
    orig.addProfile(p);
    p.addDependency(dep);
    final DependencyManagement mgmt = new DependencyManagement();
    final Dependency managed = new Dependency();
    managed.setGroupId(depModel.getGroupId());
    managed.setArtifactId(depModel.getArtifactId());
    managed.setVersion(depModel.getVersion());
    mgmt.addDependency(managed);
    p.setDependencyManagement(mgmt);
    final String suff = "redhat-1";
    final String mv = orig.getVersion() + "." + suff;
    final Map<ProjectVersionRef, String> versionsByGA = new HashMap<>();
    versionsByGA.put(new SimpleProjectVersionRef(orig.getGroupId(), orig.getArtifactId(), orig.getVersion()), mv);
    versionsByGA.put(new SimpleProjectVersionRef(depModel.getGroupId(), depModel.getArtifactId(), depModel.getVersion()), mv);
    final List<MavenProject> projects = new ArrayList<>();
    MavenProject project = new MavenProject(depModel.clone());
    project.setOriginalModel(depModel);
    projects.add(project);
    project = new MavenProject(orig.clone());
    project.setOriginalModel(orig);
    projects.add(project);
    final Set<MavenProject> changes = newVersioningModifier().applyVersioningChanges(projects, versionsByGA);
    assertThat(changes.size(), equalTo(2));
    for (final MavenProject proj : changes) {
        final String a = proj.getArtifactId();
        if (a.equals("bar")) {
            assertThat(proj.getOriginalModel().getVersion(), equalTo(mv));
            assertThat(proj.getModel().getVersion(), equalTo(mv));
            final Profile op = proj.getOriginalModel().getProfiles().get(0);
            final Profile ep = proj.getModel().getProfiles().get(0);
            List<Dependency> deps = op.getDependencies();
            assertThat(deps.size(), equalTo(1));
            Dependency d = deps.get(0);
            assertThat(d, notNullValue());
            assertThat(d.getVersion(), nullValue());
            deps = ep.getDependencies();
            assertThat(deps.size(), equalTo(1));
            d = deps.get(0);
            assertThat(d, notNullValue());
            assertThat(d.getVersion(), nullValue());
            deps = op.getDependencyManagement().getDependencies();
            assertThat(deps.size(), equalTo(1));
            d = deps.get(0);
            assertThat(d, notNullValue());
            assertThat(d.getVersion(), equalTo(mv));
            deps = ep.getDependencyManagement().getDependencies();
            assertThat(deps.size(), equalTo(1));
            d = deps.get(0);
            assertThat(d, notNullValue());
            assertThat(d.getVersion(), equalTo(mv));
        } else {
            assertThat(proj.getOriginalModel().getVersion(), equalTo(mv));
            assertThat(proj.getModel().getVersion(), equalTo(mv));
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Profile(org.apache.maven.model.Profile) MavenProject(org.apache.maven.project.MavenProject) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Model(org.apache.maven.model.Model) DependencyManagement(org.apache.maven.model.DependencyManagement) Test(org.junit.Test)

Example 45 with SimpleProjectVersionRef

use of org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef in project pom-manipulation-ext by release-engineering.

the class ProjectVersionManipulatorTest method updateEffectiveAndOriginalModelDependencyVersions.

@Test
public void updateEffectiveAndOriginalModelDependencyVersions() throws Exception {
    final Model orig = new Model();
    orig.setGroupId("org.foo");
    orig.setArtifactId("bar");
    orig.setVersion("1.0");
    final Model depModel = new Model();
    depModel.setGroupId("org.foo");
    depModel.setArtifactId("bar-dep");
    depModel.setVersion("1.0");
    final Dependency dep = new Dependency();
    dep.setGroupId(depModel.getGroupId());
    dep.setArtifactId(depModel.getArtifactId());
    dep.setVersion(depModel.getVersion());
    orig.addDependency(dep);
    final DependencyManagement mgmt = new DependencyManagement();
    final Model dmModel = new Model();
    dmModel.setGroupId("org.foo");
    dmModel.setArtifactId("bar-managed-dep");
    dmModel.setVersion("1.0");
    final Dependency managed = new Dependency();
    managed.setGroupId(dmModel.getGroupId());
    managed.setArtifactId(dmModel.getArtifactId());
    managed.setVersion(dmModel.getVersion());
    mgmt.addDependency(managed);
    orig.setDependencyManagement(mgmt);
    final String suff = "redhat-1";
    final String mv = orig.getVersion() + "." + suff;
    final Map<ProjectVersionRef, String> versionsByGA = new HashMap<>();
    versionsByGA.put(new SimpleProjectVersionRef(orig.getGroupId(), orig.getArtifactId(), orig.getVersion()), mv);
    versionsByGA.put(new SimpleProjectVersionRef(depModel.getGroupId(), depModel.getArtifactId(), depModel.getVersion()), mv);
    versionsByGA.put(new SimpleProjectVersionRef(dmModel.getGroupId(), dmModel.getArtifactId(), dmModel.getVersion()), mv);
    final List<MavenProject> projects = new ArrayList<>();
    MavenProject project = new MavenProject(depModel.clone());
    project.setOriginalModel(depModel);
    projects.add(project);
    project = new MavenProject(dmModel.clone());
    project.setOriginalModel(dmModel);
    projects.add(project);
    project = new MavenProject(orig.clone());
    project.setOriginalModel(orig);
    projects.add(project);
    final Set<MavenProject> changes = newVersioningModifier().applyVersioningChanges(projects, versionsByGA);
    assertThat(changes.size(), equalTo(3));
    for (final MavenProject p : changes) {
        final String a = p.getArtifactId();
        if (a.equals("bar")) {
            assertThat(p.getOriginalModel().getVersion(), equalTo(mv));
            assertThat(p.getModel().getVersion(), equalTo(mv));
            List<Dependency> deps = p.getOriginalModel().getDependencies();
            assertThat(deps.size(), equalTo(1));
            Dependency d = deps.get(0);
            assertThat(d, notNullValue());
            assertThat(d.getVersion(), equalTo(mv));
            deps = p.getModel().getDependencies();
            assertThat(deps.size(), equalTo(1));
            d = deps.get(0);
            assertThat(d, notNullValue());
            assertThat(d.getVersion(), equalTo(mv));
            deps = p.getOriginalModel().getDependencyManagement().getDependencies();
            assertThat(deps.size(), equalTo(1));
            d = deps.get(0);
            assertThat(d, notNullValue());
            assertThat(d.getVersion(), equalTo(mv));
            deps = p.getModel().getDependencyManagement().getDependencies();
            assertThat(deps.size(), equalTo(1));
            d = deps.get(0);
            assertThat(d, notNullValue());
            assertThat(d.getVersion(), equalTo(mv));
        } else {
            assertThat(p.getOriginalModel().getVersion(), equalTo(mv));
            assertThat(p.getModel().getVersion(), equalTo(mv));
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) MavenProject(org.apache.maven.project.MavenProject) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Model(org.apache.maven.model.Model) DependencyManagement(org.apache.maven.model.DependencyManagement) Test(org.junit.Test)

Aggregations

SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)49 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)41 Test (org.junit.Test)36 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)11 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)11 TestDownload (org.commonjava.maven.galley.testing.core.transport.job.TestDownload)11 Model (org.apache.maven.model.Model)9 RestException (org.commonjava.maven.ext.io.rest.exception.RestException)9 Transfer (org.commonjava.maven.galley.model.Transfer)9 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)7 MavenProject (org.apache.maven.project.MavenProject)6 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)6 URI (java.net.URI)5 LinkedHashMap (java.util.LinkedHashMap)5 Dependency (org.apache.maven.model.Dependency)5 DependencyManagement (org.apache.maven.model.DependencyManagement)5 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)5 Map (java.util.Map)4 Project (org.commonjava.maven.ext.common.model.Project)4