Skip to content

Commit 1fcb9ce

Browse files
authored
Merge pull request #10130 from famod/issue-9721-devmode-resource-config
Dev-mode: respect configuration when running resources:resource
2 parents ae55a55 + 3c4603a commit 1fcb9ce

File tree

3 files changed

+46
-12
lines changed
  • devtools/maven/src/main/java/io/quarkus/maven
  • integration-tests/maven/src/test

3 files changed

+46
-12
lines changed

devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ private void handleResources() throws MojoExecutionException {
416416
MojoExecutor.version(resourcesPlugin.getVersion()),
417417
resourcesPlugin.getDependencies()),
418418
MojoExecutor.goal("resources"),
419-
MojoExecutor.configuration(),
419+
getPluginConfig(resourcesPlugin),
420420
MojoExecutor.executionEnvironment(
421421
project,
422422
session,
@@ -425,30 +425,34 @@ private void handleResources() throws MojoExecutionException {
425425
}
426426

427427
private void executeCompileGoal(Plugin plugin, String groupId, String artifactId) throws MojoExecutionException {
428-
Xpp3Dom configuration = MojoExecutor.configuration();
429-
Xpp3Dom pluginConfiguration = (Xpp3Dom) plugin.getConfiguration();
430-
if (pluginConfiguration != null) {
431-
//Filter out `test*` configurations
432-
for (Xpp3Dom child : pluginConfiguration.getChildren()) {
433-
if (!child.getName().startsWith("test")) {
434-
configuration.addChild(child);
435-
}
436-
}
437-
}
438428
MojoExecutor.executeMojo(
439429
MojoExecutor.plugin(
440430
MojoExecutor.groupId(groupId),
441431
MojoExecutor.artifactId(artifactId),
442432
MojoExecutor.version(plugin.getVersion()),
443433
plugin.getDependencies()),
444434
MojoExecutor.goal("compile"),
445-
configuration,
435+
getPluginConfig(plugin),
446436
MojoExecutor.executionEnvironment(
447437
project,
448438
session,
449439
pluginManager));
450440
}
451441

442+
private Xpp3Dom getPluginConfig(Plugin plugin) {
443+
Xpp3Dom configuration = MojoExecutor.configuration();
444+
Xpp3Dom pluginConfiguration = (Xpp3Dom) plugin.getConfiguration();
445+
if (pluginConfiguration != null) {
446+
//Filter out `test*` configurations
447+
for (Xpp3Dom child : pluginConfiguration.getChildren()) {
448+
if (!child.getName().startsWith("test")) {
449+
configuration.addChild(child);
450+
}
451+
}
452+
}
453+
return configuration;
454+
}
455+
452456
private Map<Path, Long> readPomFileTimestamps(DevModeRunner runner) throws IOException {
453457
Map<Path, Long> ret = new HashMap<>();
454458
for (Path i : runner.getPomFiles()) {

integration-tests/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static org.junit.Assert.assertEquals;
77

88
import java.io.File;
9+
import java.io.FileOutputStream;
910
import java.io.IOException;
1011
import java.nio.charset.Charset;
1112
import java.util.Arrays;
@@ -15,6 +16,9 @@
1516
import java.util.concurrent.TimeUnit;
1617
import java.util.concurrent.atomic.AtomicReference;
1718
import java.util.stream.IntStream;
19+
import java.util.zip.ZipEntry;
20+
import java.util.zip.ZipFile;
21+
import java.util.zip.ZipOutputStream;
1822

1923
import org.apache.commons.io.FileUtils;
2024
import org.apache.maven.shared.invoker.MavenInvocationException;
@@ -74,12 +78,29 @@ public void testThatResteasyWithoutUndertowCanRun() throws MavenInvocationExcept
7478
@Test
7579
public void testThatInitialMavenResourceFilteringWorks() throws MavenInvocationException, IOException {
7680
testDir = initProject("projects/classic-resource-filtering", "projects/project-classic-resource-filtering");
81+
82+
//also test that a zipfile must not be filtered because of nonFilteredFileExtensions configuration
83+
//as initProject() would already corrupt the zipfile, it has to be created _after_ initProject()
84+
try (ZipOutputStream zipOut = new ZipOutputStream(
85+
new FileOutputStream(new File(testDir, "src/main/resources/test.zip")))) {
86+
ZipEntry zipEntry = new ZipEntry("test.txt");
87+
zipOut.putNextEntry(zipEntry);
88+
zipOut.write("test".getBytes());
89+
}
90+
7791
run(false);
7892

7993
//make sure that a simple HTTP GET request always works
8094
IntStream.range(0, 10).forEach(i -> {
8195
assertThat(DevModeTestUtils.getStrictHttpResponse("/hello", 200)).isTrue();
8296
});
97+
98+
//try to open the copied test.zip (which will fail if it was filtered)
99+
File copiedTestZipFile = new File(testDir, "target/classes/test.zip");
100+
assertThat(copiedTestZipFile).exists();
101+
try (ZipFile zipFile = new ZipFile(copiedTestZipFile)) {
102+
//everything is fine once we get here (ZipFile is still readable)
103+
}
83104
}
84105

85106
@Test

integration-tests/maven/src/test/resources/projects/classic-resource-filtering/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@
5050
</resource>
5151
</resources>
5252
<plugins>
53+
<plugin>
54+
<artifactId>maven-resources-plugin</artifactId>
55+
<version>3.1.0</version>
56+
<configuration>
57+
<nonFilteredFileExtensions>
58+
<nonFilteredFileExtension>zip</nonFilteredFileExtension>
59+
</nonFilteredFileExtensions>
60+
</configuration>
61+
</plugin>
5362
<plugin>
5463
<groupId>io.quarkus</groupId>
5564
<artifactId>quarkus-maven-plugin</artifactId>

0 commit comments

Comments
 (0)