Skip to content

Commit

Permalink
Merge pull request #19706 from stuartwdouglas/19655
Browse files Browse the repository at this point in the history
Handle creating the src dir in dev mode
  • Loading branch information
stuartwdouglas authored Aug 27, 2021
2 parents 918ae7d + 3935094 commit 9f04255
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
13 changes: 2 additions & 11 deletions devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 9f04255

Please sign in to comment.