You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2019/10/25 15:43:18 UTC
[maven-artifact-transfer] 04/06: Made requested changes:
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch MSHARED-817
in repository https://gitbox.apache.org/repos/asf/maven-artifact-transfer.git
commit 634c79269c9a7a9dba439084acae9bd786b0e18d
Author: Gabriel Belingueres <be...@gmail.com>
AuthorDate: Sat Aug 17 20:17:02 2019 -0300
Made requested changes:
- added optional classworlds dependency.
- Adapted MavenAetherUtils.importAether() method.
---
pom.xml | 8 +++++
.../shared/transfer/project/MavenAetherUtils.java | 40 +++++++++-------------
2 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/pom.xml b/pom.xml
index 9c8f757..8511433 100644
--- a/pom.xml
+++ b/pom.xml
@@ -195,6 +195,14 @@
<scope>provided</scope>
</dependency>
+ <!-- Allow importing the aether-util library from the user's distribution -->
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-classworlds</artifactId>
+ <version>2.2.3</version>
+ <optional>true</optional>
+ </dependency>
+
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
diff --git a/src/main/java/org/apache/maven/shared/transfer/project/MavenAetherUtils.java b/src/main/java/org/apache/maven/shared/transfer/project/MavenAetherUtils.java
index 75ed603..4ea5d1f 100644
--- a/src/main/java/org/apache/maven/shared/transfer/project/MavenAetherUtils.java
+++ b/src/main/java/org/apache/maven/shared/transfer/project/MavenAetherUtils.java
@@ -19,10 +19,8 @@ package org.apache.maven.shared.transfer.project;
* under the License.
*/
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,6 +36,8 @@ public class MavenAetherUtils
private static final Logger LOGGER = LoggerFactory.getLogger( MavenAetherUtils.class );
+ private static final String NO_SUCH_REALM_EXCEPTION = "org.codehaus.plexus.classworlds.realm.NoSuchRealmException";
+
/**
* Import the core Aether library from the maven distribution.
*
@@ -54,40 +54,34 @@ public class MavenAetherUtils
}
/**
- * Using reflection check if the Classloader is actually a ClassRealm.
+ * Imports aether-util library from the user's Maven distribution.
* <p>
* PRECONDITION: the classLoader parameter is an instance of ClassRealm.
* </p>
*
- * @param classLoader the Classloader to test.
+ * @param classLoader the Classloader which needs to access aether-util.
*/
private static void importAether( ClassLoader classLoader )
{
+ ClassRealm classRealm = (ClassRealm) classLoader;
try
{
- try
+ classRealm.importFrom( "plexus.core", "org.eclipse.aether.util" );
+ }
+ catch ( Exception e )
+ {
+ if ( NO_SUCH_REALM_EXCEPTION.equals( e.getClass().getCanonicalName() ) )
{
- Method importFromMethod = classLoader.getClass().getMethod( "importFrom", String.class, String.class );
- importFromMethod.invoke( classLoader, "plexus.core", "org.eclipse.aether.util" );
+ LOGGER.info( "'plexus.core' ClassRealm could not be found. "
+ + "Ignore this message if you are using the library outside of a Maven execution.", e );
}
- catch ( InvocationTargetException e )
+ else
{
- if ( "NoSuchRealmException".equals( e.getCause().getClass().getSimpleName() ) )
- {
- LOGGER.info( "'plexus.core' ClassRealm could not be found. "
- + "Ignore this message if you are using the library outside of a Maven execution.", e );
- }
- else
- {
- // another exception
- throw e;
- }
+ // another exception
+ LOGGER.error( "Unexpected exception when importing Aether library to the '{}' ClassRealm", classLoader,
+ e );
}
}
- catch ( Exception e )
- {
- LOGGER.error( "Unexpected exception when importing Aether library to the '{}' ClassRealm", classLoader, e );
- }
}
/**