Search in sources :

Example 1 with PathTree

use of io.quarkus.paths.PathTree 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 PathTree

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

the class QuarkusModelBuilderTest method assertProjectModule.

private void assertProjectModule(WorkspaceModule projectModule, File projectDir, boolean withTests) {
    assertNotNull(projectModule);
    assertEquals(projectDir, projectModule.getModuleDir());
    assertEquals(new File(projectDir, "build"), projectModule.getBuildDir());
    SourceDir src = projectModule.getMainSources().getSourceDirs().iterator().next();
    assertNotNull(src);
    assertThat(src.getOutputDir()).isEqualTo(projectDir.toPath().resolve("build/classes/java/main"));
    PathTree sourceTree = src.getSourceTree();
    assertThat(sourceTree).isNotNull();
    assertThat(sourceTree.getRoots()).hasSize(1);
    assertThat(sourceTree.getRoots().iterator().next()).isEqualTo(projectDir.toPath().resolve("src/main/java"));
    src = projectModule.getMainSources().getResourceDirs().iterator().next();
    assertNotNull(src);
    assertThat(src.getOutputDir()).isEqualTo(projectDir.toPath().resolve("build/resources/main"));
    sourceTree = src.getSourceTree();
    assertThat(sourceTree).isNotNull();
    assertThat(sourceTree.getRoots()).hasSize(1);
    assertThat(sourceTree.getRoots().iterator().next()).isEqualTo(projectDir.toPath().resolve("src/main/resources"));
    if (withTests) {
        src = projectModule.getTestSources().getSourceDirs().iterator().next();
        assertNotNull(src);
        assertThat(src.getOutputDir()).isEqualTo(projectDir.toPath().resolve("build/classes/java/test"));
        sourceTree = src.getSourceTree();
        assertThat(sourceTree).isNotNull();
        assertThat(sourceTree.getRoots()).hasSize(1);
        assertThat(sourceTree.getRoots().iterator().next()).isEqualTo(projectDir.toPath().resolve("src/test/java"));
        src = projectModule.getTestSources().getResourceDirs().iterator().next();
        assertNotNull(src);
        assertThat(src.getOutputDir()).isEqualTo(projectDir.toPath().resolve("build/resources/test"));
        sourceTree = src.getSourceTree();
        assertThat(sourceTree).isNotNull();
        assertThat(sourceTree.getRoots()).hasSize(1);
        assertThat(sourceTree.getRoots().iterator().next()).isEqualTo(projectDir.toPath().resolve("src/test/resources"));
    } else {
        assertThat(projectModule.getTestSources()).isNull();
    }
}
Also used : SourceDir(io.quarkus.bootstrap.workspace.SourceDir) File(java.io.File) PathTree(io.quarkus.paths.PathTree)

Example 3 with PathTree

use of io.quarkus.paths.PathTree 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 4 with PathTree

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

the class CuratedApplication method processCpElement.

private synchronized void processCpElement(ResolvedDependency artifact, Consumer<ClassPathElement> consumer) {
    if (!artifact.isJar()) {
        // avoid the need for this sort of check in multiple places
        consumer.accept(ClassPathElement.EMPTY);
        return;
    }
    List<String> filteredResources = configuredClassLoading.removedResources.get(artifact.getKey());
    if (filteredResources != null) {
        Consumer<ClassPathElement> old = consumer;
        consumer = new Consumer<ClassPathElement>() {

            @Override
            public void accept(ClassPathElement classPathElement) {
                old.accept(new FilteredClassPathElement(classPathElement, filteredResources));
            }
        };
    }
    ClassPathElement cpe = augmentationElements.get(artifact.getKey());
    if (cpe != null) {
        consumer.accept(cpe);
        return;
    }
    final PathTree contentTree = artifact.getContentTree();
    if (contentTree.isEmpty()) {
        consumer.accept(ClassPathElement.EMPTY);
        return;
    }
    cpe = ClassPathElement.fromDependency(artifact);
    consumer.accept(cpe);
    augmentationElements.put(artifact.getKey(), cpe);
}
Also used : FilteredClassPathElement(io.quarkus.bootstrap.classloading.FilteredClassPathElement) MemoryClassPathElement(io.quarkus.bootstrap.classloading.MemoryClassPathElement) ClassPathElement(io.quarkus.bootstrap.classloading.ClassPathElement) FilteredClassPathElement(io.quarkus.bootstrap.classloading.FilteredClassPathElement) PathTree(io.quarkus.paths.PathTree) OpenPathTree(io.quarkus.paths.OpenPathTree)

Example 5 with PathTree

use of io.quarkus.paths.PathTree 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)

Aggregations

PathTree (io.quarkus.paths.PathTree)7 MultiRootPathTree (io.quarkus.paths.MultiRootPathTree)4 Path (java.nio.file.Path)4 OpenPathTree (io.quarkus.paths.OpenPathTree)3 SourceDir (io.quarkus.bootstrap.workspace.SourceDir)2 WorkspaceModule (io.quarkus.bootstrap.workspace.WorkspaceModule)2 EmptyPathTree (io.quarkus.paths.EmptyPathTree)2 File (java.io.File)2 URL (java.net.URL)2 ClassPathElement (io.quarkus.bootstrap.classloading.ClassPathElement)1 FilteredClassPathElement (io.quarkus.bootstrap.classloading.FilteredClassPathElement)1 MemoryClassPathElement (io.quarkus.bootstrap.classloading.MemoryClassPathElement)1 LocalProject (io.quarkus.bootstrap.resolver.maven.workspace.LocalProject)1 LocalWorkspace (io.quarkus.bootstrap.resolver.maven.workspace.LocalWorkspace)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