xmvn/0002-Mimic-maven-javadoc-plugin-for--source-and---release.patch
Marian Koncek 1734725d14 Mimic maven-javadoc-plugin for -source and --release
Add simple implementation of toolchains
2022-09-05 13:57:18 +02:00

175 lines
6.7 KiB
Diff

From c2f74691a71509c3671d3bc612be285a511c53f1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fridrich=20=C5=A0trba?= <fridrich.strba@bluewin.ch>
Date: Wed, 4 May 2022 13:26:00 +0200
Subject: [PATCH 1/2] Mimic maven-javadoc-plugin for -source and --release
Consider the maven.compiler.source and maven.compiler.release
properties. Skip module-info.java if source level is specified
and it is < 9 or if non-modular Java is used
---
.../fedoraproject/xmvn/mojo/JavadocMojo.java | 38 +++++++++++++++++--
1 file changed, 34 insertions(+), 4 deletions(-)
diff --git a/xmvn-mojo/src/main/java/org/fedoraproject/xmvn/mojo/JavadocMojo.java b/xmvn-mojo/src/main/java/org/fedoraproject/xmvn/mojo/JavadocMojo.java
index b2cd41fd..68d097f5 100644
--- a/xmvn-mojo/src/main/java/org/fedoraproject/xmvn/mojo/JavadocMojo.java
+++ b/xmvn-mojo/src/main/java/org/fedoraproject/xmvn/mojo/JavadocMojo.java
@@ -84,9 +84,12 @@
@Parameter( defaultValue = "${project.build.directory}", required = true )
private File buildDirectory;
- @Parameter( property = "source" )
+ @Parameter( property = "source", defaultValue = "${maven.compiler.source}" )
private String source;
+ @Parameter( defaultValue = "${maven.compiler.release}" )
+ private String release;
+
private static String quoted( Object obj )
{
String arg = obj.toString();
@@ -222,8 +225,9 @@ public void execute()
List<Path> reactorClassPath = new ArrayList<>();
List<Path> fullClassPath = new ArrayList<>();
populateClasspath( reactorClassPath, fullClassPath );
+ boolean isModular = !findFiles( reactorClassPath, "module-info\\.class" ).isEmpty();
- if ( findFiles( reactorClassPath, "module-info\\.class" ).isEmpty() )
+ if ( !isModular )
{
opts.add( "-classpath" );
}
@@ -244,15 +248,41 @@ public void execute()
opts.add( quoted( docencoding ) );
opts.add( "-doctitle" );
opts.add( quoted( "Javadoc for package XXX" ) );
- if ( source != null )
+
+ String sourceLevel = null;
+ if ( release != null && isModular )
+ {
+ opts.add( "--release" );
+ opts.add( quoted( release ) );
+ sourceLevel = release;
+
+ }
+ else if ( source != null )
{
opts.add( "-source" );
opts.add( quoted( source ) );
+ sourceLevel = source;
+ }
+
+ boolean skipModuleInfo = !isModular;
+ if ( sourceLevel != null && !skipModuleInfo )
+ {
+ try
+ {
+ float f = Float.parseFloat( sourceLevel );
+ if ( f < 9 )
+ skipModuleInfo = true;
+ }
+ catch ( Exception e )
+ {
+ // pass, we assume that we use modular Java
+ }
}
for ( Path file : sourceFiles )
{
- opts.add( quoted( file ) );
+ if ( !skipModuleInfo || !file.endsWith( "module-info.java" ) )
+ opts.add( quoted( file ) );
}
Files.write( outputDir.resolve( "args" ), opts, StandardOpenOption.CREATE );
From 34ee4dad896f9f82131a090293c3a9ccaa77b729 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fridrich=20=C5=A0trba?= <fridrich.strba@bluewin.ch>
Date: Sun, 8 May 2022 15:19:45 +0200
Subject: [PATCH 2/2] --module-path not allowed with release=8
---
.../fedoraproject/xmvn/mojo/JavadocMojo.java | 49 +++++++++----------
1 file changed, 24 insertions(+), 25 deletions(-)
diff --git a/xmvn-mojo/src/main/java/org/fedoraproject/xmvn/mojo/JavadocMojo.java b/xmvn-mojo/src/main/java/org/fedoraproject/xmvn/mojo/JavadocMojo.java
index 68d097f5..480b0f0a 100644
--- a/xmvn-mojo/src/main/java/org/fedoraproject/xmvn/mojo/JavadocMojo.java
+++ b/xmvn-mojo/src/main/java/org/fedoraproject/xmvn/mojo/JavadocMojo.java
@@ -227,35 +227,12 @@ public void execute()
populateClasspath( reactorClassPath, fullClassPath );
boolean isModular = !findFiles( reactorClassPath, "module-info\\.class" ).isEmpty();
- if ( !isModular )
- {
- opts.add( "-classpath" );
- }
- else
- {
- opts.add( "--module-path" );
- }
- opts.add( quoted( StringUtils.join( fullClassPath.iterator(), ":" ) ) );
- opts.add( "-encoding" );
- opts.add( quoted( encoding ) );
- opts.add( "-sourcepath" );
- opts.add( quoted( StringUtils.join( sourcePaths.iterator(), ":" ) ) );
- opts.add( "-charset" );
- opts.add( quoted( docencoding ) );
- opts.add( "-d" );
- opts.add( quoted( outputDir ) );
- opts.add( "-docencoding" );
- opts.add( quoted( docencoding ) );
- opts.add( "-doctitle" );
- opts.add( quoted( "Javadoc for package XXX" ) );
-
String sourceLevel = null;
- if ( release != null && isModular )
+ if ( release != null )
{
opts.add( "--release" );
opts.add( quoted( release ) );
sourceLevel = release;
-
}
else if ( source != null )
{
@@ -265,7 +242,7 @@ else if ( source != null )
}
boolean skipModuleInfo = !isModular;
- if ( sourceLevel != null && !skipModuleInfo )
+ if ( sourceLevel != null )
{
try
{
@@ -279,6 +256,28 @@ else if ( source != null )
}
}
+ if ( !isModular || skipModuleInfo )
+ {
+ opts.add( "-classpath" );
+ }
+ else
+ {
+ opts.add( "--module-path" );
+ }
+ opts.add( quoted( StringUtils.join( fullClassPath.iterator(), ":" ) ) );
+ opts.add( "-encoding" );
+ opts.add( quoted( encoding ) );
+ opts.add( "-sourcepath" );
+ opts.add( quoted( StringUtils.join( sourcePaths.iterator(), ":" ) ) );
+ opts.add( "-charset" );
+ opts.add( quoted( docencoding ) );
+ opts.add( "-d" );
+ opts.add( quoted( outputDir ) );
+ opts.add( "-docencoding" );
+ opts.add( quoted( docencoding ) );
+ opts.add( "-doctitle" );
+ opts.add( quoted( "Javadoc for package XXX" ) );
+
for ( Path file : sourceFiles )
{
if ( !skipModuleInfo || !file.endsWith( "module-info.java" ) )