From 42c03370cc7d30b2763e300ca3871f404968c41f Mon Sep 17 00:00:00 2001 From: essobedo Date: Mon, 17 May 2021 21:28:12 +0200 Subject: [PATCH] Replace Set of paths to PathsCollection --- .../io/quarkus/deployment/CodeGenerator.java | 6 +-- .../deployment/dev/CompilationProvider.java | 4 +- .../deployment/dev/DevModeContext.java | 52 +++++++++--------- .../deployment/dev/IDEDevModeMain.java | 29 +++++----- .../deployment/dev/IsolatedDevModeMain.java | 3 +- .../dev/JavaCompilationProvider.java | 12 ++--- .../deployment/dev/QuarkusCompiler.java | 7 +-- .../dev/RuntimeUpdatesProcessor.java | 43 ++++++++------- .../gradle/builder/QuarkusModelBuilder.java | 27 +++++----- .../io/quarkus/gradle/tasks/QuarkusDev.java | 36 +++++++------ .../main/java/io/quarkus/maven/DevMojo.java | 54 +++++++++---------- .../io/quarkus/maven/GenerateCodeMojo.java | 8 +-- .../ConfigPropertiesBuildStep.java | 1 - .../deployment/KotlinCompilationProvider.java | 3 +- .../deployment/ScalaCompilationProvider.java | 3 +- .../io/quarkus/bootstrap/IDELauncherImpl.java | 4 +- .../bootstrap/resolver/model/SourceSet.java | 7 ++- .../resolver/model/impl/SourceSetImpl.java | 31 +++++------ .../bootstrap/util/QuarkusModelHelper.java | 16 +++--- .../maven/workspace/LocalProject.java | 19 +++---- .../maven/workspace/LocalWorkspace.java | 2 +- .../jacoco/deployment/JacocoProcessor.java | 11 ++-- .../io/quarkus/test/QuarkusDevModeTest.java | 15 +++--- .../test/junit/IntegrationTestUtil.java | 8 +-- .../test/junit/QuarkusTestExtension.java | 9 ++-- 25 files changed, 208 insertions(+), 202 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/CodeGenerator.java b/core/deployment/src/main/java/io/quarkus/deployment/CodeGenerator.java index a530e31c842679..c42d1524fc7f7e 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/CodeGenerator.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/CodeGenerator.java @@ -7,10 +7,10 @@ import java.util.List; import java.util.Map; import java.util.ServiceLoader; -import java.util.Set; import java.util.function.Consumer; import io.quarkus.bootstrap.model.AppModel; +import io.quarkus.bootstrap.model.PathsCollection; import io.quarkus.bootstrap.prebuild.CodeGenException; import io.quarkus.deployment.codegen.CodeGenData; @@ -22,7 +22,7 @@ public class CodeGenerator { // used by Gradle @SuppressWarnings("unused") public static void initAndRun(ClassLoader classLoader, - Set sourceParentDirs, Path generatedSourcesDir, Path buildDir, + PathsCollection sourceParentDirs, Path generatedSourcesDir, Path buildDir, Consumer sourceRegistrar, AppModel appModel, Map properties) throws CodeGenException { List generators = init(classLoader, sourceParentDirs, generatedSourcesDir, buildDir, sourceRegistrar); @@ -33,7 +33,7 @@ public static void initAndRun(ClassLoader classLoader, } public static List init(ClassLoader deploymentClassLoader, - Set sourceParentDirs, + PathsCollection sourceParentDirs, Path generatedSourcesDir, Path buildDir, Consumer sourceRegistrar) throws CodeGenException { diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/CompilationProvider.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/CompilationProvider.java index d1829ea2c7947b..898cd7b033af6e 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/CompilationProvider.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/CompilationProvider.java @@ -11,6 +11,8 @@ import java.util.List; import java.util.Set; +import io.quarkus.bootstrap.model.PathsCollection; + public interface CompilationProvider extends Closeable { Set handledExtensions(); @@ -21,7 +23,7 @@ default Set handledSourcePaths() { void compile(Set files, Context context); - Path getSourcePath(Path classFilePath, Set sourcePaths, String classesPath); + Path getSourcePath(Path classFilePath, PathsCollection sourcePaths, String classesPath); @Override default void close() throws IOException { diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/DevModeContext.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/DevModeContext.java index 0ebb11ce4f6bac..b52164b6a81366 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/DevModeContext.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/DevModeContext.java @@ -3,13 +3,12 @@ import java.io.File; import java.io.Serializable; import java.net.URL; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Optional; @@ -17,6 +16,7 @@ import io.quarkus.bootstrap.app.QuarkusBootstrap; import io.quarkus.bootstrap.model.AppArtifactKey; +import io.quarkus.bootstrap.model.PathsCollection; /** * Object that is used to pass context data from the plugin doing the invocation @@ -26,7 +26,7 @@ */ public class DevModeContext implements Serializable { - public static final CompilationUnit EMPTY_COMPILATION_UNIT = new CompilationUnit(Collections.emptySet(), null, null, null); + public static final CompilationUnit EMPTY_COMPILATION_UNIT = new CompilationUnit(PathsCollection.of(), null, null, null); public static final String ENABLE_PREVIEW_FLAG = "--enable-preview"; @@ -235,18 +235,18 @@ public static class ModuleInfo implements Serializable { private final CompilationUnit test; private final String preBuildOutputDir; - private final Set sourceParents; + private final PathsCollection sourceParents; private final String targetDir; ModuleInfo(Builder builder) { this.appArtifactKey = builder.appArtifactKey; this.name = builder.name; this.projectDirectory = builder.projectDirectory; - this.main = new CompilationUnit(new LinkedHashSet<>(builder.sourcePaths), builder.classesPath, + this.main = new CompilationUnit(builder.sourcePaths, builder.classesPath, builder.resourcePaths, builder.resourcesOutputPath); if (builder.testClassesPath != null) { - this.test = new CompilationUnit(new LinkedHashSet<>(builder.testSourcePaths), + this.test = new CompilationUnit(builder.testSourcePaths, builder.testClassesPath, builder.testResourcePaths, builder.testResourcesOutputPath); } else { this.test = null; @@ -264,15 +264,17 @@ public String getProjectDirectory() { return projectDirectory; } - public Set getSourceParents() { + public PathsCollection getSourceParents() { return sourceParents; } //TODO: why isn't this immutable? public void addSourcePaths(Collection additionalPaths) { - additionalPaths.stream() - .map(p -> Paths.get(p).isAbsolute() ? p : (projectDirectory + File.separator + p)) - .forEach(main.sourcePaths::add); + this.main.sourcePaths = this.main.sourcePaths.add( + additionalPaths.stream() + .map(p -> Paths.get(p).isAbsolute() ? p : (projectDirectory + File.separator + p)) + .map(Paths::get) + .toArray(Path[]::new)); } public String getPreBuildOutputDir() { @@ -300,18 +302,18 @@ public static class Builder { private AppArtifactKey appArtifactKey; private String name; private String projectDirectory; - private Set sourcePaths = Collections.emptySet(); + private PathsCollection sourcePaths = PathsCollection.of(); private String classesPath; - private Set resourcePaths = Collections.emptySet(); + private PathsCollection resourcePaths = PathsCollection.of(); private String resourcesOutputPath; private String preBuildOutputDir; - private Set sourceParents = Collections.emptySet(); + private PathsCollection sourceParents = PathsCollection.of(); private String targetDir; - private Set testSourcePaths = Collections.emptySet(); + private PathsCollection testSourcePaths = PathsCollection.of(); private String testClassesPath; - private Set testResourcePaths = Collections.emptySet(); + private PathsCollection testResourcePaths = PathsCollection.of(); private String testResourcesOutputPath; public Builder setAppArtifactKey(AppArtifactKey appArtifactKey) { @@ -329,7 +331,7 @@ public Builder setProjectDirectory(String projectDirectory) { return this; } - public Builder setSourcePaths(Set sourcePaths) { + public Builder setSourcePaths(PathsCollection sourcePaths) { this.sourcePaths = sourcePaths; return this; } @@ -339,7 +341,7 @@ public Builder setClassesPath(String classesPath) { return this; } - public Builder setResourcePaths(Set resourcePaths) { + public Builder setResourcePaths(PathsCollection resourcePaths) { this.resourcePaths = resourcePaths; return this; } @@ -354,7 +356,7 @@ public Builder setPreBuildOutputDir(String preBuildOutputDir) { return this; } - public Builder setSourceParents(Set sourceParents) { + public Builder setSourceParents(PathsCollection sourceParents) { this.sourceParents = sourceParents; return this; } @@ -364,7 +366,7 @@ public Builder setTargetDir(String targetDir) { return this; } - public Builder setTestSourcePaths(Set testSourcePaths) { + public Builder setTestSourcePaths(PathsCollection testSourcePaths) { this.testSourcePaths = testSourcePaths; return this; } @@ -374,7 +376,7 @@ public Builder setTestClassesPath(String testClassesPath) { return this; } - public Builder setTestResourcePaths(Set testResourcePaths) { + public Builder setTestResourcePaths(PathsCollection testResourcePaths) { this.testResourcePaths = testResourcePaths; return this; } @@ -391,12 +393,12 @@ public ModuleInfo build() { } public static class CompilationUnit implements Serializable { - private final Set sourcePaths; + private PathsCollection sourcePaths; private final String classesPath; - private final Set resourcePaths; + private final PathsCollection resourcePaths; private final String resourcesOutputPath; - public CompilationUnit(Set sourcePaths, String classesPath, Set resourcePaths, + public CompilationUnit(PathsCollection sourcePaths, String classesPath, PathsCollection resourcePaths, String resourcesOutputPath) { this.sourcePaths = sourcePaths; this.classesPath = classesPath; @@ -404,7 +406,7 @@ public CompilationUnit(Set sourcePaths, String classesPath, Set this.resourcesOutputPath = resourcesOutputPath; } - public Set getSourcePaths() { + public PathsCollection getSourcePaths() { return sourcePaths; } @@ -412,7 +414,7 @@ public String getClassesPath() { return classesPath; } - public Set getResourcePaths() { + public PathsCollection getResourcePaths() { return resourcePaths; } diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/IDEDevModeMain.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/IDEDevModeMain.java index e274bd57ebf175..f9440a747d4cf9 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/IDEDevModeMain.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/IDEDevModeMain.java @@ -1,10 +1,9 @@ package io.quarkus.deployment.dev; import java.io.Closeable; -import java.io.File; import java.nio.file.Path; import java.util.Collections; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; import java.util.function.BiConsumer; @@ -15,6 +14,7 @@ import io.quarkus.bootstrap.BootstrapGradleException; import io.quarkus.bootstrap.app.CuratedApplication; import io.quarkus.bootstrap.model.AppArtifactKey; +import io.quarkus.bootstrap.model.PathsCollection; import io.quarkus.bootstrap.resolver.AppModelResolverException; import io.quarkus.bootstrap.resolver.maven.workspace.LocalProject; import io.quarkus.bootstrap.resolver.maven.workspace.LocalWorkspace; @@ -96,27 +96,24 @@ private DevModeContext.ModuleInfo toModule(WorkspaceModule module) throws Bootst AppArtifactKey key = new AppArtifactKey(module.getArtifactCoords().getGroupId(), module.getArtifactCoords().getArtifactId(), module.getArtifactCoords().getClassifier()); - Set sourceDirectories = new HashSet<>(); - Set sourceParents = new HashSet<>(); - for (File srcDir : module.getSourceSourceSet().getSourceDirectories()) { - sourceDirectories.add(srcDir.getPath()); + final Set sourceParents = new LinkedHashSet<>(); + for (Path srcDir : module.getSourceSourceSet().getSourceDirectories()) { sourceParents.add(srcDir.getParent()); } String resourceDirectory = null; if (!module.getSourceSet().getResourceDirectories().isEmpty()) { // Peek the first one as we assume that it is the primary - resourceDirectory = module.getSourceSet().getResourceDirectories().iterator().next().getPath(); + resourceDirectory = module.getSourceSet().getResourceDirectories().iterator().next().toString(); } return new DevModeContext.ModuleInfo.Builder() .setAppArtifactKey(key) .setName(module.getArtifactCoords().getArtifactId()) .setProjectDirectory(module.getProjectRoot().getPath()) - .setSourcePaths(sourceDirectories) + .setSourcePaths(module.getSourceSourceSet().getSourceDirectories()) .setClassesPath(QuarkusModelHelper.getClassPath(module).toAbsolutePath().toString()) - .setResourcePaths(module.getSourceSourceSet().getResourceDirectories().stream().map(Object::toString) - .collect(Collectors.toSet())) + .setResourcePaths(module.getSourceSourceSet().getResourceDirectories()) .setResourcesOutputPath(resourceDirectory) - .setSourceParents(sourceParents) + .setSourceParents(PathsCollection.from(sourceParents)) .setPreBuildOutputDir(module.getBuildDir().toPath().resolve("generated-sources").toAbsolutePath().toString()) .setTargetDir(module.getBuildDir().toString()).build(); } @@ -127,14 +124,14 @@ private DevModeContext.ModuleInfo toModule(LocalProject project) { .setAppArtifactKey(project.getKey()) .setName(project.getArtifactId()) .setProjectDirectory(project.getDir().toAbsolutePath().toString()) - .setSourcePaths(Collections.singleton(project.getSourcesSourcesDir().toAbsolutePath().toString())) + .setSourcePaths(PathsCollection.of(project.getSourcesSourcesDir().toAbsolutePath())) .setClassesPath(project.getClassesDir().toAbsolutePath().toString()) .setResourcesOutputPath(project.getClassesDir().toAbsolutePath().toString()) .setResourcePaths( - project.getResourcesSourcesDirs().stream() - .map(resourcesSourcesDir -> resourcesSourcesDir.toAbsolutePath().toString()) - .collect(Collectors.toSet())) - .setSourceParents(Collections.singleton(project.getSourcesDir().toString())) + PathsCollection.from(project.getResourcesSourcesDirs().toList().stream() + .map(Path::toAbsolutePath) + .collect(Collectors.toCollection(LinkedHashSet::new)))) + .setSourceParents(PathsCollection.of(project.getSourcesDir())) .setPreBuildOutputDir(project.getCodeGenOutputDir().toString()) .setTargetDir(project.getOutputDir().toString()).build(); } diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedDevModeMain.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedDevModeMain.java index 3da2424e11bba5..c46b39f045aacf 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedDevModeMain.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedDevModeMain.java @@ -23,7 +23,6 @@ import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Predicate; -import java.util.stream.Collectors; import org.eclipse.microprofile.config.spi.ConfigProviderResolver; import org.jboss.logging.Logger; @@ -394,7 +393,7 @@ public boolean test(String s) { codeGens.addAll( CodeGenerator.init( deploymentClassLoader, - module.getSourceParents().stream().map(Paths::get).collect(Collectors.toSet()), + module.getSourceParents(), Paths.get(module.getPreBuildOutputDir()), Paths.get(module.getTargetDir()), sourcePath -> module.addSourcePaths(singleton(sourcePath.toAbsolutePath().toString())))); diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/JavaCompilationProvider.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/JavaCompilationProvider.java index 47decbc6dbc701..2346fba5cbfb7b 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/JavaCompilationProvider.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/JavaCompilationProvider.java @@ -23,6 +23,7 @@ import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; +import io.quarkus.bootstrap.model.PathsCollection; import io.quarkus.gizmo.Gizmo; public class JavaCompilationProvider implements CompilationProvider { @@ -94,7 +95,7 @@ public void compile(Set filesToCompile, Context context) { } @Override - public Path getSourcePath(Path classFilePath, Set sourcePaths, String classesPath) { + public Path getSourcePath(Path classFilePath, PathsCollection sourcePaths, String classesPath) { Path sourceFilePath = null; final RuntimeUpdatesClassVisitor visitor = new RuntimeUpdatesClassVisitor(sourcePaths, classesPath); try (final InputStream inputStream = Files.newInputStream(classFilePath)) { @@ -117,11 +118,11 @@ public void close() throws IOException { } static class RuntimeUpdatesClassVisitor extends ClassVisitor { - private Set sourcePaths; - private String classesPath; + private final PathsCollection sourcePaths; + private final String classesPath; private String sourceFile; - public RuntimeUpdatesClassVisitor(Set sourcePaths, String classesPath) { + public RuntimeUpdatesClassVisitor(PathsCollection sourcePaths, String classesPath) { super(Gizmo.ASM_API_VERSION); this.sourcePaths = sourcePaths; this.classesPath = classesPath; @@ -133,8 +134,7 @@ public void visitSource(String source, String debug) { } public Path getSourceFileForClass(final Path classFilePath) { - for (String moduleSourcePath : sourcePaths) { - final Path sourcesDir = Paths.get(moduleSourcePath); + for (Path sourcesDir : sourcePaths) { final Path classesDir = Paths.get(classesPath); final StringBuilder sourceRelativeDir = new StringBuilder(); sourceRelativeDir.append(classesDir.relativize(classFilePath.getParent())); diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/QuarkusCompiler.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/QuarkusCompiler.java index 208bc783f91767..20b1285ad214da 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/QuarkusCompiler.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/QuarkusCompiler.java @@ -27,6 +27,7 @@ import io.quarkus.bootstrap.app.CuratedApplication; import io.quarkus.bootstrap.app.QuarkusBootstrap; import io.quarkus.bootstrap.model.AppDependency; +import io.quarkus.bootstrap.model.PathsCollection; /** * Class that handles compilation of source files @@ -161,12 +162,12 @@ public void setupSourceCompilationContext(DevModeContext context, Set clas return; } compilationUnit.getSourcePaths().forEach(sourcePath -> { - this.compilationContexts.put(sourcePath, + this.compilationContexts.put(sourcePath.toString(), new CompilationProvider.Context( i.getName(), classPathElements, i.getProjectDirectory() == null ? null : new File(i.getProjectDirectory()), - new File(sourcePath), + sourcePath.toFile(), new File(compilationUnit.getClassesPath()), context.getSourceEncoding(), context.getCompilerOptions(), @@ -194,7 +195,7 @@ public void compile(String sourceDir, Map> extensionToChangedF } } - public Path findSourcePath(Path classFilePath, Set sourcePaths, String classesPath) { + public Path findSourcePath(Path classFilePath, PathsCollection sourcePaths, String classesPath) { for (CompilationProvider compilationProvider : compilationProviders) { Path sourcePath = compilationProvider.getSourcePath(classFilePath, sourcePaths, classesPath); diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/RuntimeUpdatesProcessor.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/RuntimeUpdatesProcessor.java index baa23121b420b3..92bb6239f0dfc0 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/RuntimeUpdatesProcessor.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/RuntimeUpdatesProcessor.java @@ -53,6 +53,7 @@ import org.jboss.jandex.Indexer; import org.jboss.logging.Logger; +import io.quarkus.bootstrap.model.PathsCollection; import io.quarkus.bootstrap.runner.Timing; import io.quarkus.changeagent.ClassChangeAgent; import io.quarkus.deployment.dev.filewatch.FileChangeCallback; @@ -182,7 +183,7 @@ public Path getClassesDir() { @Override public List getSourcesDir() { - return context.getAllModules().stream().flatMap(m -> m.getMain().getSourcePaths().stream()).map(Paths::get) + return context.getAllModules().stream().flatMap(m -> m.getMain().getSourcePaths().toList().stream()) .collect(toList()); } @@ -213,18 +214,18 @@ public void handleChanges(Collection changes) { } }; for (DevModeContext.ModuleInfo module : context.getAllModules()) { - for (String path : module.getMain().getSourcePaths()) { - testClassChangeWatcher.watchPath(new File(path), callback); + for (Path path : module.getMain().getSourcePaths()) { + testClassChangeWatcher.watchPath(path.toFile(), callback); } - for (String path : module.getMain().getResourcePaths()) { - testClassChangeWatcher.watchPath(new File(path), callback); + for (Path path : module.getMain().getResourcePaths()) { + testClassChangeWatcher.watchPath(path.toFile(), callback); } } - for (String path : context.getApplicationRoot().getTest().get().getSourcePaths()) { - testClassChangeWatcher.watchPath(new File(path), callback); + for (Path path : context.getApplicationRoot().getTest().get().getSourcePaths()) { + testClassChangeWatcher.watchPath(path.toFile(), callback); } - for (String path : context.getApplicationRoot().getTest().get().getResourcePaths()) { - testClassChangeWatcher.watchPath(new File(path), callback); + for (Path path : context.getApplicationRoot().getTest().get().getResourcePaths()) { + testClassChangeWatcher.watchPath(path.toFile(), callback); } periodicTestCompile(); } else { @@ -295,8 +296,8 @@ public List getResourcesDir() { List ret = new ArrayList<>(); for (DevModeContext.ModuleInfo i : context.getAllModules()) { if (!i.getMain().getResourcePaths().isEmpty()) { - for (String path : i.getMain().getResourcePaths()) { - ret.add(Paths.get(path)); + for (Path path : i.getMain().getResourcePaths()) { + ret.add(path); } } else if (i.getMain().getResourcesOutputPath() != null) { ret.add(Paths.get(i.getMain().getResourcesOutputPath())); @@ -554,9 +555,9 @@ ClassScanResult checkForChangedClasses(QuarkusCompiler compiler, for (DevModeContext.ModuleInfo module : context.getAllModules()) { final List moduleChangedSourceFilePaths = new ArrayList<>(); - for (String sourcePath : cuf.apply(module).getSourcePaths()) { + for (Path sourcePath : cuf.apply(module).getSourcePaths()) { final Set changedSourceFiles; - Path start = Paths.get(sourcePath); + Path start = sourcePath; if (!Files.exists(start)) { continue; } @@ -580,7 +581,7 @@ && sourceFileWasRecentModified(p, ignoreFirstScanChanges)) .map(File::toPath) .collect(Collectors.toSet()); moduleChangedSourceFilePaths.addAll(changedPaths); - compiler.compile(sourcePath, changedSourceFiles.stream() + compiler.compile(sourcePath.toString(), changedSourceFiles.stream() .collect(groupingBy(this::getFileExtension, Collectors.toSet()))); compileProblem = null; } catch (Exception e) { @@ -701,12 +702,12 @@ Set checkForFileChange(Function moduleResources = correspondingResources.computeIfAbsent(cuf.apply(module), m -> Collections.newSetFromMap(new ConcurrentHashMap<>())); boolean doCopy = true; - Set rootPaths = cuf.apply(module).getResourcePaths(); + PathsCollection rootPaths = cuf.apply(module).getResourcePaths(); String outputPath = cuf.apply(module).getResourcesOutputPath(); if (rootPaths.isEmpty()) { String rootPath = cuf.apply(module).getClassesPath(); if (rootPath != null) { - rootPaths = Collections.singleton(rootPath); + rootPaths = PathsCollection.of(Paths.get(rootPath)); } outputPath = rootPath; doCopy = false; @@ -714,8 +715,7 @@ Set checkForFileChange(Function roots = rootPaths.stream() - .map(Paths::get) + final List roots = rootPaths.toList().stream() .filter(Files::exists) .filter(Files::isReadable) .collect(Collectors.toList()); @@ -880,16 +880,15 @@ private RuntimeUpdatesProcessor setWatchedFilePathsInternal(Map for (DevModeContext.ModuleInfo module : context.getAllModules()) { List compilationUnits = cuf.apply(module); for (DevModeContext.CompilationUnit unit : compilationUnits) { - Set rootPaths = unit.getResourcePaths(); + PathsCollection rootPaths = unit.getResourcePaths(); if (rootPaths.isEmpty()) { String rootPath = unit.getClassesPath(); if (rootPath == null) { continue; } - rootPaths = Collections.singleton(rootPath); + rootPaths = PathsCollection.of(Paths.get(rootPath)); } - for (String rootPath : rootPaths) { - Path root = Paths.get(rootPath); + for (Path root : rootPaths) { for (String path : watchedFilePaths.keySet()) { Path config = root.resolve(path); if (config.toFile().exists()) { diff --git a/devtools/gradle/src/main/java/io/quarkus/gradle/builder/QuarkusModelBuilder.java b/devtools/gradle/src/main/java/io/quarkus/gradle/builder/QuarkusModelBuilder.java index 12a7c4369dc3fc..218857ad25014b 100644 --- a/devtools/gradle/src/main/java/io/quarkus/gradle/builder/QuarkusModelBuilder.java +++ b/devtools/gradle/src/main/java/io/quarkus/gradle/builder/QuarkusModelBuilder.java @@ -16,6 +16,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -23,6 +24,7 @@ import java.util.Properties; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.gradle.api.GradleException; import org.gradle.api.Project; @@ -218,15 +220,16 @@ private WorkspaceModule getWorkspaceModule(Project project, LaunchMode mode, boo ArtifactCoords appArtifactCoords = new ArtifactCoordsImpl(project.getGroup().toString(), project.getName(), project.getVersion().toString()); final SourceSet mainSourceSet = QuarkusGradleUtils.getSourceSet(project, SourceSet.MAIN_SOURCE_SET_NAME); - final SourceSetImpl modelSourceSet = convert(mainSourceSet); - WorkspaceModuleImpl workspaceModule = new WorkspaceModuleImpl(appArtifactCoords, - project.getProjectDir().getAbsoluteFile(), - project.getBuildDir().getAbsoluteFile(), getSourceSourceSet(mainSourceSet), modelSourceSet); + final SourceSetImpl modelSourceSet; if (isMainModule && mode == LaunchMode.TEST) { final SourceSet testSourceSet = QuarkusGradleUtils.getSourceSet(project, SourceSet.TEST_SOURCE_SET_NAME); - workspaceModule.getSourceSet().getSourceDirectories().addAll(testSourceSet.getOutput().getClassesDirs().getFiles()); + modelSourceSet = convert(mainSourceSet, testSourceSet.getOutput().getClassesDirs().getFiles()); + } else { + modelSourceSet = convert(mainSourceSet, Collections.emptySet()); } - return workspaceModule; + return new WorkspaceModuleImpl(appArtifactCoords, + project.getProjectDir().getAbsoluteFile(), + project.getBuildDir().getAbsoluteFile(), getSourceSourceSet(mainSourceSet), modelSourceSet); } private List getEnforcedPlatforms(Project project) { @@ -470,13 +473,11 @@ private IncludedBuild includedBuild(final Project project, final String projectN } } - private SourceSetImpl convert(SourceSet sourceSet) { - Set existingSrcDirs = new HashSet<>(); - for (File srcDir : sourceSet.getOutput().getClassesDirs().getFiles()) { - if (srcDir.exists()) { - existingSrcDirs.add(srcDir); - } - } + private SourceSetImpl convert(SourceSet sourceSet, Set additionalSourceDirs) { + Set existingSrcDirs = Stream.of(sourceSet.getOutput().getClassesDirs().getFiles(), additionalSourceDirs) + .flatMap(Collection::stream) + .filter(File::exists) + .collect(Collectors.toCollection(LinkedHashSet::new)); if (sourceSet.getOutput().getResourcesDir().exists()) { return new SourceSetImpl( existingSrcDirs, diff --git a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java index 83809c6a733265..cdcb34ddd257a1 100644 --- a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java +++ b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java @@ -8,6 +8,7 @@ import java.nio.file.Paths; import java.util.Arrays; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -45,6 +46,7 @@ import io.quarkus.bootstrap.model.AppArtifactKey; import io.quarkus.bootstrap.model.AppDependency; import io.quarkus.bootstrap.model.AppModel; +import io.quarkus.bootstrap.model.PathsCollection; import io.quarkus.bootstrap.resolver.AppModelResolver; import io.quarkus.bootstrap.resolver.AppModelResolverException; import io.quarkus.deployment.dev.DevModeContext; @@ -360,18 +362,18 @@ private void addLocalProject(Project project, GradleDevModeLauncher.Builder buil if (mainSourceSet == null) { return; } - Set sourcePaths = new HashSet<>(); - Set sourceParentPaths = new HashSet<>(); + Set sourcePaths = new LinkedHashSet<>(); + Set sourceParentPaths = new LinkedHashSet<>(); for (File sourceDir : mainSourceSet.getAllJava().getSrcDirs()) { if (sourceDir.exists()) { - sourcePaths.add(sourceDir.getAbsolutePath()); - sourceParentPaths.add(sourceDir.toPath().getParent().toAbsolutePath().toString()); + sourcePaths.add(sourceDir.toPath().toAbsolutePath()); + sourceParentPaths.add(sourceDir.toPath().getParent().toAbsolutePath()); } } - final Set resourcesSrcDirs = new HashSet<>(); + final Set resourcesSrcDirs = new LinkedHashSet<>(); for (File resourcesSrcDir : mainSourceSet.getResources().getSourceDirectories().getFiles()) { - resourcesSrcDirs.add(resourcesSrcDir.getAbsolutePath()); + resourcesSrcDirs.add(resourcesSrcDir.toPath().toAbsolutePath()); } // resourcesSrcDir may exist but if it's empty the resources output dir won't be created final File resourcesOutputDir = mainSourceSet.getOutput().getResourcesDir(); @@ -405,29 +407,29 @@ private void addLocalProject(Project project, GradleDevModeLauncher.Builder buil DevModeContext.ModuleInfo.Builder moduleBuilder = new DevModeContext.ModuleInfo.Builder().setAppArtifactKey(key) .setName(project.getName()) .setProjectDirectory(project.getProjectDir().getAbsolutePath()) - .setSourcePaths(sourcePaths) + .setSourcePaths(PathsCollection.from(sourcePaths)) .setClassesPath(classesDir) - .setResourcePaths(resourcesSrcDirs) + .setResourcePaths(PathsCollection.from(resourcesSrcDirs)) .setResourcesOutputPath(resourcesOutputPath) - .setSourceParents(sourceParentPaths) + .setSourceParents(PathsCollection.from(sourceParentPaths)) .setPreBuildOutputDir(project.getBuildDir().toPath().resolve("generated-sources").toAbsolutePath().toString()) .setTargetDir(project.getBuildDir().toString()); SourceSet testSourceSet = sourceSets.findByName(SourceSet.TEST_SOURCE_SET_NAME); if (testSourceSet != null) { - Set testSourcePaths = new HashSet<>(); - Set testSourceParentPaths = new HashSet<>(); + Set testSourcePaths = new LinkedHashSet<>(); + Set testSourceParentPaths = new LinkedHashSet<>(); for (File sourceDir : testSourceSet.getAllJava().getSrcDirs()) { if (sourceDir.exists()) { - testSourcePaths.add(sourceDir.getAbsolutePath()); - testSourceParentPaths.add(sourceDir.toPath().getParent().toAbsolutePath().toString()); + testSourcePaths.add(sourceDir.toPath().toAbsolutePath()); + testSourceParentPaths.add(sourceDir.toPath().getParent().toAbsolutePath()); } } - final Set testResourcesSrcDirs = new HashSet<>(); + final Set testResourcesSrcDirs = new LinkedHashSet<>(); for (File testResourcesSrcDir : testSourceSet.getResources().getSourceDirectories().getFiles()) { - testResourcesSrcDirs.add(testResourcesSrcDir.getAbsolutePath()); + testResourcesSrcDirs.add(testResourcesSrcDir.toPath().toAbsolutePath()); } // resourcesSrcDir may exist but if it's empty the resources output dir won't be created final File testResourcesOutputDir = testSourceSet.getOutput().getResourcesDir(); @@ -448,9 +450,9 @@ private void addLocalProject(Project project, GradleDevModeLauncher.Builder buil // currently resources dir should exist testResourcesOutputPath = testClassesDir; } - moduleBuilder.setTestSourcePaths(testSourcePaths) + moduleBuilder.setTestSourcePaths(PathsCollection.from(testSourcePaths)) .setTestClassesPath(testClassesDir) - .setTestResourcePaths(testResourcesSrcDirs) + .setTestResourcePaths(PathsCollection.from(testResourcesSrcDirs)) .setTestResourcesOutputPath(testResourcesOutputPath); } } diff --git a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java index b92a6cf0b9ce81..bc23b00071cba2 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Optional; @@ -76,6 +77,7 @@ import io.quarkus.bootstrap.devmode.DependenciesFilter; import io.quarkus.bootstrap.model.AppArtifactKey; import io.quarkus.bootstrap.model.AppModel; +import io.quarkus.bootstrap.model.PathsCollection; import io.quarkus.bootstrap.resolver.maven.options.BootstrapMavenOptions; import io.quarkus.bootstrap.resolver.maven.workspace.LocalProject; import io.quarkus.deployment.dev.DevModeContext; @@ -577,13 +579,13 @@ private String getSourceEncoding() { private void addProject(MavenDevModeLauncher.Builder builder, LocalProject localProject, boolean root) throws Exception { - String projectDirectory = null; - Set sourcePaths = null; + String projectDirectory; + Set sourcePaths; String classesPath = null; - Set resourcePaths; - Set testSourcePaths = null; + Set resourcePaths; + Set testSourcePaths; String testClassesPath = null; - Set testResourcePaths; + Set testResourcePaths; List activeProfiles = Collections.emptyList(); final MavenProject mavenProject = session.getProjectMap().get( @@ -592,15 +594,13 @@ private void addProject(MavenDevModeLauncher.Builder builder, LocalProject local projectDirectory = localProject.getDir().toAbsolutePath().toString(); Path sourcePath = localProject.getSourcesSourcesDir().toAbsolutePath(); if (Files.isDirectory(sourcePath)) { - sourcePaths = Collections.singleton( - sourcePath.toString()); + sourcePaths = Collections.singleton(sourcePath); } else { sourcePaths = Collections.emptySet(); } Path testSourcePath = localProject.getTestSourcesSourcesDir().toAbsolutePath(); if (Files.isDirectory(testSourcePath)) { - testSourcePaths = Collections.singleton( - testSourcePath.toString()); + testSourcePaths = Collections.singleton(testSourcePath); } else { testSourcePaths = Collections.emptySet(); } @@ -609,13 +609,13 @@ private void addProject(MavenDevModeLauncher.Builder builder, LocalProject local sourcePaths = mavenProject.getCompileSourceRoots().stream() .map(Paths::get) .filter(Files::isDirectory) - .map(src -> src.toAbsolutePath().toString()) - .collect(Collectors.toSet()); + .map(Path::toAbsolutePath) + .collect(Collectors.toCollection(LinkedHashSet::new)); testSourcePaths = mavenProject.getTestCompileSourceRoots().stream() .map(Paths::get) .filter(Files::isDirectory) - .map(src -> src.toAbsolutePath().toString()) - .collect(Collectors.toSet()); + .map(Path::toAbsolutePath) + .collect(Collectors.toCollection(LinkedHashSet::new)); activeProfiles = mavenProject.getActiveProfiles(); } Path sourceParent = localProject.getSourcesDir().toAbsolutePath(); @@ -628,14 +628,14 @@ private void addProject(MavenDevModeLauncher.Builder builder, LocalProject local if (Files.isDirectory(testClassesDir)) { testClassesPath = testClassesDir.toAbsolutePath().toString(); } - resourcePaths = localProject.getResourcesSourcesDirs().stream() + resourcePaths = localProject.getResourcesSourcesDirs().toList().stream() .filter(Files::isDirectory) - .map(resourcesSourcesDir -> resourcesSourcesDir.toAbsolutePath().toString()) - .collect(Collectors.toSet()); - testResourcePaths = localProject.getTestResourcesSourcesDirs().stream() + .map(Path::toAbsolutePath) + .collect(Collectors.toCollection(LinkedHashSet::new)); + testResourcePaths = localProject.getTestResourcesSourcesDirs().toList().stream() .filter(Files::isDirectory) - .map(resourcesSourcesDir -> resourcesSourcesDir.toAbsolutePath().toString()) - .collect(Collectors.toSet()); + .map(Path::toAbsolutePath) + .collect(Collectors.toCollection(LinkedHashSet::new)); // Add the resources and test resources from the profiles for (Profile profile : activeProfiles) { final BuildBase build = profile.getBuild(); @@ -644,13 +644,13 @@ private void addProject(MavenDevModeLauncher.Builder builder, LocalProject local build.getResources().stream() .map(Resource::getDirectory) .map(localProject::resolveRelativeToBaseDir) - .map(resourcesSourcesDir -> resourcesSourcesDir.toAbsolutePath().toString()) + .map(Path::toAbsolutePath) .collect(Collectors.toList())); testResourcePaths.addAll( build.getTestResources().stream() .map(Resource::getDirectory) .map(localProject::resolveRelativeToBaseDir) - .map(resourcesSourcesDir -> resourcesSourcesDir.toAbsolutePath().toString()) + .map(Path::toAbsolutePath) .collect(Collectors.toList())); } } @@ -665,18 +665,18 @@ private void addProject(MavenDevModeLauncher.Builder builder, LocalProject local DevModeContext.ModuleInfo moduleInfo = new DevModeContext.ModuleInfo.Builder().setAppArtifactKey(localProject.getKey()) .setName(localProject.getArtifactId()) .setProjectDirectory(projectDirectory) - .setSourcePaths(sourcePaths) + .setSourcePaths(PathsCollection.from(sourcePaths)) .setClassesPath(classesPath) .setResourcesOutputPath(classesPath) - .setResourcePaths(resourcePaths) - .setSourceParents(Collections.singleton(sourceParent.toAbsolutePath().toString())) + .setResourcePaths(PathsCollection.from(resourcePaths)) + .setSourceParents(PathsCollection.of(sourceParent.toAbsolutePath())) .setPreBuildOutputDir(targetDir.resolve("generated-sources").toAbsolutePath().toString()) .setTargetDir(targetDir.toAbsolutePath().toString()) - .setTestSourcePaths(testSourcePaths) + .setTestSourcePaths(PathsCollection.from(testSourcePaths)) .setTestClassesPath(testClassesPath) - .setTestResourcePaths(testResourcePaths) + .setTestResourcePaths(PathsCollection.from(testResourcePaths)) .setTestResourcesOutputPath(testClassesPath) - .setTestResourcePaths(testResourcePaths) + .setTestResourcePaths(PathsCollection.from(testResourcePaths)) .build(); if (root) { diff --git a/devtools/maven/src/main/java/io/quarkus/maven/GenerateCodeMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/GenerateCodeMojo.java index cb7bd5159d0dab..cd72420cce4eb3 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/GenerateCodeMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/GenerateCodeMojo.java @@ -3,9 +3,7 @@ import java.lang.reflect.Method; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Collections; import java.util.Map; -import java.util.Set; import java.util.function.Consumer; import org.apache.maven.plugin.MojoExecutionException; @@ -18,6 +16,7 @@ import io.quarkus.bootstrap.app.CuratedApplication; import io.quarkus.bootstrap.classloading.QuarkusClassLoader; import io.quarkus.bootstrap.model.AppModel; +import io.quarkus.bootstrap.model.PathsCollection; @Mojo(name = "generate-code", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, threadSafe = true) public class GenerateCodeMojo extends QuarkusBootstrapMojo { @@ -61,11 +60,12 @@ void generateCode(Path sourcesDir, Thread.currentThread().setContextClassLoader(deploymentClassLoader); final Class codeGenerator = deploymentClassLoader.loadClass("io.quarkus.deployment.CodeGenerator"); - final Method initAndRun = codeGenerator.getMethod("initAndRun", ClassLoader.class, Set.class, Path.class, + final Method initAndRun = codeGenerator.getMethod("initAndRun", ClassLoader.class, PathsCollection.class, + Path.class, Path.class, Consumer.class, AppModel.class, Map.class); initAndRun.invoke(null, deploymentClassLoader, - Collections.singleton(sourcesDir), + PathsCollection.of(sourcesDir), generatedSourcesDir(test), buildDir().toPath(), sourceRegistrar, diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/configproperties/ConfigPropertiesBuildStep.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/configproperties/ConfigPropertiesBuildStep.java index 7f2245e2e822ad..0130f1f64b01c4 100644 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/configproperties/ConfigPropertiesBuildStep.java +++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/configproperties/ConfigPropertiesBuildStep.java @@ -49,7 +49,6 @@ void produceConfigPropertiesMetadata(CombinedIndexBuildItem combinedIndex, ArcCo Map failOnMismatchingMembers = new HashMap<>(); // handle @ConfigProperties - final Set excludedDeclaringClasses = exclusionsBuildItem.getExcludedDeclaringClasses(); for (AnnotationInstance instance : index.getAnnotations(DotNames.CONFIG_PROPERTIES)) { final AnnotationTarget target = instance.target(); if (exclusionsBuildItem.isExcluded(target)) { diff --git a/extensions/kotlin/deployment/src/main/java/io/quarkus/kotlin/deployment/KotlinCompilationProvider.java b/extensions/kotlin/deployment/src/main/java/io/quarkus/kotlin/deployment/KotlinCompilationProvider.java index ea7340edf98ded..18633f295c9e17 100644 --- a/extensions/kotlin/deployment/src/main/java/io/quarkus/kotlin/deployment/KotlinCompilationProvider.java +++ b/extensions/kotlin/deployment/src/main/java/io/quarkus/kotlin/deployment/KotlinCompilationProvider.java @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler; import org.jetbrains.kotlin.config.Services; +import io.quarkus.bootstrap.model.PathsCollection; import io.quarkus.deployment.dev.CompilationProvider; public class KotlinCompilationProvider implements CompilationProvider { @@ -87,7 +88,7 @@ public void compile(Set filesToCompile, Context context) { } @Override - public Path getSourcePath(Path classFilePath, Set sourcePaths, String classesPath) { + public Path getSourcePath(Path classFilePath, PathsCollection sourcePaths, String classesPath) { // return same class so it is not removed return classFilePath; } diff --git a/extensions/scala/deployment/src/main/java/io/quarkus/scala/deployment/ScalaCompilationProvider.java b/extensions/scala/deployment/src/main/java/io/quarkus/scala/deployment/ScalaCompilationProvider.java index f5edd1faf09e45..0e4f32e03d3ef2 100644 --- a/extensions/scala/deployment/src/main/java/io/quarkus/scala/deployment/ScalaCompilationProvider.java +++ b/extensions/scala/deployment/src/main/java/io/quarkus/scala/deployment/ScalaCompilationProvider.java @@ -6,6 +6,7 @@ import java.util.Set; import java.util.stream.Collectors; +import io.quarkus.bootstrap.model.PathsCollection; import io.quarkus.deployment.dev.CompilationProvider; import scala.collection.JavaConverters; import scala.tools.nsc.Global; @@ -35,7 +36,7 @@ public void compile(Set files, Context context) { } @Override - public Path getSourcePath(Path classFilePath, Set sourcePaths, String classesPath) { + public Path getSourcePath(Path classFilePath, PathsCollection sourcePaths, String classesPath) { return classFilePath; } } diff --git a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/IDELauncherImpl.java b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/IDELauncherImpl.java index 8c1014ac87ffcf..2bd66dfb4ff045 100644 --- a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/IDELauncherImpl.java +++ b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/IDELauncherImpl.java @@ -52,10 +52,10 @@ public static Closeable launch(Path classesDir, Map context) { for (WorkspaceModule additionalModule : quarkusModel.getWorkspace().getAllModules()) { if (!additionalModule.getArtifactCoords().equals(launchingModule.getArtifactCoords())) { builder.addAdditionalApplicationArchive(new AdditionalDependency( - QuarkusModelHelper.toPathsCollection(additionalModule.getSourceSet().getSourceDirectories()), + additionalModule.getSourceSet().getSourceDirectories(), true, false)); builder.addAdditionalApplicationArchive(new AdditionalDependency( - QuarkusModelHelper.toPathsCollection(additionalModule.getSourceSet().getResourceDirectories()), + additionalModule.getSourceSet().getResourceDirectories(), true, false)); } } diff --git a/independent-projects/bootstrap/gradle-resolver/src/main/java/io/quarkus/bootstrap/resolver/model/SourceSet.java b/independent-projects/bootstrap/gradle-resolver/src/main/java/io/quarkus/bootstrap/resolver/model/SourceSet.java index c2034cf2fb5d34..181b016858621b 100644 --- a/independent-projects/bootstrap/gradle-resolver/src/main/java/io/quarkus/bootstrap/resolver/model/SourceSet.java +++ b/independent-projects/bootstrap/gradle-resolver/src/main/java/io/quarkus/bootstrap/resolver/model/SourceSet.java @@ -1,11 +1,10 @@ package io.quarkus.bootstrap.resolver.model; -import java.io.File; -import java.util.Set; +import io.quarkus.bootstrap.model.PathsCollection; public interface SourceSet { - Set getSourceDirectories(); + PathsCollection getSourceDirectories(); - Set getResourceDirectories(); + PathsCollection getResourceDirectories(); } diff --git a/independent-projects/bootstrap/gradle-resolver/src/main/java/io/quarkus/bootstrap/resolver/model/impl/SourceSetImpl.java b/independent-projects/bootstrap/gradle-resolver/src/main/java/io/quarkus/bootstrap/resolver/model/impl/SourceSetImpl.java index 166995474d2c4b..952a8ec9f7b217 100644 --- a/independent-projects/bootstrap/gradle-resolver/src/main/java/io/quarkus/bootstrap/resolver/model/impl/SourceSetImpl.java +++ b/independent-projects/bootstrap/gradle-resolver/src/main/java/io/quarkus/bootstrap/resolver/model/impl/SourceSetImpl.java @@ -1,47 +1,48 @@ package io.quarkus.bootstrap.resolver.model.impl; +import io.quarkus.bootstrap.model.PathsCollection; import io.quarkus.bootstrap.resolver.model.SourceSet; import java.io.File; import java.io.Serializable; -import java.util.HashSet; +import java.nio.file.Path; +import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; import java.util.stream.Collectors; public class SourceSetImpl implements SourceSet, Serializable { - private final Set sourceDirectories = new HashSet<>(); - // Use a LinkedHashSet to keep the original order - private final Set resourceDirectories = new LinkedHashSet<>(); + private final PathsCollection sourceDirectories; + private final PathsCollection resourceDirectories; public SourceSetImpl(Set sourceDirectories, Set resourceDirectories) { - this.sourceDirectories.addAll(sourceDirectories); - this.resourceDirectories.addAll(resourceDirectories); + this.sourceDirectories = PathsCollection + .from(sourceDirectories.stream().map(File::toPath).collect(Collectors.toCollection(LinkedHashSet::new))); + this.resourceDirectories = PathsCollection + .from(resourceDirectories.stream().map(File::toPath).collect(Collectors.toCollection(LinkedHashSet::new))); } public SourceSetImpl(Set sourceDirectories) { - this.sourceDirectories.addAll(sourceDirectories); - } - - public void addSourceDirectories(Set files) { - sourceDirectories.addAll(files); + this(sourceDirectories, Collections.emptySet()); } @Override - public Set getSourceDirectories() { + public PathsCollection getSourceDirectories() { return sourceDirectories; } @Override - public Set getResourceDirectories() { + public PathsCollection getResourceDirectories() { return resourceDirectories; } @Override public String toString() { return "SourceSetImpl{" + - "sourceDirectories=" + sourceDirectories.stream().map(File::getPath).collect(Collectors.joining(":")) + - ", resourceDirectories=" + resourceDirectories.stream().map(File::getPath).collect(Collectors.joining(":")) + + "sourceDirectories=" + sourceDirectories.toList().stream().map(Path::toString).collect(Collectors.joining(":")) + + + ", resourceDirectories=" + + resourceDirectories.toList().stream().map(Path::toString).collect(Collectors.joining(":")) + '}'; } } diff --git a/independent-projects/bootstrap/gradle-resolver/src/main/java/io/quarkus/bootstrap/util/QuarkusModelHelper.java b/independent-projects/bootstrap/gradle-resolver/src/main/java/io/quarkus/bootstrap/util/QuarkusModelHelper.java index d128d659119688..d6427ae0e299f1 100644 --- a/independent-projects/bootstrap/gradle-resolver/src/main/java/io/quarkus/bootstrap/util/QuarkusModelHelper.java +++ b/independent-projects/bootstrap/gradle-resolver/src/main/java/io/quarkus/bootstrap/util/QuarkusModelHelper.java @@ -88,8 +88,9 @@ public static QuarkusModel deserializeQuarkusModel(Path modelPath) throws Bootst public static Path getClassPath(WorkspaceModule model) throws BootstrapGradleException { // TODO handle multiple class directory - final Optional classDir = model.getSourceSet().getSourceDirectories().stream().filter(File::exists) - .map(File::toPath).findFirst(); + final Optional classDir = model.getSourceSet().getSourceDirectories().toList().stream() + .filter(Files::exists) + .findFirst(); if (!classDir.isPresent()) { throw new BootstrapGradleException("Failed to locate class directory"); } @@ -143,13 +144,12 @@ public static AppModel convert(QuarkusModel model, AppArtifact appArtifact) thro if (!appArtifact.isResolved()) { PathsCollection.Builder paths = PathsCollection.builder(); WorkspaceModule module = model.getWorkspace().getMainModule(); - module.getSourceSet().getSourceDirectories().stream().filter(File::exists).map(File::toPath) + module.getSourceSet().getSourceDirectories().toList().stream() + .filter(Files::exists) + .forEach(paths::add); + module.getSourceSet().getResourceDirectories().toList().stream() + .filter(Files::exists) .forEach(paths::add); - for (File resourceDirectory : module.getSourceSet().getResourceDirectories()) { - if (resourceDirectory.exists()) { - paths.add(resourceDirectory.toPath()); - } - } appArtifact.setPaths(paths.build()); } diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalProject.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalProject.java index 82cf271df6798f..30b2048e3856b9 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalProject.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalProject.java @@ -2,6 +2,7 @@ import io.quarkus.bootstrap.model.AppArtifact; import io.quarkus.bootstrap.model.AppArtifactKey; +import io.quarkus.bootstrap.model.PathsCollection; import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext; import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException; import java.io.IOException; @@ -10,8 +11,8 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; +import java.util.LinkedHashSet; import java.util.List; -import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; import org.apache.maven.model.Build; @@ -230,28 +231,28 @@ public Path getSourcesDir() { return getSourcesSourcesDir().getParent(); } - public Set getResourcesSourcesDirs() { + public PathsCollection getResourcesSourcesDirs() { final List resources = rawModel.getBuild() == null ? Collections.emptyList() : rawModel.getBuild().getResources(); if (resources.isEmpty()) { - return Collections.singleton(resolveRelativeToBaseDir(null, "src/main/resources")); + return PathsCollection.of(resolveRelativeToBaseDir(null, "src/main/resources")); } - return resources.stream() + return PathsCollection.from(resources.stream() .map(Resource::getDirectory) .map(resourcesDir -> resolveRelativeToBaseDir(resourcesDir, "src/main/resources")) - .collect(Collectors.toSet()); + .collect(Collectors.toCollection(LinkedHashSet::new))); } - public Set getTestResourcesSourcesDirs() { + public PathsCollection getTestResourcesSourcesDirs() { final List resources = rawModel.getBuild() == null ? Collections.emptyList() : rawModel.getBuild().getTestResources(); if (resources.isEmpty()) { - return Collections.singleton(resolveRelativeToBaseDir(null, "src/test/resources")); + return PathsCollection.of(resolveRelativeToBaseDir(null, "src/test/resources")); } - return resources.stream() + return PathsCollection.from(resources.stream() .map(Resource::getDirectory) .map(resourcesDir -> resolveRelativeToBaseDir(resourcesDir, "src/test/resources")) - .collect(Collectors.toSet()); + .collect(Collectors.toCollection(LinkedHashSet::new))); } public ModelBuildingResult getModelBuildingResult() { diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalWorkspace.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalWorkspace.java index b9ddb97b814ae2..34b1e417b19040 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalWorkspace.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalWorkspace.java @@ -161,7 +161,7 @@ private Path emptyJarOutput(LocalProject lp, Artifact artifact) { // so the Maven resolver will succeed resolving it from the repo. // If the artifact does not exist in the local repo, we are creating an empty classes directory in the target directory. if (!Files.exists(lp.getSourcesSourcesDir()) - && lp.getResourcesSourcesDirs().stream().noneMatch(Files::exists) + && lp.getResourcesSourcesDirs().toList().stream().noneMatch(Files::exists) && !isFoundInLocalRepo(artifact)) { try { final Path classesDir = lp.getClassesDir(); diff --git a/test-framework/jacoco/deployment/src/main/java/io/quarkus/jacoco/deployment/JacocoProcessor.java b/test-framework/jacoco/deployment/src/main/java/io/quarkus/jacoco/deployment/JacocoProcessor.java index e040fce63c2f5e..3fd5141e0b448f 100644 --- a/test-framework/jacoco/deployment/src/main/java/io/quarkus/jacoco/deployment/JacocoProcessor.java +++ b/test-framework/jacoco/deployment/src/main/java/io/quarkus/jacoco/deployment/JacocoProcessor.java @@ -3,6 +3,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; import java.util.HashSet; @@ -130,12 +131,12 @@ public byte[] apply(String className, byte[] bytes) { QuarkusModel model = BuildToolHelper.enableGradleAppModelForDevMode(targetdir.toPath()); for (WorkspaceModule i : model.getWorkspace().getAllModules()) { info.savedData.add(new File(i.getBuildDir(), config.dataFile).getAbsolutePath()); - for (File src : i.getSourceSourceSet().getSourceDirectories()) { - sources.add(src.getAbsolutePath()); + for (Path src : i.getSourceSourceSet().getSourceDirectories()) { + sources.add(src.toAbsolutePath().toString()); } - for (File classesDir : i.getSourceSet().getSourceDirectories()) { - if (classesDir.isDirectory()) { - for (final File file : FileUtils.getFiles(classesDir, includes, excludes, + for (Path classesDir : i.getSourceSet().getSourceDirectories()) { + if (Files.isDirectory(classesDir)) { + for (final File file : FileUtils.getFiles(classesDir.toFile(), includes, excludes, true)) { if (file.getName().endsWith(".class")) { classes.add(file.getAbsolutePath()); diff --git a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusDevModeTest.java b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusDevModeTest.java index 47ce1c26d7a8d0..2a71daa94ac94e 100644 --- a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusDevModeTest.java +++ b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusDevModeTest.java @@ -46,6 +46,7 @@ import org.junit.jupiter.api.extension.TestInstantiationException; import io.quarkus.bootstrap.model.AppArtifactKey; +import io.quarkus.bootstrap.model.PathsCollection; import io.quarkus.bootstrap.util.ZipUtils; import io.quarkus.deployment.dev.CompilationProvider; import io.quarkus.deployment.dev.DevModeContext; @@ -335,11 +336,11 @@ private DevModeContext exportArchive(Path deploymentDir, Path testSourceDir, Pat .setAppArtifactKey(AppArtifactKey.fromString("io.quarkus.test:app-under-test")) .setName("default") .setProjectDirectory(deploymentDir.toAbsolutePath().toString()) - .setSourcePaths(Collections.singleton(deploymentSourcePath.toAbsolutePath().toString())) + .setSourcePaths(PathsCollection.of(deploymentSourcePath.toAbsolutePath())) .setClassesPath(classes.toAbsolutePath().toString()) - .setResourcePaths(Collections.singleton(deploymentResourcePath.toAbsolutePath().toString())) + .setResourcePaths(PathsCollection.of(deploymentResourcePath.toAbsolutePath())) .setResourcesOutputPath(classes.toAbsolutePath().toString()) - .setSourceParents(Collections.singleton(deploymentSourceParentPath.toAbsolutePath().toString())) + .setSourceParents(PathsCollection.of(deploymentSourceParentPath.toAbsolutePath())) .setPreBuildOutputDir(targetDir.resolve("generated-sources").toAbsolutePath().toString()) .setTargetDir(targetDir.toAbsolutePath().toString()); @@ -384,9 +385,9 @@ private DevModeContext exportArchive(Path deploymentDir, Path testSourceDir, Pat }); } moduleBuilder - .setTestSourcePaths(Collections.singleton(deploymentTestSourcePath.toAbsolutePath().toString())) + .setTestSourcePaths(PathsCollection.of(deploymentTestSourcePath.toAbsolutePath())) .setTestClassesPath(testClasses.toAbsolutePath().toString()) - .setTestResourcePaths(Collections.singleton(deploymentTestResourcePath.toAbsolutePath().toString())) + .setTestResourcePaths(PathsCollection.of(deploymentTestResourcePath.toAbsolutePath())) .setTestResourcesOutputPath(testClasses.toAbsolutePath().toString()); } @@ -775,7 +776,7 @@ private void copyFromSource(Path projectSourcesDir, Path deploymentSourcesDir, P private Path copySourceFilesForClass(Path projectSourcesDir, Path deploymentSourcesDir, Path classesDir, Path classFile) { for (CompilationProvider provider : compilationProviders) { Path source = provider.getSourcePath(classFile, - Collections.singleton(projectSourcesDir.toAbsolutePath().toString()), + PathsCollection.of(projectSourcesDir.toAbsolutePath()), classesDir.toAbsolutePath().toString()); if (source != null) { String relative = projectSourcesDir.relativize(source).toString(); @@ -797,7 +798,7 @@ private Path findTargetSourceFilesForPath(Path projectSourcesDir, Path deploymen Path classFile) { for (CompilationProvider provider : compilationProviders) { Path source = provider.getSourcePath(classFile, - Collections.singleton(projectSourcesDir.toAbsolutePath().toString()), + PathsCollection.of(projectSourcesDir.toAbsolutePath()), classesDir.toAbsolutePath().toString()); if (source != null) { String relative = projectSourcesDir.relativize(source).toString(); diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java index e5f535d0ec2cc2..f981b5b08fbe4f 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java @@ -184,11 +184,11 @@ static Map handleDevDb(ExtensionContext context) throws Exceptio if (System.getProperty(BootstrapConstants.SERIALIZED_TEST_APP_MODEL) == null) { QuarkusModel model = BuildToolHelper.enableGradleAppModelForTest(projectRoot); if (model != null) { - final Set classDirectories = model.getWorkspace().getMainModule().getSourceSet() + final PathsCollection classDirectories = model.getWorkspace().getMainModule().getSourceSet() .getSourceDirectories(); - for (File classes : classDirectories) { - if (classes.exists() && !rootBuilder.contains(classes.toPath())) { - rootBuilder.add(classes.toPath()); + for (Path classes : classDirectories) { + if (Files.exists(classes) && !rootBuilder.contains(classes)) { + rootBuilder.add(classes); } } } diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java index 05e355a7ec8ef1..7223699790b967 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java @@ -4,7 +4,6 @@ import static io.quarkus.test.common.PathTestHelper.getTestClassesLocation; import java.io.Closeable; -import java.io.File; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.management.ManagementFactory; @@ -276,11 +275,11 @@ private ExtensionState doJavaStart(ExtensionContext context, Class classDirectories = model.getWorkspace().getMainModule().getSourceSet() + final PathsCollection classDirectories = model.getWorkspace().getMainModule().getSourceSet() .getSourceDirectories(); - for (File classes : classDirectories) { - if (classes.exists() && !rootBuilder.contains(classes.toPath())) { - rootBuilder.add(classes.toPath()); + for (Path classes : classDirectories) { + if (Files.exists(classes) && !rootBuilder.contains(classes)) { + rootBuilder.add(classes); } } }