com.danielflower.apprunner.runners.AppRunnerFactoryProvider Maven / Gradle / Ivy
package com.danielflower.apprunner.runners;
import com.danielflower.apprunner.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import static java.util.stream.Collectors.joining;
import static org.apache.commons.io.IOUtils.LINE_SEPARATOR;
public class AppRunnerFactoryProvider {
public static final Logger log = LoggerFactory.getLogger(AppRunnerFactoryProvider.class);
private final List factories;
public AppRunnerFactoryProvider(List factories) {
this.factories = factories;
}
public static AppRunnerFactoryProvider create(Config config) {
List factories = new ArrayList<>();
MavenRunnerFactory.createIfAvailable(config).ifPresent(factories::add);
NodeRunnerFactory.createIfAvailable(config).ifPresent(factories::add);
LeinRunnerFactory.createIfAvailable(config).ifPresent(factories::add);
SbtRunnerFactory.createIfAvailable(config).ifPresent(factories::add);
GoRunnerFactory.createIfAvailable(config).ifPresent((factories::add));
return new AppRunnerFactoryProvider(factories);
}
public AppRunnerFactory runnerFor(String appName, File projectRoot) throws UnsupportedProjectTypeException {
for (AppRunnerFactory factory : factories) {
if (factory.canRun(projectRoot)) {
return factory;
}
}
throw new UnsupportedProjectTypeException("No app runner found for " + appName);
}
public String describeRunners() {
return factories.stream()
.map(AppRunnerFactory::versionInfo)
.collect(joining(LINE_SEPARATOR));
}
public List factories() {
return factories;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy