use of com.disney.groovity.source.HttpGroovitySourceLocator in project groovity by disney.
the class GroovityBuilder method build.
/**
* After setting all initialization parameters, call build(true) to construct, initialize and return the fully started Groovity,
* or build(false) to initialize the Groovity without starting (e.g. to just build jar files without initing and starting classes)
*
* @return an initialized Groovity
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @throws InvocationTargetException
* @throws IOException
* @throws URISyntaxException
*/
public Groovity build(boolean start) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException, URISyntaxException {
CopyOnWriteArrayList<Configurator> configurators = new CopyOnWriteArrayList<Configurator>();
configurators.add(new SystemConfigurator());
if (propsResource != null) {
configurators.add(new PropertiesResourceConfigurator(propsResource));
}
if (propsFile != null) {
configurators.add(new PropertiesFileConfigurator(propsFile));
}
if (propsURL != null) {
configurators.add(new PropertiesURLConfigurator(propsURL));
}
if (configurator != null) {
configurators.add(configurator);
}
Groovity groovity = new Groovity();
groovity.setJarDirectory(jarDirectory);
groovity.setJarPhases(jarPhases);
groovity.setSourcePhases(sourcePhases);
groovity.setCaseSensitive(caseSensitive);
groovity.setArgsLookup(argsLookup);
groovity.setAsyncThreads(asyncThreads);
groovity.setScriptBaseClass(scriptBaseClass);
groovity.setParentLoader(parentClassLoader);
groovity.setConfigurator(new MultiConfigurator(configurators));
final AtomicReference<BindingDecorator> bindingDecoratorRef = new AtomicReference<BindingDecorator>(bindingDecorator);
if (defaultBinding != null) {
bindingDecoratorRef.set(new BindingMapDecorator(new ConcurrentHashMap<String, Object>(defaultBinding), bindingDecoratorRef.get()));
}
ServiceLoader.load(BindingDecorator.class).forEach(decorator -> {
decorator.setChainedDecorator(bindingDecoratorRef.get());
bindingDecoratorRef.set(decorator);
});
groovity.setBindingDecorator(bindingDecoratorRef.get());
if (httpClientBuilder == null) {
httpClientBuilder = HttpClientBuilder.create().useSystemProperties();
}
if (maxHttpConnPerRoute > 0) {
httpClientBuilder.setMaxConnPerRoute(maxHttpConnPerRoute);
}
if (maxHttpConnTotal > 0) {
httpClientBuilder.setMaxConnTotal(maxHttpConnTotal);
}
groovity.setHttpClient(httpClientBuilder.build());
List<GroovitySourceLocator> locators = new ArrayList<GroovitySourceLocator>();
if ((sourceLocations == null || sourceLocations.isEmpty()) && (sourceLocators == null || sourceLocators.isEmpty()) && jarDirectory == null) {
throw new IllegalArgumentException("No groovity source locators or jar directories configured");
}
if (sourceLocators != null) {
for (GroovitySourceLocator locator : sourceLocators) {
locators.add(locator);
}
}
if (sourceLocations != null) {
for (URI location : sourceLocations) {
AbstractGroovitySourceLocator sourceLocator = null;
String scheme = location.getScheme();
if (scheme != null) {
scheme = scheme.toLowerCase();
if (scheme.startsWith("http")) {
sourceLocator = new HttpGroovitySourceLocator(location);
} else if (scheme.equals("classpath")) {
sourceLocator = new ClasspathGroovitySourceLocator(location.getPath());
}
}
if (sourceLocator == null) {
// file locator
if (location.isAbsolute()) {
sourceLocator = new FileGroovitySourceLocator(new File(location));
} else {
sourceLocator = new FileGroovitySourceLocator(new File(location.getPath()));
}
}
sourceLocator.setInterval(sourcePollSeconds);
locators.add(sourceLocator);
}
}
groovity.setSourceLocators(locators.toArray(new GroovitySourceLocator[0]));
if (start) {
groovity.start();
} else {
groovity.init(false);
}
return groovity;
}
Aggregations