Mimic maven-javadoc-plugin for -source and --release

Add simple implementation of toolchains
This commit is contained in:
Marian Koncek 2022-09-05 13:48:48 +02:00
parent 1ccdc99bb8
commit 1734725d14
3 changed files with 259 additions and 1 deletions

View File

@ -0,0 +1,174 @@
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" ) )

View File

@ -0,0 +1,76 @@
From acb236f878b020722512b1ce0ba20329500083c2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fridrich=20=C5=A0trba?= <fridrich.strba@bluewin.ch>
Date: Sat, 7 May 2022 18:13:02 +0200
Subject: [PATCH 1/2] Simple implementation of toolchains
https://github.com/fedora-java/xmvn/issues/142
---
.../fedoraproject/xmvn/mojo/JavadocMojo.java | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
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..2b06e702 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
@@ -45,6 +45,8 @@
import org.apache.maven.project.DependencyResolutionResult;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectDependenciesResolver;
+import org.apache.maven.toolchain.Toolchain;
+import org.apache.maven.toolchain.ToolchainManager;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.aether.util.filter.AndDependencyFilter;
@@ -69,6 +71,9 @@
@Component
private Configurator confugurator;
+ @Component
+ private ToolchainManager toolchainManager;
+
@Parameter( defaultValue = "${session}", readonly = true )
private MavenSession session;
@@ -161,8 +166,18 @@ private void populateClasspath( Collection<Path> reactorClassPath, Collection<Pa
public void execute()
throws MojoExecutionException, MojoFailureException
{
+ String javadocTool = null;
+ Toolchain tc = toolchainManager.getToolchainFromBuildContext( "jdk", session );
+ if ( tc != null )
+ {
+ javadocTool = tc.findTool( "javadoc" );
+ }
Path javadocExecutable;
- if ( System.getenv().containsKey( "JAVA_HOME" ) )
+ if ( javadocTool != null && !javadocTool.isEmpty() )
+ {
+ javadocExecutable = Paths.get( javadocTool );
+ }
+ else if ( System.getenv().containsKey( "JAVA_HOME" ) )
{
javadocExecutable = Paths.get( System.getenv( "JAVA_HOME" ) ) //
.resolve( "bin" ) //
From 110da12905adb020630c540e2a8937a71a0b2dc6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fridrich=20=C5=A0trba?= <fridrich.strba@bluewin.ch>
Date: Sat, 7 May 2022 21:29:24 +0200
Subject: [PATCH 2/2] Fix typo
---
.../src/main/java/org/fedoraproject/xmvn/mojo/JavadocMojo.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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 2b06e702..a83e8acf 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
@@ -69,7 +69,7 @@
private ProjectDependenciesResolver resolver;
@Component
- private Configurator confugurator;
+ private Configurator configurator;
@Component
private ToolchainManager toolchainManager;

View File

@ -6,7 +6,7 @@
Name: xmvn
Version: 4.0.0
Release: 10%{?dist}
Release: 11%{?dist}
Summary: Local Extensions for Apache Maven
License: ASL 2.0
URL: https://fedora-java.github.io/xmvn/
@ -16,6 +16,8 @@ ExclusiveArch: %{java_arches} noarch
Source0: https://github.com/fedora-java/xmvn/releases/download/%{version}/xmvn-%{version}.tar.xz
Patch0: 0001-Port-to-Modello-2.0.0.patch
Patch1: 0002-Mimic-maven-javadoc-plugin-for--source-and---release.patch
Patch2: 0003-Simple-implementation-of-toolchains.patch
%if %{with bootstrap}
BuildRequires: javapackages-bootstrap
@ -131,6 +133,8 @@ This package provides %{summary}.
%prep
%setup -q
%patch0 -p1
%patch1 -p1
%patch2 -p1
%mvn_package ::tar.gz: __noinstall
%mvn_package ":{xmvn,xmvn-connector}" xmvn
@ -267,6 +271,10 @@ end
%license LICENSE NOTICE
%changelog
* Mon Sep 05 2022 Marian Koncek <mkoncek@redhat.com> - 4.0.0-11
- Mimic maven-javadoc-plugin for -source and --release
- Add simple implementation of toolchains
* Sat Jul 23 2022 Fedora Release Engineering <releng@fedoraproject.org> - 4.0.0-10
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild