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

io.takari.builder.internal.ClasspathMatcher Maven / Gradle / Ivy

package io.takari.builder.internal;

import static io.takari.builder.internal.pathmatcher.PathNormalizer.normalize0;

import java.nio.file.Paths;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import io.takari.builder.internal.pathmatcher.PathMatcher;
import io.takari.builder.internal.pathmatcher.PathMatcher.Builder;
import io.takari.builder.internal.pathmatcher.PathNormalizer;
import io.takari.incrementalbuild.classpath.ClasspathEntriesSupplier;

@Named
@Singleton
public class ClasspathMatcher {

  private final List suppliers;
  private PathMatcher matcher;

  @Inject
  public ClasspathMatcher(List suppliers) {
    this.suppliers = suppliers;
  }

  public synchronized PathMatcher getMatcher() {
    if (matcher == null) {
      matcher = createMatcher();
    }
    return matcher;
  }

  private PathMatcher createMatcher() {
    Builder builder = PathMatcher.builder(new PathNormalizer(Paths.get("/")));

    suppliers.stream().map(s -> s.entries()).flatMap(entries -> entries.stream())
        .forEach(entry -> builder.includePrefix(normalize0(entry)));

    return builder.build();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy