Java Code Examples for org.apache.maven.model.Model#setParent()

The following examples show how to use org.apache.maven.model.Model#setParent() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: maven-git-versioning-extension   File: GAVTest.java    License: MIT License 6 votes vote down vote up
@Test
void of_model_withParent_noInheritance() {
    // Given
    Model model = new Model();
    model.setGroupId("group");
    model.setArtifactId("artifact");
    model.setVersion("version");

    Parent parent = new Parent();
    parent.setGroupId("parentGroup");
    parent.setArtifactId("parentArtifact");
    parent.setVersion("parentVersion");
    model.setParent(parent);

    // When
    GAV gav = GAV.of(model);

    // Then
    assertThat(gav).isNotNull();
    assertThat(gav.getGroupId()).isEqualTo("group");
    assertThat(gav.getArtifactId()).isEqualTo("artifact");
    assertThat(gav.getVersion()).isEqualTo("version");
}
 
Example 2
Source Project: maven-git-versioning-extension   File: GAVTest.java    License: MIT License 6 votes vote down vote up
@Test
void of_model_withParent_withInheritance() {
    // Given
    Model model = new Model();
    model.setArtifactId("artifact");

    Parent parent = new Parent();
    parent.setGroupId("parentGroup");
    parent.setArtifactId("parentArtifact");
    parent.setVersion("parentVersion");
    model.setParent(parent);

    // When
    GAV gav = GAV.of(model);

    // Then
    assertThat(gav).isNotNull();
    assertThat(gav.getGroupId()).isEqualTo("parentGroup");
    assertThat(gav.getArtifactId()).isEqualTo("artifact");
    assertThat(gav.getVersion()).isEqualTo("parentVersion");
}
 
Example 3
private void fixParentProject(IProject p, IProject parentProject)
		throws CoreException {
	IFile existingPom = p.getFile("pom.xml");
	Model model = MavenPlugin.getMavenModelManager().readMavenModel(existingPom);
	Model parent = MavenPlugin.getMavenModelManager().readMavenModel(parentProject.getFile("pom.xml"));
	//Parent oldParent = model.getParent();
	Parent newParent = new Parent();
	newParent.setGroupId(parent.getGroupId());
	newParent.setArtifactId(parent.getArtifactId());
	newParent.setRelativePath(calculateRelativePath(p, parentProject));
	newParent.setVersion(parent.getVersion());
	model.setParent(newParent);
	// outright deletion doesn't work on windows as the process has a ref to the file itself
	// so creating a temp '_newpom_.xml'
	final IFile newPom = p.getFile("_newpom_.xml");
	MavenPlugin.getMavenModelManager().createMavenModel(newPom, model);
	// then copying that content over to the pom.xml
	existingPom.setContents(newPom.getContents(), true,  true, new NullProgressMonitor());
	// and deleting the temp pom
	newPom.delete(true,  false, new NullProgressMonitor());
	
}
 
Example 4
@Test
public void testValidatPom_parentGroup() {
  Model model = new Model();
  model.setParent(new Parent());
  model.getParent().setGroupId("parentGroup");
  model.setArtifactId("testArtifact");
  model.setVersion("1.0");

  underTest.validatePom(model);
}
 
Example 5
@Test
public void testValidatPom_parentVersion() {
  Model model = new Model();
  model.setParent(new Parent());
  model.getParent().setVersion("2.0");
  model.setGroupId("testGroup");
  model.setArtifactId("testArtifact");

  underTest.validatePom(model);
}
 
Example 6
private void mergeParentVersions(Model local, Model remote, Model base, Model result) throws ScmException {
  String localParentVersion = local.getParent() != null ? local.getParent().getVersion() : null;
  String remoteParentVersion = remote.getParent() != null ? remote.getParent().getVersion() : null;
  String baseParentVersion = base.getParent() != null ? base.getParent().getVersion() : null;

  boolean remoteParentRemoved = remoteParentVersion == null && baseParentVersion != null;
  boolean remoteParentAdded = remoteParentVersion != null && baseParentVersion == null;
  boolean remoteParentVersionChanged = !Objects.equal(remoteParentVersion, baseParentVersion);

  boolean localParentRemoved = localParentVersion == null && baseParentVersion != null;
  boolean localParentAdded = localParentVersion != null && baseParentVersion == null;
  boolean localParentVersionChanged = !Objects.equal(localParentVersion, baseParentVersion);

  if (localParentAdded) {
    // if locally added the base had no parent (remote remove and change is not relevant)
    if (remoteParentAdded) {
      if (Objects.equal(local.getParent().getArtifactId(), remote.getParent().getArtifactId())
          && Objects.equal(local.getParent().getGroupId(), remote.getParent().getGroupId())) {
        if (MavenVersionUtil.isNewerVersion(local.getParent().getVersion(), remote.getParent().getVersion())) {
          result.setParent(local.getParent());
        }
      } else {
        throw new ScmException(ScmOperation.MERGE,
            "Could not merge local and remote POM parent changes since both versions added different parent artifacts.");
      }
    } else {
      result.setParent(local.getParent());
    }
  } else if (localParentRemoved) {
    // if locally removed the base had a parent (remote add is not relevant and remote remove is ok)
    if (remoteParentVersionChanged) {
      throw new ScmException(ScmOperation.MERGE,
          "Could not merge POM parent version conflicts since in the local POM the parent had been removed and in the remote POM the parent had been changed.");
    } else {
      result.getParent().setVersion(localParentVersion);
    }
  } else if (localParentVersionChanged) {
    // if locally changed the base had a parent (remote add is not relevant)
    if (remoteParentVersionChanged) {
      if (Objects.equal(local.getParent().getArtifactId(), remote.getParent().getArtifactId())
          && Objects.equal(local.getParent().getGroupId(), remote.getParent().getGroupId())) {
        if (MavenVersionUtil.isNewerVersion(local.getParent().getVersion(), remote.getParent().getVersion())) {
          result.setParent(local.getParent());
        }
      } else {
        throw new ScmException(ScmOperation.MERGE,
            "Could not merge local and remote POM parent changes since both versions are referencing different parent artifacts.");
      }
    } else if (remoteParentRemoved) {
      throw new ScmException(ScmOperation.MERGE,
          "Could not merge POM parent version conflicts since in the local POM the parent had been updated while in the remote POM the parent had been removed.");
    } else {
      result.getParent().setVersion(localParentVersion);
    }
  }
}
 
Example 7
@Override
public void set( Model model, Parent value )
{
    model.setParent( value );
}