-
Notifications
You must be signed in to change notification settings - Fork 35
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
Modularize modernize #61
Conversation
This cleans up the POM files in several ways: Dependency versions are declared in the parent POM so that all version updates happen in one place. The user is now required to use JDK 9 to compile the code, but the produced bytecode is guaranteed to be compatible with JDK 7 and above thanks to the use of the -release flag. Plugin versions are replaced with properties for painless updates with the Maven Versions plugin. All POM files were run through Intellij IDEA's XML formatter for consistent indentation. Compiler severity has been reduced from -Werror temporarily due to new warnings that would have otherwise broken the build.
This adds @deprecated annotations to all methods that had @deprecated JavaDoc sections.
This adds module descriptors with the correct "requires" clauses. The modules export everything (including classes in the "internal" packages), so this may need to be reviewed.
Thank, very nice, I'll have a look. I wonder what other users think, being backwards compatible is an important feature (which you considered). |
Having done quite a lot of this, I think it's arguably acceptable to push people to use newer compilers (because they're freely available everywhere and there are rarely any downsides to upgrading), but not acceptable to force people to use newer runtimes (because there are often technical and organizational reasons that users can't migrate their existing deployments right away). The above changes only do the former, to be clear! |
I have some extra additions I can make that would add OSGi metadata. Because why be compatible with one module system when you can be compatible with two! 😁 |
Hmm, I'm not sure I understand the point of using OSGi for ode4j. Wouldn't there need to be a standard physics API that ode4j needs to support? Or how would you use ode4j through OSGi? |
I'm not sure what you mean. A standard physics API? OSGi is a module system just like Java 9's module system. To support it, you just add some fields to the jar manifest. We actually did this for Dyn4j: https://github.com/dyn4j/dyn4j/blob/master/pom.xml#L219
The |
I've heard good things about dyn4j, but haven't used it myself yet :-) Hmm, I honestly haven't used OSGi much (a tiny Eclipse plugin, and my ZooDB project also supports OSGi service discovery). In both cases OSGi provides dynamic loading of components/services, which, however, require implementing some kind of standard API in order to provide that service. So I thought ode4j would also become a 'service', hence my assumed need for a standard physics API. I suppose there is much more to OSGi than I am aware. I'll have to read up on it a bit to see what it can do, especially in terms of modularization. If I understand correctly, the OSGi update consists (mostly) of a Manifest update? |
Yep. Essentially what we do is compile all of the code (including the module descriptor) as Java 9 bytecode. This gives us error reporting for things like missing "requires" clauses, etc. We then recompile all of the code except for the module descriptor using the
You're right in that they do love their services. In the case of
I think in the case of a project like
Yep, it's purely a manifest update. |
You might enjoy this one: https://blog.io7m.com/2017/06/01/osgi-resource-bundles.xhtml |
* * | ||
*************************************************************************/ | ||
|
||
module ord.ode4j.cpp { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ord.ode4j ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Corrected!
Looks good to me. I am wondering if there are any OSGi-based applications using ode4j currently, maybe some apps based on Eclipse or Netbeans platform? |
I have pulled the changes, however, I have set source=1.7 for know. I created a poll to get a better idea who requires Java 7 compatible source code (for example when developing for android): |
'Ello. This change is incorrect: bde8b23#diff-600376dffeb79835ede4a0b285078036R205 The reason being that the first step is to compile all of the code as Java 9 (hence source == |
Maybe add:
and:
... to help IDEs decide what compliance level they should be using. |
Okay, I admit I didn't completely realize the implications of this whole pull request. First, two observations:
I'm not quite sure where you suggested to put the source/target=9 entries? What I somehow missed is this: With the original pull-request, a developer may be tempted to write something with Java 9 compliant code and only during the maven build (potentially much later) realize that Java 9 is not 'allowed'. However, enforcing Java 7 source compliance removes the benefit of better warnings, it also unnecessarily limits developers that do not build with Maven at all. Does anyone have any more thoughts on this? |
I think they probably are, yes. I've been staring at Java 9 projects for so long that I've developed the habit of referring to versions by their "new" names. 😄
Yes, I've just tried it and I see that too. I'm not sure that's supposed to happen.
I'm not sure which would be preferable behaviour. If you specify Java 7 in a way that'll be picked up by IDEs, then those IDEs are going to complain about the module descriptor existing at all (IDEA, for example, tells you that you need to use Java 9 to define one). If you specify Java 9, the IDE will let you write a module descriptor but you won't get errors about using I feel like the latter is better. Most projects I work with use the Maven build as the canonical source of binaries, and they usually set up something like Travis CI to build pull requests and complain if the compilation fails. I think this is more a case of IDE immaturity than anything. Java 9 hasn't been out long, and I don't think IDEs have fully caught up with the consequences of the I have noticed that some IDEs ignore the Maybe you want something like this:
|
Turns out Mark Reinhold brought up this exact point on the OpenJDK Jigsaw list yesterday:
http://mail.openjdk.java.net/pipermail/jigsaw-dev/2018-March/013689.html |
Hello!
I'm not sure if you'll be interested in this, but I want to use
ode4j
in a Java 9 modular project. I've been assisting a lot of other projects with transitioning to a modular world, so I thought I'd give modularizingode4j
a try.It actually went very well: You have very few dependencies and a well defined package hierarchy. The commits below do the following:
Clean up the POM structure slightly. This moves all version numbers to a central location so that they can be updated once. It moves all plugin versions to properties so that they can be updated with the Maven Versions plugin (for some reason the plugin doesn't support updating plugin versions, but it does support updating properties and can therefore update plugins that way). I reformatted the POMs using your existing layout settings.
Start requiring JDK 9 to build the code. Don't panic: The code produced is still Java 7 compatible. In fact, it's actually guaranteed to be Java 7 compatible in a way that it wasn't before: The JDK 9 compiler comes with a new
--release
flag that guarantees both bytecode and API compatibility with the specified release version (previouslyjavac
could only guarantee bytecode compatibility). I've added an Enforcer plugin execution to give users a nice error message if they try to compile the code with a version of the JDK that's too old. I had to remove-Werror
from the compiler options as the newer compiler seems to emit warnings that the old compiler didn't and I didn't want to modify the code to fix them without knowing what I was doing. One exception to this: I added@Deprecated
annotations to methods that were marked via JavaDoc as@deprecated
but lacked a corresponding@Deprecated
annotation. This squashed a good 50-60 warnings.Add module descriptors. This is what makes the project a modular project. The descriptors explicitly state which modules are required and which packages are exported. I exported everything, but perhaps you'd want to review this as maybe some of the "internal" packages shouldn't be exported. I don't know the API well enough yet to say.
Add a
.travis.yml
config file to build the code on Travis CI. You don't have to keep this if you don't want Travis. The config file will sit there doing nothing until you either delete it or enable Travis for your Github account. The code builds correctly and all tests pass.