All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.thucydides.core.fixtureservices.ClasspathFixtureProviderService Maven / Gradle / Ivy

There is a newer version: 4.2.8
Show newest version
package net.thucydides.core.fixtureservices;

import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;

/**
 * Load any implementations of the FixtureService class declared on the classpath.
 * FixtureService implementations must be declared in a file called net.thucydides.core.fixtureservices.FixtureService
 * in the META-INF/services directory somewhere on the classpath.
 */
public class ClasspathFixtureProviderService implements FixtureProviderService {

    private volatile List fixtureServices;

    @Override
    public List getFixtureServices() {
        List result = fixtureServices;
        if (result == null) {
            synchronized (this) {
                result = fixtureServices;
                if (result == null) {
                    result = new ArrayList<>();

                    ServiceLoader fixtureServiceLoader = ServiceLoader.load(FixtureService.class);

                    for (FixtureService fixtureService : fixtureServiceLoader) {
                        result.add(fixtureService);
                    }
                    fixtureServices = result;
                }
            }
        }
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy