Search in sources :

Example 1 with ThrowingConsumer

use of loghub.Helpers.ThrowingConsumer in project LogHub by fbacchella.

the class Configuration method doClassLoader.

ClassLoader doClassLoader(Object[] pathElements) throws IOException {
    final Collection<URL> urls = new ArrayList<URL>();
    // Needed for all the lambda that throws exception
    ThrowingPredicate<Path> filterReadable = i -> !Files.isHidden(i);
    ThrowingConsumer<Path> toUrl = i -> urls.add(i.toUri().toURL());
    Arrays.stream(pathElements).map(i -> Paths.get(i.toString())).filter(i -> Files.isReadable(i)).filter(filterReadable).filter(i -> (Files.isRegularFile(i) && i.toString().endsWith(".jar")) || Files.isDirectory(i)).forEach(i -> {
        toUrl.accept(i);
        if (Files.isDirectory(i)) {
            try {
                Files.list(i).filter(p -> Files.isRegularFile(p) && p.toString().endsWith(".jar")).forEach(toUrl);
            } catch (Exception e) {
                new RuntimeException(e);
            }
        }
    });
    // Add myself to class loader, so the custom class loader is used in priority
    Path myself = locateResourcefile("loghub");
    if (myself.endsWith("loghub")) {
        myself = myself.getParent();
    }
    urls.add(myself.toUri().toURL());
    return new LogHubClassloader(urls.toArray(new URL[] {}));
}
Also used : Path(java.nio.file.Path) PropertyContext(loghub.RouteParser.PropertyContext) Arrays(java.util.Arrays) ArrayContext(loghub.RouteParser.ArrayContext) Input(loghub.configuration.ConfigListener.Input) URL(java.net.URL) LoggerContext(org.apache.logging.log4j.core.LoggerContext) URISyntaxException(java.net.URISyntaxException) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) URLClassLoader(java.net.URLClassLoader) CharStreams(org.antlr.v4.runtime.CharStreams) Helpers(loghub.Helpers) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) ObjectReference(loghub.configuration.ConfigListener.ObjectReference) Map(java.util.Map) URI(java.net.URI) Path(java.nio.file.Path) DateTimeException(java.time.DateTimeException) Receiver(loghub.Receiver) TimeZone(java.util.TimeZone) Collection(java.util.Collection) LiteralContext(loghub.RouteParser.LiteralContext) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) Reader(java.io.Reader) RouteLexer(loghub.RouteLexer) ZoneId(java.time.ZoneId) RouteParser(loghub.RouteParser) InvocationTargetException(java.lang.reflect.InvocationTargetException) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Processor(loghub.Processor) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Entry(java.util.Map.Entry) Pattern(java.util.regex.Pattern) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) ThrowingFunction(loghub.Helpers.ThrowingFunction) ThrowingConsumer(loghub.Helpers.ThrowingConsumer) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CharStream(org.antlr.v4.runtime.CharStream) Sender(loghub.Sender) ThrowingPredicate(loghub.Helpers.ThrowingPredicate) Output(loghub.configuration.ConfigListener.Output) BeanValueContext(loghub.RouteParser.BeanValueContext) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) Pipeline(loghub.Pipeline) IOException(java.io.IOException) Source(loghub.Source) File(java.io.File) Consumer(java.util.function.Consumer) NamedSubPipeline(loghub.processors.NamedSubPipeline) RecognitionException(org.antlr.v4.runtime.RecognitionException) Paths(java.nio.file.Paths) AnonymousSubPipeline(loghub.processors.AnonymousSubPipeline) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) Event(loghub.Event) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) DateTimeException(java.time.DateTimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 DateTimeException (java.time.DateTimeException)1 ZoneId (java.time.ZoneId)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1