You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2013/03/27 08:04:35 UTC

svn commit: r1461429 - in /maven/shared/trunk/maven-reporting-exec: ./ src/main/java/org/apache/maven/reporting/exec/

Author: hboutemy
Date: Wed Mar 27 07:04:35 2013
New Revision: 1461429

URL: http://svn.apache.org/r1461429
Log:
[MSHARED-280] add support for Maven 3.1/Eclipse Aether in addition to Maven 3.0/Sonatype Aether

Added:
    maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenPluginManagerHelper.java   (with props)
    maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/MavenPluginManagerHelper.java   (with props)
Modified:
    maven/shared/trunk/maven-reporting-exec/pom.xml
    maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java

Modified: maven/shared/trunk/maven-reporting-exec/pom.xml
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-exec/pom.xml?rev=1461429&r1=1461428&r2=1461429&view=diff
==============================================================================
--- maven/shared/trunk/maven-reporting-exec/pom.xml (original)
+++ maven/shared/trunk/maven-reporting-exec/pom.xml Wed Mar 27 07:04:35 2013
@@ -29,7 +29,7 @@
 
   <groupId>org.apache.maven.reporting</groupId>
   <artifactId>maven-reporting-exec</artifactId>
-  <version>1.0.3-SNAPSHOT</version>
+  <version>1.1-SNAPSHOT</version>
 
   <name>Maven Reporting Executor</name>
   <description>Classes to manage report plugin executions with Maven 3.</description>
@@ -108,8 +108,20 @@
       <groupId>org.sonatype.aether</groupId>
       <artifactId>aether-util</artifactId>
       <version>1.7</version>
+    </dependency>
+
+    <!-- Eclipse Aether for Maven 3.1.x -->
+    <dependency>
+      <groupId>org.eclipse.aether</groupId>
+      <artifactId>aether-api</artifactId>
+      <version>0.9.0.M2</version>
       <optional>true</optional>
     </dependency>
+    <dependency>
+      <groupId>org.eclipse.aether</groupId>
+      <artifactId>aether-util</artifactId>
+      <version>0.9.0.M2</version>
+    </dependency>
 
     <!-- test -->
     <dependency>

Added: maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenPluginManagerHelper.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenPluginManagerHelper.java?rev=1461429&view=auto
==============================================================================
--- maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenPluginManagerHelper.java (added)
+++ maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenPluginManagerHelper.java Wed Mar 27 07:04:35 2013
@@ -0,0 +1,219 @@
+package org.apache.maven.reporting.exec;
+
+/*
+ * 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 java.util.List;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.plugin.InvalidPluginDescriptorException;
+import org.apache.maven.plugin.MavenPluginManager;
+import org.apache.maven.plugin.PluginContainerException;
+import org.apache.maven.plugin.PluginDescriptorParsingException;
+import org.apache.maven.plugin.PluginResolutionException;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.logging.Logger;
+import org.sonatype.aether.repository.RemoteRepository;
+
+/**
+ * {@link MavenPluginManager} helper to deal with API changes between Maven 3.0.x and 3.1.x, ie switch from Sonatype Aether
+ * (in org.sonatype.aether package) to Eclipse Aether (in org.eclipse.aether package).
+ * 
+ * @author Hervé Boutemy
+ * @since 1.1
+ */
+@Component( role = MavenPluginManagerHelper.class )
+public class DefaultMavenPluginManagerHelper
+    implements MavenPluginManagerHelper
+{
+    @Requirement
+    private Logger logger;
+
+    @Requirement
+    protected MavenPluginManager mavenPluginManager;
+
+    private Boolean isEclipseAether;
+
+    private Method setupPluginRealm;
+
+    private Method getPluginDescriptor;
+
+    private Method getRepositorySession;
+
+    public DefaultMavenPluginManagerHelper()
+    {
+        try
+        {
+            for ( Method m : MavenPluginManager.class.getMethods() )
+            {
+                if ( "setupPluginRealm".equals( m.getName() ) )
+                {
+                    setupPluginRealm = m;
+                }
+                else if ( "getPluginDescriptor".equals( m.getName() ) )
+                {
+                    getPluginDescriptor = m;
+                }
+            }
+        }
+        catch ( SecurityException e )
+        {
+            logger.warn( "unable to find MavenPluginManager.setupPluginRealm() method", e );
+        }
+
+        try
+        {
+            for ( Method m : MavenSession.class.getMethods() )
+            {
+                if ( "getRepositorySession".equals( m.getName() ) )
+                {
+                    getRepositorySession = m;
+                    break;
+                }
+            }
+        }
+        catch ( SecurityException e )
+        {
+            logger.warn( "unable to find MavenSession.getRepositorySession() method", e );
+        }
+    }
+
+    private boolean isEclipseAether()
+    {
+        if ( isEclipseAether == null )
+        {
+            try
+            {
+                Class.forName( "org.sonatype.aether.graph.DependencyFilter" );
+                isEclipseAether = false;
+            }
+            catch ( ClassNotFoundException e )
+            {
+                isEclipseAether = true;
+            }
+        }
+
+        return isEclipseAether.booleanValue();
+    }
+
+    private Object createExclusionsDependencyFilter( List<String> artifactIdsList )
+    {
+        if ( isEclipseAether() )
+        {
+            return new org.eclipse.aether.util.filter.ExclusionsDependencyFilter( artifactIdsList );
+        }
+        else
+        {
+            return new org.sonatype.aether.util.filter.ExclusionsDependencyFilter( artifactIdsList );
+        }
+    }
+
+    public PluginDescriptor getPluginDescriptor( Plugin plugin, List<RemoteRepository> repositories,
+                                                 MavenSession session )
+        throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException
+    {
+        try
+        {
+            Object repositorySession = getRepositorySession.invoke( session );
+
+            return (PluginDescriptor) getPluginDescriptor.invoke( mavenPluginManager, plugin, repositories,
+                                                                  repositorySession );
+        }
+        catch ( IllegalArgumentException e )
+        {
+            logger.warn( "IllegalArgumentException during MavenPluginManager.getPluginDescriptor() call", e );
+        }
+        catch ( IllegalAccessException e )
+        {
+            logger.warn( "IllegalAccessException during MavenPluginManager.getPluginDescriptor() call", e );
+        }
+        catch ( InvocationTargetException e )
+        {
+            Throwable target = e.getTargetException();
+            if ( target instanceof PluginResolutionException )
+            {
+                throw (PluginResolutionException) target;
+            }
+            if ( target instanceof PluginDescriptorParsingException )
+            {
+                throw (PluginDescriptorParsingException) target;
+            }
+            if ( target instanceof InvalidPluginDescriptorException )
+            {
+                throw (InvalidPluginDescriptorException) target;
+            }
+            if ( target instanceof RuntimeException )
+            {
+                throw (RuntimeException) target;
+            }
+            if ( target instanceof Error )
+            {
+                throw (Error) target;
+            }
+            logger.warn( "Exception during MavenPluginManager.getPluginDescriptor() call", e );
+        }
+
+        return null;
+    }
+
+    public void setupPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent,
+                                  List<String> imports, List<String> excludeArtifactIds )
+        throws PluginResolutionException, PluginContainerException
+    {
+        try
+        {
+            setupPluginRealm.invoke( mavenPluginManager, pluginDescriptor, session, parent, imports,
+                                     createExclusionsDependencyFilter( excludeArtifactIds ) );
+        }
+        catch ( IllegalArgumentException e )
+        {
+            logger.warn( "IllegalArgumentException during MavenPluginManager.setupPluginRealm() call", e );
+        }
+        catch ( IllegalAccessException e )
+        {
+            logger.warn( "IllegalAccessException during MavenPluginManager.setupPluginRealm() call", e );
+        }
+        catch ( InvocationTargetException e )
+        {
+            Throwable target = e.getTargetException();
+            if ( target instanceof PluginResolutionException )
+            {
+                throw (PluginResolutionException) target;
+            }
+            if ( target instanceof PluginContainerException )
+            {
+                throw (PluginContainerException) target;
+            }
+            if ( target instanceof RuntimeException )
+            {
+                throw (RuntimeException) target;
+            }
+            if ( target instanceof Error )
+            {
+                throw (Error) target;
+            }
+            logger.warn( "Exception during MavenPluginManager.setupPluginRealm() call", e );
+        }
+    }
+}

Propchange: maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenPluginManagerHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenPluginManagerHelper.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenPluginManagerHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java?rev=1461429&r1=1461428&r2=1461429&view=diff
==============================================================================
--- maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java (original)
+++ maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java Wed Mar 27 07:04:35 2013
@@ -58,7 +58,6 @@ import org.codehaus.plexus.util.xml.Xpp3
 import org.sonatype.aether.RepositorySystemSession;
 import org.sonatype.aether.graph.DependencyFilter;
 import org.sonatype.aether.repository.RemoteRepository;
-import org.sonatype.aether.util.filter.ExclusionsDependencyFilter;
 
 /**
  * <p>
@@ -109,6 +108,9 @@ public class DefaultMavenReportExecutor
     protected MavenPluginManager mavenPluginManager;
 
     @Requirement
+    protected MavenPluginManagerHelper mavenPluginManagerHelper;
+
+    @Requirement
     protected LifecycleExecutor lifecycleExecutor;
 
     @Requirement
@@ -124,8 +126,8 @@ public class DefaultMavenReportExecutor
                                                                "org.apache.maven.doxia.logging.LogEnabled",
                                                                "org.apache.maven.doxia.logging.Log" );
 
-    private static final DependencyFilter EXCLUDES =
-        new ExclusionsDependencyFilter( Arrays.asList( "doxia-site-renderer", "doxia-sink-api", "maven-reporting-api" ) );
+    private static final List<String> EXCLUDES = Arrays.asList( "doxia-site-renderer", "doxia-sink-api",
+                                                                "maven-reporting-api" );
 
     public List<MavenReportExecution> buildMavenReports( MavenReportExecutorRequest mavenReportExecutorRequest )
         throws MojoExecutionException
@@ -188,7 +190,7 @@ public class DefaultMavenReportExecutor
         List<RemoteRepository> remoteRepositories = session.getCurrentProject().getRemotePluginRepositories();
 
         PluginDescriptor pluginDescriptor =
-            mavenPluginManager.getPluginDescriptor( plugin, remoteRepositories, session.getRepositorySession() );
+            mavenPluginManagerHelper.getPluginDescriptor( plugin, remoteRepositories, session );
 
         Map<String, PlexusConfiguration> goalsWithConfiguration = new LinkedHashMap<String, PlexusConfiguration>();
 
@@ -263,8 +265,9 @@ public class DefaultMavenReportExecutor
 
             mojoExecution.setMojoDescriptor( mojoDescriptor );
 
-            mavenPluginManager.setupPluginRealm( pluginDescriptor, mavenReportExecutorRequest.getMavenSession(),
-                                                 Thread.currentThread().getContextClassLoader(), IMPORTS, EXCLUDES );
+            mavenPluginManagerHelper.setupPluginRealm( pluginDescriptor, mavenReportExecutorRequest.getMavenSession(),
+                                                       Thread.currentThread().getContextClassLoader(), IMPORTS,
+                                                       EXCLUDES );
             MavenReport mavenReport =
                 getConfiguredMavenReport( mojoExecution, pluginDescriptor, mavenReportExecutorRequest );
 

Added: maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/MavenPluginManagerHelper.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/MavenPluginManagerHelper.java?rev=1461429&view=auto
==============================================================================
--- maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/MavenPluginManagerHelper.java (added)
+++ maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/MavenPluginManagerHelper.java Wed Mar 27 07:04:35 2013
@@ -0,0 +1,48 @@
+package org.apache.maven.reporting.exec;
+
+/*
+ * 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.util.List;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.plugin.InvalidPluginDescriptorException;
+import org.apache.maven.plugin.MavenPluginManager;
+import org.apache.maven.plugin.PluginContainerException;
+import org.apache.maven.plugin.PluginDescriptorParsingException;
+import org.apache.maven.plugin.PluginResolutionException;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.sonatype.aether.repository.RemoteRepository;
+
+/**
+ * {@link MavenPluginManager} helper to deal with API changes between Maven 3.0.x and 3.1.x.
+ * 
+ * @author Hervé Boutemy
+ * @since 1.1
+ */
+public interface MavenPluginManagerHelper
+{
+    PluginDescriptor getPluginDescriptor( Plugin plugin, List<RemoteRepository> repositories, MavenSession session )
+        throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException;
+
+    void setupPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent,
+                                  List<String> imports, List<String> excludeArtifactIds )
+        throws PluginResolutionException, PluginContainerException;
+}

Propchange: maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/MavenPluginManagerHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/MavenPluginManagerHelper.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: maven/shared/trunk/maven-reporting-exec/src/main/java/org/apache/maven/reporting/exec/MavenPluginManagerHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain