Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper methods on MavenProjectResult to get Model from sub-modules in multi-model project #298

Open
JWT007 opened this issue Nov 2, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@JWT007
Copy link

JWT007 commented Nov 2, 2022

I don't know if this is even possible but I thought I would throw it out there. :)
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is.

Currently it is possible to get the maven Model from the execution result.

result.getMavenProjectResult().getModel()

In a multi-module project, you can currently only get the path to a nested POM and use the MavenXpp3Reader to read it to get the nested Model.

assertThat(result)
        .isSuccessful()
        .satisfies(r -> {
          assertThat(new File(r.getMavenProjectResult().getTargetProjectDirectory(), "test-jar1/pom.xml"))
            .as("Jar1 POM file")
            .exists()
            .satisfies(f -> {
              assertThat(readPomModelFromFile(f))
                .as("Jar1 POM Model")
                .isNotNull()
                .extracting(Model::getGroupId, Model::getArtifactId, Model::getVersion, Model::getPackaging)
                .as("GAVP")
                .containsExactly("me.jwt007.maven.plugins.foobar.its", "foobar-jar1", "1.2.3", "jar");
            });
        });

  private Model readPomModelFromFile(final File pomFile) {
    Model model = null;
    try (FileInputStream fis = new FileInputStream(pomFile)) {
      model = (new MavenXpp3Reader()).read(fis);
    } catch (Exception ex) {
      fail("Unable to parse flattened POM model from: " + pomFile, ex);
    }
    assertNotNull(model);
    return model;
  }

Describe the solution you'd like
A clear and concise description of what you want to happen.

If possible it would be great if there was a convenience function to get the Model of a sub-module in a multi-module project.

result.getMavenProjectResult().getModule("myjars").getModule("jar1").getModel()

.. or something along those lines. :).

It would reduce the test size by a few lines and eliminate the need for a helper function (at least in my code :P)

  assertThat(result)
        .isSuccessful()
        .satisfies(r -> {
          assertThat(r.getMavenProjectResult().getModule("test-jar1").getModel())
            .as("Jar1 POM Model")
            .isNotNull()
            .extracting(Model::getGroupId, Model::getArtifactId, Model::getVersion, Model::getPackaging)
            .as("GAVP")
            .containsExactly("me.jwt007.maven.plugins.foobar.its", "foobar-jar1", "1.2.3", "jar");
          });
@JWT007 JWT007 added the enhancement New feature or request label Nov 2, 2022
@JWT007
Copy link
Author

JWT007 commented Nov 3, 2022

Maybe this request makes no sense... sorry I am no assertj expert and am sort of learning by doing now.

I guess to get the Model you need to do the satisfies/assertThat to get at the "actual" where the Model lives. Since I am assuming you don't want to write AssertJ extensions for the whole Maven model. :)


But if I am not totally off :) (not the subject of this issue)...

It should be relatively easy to add the following to MavenProjectResultAssert since you are saving the Optional<MavenProjectResultAssert> parent.

  • public MavenProjectResultAssert hasParent()
  • public MavenProjectResultAssert parent()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant