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:14 UTC

[maven-artifact-transfer] branch MSHARED-817 created (now fd29b77)

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a change to branch MSHARED-817
in repository https://gitbox.apache.org/repos/asf/maven-artifact-transfer.git.


      at fd29b77  Compare ClassRealm using its canonical class name.

This branch includes the following new commits:

     new 7f047af  Change eclipse aether dependency scope to provided
     new 4fc6d26  Changed to allow the handle of the aether-util classloading issue inside the library.
     new c6237cd  Removed unnecessary imports.
     new 634c792  Made requested changes:
     new 3ad4fb0  Removed IT with app execution outside of Maven Classworld's context.
     new fd29b77  Compare ClassRealm using its canonical class name.

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-artifact-transfer] 03/06: Removed unnecessary imports.

Posted by rf...@apache.org.
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 c6237cd2a42360161818a6c54cabfbc4537dc891
Author: Gabriel Belingueres <be...@gmail.com>
AuthorDate: Sun May 5 16:33:46 2019 -0300

    Removed unnecessary imports.
---
 .../org/apache/maven/plugin/project/deploy/ProjectDeployerMojo.java   | 4 ----
 .../org/apache/maven/plugin/project/install/ProjectInstallerMojo.java | 2 --
 2 files changed, 6 deletions(-)

diff --git a/src/it/maven-project-deployer-plugin/src/main/java/org/apache/maven/plugin/project/deploy/ProjectDeployerMojo.java b/src/it/maven-project-deployer-plugin/src/main/java/org/apache/maven/plugin/project/deploy/ProjectDeployerMojo.java
index f1c4094..26c794e 100644
--- a/src/it/maven-project-deployer-plugin/src/main/java/org/apache/maven/plugin/project/deploy/ProjectDeployerMojo.java
+++ b/src/it/maven-project-deployer-plugin/src/main/java/org/apache/maven/plugin/project/deploy/ProjectDeployerMojo.java
@@ -32,21 +32,18 @@ import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugin.descriptor.PluginDescriptor;
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProjectHelper;
 import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.shared.transfer.artifact.TransferUtils;
 import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployerException;
 import org.apache.maven.shared.transfer.project.NoFileAssignedException;
 import org.apache.maven.shared.transfer.project.deploy.ProjectDeployer;
 import org.apache.maven.shared.transfer.project.deploy.ProjectDeployerRequest;
 import org.apache.maven.shared.transfer.project.install.ProjectInstaller;
 import org.apache.maven.shared.transfer.repository.RepositoryManager;
-import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
 
 /**
  * This mojo is implemented to test the {@link ProjectInstaller} part of the maven-artifact-transfer shared component.
@@ -115,7 +112,6 @@ public class ProjectDeployerMojo
             pdr.setProject( session.getCurrentProject());
             
             ArtifactRepository repo = session.getCurrentProject().getDistributionManagementArtifactRepository();
-            
             deployer.deploy( session.getProjectBuildingRequest(), pdr, repo );
         }
         catch ( IOException e )
diff --git a/src/it/maven-project-installer-plugin/src/main/java/org/apache/maven/plugin/project/install/ProjectInstallerMojo.java b/src/it/maven-project-installer-plugin/src/main/java/org/apache/maven/plugin/project/install/ProjectInstallerMojo.java
index 0daa934..2e6a878 100644
--- a/src/it/maven-project-installer-plugin/src/main/java/org/apache/maven/plugin/project/install/ProjectInstallerMojo.java
+++ b/src/it/maven-project-installer-plugin/src/main/java/org/apache/maven/plugin/project/install/ProjectInstallerMojo.java
@@ -31,14 +31,12 @@ import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugin.descriptor.PluginDescriptor;
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProjectHelper;
 import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.shared.transfer.artifact.TransferUtils;
 import org.apache.maven.shared.transfer.artifact.install.ArtifactInstallerException;
 import org.apache.maven.shared.transfer.project.NoFileAssignedException;
 import org.apache.maven.shared.transfer.project.install.ProjectInstaller;


[maven-artifact-transfer] 06/06: Compare ClassRealm using its canonical class name.

Posted by rf...@apache.org.
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 fd29b774a1d29bde1e34cdf4f6174b1f15a9a3e1
Author: Gabriel Belingueres <be...@gmail.com>
AuthorDate: Wed Sep 4 20:23:22 2019 -0300

    Compare ClassRealm using its canonical class name.
---
 .../java/org/apache/maven/shared/transfer/project/MavenAetherUtils.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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 4ea5d1f..610b314 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
@@ -94,7 +94,7 @@ public class MavenAetherUtils
     {
         for ( Class<?> clazz = classLoader.getClass(); clazz != null; clazz = clazz.getSuperclass() )
         {
-            if ( "ClassRealm".equals( clazz.getSimpleName() ) )
+            if ( "org.codehaus.plexus.classworlds.realm.ClassRealm".equals( clazz.getCanonicalName() ) )
             {
                 return true;
             }


[maven-artifact-transfer] 04/06: Made requested changes:

Posted by rf...@apache.org.
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 );
-        }
     }
 
     /**


[maven-artifact-transfer] 01/06: Change eclipse aether dependency scope to provided

Posted by rf...@apache.org.
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 7f047af3a41594cd759ba5776bcff6aa28b346ba
Author: Gabriel Belingueres <be...@gmail.com>
AuthorDate: Wed May 1 00:57:22 2019 -0300

    Change eclipse aether dependency scope to provided
    
    - Changed eclipse aether dependency to provided scope.
    - Removed shading of aether classes.
    - Added method to import aether library inside TransferUtils to use from
    a plugin.
    - Modified ProjectDeployerMojo and ProjectInstallerMojo plugins used for
    ITs.
---
 pom.xml                                            | 38 ++--------------------
 .../plugin/project/deploy/ProjectDeployerMojo.java |  8 +++++
 .../project/install/ProjectInstallerMojo.java      |  6 ++++
 .../shared/transfer/artifact/TransferUtils.java    | 23 +++++++++++++
 4 files changed, 39 insertions(+), 36 deletions(-)

diff --git a/pom.xml b/pom.xml
index a87744a..9c8f757 100644
--- a/pom.xml
+++ b/pom.xml
@@ -68,40 +68,6 @@
         </executions>
       </plugin>
       <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-shade-plugin</artifactId>
-        <!--
-         ! explicit overwrite cause otherwise we get an 2.4.3...instead. 
-         -->
-        <version>3.1.0</version>
-        <executions>
-          <execution>
-            <phase>package</phase>
-            <goals>
-              <goal>shade</goal>
-            </goals>
-            <configuration>
-              <artifactSet>
-                <includes>
-                  <include>org.eclipse.aether:aether-util</include>
-                </includes>
-              </artifactSet>
-              <filters>
-                <filter>
-                  <artifact>org.eclipse.aether:aether-util</artifact>
-                  <includes>
-                    <!-- to prevent java.lang.ClassNotFoundException: org.eclipse.aether.util.artifact.SubArtifact (M3.1.1 - M3.3.3) -->
-                    <include>org/eclipse/aether/util/artifact/SubArtifact.class</include>
-                    <!-- to prevent java.lang.ClassNotFoundException: org.eclipse.aether.util.filter.* (M3.1.1+ ) -->
-                    <include>org/eclipse/aether/util/filter/*</include>
-                  </includes>
-                </filter>
-              </filters>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-      <plugin>
         <groupId>org.apache.rat</groupId>
         <artifactId>apache-rat-plugin</artifactId>
         <configuration>
@@ -206,7 +172,7 @@
       <groupId>org.sonatype.aether</groupId>
       <artifactId>aether-impl</artifactId>
       <version>1.7</version>
-      <scope>test</scope>
+      <scope>provided</scope>
     </dependency>
 
     <!-- Maven 3.1.x and above -->
@@ -220,7 +186,7 @@
       <groupId>org.eclipse.aether</groupId>
       <artifactId>aether-util</artifactId>
       <version>0.9.0.M2</version>
-      <!-- provided scoped dependencies aren't shaded -->
+      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.eclipse.aether</groupId>
diff --git a/src/it/maven-project-deployer-plugin/src/main/java/org/apache/maven/plugin/project/deploy/ProjectDeployerMojo.java b/src/it/maven-project-deployer-plugin/src/main/java/org/apache/maven/plugin/project/deploy/ProjectDeployerMojo.java
index 26c794e..13967bf 100644
--- a/src/it/maven-project-deployer-plugin/src/main/java/org/apache/maven/plugin/project/deploy/ProjectDeployerMojo.java
+++ b/src/it/maven-project-deployer-plugin/src/main/java/org/apache/maven/plugin/project/deploy/ProjectDeployerMojo.java
@@ -32,18 +32,21 @@ import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProjectHelper;
 import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.shared.transfer.artifact.TransferUtils;
 import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployerException;
 import org.apache.maven.shared.transfer.project.NoFileAssignedException;
 import org.apache.maven.shared.transfer.project.deploy.ProjectDeployer;
 import org.apache.maven.shared.transfer.project.deploy.ProjectDeployerRequest;
 import org.apache.maven.shared.transfer.project.install.ProjectInstaller;
 import org.apache.maven.shared.transfer.repository.RepositoryManager;
+import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
 
 /**
  * This mojo is implemented to test the {@link ProjectInstaller} part of the maven-artifact-transfer shared component.
@@ -65,6 +68,9 @@ public class ProjectDeployerMojo
     @Parameter( defaultValue = "${session}", required = true, readonly = true )
     protected MavenSession session;
 
+    @Parameter( defaultValue = "${plugin}", required = true, readonly = true )
+    protected PluginDescriptor pluginDescriptor;
+
     @Component
     private ProjectDeployer deployer;
 
@@ -112,6 +118,8 @@ public class ProjectDeployerMojo
             pdr.setProject( session.getCurrentProject());
             
             ArtifactRepository repo = session.getCurrentProject().getDistributionManagementArtifactRepository();
+            
+            TransferUtils.importAetherLibrary( pluginDescriptor );
             deployer.deploy( session.getProjectBuildingRequest(), pdr, repo );
         }
         catch ( IOException e )
diff --git a/src/it/maven-project-installer-plugin/src/main/java/org/apache/maven/plugin/project/install/ProjectInstallerMojo.java b/src/it/maven-project-installer-plugin/src/main/java/org/apache/maven/plugin/project/install/ProjectInstallerMojo.java
index 2e6a878..ab910e4 100644
--- a/src/it/maven-project-installer-plugin/src/main/java/org/apache/maven/plugin/project/install/ProjectInstallerMojo.java
+++ b/src/it/maven-project-installer-plugin/src/main/java/org/apache/maven/plugin/project/install/ProjectInstallerMojo.java
@@ -31,12 +31,14 @@ import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProjectHelper;
 import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.shared.transfer.artifact.TransferUtils;
 import org.apache.maven.shared.transfer.artifact.install.ArtifactInstallerException;
 import org.apache.maven.shared.transfer.project.NoFileAssignedException;
 import org.apache.maven.shared.transfer.project.install.ProjectInstaller;
@@ -63,6 +65,9 @@ public class ProjectInstallerMojo
     @Parameter( defaultValue = "${session}", required = true, readonly = true )
     protected MavenSession session;
 
+    @Parameter( defaultValue = "${plugin}", required = true, readonly = true )
+    protected PluginDescriptor pluginDescriptor;
+
     @Component
     private ProjectInstaller installer;
 
@@ -108,6 +113,7 @@ public class ProjectInstallerMojo
             
             ProjectInstallerRequest pir = new ProjectInstallerRequest();
             pir.setProject( session.getCurrentProject());
+            TransferUtils.importAetherLibrary( pluginDescriptor );
             installer.install( pbr, pir );
         }
         catch ( ArtifactInstallerException e )
diff --git a/src/main/java/org/apache/maven/shared/transfer/artifact/TransferUtils.java b/src/main/java/org/apache/maven/shared/transfer/artifact/TransferUtils.java
index 83fa7e1..fc07b95 100644
--- a/src/main/java/org/apache/maven/shared/transfer/artifact/TransferUtils.java
+++ b/src/main/java/org/apache/maven/shared/transfer/artifact/TransferUtils.java
@@ -24,6 +24,9 @@ import org.apache.maven.model.Extension;
 import org.apache.maven.model.Parent;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.model.ReportPlugin;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
 
 /**
  * Utility class
@@ -122,4 +125,24 @@ public final class TransferUtils
         return coordinate;
     }
 
+    /**
+     * Import the core Aether library from the maven distribution.
+     * 
+     * @param pluginDescriptor the plugin descriptor where the operation will be executed.
+     * @throws MojoExecutionException if there is an error when importing the library.
+     * @since 0.11.1
+     */
+    public static void importAetherLibrary( PluginDescriptor pluginDescriptor )
+        throws MojoExecutionException
+    {
+        try
+        {
+            pluginDescriptor.getClassRealm().importFrom( "plexus.core", "org.eclipse.aether.util" );
+        }
+        catch ( NoSuchRealmException e )
+        {
+            throw new MojoExecutionException( "NoSuchRealmException", e );
+        }
+    }
+
 }


[maven-artifact-transfer] 02/06: Changed to allow the handle of the aether-util classloading issue inside the library.

Posted by rf...@apache.org.
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 4fc6d26b8696a4c2ebf6d027a219c8fb7f03447d
Author: Gabriel Belingueres <be...@gmail.com>
AuthorDate: Sun May 5 16:19:11 2019 -0300

    Changed to allow the handle of the aether-util classloading issue inside the library.
    
    - Moved and renamed class to
    org.apache.maven.shared.transfer.project.MavenAetherUtils.
    - No dependency with org.codehaus.plexus:plexus-classworlds is required.
    - Added an IT.
---
 src/it/artifact-transfer-no-classworlds/pom.xml    |  80 +++++++++++++++
 .../artifact/transfer/noclassworlds/App.java       |  50 ++++++++++
 .../artifact-transfer-no-classworlds/verify.groovy |  27 +++++
 .../plugin/project/deploy/ProjectDeployerMojo.java |   4 -
 .../project/install/ProjectInstallerMojo.java      |   4 -
 .../shared/transfer/artifact/TransferUtils.java    |  23 -----
 .../shared/transfer/project/MavenAetherUtils.java  | 110 +++++++++++++++++++++
 .../deploy/internal/DefaultProjectDeployer.java    |   3 +
 .../install/internal/DefaultProjectInstaller.java  |   4 +
 9 files changed, 274 insertions(+), 31 deletions(-)

diff --git a/src/it/artifact-transfer-no-classworlds/pom.xml b/src/it/artifact-transfer-no-classworlds/pom.xml
new file mode 100644
index 0000000..70cf869
--- /dev/null
+++ b/src/it/artifact-transfer-no-classworlds/pom.xml
@@ -0,0 +1,80 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.shared</groupId>
+  <artifactId>artifact-transfer-no-classworlds</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <name>artifact-transfer-no-classworlds</name>
+  <url>http://maven.apache.org</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-artifact-transfer</artifactId>
+      <version>@project.version@</version>
+    </dependency>
+    <dependency>
+        <groupId>org.slf4j</groupId>
+        <artifactId>slf4j-simple</artifactId>
+        <version>1.7.5</version>
+        <scope>runtime</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-shade-plugin</artifactId>
+        <version>3.2.1</version>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+            <configuration>
+              <artifactSet>
+                <excludes>
+                  <exclude>org.codehaus.plexus:plexus-classworlds</exclude>
+                </excludes>
+              </artifactSet>
+              <transformers>
+                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+                  <mainClass>org.apache.maven.shared.artifact.transfer.noclassworlds.App</mainClass>
+                </transformer>
+              </transformers>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/it/artifact-transfer-no-classworlds/src/main/java/org/apache/maven/shared/artifact/transfer/noclassworlds/App.java b/src/it/artifact-transfer-no-classworlds/src/main/java/org/apache/maven/shared/artifact/transfer/noclassworlds/App.java
new file mode 100644
index 0000000..edbd6e3
--- /dev/null
+++ b/src/it/artifact-transfer-no-classworlds/src/main/java/org/apache/maven/shared/artifact/transfer/noclassworlds/App.java
@@ -0,0 +1,50 @@
+package org.apache.maven.shared.artifact.transfer.noclassworlds;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.shared.transfer.project.MavenAetherUtils;
+
+/**
+ * Test that if there is no dependecy with Classworlds artifact, the import of the library will fallback to doing
+ * nothing without runtime errors.
+ *
+ * @since 0.11.1
+ */
+public class App
+{
+    private void test()
+    {
+        try
+        {
+            MavenAetherUtils.importAetherLibrary();
+            System.out.println( "OK" );
+        }
+        catch ( Exception e )
+        {
+            System.out.println( "ERROR" );
+        }
+    }
+
+    public static void main( String[] args )
+    {
+        App app = new App();
+        app.test();
+    }
+}
diff --git a/src/it/artifact-transfer-no-classworlds/verify.groovy b/src/it/artifact-transfer-no-classworlds/verify.groovy
new file mode 100644
index 0000000..2797fe0
--- /dev/null
+++ b/src/it/artifact-transfer-no-classworlds/verify.groovy
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+String command = 'java -jar artifact-transfer-no-classworlds-1.0.0-SNAPSHOT.jar';
+File commandDir = new File( basedir, "target" );
+
+def output = command.execute(null, commandDir).text;
+
+assert output.contains( 'OK' );
+
+return true;
\ No newline at end of file
diff --git a/src/it/maven-project-deployer-plugin/src/main/java/org/apache/maven/plugin/project/deploy/ProjectDeployerMojo.java b/src/it/maven-project-deployer-plugin/src/main/java/org/apache/maven/plugin/project/deploy/ProjectDeployerMojo.java
index 13967bf..f1c4094 100644
--- a/src/it/maven-project-deployer-plugin/src/main/java/org/apache/maven/plugin/project/deploy/ProjectDeployerMojo.java
+++ b/src/it/maven-project-deployer-plugin/src/main/java/org/apache/maven/plugin/project/deploy/ProjectDeployerMojo.java
@@ -68,9 +68,6 @@ public class ProjectDeployerMojo
     @Parameter( defaultValue = "${session}", required = true, readonly = true )
     protected MavenSession session;
 
-    @Parameter( defaultValue = "${plugin}", required = true, readonly = true )
-    protected PluginDescriptor pluginDescriptor;
-
     @Component
     private ProjectDeployer deployer;
 
@@ -119,7 +116,6 @@ public class ProjectDeployerMojo
             
             ArtifactRepository repo = session.getCurrentProject().getDistributionManagementArtifactRepository();
             
-            TransferUtils.importAetherLibrary( pluginDescriptor );
             deployer.deploy( session.getProjectBuildingRequest(), pdr, repo );
         }
         catch ( IOException e )
diff --git a/src/it/maven-project-installer-plugin/src/main/java/org/apache/maven/plugin/project/install/ProjectInstallerMojo.java b/src/it/maven-project-installer-plugin/src/main/java/org/apache/maven/plugin/project/install/ProjectInstallerMojo.java
index ab910e4..0daa934 100644
--- a/src/it/maven-project-installer-plugin/src/main/java/org/apache/maven/plugin/project/install/ProjectInstallerMojo.java
+++ b/src/it/maven-project-installer-plugin/src/main/java/org/apache/maven/plugin/project/install/ProjectInstallerMojo.java
@@ -65,9 +65,6 @@ public class ProjectInstallerMojo
     @Parameter( defaultValue = "${session}", required = true, readonly = true )
     protected MavenSession session;
 
-    @Parameter( defaultValue = "${plugin}", required = true, readonly = true )
-    protected PluginDescriptor pluginDescriptor;
-
     @Component
     private ProjectInstaller installer;
 
@@ -113,7 +110,6 @@ public class ProjectInstallerMojo
             
             ProjectInstallerRequest pir = new ProjectInstallerRequest();
             pir.setProject( session.getCurrentProject());
-            TransferUtils.importAetherLibrary( pluginDescriptor );
             installer.install( pbr, pir );
         }
         catch ( ArtifactInstallerException e )
diff --git a/src/main/java/org/apache/maven/shared/transfer/artifact/TransferUtils.java b/src/main/java/org/apache/maven/shared/transfer/artifact/TransferUtils.java
index fc07b95..83fa7e1 100644
--- a/src/main/java/org/apache/maven/shared/transfer/artifact/TransferUtils.java
+++ b/src/main/java/org/apache/maven/shared/transfer/artifact/TransferUtils.java
@@ -24,9 +24,6 @@ import org.apache.maven.model.Extension;
 import org.apache.maven.model.Parent;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.model.ReportPlugin;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.descriptor.PluginDescriptor;
-import org.codehaus.plexus.classworlds.realm.NoSuchRealmException;
 
 /**
  * Utility class
@@ -125,24 +122,4 @@ public final class TransferUtils
         return coordinate;
     }
 
-    /**
-     * Import the core Aether library from the maven distribution.
-     * 
-     * @param pluginDescriptor the plugin descriptor where the operation will be executed.
-     * @throws MojoExecutionException if there is an error when importing the library.
-     * @since 0.11.1
-     */
-    public static void importAetherLibrary( PluginDescriptor pluginDescriptor )
-        throws MojoExecutionException
-    {
-        try
-        {
-            pluginDescriptor.getClassRealm().importFrom( "plexus.core", "org.eclipse.aether.util" );
-        }
-        catch ( NoSuchRealmException e )
-        {
-            throw new MojoExecutionException( "NoSuchRealmException", e );
-        }
-    }
-
 }
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
new file mode 100644
index 0000000..75ed603
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/transfer/project/MavenAetherUtils.java
@@ -0,0 +1,110 @@
+package org.apache.maven.shared.transfer.project;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This util class will import the Aether library available from the installed Maven distribution. It will do nothing if
+ * it is called from outside of a ClassRealm.
+ *
+ * @since 0.11.1
+ * @author Gabriel Belingueres <a href="mailto:belingueres@gmail.com">belingueres@gmail.com</a>
+ */
+public class MavenAetherUtils
+{
+
+    private static final Logger LOGGER = LoggerFactory.getLogger( MavenAetherUtils.class );
+
+    /**
+     * Import the core Aether library from the maven distribution.
+     *
+     * @param pluginDescriptor the plugin descriptor where the operation will be executed.
+     * @throws MojoExecutionException if there is an error when importing the library.
+     */
+    public static void importAetherLibrary()
+    {
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        if ( isClassRealm( classLoader ) )
+        {
+            importAether( classLoader );
+        }
+    }
+
+    /**
+     * Using reflection check if the Classloader is actually a ClassRealm.
+     * <p>
+     * PRECONDITION: the classLoader parameter is an instance of ClassRealm.
+     * </p>
+     *
+     * @param classLoader the Classloader to test.
+     */
+    private static void importAether( ClassLoader classLoader )
+    {
+        try
+        {
+            try
+            {
+                Method importFromMethod = classLoader.getClass().getMethod( "importFrom", String.class, String.class );
+                importFromMethod.invoke( classLoader, "plexus.core", "org.eclipse.aether.util" );
+            }
+            catch ( InvocationTargetException e )
+            {
+                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;
+                }
+            }
+        }
+        catch ( Exception e )
+        {
+            LOGGER.error( "Unexpected exception when importing Aether library to the '{}' ClassRealm", classLoader, e );
+        }
+    }
+
+    /**
+     * Using reflection, check if the Classloader is actually an instance of a ClassRealm.
+     *
+     * @param classLoader the Classloader to test.
+     * @return true if it an instance of ClassRealm; false otherwise.
+     */
+    private static boolean isClassRealm( ClassLoader classLoader )
+    {
+        for ( Class<?> clazz = classLoader.getClass(); clazz != null; clazz = clazz.getSuperclass() )
+        {
+            if ( "ClassRealm".equals( clazz.getSimpleName() ) )
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+}
diff --git a/src/main/java/org/apache/maven/shared/transfer/project/deploy/internal/DefaultProjectDeployer.java b/src/main/java/org/apache/maven/shared/transfer/project/deploy/internal/DefaultProjectDeployer.java
index c46f520..0fae478 100644
--- a/src/main/java/org/apache/maven/shared/transfer/project/deploy/internal/DefaultProjectDeployer.java
+++ b/src/main/java/org/apache/maven/shared/transfer/project/deploy/internal/DefaultProjectDeployer.java
@@ -32,6 +32,7 @@ import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.project.artifact.ProjectArtifactMetadata;
 import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployer;
 import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployerException;
+import org.apache.maven.shared.transfer.project.MavenAetherUtils;
 import org.apache.maven.shared.transfer.project.NoFileAssignedException;
 import org.apache.maven.shared.transfer.project.deploy.ProjectDeployer;
 import org.apache.maven.shared.transfer.project.deploy.ProjectDeployerRequest;
@@ -71,6 +72,8 @@ class DefaultProjectDeployer
     {
         validateParameters( buildingRequest, projectDeployerRequest, artifactRepository );
 
+        MavenAetherUtils.importAetherLibrary();
+
         Artifact artifact = projectDeployerRequest.getProject().getArtifact();
         String packaging = projectDeployerRequest.getProject().getPackaging();
         File pomFile = projectDeployerRequest.getProject().getFile();
diff --git a/src/main/java/org/apache/maven/shared/transfer/project/install/internal/DefaultProjectInstaller.java b/src/main/java/org/apache/maven/shared/transfer/project/install/internal/DefaultProjectInstaller.java
index 8804ee3..dd6de0d 100644
--- a/src/main/java/org/apache/maven/shared/transfer/project/install/internal/DefaultProjectInstaller.java
+++ b/src/main/java/org/apache/maven/shared/transfer/project/install/internal/DefaultProjectInstaller.java
@@ -34,6 +34,7 @@ import org.apache.maven.project.artifact.ProjectArtifact;
 import org.apache.maven.project.artifact.ProjectArtifactMetadata;
 import org.apache.maven.shared.transfer.artifact.install.ArtifactInstaller;
 import org.apache.maven.shared.transfer.artifact.install.ArtifactInstallerException;
+import org.apache.maven.shared.transfer.project.MavenAetherUtils;
 import org.apache.maven.shared.transfer.project.NoFileAssignedException;
 import org.apache.maven.shared.transfer.project.install.ProjectInstaller;
 import org.apache.maven.shared.transfer.project.install.ProjectInstallerRequest;
@@ -70,6 +71,9 @@ class DefaultProjectInstaller
     {
 
         validateParameters( buildingRequest, installerRequest );
+
+        MavenAetherUtils.importAetherLibrary();
+
         MavenProject project = installerRequest.getProject();
 
         Artifact artifact = project.getArtifact();


[maven-artifact-transfer] 05/06: Removed IT with app execution outside of Maven Classworld's context.

Posted by rf...@apache.org.
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 3ad4fb0747f50f7d0321cc664e16305cb4a14a76
Author: Gabriel Belingueres <be...@gmail.com>
AuthorDate: Sat Aug 17 20:21:44 2019 -0300

    Removed IT with app execution outside of Maven Classworld's context.
---
 src/it/artifact-transfer-no-classworlds/pom.xml    | 80 ----------------------
 .../artifact/transfer/noclassworlds/App.java       | 50 --------------
 .../artifact-transfer-no-classworlds/verify.groovy | 27 --------
 3 files changed, 157 deletions(-)

diff --git a/src/it/artifact-transfer-no-classworlds/pom.xml b/src/it/artifact-transfer-no-classworlds/pom.xml
deleted file mode 100644
index 70cf869..0000000
--- a/src/it/artifact-transfer-no-classworlds/pom.xml
+++ /dev/null
@@ -1,80 +0,0 @@
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one
-  or more contributor license agreements. See the NOTICE file
-  distributed with this work for additional information
-  regarding copyright ownership. The ASF licenses this file
-  to you 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.
--->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-  <modelVersion>4.0.0</modelVersion>
-
-  <groupId>org.apache.maven.shared</groupId>
-  <artifactId>artifact-transfer-no-classworlds</artifactId>
-  <version>1.0.0-SNAPSHOT</version>
-  <packaging>jar</packaging>
-
-  <name>artifact-transfer-no-classworlds</name>
-  <url>http://maven.apache.org</url>
-
-  <properties>
-    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-  </properties>
-
-  <dependencies>
-    <dependency>
-      <groupId>org.apache.maven.shared</groupId>
-      <artifactId>maven-artifact-transfer</artifactId>
-      <version>@project.version@</version>
-    </dependency>
-    <dependency>
-        <groupId>org.slf4j</groupId>
-        <artifactId>slf4j-simple</artifactId>
-        <version>1.7.5</version>
-        <scope>runtime</scope>
-    </dependency>
-  </dependencies>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-shade-plugin</artifactId>
-        <version>3.2.1</version>
-        <executions>
-          <execution>
-            <phase>package</phase>
-            <goals>
-              <goal>shade</goal>
-            </goals>
-            <configuration>
-              <artifactSet>
-                <excludes>
-                  <exclude>org.codehaus.plexus:plexus-classworlds</exclude>
-                </excludes>
-              </artifactSet>
-              <transformers>
-                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
-                  <mainClass>org.apache.maven.shared.artifact.transfer.noclassworlds.App</mainClass>
-                </transformer>
-              </transformers>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
-</project>
diff --git a/src/it/artifact-transfer-no-classworlds/src/main/java/org/apache/maven/shared/artifact/transfer/noclassworlds/App.java b/src/it/artifact-transfer-no-classworlds/src/main/java/org/apache/maven/shared/artifact/transfer/noclassworlds/App.java
deleted file mode 100644
index edbd6e3..0000000
--- a/src/it/artifact-transfer-no-classworlds/src/main/java/org/apache/maven/shared/artifact/transfer/noclassworlds/App.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.apache.maven.shared.artifact.transfer.noclassworlds;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
- */
-
-import org.apache.maven.shared.transfer.project.MavenAetherUtils;
-
-/**
- * Test that if there is no dependecy with Classworlds artifact, the import of the library will fallback to doing
- * nothing without runtime errors.
- *
- * @since 0.11.1
- */
-public class App
-{
-    private void test()
-    {
-        try
-        {
-            MavenAetherUtils.importAetherLibrary();
-            System.out.println( "OK" );
-        }
-        catch ( Exception e )
-        {
-            System.out.println( "ERROR" );
-        }
-    }
-
-    public static void main( String[] args )
-    {
-        App app = new App();
-        app.test();
-    }
-}
diff --git a/src/it/artifact-transfer-no-classworlds/verify.groovy b/src/it/artifact-transfer-no-classworlds/verify.groovy
deleted file mode 100644
index 2797fe0..0000000
--- a/src/it/artifact-transfer-no-classworlds/verify.groovy
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
- */
-
-String command = 'java -jar artifact-transfer-no-classworlds-1.0.0-SNAPSHOT.jar';
-File commandDir = new File( basedir, "target" );
-
-def output = command.execute(null, commandDir).text;
-
-assert output.contains( 'OK' );
-
-return true;
\ No newline at end of file