Search in sources :

Example 36 with Project

use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.

the class JSONManipulatorTest method updateURL.

@Test
public void updateURL() throws ManipulationException, IOException {
    String modifyPath = "$.repository.url";
    File target = tf.newFile();
    FileUtils.copyFile(pluginFile, target);
    Project project = new Project(null, target, null);
    jsonManipulator.internalApplyChanges(project, new JSONState.JSONOperation(target.getName(), modifyPath, "https://maven.repository.redhat.com/ga/"));
    assertTrue(FileUtils.readFileToString(target).contains("https://maven.repository.redhat.com/ga/"));
    assertFalse(FileUtils.contentEquals(pluginFile, target));
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) File(java.io.File) JSONState(org.commonjava.maven.ext.core.state.JSONState) Test(org.junit.Test) JSONIOTest(org.commonjava.maven.ext.io.JSONIOTest)

Example 37 with Project

use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.

the class DistributionEnforcingManipulatorTest method applyTest.

@SuppressWarnings("unused")
private void applyTest(final Set<Model> models, final Set<Model> expectChanged) throws Exception {
    final List<Project> projects = new ArrayList<>();
    final Map<String, Model> manipulatedModels = new HashMap<>();
    for (final Model model : models) {
        final Project project = new Project(model);
        projects.add(project);
        manipulatedModels.put(ga(model), model);
    }
    final Set<Project> changed = manipulator.applyChanges(projects);
    if (expectChanged != null && !expectChanged.isEmpty()) {
        assertThat(changed.isEmpty(), equalTo(false));
        for (final Model model : expectChanged) {
            assertThat(changed.contains(new Project(model)), equalTo(true));
        }
    } else {
        assertThat(changed.isEmpty(), equalTo(true));
    }
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Model(org.apache.maven.model.Model)

Example 38 with Project

use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.

the class VersioningCalculatorTest method incrementExistingSerialSuffix_TwoProjects_UsingRepositoryMetadata_DifferentAvailableIncrements.

@Test
public void incrementExistingSerialSuffix_TwoProjects_UsingRepositoryMetadata_DifferentAvailableIncrements() throws Exception {
    final String v = "1.2.0.GA";
    final String os = "-foo-1";
    final String ns = "foo-10";
    final Model m1 = new Model();
    m1.setGroupId(GROUP_ID);
    m1.setArtifactId(ARTIFACT_ID);
    m1.setVersion(v + os);
    final Project p1 = new Project(m1);
    final String a2 = ARTIFACT_ID + "-dep";
    final Model m2 = new Model();
    m2.setGroupId(GROUP_ID);
    m2.setArtifactId(a2);
    m2.setVersion(v + os);
    final Project p2 = new Project(m2);
    final Properties props = new Properties();
    props.setProperty(VersioningState.INCREMENT_SERIAL_SUFFIX_SYSPROP.getCurrent(), "foo-0");
    final Map<ProjectRef, String[]> versionMap = new HashMap<>();
    versionMap.put(new SimpleProjectRef(p1.getGroupId(), p1.getArtifactId()), new String[] { "1.2.0.GA-foo-3", "1.2.0.GA-foo-2", "1.2.0.GA-foo-9" });
    versionMap.put(new SimpleProjectRef(p2.getGroupId(), p2.getArtifactId()), new String[] { "1.2.0.GA-foo-3", "1.2.0.GA-foo-2" });
    setupSession(props, versionMap);
    final Map<ProjectVersionRef, String> result = modder.calculateVersioningChanges(Arrays.asList(p1, p2), session);
    assertThat(result.get(new SimpleProjectVersionRef(GROUP_ID, ARTIFACT_ID, v + os)), equalTo(v + "-" + ns));
    assertThat(result.get(new SimpleProjectVersionRef(GROUP_ID, a2, v + os)), equalTo(v + "-" + ns));
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) SimpleProjectRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectRef) 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) Properties(java.util.Properties) SimpleProjectRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectRef) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Test(org.junit.Test)

Example 39 with Project

use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.

the class VersioningCalculatorTest method incrementExistingSerialSuffix_TwoProjects_UsingRepositoryMetadata_AvailableOnlyForOne.

@Test
public void incrementExistingSerialSuffix_TwoProjects_UsingRepositoryMetadata_AvailableOnlyForOne() throws Exception {
    final String v = "1.2.0.GA";
    final String os = "-foo-1";
    final String ns = "foo-10";
    final Model m1 = new Model();
    m1.setGroupId(GROUP_ID);
    m1.setArtifactId(ARTIFACT_ID);
    m1.setVersion(v + os);
    final Project p1 = new Project(m1);
    final String a2 = ARTIFACT_ID + "-dep";
    final Model m2 = new Model();
    m2.setGroupId(GROUP_ID);
    m2.setArtifactId(a2);
    m2.setVersion(v + os);
    final Project p2 = new Project(m2);
    final Properties props = new Properties();
    props.setProperty(VersioningState.INCREMENT_SERIAL_SUFFIX_SYSPROP.getCurrent(), "foo-0");
    setupSession(props, "1.2.0.GA-foo-3", "1.2.0.GA-foo-2", "1.2.0.GA-foo-9");
    final Map<ProjectVersionRef, String> result = modder.calculateVersioningChanges(Arrays.asList(p1, p2), session);
    assertThat(result.get(new SimpleProjectVersionRef(GROUP_ID, ARTIFACT_ID, v + os)), equalTo(v + "-" + ns));
    assertThat(result.get(new SimpleProjectVersionRef(GROUP_ID, a2, v + os)), equalTo(v + "-" + ns));
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Model(org.apache.maven.model.Model) Properties(java.util.Properties) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Test(org.junit.Test)

Example 40 with Project

use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.

the class PropertiesUtilsTest method testUpdateNestedProperties2.

@Test
public void testUpdateNestedProperties2() throws Exception {
    Project pP = getProject();
    ManipulationSession session = createUpdateSession();
    assertTrue(updateProperties(session, pP, false, "version.hibernate.osgi", "5.0.4.Final-redhat-1") == PropertiesUtils.PropertyUpdate.FOUND);
    assertFalse(updateProperties(session, pP, false, "version.scala", "2.11.7") == PropertiesUtils.PropertyUpdate.FOUND);
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) Test(org.junit.Test)

Aggregations

Project (org.commonjava.maven.ext.common.model.Project)56 Model (org.apache.maven.model.Model)27 Test (org.junit.Test)25 HashSet (java.util.HashSet)21 File (java.io.File)19 HashMap (java.util.HashMap)11 ManipulationSession (org.commonjava.maven.ext.core.ManipulationSession)9 Profile (org.apache.maven.model.Profile)7 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)7 PomIO (org.commonjava.maven.ext.io.PomIO)7 ArrayList (java.util.ArrayList)6 Properties (java.util.Properties)6 ArtifactRef (org.commonjava.maven.atlas.ident.ref.ArtifactRef)6 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)6 Map (java.util.Map)5 Dependency (org.apache.maven.model.Dependency)5 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)5 SimpleArtifactRef (org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef)4 DependencyState (org.commonjava.maven.ext.core.state.DependencyState)4 IOException (java.io.IOException)3