Skip to content

Commit

Permalink
Merge pull request #13087 from aloubyansky/gradle-resources-output-de…
Browse files Browse the repository at this point in the history
…vmode

Gradle devmode: if the resources dir is empty the corresponding resources output dir won't exist
  • Loading branch information
glefloch committed Nov 3, 2020
2 parents 6c45f60 + ca60ce7 commit a7be481
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
Expand Up @@ -21,6 +21,7 @@

import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ExternalModuleDependency;
import org.gradle.api.artifacts.ModuleDependency;
Expand Down Expand Up @@ -89,7 +90,6 @@ public Object buildAll(String modelName, Project project) {
@Override
public Object buildAll(String modelName, ModelParameter parameter, Project project) {
LaunchMode mode = LaunchMode.valueOf(parameter.getMode());

final Set<org.gradle.api.artifacts.Dependency> deploymentDeps = getEnforcedPlatforms(project);
final Map<ArtifactCoords, Dependency> appDependencies = new LinkedHashMap<>();
final Set<ArtifactCoords> visitedDeps = new HashSet<>();
Expand Down Expand Up @@ -298,26 +298,27 @@ private void addDevModePaths(final DependencyImpl dep, ResolvedArtifact a, Proje
final JavaPluginConvention javaConvention = project.getConvention().findPlugin(JavaPluginConvention.class);
if (javaConvention == null) {
dep.addPath(a.getFile());
} else {
SourceSet mainSourceSet = javaConvention.getSourceSets().findByName(SourceSet.MAIN_SOURCE_SET_NAME);
if (mainSourceSet != null) {
final File classesDir = new File(QuarkusGradleUtils.getClassesDir(mainSourceSet, project.getBuildDir(), false));
if (classesDir.exists()) {
dep.addPath(classesDir);
}
for (File resourcesDir : mainSourceSet.getResources().getSourceDirectories()) {
if (resourcesDir.exists()) {
dep.addPath(resourcesDir);
}
}
for (File outputDir : project.getTasks().findByName(JavaPlugin.PROCESS_RESOURCES_TASK_NAME)
.getOutputs().getFiles()) {
if (outputDir.exists()) {
dep.addPath(outputDir);
}
}
} else {
dep.addPath(a.getFile());
return;
}
final SourceSet mainSourceSet = javaConvention.getSourceSets().findByName(SourceSet.MAIN_SOURCE_SET_NAME);
if (mainSourceSet == null) {
dep.addPath(a.getFile());
return;
}

final File classesDir = new File(QuarkusGradleUtils.getClassesDir(mainSourceSet, project.getBuildDir(), false));
if (classesDir.exists()) {
dep.addPath(classesDir);
}
for (File resourcesDir : mainSourceSet.getResources().getSourceDirectories()) {
if (resourcesDir.exists()) {
dep.addPath(resourcesDir);
}
}
final Task resourcesTask = project.getTasks().findByName(JavaPlugin.PROCESS_RESOURCES_TASK_NAME);
for (File outputDir : resourcesTask.getOutputs().getFiles()) {
if (outputDir.exists()) {
dep.addPath(outputDir);
}
}
}
Expand Down
Expand Up @@ -43,7 +43,6 @@
import io.quarkus.bootstrap.resolver.AppModelResolverException;
import io.quarkus.deployment.dev.DevModeContext;
import io.quarkus.deployment.dev.QuarkusDevModeLauncher;
import io.quarkus.gradle.QuarkusPluginExtension;
import io.quarkus.runtime.LaunchMode;

public class QuarkusDev extends QuarkusTask {
Expand Down Expand Up @@ -167,9 +166,6 @@ public void setCompilerArgs(List<String> compilerArgs) {

@TaskAction
public void startDev() {
Project project = getProject();
QuarkusPluginExtension extension = (QuarkusPluginExtension) project.getExtensions().findByName("quarkus");

if (!getSourceDir().isDirectory()) {
throw new GradleException("The `src/main/java` directory is required, please create it.");
}
Expand All @@ -182,7 +178,7 @@ public void startDev() {

try {
QuarkusDevModeLauncher runner = newLauncher();
project.exec(action -> {
getProject().exec(action -> {
action.commandLine(runner.args()).workingDir(getWorkingDir());
action.setStandardInput(System.in)
.setErrorOutput(System.out)
Expand Down Expand Up @@ -330,16 +326,18 @@ private void addLocalProject(Project project, GradleDevModeLauncher.Builder buil
}
//TODO: multiple resource directories
final File resourcesSrcDir = mainSourceSet.getResources().getSourceDirectories().getSingleFile();
// resourcesSrcDir may exist but if it's empty the resources output dir won't be created
final File resourcesOutputDir = mainSourceSet.getOutput().getResourcesDir();

if (sourcePaths.isEmpty() && !resourcesSrcDir.exists()) {
if (sourcePaths.isEmpty() && !resourcesOutputDir.exists()) {
return;
}

String classesDir = QuarkusGradleUtils.getClassesDir(mainSourceSet, project.getBuildDir());

final String resourcesOutputPath;
if (resourcesSrcDir.exists()) {
resourcesOutputPath = mainSourceSet.getOutput().getResourcesDir().getAbsolutePath();
if (resourcesOutputDir.exists()) {
resourcesOutputPath = resourcesOutputDir.getAbsolutePath();
if (!Files.exists(Paths.get(classesDir))) {
// currently classesDir can't be null and is expected to exist
classesDir = resourcesOutputPath;
Expand Down

0 comments on commit a7be481

Please sign in to comment.