You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2019/05/23 16:06:59 UTC

[maven-surefire] 03/03: providers do not need to have 'surefire-common' in classpath

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

tibordigana pushed a commit to branch 1546-1222-v2
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git

commit ad1b306c33dc541f1b63a2ffb8e68712aa31f3e5
Author: tibordigana <ti...@apache.org>
AuthorDate: Thu May 23 18:02:59 2019 +0200

    providers do not need to have 'surefire-common' in classpath
---
 .../plugin/surefire/AbstractSurefireMojo.java      |   2 +-
 .../surefire/SurefireDependencyResolver.java       |   9 +-
 .../surefire/SurefireDependencyResolverTest.java   |   4 +-
 .../surefire/log/api/ConsoleLoggerDecorator.java   | 193 ++++++++++++++++++++-
 4 files changed, 198 insertions(+), 10 deletions(-)

diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
index 856a527..6eeeb5e 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
@@ -3159,7 +3159,7 @@ public abstract class AbstractSurefireMojo
         public Set<Artifact> getProviderClasspath()
         {
             return surefireDependencyResolver.addProviderToClasspath( getPluginArtifactMap(), getMojoArtifact(),
-                    getCommonArtifact(), getApiArtifact(), getLoggerApiArtifact() );
+                    getApiArtifact(), getLoggerApiArtifact() );
         }
     }
 
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireDependencyResolver.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireDependencyResolver.java
index 170107c..16cb6c8 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireDependencyResolver.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireDependencyResolver.java
@@ -205,7 +205,7 @@ final class SurefireDependencyResolver
     }
 
     Set<Artifact> addProviderToClasspath( Map<String, Artifact> pluginArtifactMap, Artifact mojoPluginArtifact,
-                                          Artifact surefireCommon, Artifact surefireApi, Artifact surefireLoggerApi )
+                                          Artifact surefireApi, Artifact surefireLoggerApi )
     {
         Set<Artifact> providerArtifacts = new LinkedHashSet<>();
         ArtifactResolutionResult artifactResolutionResult = resolvePluginArtifact( mojoPluginArtifact );
@@ -218,12 +218,7 @@ final class SurefireDependencyResolver
                 {
                     String groupId = dependency.getGroupId();
                     String artifactId = dependency.getArtifactId();
-                    if ( groupId.equals( surefireCommon.getGroupId() )
-                            && artifactId.equals( surefireCommon.getArtifactId() ) )
-                    {
-                        providerArtifacts.add( surefireCommon );
-                    }
-                    else if ( groupId.equals( surefireApi.getGroupId() )
+                    if ( groupId.equals( surefireApi.getGroupId() )
                             && artifactId.equals( surefireApi.getArtifactId() ) )
                     {
                         providerArtifacts.add( surefireApi );
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefireDependencyResolverTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefireDependencyResolverTest.java
index fdb1bbe..c7e982d 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefireDependencyResolverTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefireDependencyResolverTest.java
@@ -359,7 +359,9 @@ public class SurefireDependencyResolverTest
         pluginArtifactsMapping.put( provider.getGroupId() + ":" + provider.getArtifactId(), provider );
         pluginArtifactsMapping.put( ext.getGroupId() + ":" + ext.getArtifactId(), ext );
 
-        Set<Artifact> cp = surefireDependencyResolver.addProviderToClasspath( pluginArtifactsMapping, plugin, common, api, logger );
+        Set<Artifact> cp =
+                surefireDependencyResolver.addProviderToClasspath( pluginArtifactsMapping, plugin, api, logger );
+
         assertThat( cp )
                 .hasSize( 4 )
                 .containsOnly( provider, api, logger, ext );
diff --git a/surefire-logger-api/src/main/java/org/apache/maven/plugin/surefire/log/api/ConsoleLoggerDecorator.java b/surefire-logger-api/src/main/java/org/apache/maven/plugin/surefire/log/api/ConsoleLoggerDecorator.java
index 02105fa..bff2c63 100644
--- a/surefire-logger-api/src/main/java/org/apache/maven/plugin/surefire/log/api/ConsoleLoggerDecorator.java
+++ b/surefire-logger-api/src/main/java/org/apache/maven/plugin/surefire/log/api/ConsoleLoggerDecorator.java
@@ -1 +1,192 @@
-package org.apache.maven.plugin.surefire.log.api;

/*
 * 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.
 */

/**
 * Decorator around {@link ConsoleLogger}.
 * This class is loaded in the isolated ClassLoader and the child logger in the in-plugi
 n ClassLoader.
 *
 * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
 * @since 2.20
 */
public final class ConsoleLoggerDecorator
        implements ConsoleLogger
{
    private final Object logger;

    public ConsoleLoggerDecorator( Object logger )
    {
        if ( logger == null )
        {
            throw new NullPointerException( "logger argument is null in " + ConsoleLoggerDecorator.class );
        }
        this.logger = logger;
    }

    @Override
    public boolean isDebugEnabled()
    {
        try
        {
            return (Boolean) logger.getClass()
                    .getMethod( "isDebugEnabled" )
                    .invoke( logger );
        }
        catch ( Exception e )
        {
            throw new IllegalStateException( e.getLocalizedMessage(), e );
        }
    }

    @Override
    public void debug( String message )
    {
        try
        {
            logger.getClass()
                    .getMethod( "debug", String.cl
 ass )
                    .invoke( logger, message );
        }
        catch ( Exception e )
        {
            throw new IllegalStateException( e.getLocalizedMessage(), e );
        }
    }

    @Override
    public boolean isInfoEnabled()
    {
        try
        {
            return (Boolean) logger.getClass()
                    .getMethod( "isInfoEnabled" )
                    .invoke( logger );
        }
        catch ( Exception e )
        {
            throw new IllegalStateException( e.getLocalizedMessage(), e );
        }
    }

    @Override
    public void info( String message )
    {
        try
        {
            logger.getClass()
                    .getMethod( "info", String.class )
                    .invoke( logger, message );
        }
        catch ( Exception e )
        {
            throw new IllegalStateException( e.getLocalizedMessage(), e );
        }
    }

    @Override
    public boolean isWarnEnabled()
    {
        try
        {
            r
 eturn (Boolean) logger.getClass()
                    .getMethod( "isWarnEnabled" )
                    .invoke( logger );
        }
        catch ( Exception e )
        {
            throw new IllegalStateException( e.getLocalizedMessage(), e );
        }
    }

    @Override
    public void warning( String message )
    {
        try
        {
            logger.getClass()
                    .getMethod( "warning", String.class )
                    .invoke( logger, message );
        }
        catch ( Exception e )
        {
            throw new IllegalStateException( e.getLocalizedMessage(), e );
        }
    }

    @Override
    public boolean isErrorEnabled()
    {
        try
        {
            return (Boolean) logger.getClass()
                    .getMethod( "isErrorEnabled" )
                    .invoke( logger );
        }
        catch ( Exception e )
        {
            throw new IllegalStateException( e.getLocalizedMessage(), e );
        }
    }

    @Override
 
    public void error( String message )
    {
        try
        {
            logger.getClass()
                    .getMethod( "error", String.class )
                    .invoke( logger, message );
        }
        catch ( Exception e )
        {
            throw new IllegalStateException( e.getLocalizedMessage(), e );
        }
    }

    @Override
    public void error( String message, Throwable t )
    {
        try
        {
            logger.getClass()
                    .getMethod( "error", String.class, Throwable.class )
                    .invoke( logger, message, t );
        }
        catch ( Exception e )
        {
            throw new IllegalStateException( e.getLocalizedMessage(), e );
        }
    }

    @Override
    public void error( Throwable t )
    {
        try
        {
            logger.getClass()
                    .getMethod( "error", Throwable.class )
                    .invoke( logger, t );
        }
        catch ( Exception e )
        {
 
            throw new IllegalStateException( e.getLocalizedMessage(), e );
        }
    }
}
\ No newline at end of file
+package org.apache.maven.plugin.surefire.log.api;
+
+/*
+ * 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.
+ */
+
+/**
+ * Decorator around {@link ConsoleLogger}.
+ * This class is loaded in the isolated ClassLoader and the child logger in the in-plugin ClassLoader.
+ *
+ * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
+ * @since 2.20
+ */
+public final class ConsoleLoggerDecorator
+        implements ConsoleLogger
+{
+    private final Object logger;
+
+    public ConsoleLoggerDecorator( Object logger )
+    {
+        if ( logger == null )
+        {
+            throw new NullPointerException( "logger argument is null in " + ConsoleLoggerDecorator.class );
+        }
+        this.logger = logger;
+    }
+
+    @Override
+    public boolean isDebugEnabled()
+    {
+        try
+        {
+            return (Boolean) logger.getClass()
+                    .getMethod( "isDebugEnabled" )
+                    .invoke( logger );
+        }
+        catch ( Exception e )
+        {
+            throw new IllegalStateException( e.getLocalizedMessage(), e );
+        }
+    }
+
+    @Override
+    public void debug( String message )
+    {
+        try
+        {
+            logger.getClass()
+                    .getMethod( "debug", String.class )
+                    .invoke( logger, message );
+        }
+        catch ( Exception e )
+        {
+            throw new IllegalStateException( e.getLocalizedMessage(), e );
+        }
+    }
+
+    @Override
+    public boolean isInfoEnabled()
+    {
+        try
+        {
+            return (Boolean) logger.getClass()
+                    .getMethod( "isInfoEnabled" )
+                    .invoke( logger );
+        }
+        catch ( Exception e )
+        {
+            throw new IllegalStateException( e.getLocalizedMessage(), e );
+        }
+    }
+
+    @Override
+    public void info( String message )
+    {
+        try
+        {
+            logger.getClass()
+                    .getMethod( "info", String.class )
+                    .invoke( logger, message );
+        }
+        catch ( Exception e )
+        {
+            throw new IllegalStateException( e.getLocalizedMessage(), e );
+        }
+    }
+
+    @Override
+    public boolean isWarnEnabled()
+    {
+        try
+        {
+            return (Boolean) logger.getClass()
+                    .getMethod( "isWarnEnabled" )
+                    .invoke( logger );
+        }
+        catch ( Exception e )
+        {
+            throw new IllegalStateException( e.getLocalizedMessage(), e );
+        }
+    }
+
+    @Override
+    public void warning( String message )
+    {
+        try
+        {
+            logger.getClass()
+                    .getMethod( "warning", String.class )
+                    .invoke( logger, message );
+        }
+        catch ( Exception e )
+        {
+            throw new IllegalStateException( e.getLocalizedMessage(), e );
+        }
+    }
+
+    @Override
+    public boolean isErrorEnabled()
+    {
+        try
+        {
+            return (Boolean) logger.getClass()
+                    .getMethod( "isErrorEnabled" )
+                    .invoke( logger );
+        }
+        catch ( Exception e )
+        {
+            throw new IllegalStateException( e.getLocalizedMessage(), e );
+        }
+    }
+
+    @Override
+    public void error( String message )
+    {
+        try
+        {
+            logger.getClass()
+                    .getMethod( "error", String.class )
+                    .invoke( logger, message );
+        }
+        catch ( Exception e )
+        {
+            throw new IllegalStateException( e.getLocalizedMessage(), e );
+        }
+    }
+
+    @Override
+    public void error( String message, Throwable t )
+    {
+        try
+        {
+            logger.getClass()
+                    .getMethod( "error", String.class, Throwable.class )
+                    .invoke( logger, message, t );
+        }
+        catch ( Exception e )
+        {
+            throw new IllegalStateException( e.getLocalizedMessage(), e );
+        }
+    }
+
+    @Override
+    public void error( Throwable t )
+    {
+        try
+        {
+            logger.getClass()
+                    .getMethod( "error", Throwable.class )
+                    .invoke( logger, t );
+        }
+        catch ( Exception e )
+        {
+            throw new IllegalStateException( e.getLocalizedMessage(), e );
+        }
+    }
+}