[ppt]powerpoint presentation - rainfocus | harness … · web viewoutreach jdk 9 ready status for...

Post on 15-Apr-2018

233 Views

Category:

Documents

5 Downloads

Preview:

Click to see full reader

TRANSCRIPT

PROJECT J IGSAW – INTEGRATION WITH

TOOLSJavaOne03.10.201

7 Alexandru JecanSoftware Engineer | Author | Trainer | Speaker | Consultant

SAN FRANCISCO

SUMMARY

02

1 Integration with Build Tools2 Apache Maven

7 Maven Jmod Plugin

PROJECT JIGSAW – INTEGRATION WITH TOOLS

3 Maven Compiler Plugin

5 Backward Compatibility Using Maven Toolchain Plugin Toolchain Plugin6 Maven JDeps Plugin

4 Maven Exec Plugin

SUMMARY

03

8 Maven Jlink Plugin9 Maven Dependency Plugin

12

PROJECT JIGSAW – INTEGRATION WITH TOOLS

1110

Ant

Gradle

Loom

SUMMARY

04

13 Moditect

PROJECT JIGSAW – INTEGRATION WITH TOOLS

GradleAnt

Loom

14 SonarJava

15 Graphviz

SUMMARY

05

16 Integration with Integrated Development Environments

17 NetBeans support

18 Eclipse support

19 Intellij IDEA support

PROJECT JIGSAW – INTEGRATION WITH TOOLS

21 JDK 9 Ready Libraries

22 Status Modularization Third-party Libraries

20 JDK 9 Ready Status

SUMMARY

06

23 Modularized Third-party Libraries24 How to Modularize a Library

29PROJECT JIGSAW – INTEGRATION WITH TOOLS

25 Encapsulated JDK internal APIs

26 Not resolved platform modules

2728

Cyclic dependenciesSplit packages

Java 9 Modularity Revealed book

What do you expect from a tool to do in order to make development using Jigsaw easier?

QUESTION

07 PROJECT JIGSAW – INTEGRATION WITH TOOLS

INTEGRATION WITH BUILD TOOLS

08 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Jigsaw

Build Tools Strong encapsulation

Services Build the project Central repository

Link into run-time images Dependency management

The Java Module System, Nicolai Parlog, Manning

Reliable configuration Record dependencies Verify at compile time

and run time

Record artifacts Verify for compilation

Download artifacts

Select artifacts for compilation

INTEGRATION WITH BUILD TOOLS

09 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Build Tools Class path

Build ToolsClass path

Module path

Prior to JDK 9

JDK 9+

Only Maven 3+ supports Java 9

APACHE MAVEN

10 PROJECT JIGSAW – INTEGRATION WITH TOOLS

No changes were performed in Maven Core in order to make Maven run on Java 9

Maven can also use the module path for compilation (besides the class path)

Normal modules as well as automatic modules can be defined as dependencies

The presence of module-info.java decides if Maven uses the module path or not

The <groupId>, <artifactId> and <version> from pom.xml are not related to the name of the module from module-info.java

APACHE MAVEN

11 PROJECT JIGSAW – INTEGRATION WITH TOOLS

To add a dependency in pom.xml, the Maven specific names are used, as before

To require a module in module-info.java, the name of the module from the module

descriptors is used

Offers support for JPMS starting with version 3.6.0

MAVEN COMPILER PLUGIN

12 PROJECT JIGSAW – INTEGRATION WITH TOOLS

During the compile phase, when a module-info.java file is found, it automatically switches to the module path

source and target have to be minimum 6

Latest version = 3.7.0 (as of September 2017) Requires JDK 7+

Module-info is compiled as well

MAVEN COMPILER PLUGIN

13 PROJECT JIGSAW – INTEGRATION WITH TOOLS

<compilerArgs> <arg>--add-modules</arg> <arg>java.xml.bind</arg></compilerArgs>

Flags like --add-modules or --add-exports can be added directly in the pom.xml

<compilerArgs> <arg>--add-exports</arg> <arg>java.base/sun.net=myModule</arg></compilerArgs>

MAVEN COMPILER PLUGIN

14 PROJECT JIGSAW – INTEGRATION WITH TOOLS

<plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.0</version> <executions> <execution> <id>example</id> <goals> <goal>compile</goal> </goals> <configuration> <compilerArgs> <arg>--add-exports</arg>

<arg>java.base/sun.net=myModule</arg> <arg>--add-modules</arg> <arg>java.xml.bind</arg></compilerArgs>

</configuration> </execution> </executions></plugin>

MAVEN COMPILER PLUGIN

15 PROJECT JIGSAW – INTEGRATION WITH TOOLS

A new tag called <release>, which has greater precendence over the <source> and <target> tags

<release> corresponds to the option “maven.compiler.release” For providing backward compatibility:

1) Module-info should be compiled with --release 92) All the other sources compiled with --source < 9 and --target < 9

MAVEN EXEC PLUGIN

16 PROJECT JIGSAW – INTEGRATION WITH TOOLS

<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.6.0</version> <executions> <execution> <goals> <goal>exec</goal> </goals> </execution> </executions> <configuration> <executable>${JAVA_HOME}/bin/java</executable> <arguments> <argument>--module-path</argument> <modulepath/> <argument>--module</argument> <argument>{myMainClass}</argument> <argument>${myArgument}</argument> </arguments> </configuration></plugin>

Java 9 Modularity Sander Mak,Paul Bakker,O’Reilly

Solves JEP 247: Compile for Older Platform VersionsBACKWARD COMPATIBILITY WITH MAVEN TOOLCHAIN PLUGIN

17 PROJECT JIGSAW – INTEGRATION WITH TOOLS

With toolchains, we can specify the JDKs installed on our system A project can be built using a specific version of the JDK that is independent from the one Maven is running with

To use Toolchains:1) The maven-toolchain-plugin should be adjusted2) The toolchains.xml file should be adjusted

Toolchains required when we have the module-info.java file inside the sources and we want to compile it with an older version of Java

BACKWARD COMPATIBILITY WITH MAVEN TOOLCHAIN PLUGIN

18 PROJECT JIGSAW – INTEGRATION WITH TOOLS

JDeps can:

MAVEN JDEPS PLUGIN

19 PROJECT JIGSAW – INTEGRATION WITH TOOLS

discover all static dependencies of a library discover the usages of internal JDK APIs automatically generate a module descriptor for a JAR

file Maven JDeps Plugin has two goals: jdkinternals => checks if main classes depend on

JDK-internal classes test-internals => checks if test classes depend on

JDK-internal classes

A compilation is necessary, since JDeps uses classes and not sources

MAVEN JDEPS PLUGIN

20 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Should be used to test if your project is ready for JDK 9 By setting the <failOnWarning> option to true, the build will immediately fail if there are any warnings

MAVEN JDEPS plugin

21 PROJECT JIGSAW – INTEGRATION WITH TOOLS

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jdeps-plugin</artifactId> <version>3.0.0</version> <executions> <execution> <id>testOnClasses</id> <goals> <goal>jdkinternals</goal> <goal>test-jdkinternals</goal> </goals> </execution> <execution> <id>testOnDependencies</id> <goals> <goal>jdkinternals</goal> <goal>test-jdkinternals</goal> </goals> <configuration> <failOnWarning>false</failOnWarning> <recursive>true</recursive> </configuration> </execution> </executions></plugin>

Pre-release version (as of September 2017)

MAVEN JMOD PLUGIN

22 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Can create JMOD files (create goal)

First version = 3.0.0-alpha-1 Works with Maven 3+ and JDK 7+

Can list the content of a JMOD file (list or describe goal)

Pre-release version (as of September 2017)

MAVEN JLINK PLUGIN

23 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Can create Modular Run-Time Images via Jlink from jar /JMOD files (jlink goal)

First version = 3.0.0-alpha-1 Works with Maven 3+ and JDK 7+

Has parameters like: <addModules>, <bindServices>, <compression>, <limitModules>, etc.

MAVEN DEPENDENCY PLUGIN

24 PROJECT JIGSAW – INTEGRATION WITH TOOLS

The list option lists the groupId, artifactId together with the name of the module

Works since the --illegal-access=permit option was set as default

GRADLE

25 PROJECT JIGSAW – INTEGRATION WITH TOOLS

No --add-opens options necessary to build GradleNo first class support for Java 9 modules as of 26.09.2017

Work in progress

Running Java 9 on Gradle 4.1+ is supported Example of producing a multi-release JAR with Gradle => https://github.com/melix/mrjar-gradle

Ants java, javac and junit understand the new command-line parameters that are specific to JDK 9 modules

ANT

26 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Single module and multi module compilation supported Support for module path and upgrade module path added in Ant 1.9.7

Since Ant 1.9.8 and 1.10.0: <java>, <javac> and <junit> support JDK 9 modules Support for javac --release option ant.java.version holds the value “9”

LOOM

27 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Modern and lightweight build tool for Java 9+ YAML configuration Convention over configuration Build with Java 9 => first-class JPMS support (Optional) Minimalistic configuration Dependency resolution (powered by the Apache Maven Repository) Support for Junit 5, Checkstyle, SpotBugs, PMD, IntellijIDEA, Eclipse

LOOM

28 PROJECT JIGSAW – INTEGRATION WITH TOOLS

https://loom.builders/

Loom source code => https://github.com/loom-build-tool/loom

Loom documentation => https://loom-build-tool.readthedocs.io/en/latest/

Examples with Loom => https://github.com/loom-build-tool/loom-examples

https://github.com/moditect/moditect

MODITECT

29 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Maven plugin Can generate module-info.java descriptors for given artifacts on behalf of the specific information written by developers in pom.xml Can add module descriptors to JAR files

Can create modular runtime images

Support for JPMS starting from version 4.11

SonarJAVA

30 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Able to recognize and parse module-info.java Can handle the directives from module-info.java: requires, exports, opens, uses and provides

ModuleDeclaration: {Annotation} [open] module Identifier {. Identifier} { {ModuleDirective} }

Recognizes new keywords related to modules from Java 9

Open source graph visualization softwareGRAPHVIZ

31 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Creates a graphical representation of Jigsaw modules and their dependencies:

jdeps -dotoutput jdeps-dotoutput modules/*.jar \Tools\Graphviz\release\bin\dot.exe –Tpngjdeps-dotoutput/summary.dot > graphviz-summary.png

start graphviz-summary.png

Example for Windows:

http://www.torsten-horn.de/techdocs/Jigsaw.html#Abh%C3%A4ngigkeitsgraph-mit-Graphviz

INTEGRATION WITH INTEGRATED DEVELOPMENT ENVIRONMENTS

32 PROJECT JIGSAW – INTEGRATION WITH TOOLS

NetBeans Support

Intellij IDEA Support Eclipse Support

NETBEANS SUPPORT

33 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Support for JDK 9 starting from NetBeans 9

1) Build with Ant from: https://github.com/apache/incubator-netbeans

NetBeans 9 not yet officialy released (as of 26.09.2017)

JDK 8 is mandatory for building NetBeans 9; cannot use JDK 9 or JDK 7 or older

Two options:

2) Download the latest Development build from: https://builds.apache.org/job/incubator-netbeans-linux/

NetBeans 9 runs on top of JDK 8 as well as JDK 9

NETBEANS SUPPORT

34

One NetBeans project now supports multiple Jigsaw modules Support for Maven projects

New Project Type => Java Modular Project

https://cwiki.apache.org/confluence/display/NETBEANS/NetBeans+9.0+-+New+and+Noteworthy

Set netbeans_jdkhome in netbeans.conf to point

to JDK 9 installation

NETBEANS SUPPORT

35 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Support for adding module-info (New =>Other => Java => Java Module Info) => supports code completion

https://cwiki.apache.org/confluence/display/NETBEANS/NetBeans+9.0+-+New+and+Noteworthy

NETBEANS SUPPORT

36 PROJECT JIGSAW – INTEGRATION WITH TOOLS

https://cwiki.apache.org/confluence/display/NETBEANS/NetBeans+9.0+-+New+and+Noteworthy

Support for module path Edit – Compile – Debug cycle supported

NETBEANS SUPPORT

37 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Go to Tools => Java Platforms and verify that it is running on JDK 9

Project property can be set to JDK 9 Source/binary format for files can be set to JDK 9

NETBEANS SUPPORT

38 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Module Dependency Graph using the Graph View

http://wiki.netbeans.org/JDK9Support

NETBEANS SUPPORT

39 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Support for packaging project files into a custom run-time using Jlink

https://cwiki.apache.org/confluence/display/NETBEANS/NetBeans+9.0+-+New+and+Noteworthy

NETBEANS SUPPORT

40

JShell integration

https://cwiki.apache.org/confluence/display/NETBEANS/NetBeans+9.0+-+New+and+Noteworthy

ECLIPSE SUPPORT

41 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Eclipse Oxygen with Java 9 support Oxygen.1 => 27.09.2017 Oxygen.2 => 20.12.2017 Oxygen.3 => 21.03.2018

https://wiki.eclipse.org/Photon/Simultaneous_Release_Plan#Schedule

For Java 9 support, you can also update other Eclipse IDE to Eclipse 4.7. More info => https://marketplace.eclipse.org/content/java-9-support-beta-oxygen

ECLISE SUPPORT

42 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Add JRE and JDK 9 as installed JRE Support for JavaSE-9 execution environment Module compilation IDE can be launched with JDK 8 or JDK 9 Support for module path + class path

INTELLIJ IDEA SUPPORT

43 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Support for Jigsaw modules starting from version 2017.1

Code completion in the module-info Each Jigsaw module has to correspond to an Intellij IDEA module

Enhancements in versions 2017.2 and 2017.3

For a module, “Mark directory as => Sources root”

INTELLIJ IDEA SUPPORT

44 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Supports module path, class path, module path + class path

INTELLIJ IDEA SUPPORT

45 PROJECT JIGSAW – INTEGRATION WITH TOOLS

INTELLIJ IDEA SUPPORT

46 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Intellij idea support

47 PROJECT JIGSAW – INTEGRATION WITH TOOLS

INTELLIJ IDEA SUPPORT

48 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Package not exported => “Package not found”

No readability defined in module-info

INTELLIJ IDEA SUPPORT

49

Recognizes when a platform module is not required

Can suggest to add missing requires clauses in module-info

INTELLIJ IDEA SUPPORT

50

Code completion for exporting packages

Code completion in module-info

INTELLIJ IDEA SUPPORT

51 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Both Intellij IDEA module dependencies as well as Jigsaw module dependencies have to be declared

module com.javaone.application { requires com.javaone.service;}

INTELLIJ IDEA SUPPORT

52 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Dependency Diagram for Java 9

INTELLIJ IDEA SUPPORT

53 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Opens clause in open module not allowed

Duplicate clauses in module-info detected

https://blog.jetbrains.com/idea/2017/07/support-for-java-9-in-intellij-idea-2017-2/

INTELLIJ IDEA SUPPORT

54 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Find usages

https://blog.jetbrains.com/idea/2017/07/support-for-java-9-in-intellij-idea-2017-2/

INTELLIJ IDEA SUPPORT

55 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Inspection

Possibility to highlight the automatic modules, etc.

INTELLIJ IDEA SUPPORT

56 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Support for Maven projects

Automatically runs with the module path instead of class path Quick fixes for adding items in the module-info.java file

JDK 9 READY STATUS (AS OF 24.09.17)

57 PROJECT JIGSAW – INTEGRATION WITH TOOLS

23%

30%

47%

JDK 9 Ready Status for 98 third-party libraries

JDK 9 Ready librariesJDK 9 Ready soon librariesJDK 9 libraries not ready

https://wiki.openjdk.java.net/display/quality/Quality+Outreach

JDK 9 READY LIBRARIES (AS OF 24.09.17)

58 PROJECT JIGSAW – INTEGRATION WITH TOOLS

https://wiki.openjdk.java.net/display/quality/Quality+Outreach

Library Name JDK 9 Ready

JDK 9 Ready starting from Version

Apache Derby Yes 10.13.1.1Apache Log4j Yes 2.9.0Apache Lucene / Solr Yes 7.0 (for both Lucene and Solr)Apache Maven Yes 3.0Apache PDFBox Yes 2.0.8Apache POI Yes 3.17bt YesCruiseControl YesGraphHopper Yes

JDK 9 READY LIBRARIES (AS OF 24.09.17)

59 PROJECT JIGSAW – INTEGRATION WITH TOOLS

https://wiki.openjdk.java.net/display/quality/Quality+Outreach

Library Name JDK 9 ReadyHeapStats YesHibernate YesJackson YesJaCoCo YesJITWatch YesJOSM YesJunit 5 YesLWJGL YesRapidoid Yes

JDK 9 READY LIBRARIES (AS OF 24.09.17)

60 PROJECT JIGSAW – INTEGRATION WITH TOOLS

https://wiki.openjdk.java.net/display/quality/Quality+Outreach

Library Name JDK 9 ReadyRedHat Wildfly YesRxJava YesSpotbugs YesWoodstox Yes

JDK 9 READY SOON LIBRARIES (AS OF 24.09.17)

61 PROJECT JIGSAW – INTEGRATION WITH TOOLS

https://wiki.openjdk.java.net/display/quality/Quality+Outreach

Library Name

Library Name

Library Name

Library Name

Library Name

Apache JMeter DataCleaner Golo JLine Roaring

Apache MetaModel

Drools Groovy Jboss-Forge Spring Framework

Apache Tomcat EasyMock Hazelcast Kotlin ZXing

Apache Tika Eclipse Jetty HSQLDB Objenesis

Byteman Ehcache JavaEWAH OptaPlanner

Classworlds ElasticSearch JBoss Tools oVirt engine

STATUS MODULARIZATION THIRD-PARTY LIBRARIES

62 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Modular-ized 2%

Not Modu-larized98%

Status modularization - 58 libraries

Modularized Not Modularized

MODULARIZED THIRD-PARTY LIBRARIES

63 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Library Name Modularized (as of 23.09.2017)

Accumulo NoActiveMQ NoAmbari NoAnt NoAurora NoAvro NoAxis NoCassandra NoCloudStack NoCordova NoCouchDB No

MODULARIZED THIRD-PARTY LIBRARIES

64 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Library Name Modularized (as of 23.09.2017)

EclipseLink NoFalcon NoFlex NoFlume NoGeronimo NoGrails NoGroovy NoGuava NoHadoop NoHbase NoHibernate No

MODULARIZED THIRD-PARTY LIBRARIES

65 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Library Name Modularized (as of 23.09.2017)

Jackrabbit NoJackson NoJDO NoJersey NoJetty NoJoda NoJsoup NoKafka NoKnox NoLog4j NoLombok No

MODULARIZED THIRD-PARTY LIBRARIES

66 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Library Name Modularized (as of 23.09.2017)

Lucene NoMahout NoMaven NoMesos NoMockito NoOozie NoOpenJPA NoPerl NoPig NoPowerMock NoQuarz No

MODULARIZED THIRD-PARTY LIBRARIES

67 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Library Name Modularized (as of 23.09.2017)

SLF4J YesSpark NoSpring NoStruts NoSubversion NoSWT NoTapestry NoTestNG NoTiles NoTomcat NoVaadin No

MODULARIZED THIRD-PARTY LIBRARIES

68 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Library Name Modularized (as of 23.09.2017)

Velocity NoXerces NoZooKeeper No

HOW TO MODULARIZE A LIBRARY

69 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Modularize the codebase by introducing a module-info.java file for each module A module-info.java file can be:

1) Created manually by the developers2) Automatically generated using the JDeps tool with the option --generate-module-info

The most common four issues that can occur during the modularization of a library are:

1) Encapsulated JDK internal APIs2) Not resolved modules

3) Cyclic dependencies4) Split packages

ENCAPSULATED JDK INTERNAL APIS

70 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Most of the internal JDK APIs are inaccessible in Java 9 Trying to access them causes a compilation error

Internal APIs are in the sun.* package, but not onlyThe module jdk.unsupported is still accessible: sun.misc.Unsafe, sun.reflect.Reflection, sun.misc.Signal, sun.reflect.ReflectionFactory, sun.misc.SignalHandler

ENCAPSULATED JDK INTERNAL APIS

71 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Breaking encapsulation of the JDK Internal APIs:

NOT RESOLVED PLATFORM MODULES

72 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Not all the platform modules from the JDK are available at compile-time

All the packages from module java.se.ee are not available at compile-time: java.xml.ws, java.xml.bind, java.corba, java.activation, java.xml.ws.annotations => package not exist error encountered at compile-time

NOT RESOLVED PLATFORM MODULES

73 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Solution: add the module that contains the needed packages in the graph of modules using the --add-modules options

--add-modules java.xml.bind

Use --add-modules both at compile-time and at run-time

CYCLIC DEPENDENCIES

74 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Forbidden at compile-time (between modules) JPMS does not allow cycles in the “requires” clauses JPMS allows cycles in the “reads” relation of run-time modules

module A { requires B;}

module B { requires A;}

CYCLIC DEPENDENCIES

75 PROJECT JIGSAW – INTEGRATION WITH TOOLS

One solution is to merge the JARs into a single module Redesign might be necessary to a higher degree Cycles can be broken by using interfaces

SPLIT PACKAGES

76 PROJECT JIGSAW – INTEGRATION WITH TOOLS

Modules that contain packages having the same name must not interfere with each other

Solutions for JAR files: Create a single JAR file out of the two JAR files Rename one of the package

Solutions for modules: Create a single module out of two or more modules Create a third module Remove the package dependencies

Java 9 Modularity Revealed

Apress, 2017221 pagesISBN: 978 - 1484227121

@alexandrujecan

alexandrujecan

alexandrujecan@gmail.com

alexandrujecan.com

top related