Skip to content

Commit

Permalink
[SUREFIRE-1954] move inner class ProviderList to upper level
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski authored and Tibor17 committed Nov 19, 2021
1 parent 189b0de commit e71fec7
Show file tree
Hide file tree
Showing 12 changed files with 854 additions and 653 deletions.
11 changes: 11 additions & 0 deletions maven-surefire-common/pom.xml
Expand Up @@ -166,6 +166,17 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<executions>
<execution>
<goals>
<goal>generate-metadata</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Large diffs are not rendered by default.

This file was deleted.

@@ -1,4 +1,4 @@
package org.apache.maven.plugin.surefire;
package org.apache.maven.surefire.providerapi;

/*
* Licensed to the Apache Software Foundation (ASF) under one
Expand All @@ -22,7 +22,7 @@
/**
* @author Kristian Rosenvold
*/
interface ConfigurableProviderInfo
public interface ConfigurableProviderInfo
extends ProviderInfo
{
ProviderInfo instantiate( String providerName );
Expand Down
@@ -0,0 +1,104 @@
package org.apache.maven.surefire.providerapi;

/*
* 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 javax.annotation.Nonnull;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.apache.maven.surefire.api.provider.SurefireProvider;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;

import static java.lang.Thread.currentThread;

/**
* @author Kristian Rosenvold
*/
@Component( role = ProviderDetector.class )
public final class ProviderDetector
{
@Requirement
private Logger logger;

@Requirement
private ServiceLoader serviceLoader;

@Nonnull
public List<ProviderInfo> resolve( ConfigurableProviderInfo dynamicProvider, ProviderInfo... wellKnownProviders )
{
List<ProviderInfo> providersToRun = new ArrayList<>();
Set<String> manuallyConfiguredProviders = getManuallyConfiguredProviders();
for ( String name : manuallyConfiguredProviders )
{
ProviderInfo wellKnown = findByName( name, wellKnownProviders );
ProviderInfo providerToAdd = wellKnown != null ? wellKnown : dynamicProvider.instantiate( name );
logger.info( "Using configured provider " + providerToAdd.getProviderName() );
providersToRun.add( providerToAdd );
}
return manuallyConfiguredProviders.isEmpty() ? autoDetectOneWellKnownProvider( wellKnownProviders )
: providersToRun;
}

@Nonnull
private List<ProviderInfo> autoDetectOneWellKnownProvider( ProviderInfo... wellKnownProviders )
{
List<ProviderInfo> providersToRun = new ArrayList<>();
for ( ProviderInfo wellKnownProvider : wellKnownProviders )
{
if ( wellKnownProvider.isApplicable() )
{
logger.info( "Using auto detected provider " + wellKnownProvider.getProviderName() );
providersToRun.add( wellKnownProvider );
return providersToRun;
}
}
return providersToRun;
}

private Set<String> getManuallyConfiguredProviders()
{
try
{
ClassLoader cl = currentThread().getContextClassLoader();
return serviceLoader.lookup( SurefireProvider.class, cl );
}
catch ( IOException e )
{
throw new RuntimeException( e );
}
}

private ProviderInfo findByName( String providerClassName, ProviderInfo... wellKnownProviders )
{
for ( ProviderInfo wellKnownProvider : wellKnownProviders )
{
if ( wellKnownProvider.getProviderName().equals( providerClassName ) )
{
return wellKnownProvider;
}
}
return null;
}
}
@@ -1,4 +1,4 @@
package org.apache.maven.plugin.surefire;
package org.apache.maven.surefire.providerapi;

/*
* Licensed to the Apache Software Foundation (ASF) under one
Expand All @@ -19,12 +19,12 @@
* under the License.
*/

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;

import javax.annotation.Nonnull;
import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;

/**
* @author Kristian Rosenvold
Expand Down
@@ -1,4 +1,4 @@
package org.apache.maven.plugin.surefire;
package org.apache.maven.surefire.providerapi;

/*
* Licensed to the Apache Software Foundation (ASF) under one
Expand All @@ -24,30 +24,30 @@
*
* @see ProviderInfo#getJpmsArguments(ProviderRequirements)
*/
final class ProviderRequirements
public final class ProviderRequirements
{
private final boolean modularPath;
private final boolean mainModuleDescriptor;
private final boolean testModuleDescriptor;

ProviderRequirements( boolean modularPath, boolean mainModuleDescriptor, boolean testModuleDescriptor )
public ProviderRequirements( boolean modularPath, boolean mainModuleDescriptor, boolean testModuleDescriptor )
{
this.modularPath = modularPath;
this.mainModuleDescriptor = mainModuleDescriptor;
this.testModuleDescriptor = testModuleDescriptor;
}

boolean isModularPath()
public boolean isModularPath()
{
return modularPath;
}

boolean hasMainModuleDescriptor()
public boolean hasMainModuleDescriptor()
{
return mainModuleDescriptor;
}

boolean hasTestModuleDescriptor()
public boolean hasTestModuleDescriptor()
{
return testModuleDescriptor;
}
Expand Down
Expand Up @@ -20,6 +20,7 @@
*/

import javax.annotation.Nonnull;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -29,6 +30,8 @@
import java.util.HashSet;
import java.util.Set;

import org.codehaus.plexus.component.annotations.Component;

import static java.lang.Character.isJavaIdentifierPart;
import static java.lang.Character.isJavaIdentifierStart;
import static java.util.Collections.emptySet;
Expand All @@ -42,7 +45,8 @@
*
* @since 2.20
*/
public final class ServiceLoader
@Component( role = ServiceLoader.class )
public class ServiceLoader
{

@Nonnull
Expand All @@ -67,7 +71,7 @@ public <T> Set<T> load( Class<T> clazz, ClassLoader classLoader )

@Nonnull
public Set<String> lookup( Class<?> clazz, ClassLoader classLoader )
throws IOException
throws IOException
{
final String resourceName = "META-INF/services/" + clazz.getName();

Expand All @@ -90,7 +94,7 @@ public Set<String> lookup( Class<?> clazz, ClassLoader classLoader )
@Nonnull
@SuppressWarnings( "checkstyle:innerassignment" )
private static Set<String> lookupSpiImplementations( final Enumeration<URL> urlEnumeration )
throws IOException
throws IOException
{
final Set<String> names = new HashSet<>();
nextUrl:
Expand Down Expand Up @@ -143,7 +147,7 @@ private static Set<String> lookupSpiImplementations( final Enumeration<URL> urlE

@Nonnull
private static BufferedReader getReader( @Nonnull URL url )
throws IOException
throws IOException
{
final InputStream inputStream = url.openStream();
final InputStreamReader inputStreamReader = new InputStreamReader( inputStream );
Expand Down
Expand Up @@ -31,6 +31,8 @@
import org.apache.maven.surefire.extensions.ForkNodeFactory;
import org.apache.maven.surefire.api.suite.RunResult;
import org.apache.maven.surefire.api.util.DefaultScanResult;
import org.apache.maven.surefire.providerapi.ProviderInfo;
import org.apache.maven.surefire.providerapi.ProviderRequirements;
import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor;
import org.codehaus.plexus.languages.java.jpms.LocationManager;
import org.codehaus.plexus.languages.java.jpms.ResolvePathResult;
Expand Down

0 comments on commit e71fec7

Please sign in to comment.