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

org.qbicc.machine.tool.ToolProvider Maven / Gradle / Ivy

There is a newer version: 0.77.0
Show newest version
package org.qbicc.machine.tool;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.function.Predicate;

import org.qbicc.machine.arch.Platform;

/**
 *
 */
public interface ToolProvider {
    /**
     * Try to find a tool provider which responds to the given executable path.
     *
     * @param type the tool class (must not be {@code null})
     * @param platform the platform that the tool must support (must not be {@code null})
     * @param path the path to try (must not be {@code null})
     * @param  the tool type
     * @return a (possibly empty) iterable containing all of the matching candidate tools
     */
     Iterable findTools(Class type, Platform platform, Path path);

    static  Iterable findAllTools(Class type, final Platform platform, Predicate filter, ClassLoader classLoader, List paths) {
        final List list = new ArrayList<>();
        final ServiceLoader loader = ServiceLoader.load(ToolProvider.class, classLoader);
        for (Path path : paths) {
            final Iterator iterator = loader.iterator();
            for (;;) try {
                if (!iterator.hasNext()) {
                    break;
                }
                ToolProvider item = iterator.next();
                for (T t : item.findTools(type, platform, path)) {
                    if (filter.test(t)) {
                        list.add(t);
                    }
                }
            } catch (ServiceConfigurationError ignored) {
            }
        }
        return list;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy