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 abeab532960d6..c015ef36958b4 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java @@ -653,22 +653,13 @@ private void addProject(MavenDevModeLauncher.Builder builder, LocalProject local if (mavenProject == null) { projectDirectory = localProject.getDir().toAbsolutePath().toString(); Path sourcePath = localProject.getSourcesSourcesDir().toAbsolutePath(); - if (Files.isDirectory(sourcePath)) { - sourcePaths = Collections.singleton(sourcePath); - } else { - sourcePaths = Collections.emptySet(); - } + sourcePaths = Collections.singleton(sourcePath); Path testSourcePath = localProject.getTestSourcesSourcesDir().toAbsolutePath(); - if (Files.isDirectory(testSourcePath)) { - testSourcePaths = Collections.singleton(testSourcePath); - } else { - testSourcePaths = Collections.emptySet(); - } + testSourcePaths = Collections.singleton(testSourcePath); } else { projectDirectory = mavenProject.getBasedir().getPath(); sourcePaths = mavenProject.getCompileSourceRoots().stream() .map(Paths::get) - .filter(Files::isDirectory) .map(Path::toAbsolutePath) .collect(Collectors.toCollection(LinkedHashSet::new)); testSourcePaths = mavenProject.getTestCompileSourceRoots().stream() diff --git a/integration-tests/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java b/integration-tests/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java index 475a22423adb3..22e5190d88f32 100644 --- a/integration-tests/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java +++ b/integration-tests/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java @@ -275,6 +275,37 @@ public void testThatTheApplicationIsReloadedOnJavaChange() throws MavenInvocatio .atMost(1, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello").contains("carambar")); } + @Test + public void testThatNonExistentSrcDirCanBeAdded() throws MavenInvocationException, IOException { + testDir = initProject("projects/classic", "projects/project-classic-run-java-change"); + + File sourceDir = new File(testDir, "src/main/java"); + File sourceDirMoved = new File(testDir, "src/main/java-moved"); + if (!sourceDir.renameTo(sourceDirMoved)) { + Assertions.fail("move failed"); + } + //we need this to make run and check work + File hello = new File(testDir, "src/main/resources/META-INF/resources/app/hello"); + hello.getParentFile().mkdir(); + try (var o = new FileOutputStream(hello)) { + o.write("hello".getBytes(StandardCharsets.UTF_8)); + } + + runAndCheck(); + hello.delete(); + if (!DevModeTestUtils.getHttpResponse("/app/hello", 404)) { + Assertions.fail("expected resource to be deleted"); + } + if (!sourceDirMoved.renameTo(sourceDir)) { + Assertions.fail("move failed"); + } + + // Wait until we get "hello" + await() + .pollDelay(100, TimeUnit.MILLISECONDS) + .atMost(1, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello").contains("hello")); + } + @Test public void testThatInstrumentationBasedReloadWorks() throws MavenInvocationException, IOException { testDir = initProject("projects/classic-inst", "projects/project-intrumentation-reload");