Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SUREFIRE-1954] move inner class ProviderList to upper level #393

Merged
merged 1 commit into from Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
Copy link
Contributor

@Tibor17 Tibor17 Nov 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slawekjaranowski Why the package has changed? There are probably many classes in the new package, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put all classes responsible for providers detecting in one package.

Before we have:
org.apache.maven.plugin.surefire.booterclient.ProviderDetector
which use
org.apache.maven.surefire.providerapi.ServiceLoader
and ProviderDetector was used only by AbstractSurefireMojo so one responsibility was in many package.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I see there are now 5 classes. LGTM


/*
* Licensed to the Apache Software Foundation (ASF) under one
Expand All @@ -22,7 +22,7 @@
/**
* @author Kristian Rosenvold
*/
interface ConfigurableProviderInfo
public interface ConfigurableProviderInfo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slawekjaranowski This interface is only used ASM class or you think that other project which extends the ASM class can instantiate it in the subclass of ASM class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before we have, in package: org.apache.maven.plugin.surefire

  • interface ConfigurableProviderInfo extends ProviderInfo
  • public interface ProviderInfo
    both used in AbstarctSurefireMojo for implementing inner class like xxxProviderInfo

Now are moved to providerapi and both must be public for technical purpose.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely extracted class. I want to ask about the modifiers public. Are they important?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used in ASM from another package ...

{
@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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slawekjaranowski Can this Component be also public final class as the other classes in this package? So that we indicate that the component class cannot be extended by the user in another project.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use mock ServiceLoader of in ProviderDetectorTest but final clases can't be mocked.
I can introduce interfaces for components and mock on interface will be posible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok, so let it be, the tests with mock are more important

{

@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