Skip to content

Modularize JHotDraw with Java Platform Module System (JPMS) - #35

Open
taherehbi1994 wants to merge 1 commit into
wumpz:developfrom
taherehbi1994:modularize-jhotdraw
Open

Modularize JHotDraw with Java Platform Module System (JPMS)#35
taherehbi1994 wants to merge 1 commit into
wumpz:developfrom
taherehbi1994:modularize-jhotdraw

Conversation

@taherehbi1994

Copy link
Copy Markdown

Hey there 👋
I've been working on modularizing JHotDraw using JPMS (Java Platform Module System) as part of my PhD research. Each sub-module now has its own module-info.java, so dependencies and exported packages are explicit.
It was a fun (and sometimes tricky!) exercise figuring out the right module boundaries for this codebase. Would love to hear your thoughts on it, and I'm happy to adjust anything that doesn't fit well with the project's direction.
Thanks for maintaining such a great project!

@wumpz wumpz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Looking at the branch network JHotdraw seems to be a project in multiple student tasks. Nice.
Since we use it in a non JPMS project, this was never a problem or an issue.

What kind of task do you want to achieve JPMS modularizing JHotdraw?

Looking forward hearing from you.

Tobias

if (c != null && c.isEnabled()) {
Transferable t = ClipboardUtil.getClipboard().getContents(c);
if (t != null && c.getTransferHandler() != null) {
if (c.getTransferHandler().importData(c, t)) importDataSuccess();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why did you revert my recent changes?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi Tobias,

Just to clarify the overall approach: for the modularization itself, we don't need to touch the logic of the code or change anything inside the methods.

The only changes involved are:

  • Adding module-info.java files to declare dependencies and exports
  • Adjusting pom.xml for module support
  • In some cases, renaming a test's package when it collides with the main class's package, to avoid a split-package error under JPMS

So any place where a line looks removed or changed in the diff (like the importData call in PasteAction.java) wasn't an intentional edit on my part - it's most likely because my branch was based on an older point in develop and doesn't include some of your more recent commits. I'll rebase on the latest develop so the diff only reflects the actual modularization changes.

@@ -17,7 +17,7 @@
* MA 02110-1301 USA
*/

package org.jhotdraw.io;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why do you move tests in a subpackage test? Since tests should be in the same package as the tested class. This has also something to do with visibility and maven standards.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is because of a JPMS rule: two modules can't share the same package name (a "split package", which the compiler rejects). Since the tests are being modularized into their own module, and org.jhotdraw.io is already owned by the main module, the test module needs a different package name, hence org.jhotdraw.io.test.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Sorry for keeping you waiting. ;)

I do not like the tests in a different package. This goes against maven standards. Developers, IDEs are expecting the directory structure of a familiar kind.
As far as I know, the surefire plugin somehow injects the tests into the main module, when the tests do not have a module-info.java file. Its called patching. So the test classes could be in the same package as the tested classes. That would be suitable and not break the standards. Right?

Building multiple larger Server/Client applications, the use of JPMS was til now never needed or even could not be acomplished in a meaninful manner and time. So what is the advantage using JPMS while most of the libraries you are using for an application are not using it? Using an automatic module name introduces other problems. For instance in some configurations you get a version at the module name generated from the base package.

Sure, JPMS gives you more control over which parts of your module you open to the outside. However, to use JPMS you need to tackle those problems mentioned above. At the moment the only real advantage of JPMS was indeed the modularization of the JDK. IMHO

Tobias

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