Skip to content

Commit

Permalink
Gradle - Correctly merge classes dir when using dev mode
Browse files Browse the repository at this point in the history
We were returning an empty dir before which would trigger the use of the
resources dir instead.

Also simplify the logic as it was quite hard to follow and it's actually
quite simple.

Fixes #42860
  • Loading branch information
gsmet committed Aug 30, 2024
1 parent 458c705 commit 6394622
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ private void addLocalProject(ResolvedDependency project, GradleDevModeLauncher.B
}
}
Path classesDir = classesDirs.isEmpty() ? null
: QuarkusGradleUtils.mergeClassesDirs(classesDirs, project.getWorkspaceModule().getBuildDir(), root, false);
: QuarkusGradleUtils.mergeClassesDirs(classesDirs, project.getWorkspaceModule().getBuildDir(), true, false);
Path generatedSourcesPath = sources.getSourceDirs().isEmpty() ? null
: sources.getSourceDirs().iterator().next().getAptSourcesDir();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.nio.file.Path;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.gradle.api.Project;
Expand Down Expand Up @@ -46,44 +46,35 @@ public static String getClassesDir(SourceSet sourceSet, File tmpDir, boolean pop
}

public static Path mergeClassesDirs(Collection<Path> classesDirs, File tmpDir, boolean populated, boolean test) {
Path classesDir = null;
final Iterator<Path> i = classesDirs.iterator();
int dirCount = 0;
while (i.hasNext()) {
final Path next = i.next();
if (!Files.exists(next)) {
continue;
List<Path> existingClassesDirs = classesDirs.stream().filter(p -> Files.exists(p)).toList();

if (existingClassesDirs.size() == 0) {
return null;
}

if (existingClassesDirs.size() == 1) {
return existingClassesDirs.get(0);
}

try {
Path mergedClassesDir = tmpDir.toPath().resolve("quarkus-app-classes" + (test ? "-test" : ""));

if (!populated) {
return mergedClassesDir;
}
try {
switch (dirCount++) {
case 0:
classesDir = next;
break;
case 1:
//there does not seem to be any sane way of dealing with multiple output dirs, as there does not seem
//to be a way to map them. We will need to address this at some point, but for now we just stick them
//all in a temp dir
final Path tmpClassesDir = tmpDir.toPath().resolve("quarkus-app-classes" + (test ? "-test" : ""));
if (!populated) {
return tmpClassesDir;
}
if (Files.exists(tmpClassesDir)) {
IoUtils.recursiveDelete(tmpClassesDir);
}
IoUtils.copy(classesDir, tmpClassesDir);
classesDir = tmpClassesDir;
default:
IoUtils.copy(next, classesDir);

}
} catch (IOException e) {
throw new UncheckedIOException(ERROR_COLLECTING_PROJECT_CLASSES, e);

if (Files.exists(mergedClassesDir)) {
IoUtils.recursiveDelete(mergedClassesDir);
}

for (Path classesDir : existingClassesDirs) {
IoUtils.copy(classesDir, mergedClassesDir);
}

return mergedClassesDir;
} catch (IOException e) {
throw new UncheckedIOException(ERROR_COLLECTING_PROJECT_CLASSES, e);
}
if (classesDir == null) {
return null;
}
return classesDir;
}

}

0 comments on commit 6394622

Please sign in to comment.