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);
}
}
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();
}
}
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);
}
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);
}
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]));
}
Aggregations