Skip to content

Commit

Permalink
Merge pull request #42913 from gsmet/gradle-classes-dir
Browse files Browse the repository at this point in the history
Gradle - Correctly merge classes dir when using dev mode
  • Loading branch information
gsmet authored Aug 31, 2024
2 parents 7b0575a + 6394622 commit 2642c0b
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 2642c0b

Please sign in to comment.