Add bindings for XMvn toolchains and fix empty javadoc

Bootstrap build.

Related: RHEL-70855
Related: RHEL-70860
Related: RHEL-71057
This commit is contained in:
Mikolaj Izdebski 2024-11-22 10:01:38 +01:00
parent b02b8415f0
commit efe77d8fa0
8 changed files with 349 additions and 85 deletions

View File

@ -1,77 +0,0 @@
From c9362d3f23f950bb6987c63c67b06528de3ce100 Mon Sep 17 00:00:00 2001
From: Mikolaj Izdebski <mizdebsk@redhat.com>
Date: Thu, 23 Jan 2020 12:50:42 +0100
Subject: [PATCH] Initial PoC of XMvn toolchain manager
---
.../aether/XMvnMavenLifecycleParticipant.java | 38 +++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/xmvn-connector-aether/src/main/java/org/fedoraproject/xmvn/connector/aether/XMvnMavenLifecycleParticipant.java b/xmvn-connector-aether/src/main/java/org/fedoraproject/xmvn/connector/aether/XMvnMavenLifecycleParticipant.java
index 0e360488..ddd6151b 100644
--- a/xmvn-connector-aether/src/main/java/org/fedoraproject/xmvn/connector/aether/XMvnMavenLifecycleParticipant.java
+++ b/xmvn-connector-aether/src/main/java/org/fedoraproject/xmvn/connector/aether/XMvnMavenLifecycleParticipant.java
@@ -15,10 +15,15 @@
*/
package org.fedoraproject.xmvn.connector.aether;
+import java.util.Collections;
+
import org.apache.maven.AbstractMavenLifecycleParticipant;
import org.apache.maven.MavenExecutionException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.toolchain.MisconfiguredToolchainException;
+import org.apache.maven.toolchain.ToolchainManagerPrivate;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
@@ -42,6 +47,9 @@ public class XMvnMavenLifecycleParticipant
@Requirement( role = XMvnMojoExecutionListener.class )
private XMvnMojoExecutionListener mojoExecutionListener;
+ @Requirement
+ private ToolchainManagerPrivate toolchainManager;
+
@Override
public void afterSessionStart( MavenSession session )
throws MavenExecutionException
@@ -61,4 +69,34 @@ public class XMvnMavenLifecycleParticipant
chainedListener.addExecutionListener( reportGenerator );
request.setExecutionListener( chainedListener );
}
+
+ @Override
+ public void afterProjectsRead( MavenSession session )
+ throws MavenExecutionException
+ {
+ MavenProject currentProject = session.getCurrentProject();
+
+ try
+ {
+ for ( var toolchain : toolchainManager.getToolchainsForType( "jdk", session ) )
+ {
+ if ( toolchain.matchesRequirements( Collections.singletonMap( "xmvn", "xmvn" ) ) )
+ {
+ for ( var project : session.getAllProjects() )
+ {
+ session.setCurrentProject( project );
+ toolchainManager.storeToolchainToBuildContext( toolchain, session );
+ }
+ }
+ }
+ }
+ catch ( MisconfiguredToolchainException e )
+ {
+ throw new MavenExecutionException( "Unable to configure toolchains", e );
+ }
+ finally
+ {
+ session.setCurrentProject( currentProject );
+ }
+ }
}
--
2.21.0

View File

@ -0,0 +1,56 @@
From 1b66b3d5d6cd1e502012e4dbd68f978dacc1312f 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.DependencyResolutionRequest;
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 @@ public class JavadocMojo
@Component
private Configurator confugurator;
+ @Component
+ private ToolchainManager toolchainManager;
+
@Parameter( defaultValue = "${session}", readonly = true )
private MavenSession session;
@@ -161,8 +166,18 @@ public class JavadocMojo
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" ) //
--
2.47.1

View File

@ -0,0 +1,151 @@
From 01e7e776e2af1938f4a1daac08078284913994a1 Mon Sep 17 00:00:00 2001
From: Mikolaj Izdebski <mizdebsk@redhat.com>
Date: Tue, 21 Jun 2022 09:13:51 +0200
Subject: [PATCH 2/2] [it] Add test for javadoc MOJO toolchains
---
.../JavadocToolchainsIntegrationTest.java | 39 +++++++++++++++++++
.../.xmvn/configuration.xml | 7 ++++
.../resources/testJavadocToolchains/pom.xml | 6 +++
.../src/main/java/somepkg/SomeClass.java | 24 ++++++++++++
.../testJavadocToolchains/toolchains.xml | 11 ++++++
.../fedoraproject/xmvn/mojo/JavadocMojo.java | 1 +
6 files changed, 88 insertions(+)
create mode 100644 xmvn-it/src/test/java/org/fedoraproject/xmvn/it/maven/mojo/javadoc/JavadocToolchainsIntegrationTest.java
create mode 100644 xmvn-it/src/test/resources/testJavadocToolchains/.xmvn/configuration.xml
create mode 100644 xmvn-it/src/test/resources/testJavadocToolchains/pom.xml
create mode 100644 xmvn-it/src/test/resources/testJavadocToolchains/src/main/java/somepkg/SomeClass.java
create mode 100644 xmvn-it/src/test/resources/testJavadocToolchains/toolchains.xml
diff --git a/xmvn-it/src/test/java/org/fedoraproject/xmvn/it/maven/mojo/javadoc/JavadocToolchainsIntegrationTest.java b/xmvn-it/src/test/java/org/fedoraproject/xmvn/it/maven/mojo/javadoc/JavadocToolchainsIntegrationTest.java
new file mode 100644
index 00000000..c552652d
--- /dev/null
+++ b/xmvn-it/src/test/java/org/fedoraproject/xmvn/it/maven/mojo/javadoc/JavadocToolchainsIntegrationTest.java
@@ -0,0 +1,39 @@
+/*-
+ * Copyright (c) 2021 Red Hat, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.fedoraproject.xmvn.it.maven.mojo.javadoc;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+
+import org.fedoraproject.xmvn.it.maven.mojo.AbstractMojoIntegrationTest;
+
+/**
+ * Integration tests for javadoc MOJO.
+ *
+ * @author Mikolaj Izdebski
+ */
+public class JavadocToolchainsIntegrationTest
+ extends AbstractMojoIntegrationTest
+{
+ @Test
+ public void testJavadocToolchains()
+ throws Exception
+ {
+ performTest( "org.fedoraproject.xmvn:xmvn-mojo:javadoc" );
+ assertTrue( getStdout().anyMatch( s -> s.equals( "[INFO] Toolchain in xmvn-mojo: JDK[/tmp]" ) ) );
+ }
+}
diff --git a/xmvn-it/src/test/resources/testJavadocToolchains/.xmvn/configuration.xml b/xmvn-it/src/test/resources/testJavadocToolchains/.xmvn/configuration.xml
new file mode 100644
index 00000000..06f5b389
--- /dev/null
+++ b/xmvn-it/src/test/resources/testJavadocToolchains/.xmvn/configuration.xml
@@ -0,0 +1,7 @@
+<configuration>
+ <resolverSettings>
+ <metadataRepositories>
+ <repository>metadata.xml</repository>
+ </metadataRepositories>
+ </resolverSettings>
+</configuration>
diff --git a/xmvn-it/src/test/resources/testJavadocToolchains/pom.xml b/xmvn-it/src/test/resources/testJavadocToolchains/pom.xml
new file mode 100644
index 00000000..5296a0fe
--- /dev/null
+++ b/xmvn-it/src/test/resources/testJavadocToolchains/pom.xml
@@ -0,0 +1,6 @@
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>xmvn.its</groupId>
+ <artifactId>javadoc-toolchains-test</artifactId>
+ <version>0.0.0-SNAPSHOT</version>
+</project>
diff --git a/xmvn-it/src/test/resources/testJavadocToolchains/src/main/java/somepkg/SomeClass.java b/xmvn-it/src/test/resources/testJavadocToolchains/src/main/java/somepkg/SomeClass.java
new file mode 100644
index 00000000..087d2158
--- /dev/null
+++ b/xmvn-it/src/test/resources/testJavadocToolchains/src/main/java/somepkg/SomeClass.java
@@ -0,0 +1,24 @@
+/*-
+ * Copyright (c) 2016-2021 Red Hat, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package somepkg;
+
+/**
+ * @author Mikolaj Izdebski
+ */
+public class SomeClass
+{
+
+}
diff --git a/xmvn-it/src/test/resources/testJavadocToolchains/toolchains.xml b/xmvn-it/src/test/resources/testJavadocToolchains/toolchains.xml
new file mode 100644
index 00000000..9e92c646
--- /dev/null
+++ b/xmvn-it/src/test/resources/testJavadocToolchains/toolchains.xml
@@ -0,0 +1,11 @@
+<toolchains>
+ <toolchain>
+ <type>jdk</type>
+ <provides>
+ <xmvn>xmvn</xmvn>
+ </provides>
+ <configuration>
+ <jdkHome>/tmp</jdkHome>
+ </configuration>
+ </toolchain>
+</toolchains>
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..cf388f5a 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
@@ -170,6 +170,7 @@ public class JavadocMojo
Toolchain tc = toolchainManager.getToolchainFromBuildContext( "jdk", session );
if ( tc != null )
{
+ logger.info( "Toolchain in xmvn-mojo: " + tc );
javadocTool = tc.findTool( "javadoc" );
}
Path javadocExecutable;
--
2.47.1

11
toolchains-openjdk11.xml Normal file
View File

@ -0,0 +1,11 @@
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<xmvn>xmvn</xmvn>
</provides>
<configuration>
<jdkHome>/usr/lib/jvm/java-11-openjdk</jdkHome>
</configuration>
</toolchain>
</toolchains>

11
toolchains-openjdk17.xml Normal file
View File

@ -0,0 +1,11 @@
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<xmvn>xmvn</xmvn>
</provides>
<configuration>
<jdkHome>/usr/lib/jvm/java-17-openjdk</jdkHome>
</configuration>
</toolchain>
</toolchains>

11
toolchains-openjdk21.xml Normal file
View File

@ -0,0 +1,11 @@
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<xmvn>xmvn</xmvn>
</provides>
<configuration>
<jdkHome>/usr/lib/jvm/java-21-openjdk</jdkHome>
</configuration>
</toolchain>
</toolchains>

11
toolchains-openjdk8.xml Normal file
View File

@ -0,0 +1,11 @@
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<xmvn>xmvn</xmvn>
</provides>
<configuration>
<jdkHome>/usr/lib/jvm/java-1.8.0-openjdk</jdkHome>
</configuration>
</toolchain>
</toolchains>

106
xmvn.spec
View File

@ -1,23 +1,33 @@
%bcond_with bootstrap
%bcond_without bootstrap
%global java_arches aarch64 ppc64le s390x x86_64
%if %{with bootstrap}
%global mbi 1
%endif
Name: xmvn
Version: 4.0.0
Release: 2%{?dist}
Release: 3%{?dist}
Summary: Local Extensions for Apache Maven
License: ASL 2.0
URL: https://fedora-java.github.io/xmvn/
BuildArch: noarch
ExclusiveArch: %{java_arches} noarch
Source0: https://github.com/fedora-java/xmvn/releases/download/%{version}/xmvn-%{version}.tar.xz
BuildRequires: maven-local
Patch: 0001-Simple-implementation-of-toolchains-https-github.com.patch
Patch: 0002-it-Add-test-for-javadoc-MOJO-toolchains.patch
Source8: toolchains-openjdk8.xml
Source11: toolchains-openjdk11.xml
Source17: toolchains-openjdk17.xml
Source21: toolchains-openjdk21.xml
%if %{with bootstrap}
BuildRequires: javapackages-bootstrap
%else
BuildRequires: maven-local >= 6.4.0
BuildRequires: mvn(com.beust:jcommander)
BuildRequires: mvn(org.apache.commons:commons-compress)
BuildRequires: mvn(org.apache.maven.plugin-tools:maven-plugin-annotations)
@ -111,6 +121,7 @@ Summary: XMvn tools
# Explicit javapackages-tools requires since scripts use
# /usr/share/java-utils/java-functions
Requires: javapackages-tools
Requires: java-11-openjdk-headless
Obsoletes: xmvn-tools-pom < 4.0.0
Obsoletes: xmvn-bisect < 4.0.0
Obsoletes: xmvn-install < 4.0.0
@ -136,8 +147,68 @@ Summary: API documentation for %{name}
%description javadoc
This package provides %{summary}.
%if !0%{?specpartsdir:1}
%package toolchain-openjdk8
Summary: xmvn-minimal binding for openjdk8
Requires: java-1.8.0-openjdk-devel
Requires: javapackages-tools
Requires(meta): xmvn-minimal
%description toolchain-openjdk8
Configures xmvn-minimal to work with openjdk8.
%files toolchain-openjdk8
%ghost %{_jpbindingdir}/xmvn-toolchains.xml
%dir %{_jpbindingdir}/xmvn-toolchains.xml.d
%{_jpbindingdir}/xmvn-toolchains.xml.d/openjdk8
%package toolchain-openjdk11
Summary: xmvn-minimal binding for openjdk11
Requires: java-11-openjdk-devel
Requires: javapackages-tools
Requires(meta): xmvn-minimal
%description toolchain-openjdk11
Configures xmvn-minimal to work with openjdk11.
%files toolchain-openjdk11
%ghost %{_jpbindingdir}/xmvn-toolchains.xml
%dir %{_jpbindingdir}/xmvn-toolchains.xml.d
%{_jpbindingdir}/xmvn-toolchains.xml.d/openjdk11
%package toolchain-openjdk17
Summary: xmvn-minimal binding for openjdk17
Requires: java-17-openjdk-devel
Requires: javapackages-tools
Requires(meta): xmvn-minimal
%description toolchain-openjdk17
Configures xmvn-minimal to work with openjdk17.
%files toolchain-openjdk17
%ghost %{_jpbindingdir}/xmvn-toolchains.xml
%dir %{_jpbindingdir}/xmvn-toolchains.xml.d
%{_jpbindingdir}/xmvn-toolchains.xml.d/openjdk17
%package toolchain-openjdk21
Summary: xmvn-minimal binding for openjdk21
Requires: java-21-openjdk-devel
Requires: javapackages-tools
Requires(meta): xmvn-minimal
%description toolchain-openjdk21
Configures xmvn-minimal to work with openjdk21.
%files toolchain-openjdk21
%ghost %{_jpbindingdir}/xmvn-toolchains.xml
%dir %{_jpbindingdir}/xmvn-toolchains.xml.d
%{_jpbindingdir}/xmvn-toolchains.xml.d/openjdk21
%endif
%prep
%setup -q
%autosetup -p1
%mvn_package ::tar.gz: __noinstall
%mvn_package ":{xmvn,xmvn-connector}" xmvn
@ -151,14 +222,14 @@ This package provides %{summary}.
# Copy Maven home packaged as RPM instead of unpacking Maven binary
# tarball with maven-dependency-plugin
%pom_remove_plugin :maven-dependency-plugin
maven_home=$(realpath $(dirname $(realpath $(%{?jpb_env} which mvn)))/..)
maven_home=$(realpath $(dirname $(realpath $(%{?jpb_env} type -p mvn)))/..)
mver=$(sed -n '/<mavenVersion>/{s/.*>\(.*\)<.*/\1/;p}' \
xmvn-parent/pom.xml)
mkdir -p target/dependency/
cp -a "${maven_home}" target/dependency/apache-maven-$mver
%build
%mvn_build -j -- -P\\!quality
%mvn_build -- -P\\!quality
version=4.0.0
tar --delay-directory-restore -xvf target/xmvn-*-bin.tar.gz
@ -175,7 +246,7 @@ rm -f %{name}-${version}*/bin/*
%mvn_install
version=4.0.0
maven_home=$(realpath $(dirname $(realpath $(%{?jpb_env} which mvn)))/..)
maven_home=$(realpath $(dirname $(realpath $(%{?jpb_env} type -p mvn)))/..)
install -d -m 755 %{buildroot}%{_datadir}/%{name}
cp -r%{?mbi:L} %{name}-${version}*/* %{buildroot}%{_datadir}/%{name}/
@ -217,6 +288,20 @@ cp -P ${maven_home}/bin/m2.conf %{buildroot}%{_datadir}/%{name}/bin/
# Make sure javapackages config is not bundled
rm -rf %{buildroot}%{_datadir}/%{name}/{configuration.xml,config.d/,conf/toolchains.xml,maven-metadata/}
# Toolchains
%if !0%{?specpartsdir:1}
export RPM_SPECPARTS_DIR=/tmp
%endif
ln -sf %{_jpbindingdir}/xmvn-toolchains.xml %{buildroot}%{_datadir}/%{name}/conf/toolchains.xml
install -p -m 644 %{SOURCE8} %{buildroot}%{_datadir}/%{name}/conf/toolchains-openjdk8.xml
install -p -m 644 %{SOURCE11} %{buildroot}%{_datadir}/%{name}/conf/toolchains-openjdk11.xml
install -p -m 644 %{SOURCE17} %{buildroot}%{_datadir}/%{name}/conf/toolchains-openjdk17.xml
install -p -m 644 %{SOURCE21} %{buildroot}%{_datadir}/%{name}/conf/toolchains-openjdk21.xml
%jp_binding --verbose --base-pkg xmvn-minimal --binding-pkg xmvn-toolchain-openjdk8 --variant openjdk8 --ghost xmvn-toolchains.xml --target %{_datadir}/%{name}/conf/toolchains-openjdk8.xml --requires java-1.8.0-openjdk-devel
%jp_binding --verbose --base-pkg xmvn-minimal --binding-pkg xmvn-toolchain-openjdk11 --variant openjdk11 --ghost xmvn-toolchains.xml --target %{_datadir}/%{name}/conf/toolchains-openjdk11.xml --requires java-11-openjdk-devel
%jp_binding --verbose --base-pkg xmvn-minimal --binding-pkg xmvn-toolchain-openjdk17 --variant openjdk17 --ghost xmvn-toolchains.xml --target %{_datadir}/%{name}/conf/toolchains-openjdk17.xml --requires java-17-openjdk-devel
%jp_binding --verbose --base-pkg xmvn-minimal --binding-pkg xmvn-toolchain-openjdk21 --variant openjdk21 --ghost xmvn-toolchains.xml --target %{_datadir}/%{name}/conf/toolchains-openjdk21.xml --requires java-21-openjdk-devel
# Workaround for rpm bug 447156 - rpm fails to change directory to symlink
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Directory_Replacement/
%pretrans -p <lua> minimal
@ -263,10 +348,15 @@ end
%{_bindir}/%{name}-resolve
%{_bindir}/%{name}-subst
%files javadoc
%files javadoc -f .mfiles-javadoc
%license LICENSE NOTICE
%changelog
* Tue Dec 10 2024 Mikolaj Izdebski <mizdebsk@redhat.com> - 4.0.0-3
- Add bindings for XMvn toolchains
- Resolves: RHEL-70855, RHEL-70860
- Related: RHEL-71057
* Tue Aug 10 2021 Mohan Boddu <mboddu@redhat.com> - 4.0.0-2
- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
Related: rhbz#1991688