Skip to content

Commit

Permalink
ignoredEntries from plugins is now used
Browse files Browse the repository at this point in the history
Add Maven tests
  • Loading branch information
gastaldi committed Jul 3, 2020
1 parent d6b292d commit 38a5941
Show file tree
Hide file tree
Showing 11 changed files with 317 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,7 +94,7 @@
*/
public class JarResultBuildStep {

private static final Set<String> IGNORED_ENTRIES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
private static final Collection<String> IGNORED_ENTRIES = Arrays.asList(
"META-INF/INDEX.LIST",
"META-INF/MANIFEST.MF",
"module-info.class",
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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)
Expand Down
15 changes: 10 additions & 5 deletions devtools/maven/src/main/java/io/quarkus/maven/BuildMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,9 +54,4 @@ private void ensureManifestOfJarIsReadableByJarInputStream(File jar) throws IOEx
}
}
}

private List<File> getFilesEndingWith(File dir, String suffix) {
final File[] files = dir.listFiles((d, name) -> name.endsWith(suffix));
return files != null ? Arrays.asList(files) : Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
@@ -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<File> 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<JarEntry> en = z.entries(); en.hasMoreElements();) {
String fileName = en.nextElement().getName();
if (name.equalsIgnoreCase(fileName)) {
return true;
}
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,6 @@ public void testQuarkusIndexDependencyOnLocalModule() throws Exception {
assertZipEntriesCanBeOpenedAndClosed(runnerJar);
}

private List<File> 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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.acme</groupId>
<artifactId>acme</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.version>@project.version@</quarkus.platform.version>
<quarkus-plugin.version>@project.version@</quarkus-plugin.version>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<!-- insert managed dependencies here -->
<dependency>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- insert test dependencies here -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-swagger-ui</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus-plugin.version}</version>
<configuration>
<uberJar>true</uberJar>
<ignoredEntries>
<ignoredEntry>META-INF/swagger-ui-files/swagger-ui-bundle.js.map</ignoredEntry>
<ignoredEntry>META-INF/swagger-ui-files/swagger-ui-standalone-preset.js.map</ignoredEntry>
</ignoredEntries>
</configuration>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -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";
}

}
Loading

0 comments on commit 38a5941

Please sign in to comment.