Search in sources :

Example 1 with MultiRootPathTree

use of io.quarkus.paths.MultiRootPathTree in project quarkus by quarkusio.

the class SnapshotTesting method getSnapshotsBaseTree.

public static PathTree getSnapshotsBaseTree() {
    if (snapshotsBaseRoot != null) {
        return snapshotsBaseRoot;
    }
    PathTree srcTree = null;
    if (Files.isDirectory(SNAPSHOTS_DIR)) {
        srcTree = PathTree.ofDirectoryOrArchive(SNAPSHOTS_DIR.getParent());
    } else if (shouldUpdateSnapshot(SNAPSHOTS_DIR_NAME)) {
        try {
            Files.createDirectories(SNAPSHOTS_DIR);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
        srcTree = PathTree.ofDirectoryOrArchive(SNAPSHOTS_DIR.getParent());
    }
    final URL url = Thread.currentThread().getContextClassLoader().getResource(SNAPSHOTS_DIR_NAME);
    if (url == null) {
        if (srcTree == null) {
            Assertions.fail("Failed to locate " + SNAPSHOTS_DIR_NAME + " directory on the classpath and " + SNAPSHOTS_DIR.toAbsolutePath() + " directory does not exist (use -Dsnap to create it automatically)");
        }
        return snapshotsBaseRoot = srcTree;
    } else if ("file".equals(url.getProtocol())) {
        final Path p;
        try {
            p = Path.of(url.toURI());
        } catch (URISyntaxException e) {
            throw new IllegalStateException("Failed to translate " + url + " to path", e);
        }
        return snapshotsBaseRoot = new MultiRootPathTree(PathTree.ofDirectoryOrArchive(p.getParent()), srcTree);
    } else if ("jar".equals(url.getProtocol())) {
        final String jarUrlStr = url.toExternalForm();
        final String fileUrlStr = jarUrlStr.substring("jar:".length(), jarUrlStr.length() - ("!/" + SNAPSHOTS_DIR_NAME).length());
        final Path p = Path.of(URI.create(fileUrlStr));
        return snapshotsBaseRoot = new MultiRootPathTree(PathTree.ofDirectoryOrArchive(p), srcTree);
    } else {
        throw new IllegalStateException("Unexpected URL protocol in " + url);
    }
}
Also used : Path(java.nio.file.Path) MultiRootPathTree(io.quarkus.paths.MultiRootPathTree) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) URISyntaxException(java.net.URISyntaxException) PathTree(io.quarkus.paths.PathTree) OpenPathTree(io.quarkus.paths.OpenPathTree) MultiRootPathTree(io.quarkus.paths.MultiRootPathTree) URL(java.net.URL)

Example 2 with MultiRootPathTree

use of io.quarkus.paths.MultiRootPathTree in project quarkus by quarkusio.

the class ApplicationArchiveBuildStep method build.

@BuildStep
ApplicationArchivesBuildItem build(QuarkusBuildCloseablesBuildItem buildCloseables, ArchiveRootBuildItem root, ApplicationIndexBuildItem appindex, List<AdditionalApplicationArchiveMarkerBuildItem> appMarkers, List<AdditionalApplicationArchiveBuildItem> additionalApplicationArchiveBuildItem, List<IndexDependencyBuildItem> indexDependencyBuildItems, LiveReloadBuildItem liveReloadContext, CurateOutcomeBuildItem curateOutcomeBuildItem, ClassLoadingConfig classLoadingConfig) throws IOException {
    IndexCache indexCache = liveReloadContext.getContextObject(IndexCache.class);
    if (indexCache == null) {
        indexCache = new IndexCache();
        liveReloadContext.setContextObject(IndexCache.class, indexCache);
    }
    Map<ArtifactKey, Set<String>> removedResources = new HashMap<>();
    for (Map.Entry<String, Set<String>> entry : classLoadingConfig.removedResources.entrySet()) {
        removedResources.put(new GACT(entry.getKey().split(":")), entry.getValue());
    }
    List<ApplicationArchive> applicationArchives = scanForOtherIndexes(buildCloseables, appMarkers, root, additionalApplicationArchiveBuildItem, indexDependencyBuildItems, indexCache, curateOutcomeBuildItem, removedResources);
    final OpenPathTree tree;
    if (root.getRootDirectories().size() == 1) {
        tree = new DirectoryPathTree(root.getRootDirectories().iterator().next());
    } else {
        final PathTree[] trees = new PathTree[root.getRootDirectories().size()];
        int i = 0;
        for (Path p : root.getRootDirectories()) {
            trees[i++] = new DirectoryPathTree(p);
        }
        tree = new MultiRootPathTree(trees);
    }
    return new ApplicationArchivesBuildItem(new ApplicationArchiveImpl(appindex.getIndex(), tree, curateOutcomeBuildItem.getApplicationModel().getAppArtifact().getKey()), applicationArchives);
}
Also used : Path(java.nio.file.Path) OpenPathTree(io.quarkus.paths.OpenPathTree) ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) Set(java.util.Set) HashSet(java.util.HashSet) ApplicationArchiveImpl(io.quarkus.deployment.ApplicationArchiveImpl) HashMap(java.util.HashMap) DirectoryPathTree(io.quarkus.paths.DirectoryPathTree) GACT(io.quarkus.maven.dependency.GACT) ApplicationArchivesBuildItem(io.quarkus.deployment.builditem.ApplicationArchivesBuildItem) ApplicationArchive(io.quarkus.deployment.ApplicationArchive) OpenPathTree(io.quarkus.paths.OpenPathTree) MultiRootPathTree(io.quarkus.paths.MultiRootPathTree) PathTree(io.quarkus.paths.PathTree) DirectoryPathTree(io.quarkus.paths.DirectoryPathTree) MultiRootPathTree(io.quarkus.paths.MultiRootPathTree) Map(java.util.Map) HashMap(java.util.HashMap) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 3 with MultiRootPathTree

use of io.quarkus.paths.MultiRootPathTree in project quarkus by quarkusio.

the class ArtifactSources method getOutputTree.

default PathTree getOutputTree() {
    final Collection<SourceDir> sourceDirs = getSourceDirs();
    final Collection<SourceDir> resourceDirs = getResourceDirs();
    final List<PathTree> trees = new ArrayList<>(sourceDirs.size() + resourceDirs.size());
    for (SourceDir src : sourceDirs) {
        final PathTree outputTree = src.getOutputTree();
        if (outputTree != null && !outputTree.isEmpty() && !trees.contains(outputTree)) {
            trees.add(outputTree);
        }
    }
    for (SourceDir src : resourceDirs) {
        final PathTree outputTree = src.getOutputTree();
        if (outputTree != null && !outputTree.isEmpty() && !trees.contains(outputTree)) {
            trees.add(outputTree);
        }
    }
    if (trees.isEmpty()) {
        return EmptyPathTree.getInstance();
    }
    if (trees.size() == 1) {
        return trees.get(0);
    }
    return new MultiRootPathTree(trees.toArray(new PathTree[0]));
}
Also used : MultiRootPathTree(io.quarkus.paths.MultiRootPathTree) ArrayList(java.util.ArrayList) PathTree(io.quarkus.paths.PathTree) MultiRootPathTree(io.quarkus.paths.MultiRootPathTree) EmptyPathTree(io.quarkus.paths.EmptyPathTree)

Example 4 with MultiRootPathTree

use of io.quarkus.paths.MultiRootPathTree in project quarkus by quarkusio.

the class ResolvedDependency method getContentTree.

default PathTree getContentTree() {
    final WorkspaceModule module = getWorkspaceModule();
    final PathTree workspaceTree = module == null ? EmptyPathTree.getInstance() : module.getContentTree(getClassifier());
    if (!workspaceTree.isEmpty()) {
        return workspaceTree;
    }
    final PathCollection paths = getResolvedPaths();
    if (paths == null || paths.isEmpty()) {
        return EmptyPathTree.getInstance();
    }
    if (paths.isSinglePath()) {
        final Path p = paths.getSinglePath();
        return PathTree.ofDirectoryOrArchive(p);
    }
    final PathTree[] trees = new PathTree[paths.size()];
    int i = 0;
    for (Path p : paths) {
        trees[i++] = PathTree.ofDirectoryOrArchive(p);
    }
    return new MultiRootPathTree(trees);
}
Also used : PathCollection(io.quarkus.paths.PathCollection) Path(java.nio.file.Path) MultiRootPathTree(io.quarkus.paths.MultiRootPathTree) WorkspaceModule(io.quarkus.bootstrap.workspace.WorkspaceModule) PathTree(io.quarkus.paths.PathTree) MultiRootPathTree(io.quarkus.paths.MultiRootPathTree) EmptyPathTree(io.quarkus.paths.EmptyPathTree)

Aggregations

MultiRootPathTree (io.quarkus.paths.MultiRootPathTree)4 PathTree (io.quarkus.paths.PathTree)4 Path (java.nio.file.Path)3 EmptyPathTree (io.quarkus.paths.EmptyPathTree)2 OpenPathTree (io.quarkus.paths.OpenPathTree)2 WorkspaceModule (io.quarkus.bootstrap.workspace.WorkspaceModule)1 ApplicationArchive (io.quarkus.deployment.ApplicationArchive)1 ApplicationArchiveImpl (io.quarkus.deployment.ApplicationArchiveImpl)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 ApplicationArchivesBuildItem (io.quarkus.deployment.builditem.ApplicationArchivesBuildItem)1 ArtifactKey (io.quarkus.maven.dependency.ArtifactKey)1 GACT (io.quarkus.maven.dependency.GACT)1 DirectoryPathTree (io.quarkus.paths.DirectoryPathTree)1 PathCollection (io.quarkus.paths.PathCollection)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1