From 3791f386844aa4af6636acf6371a3dca999b5fbc Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 1 Feb 2022 13:58:41 -0600 Subject: [PATCH] Issue #6017 - fix accidentally broken k+=v property usage (#7510) Signed-off-by: Joakim Erdfelt --- .../java/org/eclipse/jetty/start/Module.java | 6 +-- .../tests/distribution/DemoModulesTests.java | 46 ++++++++++++++++++- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java index 0425e6314e9..48802ef4cba 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java @@ -417,14 +417,14 @@ public class Module implements Comparable case "DEFAULTS": // old name introduced in 9.2.x case "INI": // new name for 9.3+ { - // All default properties are to be treated as `?=` by the configuration system - // even if they are present as `=` + // If a property is specified as `=` it is to be treated as `?=`. + // All other property usages are left as-is (eg: `+=`) int idx = line.indexOf('='); if (idx > 0) { String key = line.substring(0, idx); String value = line.substring(idx + 1); - if (key.endsWith("?")) + if (key.endsWith("?") || key.endsWith("+")) { // already the correct way _defaultConfig.add(line); diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DemoModulesTests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DemoModulesTests.java index 55f35976e5d..09c977c42bb 100644 --- a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DemoModulesTests.java +++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DemoModulesTests.java @@ -15,8 +15,8 @@ package org.eclipse.jetty.tests.distribution; import java.net.URI; import java.nio.file.Path; +import java.util.NoSuchElementException; import java.util.concurrent.TimeUnit; -import java.util.function.Supplier; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.util.FormRequestContent; @@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -34,6 +35,49 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class DemoModulesTests extends AbstractJettyHomeTest { + @Test + public void testDemoAddServerClasses() throws Exception + { + Path jettyBase = newTestJettyBaseDirectory(); + String jettyVersion = System.getProperty("jettyVersion"); + JettyHomeTester distribution = JettyHomeTester.Builder.newInstance() + .jettyVersion(jettyVersion) + .jettyBase(jettyBase) + .mavenLocalRepository(System.getProperty("mavenRepoPath")) + .build(); + + int httpPort = distribution.freePort(); + int httpsPort = distribution.freePort(); + assertThat("httpPort != httpsPort", httpPort, is(not(httpsPort))); + + String[] argsConfig = { + "--add-modules=demo" + }; + + try (JettyHomeTester.Run runConfig = distribution.start(argsConfig)) + { + assertTrue(runConfig.awaitFor(5, TimeUnit.SECONDS)); + assertEquals(0, runConfig.getExitValue()); + + try (JettyHomeTester.Run runListConfig = distribution.start("--list-config")) + { + assertTrue(runListConfig.awaitFor(5, TimeUnit.SECONDS)); + assertEquals(0, runListConfig.getExitValue()); + // Example of what we expect + // jetty.webapp.addServerClasses = org.eclipse.jetty.logging.,${jetty.home.uri}/lib/logging/,org.slf4j.,${jetty.base.uri}/lib/bouncycastle/ + String addServerKey = " jetty.webapp.addServerClasses = "; + String addServerClasses = runListConfig.getLogs().stream() + .filter(s -> s.startsWith(addServerKey)) + .findFirst() + .orElseThrow(() -> + new NoSuchElementException("Unable to find [" + addServerKey + "]")); + assertThat("'jetty.webapp.addServerClasses' entry count", + addServerClasses.split(",").length, + greaterThan(1)); + } + } + } + @Test public void testJspDump() throws Exception {