org.qbicc.machine.tool.ToolProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of qbicc-machine-tool-api Show documentation
Show all versions of qbicc-machine-tool-api Show documentation
The API for Qbicc machine tooling support
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 super T> 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 - 2025 Weber Informatics LLC | Privacy Policy