xmvn/0001-Initial-PoC-of-XMvn-toolchain-manager.patch
2020-01-23 13:51:34 +01:00

78 lines
3.0 KiB
Diff

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