diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/JarResultBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/JarResultBuildStep.java index ecee871dfc177..d0ed81000e0b5 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/JarResultBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/JarResultBuildStep.java @@ -24,6 +24,7 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.EnumSet; import java.util.Enumeration; @@ -93,7 +94,7 @@ */ public class JarResultBuildStep { - private static final Set IGNORED_ENTRIES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( + private static final Collection IGNORED_ENTRIES = Arrays.asList( "META-INF/INDEX.LIST", "META-INF/MANIFEST.MF", "module-info.class", @@ -117,7 +118,7 @@ public class JarResultBuildStep { "META-INF/quarkus-extension.yaml", "META-INF/quarkus-deployment-dependency.graph", "META-INF/jandex.idx", - "LICENSE"))); + "LICENSE"); private static final Logger log = Logger.getLogger(JarResultBuildStep.class); // we shouldn't have to specify these flags when opening a ZipFS (since they are the default ones), but failure to do so diff --git a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusBuild.java b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusBuild.java index c19a90bd3f871..47318d44ce740 100644 --- a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusBuild.java +++ b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusBuild.java @@ -90,8 +90,11 @@ public void buildQuarkus() { appArtifact.setPaths(QuarkusGradleUtils.getOutputPaths(getProject())); final AppModelResolver modelResolver = extension().getAppModelResolver(); - final Properties realProperties = getBuildSystemProperties(appArtifact); - + final Properties effectiveProperties = getBuildSystemProperties(appArtifact); + if (ignoredEntries != null && ignoredEntries.size() > 0) { + String joinedEntries = String.join(",", ignoredEntries); + effectiveProperties.setProperty("quarkus.package.user-configured-ignored-entries", joinedEntries); + } boolean clear = false; if (uberJar && System.getProperty("quarkus.package.uber-jar") == null) { System.setProperty("quarkus.package.uber-jar", "true"); @@ -102,7 +105,7 @@ public void buildQuarkus() { .setAppModelResolver(modelResolver) .setTargetDirectory(getProject().getBuildDir().toPath()) .setBaseName(extension().finalName()) - .setBuildSystemProperties(realProperties) + .setBuildSystemProperties(effectiveProperties) .setAppArtifact(appArtifact) .setLocalProjectDiscovery(false) .setIsolateDeployment(true) diff --git a/devtools/maven/src/main/java/io/quarkus/maven/BuildMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/BuildMojo.java index 19b5d6ad00c1f..0ce8b9c8e8aa8 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/BuildMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/BuildMojo.java @@ -149,18 +149,23 @@ public void execute() throws MojoExecutionException { try { final Properties projectProperties = project.getProperties(); - final Properties realProperties = new Properties(); + final Properties effectiveProperties = new Properties(); + // quarkus. properties > ignoredEntries in pom.xml + if (ignoredEntries != null && ignoredEntries.length > 0) { + String joinedEntries = String.join(",", ignoredEntries); + effectiveProperties.setProperty("quarkus.package.user-configured-ignored-entries", joinedEntries); + } for (String name : projectProperties.stringPropertyNames()) { if (name.startsWith("quarkus.")) { - realProperties.setProperty(name, projectProperties.getProperty(name)); + effectiveProperties.setProperty(name, projectProperties.getProperty(name)); } } if (uberJar && System.getProperty(QUARKUS_PACKAGE_UBER_JAR) == null) { System.setProperty(QUARKUS_PACKAGE_UBER_JAR, "true"); clear = true; } - realProperties.putIfAbsent("quarkus.application.name", project.getArtifactId()); - realProperties.putIfAbsent("quarkus.application.version", project.getVersion()); + effectiveProperties.putIfAbsent("quarkus.application.name", project.getArtifactId()); + effectiveProperties.putIfAbsent("quarkus.application.version", project.getVersion()); MavenArtifactResolver resolver = MavenArtifactResolver.builder() .setWorkspaceDiscovery(false) @@ -192,7 +197,7 @@ public void execute() throws MojoExecutionException { .setAppArtifact(appArtifact) .setMavenArtifactResolver(resolver) .setBaseClassLoader(BuildMojo.class.getClassLoader()) - .setBuildSystemProperties(realProperties) + .setBuildSystemProperties(effectiveProperties) .setLocalProjectDiscovery(false) .setProjectRoot(project.getBasedir().toPath()) .setBaseName(finalName) diff --git a/integration-tests/maven/src/test/java/io/quarkus/maven/it/BuildIT.java b/integration-tests/maven/src/test/java/io/quarkus/maven/it/BuildIT.java index b219c784faf71..e78eb1d2ee60c 100644 --- a/integration-tests/maven/src/test/java/io/quarkus/maven/it/BuildIT.java +++ b/integration-tests/maven/src/test/java/io/quarkus/maven/it/BuildIT.java @@ -6,7 +6,6 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.jar.JarInputStream; @@ -55,9 +54,4 @@ private void ensureManifestOfJarIsReadableByJarInputStream(File jar) throws IOEx } } } - - private List getFilesEndingWith(File dir, String suffix) { - final File[] files = dir.listFiles((d, name) -> name.endsWith(suffix)); - return files != null ? Arrays.asList(files) : Collections.emptyList(); - } } diff --git a/integration-tests/maven/src/test/java/io/quarkus/maven/it/IgnoreEntriesIT.java b/integration-tests/maven/src/test/java/io/quarkus/maven/it/IgnoreEntriesIT.java new file mode 100644 index 0000000000000..552871a1f0217 --- /dev/null +++ b/integration-tests/maven/src/test/java/io/quarkus/maven/it/IgnoreEntriesIT.java @@ -0,0 +1,51 @@ +package io.quarkus.maven.it; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +import org.apache.maven.shared.invoker.MavenInvocationException; +import org.junit.jupiter.api.Test; + +import io.quarkus.maven.it.verifier.MavenProcessInvocationResult; +import io.quarkus.maven.it.verifier.RunningInvoker; + +@DisableForNative +public class IgnoreEntriesIT extends MojoTestBase { + + @Test + public void testIgnoreEntries() + throws MavenInvocationException, IOException, InterruptedException { + File testDir = initProject("projects/ignore-entries-uber-jar"); + + RunningInvoker running = new RunningInvoker(testDir, false); + MavenProcessInvocationResult result = running.execute(Arrays.asList("compile", "quarkus:build"), + Collections.emptyMap()); + assertThat(result.getProcess().waitFor()).isEqualTo(0); + + final File targetDir = new File(testDir, "target"); + List jars = getFilesEndingWith(targetDir, ".jar"); + assertThat(jars).hasSize(1); + assertThat(jars.get(0)).isFile(); + assertThat(jarContains(jars.get(0), "META-INF/swagger-ui-files/swagger-ui-bundle.js.map")).isFalse(); + } + + private boolean jarContains(File jar, String name) throws IOException { + try (JarFile z = new JarFile(jar)) { + for (Enumeration en = z.entries(); en.hasMoreElements();) { + String fileName = en.nextElement().getName(); + if (name.equalsIgnoreCase(fileName)) { + return true; + } + } + } + return false; + } +} diff --git a/integration-tests/maven/src/test/java/io/quarkus/maven/it/PackageIT.java b/integration-tests/maven/src/test/java/io/quarkus/maven/it/PackageIT.java index 39d0bd09cb49a..ae4935a26a8e2 100644 --- a/integration-tests/maven/src/test/java/io/quarkus/maven/it/PackageIT.java +++ b/integration-tests/maven/src/test/java/io/quarkus/maven/it/PackageIT.java @@ -194,11 +194,6 @@ public void testQuarkusIndexDependencyOnLocalModule() throws Exception { assertZipEntriesCanBeOpenedAndClosed(runnerJar); } - private List getFilesEndingWith(File dir, String suffix) { - final File[] files = dir.listFiles((d, name) -> name.endsWith(suffix)); - return files != null ? Arrays.asList(files) : Collections.emptyList(); - } - private int getNumberOfFilesEndingWith(File dir, String suffix) { return getFilesEndingWith(dir, suffix).size(); } diff --git a/integration-tests/maven/src/test/resources/projects/ignore-entries-uber-jar/pom.xml b/integration-tests/maven/src/test/resources/projects/ignore-entries-uber-jar/pom.xml new file mode 100644 index 0000000000000..248df4d59f14b --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/ignore-entries-uber-jar/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + org.acme + acme + 1.0-SNAPSHOT + + io.quarkus + quarkus-bom + @project.version@ + @project.version@ + 1.8 + UTF-8 + 1.8 + + + + + + ${quarkus.platform.group-id} + ${quarkus.platform.artifact-id} + ${quarkus.platform.version} + pom + import + + + + + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-swagger-ui + + + + + + io.quarkus + quarkus-maven-plugin + ${quarkus-plugin.version} + + true + + META-INF/swagger-ui-files/swagger-ui-bundle.js.map + META-INF/swagger-ui-files/swagger-ui-standalone-preset.js.map + + + + + + build + + + + + + + diff --git a/integration-tests/maven/src/test/resources/projects/ignore-entries-uber-jar/src/main/java/org/acme/HelloResource.java b/integration-tests/maven/src/test/resources/projects/ignore-entries-uber-jar/src/main/java/org/acme/HelloResource.java new file mode 100644 index 0000000000000..a405740d8c682 --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/ignore-entries-uber-jar/src/main/java/org/acme/HelloResource.java @@ -0,0 +1,17 @@ +package org.acme; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/hello") +public class HelloResource { + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return "hello"; + } + +} diff --git a/integration-tests/maven/src/test/resources/projects/ignore-entries-uber-jar/src/main/resources/META-INF/resources/index.html b/integration-tests/maven/src/test/resources/projects/ignore-entries-uber-jar/src/main/resources/META-INF/resources/index.html new file mode 100644 index 0000000000000..c09bb5c96b869 --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/ignore-entries-uber-jar/src/main/resources/META-INF/resources/index.html @@ -0,0 +1,156 @@ + + + + + acme - 1.0-SNAPSHOT + + + + + + +
+
+

Congratulations, you have created a new Quarkus application.

+ +

Why do you see this?

+ +

This page is served by Quarkus. The source is in + src/main/resources/META-INF/resources/index.html.

+ +

What can I do from here?

+ +

If not already done, run the application in dev mode using: mvn compile quarkus:dev. +

+
    +
  • Add REST resources, Servlets, functions and other services in src/main/java.
  • +
  • Your static assets are located in src/main/resources/META-INF/resources.
  • +
  • Configure your application in src/main/resources/application.properties. +
  • +
+ +

Do you like Quarkus?

+

Go give it a star on GitHub.

+ +

How do I get rid of this page?

+

Just delete the src/main/resources/META-INF/resources/index.html file.

+
+
+
+

Application

+
    +
  • GroupId: org.acme
  • +
  • ArtifactId: acme
  • +
  • Version: 1.0-SNAPSHOT
  • +
  • Quarkus Version: 999-SNAPSHOT
  • +
+
+
+

Next steps

+ +
+
+
+ + + + \ No newline at end of file diff --git a/integration-tests/maven/src/test/resources/projects/ignore-entries-uber-jar/src/main/resources/application.properties b/integration-tests/maven/src/test/resources/projects/ignore-entries-uber-jar/src/main/resources/application.properties new file mode 100644 index 0000000000000..8edeb37c0186e --- /dev/null +++ b/integration-tests/maven/src/test/resources/projects/ignore-entries-uber-jar/src/main/resources/application.properties @@ -0,0 +1,2 @@ +# Configuration file +quarkus.swagger-ui.always-include=true \ No newline at end of file diff --git a/test-framework/maven/src/main/java/io/quarkus/maven/it/MojoTestBase.java b/test-framework/maven/src/main/java/io/quarkus/maven/it/MojoTestBase.java index 86aee9b5ec643..dde39e2c25653 100644 --- a/test-framework/maven/src/main/java/io/quarkus/maven/it/MojoTestBase.java +++ b/test-framework/maven/src/main/java/io/quarkus/maven/it/MojoTestBase.java @@ -7,7 +7,10 @@ import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.function.Predicate; import java.util.logging.Level; @@ -131,4 +134,10 @@ public static Model loadPom(File directory) { throw new IllegalArgumentException("Cannot read the pom.xml file", e); } } + + public static List getFilesEndingWith(File dir, String suffix) { + final File[] files = dir.listFiles((d, name) -> name.endsWith(suffix)); + return files != null ? Arrays.asList(files) : Collections.emptyList(); + } + }