bmarwell commented on a change in pull request #36:
URL:
https://github.com/apache/maven-compiler-plugin/pull/36#discussion_r546799029
##########
File path: src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java
##########
@@ -319,7 +352,42 @@ else if ( Double.valueOf( getTarget() ) < Double.valueOf(
MODULE_INFO_TARGET ) )
if ( testModuleDescriptor != null )
{
modulepathElements = testPath;
- classpathElements = Collections.emptyList();
+ classpathElements = null;
+ for ( String path : modulepathElements )
+ {
+ File file = new File( path );
+ if ( file.exists() && ! file.isDirectory() &&
file.getName().endsWith( ".jar" ) )
+ {
+ // check if the jar file contains the module-info.class
+ try
+ {
+ JarFile jarFile = new JarFile( file );
+ if ( jarFile.getJarEntry( "module-info.class" ) ==
null )
+ {
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().debug( "Add non-module jar dependency
" + path
+ + " to class path." );
+ }
+ if ( classpathElements == null )
+ {
+ classpathElements = new ArrayList<String>();
+ }
+ // add the path to the classpathElements list.
+ classpathElements.add( path );
+ }
Review comment:
Yes that is what I had in mind. A small comment why stuff happens there
would be helpful as well. I would start a little above in the "try" statement
with the comment: ` // check if the jar file contains the
module-info.class.`.
I think the whole try statement would make a nice method. A simple comment
why the jars are explicitly added to the classpath would absolutely suffice.
Also:
`new ArrayList<String>();` -- you can just use the diamond operator: `new
ArrayList<>();`. We are on Java 7, not 5. ;-)
Thanks!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]