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

Add JPMS module test #2685

Merged
merged 2 commits into from
May 29, 2024

Conversation

Marcono1234
Copy link
Collaborator

@Marcono1234 Marcono1234 commented May 26, 2024

Purpose

Adds a Maven module to test Gson's module-info.class

Description

Previously the build would not have detected if module-info.class was missing, or incorrectly configured. Therefore this pull request adds a new Maven module to test using the module-info.class.

The new integration tests might not work when run from the IDE, but they will work when run with mvn ... from the command line.

Please let me know if you think it is too verbose, if the test should cover additional cases, or if there might be a better way to implement this. Any feedback is appreciated.

To simplify disabling certain Maven plugins (e.g. install, gpg and deploy) for the integration test modules I have instead added two properties in the parent project which can disable the plugins. See the second commit.
I have done a short test of the release workflow (but without gpg), and everything still seems to work as desired: The build succeeds and only gson-parent and gson are deployed.

Checklist

  • New code follows the Google Java Style Guide
    This is automatically checked by mvn verify, but can also be checked on its own using mvn spotless:check.
    Style violations can be fixed using mvn spotless:apply; this can be done in a separate commit to verify that it did not cause undesired changes.
  • If necessary, new public API validates arguments, for example rejects null
  • New public API has Javadoc
    • Javadoc uses @since $next-version$
      ($next-version$ is a special placeholder which is automatically replaced during release)
  • If necessary, new unit tests have been added
    • Assertions in unit tests use Truth, see existing tests
    • No JUnit 3 features are used (such as extending class TestCase)
    • If this pull request fixes a bug, a new test was added for a situation which failed previously and is now fixed
  • mvn clean verify javadoc:jar passes without errors

Previously the build would not have detected if `module-info.class` was missing,
or incorrectly configured.
Defines properties in the parent POM which determine whether the plugins
should be skipped, and then sets the properties in the Maven modules.
@Marcono1234 Marcono1234 force-pushed the marcono1234/jpms-module-test branch from 1ef331c to f141d13 Compare May 26, 2024 00:20
*
* <blockquote>
*
* Can't compile test sources when main sources are missing a module descriptor
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe there is another way to work around this; the Maven Compiler Plugin checks if the main output directory exists, but maybe that check is a bit brittle?

https://lists.apache.org/thread/c3f71v8tf3643dto6bwf3ctcos4gt5cq suggests it might even depend on the JUnit version being used (?).

So for now having this dummy module declaration might be the most reliable workaround.

Comment on lines +31 to 33
<module>jpms-test</module>
<module>graal-native-image-test</module>
<module>shrinker-test</module>
Copy link
Collaborator Author

@Marcono1234 Marcono1234 May 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would make sense to change the names of these modules to be test-... instead of ...-test so that they are grouped in the file system, and it is more obvious that they are tests.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be an excellent idea for a follow-up PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have created #2691

Copy link
Member

@eamonnmcmanus eamonnmcmanus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thanks very much for doing it!

Are you able to test dry-run releasing? No problem if not, we'll find out soon enough and I'll fix any issues that arise.

"com.google.gson.reflect",
"com.google.gson.stream");
// Gson currently does not export packages to specific modules only
assertThat(packageExports.stream().filter(Exports::isQualified)).isEmpty();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think noneMatch would be a bit more succinct.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean assertThat(stream.noneMatch(...)).isTrue()? (Or is there a Truth method I am overlooking?)

The disadvantage might be that if there are actually matching packages, the assertion failure message would just say that true was expected but it was false, whereas this approach should (hopefully) produce a more helpful assertion failure message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point. It's better the way it is.

Comment on lines +31 to 33
<module>jpms-test</module>
<module>graal-native-image-test</module>
<module>shrinker-test</module>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be an excellent idea for a follow-up PR.

@Marcono1234
Copy link
Collaborator Author

Are you able to test dry-run releasing? No problem if not, we'll find out soon enough and I'll fix any issues that arise.

I tried the approach described in https://github.com/google/gson/blob/main/ReleaseProcess.md#testing-maven-release-workflow-locally (except for GPG signing), and it looks like everything was still working. So I hope this shouldn't break anything.

But yes, in the worst case we notice it for the next release... (or hopefully earlier)

(Also sorry that I had missed that the GPG plugin was not disabled for the graal-native-image-test module, which you then fixed in #2675.)

@eamonnmcmanus eamonnmcmanus merged commit 6ebbc9d into google:main May 29, 2024
11 checks passed
@Marcono1234 Marcono1234 deleted the marcono1234/jpms-module-test branch May 30, 2024 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants