From 0f30b74a944cf956e2ca3f391a6c269197dd7535 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 9 Apr 2024 16:45:50 -0500 Subject: [PATCH 01/15] Issue #11026 - fix jetty.sh restart flaw --- jetty-home/src/main/resources/bin/jetty.sh | 2 +- .../jettysh/JettyShStartTest.java | 106 ++++++++++++++++++ 2 files changed, 107 insertions(+), 1 deletion(-) diff --git a/jetty-home/src/main/resources/bin/jetty.sh b/jetty-home/src/main/resources/bin/jetty.sh index 005e542c145..738bb861184 100755 --- a/jetty-home/src/main/resources/bin/jetty.sh +++ b/jetty-home/src/main/resources/bin/jetty.sh @@ -712,7 +712,7 @@ case "$ACTION" in restart) JETTY_SH=$0 - > "$JETTY_STATE" + echo "restart" >> "$JETTY_STATE" if [ ! -f $JETTY_SH ]; then if [ ! -f $JETTY_HOME/bin/jetty.sh ]; then echo "$JETTY_HOME/bin/jetty.sh does not exist." diff --git a/tests/test-distribution/test-distribution-common/src/test/java/org/eclipse/jetty/tests/distribution/jettysh/JettyShStartTest.java b/tests/test-distribution/test-distribution-common/src/test/java/org/eclipse/jetty/tests/distribution/jettysh/JettyShStartTest.java index 0b86810eb7d..35cecca6107 100644 --- a/tests/test-distribution/test-distribution-common/src/test/java/org/eclipse/jetty/tests/distribution/jettysh/JettyShStartTest.java +++ b/tests/test-distribution/test-distribution-common/src/test/java/org/eclipse/jetty/tests/distribution/jettysh/JettyShStartTest.java @@ -191,6 +191,112 @@ public class JettyShStartTest extends AbstractJettyHomeTest } } + @ParameterizedTest + @MethodSource("jettyImages") + public void testStartRestartStopJettyBase(ImageFromDSL jettyImage) throws Exception + { + ensureParentImagesExist(jettyImage); + + try (GenericContainer genericContainer = new GenericContainer<>(jettyImage)) + { + genericContainer.withImagePullPolicy(PullPolicy.defaultPolicy()); + genericContainer.setWaitStrategy(new ShellStrategy().withCommand("id")); + + genericContainer.withExposedPorts(80, 8080) // jetty + .withCommand("/bin/sh", "-c", "while true; do pwd | nc -l -p 80; done") + .withStartupAttempts(2) + .withStartupCheckStrategy(new IsRunningStartupCheckStrategy()) + .start(); + + LOG.info("Started: " + jettyImage.getDockerImageName()); + + System.err.println("== jetty.sh start =="); + Container.ExecResult result = genericContainer.execInContainer("/var/test/jetty-home/bin/jetty.sh", "start"); + assertThat(result.getExitCode(), is(0)); + /* + * Example successful output + * ---- + * STDOUT: + * Starting Jetty: . started + * OK Wed Oct 18 19:29:35 UTC 2023 + * ---- + */ + Awaitility.await().atMost(Duration.ofSeconds(5)).until(result::getStdout, + allOf( + containsString("Starting Jetty:"), + containsString("\nOK ") + )); + + startHttpClient(); + + URI containerUriRoot = URI.create("http://" + genericContainer.getHost() + ":" + genericContainer.getMappedPort(8080) + "/"); + LOG.debug("Container URI Root: {}", containerUriRoot); + + System.err.println("== Attempt GET request to service =="); + ContentResponse response = client.GET(containerUriRoot); + assertEquals(HttpStatus.NOT_FOUND_404, response.getStatus(), new ResponseDetails(response)); + assertThat(response.getContentAsString(), containsString("Powered by Eclipse Jetty:// Server")); + + System.err.println("== jetty.sh status (should be running) =="); + result = genericContainer.execInContainer("/var/test/jetty-home/bin/jetty.sh", "status"); + assertThat(result.getExitCode(), is(0)); + Awaitility.await().atMost(Duration.ofSeconds(5)).until(result::getStdout, + containsString("Jetty running pid")); + + System.err.println("== jetty.sh restart =="); + result = genericContainer.execInContainer("/var/test/jetty-home/bin/jetty.sh", "restart"); + assertThat(result.getExitCode(), is(0)); + Awaitility.await().atMost(Duration.ofSeconds(5)).until(result::getStdout, + allOf( + containsString("Starting Jetty:"), + containsString("\nOK ") + )); + + System.err.println("== Attempt GET request to service =="); + response = client.GET(containerUriRoot); + assertEquals(HttpStatus.NOT_FOUND_404, response.getStatus(), new ResponseDetails(response)); + assertThat(response.getContentAsString(), containsString("Powered by Eclipse Jetty:// Server")); + + System.err.println("== jetty.sh status (should be running) =="); + result = genericContainer.execInContainer("/var/test/jetty-home/bin/jetty.sh", "status"); + assertThat(result.getExitCode(), is(0)); + Awaitility.await().atMost(Duration.ofSeconds(5)).until(result::getStdout, + containsString("Jetty running pid")); + + System.err.println("== jetty.sh stop =="); + result = genericContainer.execInContainer("/var/test/jetty-home/bin/jetty.sh", "stop"); + assertThat(result.getExitCode(), is(0)); + /* Looking for output from jetty.sh indicating a stopped jetty. + * STDOUT Example 1 + * ---- + * Stopping Jetty: OK\n + * ---- + * STOUT Example 2 + * ---- + * Stopping Jetty: .Killed 12345\n + * OK\n + * ---- + */ + Awaitility.await().atMost(Duration.ofSeconds(5)).until(result::getStdout, + matchesRegex("Stopping Jetty: .*[\n]?OK[\n]")); + + System.err.println("== jetty.sh status (should be stopped) =="); + result = genericContainer.execInContainer("/var/test/jetty-home/bin/jetty.sh", "status"); + assertThat(result.getExitCode(), is(1)); + Awaitility.await().atMost(Duration.ofSeconds(5)).until(result::getStdout, + containsString("Jetty NOT running")); + + System.err.println("== Attempt GET request to non-existent service =="); + client.setConnectTimeout(1000); + Exception failedGetException = assertThrows(Exception.class, () -> client.GET(containerUriRoot)); + // GET failure can result in either exception below (which one is based on timing / race) + assertThat(failedGetException, anyOf( + instanceOf(ExecutionException.class), + instanceOf(AsynchronousCloseException.class)) + ); + } + } + private void ensureParentImagesExist(ImageFromDSL jettyImage) { // The build stack for images From bb633b8a0fffa5d4ce4abec88f6150587ae0035d Mon Sep 17 00:00:00 2001 From: Ludovic Orban Date: Wed, 24 Apr 2024 01:13:01 +0200 Subject: [PATCH 02/15] Fix `HttpFields.Mutable.Wrapper.computeField()` (#11688) * #11687 make HttpFields.Mutable.Wrapper.computeField() call onRemoveField() and remove the field when null is returned by computeFn * #11687 replace IAE with NPE * #11687 replace collect(Collectors.toList()) with toList() --------- Signed-off-by: Ludovic Orban --- .../org/eclipse/jetty/http/HttpFields.java | 41 ++++++++++---- .../eclipse/jetty/http/HttpFieldsTest.java | 54 ++++++++++++++++++- .../jetty/http/HttpGeneratorClientTest.java | 4 +- .../servlet/ServletContextHandlerTest.java | 27 ++++++++++ 4 files changed, 114 insertions(+), 12 deletions(-) diff --git a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java index 977580318e6..a38b1c90512 100644 --- a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java +++ b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java @@ -896,8 +896,8 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable add(String name, String value) { - if (value == null) - throw new IllegalArgumentException("null value"); + Objects.requireNonNull(name); + Objects.requireNonNull(value); return add(new HttpField(name, value)); } @@ -912,6 +912,7 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable add(String name, long value) { + Objects.requireNonNull(name); return add(new HttpField.LongValueHttpField(name, value)); } @@ -926,6 +927,8 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable add(HttpHeader header, HttpHeaderValue value) { + Objects.requireNonNull(header); + Objects.requireNonNull(value); return add(header, value.toString()); } @@ -940,8 +943,8 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable add(HttpHeader header, String value) { - if (value == null) - throw new IllegalArgumentException("null value"); + Objects.requireNonNull(header); + Objects.requireNonNull(value); return add(new HttpField(header, value)); } @@ -956,6 +959,7 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable add(HttpHeader header, long value) { + Objects.requireNonNull(header); return add(new HttpField.LongValueHttpField(header, value)); } @@ -967,6 +971,7 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable add(HttpField field) { + Objects.requireNonNull(field); ListIterator i = listIterator(size()); i.add(field); return this; @@ -998,8 +1003,7 @@ public interface HttpFields extends Iterable, Supplier default Mutable add(String name, List list) { Objects.requireNonNull(name); - if (list == null) - throw new IllegalArgumentException("null list"); + Objects.requireNonNull(list); if (list.isEmpty()) return this; if (list.size() == 1) @@ -1022,6 +1026,7 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable addCSV(HttpHeader header, String... values) { + Objects.requireNonNull(header); QuotedCSV existing = null; for (HttpField f : this) { @@ -1049,6 +1054,7 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable addCSV(String name, String... values) { + Objects.requireNonNull(name); QuotedCSV existing = null; for (HttpField f : this) { @@ -1076,6 +1082,7 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable addDateField(String name, long date) { + Objects.requireNonNull(name); add(name, DateGenerator.formatDate(date)); return this; } @@ -1105,6 +1112,7 @@ public interface HttpFields extends Iterable, Supplier */ default void ensureField(HttpField field) { + Objects.requireNonNull(field); HttpHeader header = field.getHeader(); // Is the field value multi valued? if (field.getValue().indexOf(',') < 0) @@ -1136,6 +1144,7 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable put(HttpField field) { + Objects.requireNonNull(field); boolean put = false; ListIterator i = listIterator(); while (i.hasNext()) @@ -1170,6 +1179,7 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable put(String name, String value) { + Objects.requireNonNull(name); if (value == null) return remove(name); return put(new HttpField(name, value)); @@ -1186,6 +1196,7 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable put(HttpHeader header, HttpHeaderValue value) { + Objects.requireNonNull(header); if (value == null) return remove(header); return put(new HttpField(header, value.toString())); @@ -1202,6 +1213,7 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable put(HttpHeader header, String value) { + Objects.requireNonNull(header); if (value == null) return remove(header); return put(new HttpField(header, value)); @@ -1241,6 +1253,7 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable putDate(HttpHeader name, long date) { + Objects.requireNonNull(name); return put(name, DateGenerator.formatDate(date)); } @@ -1256,6 +1269,7 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable putDate(String name, long date) { + Objects.requireNonNull(name); return put(name, DateGenerator.formatDate(date)); } @@ -1269,6 +1283,7 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable put(HttpHeader header, long value) { + Objects.requireNonNull(header); if (value == 0 && header == HttpHeader.CONTENT_LENGTH) return put(HttpFields.CONTENT_LENGTH_0); return put(new HttpField.LongValueHttpField(header, value)); @@ -1284,6 +1299,7 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable put(String name, long value) { + Objects.requireNonNull(name); if (value == 0 && HttpHeader.CONTENT_LENGTH.is(name)) return put(HttpFields.CONTENT_LENGTH_0); return put(new HttpField.LongValueHttpField(name, value)); @@ -1367,7 +1383,9 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable computeField(HttpHeader header, BiFunction, HttpField> computeFn) { - return put(computeFn.apply(header, stream().filter(f -> f.getHeader() == header).collect(Collectors.toList()))); + Objects.requireNonNull(header); + HttpField result = computeFn.apply(header, stream().filter(f -> f.getHeader() == header).toList()); + return result != null ? put(result) : remove(header); } /** @@ -1380,7 +1398,9 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable computeField(String name, BiFunction, HttpField> computeFn) { - return put(computeFn.apply(name, stream().filter(f -> f.is(name)).collect(Collectors.toList()))); + Objects.requireNonNull(name); + HttpField result = computeFn.apply(name, stream().filter(f -> f.is(name)).toList()); + return result != null ? put(result) : remove(name); } /** @@ -1391,6 +1411,7 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable remove(HttpHeader header) { + Objects.requireNonNull(header); Iterator i = iterator(); while (i.hasNext()) { @@ -1428,6 +1449,7 @@ public interface HttpFields extends Iterable, Supplier */ default Mutable remove(String name) { + Objects.requireNonNull(name); for (ListIterator i = listIterator(); i.hasNext(); ) { HttpField f = i.next(); @@ -1656,6 +1678,7 @@ public interface HttpFields extends Iterable, Supplier @Override public Mutable put(HttpField field) { + Objects.requireNonNull(field); // rewrite put to ensure that removes are called before replace int put = -1; ListIterator i = _fields.listIterator(); @@ -1675,7 +1698,7 @@ public interface HttpFields extends Iterable, Supplier { field = onAddField(field); if (field != null) - add(field); + _fields.add(field); } else { diff --git a/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java b/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java index 50f6abf6b76..a41983543be 100644 --- a/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java +++ b/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java @@ -1004,7 +1004,7 @@ public class HttpFieldsTest public void testAddNullValueList() { HttpFields.Mutable fields = HttpFields.build(); - assertThrows(IllegalArgumentException.class, () -> fields.add("name", (List)null)); + assertThrows(NullPointerException.class, () -> fields.add("name", (List)null)); assertThat(fields.size(), is(0)); List list = new ArrayList<>(); fields.add("name", list); @@ -1374,4 +1374,56 @@ public class HttpFieldsTest fields.ensureField(new HttpField("Test", "three, four")); assertThat(fields.stream().map(HttpField::toString).collect(Collectors.toList()), contains("Test: one, two, three, four")); } + + @Test + public void testWrapperComputeFieldCallingOnField() + { + var wrapper = new HttpFields.Mutable.Wrapper(HttpFields.build()) + { + final List actions = new ArrayList<>(); + + @Override + public HttpField onAddField(HttpField field) + { + actions.add("onAddField"); + return super.onAddField(field); + } + + @Override + public boolean onRemoveField(HttpField field) + { + actions.add("onRemoveField"); + return super.onRemoveField(field); + } + + @Override + public HttpField onReplaceField(HttpField oldField, HttpField newField) + { + actions.add("onReplaceField"); + return super.onReplaceField(oldField, newField); + } + }; + + wrapper.computeField("non-existent", (name, httpFields) -> null); + assertThat(wrapper.size(), is(0)); + assertThat(wrapper.actions, is(List.of())); + + wrapper.computeField("non-existent", (name, httpFields) -> new HttpField("non-existent", "a")); + wrapper.computeField("non-existent", (name, httpFields) -> new HttpField("non-existent", "b")); + wrapper.computeField("non-existent", (name, httpFields) -> null); + assertThat(wrapper.size(), is(0)); + assertThat(wrapper.actions, is(List.of("onAddField", "onReplaceField", "onRemoveField"))); + wrapper.actions.clear(); + + wrapper.computeField(HttpHeader.VARY, (name, httpFields) -> null); + assertThat(wrapper.size(), is(0)); + assertThat(wrapper.actions, is(List.of())); + + wrapper.computeField(HttpHeader.VARY, (name, httpFields) -> new HttpField(HttpHeader.VARY, "a")); + wrapper.computeField(HttpHeader.VARY, (name, httpFields) -> new HttpField(HttpHeader.VARY, "b")); + wrapper.computeField(HttpHeader.VARY, (name, httpFields) -> null); + assertThat(wrapper.size(), is(0)); + assertThat(wrapper.actions, is(List.of("onAddField", "onReplaceField", "onRemoveField"))); + wrapper.actions.clear(); + } } diff --git a/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorClientTest.java b/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorClientTest.java index 8bb2903cf9e..b0fc2a5dd62 100644 --- a/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorClientTest.java +++ b/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorClientTest.java @@ -99,8 +99,8 @@ public class HttpGeneratorClientTest HttpFields.Mutable fields = HttpFields.build(); fields.add("Host", "something"); - assertThrows(IllegalArgumentException.class, () -> fields.add("Null", (String)null)); - assertThrows(IllegalArgumentException.class, () -> fields.add("Null", (List)null)); + assertThrows(NullPointerException.class, () -> fields.add("Null", (String)null)); + assertThrows(NullPointerException.class, () -> fields.add("Null", (List)null)); fields.add("Empty", ""); RequestInfo info = new RequestInfo("GET", "/index.html", fields); assertFalse(gen.isChunking()); diff --git a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/ServletContextHandlerTest.java b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/ServletContextHandlerTest.java index b29f7bb0b2e..83a96c69fba 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/ServletContextHandlerTest.java +++ b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/ServletContextHandlerTest.java @@ -79,6 +79,7 @@ import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.LocalConnector; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Response; +import org.eclipse.jetty.server.ResponseUtils; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ContextHandlerCollection; @@ -103,6 +104,7 @@ import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.sameInstance; @@ -692,6 +694,31 @@ public class ServletContextHandlerTest _server.join(); } + @Test + public void testEnsureNotPersistent() throws Exception + { + ServletContextHandler root = new ServletContextHandler("/", ServletContextHandler.SESSIONS); + root.setContextPath("/"); + root.addServlet(new ServletHolder(new HttpServlet() + { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + { + Request request = ((ServletApiRequest)req).getRequest(); + Response response = ((ServletApiResponse)resp).getResponse(); + + ResponseUtils.ensureNotPersistent(request, response); + } + }), "/ensureNotPersistent"); + _server.setHandler(root); + + _server.start(); + + String rawResponse = _connector.getResponse("GET /ensureNotPersistent HTTP/1.0\r\n\r\n"); + HttpTester.Response response = HttpTester.parseResponse(rawResponse); + assertThat(response.getStatus(), is(200)); + } + @Test public void testInitParams() throws Exception { From 1f4d19c841524b551ced7955ca4c67cf82020ce2 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 23 Apr 2024 20:31:32 -0500 Subject: [PATCH 03/15] Tweaking DisableUrlCacheTest to identify flaky nature of testcase. (#11670) * Tweaking DisableUrlCacheTest to identify flaky nature of testcase. * More logging details (in case failure happens) * Repeat til failure --- .../distribution/DisableUrlCacheTest.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/test-distribution/test-ee10-distribution/src/test/java/org/eclipse/jetty/ee10/tests/distribution/DisableUrlCacheTest.java b/tests/test-distribution/test-ee10-distribution/src/test/java/org/eclipse/jetty/ee10/tests/distribution/DisableUrlCacheTest.java index fbc353bd521..b109d9abaa1 100644 --- a/tests/test-distribution/test-ee10-distribution/src/test/java/org/eclipse/jetty/ee10/tests/distribution/DisableUrlCacheTest.java +++ b/tests/test-distribution/test-ee10-distribution/src/test/java/org/eclipse/jetty/ee10/tests/distribution/DisableUrlCacheTest.java @@ -26,8 +26,10 @@ import org.eclipse.jetty.tests.distribution.AbstractJettyHomeTest; import org.eclipse.jetty.tests.testers.JettyHomeTester; import org.eclipse.jetty.tests.testers.Tester; import org.eclipse.jetty.toolchain.test.FS; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.parallel.Isolated; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; @@ -38,7 +40,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @Isolated public class DisableUrlCacheTest extends AbstractJettyHomeTest { - @Test + private static final Logger LOG = LoggerFactory.getLogger(DisableUrlCacheTest.class); + + @RepeatedTest(value = 40, failureThreshold = 1) public void testReloadWebAppWithLog4j2() throws Exception { Path jettyBase = newTestJettyBaseDirectory(); @@ -65,6 +69,9 @@ public class DisableUrlCacheTest extends AbstractJettyHomeTest Path tempDir = distribution.getJettyBase().resolve("work"); FS.ensureEmpty(tempDir); + Path resourcesDir = distribution.getJettyBase().resolve("resources"); + FS.ensureEmpty(resourcesDir); + Path webappsDir = distribution.getJettyBase().resolve("webapps"); String warXml = """ @@ -79,6 +86,17 @@ public class DisableUrlCacheTest extends AbstractJettyHomeTest Path warXmlPath = webappsDir.resolve("test.xml"); Files.writeString(warXmlPath, warXml, StandardCharsets.UTF_8); + Path loggingFile = resourcesDir.resolve("jetty-logging.properties"); + String loggingConfig = """ + org.eclipse.jetty.LEVEL=INFO + org.eclipse.jetty.deploy.LEVEL=DEBUG + org.eclipse.jetty.ee10.webapp.LEVEL=DEBUG + org.eclipse.jetty.ee10.webapp.WebAppClassLoader.LEVEL=INFO + org.eclipse.jetty.ee10.servlet.LEVEL=DEBUG + """; + Files.writeString(loggingFile, loggingConfig, StandardCharsets.UTF_8); + + int port = Tester.freePort(); String[] runArgs = { "jetty.http.port=" + port, @@ -101,12 +119,14 @@ public class DisableUrlCacheTest extends AbstractJettyHomeTest touch(warXmlPath); // Wait for reload + // Started oeje10w.WebAppContext@3fec304{test,/test,b=file:///h assertTrue(run2.awaitConsoleLogsFor("Started oeje10w.WebAppContext@", START_TIMEOUT, TimeUnit.SECONDS)); + assertTrue(run2.awaitConsoleLogsFor("{test,/test,", START_TIMEOUT, TimeUnit.SECONDS)); // Is webapp still there? response = client.GET("http://localhost:" + port + "/test/log/"); - assertThat(response.getStatus(), is(HttpStatus.OK_200)); content = response.getContentAsString(); + assertThat(content, response.getStatus(), is(HttpStatus.OK_200)); assertThat(content, containsString("GET at LogServlet")); } } @@ -114,6 +134,7 @@ public class DisableUrlCacheTest extends AbstractJettyHomeTest private void touch(Path path) throws IOException { + LOG.info("Touch: {}", path); FileTime now = FileTime.fromMillis(System.currentTimeMillis() + 2000); Files.setLastModifiedTime(path, now); } From bc16e9081469bbfc6cc44f5774754b8192eca254 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 23 Apr 2024 20:45:39 -0500 Subject: [PATCH 04/15] Revert @RepeatedTest to @Test --- .../jetty/ee10/tests/distribution/DisableUrlCacheTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-distribution/test-ee10-distribution/src/test/java/org/eclipse/jetty/ee10/tests/distribution/DisableUrlCacheTest.java b/tests/test-distribution/test-ee10-distribution/src/test/java/org/eclipse/jetty/ee10/tests/distribution/DisableUrlCacheTest.java index b109d9abaa1..4927a6e0db6 100644 --- a/tests/test-distribution/test-ee10-distribution/src/test/java/org/eclipse/jetty/ee10/tests/distribution/DisableUrlCacheTest.java +++ b/tests/test-distribution/test-ee10-distribution/src/test/java/org/eclipse/jetty/ee10/tests/distribution/DisableUrlCacheTest.java @@ -26,7 +26,7 @@ import org.eclipse.jetty.tests.distribution.AbstractJettyHomeTest; import org.eclipse.jetty.tests.testers.JettyHomeTester; import org.eclipse.jetty.tests.testers.Tester; import org.eclipse.jetty.toolchain.test.FS; -import org.junit.jupiter.api.RepeatedTest; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.parallel.Isolated; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,7 +42,7 @@ public class DisableUrlCacheTest extends AbstractJettyHomeTest { private static final Logger LOG = LoggerFactory.getLogger(DisableUrlCacheTest.class); - @RepeatedTest(value = 40, failureThreshold = 1) + @Test public void testReloadWebAppWithLog4j2() throws Exception { Path jettyBase = newTestJettyBaseDirectory(); From 33a65f636f768fb49660c45c95b6f220febf2a33 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 24 Apr 2024 18:06:02 +1000 Subject: [PATCH 05/15] Fix distribution test race (#11691) --- .../ee10/tests/distribution/DisableUrlCacheTest.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/test-distribution/test-ee10-distribution/src/test/java/org/eclipse/jetty/ee10/tests/distribution/DisableUrlCacheTest.java b/tests/test-distribution/test-ee10-distribution/src/test/java/org/eclipse/jetty/ee10/tests/distribution/DisableUrlCacheTest.java index 4927a6e0db6..918a38c08dc 100644 --- a/tests/test-distribution/test-ee10-distribution/src/test/java/org/eclipse/jetty/ee10/tests/distribution/DisableUrlCacheTest.java +++ b/tests/test-distribution/test-ee10-distribution/src/test/java/org/eclipse/jetty/ee10/tests/distribution/DisableUrlCacheTest.java @@ -18,6 +18,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.FileTime; +import java.util.List; import java.util.concurrent.TimeUnit; import org.eclipse.jetty.client.ContentResponse; @@ -50,10 +51,11 @@ public class DisableUrlCacheTest extends AbstractJettyHomeTest JettyHomeTester distribution = JettyHomeTester.Builder.newInstance() .jettyVersion(jettyVersion) .jettyBase(jettyBase) + .jvmArgs(List.of("-Dorg.eclipse.jetty.deploy.LEVEL=DEBUG")) .build(); String[] setupArgs = { - "--add-to-start=http,ee10-webapp,ee10-deploy,disable-urlcache" + "--add-modules=http,ee10-webapp,ee10-deploy,disable-urlcache" }; try (JettyHomeTester.Run setupRun = distribution.start(setupArgs)) @@ -118,10 +120,10 @@ public class DisableUrlCacheTest extends AbstractJettyHomeTest run2.getLogs().clear(); touch(warXmlPath); - // Wait for reload - // Started oeje10w.WebAppContext@3fec304{test,/test,b=file:///h + // Wait for reload to start context assertTrue(run2.awaitConsoleLogsFor("Started oeje10w.WebAppContext@", START_TIMEOUT, TimeUnit.SECONDS)); - assertTrue(run2.awaitConsoleLogsFor("{test,/test,", START_TIMEOUT, TimeUnit.SECONDS)); + // wait for deployer node to complete so context is Started not Starting + assertTrue(run2.awaitConsoleLogsFor("Executing Node Node[started]", START_TIMEOUT, TimeUnit.SECONDS)); // Is webapp still there? response = client.GET("http://localhost:" + port + "/test/log/"); From aef8cb1b50c9fddb7f1715f2066fde0b835cc7d7 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Wed, 24 Apr 2024 15:42:29 +0200 Subject: [PATCH 06/15] Issue #11676 fix session CreationTest (#11685) --- .../jetty/ee10/session/CreationTest.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/CreationTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/CreationTest.java index 83148ef4b3d..8e829ba4833 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/CreationTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/CreationTest.java @@ -200,7 +200,7 @@ public class CreationTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); //check that the session does not exist - assertFalse(contextHandler.getSessionHandler().getSessionCache().getSessionDataStore().exists(servlet._id)); + Awaitility.waitAtMost(5, TimeUnit.SECONDS).until(() -> !contextHandler.getSessionHandler().getSessionCache().getSessionDataStore().exists(servlet._id)); } finally { @@ -245,7 +245,7 @@ public class CreationTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); //check that the session does not exist - assertFalse(contextHandler.getSessionHandler().getSessionCache().getSessionDataStore().exists(servlet._id)); + Awaitility.waitAtMost(5, TimeUnit.SECONDS).until(() -> !contextHandler.getSessionHandler().getSessionCache().getSessionDataStore().exists(servlet._id)); } finally { @@ -287,8 +287,8 @@ public class CreationTest ContentResponse response = client.GET(url); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); - //check that the session does not exist - assertTrue(contextHandler.getSessionHandler().getSessionCache().getSessionDataStore().exists(servlet._id)); + //check the session + Awaitility.waitAtMost(5, TimeUnit.SECONDS).until(() -> contextHandler.getSessionHandler().getSessionCache().getSessionDataStore().exists(servlet._id)); assertThat(response.getHeaders().getValuesList(HttpHeader.SET_COOKIE).size(), Matchers.is(1)); } finally @@ -338,8 +338,8 @@ public class CreationTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); //check that the sessions exist persisted - assertTrue(contextHandler.getSessionHandler().getSessionCache().getSessionDataStore().exists(servlet._id)); - assertTrue(ctxB.getSessionHandler().getSessionCache().getSessionDataStore().exists(servlet._id)); + Awaitility.waitAtMost(5, TimeUnit.SECONDS).until(() -> contextHandler.getSessionHandler().getSessionCache().getSessionDataStore().exists(servlet._id)); + Awaitility.waitAtMost(5, TimeUnit.SECONDS).until(() -> ctxB.getSessionHandler().getSessionCache().getSessionDataStore().exists(servlet._id)); } finally { @@ -387,9 +387,9 @@ public class CreationTest ContentResponse response = client.GET(url + "?action=forwardinv"); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); - //check that the session does not exist - assertFalse(contextHandler.getSessionHandler().getSessionCache().getSessionDataStore().exists(servlet._id)); - assertFalse(ctxB.getSessionHandler().getSessionCache().getSessionDataStore().exists(servlet._id)); + //check that the session does not exist + Awaitility.waitAtMost(5, TimeUnit.SECONDS).until(() -> !contextHandler.getSessionHandler().getSessionCache().getSessionDataStore().exists(servlet._id)); + Awaitility.waitAtMost(5, TimeUnit.SECONDS).until(() -> !ctxB.getSessionHandler().getSessionCache().getSessionDataStore().exists(servlet._id)); } finally { From 23ca73e8336b2888f38aec99283f66da3576a898 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Wed, 24 Apr 2024 15:42:53 +0200 Subject: [PATCH 07/15] Issue #11677 fix AttributeNameTest (#11689) --- .../jetty/ee10/session/nosql/mongodb/AttributeNameTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/AttributeNameTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/AttributeNameTest.java index 882b5135798..1a3493a8e7a 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/AttributeNameTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-mongodb/src/test/java/org/eclipse/jetty/ee10/session/nosql/mongodb/AttributeNameTest.java @@ -77,6 +77,7 @@ public class AttributeNameTest DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory(); cacheFactory.setEvictionPolicy(SessionCache.NEVER_EVICT); + cacheFactory.setSaveOnCreate(true); MongoSessionDataStoreFactory storeFactory = MongoTestHelper.newSessionDataStoreFactory(DB_NAME, COLLECTION_NAME); storeFactory.setGracePeriodSec(scavengePeriod); From e491fc3d309424110e76423e54e3b4a13d889f40 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 24 Apr 2024 18:19:34 +0200 Subject: [PATCH 08/15] Document the rewrite Jetty module. (#11686) * Document the rewrite Jetty module. Signed-off-by: Simone Bordet --- .../modules/module-rewrite.adoc | 84 +++++++++++++++++++ .../modules/modules-standard.adoc | 1 + .../src/main/config/modules/rewrite.mod | 6 +- .../rewrite/handler/HeaderRegexRule.java | 2 +- .../rewrite/handler/RedirectPatternRule.java | 2 +- .../rewrite/handler/RedirectRegexRule.java | 2 +- 6 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 documentation/jetty-documentation/src/main/asciidoc/operations-guide/modules/module-rewrite.adoc diff --git a/documentation/jetty-documentation/src/main/asciidoc/operations-guide/modules/module-rewrite.adoc b/documentation/jetty-documentation/src/main/asciidoc/operations-guide/modules/module-rewrite.adoc new file mode 100644 index 00000000000..22fc46b422e --- /dev/null +++ b/documentation/jetty-documentation/src/main/asciidoc/operations-guide/modules/module-rewrite.adoc @@ -0,0 +1,84 @@ +// +// ======================================================================== +// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +[[og-module-rewrite]] +===== Module `rewrite` + +The `rewrite` module inserts the `RewriteHandler` at the beginning of the `Handler` chain, providing URI-rewriting features similar to the link:https://httpd.apache.org/docs/current/mod/mod_rewrite.html[Apache's mod_rewrite] or the link:https://nginx.org/en/docs/http/ngx_http_rewrite_module.html[Nginx rewrite module]. + +The module properties are: + +---- +include::{jetty-home}/modules/rewrite.mod[tags=documentation] +---- + +A common use of the `rewrite` module is to redirect/rewrite old URI paths that have been renamed, for example from `+/old/*+` to `+/new/*+`; in this way, the old paths will not result in a `404` response, but rather be redirected/rewritten to the new paths. + +`RewriteHandler` matches incoming requests against a set of rules that you can specify in the `$JETTY_BASE/etc/jetty-rewrite-rules.xml` file. + +Rules can be matched against request data such as the request URI or the request headers; if there is a match, the rule is applied. + +The rule file `$JETTY_BASE/etc/jetty-rewrite-rules.xml` is initially empty, but contains commented examples of rules that you can add. + +The list of available rules can be found link:{javadoc-url}/org/eclipse/jetty/rewrite/handler/package-summary.html[here]. + +An example of `jetty-rewrite-rules.xml` is the following: + +[source,xml] +.jetty-rewrite-rules.xml +---- + + + + + + + + 301 + /old/(.*) + /new/$1 + + + + +---- + +Rules can be scoped to a specific virtual host. +In the example below, the rule will only be evaluated if the virtual host matches `example.com`: + +[source,xml] +.jetty-rewrite-rules.xml +---- + + + + + + + + + example.com + + + + + /advice + /support + + + + + + + +---- diff --git a/documentation/jetty-documentation/src/main/asciidoc/operations-guide/modules/modules-standard.adoc b/documentation/jetty-documentation/src/main/asciidoc/operations-guide/modules/modules-standard.adoc index c36e6a294fc..132cb491bc4 100644 --- a/documentation/jetty-documentation/src/main/asciidoc/operations-guide/modules/modules-standard.adoc +++ b/documentation/jetty-documentation/src/main/asciidoc/operations-guide/modules/modules-standard.adoc @@ -30,6 +30,7 @@ include::module-jmx.adoc[] include::module-jmx-remote.adoc[] include::module-requestlog.adoc[] include::module-resources.adoc[] +include::module-rewrite.adoc[] include::module-server.adoc[] include::module-ssl.adoc[] include::module-ssl-reload.adoc[] diff --git a/jetty-core/jetty-rewrite/src/main/config/modules/rewrite.mod b/jetty-core/jetty-rewrite/src/main/config/modules/rewrite.mod index ac4963afd23..ba7e9815457 100644 --- a/jetty-core/jetty-rewrite/src/main/config/modules/rewrite.mod +++ b/jetty-core/jetty-rewrite/src/main/config/modules/rewrite.mod @@ -1,8 +1,8 @@ # DO NOT EDIT THIS FILE - See: https://eclipse.dev/jetty/documentation/ [description] -Enables the jetty-rewrite handler. -Specific rewrite rules must be added to etc/jetty-rewrite-rules.xml. +Adds the RewriteHandler to the Handler chain. +Specific rewrite rules must be added to $JETTY_BASE/etc/jetty-rewrite-rules.xml. [tags] server @@ -24,5 +24,7 @@ etc/jetty-rewrite.xml etc/jetty-rewrite-rules.xml [ini-template] +# tag::documentation[] ## Request attribute name used to store the original request path. # jetty.rewrite.originalPathAttribute=jetty.rewrite.originalRequestPath +# end::documentation[] diff --git a/jetty-core/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/HeaderRegexRule.java b/jetty-core/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/HeaderRegexRule.java index e748da9cd0f..182d84c4967 100644 --- a/jetty-core/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/HeaderRegexRule.java +++ b/jetty-core/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/HeaderRegexRule.java @@ -66,7 +66,7 @@ public class HeaderRegexRule extends RegexRule } /** - * Set true to add the response header, false to put the response header.. + * Set true to add the response header, false to put the response header. * @param add true to add the response header, false to put the response header. */ public void setAdd(boolean add) diff --git a/jetty-core/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RedirectPatternRule.java b/jetty-core/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RedirectPatternRule.java index df660f995b2..985dd60447f 100644 --- a/jetty-core/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RedirectPatternRule.java +++ b/jetty-core/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RedirectPatternRule.java @@ -53,7 +53,7 @@ public class RedirectPatternRule extends PatternRule } /** - * Set the location to redirect.. + * Set the location to redirect. * @param value the location to redirect. */ public void setLocation(String value) diff --git a/jetty-core/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RedirectRegexRule.java b/jetty-core/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RedirectRegexRule.java index a1288a276fd..ce552c5867f 100644 --- a/jetty-core/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RedirectRegexRule.java +++ b/jetty-core/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RedirectRegexRule.java @@ -55,7 +55,7 @@ public class RedirectRegexRule extends RegexRule } /** - * Set the location to redirect.. + * Set the location to redirect. * @param location the location to redirect. */ public void setLocation(String location) From c10ec98b5bc39a81093ac306929cd9fdcc35a8d0 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 24 Apr 2024 18:57:16 +0200 Subject: [PATCH 09/15] Fixes #11597 - Document Request Customizers. Documented the request customizers in the programming guide. Signed-off-by: Simone Bordet --- .../http/server-http-request-customizers.adoc | 112 ++++++++++++++++++ .../http/server-http-request-logging.adoc | 48 ++++++++ .../server/http/server-http.adoc | 46 ++----- .../server/http/HTTPServerDocs.java | 28 +++++ .../server/ForwardedRequestCustomizer.java | 45 ++++--- .../jetty/server/SecureRequestCustomizer.java | 4 +- 6 files changed, 218 insertions(+), 65 deletions(-) create mode 100644 documentation/jetty-documentation/src/main/asciidoc/programming-guide/server/http/server-http-request-customizers.adoc create mode 100644 documentation/jetty-documentation/src/main/asciidoc/programming-guide/server/http/server-http-request-logging.adoc diff --git a/documentation/jetty-documentation/src/main/asciidoc/programming-guide/server/http/server-http-request-customizers.adoc b/documentation/jetty-documentation/src/main/asciidoc/programming-guide/server/http/server-http-request-customizers.adoc new file mode 100644 index 00000000000..642e3db5ee9 --- /dev/null +++ b/documentation/jetty-documentation/src/main/asciidoc/programming-guide/server/http/server-http-request-customizers.adoc @@ -0,0 +1,112 @@ +// +// ======================================================================== +// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +[[pg-server-http-request-customizers]] +==== Request Customizers + +A request customizer is an instance of `HttpConfiguration.Customizer`, that can customize the HTTP request and/or the HTTP response headers _before_ the `Handler` chain is invoked. + +Request customizers are added to a particular `HttpConfiguration` instance, and therefore are specific to a `Connector` instance: you can have two different ``Connector``s configured with different request customizers. + +For example, it is common to configure a secure `Connector` with the `SecureRequestCustomizer` that customizes the HTTP request by adding attributes that expose TLS data associated with the secure communication. + +A request customizer may: + +* Inspect the received HTTP request method, URI, version and headers. +* Wrap the `Request` object to allow any method to be overridden and customized. Typically this is done to synthesize additional HTTP request headers, or to change the return value of overridden methods. +* Add or modify the HTTP response headers. + +The out-of-the-box request customizers include: + +* `ForwardedRequestCustomizer` -- to interpret the `Forwarded` (or the the obsolete ``+X-Forwarded-*+``) HTTP header added by a reverse proxy; see xref:pg-server-http-request-customizer-forwarded[this section]. +* `HostHeaderCustomizer` -- to customize, or synthesize it when original absent, the HTTP `Host` header; see xref:pg-server-http-request-customizer-host[this section]. +* `ProxyCustomizer` -- to expose as `Request` attributes the `ip:port` information carried by the PROXY protocol; see xref:pg-server-http-request-customizer-proxy[this section]. +* `RewriteCustomizer` -- to rewrite the request URI; see xref:pg-server-http-request-customizer-rewrite[this section]. +* `SecureRequestCustomizer` -- to expose TLS data via `Request` attributes; see xref:pg-server-http-request-customizer-secure[this section]. + +You can also write your own request customizers and add them to the `HttpConfiguration` instance along existing request customizers. +Multiple request customizers will be invoked in the order they have been added. + +Below you can find an example of how to add a request customizer: + +[source,java,indent=0] +---- +include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=requestCustomizer] +---- + +[[pg-server-http-request-customizer-forwarded]] +===== `ForwardedRequestCustomizer` + +`ForwardedRequestCustomizer` should be added when Jetty receives requests from a reverse proxy on behalf of a remote client, and web applications need to access the remote client information. + +The reverse proxy adds the `Forwarded` (or the obsolete ``+X-Forwarded-*+``) HTTP header to the request, and may offload TLS so that the request arrives in clear-text to Jetty. + +Applications deployed in Jetty may need to access information related to the remote client, for example the remote IP address and port, or whether the request was sent through a secure communication channel. +However, the request is forwarded by the reverse proxy, so the direct information about the remote IP address is that of the proxy, not of the remote client. +Furthermore, the proxy may offload TLS and forward the request in clear-text, so that the URI scheme would be `http` as forwarded by the reverse proxy, not `https` as sent by the remote client. + +`ForwardedRequestCustomizer` reads the `Forwarded` header where the reverse proxy saved the remote client information, and wraps the original `Request` so that applications will transparently see the remote client information when calling methods such as `Request.isSecure()`, or `Request.getConnectionMetaData().getRemoteSocketAddress()`, etc. + +For more information about how to configure `ForwardedRequestCustomizer`, see also link:{javadoc-url}/org/eclipse/jetty/server/ForwardedRequestCustomizer.html[the javadocs]. + +[[pg-server-http-request-customizer-host]] +===== `HostHeaderCustomizer` + +`HostHeaderCustomizer` should be added when Jetty receives requests that may lack the `Host` HTTP header, such as HTTP/1.0, HTTP/2 or HTTP/3 requests, and web applications have logic that depends on the value of the `Host` HTTP header. + +For HTTP/2 and HTTP/3, the `Host` HTTP header is missing because the authority information is carried by the `:authority` pseudo-header, as per the respective specifications. + +`HostHeaderCustomizer` will look at the `:authority` pseudo-header, then wrap the original `Request` adding a `Host` HTTP header synthesized from the `:authority` pseudo-header. +In this way, web applications that rely on the presence of the `Host` HTTP header will work seamlessly in any HTTP protocol version. + +`HostHeaderCustomizer` works also for the WebSocket protocol. + +WebSocket over HTTP/2 or over HTTP/3 initiate the WebSocket communication with an HTTP request that only has the `:authority` pseudo-header. +`HostHeaderCustomizer` synthesizes the `Host` HTTP header for such requests, so that WebSocket web applications that inspect the initial HTTP request before the WebSocket communication will work seamlessly in any HTTP protocol version. + +For more information about how to configure `HostHeaderCustomizer`, see also link:{javadoc-url}/org/eclipse/jetty/server/HostHeaderCustomizer.html[the javadocs]. + +[[pg-server-http-request-customizer-proxy]] +===== `ProxyCustomizer` + +`ProxyCustomizer` should be added when Jetty receives requests from a reverse proxy on behalf of a remote client, prefixed by the PROXY protocol (see also this section about the xref:pg-server-http-connector-protocol-proxy-http11[PROXY protocol]). + +`ProxyCustomizer` adds the reverse proxy IP address and port as `Request` attributes. +Web applications may use these attributes in conjunction with the data exposed by `ForwardedRequestCustomizer` (see xref:pg-server-http-request-customizer-forwarded[this section]). + +For more information about how to configure `ProxyCustomizer`, see also link:{javadoc-url}/org/eclipse/jetty/server/ProxyCustomizer.html[the javadocs]. + +[[pg-server-http-request-customizer-rewrite]] +===== `RewriteCustomizer` + +`RewriteCustomizer` is similar to `RewriteHandler` (see xref:pg-server-http-handler-use-rewrite[this section]), but a `RewriteCustomizer` cannot send a response or otherwise complete the request/response processing. + +A `RewriteCustomizer` is mostly useful if you want to rewrite the request URI _before_ the `Handler` chain is invoked. +However, a very similar effect can be achieved by having the `RewriteHandler` as the first `Handler` (the child `Handler` of the `Server` instance). + +Since `RewriteCustomizer` cannot send a response or complete the request/response processing, ``Rule``s that do so such as redirect rules have no effect and are ignored; only ``Rule``s that modify or wrap the `Request` will have effect and be applied. + +Due to this limitation, it is often a better choice to use `RewriteHandler` instead of `RewriteCustomizer`. + +For more information about how to configure `RewriteCustomizer`, see also link:{javadoc-url}/org/eclipse/jetty/rewrite/RewriteCustomizer.html[the javadocs]. + +[[pg-server-http-request-customizer-secure]] +===== `SecureRequestCustomizer` + +`SecureRequestCustomizer` should be added when Jetty receives requests over a secure `Connector`. + +`SecureRequestCustomizer` adds TLS information as request attributes, in particular an instance of `EndPoint.SslSessionData` that contains information about the negotiated TLS cipher suite and possibly client certificates, and an instance of `org.eclipse.jetty.util.ssl.X509` that contains information about the server certificate. + +`SecureRequestCustomizer` also adds, if configured so, the `Strict-Transport-Security` HTTP response header (for more information about this header, see link:https://datatracker.ietf.org/doc/html/rfc6797[its specification]). + +For more information about how to configure `SecureRequestCustomizer`, see also link:{javadoc-url}/org/eclipse/jetty/server/SecureRequestCustomizer.html[the javadocs]. diff --git a/documentation/jetty-documentation/src/main/asciidoc/programming-guide/server/http/server-http-request-logging.adoc b/documentation/jetty-documentation/src/main/asciidoc/programming-guide/server/http/server-http-request-logging.adoc new file mode 100644 index 00000000000..846754a0913 --- /dev/null +++ b/documentation/jetty-documentation/src/main/asciidoc/programming-guide/server/http/server-http-request-logging.adoc @@ -0,0 +1,48 @@ +// +// ======================================================================== +// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +[[pg-server-http-request-logging]] +==== Request Logging + +HTTP requests and responses can be logged to provide data that can be later analyzed with other tools. +These tools can provide information such as the most frequently accessed request URIs, the response status codes, the request/response content lengths, geographical information about the clients, etc. + +The default request/response log line format is the link:https://en.wikipedia.org/wiki/Common_Log_Format[NCSA Format] extended with referrer data and user-agent data. + +[NOTE] +==== +Typically, the extended NCSA format is the is enough and it's the standard used and understood by most log parsing tools and monitoring tools. + +To customize the request/response log line format see the link:{javadoc-url}/org/eclipse/jetty/server/CustomRequestLog.html[`CustomRequestLog` javadocs]. +==== + +Request logging can be enabled at the `Server` level. + +The request logging output can be directed to an SLF4J logger named `"org.eclipse.jetty.server.RequestLog"` at `INFO` level, and therefore to any logging library implementation of your choice (see also xref:pg-troubleshooting-logging[this section] about logging). + +[source,java,indent=0] +---- +include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=serverRequestLogSLF4J] +---- + +Alternatively, the request logging output can be directed to a daily rolling file of your choice, and the file name must contain `yyyy_MM_dd` so that rolled over files retain their date: + +[source,java,indent=0] +---- +include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=serverRequestLogFile] +---- + +For maximum flexibility, you can log to multiple ``RequestLog``s using class `RequestLog.Collection`, for example by logging with different formats or to different outputs. + +You can use `CustomRequestLog` with a custom `RequestLog.Writer` to direct the request logging output to your custom targets (for example, an RDBMS). +You can implement your own `RequestLog` if you want to have functionalities that are not implemented by `CustomRequestLog`. diff --git a/documentation/jetty-documentation/src/main/asciidoc/programming-guide/server/http/server-http.adoc b/documentation/jetty-documentation/src/main/asciidoc/programming-guide/server/http/server-http.adoc index b324010fe6b..679c0d02825 100644 --- a/documentation/jetty-documentation/src/main/asciidoc/programming-guide/server/http/server-http.adoc +++ b/documentation/jetty-documentation/src/main/asciidoc/programming-guide/server/http/server-http.adoc @@ -123,9 +123,13 @@ First, the Jetty I/O layer emits an event that a socket has data to read. This event is converted to a call to `AbstractConnection.onFillable()`, where the `Connection` first reads from the `EndPoint` into a `ByteBuffer`, and then calls a protocol specific parser to parse the bytes in the `ByteBuffer`. The parser emit events that are protocol specific; the HTTP/2 parser, for example, emits events for each HTTP/2 frame that has been parsed, and similarly does the HTTP/3 parser. -The parser events are then converted to protocol independent events such as _"request start"_, _"request headers"_, _"request content chunk"_, etc. +The parser events are then converted to protocol independent events such as _"request start"_, _"request headers"_, _"request content chunk"_, etc. detailed in xref:pg-server-http-request-processing-events[this section]. -When enough of the HTTP request is arrived, the `Connection` calls `HttpChannel.onRequest()` that calls the `Handler` chain starting from the `Server` instance, that eventually calls your web application code. +When enough of the HTTP request is arrived, the `Connection` calls `HttpChannel.onRequest()`. + +`HttpChannel.onRequest()` calls the xref:pg-server-http-request-customizers[request customizers], that allow to customize the request and/or the response headers on a per-``Connector`` basis. + +After request customization, if any, the `Handler` chain is invoked, starting from the `Server` instance, and eventually your web application code is invoked. [[pg-server-http-request-processing-events]] ===== Request Processing Events @@ -135,42 +139,8 @@ A typical case is to know exactly _when_ the HTTP request/response processing st This is conveniently implemented by `org.eclipse.jetty.server.handler.EventsHandler`, described in more details in xref:pg-server-http-handler-use-events[this section]. -[[pg-server-http-request-logging]] -==== Request Logging - -HTTP requests and responses can be logged to provide data that can be later analyzed with other tools. -These tools can provide information such as the most frequently accessed request URIs, the response status codes, the request/response content lengths, geographical information about the clients, etc. - -The default request/response log line format is the link:https://en.wikipedia.org/wiki/Common_Log_Format[NCSA Format] extended with referrer data and user-agent data. - -[NOTE] -==== -Typically, the extended NCSA format is the is enough and it's the standard used and understood by most log parsing tools and monitoring tools. - -To customize the request/response log line format see the link:{javadoc-url}/org/eclipse/jetty/server/CustomRequestLog.html[`CustomRequestLog` javadocs]. -==== - -Request logging can be enabled at the `Server` level. - -The request logging output can be directed to an SLF4J logger named `"org.eclipse.jetty.server.RequestLog"` at `INFO` level, and therefore to any logging library implementation of your choice (see also xref:pg-troubleshooting-logging[this section] about logging). - -[source,java,indent=0] ----- -include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=serverRequestLogSLF4J] ----- - -Alternatively, the request logging output can be directed to a daily rolling file of your choice, and the file name must contain `yyyy_MM_dd` so that rolled over files retain their date: - -[source,java,indent=0] ----- -include::../../{doc_code}/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java[tags=serverRequestLogFile] ----- - -For maximum flexibility, you can log to multiple ``RequestLog``s using class `RequestLog.Collection`, for example by logging with different formats or to different outputs. - -You can use `CustomRequestLog` with a custom `RequestLog.Writer` to direct the request logging output to your custom targets (for example, an RDBMS). -You can implement your own `RequestLog` if you want to have functionalities that are not implemented by `CustomRequestLog`. - +include::server-http-request-logging.adoc[] +include::server-http-request-customizers.adoc[] include::server-http-connector.adoc[] include::server-http-handler.adoc[] include::server-http-session.adoc[] diff --git a/documentation/jetty-documentation/src/main/java/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java b/documentation/jetty-documentation/src/main/java/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java index eebc2f1c8b6..53602a65ccb 100644 --- a/documentation/jetty-documentation/src/main/java/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java +++ b/documentation/jetty-documentation/src/main/java/org/eclipse/jetty/docs/programming/server/http/HTTPServerDocs.java @@ -1593,4 +1593,32 @@ public class HTTPServerDocs } // end::continue100[] } + + public void requestCustomizer() throws Exception + { + // tag::requestCustomizer[] + Server server = new Server(); + + // Configure the secure connector. + HttpConfiguration httpsConfig = new HttpConfiguration(); + + // Add the SecureRequestCustomizer. + httpsConfig.addCustomizer(new SecureRequestCustomizer()); + + // Configure the SslContextFactory with the KeyStore information. + SslContextFactory.Server sslContextFactory = new SslContextFactory.Server(); + sslContextFactory.setKeyStorePath("/path/to/keystore"); + sslContextFactory.setKeyStorePassword("secret"); + // Configure the Connector to speak HTTP/1.1 and HTTP/2. + HttpConnectionFactory h1 = new HttpConnectionFactory(httpsConfig); + HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(httpsConfig); + ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory(); + alpn.setDefaultProtocol(h1.getProtocol()); + SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol()); + ServerConnector connector = new ServerConnector(server, ssl, alpn, h2, h1); + server.addConnector(connector); + + server.start(); + // end::requestCustomizer[] + } } diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java index b1a45182901..eddb9f7cfcf 100644 --- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java +++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/ForwardedRequestCustomizer.java @@ -43,7 +43,7 @@ import static java.lang.invoke.MethodType.methodType; /** * Customize Requests for Proxy Forwarding. *

- * This customizer looks at at HTTP request for headers that indicate + * This customizer looks at HTTP request for headers that indicate * it has been forwarded by one or more proxies. Specifically handled are *

    *
  • {@code Forwarded}, as defined by rfc7239 @@ -80,7 +80,7 @@ import static java.lang.invoke.MethodType.methodType; * * * 1 - * Forwarded Header + * {@code Forwarded} Header * "{@code host=}" param (Required) * "{@code host=:} param (Implied) * "{@code proto=}" param (Optional) @@ -88,7 +88,7 @@ import static java.lang.invoke.MethodType.methodType; * * * 2 - * X-Forwarded-Host Header + * {@code X-Forwarded-Host} Header * Required * Implied * n/a @@ -96,7 +96,7 @@ import static java.lang.invoke.MethodType.methodType; * * * 3 - * X-Forwarded-Port Header + * {@code X-Forwarded-Port} Header * n/a * Required * n/a @@ -104,7 +104,7 @@ import static java.lang.invoke.MethodType.methodType; * * * 4 - * X-Forwarded-Server Header + * {@code X-Forwarded-Server} Header * Required * Optional * n/a @@ -112,29 +112,29 @@ import static java.lang.invoke.MethodType.methodType; * * * 5 - * X-Forwarded-Proto Header + * {@code X-Forwarded-Proto} Header * n/a * Implied from value * Required * *

    left-most value becomes protocol.

    *
      - *
    • Value of "http" means port=80.
    • + *
    • Value of "{@code http}" means port=80.
    • *
    • Value of "{@link HttpConfiguration#getSecureScheme()}" means port={@link HttpConfiguration#getSecurePort()}.
    • *
    * * * * 6 - * X-Proxied-Https Header + * {@code X-Proxied-Https} Header * n/a * Implied from value * boolean * *

    left-most value determines protocol and port.

    *
      - *
    • Value of "on" means port={@link HttpConfiguration#getSecurePort()}, and protocol={@link HttpConfiguration#getSecureScheme()}).
    • - *
    • Value of "off" means port=80, and protocol=http.
    • + *
    • Value of "{@code on}" means port={@link HttpConfiguration#getSecurePort()}, and protocol={@link HttpConfiguration#getSecureScheme()}).
    • + *
    • Value of "{@code off}" means port=80, and protocol=http.
    • *
    * * @@ -799,12 +799,7 @@ public class ForwardedRequestCustomizer implements HttpConfiguration.Customizer @Override public String toString() { - final StringBuilder sb = new StringBuilder("MutableHostPort{"); - sb.append("host='").append(_host).append("'/").append(_hostSource); - sb.append(", port=").append(_port); - sb.append("/").append(_portSource); - sb.append('}'); - return sb.toString(); + return "%s@%x{host='%s'/%s, port=%d/%s}".formatted(getClass().getSimpleName(), hashCode(), _host, _hostSource, _port, _portSource); } } @@ -888,7 +883,7 @@ public class ForwardedRequestCustomizer implements HttpConfiguration.Customizer } /** - * Called if header is Proxy-auth-cert + * Called if header is {@code Proxy-auth-cert} */ public void handleCipherSuite(HttpField field) { @@ -904,7 +899,7 @@ public class ForwardedRequestCustomizer implements HttpConfiguration.Customizer } /** - * Called if header is Proxy-Ssl-Id + * Called if header is {@code Proxy-Ssl-Id} */ public void handleSslSessionId(HttpField field) { @@ -920,7 +915,7 @@ public class ForwardedRequestCustomizer implements HttpConfiguration.Customizer } /** - * Called if header is X-Forwarded-Host + * Called if header is {@code X-Forwarded-Host} */ public void handleForwardedHost(HttpField field) { @@ -928,7 +923,7 @@ public class ForwardedRequestCustomizer implements HttpConfiguration.Customizer } /** - * Called if header is X-Forwarded-For + * Called if header is {@code X-Forwarded-For} */ public void handleForwardedFor(HttpField field) { @@ -937,7 +932,7 @@ public class ForwardedRequestCustomizer implements HttpConfiguration.Customizer } /** - * Called if header is X-Forwarded-Server + * Called if header is {@code X-Forwarded-Server} */ public void handleForwardedServer(HttpField field) { @@ -947,7 +942,7 @@ public class ForwardedRequestCustomizer implements HttpConfiguration.Customizer } /** - * Called if header is X-Forwarded-Port + * Called if header is {@code X-Forwarded-Port} */ public void handleForwardedPort(HttpField field) { @@ -957,7 +952,7 @@ public class ForwardedRequestCustomizer implements HttpConfiguration.Customizer } /** - * Called if header is X-Forwarded-Proto + * Called if header is {@code X-Forwarded-Proto} */ public void handleProto(HttpField field) { @@ -965,7 +960,7 @@ public class ForwardedRequestCustomizer implements HttpConfiguration.Customizer } /** - * Called if header is X-Proxied-Https + * Called if header is {@code X-Proxied-Https} */ public void handleHttps(HttpField field) { @@ -988,7 +983,7 @@ public class ForwardedRequestCustomizer implements HttpConfiguration.Customizer } /** - * Called if header is Forwarded + * Called if header is {@code Forwarded} */ public void handleRFC7239(HttpField field) { diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/SecureRequestCustomizer.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/SecureRequestCustomizer.java index 7cb8d5b379e..9e445136015 100644 --- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/SecureRequestCustomizer.java +++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/SecureRequestCustomizer.java @@ -67,7 +67,7 @@ public class SecureRequestCustomizer implements HttpConfiguration.Customizer /** * @param sniHostCheck True if the SNI Host name must match. * @param stsMaxAgeSeconds The max age in seconds for a Strict-Transport-Security response header. If set less than zero then no header is sent. - * @param stsIncludeSubdomains If true, a include subdomain property is sent with any Strict-Transport-Security header + * @param stsIncludeSubdomains If true, an include subdomain property is sent with any Strict-Transport-Security header */ public SecureRequestCustomizer( @Name("sniHostCheck") boolean sniHostCheck, @@ -81,7 +81,7 @@ public class SecureRequestCustomizer implements HttpConfiguration.Customizer * @param sniRequired True if a SNI certificate is required. * @param sniHostCheck True if the SNI Host name must match. * @param stsMaxAgeSeconds The max age in seconds for a Strict-Transport-Security response header. If set less than zero then no header is sent. - * @param stsIncludeSubdomains If true, a include subdomain property is sent with any Strict-Transport-Security header + * @param stsIncludeSubdomains If true, an include subdomain property is sent with any Strict-Transport-Security header */ public SecureRequestCustomizer( @Name("sniRequired") boolean sniRequired, From 0c144845d489612f8521fb20bedba0a0f79c26a4 Mon Sep 17 00:00:00 2001 From: Lachlan Date: Thu, 25 Apr 2024 07:28:28 +1000 Subject: [PATCH 10/15] update SizeLimitHandler with fixes needed for appengine tests (#11570) * update SizeLimitHandler with fixes needed for appengine tests --------- Signed-off-by: Lachlan Roberts --- .../org/eclipse/jetty/server/SizeLimitHandler.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/SizeLimitHandler.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/SizeLimitHandler.java index 087d09c87fd..10352585930 100644 --- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/SizeLimitHandler.java +++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/SizeLimitHandler.java @@ -109,6 +109,7 @@ public class SizeLimitHandler extends Handler.Wrapper { private final HttpFields.Mutable _httpFields; private long _written = 0; + private HttpException.RuntimeException _failure; public SizeLimitResponseWrapper(Request request, Response wrapped) { @@ -119,7 +120,7 @@ public class SizeLimitHandler extends Handler.Wrapper @Override public HttpField onAddField(HttpField field) { - if (field.getHeader().is(HttpHeader.CONTENT_LENGTH.asString())) + if (field.getHeader() == HttpHeader.CONTENT_LENGTH) { long contentLength = field.getLongValue(); if (_responseLimit >= 0 && contentLength > _responseLimit) @@ -139,12 +140,19 @@ public class SizeLimitHandler extends Handler.Wrapper @Override public void write(boolean last, ByteBuffer content, Callback callback) { + if (_failure != null) + { + callback.failed(_failure); + return; + } + if (content != null && content.remaining() > 0) { if (_responseLimit >= 0 && (_written + content.remaining()) > _responseLimit) { - String message = "Response body is too large: %d>%d".formatted(_written + content.remaining(), _responseLimit); - callback.failed(new HttpException.RuntimeException(HttpStatus.INTERNAL_SERVER_ERROR_500, message)); + _failure = new HttpException.RuntimeException(HttpStatus.INTERNAL_SERVER_ERROR_500, + "Response body is too large: %d>%d".formatted(_written + content.remaining(), _responseLimit)); + callback.failed(_failure); return; } _written += content.remaining(); From d4805a581e2d195234909e648e6ceb3c69947047 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 24 Apr 2024 23:35:26 +0200 Subject: [PATCH 11/15] Fixes #11597 - Document Request Customizers. (#11682) * Fixes #11597 - Document Request Customizers. Documented the request customizers in the programming guide. Signed-off-by: Simone Bordet From 429809e549e4a911945ba816661647c0e4b1618f Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 25 Apr 2024 09:54:20 -0500 Subject: [PATCH 12/15] Issue #11453 - Testcase for reported issue (#11454) --- .../org/eclipse/jetty/server/RequestTest.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java b/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java index d81bab9c4e7..14010cd6c7f 100644 --- a/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java +++ b/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java @@ -16,6 +16,7 @@ package org.eclipse.jetty.server; import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; import java.util.Arrays; +import java.util.EnumSet; import java.util.List; import java.util.Locale; import java.util.concurrent.TimeUnit; @@ -25,7 +26,10 @@ import org.eclipse.jetty.http.HttpCookie; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.HttpTester; +import org.eclipse.jetty.http.UriCompliance; +import org.eclipse.jetty.io.Content; import org.eclipse.jetty.server.LocalConnector.LocalEndPoint; +import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.DumpHandler; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.component.LifeCycle; @@ -96,6 +100,49 @@ public class RequestTest assertEquals(HttpStatus.BAD_REQUEST_400, response.getStatus()); } + @Test + public void testAmbiguousPathSep() throws Exception + { + server.stop(); + for (Connector connector: server.getConnectors()) + { + HttpConnectionFactory httpConnectionFactory = connector.getConnectionFactory(HttpConnectionFactory.class); + if (httpConnectionFactory != null) + { + HttpConfiguration httpConfiguration = httpConnectionFactory.getHttpConfiguration(); + httpConfiguration.setUriCompliance(UriCompliance.from( + EnumSet.of(UriCompliance.Violation.AMBIGUOUS_PATH_SEPARATOR) + )); + } + } + + ContextHandler fooContext = new ContextHandler(); + fooContext.setContextPath("/foo"); + fooContext.setHandler(new Handler.Abstract() + { + @Override + public boolean handle(Request request, Response response, Callback callback) + { + String pathInContext = Request.getPathInContext(request); + String msg = String.format("pathInContext=\"%s\"", pathInContext); + response.getHeaders().put(HttpHeader.CONTENT_TYPE, "text/plain;charset=utf-8"); + Content.Sink.write(response, true, msg, callback); + return true; + } + }); + server.setHandler(fooContext); + server.start(); + String request = """ + GET /foo/zed%2Fbar HTTP/1.1\r + Host: local\r + Connection: close\r + \r + """; + HttpTester.Response response = HttpTester.parseResponse(connector.getResponse(request)); + assertEquals(HttpStatus.OK_200, response.getStatus()); + assertThat(response.getContent(), is("pathInContext=\"/zed%2Fbar\"")); + } + @Test public void testConnectRequestURLSameAsHost() throws Exception { From 91633359c383a98b3078f5053085434b2c90a0b9 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 25 Apr 2024 10:13:46 -0500 Subject: [PATCH 13/15] Issue #11699 - ISE when Response does not exist. --- .../java/org/eclipse/jetty/ee10/servlet/ServletChannel.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletChannel.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletChannel.java index 34d1709b829..40a20921cc3 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletChannel.java +++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletChannel.java @@ -279,7 +279,9 @@ public class ServletChannel public ServletContextResponse getServletContextResponse() { ServletContextRequest request = _servletContextRequest; - return request == null ? null : request.getServletContextResponse(); + if (_servletContextRequest == null) + throw new IllegalStateException("Request/Response does not exist (likely recycled)"); + return request.getServletContextResponse(); } /** @@ -291,6 +293,8 @@ public class ServletChannel */ public Response getResponse() { + if (_response == null) + throw new IllegalStateException("Response does not exist (likely recycled)"); return _response; } From e9c71be8113e81debdd3996b19de1f50a7b2f177 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Fri, 26 Apr 2024 03:53:40 +0200 Subject: [PATCH 14/15] Jetty 12.0.x refactor common maven plugin classes (#11651) * Issue #11514 - Cleanup `jetty.webapp.addServerClasses` property behavior for ee10/ee9/ee8 * Merging patterns (default -> env -> config) * Moved ClassMatcher to util * System Server Classes * Renaming to Hidden/Protected * Updated for loss of dump.war * Update jetty-core/jetty-ee/src/main/java/org/eclipse/jetty/ee/WebappClassLoading.java * fixed OSGi tests * Ensure default hidden server and system classes. * Fixed ee9 OSGi to load jetty-ee * Adding more deprecations * Changing XML demos/tests to use new getter names * rollback xml changes in ee9/ee8 * Fix ee8 maven plugin * Make jetty-maven dependency optional in ee9 to match ee10 --------- Co-authored-by: Joakim Erdfelt Co-authored-by: gregw --- jetty-core/jetty-maven/pom.xml | 122 +++++ .../jetty/maven/AbstractForkedChild.java | 208 +++++++++ .../eclipse/jetty/maven}/AbstractForker.java | 2 +- .../jetty/maven/AbstractHomeForker.java | 428 ++++++++++++++++++ .../jetty/maven/AbstractJettyEmbedder.java | 284 ++++++++++++ .../jetty/maven/AbstractServerForker.java | 276 +++++++++++ .../eclipse/jetty/maven}/ConsoleReader.java | 2 +- .../jetty/maven}/MavenProjectHelper.java | 4 +- .../eclipse/jetty/maven}/MavenResource.java | 2 +- .../jetty/maven}/MavenServerConnector.java | 2 +- .../org/eclipse/jetty/maven}/Overlay.java | 2 +- .../eclipse/jetty/maven}/OverlayConfig.java | 2 +- .../eclipse/jetty/maven}/OverlayManager.java | 38 +- .../org/eclipse/jetty/maven}/PluginLog.java | 2 +- .../org/eclipse/jetty/maven}/ScanPattern.java | 2 +- .../jetty/maven}/ScanTargetPattern.java | 2 +- .../jetty/maven}/SelectiveJarResource.java | 2 +- .../jetty/maven}/ServerConnectorListener.java | 2 +- .../eclipse/jetty/maven}/ServerListener.java | 2 +- .../eclipse/jetty/maven}/ServerSupport.java | 14 +- .../eclipse/jetty/maven}/WarPluginInfo.java | 2 +- jetty-core/pom.xml | 1 + jetty-ee10/jetty-ee10-maven-plugin/pom.xml | 5 + .../src/main/jetty/jetty.xml | 2 +- .../src/config/jetty.xml | 2 +- .../web/src/config/jetty.xml | 2 +- .../MyWebApp/src/config/jetty.xml | 2 +- .../src/base/etc/test-jetty-ee10.xml | 2 +- .../jetty-simple-webapp/src/config/jetty.xml | 2 +- .../beer-server/src/config/jetty.xml | 2 +- .../jetty-simple-webapp/pom.xml | 2 +- .../jetty-simple-webapp/src/config/jetty.xml | 2 +- .../webapp-war/src/config/jetty.xml | 2 +- .../jetty-simple-webapp/src/config/jetty.xml | 2 +- .../src/base/etc/test-jetty-ee10.xml | 2 +- .../jetty-simple-webapp/src/config/jetty.xml | 2 +- .../src/config/jetty.xml | 2 +- .../ee10/maven/plugin/AbstractForker.java | 251 ---------- .../plugin/AbstractUnassembledWebAppMojo.java | 5 +- .../ee10/maven/plugin/AbstractWebAppMojo.java | 7 +- .../ee10/maven/plugin/ConsoleReader.java | 66 --- .../ee10/maven/plugin/JettyEmbedder.java | 261 +---------- .../ee10/maven/plugin/JettyForkedChild.java | 165 +------ .../jetty/ee10/maven/plugin/JettyForker.java | 246 +--------- .../ee10/maven/plugin/JettyHomeForker.java | 373 +-------------- .../jetty/ee10/maven/plugin/JettyRunMojo.java | 3 +- .../ee10/maven/plugin/JettyRunWarMojo.java | 3 +- .../ee10/maven/plugin/MavenResource.java | 220 --------- .../maven/plugin/MavenServerConnector.java | 221 --------- .../ee10/maven/plugin/MavenWebAppContext.java | 1 + .../jetty/ee10/maven/plugin/Overlay.java | 103 ----- .../ee10/maven/plugin/OverlayConfig.java | 337 -------------- .../ee10/maven/plugin/OverlayManager.java | 163 ------- .../jetty/ee10/maven/plugin/PluginLog.java | 37 -- .../maven/plugin/QuickStartGenerator.java | 4 +- .../jetty/ee10/maven/plugin/ScanPattern.java | 48 -- .../ee10/maven/plugin/ScanTargetPattern.java | 108 ----- .../maven/plugin/SelectiveJarResource.java | 280 ------------ .../maven/plugin/ServerConnectorListener.java | 111 ----- .../ee10/maven/plugin/ServerListener.java | 59 --- .../ee10/maven/plugin/ServerSupport.java | 236 ---------- .../ee10/maven/plugin/WarPluginInfo.java | 239 ---------- .../plugin/utils/MavenProjectHelper.java | 185 -------- .../src/main/resources/ee10-maven.mod | 2 +- .../src/main/resources/jetty-ee10-maven.xml | 2 +- .../ee10/maven/plugin/TestForkedChild.java | 2 +- .../ee10/maven/plugin/TestJettyEmbedder.java | 4 +- .../plugin/TestSelectiveJarResource.java | 1 + jetty-ee8/jetty-ee8-maven-plugin/pom.xml | 4 + .../src/main/jetty/jetty.xml | 2 +- .../web/src/config/jetty.xml | 2 +- .../MyWebApp/src/config/jetty.xml | 2 +- .../src/base/etc/test-jetty-ee8.xml | 2 +- .../jetty-simple-webapp/src/config/jetty.xml | 2 +- .../beer-server/src/config/jetty.xml | 2 +- .../jetty-simple-webapp/pom.xml | 2 +- .../jetty-simple-webapp/src/config/jetty.xml | 2 +- .../webapp-war/src/config/jetty.xml | 2 +- .../src/base/etc/test-jetty-ee8.xml | 2 +- .../jetty-simple-webapp/src/config/jetty.xml | 2 +- .../src/config/jetty.xml | 2 +- .../src/main/resources/ee8-maven.mod | 2 +- .../src/main/resources/jetty-ee8-maven.xml | 2 +- jetty-ee9/jetty-ee9-maven-plugin/pom.xml | 5 + .../src/main/jetty/jetty.xml | 2 +- .../src/config/jetty.xml | 2 +- .../webapp-war/src/config/jetty.xml | 2 +- .../web/src/config/jetty.xml | 2 +- .../MyWebApp/src/config/jetty.xml | 2 +- .../src/base/etc/test-jetty-ee9.xml | 2 +- .../jetty-simple-webapp/src/config/jetty.xml | 2 +- .../beer-server/src/config/jetty.xml | 2 +- .../jetty-simple-webapp/pom.xml | 2 +- .../jetty-simple-webapp/src/config/jetty.xml | 2 +- .../webapp-war/src/config/jetty.xml | 2 +- .../jetty-simple-webapp/src/config/jetty.xml | 2 +- .../src/base/etc/test-jetty-ee9.xml | 2 +- .../jetty-simple-webapp/src/config/jetty.xml | 2 +- .../src/config/jetty.xml | 2 +- .../plugin/AbstractUnassembledWebAppMojo.java | 5 +- .../ee9/maven/plugin/AbstractWebAppMojo.java | 7 +- .../jetty/ee9/maven/plugin/JettyEmbedder.java | 257 +---------- .../ee9/maven/plugin/JettyForkedChild.java | 180 +------- .../jetty/ee9/maven/plugin/JettyForker.java | 246 +--------- .../ee9/maven/plugin/JettyHomeForker.java | 387 +--------------- .../jetty/ee9/maven/plugin/JettyRunMojo.java | 3 +- .../ee9/maven/plugin/JettyRunWarMojo.java | 3 +- .../ee9/maven/plugin/MavenWebAppContext.java | 1 + .../ee9/maven/plugin/QuickStartGenerator.java | 6 +- .../src/main/resources/ee9-maven.mod | 2 +- .../src/main/resources/jetty-ee9-maven.xml | 2 +- .../ee9/maven/plugin/TestForkedChild.java | 2 +- .../ee9/maven/plugin/TestJettyEmbedder.java | 4 +- .../plugin/TestSelectiveJarResource.java | 1 + pom.xml | 5 + 115 files changed, 1555 insertions(+), 4800 deletions(-) create mode 100644 jetty-core/jetty-maven/pom.xml create mode 100644 jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractForkedChild.java rename {jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin => jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven}/AbstractForker.java (99%) create mode 100644 jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractHomeForker.java create mode 100644 jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractJettyEmbedder.java create mode 100644 jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractServerForker.java rename {jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin => jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven}/ConsoleReader.java (97%) rename {jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/utils => jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven}/MavenProjectHelper.java (97%) rename {jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin => jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven}/MavenResource.java (99%) rename {jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin => jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven}/MavenServerConnector.java (99%) rename {jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin => jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven}/Overlay.java (98%) rename {jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin => jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven}/OverlayConfig.java (99%) rename {jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin => jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven}/OverlayManager.java (77%) rename {jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin => jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven}/PluginLog.java (95%) rename {jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin => jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven}/ScanPattern.java (96%) rename {jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin => jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven}/ScanTargetPattern.java (98%) rename {jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin => jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven}/SelectiveJarResource.java (99%) rename {jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin => jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven}/ServerConnectorListener.java (98%) rename {jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin => jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven}/ServerListener.java (97%) rename {jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin => jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven}/ServerSupport.java (95%) rename {jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin => jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven}/WarPluginInfo.java (99%) delete mode 100644 jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractForker.java delete mode 100644 jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ConsoleReader.java delete mode 100644 jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenResource.java delete mode 100644 jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenServerConnector.java delete mode 100644 jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/Overlay.java delete mode 100644 jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayConfig.java delete mode 100644 jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayManager.java delete mode 100644 jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/PluginLog.java delete mode 100644 jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ScanPattern.java delete mode 100644 jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ScanTargetPattern.java delete mode 100644 jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/SelectiveJarResource.java delete mode 100644 jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerConnectorListener.java delete mode 100644 jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerListener.java delete mode 100644 jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerSupport.java delete mode 100644 jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/WarPluginInfo.java delete mode 100644 jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/utils/MavenProjectHelper.java diff --git a/jetty-core/jetty-maven/pom.xml b/jetty-core/jetty-maven/pom.xml new file mode 100644 index 00000000000..b2aea6afb32 --- /dev/null +++ b/jetty-core/jetty-maven/pom.xml @@ -0,0 +1,122 @@ + + + 4.0.0 + + org.eclipse.jetty + jetty-core + 12.0.9-SNAPSHOT + + jetty-maven + Core :: Maven + + ${project.groupId}.maven + org.eclipse.jetty.maven.* + + + + org.apache.maven.plugin-tools + maven-plugin-tools-api + + + org.codehaus.plexus + plexus-xml + + + org.apache.maven + maven-api-xml + + + org.apache.maven + maven-xml-impl + + + org.apache.maven + maven-xml-meta + + + + + org.eclipse.jetty + jetty-jmx + true + + + org.eclipse.jetty + jetty-security + + + org.eclipse.jetty + jetty-server + + + org.eclipse.jetty + jetty-util + + + org.eclipse.jetty + jetty-xml + + + org.slf4j + slf4j-api + + + org.apache.maven + maven-artifact + provided + + + org.apache.maven + maven-core + provided + + + javax.annotation + javax.annotation-api + + + + + org.apache.maven + maven-model + provided + + + org.apache.maven + maven-plugin-api + provided + + + javax.annotation + javax.annotation-api + + + + + org.awaitility + awaitility + test + + + org.eclipse.jetty + jetty-slf4j-impl + test + + + org.eclipse.jetty.toolchain + jetty-test-helper + test + + + + + + maven-surefire-plugin + + @{argLine} ${jetty.surefire.argLine} + --add-reads org.eclipse.jetty.maven=org.eclipse.jetty.logging + + + + + diff --git a/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractForkedChild.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractForkedChild.java new file mode 100644 index 00000000000..b76bf023825 --- /dev/null +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractForkedChild.java @@ -0,0 +1,208 @@ +// +// ======================================================================== +// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.maven; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Properties; +import java.util.Set; + +import org.eclipse.jetty.util.Scanner; +import org.eclipse.jetty.util.StringUtil; +import org.eclipse.jetty.util.component.ContainerLifeCycle; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * JettyForkedChild + * + * This is the class that is executed when the jetty maven plugin + * forks a process when DeploymentMode=FORKED. + */ +public abstract class AbstractForkedChild extends ContainerLifeCycle +{ + private static final Logger LOG = LoggerFactory.getLogger(AbstractForkedChild.class); + + protected AbstractJettyEmbedder jetty; + protected File tokenFile; // TODO: convert to Path + protected Scanner scanner; + protected File webAppPropsFile; // TODO: convert to Path + protected int scanInterval; + + /** + * @param args arguments that were passed to main + * @throws Exception if unable to configure + */ + public AbstractForkedChild(String[] args) + throws Exception + { + jetty = newJettyEmbedder(); + configure(args); + } + + public AbstractJettyEmbedder getJettyEmbedder() + { + return jetty; + } + + protected abstract AbstractJettyEmbedder newJettyEmbedder(); + + /** + * Based on the args passed to the program, configure jetty. + * + * @param args args that were passed to the program. + * @throws Exception if unable to load webprops + */ + public void configure(String[] args) + throws Exception + { + Map jettyProperties = new HashMap<>(); + + for (int i = 0; i < args.length; i++) + { + //--stop-port + if ("--stop-port".equals(args[i])) + { + jetty.setStopPort(Integer.parseInt(args[++i])); + continue; + } + + //--stop-key + if ("--stop-key".equals(args[i])) + { + jetty.setStopKey(args[++i]); + continue; + } + + //--jettyXml + if ("--jetty-xml".equals(args[i])) + { + List jettyXmls = new ArrayList<>(); + String[] names = StringUtil.csvSplit(args[++i]); + for (int j = 0; names != null && j < names.length; j++) + { + jettyXmls.add(new File(names[j].trim())); + } + jetty.setJettyXmlFiles(jettyXmls); + continue; + } + //--webprops + if ("--webprops".equals(args[i])) + { + webAppPropsFile = new File(args[++i].trim()); + jetty.setWebAppProperties(loadWebAppProps()); + continue; + } + + //--token + if ("--token".equals(args[i])) + { + tokenFile = new File(args[++i].trim()); + continue; + } + + if ("--scanInterval".equals(args[i])) + { + scanInterval = Integer.parseInt(args[++i].trim()); + scanner = new Scanner(); + scanner.setReportExistingFilesOnStartup(false); + scanner.setScanInterval(scanInterval); + scanner.addListener(new Scanner.BulkListener() + { + public void filesChanged(Set changes) + { + if (!Objects.isNull(scanner)) + { + try + { + scanner.stop(); + jetty.redeployWebApp(loadWebAppProps()); + scanner.start(); + } + catch (Exception e) + { + LOG.error("Error reconfiguring/restarting webapp after change in watched files", e); + } + } + } + }); + + if (!Objects.isNull(webAppPropsFile)) + scanner.addFile(webAppPropsFile.toPath()); + continue; + } + + //assume everything else is a jetty property to be passed in + String[] tmp = args[i].trim().split("="); + if (tmp.length == 2) + { + jettyProperties.put(tmp[0], tmp[1]); + } + } + + jetty.setJettyProperties(jettyProperties); + jetty.setExitVm(true); + } + + /** + * Load properties from a file describing the webapp if one is + * present. + * + * @return file contents as properties + * @throws FileNotFoundException if there is a file not found problem + * @throws IOException if there is an IO problem + */ + protected Properties loadWebAppProps() throws FileNotFoundException, IOException + { + Properties props = new Properties(); + if (Objects.nonNull(webAppPropsFile)) + props.load(new FileInputStream(webAppPropsFile)); + return props; + } + + /** + * Start a jetty instance and webapp. This thread will + * wait until jetty exits. + */ + public void doStart() + throws Exception + { + super.doStart(); + + //Start the embedded jetty instance + jetty.start(); + + //touch file to signify start of jetty + Path tokenPath = tokenFile.toPath(); + Files.createFile(tokenPath); + + //Start a watcher on a file that will change if the + //webapp is regenerated; stop the webapp, apply the + //properties and restart it. + if (scanner != null) + scanner.start(); + + //wait for jetty to finish + jetty.join(); + } +} diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractForker.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractForker.java similarity index 99% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractForker.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractForker.java index 10ad7784a15..fc7947a62f3 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractForker.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractForker.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.io.File; import java.util.List; diff --git a/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractHomeForker.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractHomeForker.java new file mode 100644 index 00000000000..1e2ce6a45f3 --- /dev/null +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractHomeForker.java @@ -0,0 +1,428 @@ +// +// ======================================================================== +// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.maven; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.FileSystems; +import java.nio.file.FileVisitOption; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; +import java.util.Map; + +import org.eclipse.jetty.util.IO; +import org.eclipse.jetty.util.StringUtil; +import org.eclipse.jetty.util.TypeUtil; +import org.eclipse.jetty.util.resource.Resource; +import org.eclipse.jetty.util.resource.ResourceFactory; + +/** + * AbstractHomeForker + * + * Unpacks a jetty-home and configures it with a base that allows it + * to run an unassembled webapp. + */ +public abstract class AbstractHomeForker extends AbstractForker +{ + protected String contextXml; + + /** + * Location of existing jetty home directory + */ + protected File jettyHome; + + /** + * Zip of jetty-home + */ + protected File jettyHomeZip; + + /** + * Location of existing jetty base directory + */ + protected File jettyBase; + + protected File baseDir; + + /** + * Optional list of other modules to + * activate. + */ + protected String[] modules; + + /* + * Optional jetty commands + */ + protected String jettyOptions; + + protected List libExtJarFiles; + protected Path modulesPath; + protected Path etcPath; + protected Path libPath; + protected Path webappPath; + protected Path mavenLibPath; + protected String version; + protected String environment; + + public void setVersion(String version) + { + this.version = version; + } + + public void setJettyOptions(String jettyOptions) + { + this.jettyOptions = jettyOptions; + } + + public String getJettyOptions() + { + return jettyOptions; + } + + public List getLibExtJarFiles() + { + return libExtJarFiles; + } + + public void setLibExtJarFiles(List libExtJarFiles) + { + this.libExtJarFiles = libExtJarFiles; + } + + public File getJettyHome() + { + return jettyHome; + } + + public void setJettyHome(File jettyHome) + { + this.jettyHome = jettyHome; + } + + public File getJettyBase() + { + return jettyBase; + } + + public void setJettyBase(File jettyBase) + { + this.jettyBase = jettyBase; + } + + public String[] getModules() + { + return modules; + } + + public void setModules(String[] modules) + { + this.modules = modules; + } + + public String getContextXmlFile() + { + return contextXml; + } + + public void setContextXml(String contextXml) + { + this.contextXml = contextXml; + } + + public File getJettyHomeZip() + { + return jettyHomeZip; + } + + public void setJettyHomeZip(File jettyHomeZip) + { + this.jettyHomeZip = jettyHomeZip; + } + + public File getBaseDir() + { + return baseDir; + } + + public void setBaseDir(File baseDir) + { + this.baseDir = baseDir; + } + + @Override + protected ProcessBuilder createCommand() + { + List cmd = new ArrayList<>(); + cmd.add("java"); + + //add any args to the jvm + if (StringUtil.isNotBlank(jvmArgs)) + { + Arrays.stream(jvmArgs.split(" ")).filter(a -> StringUtil.isNotBlank(a)).forEach((a) -> cmd.add(a.trim())); + } + + cmd.add("-jar"); + cmd.add(new File(jettyHome, "start.jar").getAbsolutePath()); + + if (systemProperties != null) + { + for (Map.Entry e : systemProperties.entrySet()) + { + cmd.add("-D" + e.getKey() + "=" + e.getValue()); + } + } + + cmd.add("-DSTOP.PORT=" + stopPort); + if (stopKey != null) + cmd.add("-DSTOP.KEY=" + stopKey); + + //set up enabled jetty modules + StringBuilder tmp = new StringBuilder(); + tmp.append("--module="); + tmp.append("server,http," + environment + "-webapp," + environment + "-deploy"); + if (modules != null) + { + for (String m : modules) + { + if (tmp.indexOf(m) < 0) + tmp.append("," + m); + } + } + + if (libExtJarFiles != null && !libExtJarFiles.isEmpty() && tmp.indexOf("ext") < 0) + tmp.append(",ext"); + tmp.append("," + environment + "-maven"); + cmd.add(tmp.toString()); + + //put any other jetty options onto the command line + if (StringUtil.isNotBlank(jettyOptions)) + { + Arrays.stream(jettyOptions.split(" ")).filter(a -> StringUtil.isNotBlank(a)).forEach((a) -> cmd.add(a.trim())); + } + + //put any jetty properties onto the command line + if (jettyProperties != null) + { + for (Map.Entry e : jettyProperties.entrySet()) + { + cmd.add(e.getKey() + "=" + e.getValue()); + } + } + + //existence of this file signals process started + cmd.add("jetty.token.file=" + tokenFile.getAbsolutePath().toString()); + + ProcessBuilder builder = new ProcessBuilder(cmd); + builder.directory(workDir); + + PluginLog.getLog().info("Home process starting"); + + //set up extra environment vars if there are any + if (!env.isEmpty()) + builder.environment().putAll(env); + + if (waitForChild) + builder.inheritIO(); + else + { + builder.redirectOutput(jettyOutputFile); + builder.redirectErrorStream(true); + } + return builder; + } + + @Override + public void doStart() throws Exception + { + //set up a jetty-home + configureJettyHome(); + + if (jettyHome == null || !jettyHome.exists()) + throw new IllegalStateException("No jetty home"); + + //set up a jetty-base + configureJettyBase(); + + //convert the webapp to properties + generateWebAppPropertiesFile(); + + super.doStart(); + } + + protected void redeployWebApp() + throws Exception + { + generateWebAppPropertiesFile(); + webappPath.resolve("maven.xml").toFile().setLastModified(System.currentTimeMillis()); + } + + protected abstract void generateWebAppPropertiesFile() throws Exception; + + /** + * Create or configure a jetty base. + */ + private void configureJettyBase() throws Exception + { + if (jettyBase != null && !jettyBase.exists()) + throw new IllegalStateException(jettyBase.getAbsolutePath() + " does not exist"); + + File targetJettyBase = new File(baseDir, "jetty-base"); + Path targetBasePath = targetJettyBase.toPath(); + if (Files.exists(targetBasePath)) + IO.delete(targetJettyBase); + + targetJettyBase.mkdirs(); + + //jetty-base will be the working directory for the forked command + workDir = targetJettyBase; + + //if there is an existing jetty base, copy parts of it + if (jettyBase != null) + { + Path jettyBasePath = jettyBase.toPath(); + + final File contextXmlFile = (contextXml == null ? null : FileSystems.getDefault().getPath(contextXml).toFile()); + + //copy the existing jetty base + Files.walkFileTree(jettyBasePath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, + new SimpleFileVisitor() + { + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException + { + Path targetDir = targetBasePath.resolve(jettyBasePath.relativize(dir)); + try + { + Files.copy(dir, targetDir); + } + catch (FileAlreadyExistsException e) + { + if (!Files.isDirectory(targetDir)) //ignore attempt to recreate dir + throw e; + } + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException + { + if (contextXmlFile != null && Files.isSameFile(contextXmlFile.toPath(), file)) + return FileVisitResult.CONTINUE; //skip copying the context xml file + Files.copy(file, targetBasePath.resolve(jettyBasePath.relativize(file))); + return FileVisitResult.CONTINUE; + } + }); + } + + //make the jetty base structure + modulesPath = Files.createDirectories(targetBasePath.resolve("modules")); + etcPath = Files.createDirectories(targetBasePath.resolve("etc")); + libPath = Files.createDirectories(targetBasePath.resolve("lib")); + webappPath = Files.createDirectories(targetBasePath.resolve("webapps")); + mavenLibPath = Files.createDirectories(libPath.resolve(environment + "-maven")); + + //copy in the jetty-${ee}-maven-plugin jar + URI thisJar = TypeUtil.getLocationOfClass(this.getClass()); + if (thisJar == null) + throw new IllegalStateException("Can't find jar for jetty-" + environment + "-maven-plugin"); + + try (InputStream jarStream = thisJar.toURL().openStream(); + FileOutputStream fileStream = new FileOutputStream(mavenLibPath.resolve("jetty-" + environment + "-maven-plugin.jar").toFile())) + { + IO.copy(jarStream, fileStream); + } + + //copy in the jetty-maven.jar for common classes + URI commonJar = TypeUtil.getLocationOfClass(AbstractHomeForker.class); + if (commonJar == null) + throw new IllegalStateException("Can't find jar for jetty-maven common classes"); + try (InputStream jarStream = commonJar.toURL().openStream(); + FileOutputStream fileStream = new FileOutputStream(mavenLibPath.resolve("jetty-maven.jar").toFile())) + { + IO.copy(jarStream, fileStream); + } + + //copy in the maven-${ee}.xml webapp file + String mavenXml = "maven-" + environment + ".xml"; + try (InputStream mavenXmlStream = getClass().getClassLoader().getResourceAsStream(mavenXml); + FileOutputStream fileStream = new FileOutputStream(webappPath.resolve(mavenXml).toFile())) + { + IO.copy(mavenXmlStream, fileStream); + } + + Files.writeString(webappPath.resolve("maven-" + environment + ".properties"), "environment=" + environment); + + //copy in the ${ee}-maven.mod file + String mavenMod = environment + "-maven.mod"; + try (InputStream mavenModStream = getClass().getClassLoader().getResourceAsStream(mavenMod); + FileOutputStream fileStream = new FileOutputStream(modulesPath.resolve(mavenMod).toFile())) + { + IO.copy(mavenModStream, fileStream); + } + + //copy in the jetty-${ee}-maven.xml file + String jettyMavenXml = "jetty-" + environment + "-maven.xml"; + try (InputStream jettyMavenStream = getClass().getClassLoader().getResourceAsStream(jettyMavenXml); + FileOutputStream fileStream = new FileOutputStream(etcPath.resolve(jettyMavenXml).toFile())) + { + IO.copy(jettyMavenStream, fileStream); + } + + //if there were plugin dependencies, copy them into lib/ext + if (libExtJarFiles != null && !libExtJarFiles.isEmpty()) + { + Path libExtPath = Files.createDirectories(libPath.resolve("ext")); + for (File f : libExtJarFiles) + { + try (InputStream jarStream = new FileInputStream(f); + FileOutputStream fileStream = new FileOutputStream(libExtPath.resolve(f.getName()).toFile())) + { + IO.copy(jarStream, fileStream); + } + } + } + } + + private void configureJettyHome() + throws Exception + { + if (jettyHome == null && jettyHomeZip == null) + throw new IllegalStateException("No jettyHome"); + + if (baseDir == null) + throw new IllegalStateException("No baseDir"); + + if (jettyHome == null) + { + try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable()) + { + Resource res = resourceFactory.newJarFileResource(jettyHomeZip.toPath().toUri()); + res.copyTo(baseDir.toPath()); + } + //zip will unpack to target/jetty-home- + jettyHome = new File(baseDir, "jetty-home-" + version); + } + } +} diff --git a/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractJettyEmbedder.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractJettyEmbedder.java new file mode 100644 index 00000000000..aa25e00d082 --- /dev/null +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractJettyEmbedder.java @@ -0,0 +1,284 @@ +// +// ======================================================================== +// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.maven; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.eclipse.jetty.security.LoginService; +import org.eclipse.jetty.server.RequestLog; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ShutdownMonitor; +import org.eclipse.jetty.server.handler.ContextHandler; +import org.eclipse.jetty.util.component.ContainerLifeCycle; + +/** + * AbstractJettyEmbedder + * Starts jetty within the current process. + */ +public abstract class AbstractJettyEmbedder extends ContainerLifeCycle +{ + protected List contextHandlers; + protected List loginServices; + protected RequestLog requestLog; + protected MavenServerConnector httpConnector; + protected Server server; + protected boolean exitVm; + protected boolean stopAtShutdown; + protected List jettyXmlFiles; + protected Map jettyProperties; + protected ShutdownMonitor shutdownMonitor; + protected int stopPort; + protected String stopKey; + protected String contextXml; + protected Properties webAppProperties; + + public List getContextHandlers() + { + return contextHandlers; + } + + public void setContextHandlers(List contextHandlers) + { + if (contextHandlers == null) + this.contextHandlers = null; + else + this.contextHandlers = new ArrayList<>(contextHandlers); + } + + public List getLoginServices() + { + return loginServices; + } + + public void setLoginServices(List loginServices) + { + if (loginServices == null) + this.loginServices = null; + else + this.loginServices = new ArrayList<>(loginServices); + } + + public RequestLog getRequestLog() + { + return requestLog; + } + + public void setRequestLog(RequestLog requestLog) + { + this.requestLog = requestLog; + } + + public MavenServerConnector getHttpConnector() + { + return httpConnector; + } + + public void setHttpConnector(MavenServerConnector httpConnector) + { + this.httpConnector = httpConnector; + } + + public Server getServer() + { + return server; + } + + public void setServer(Server server) + { + this.server = server; + } + + public boolean isExitVm() + { + return exitVm; + } + + public void setExitVm(boolean exitVm) + { + this.exitVm = exitVm; + } + + public boolean isStopAtShutdown() + { + return stopAtShutdown; + } + + public void setStopAtShutdown(boolean stopAtShutdown) + { + this.stopAtShutdown = stopAtShutdown; + } + + public List getJettyXmlFiles() + { + return jettyXmlFiles; + } + + public void setJettyXmlFiles(List jettyXmlFiles) + { + this.jettyXmlFiles = jettyXmlFiles; + } + + public Map getJettyProperties() + { + return jettyProperties; + } + + public void setJettyProperties(Map jettyProperties) + { + this.jettyProperties = jettyProperties; + } + + public ShutdownMonitor getShutdownMonitor() + { + return shutdownMonitor; + } + + public void setShutdownMonitor(ShutdownMonitor shutdownMonitor) + { + this.shutdownMonitor = shutdownMonitor; + } + + public int getStopPort() + { + return stopPort; + } + + public void setStopPort(int stopPort) + { + this.stopPort = stopPort; + } + + public String getStopKey() + { + return stopKey; + } + + public void setStopKey(String stopKey) + { + this.stopKey = stopKey; + } + + public void setWebAppProperties(Properties props) + { + if (webAppProperties != null) + webAppProperties.clear(); + + if (props != null) + { + if (webAppProperties == null) + webAppProperties = new Properties(); + + webAppProperties.putAll(props); + } + } + + public String getContextXml() + { + return contextXml; + } + + public void setContextXml(String contextXml) + { + this.contextXml = contextXml; + } + + public void doStart() throws Exception + { + super.doStart(); + + configure(); + configureShutdownMonitor(); + server.start(); + } + + protected abstract void redeployWebApp() throws Exception; + + public void redeployWebApp(Properties webaAppProperties) throws Exception + { + setWebAppProperties(webaAppProperties); + redeployWebApp(); + } + + public abstract void stopWebApp() throws Exception; + + public void join() throws InterruptedException + { + server.join(); + } + + /** + * Configure the server and the webapp + * @throws Exception if there is an unspecified problem + */ + protected void configure() throws Exception + { + configureServer(); + configureWebApp(); + addWebAppToServer(); + } + + protected void configureServer() throws Exception + { + //apply any configs from jetty.xml files first + Server tmp = ServerSupport.applyXmlConfigurations(new Server(), jettyXmlFiles, jettyProperties); + + if (tmp != null) + server = tmp; + + server.setStopAtShutdown(stopAtShutdown); + + //ensure there's a connector + if (httpConnector != null) + httpConnector.setServer(server); + + ServerSupport.configureConnectors(server, httpConnector, jettyProperties); + + //set up handler structure + ServerSupport.configureHandlers(server, contextHandlers, requestLog); + + // set up security realms + ServerSupport.configureLoginServices(server, loginServices); + } + + protected abstract void configureWebApp() throws Exception; + + protected abstract void addWebAppToServer() throws Exception; + + protected void applyWebAppProperties() throws Exception + { + //apply properties to the webapp if there are any + if (contextXml != null) + { + if (webAppProperties == null) + webAppProperties = new Properties(); + + webAppProperties.put("context.xml", contextXml); + } + } + + private void configureShutdownMonitor() + { + if (stopPort > 0 && stopKey != null) + { + ShutdownMonitor monitor = ShutdownMonitor.getInstance(); + monitor.setPort(stopPort); + monitor.setKey(stopKey); + monitor.setExitVm(exitVm); + } + } +} diff --git a/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractServerForker.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractServerForker.java new file mode 100644 index 00000000000..df8e433eebd --- /dev/null +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/AbstractServerForker.java @@ -0,0 +1,276 @@ +// +// ======================================================================== +// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.maven; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.eclipse.jetty.server.Server; + +/** + * AbstractServerForker + * + * Fork a jetty Server + */ +public abstract class AbstractServerForker extends AbstractForker +{ + protected File forkWebXml; + protected Server server; + protected String containerClassPath; + protected File webAppPropsFile; + protected String contextXml; + protected int scanInterval; + protected String executionClassName; + + /** + * @return the scan + */ + public boolean isScan() + { + return scanInterval > 0; + } + + /** + * Set if true, the forked child will scan for changes at 1 second intervals. + * @param scan if true, the forked child will scan for changes at 1 second intervals + */ + public void setScan(boolean scan) + { + setScanInterval(scan ? 1 : 0); + } + + public int getScanInterval() + { + return scanInterval; + } + + public void setScanInterval(int sec) + { + scanInterval = sec; + } + + public File getWebAppPropsFile() + { + return webAppPropsFile; + } + + public void setWebAppPropsFile(File webAppPropsFile) + { + this.webAppPropsFile = webAppPropsFile; + } + + public File getForkWebXml() + { + return forkWebXml; + } + + public void setForkWebXml(File forkWebXml) + { + this.forkWebXml = forkWebXml; + } + + public String getContextXml() + { + return contextXml; + } + + public void setContextXml(String contextXml) + { + this.contextXml = contextXml; + } + + public String getContainerClassPath() + { + return containerClassPath; + } + + public void setContainerClassPath(String containerClassPath) + { + this.containerClassPath = containerClassPath; + } + + public Server getServer() + { + return server; + } + + public void setServer(Server server) + { + this.server = server; + } + + @Override + public void doStart() + throws Exception + { + generateWebApp(); + super.doStart(); + } + + protected abstract void generateWebApp() throws Exception; + + protected abstract void redeployWebApp() throws Exception; + + public ProcessBuilder createCommand() + { + List cmd = new ArrayList(); + cmd.add(getJavaBin()); + + if (jvmArgs != null) + { + String[] args = jvmArgs.split(" "); + for (int i = 0; args != null && i < args.length; i++) + { + if (args[i] != null && !"".equals(args[i])) + cmd.add(args[i].trim()); + } + } + + if (systemProperties != null) + { + for (Map.Entry e:systemProperties.entrySet()) + { + cmd.add("-D" + e.getKey() + "=" + e.getValue()); + } + } + + if (containerClassPath != null && containerClassPath.length() > 0) + { + cmd.add("-cp"); + cmd.add(containerClassPath); + } + + cmd.add(executionClassName); + + if (stopPort > 0 && stopKey != null) + { + cmd.add("--stop-port"); + cmd.add(Integer.toString(stopPort)); + cmd.add("--stop-key"); + cmd.add(stopKey); + } + if (jettyXmlFiles != null) + { + cmd.add("--jetty-xml"); + StringBuilder tmp = new StringBuilder(); + for (File jettyXml:jettyXmlFiles) + { + if (tmp.length() != 0) + tmp.append(","); + tmp.append(jettyXml.getAbsolutePath()); + } + cmd.add(tmp.toString()); + } + + cmd.add("--webprops"); + cmd.add(webAppPropsFile.getAbsolutePath()); + + cmd.add("--token"); + cmd.add(tokenFile.getAbsolutePath()); + + if (scanInterval > 0) + { + cmd.add("--scanInterval"); + cmd.add(Integer.toString(scanInterval)); + } + + if (jettyProperties != null) + { + for (Map.Entry e:jettyProperties.entrySet()) + { + cmd.add(e.getKey() + "=" + e.getValue()); + } + } + + ProcessBuilder command = new ProcessBuilder(cmd); + command.directory(workDir); + + if (PluginLog.getLog().isDebugEnabled()) + PluginLog.getLog().debug("Forked cli:" + command.command()); + + PluginLog.getLog().info("Forked process starting"); + + //set up extra environment vars if there are any + if (env != null && !env.isEmpty()) + command.environment().putAll(env); + + if (waitForChild) + { + command.inheritIO(); + } + else + { + command.redirectOutput(jettyOutputFile); + command.redirectErrorStream(true); + } + return command; + } + + /** + * Get the location of the java binary. + * @return the location of the java binary + */ + private String getJavaBin() + { + String[] javaexes = new String[]{"java", "java.exe"}; + + File javaHomeDir = new File(System.getProperty("java.home")); + for (String javaexe : javaexes) + { + File javabin = new File(javaHomeDir, fileSeparators("bin/" + javaexe)); + if (javabin.exists() && javabin.isFile()) + { + return javabin.getAbsolutePath(); + } + } + + return "java"; + } + + public static String fileSeparators(String path) + { + StringBuilder ret = new StringBuilder(); + for (char c : path.toCharArray()) + { + if ((c == '/') || (c == '\\')) + { + ret.append(File.separatorChar); + } + else + { + ret.append(c); + } + } + return ret.toString(); + } + + public static String pathSeparators(String path) + { + StringBuilder ret = new StringBuilder(); + for (char c : path.toCharArray()) + { + if ((c == ',') || (c == ':')) + { + ret.append(File.pathSeparatorChar); + } + else + { + ret.append(c); + } + } + return ret.toString(); + } +} diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ConsoleReader.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ConsoleReader.java similarity index 97% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ConsoleReader.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ConsoleReader.java index 761eb546189..9c708e11a99 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ConsoleReader.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ConsoleReader.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.io.Console; import java.util.EventListener; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/utils/MavenProjectHelper.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/MavenProjectHelper.java similarity index 97% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/utils/MavenProjectHelper.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/MavenProjectHelper.java index b336f55debd..54dcc0ad1b6 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/utils/MavenProjectHelper.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/MavenProjectHelper.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin.utils; +package org.eclipse.jetty.maven; import java.io.File; import java.nio.file.Path; @@ -35,8 +35,6 @@ import org.eclipse.aether.artifact.DefaultArtifact; import org.eclipse.aether.resolution.ArtifactRequest; import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.aether.resolution.ArtifactResult; -import org.eclipse.jetty.ee9.maven.plugin.OverlayManager; -import org.eclipse.jetty.ee9.maven.plugin.WarPluginInfo; /** * MavenProjectHelper diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenResource.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/MavenResource.java similarity index 99% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenResource.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/MavenResource.java index 78d6783cc5a..42475de50fd 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenResource.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/MavenResource.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.io.IOException; import java.io.InputStream; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenServerConnector.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/MavenServerConnector.java similarity index 99% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenServerConnector.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/MavenServerConnector.java index a44816ef2ce..d0a482cc9e7 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenServerConnector.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/MavenServerConnector.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.util.Collection; import java.util.List; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/Overlay.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/Overlay.java similarity index 98% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/Overlay.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/Overlay.java index cb9529783d3..a1b51e3d0e6 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/Overlay.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/Overlay.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.io.File; import java.io.IOException; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayConfig.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/OverlayConfig.java similarity index 99% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayConfig.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/OverlayConfig.java index f31016a69ac..4bbec73160b 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayConfig.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/OverlayConfig.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.util.ArrayList; import java.util.Arrays; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayManager.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/OverlayManager.java similarity index 77% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayManager.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/OverlayManager.java index 23cfb3672b4..7c024e0931b 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/OverlayManager.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/OverlayManager.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.io.File; import java.io.IOException; @@ -24,7 +24,7 @@ import java.util.Objects; import java.util.Set; import org.apache.maven.artifact.Artifact; -import org.eclipse.jetty.ee9.webapp.WebAppContext; +import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.resource.MountedPathResource; import org.eclipse.jetty.util.resource.Resource; @@ -45,41 +45,41 @@ public class OverlayManager this.warPlugin = warPlugin; } - public void applyOverlays(MavenWebAppContext webApp) + public void applyOverlays(ContextHandler contextHandler, boolean append) throws Exception { List resourceBases = new ArrayList(); - for (Overlay o : getOverlays(webApp)) + for (Overlay o : getOverlays(contextHandler)) { //can refer to the current project in list of overlays for ordering purposes - if (o.getConfig() != null && o.getConfig().isCurrentProject() && webApp.getBaseResource().exists()) + if (o.getConfig() != null && o.getConfig().isCurrentProject() && contextHandler.getBaseResource().exists()) { - resourceBases.add(webApp.getBaseResource()); + resourceBases.add(contextHandler.getBaseResource()); continue; } //add in the selectively unpacked overlay in the correct order to the webapp's resource base - resourceBases.add(unpackOverlay(webApp, o)); + resourceBases.add(unpackOverlay(contextHandler, o)); } - if (!resourceBases.contains(webApp.getBaseResource()) && webApp.getBaseResource().exists()) + if (!resourceBases.contains(contextHandler.getBaseResource()) && contextHandler.getBaseResource().exists()) { - if (webApp.getBaseAppFirst()) - resourceBases.add(0, webApp.getBaseResource()); + if (append) + resourceBases.add(0, contextHandler.getBaseResource()); else - resourceBases.add(webApp.getBaseResource()); + resourceBases.add(contextHandler.getBaseResource()); } - webApp.setBaseResource(ResourceFactory.combine(resourceBases)); + contextHandler.setBaseResource(ResourceFactory.combine(resourceBases)); } /** * Generate an ordered list of overlays */ - protected List getOverlays(WebAppContext webApp) + private List getOverlays(ContextHandler contextHandler) throws Exception { - Objects.requireNonNull(webApp); + Objects.requireNonNull(contextHandler); Set matchedWarArtifacts = new HashSet(); List overlays = new ArrayList(); @@ -104,7 +104,7 @@ public class OverlayManager if (a != null) { matchedWarArtifacts.add(a); - Resource resource = webApp.getResourceFactory().newJarFileResource(a.getFile().toPath().toUri()); + Resource resource = ResourceFactory.of(contextHandler).newJarFileResource(a.getFile().toPath().toUri()); SelectiveJarResource r = new SelectiveJarResource(resource); r.setIncludes(config.getIncludes()); r.setExcludes(config.getExcludes()); @@ -118,7 +118,7 @@ public class OverlayManager { if (!matchedWarArtifacts.contains(a)) { - Resource resource = webApp.getResourceFactory().newJarFileResource(a.getFile().toPath().toUri()); + Resource resource = ResourceFactory.of(contextHandler).newJarFileResource(a.getFile().toPath().toUri()); Overlay overlay = new Overlay(null, resource); overlays.add(overlay); } @@ -133,10 +133,10 @@ public class OverlayManager * @return the location to which it was unpacked * @throws IOException if there is an IO problem */ - protected Resource unpackOverlay(WebAppContext webApp, Overlay overlay) + protected Resource unpackOverlay(ContextHandler contextHandler, Overlay overlay) throws IOException { - Objects.requireNonNull(webApp); + Objects.requireNonNull(contextHandler); Objects.requireNonNull(overlay); if (overlay.getResource() == null) @@ -161,6 +161,6 @@ public class OverlayManager overlay.unpackTo(unpackDir); //use top level of unpacked content - return webApp.getResourceFactory().newResource(unpackDir.getCanonicalPath()); + return ResourceFactory.of(contextHandler).newResource(unpackDir.getCanonicalPath()); } } diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/PluginLog.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/PluginLog.java similarity index 95% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/PluginLog.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/PluginLog.java index 131647b7551..5823846d8bc 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/PluginLog.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/PluginLog.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import org.apache.maven.plugin.logging.Log; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ScanPattern.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ScanPattern.java similarity index 96% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ScanPattern.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ScanPattern.java index 41d0c77be7d..963222fc2dc 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ScanPattern.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ScanPattern.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.util.Collections; import java.util.List; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ScanTargetPattern.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ScanTargetPattern.java similarity index 98% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ScanTargetPattern.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ScanTargetPattern.java index 9523ecca537..5ddcbca2676 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ScanTargetPattern.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ScanTargetPattern.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.io.File; import java.nio.file.Path; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/SelectiveJarResource.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/SelectiveJarResource.java similarity index 99% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/SelectiveJarResource.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/SelectiveJarResource.java index bacf3007535..8e8c44f983e 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/SelectiveJarResource.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/SelectiveJarResource.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.io.IOException; import java.io.InputStream; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ServerConnectorListener.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ServerConnectorListener.java similarity index 98% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ServerConnectorListener.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ServerConnectorListener.java index d8356244887..ba2079670ac 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ServerConnectorListener.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ServerConnectorListener.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.io.Writer; import java.nio.file.AtomicMoveNotSupportedException; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ServerListener.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ServerListener.java similarity index 97% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ServerListener.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ServerListener.java index c57663c95e5..f8cf53dd5ce 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ServerListener.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ServerListener.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.nio.file.Files; import java.nio.file.Path; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ServerSupport.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ServerSupport.java similarity index 95% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ServerSupport.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ServerSupport.java index 079c646ea57..5dd105b260c 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/ServerSupport.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/ServerSupport.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.io.File; import java.util.Enumeration; @@ -19,8 +19,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.eclipse.jetty.ee9.webapp.Configurations; -import org.eclipse.jetty.ee9.webapp.WebAppContext; +import org.eclipse.jetty.maven.MavenServerConnector; +import org.eclipse.jetty.maven.PluginLog; import org.eclipse.jetty.security.LoginService; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.RequestLog; @@ -37,12 +37,6 @@ import org.eclipse.jetty.xml.XmlConfiguration; */ public class ServerSupport { - - public static void configureDefaultConfigurationClasses(Server server) - { - Configurations.setServerDefault(server); - } - /** * Set up the handler structure to receive a webapp. * Also put in a DefaultHandler so we get a nicer page @@ -144,7 +138,7 @@ public class ServerSupport * @param webapp the webapp to add * @throws Exception if there is an unspecified problem */ - public static void addWebApplication(Server server, WebAppContext webapp) throws Exception + public static void addWebApplication(Server server, ContextHandler webapp) throws Exception { if (server == null) throw new IllegalArgumentException("Server is null"); diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/WarPluginInfo.java b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/WarPluginInfo.java similarity index 99% rename from jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/WarPluginInfo.java rename to jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/WarPluginInfo.java index b028a2e70e3..051a33ca345 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/WarPluginInfo.java +++ b/jetty-core/jetty-maven/src/main/java/org/eclipse/jetty/maven/WarPluginInfo.java @@ -11,7 +11,7 @@ // ======================================================================== // -package org.eclipse.jetty.ee9.maven.plugin; +package org.eclipse.jetty.maven; import java.util.ArrayList; import java.util.Collections; diff --git a/jetty-core/pom.xml b/jetty-core/pom.xml index 97f9ff5401c..c5f629994c1 100644 --- a/jetty-core/pom.xml +++ b/jetty-core/pom.xml @@ -28,6 +28,7 @@ jetty-jmx jetty-jndi jetty-keystore + jetty-maven jetty-openid jetty-osgi jetty-plus diff --git a/jetty-ee10/jetty-ee10-maven-plugin/pom.xml b/jetty-ee10/jetty-ee10-maven-plugin/pom.xml index b86cc5b7d50..2d4ed9fe4cb 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/pom.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/pom.xml @@ -81,6 +81,11 @@ jetty-jndi true + + org.eclipse.jetty + jetty-maven + true + org.eclipse.jetty jetty-security diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml index e2575774e66..8a8f26b49f4 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-combinedresource-it/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-combinedresource-it/src/config/jetty.xml index 445b5961914..343f5e7f99b 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-combinedresource-it/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-combinedresource-it/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml index 0a3a743a2c4..ef0c9bcad93 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml @@ -32,7 +32,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml index 657264f3223..58c5b275121 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml @@ -25,7 +25,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee10.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee10.xml index 6ba1c7f8e1f..9857cb546ef 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee10.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee10.xml @@ -5,7 +5,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml index 445b5961914..343f5e7f99b 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml index 445b5961914..343f5e7f99b 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml index 94254ab8f28..521f49c0d94 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml @@ -112,7 +112,7 @@ - + ${basedir}/src/config/login.xml diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml index 445b5961914..343f5e7f99b 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml index 445b5961914..343f5e7f99b 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-overlay-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-overlay-it/jetty-simple-webapp/src/config/jetty.xml index 445b5961914..343f5e7f99b 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-overlay-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-overlay-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee10.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee10.xml index 6ba1c7f8e1f..9857cb546ef 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee10.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee10.xml @@ -5,7 +5,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml index 445b5961914..343f5e7f99b 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml index 445b5961914..343f5e7f99b 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractForker.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractForker.java deleted file mode 100644 index 690611f84a7..00000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractForker.java +++ /dev/null @@ -1,251 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.maven.plugin; - -import java.io.File; -import java.util.List; -import java.util.Map; - -import org.eclipse.jetty.util.component.AbstractLifeCycle; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * AbstractForker - * - * Base class for forking jetty. - */ -public abstract class AbstractForker extends AbstractLifeCycle -{ - private static final Logger LOG = LoggerFactory.getLogger(AbstractForker.class); - - protected Map env; - - protected String jvmArgs; - - protected boolean exitVm; - - protected boolean stopAtShutdown; - - protected List jettyXmlFiles; - - protected Map jettyProperties; - - protected int stopPort; - - protected String stopKey; - - protected File jettyOutputFile; - - protected boolean waitForChild; - - protected int maxChildStartChecks = 10; //check up to 10 times for child to start - - protected long maxChildStartCheckMs = 200; //wait 200ms between checks - - protected File tokenFile; - - protected File workDir; - - protected Map systemProperties; - - protected abstract ProcessBuilder createCommand(); - - protected abstract void redeployWebApp() throws Exception; - - public File getWorkDir() - { - return workDir; - } - - public void setWorkDir(File workDir) - { - this.workDir = workDir; - } - - /** - * @return the systemProperties - */ - public Map getSystemProperties() - { - return systemProperties; - } - - /** - * Set the systemProperties to set. - * @param systemProperties the systemProperties to set - */ - public void setSystemProperties(Map systemProperties) - { - this.systemProperties = systemProperties; - } - - public Map getEnv() - { - return env; - } - - public void setEnv(Map env) - { - this.env = env; - } - - public String getJvmArgs() - { - return jvmArgs; - } - - public void setJvmArgs(String jvmArgs) - { - this.jvmArgs = jvmArgs; - } - - public boolean isExitVm() - { - return exitVm; - } - - public void setExitVm(boolean exitVm) - { - this.exitVm = exitVm; - } - - public boolean isStopAtShutdown() - { - return stopAtShutdown; - } - - public void setStopAtShutdown(boolean stopAtShutdown) - { - this.stopAtShutdown = stopAtShutdown; - } - - public List getJettyXmlFiles() - { - return jettyXmlFiles; - } - - public void setJettyXmlFiles(List jettyXmlFiles) - { - this.jettyXmlFiles = jettyXmlFiles; - } - - public Map getJettyProperties() - { - return jettyProperties; - } - - public void setJettyProperties(Map jettyProperties) - { - this.jettyProperties = jettyProperties; - } - - public int getStopPort() - { - return stopPort; - } - - public void setStopPort(int stopPort) - { - this.stopPort = stopPort; - } - - public String getStopKey() - { - return stopKey; - } - - public void setStopKey(String stopKey) - { - this.stopKey = stopKey; - } - - public File getJettyOutputFile() - { - return jettyOutputFile; - } - - public void setJettyOutputFile(File jettyOutputFile) - { - this.jettyOutputFile = jettyOutputFile; - } - - public boolean isWaitForChild() - { - return waitForChild; - } - - public void setWaitForChild(boolean waitForChild) - { - this.waitForChild = waitForChild; - } - - public int getMaxChildtartChecks() - { - return maxChildStartChecks; - } - - public void setMaxChildStartChecks(int maxChildStartChecks) - { - this.maxChildStartChecks = maxChildStartChecks; - } - - public long getMaxChildStartCheckMs() - { - return maxChildStartCheckMs; - } - - public void setMaxChildStartCheckMs(long maxChildStartCheckMs) - { - this.maxChildStartCheckMs = maxChildStartCheckMs; - } - - public File getTokenFile() - { - return tokenFile; - } - - public void setTokenFile(File tokenFile) - { - this.tokenFile = tokenFile; - } - - public void doStart() - throws Exception - { - super.doStart(); - - //Create the command to fork - ProcessBuilder command = createCommand(); - Process process = command.start(); - - if (waitForChild) - { - //keep executing until the child dies - process.waitFor(); - } - else - { - //just wait until the child has started successfully - int attempts = maxChildStartChecks; - while (!tokenFile.exists() && attempts > 0) - { - Thread.sleep(maxChildStartCheckMs); - --attempts; - } - if (attempts <= 0) - LOG.info("Couldn't verify success of child startup"); - } - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractUnassembledWebAppMojo.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractUnassembledWebAppMojo.java index 2d44726d950..7e5683fd16e 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractUnassembledWebAppMojo.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractUnassembledWebAppMojo.java @@ -24,6 +24,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Parameter; +import org.eclipse.jetty.maven.ScanPattern; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resources; @@ -123,7 +124,7 @@ public abstract class AbstractUnassembledWebAppMojo extends AbstractWebAppMojo * * @throws IOException if there is an IO problem */ - protected void configureUnassembledWebApp() throws IOException + protected void configureUnassembledWebApp() throws Exception { //Set up the location of the webapp. //There are 2 parts to this: setWar() and setBaseResource(). On standalone jetty, @@ -208,7 +209,7 @@ public abstract class AbstractUnassembledWebAppMojo extends AbstractWebAppMojo //process any overlays and the war type artifacts, and //sets up the base resource collection for the webapp - mavenProjectHelper.getOverlayManager().applyOverlays(webApp); + mavenProjectHelper.getOverlayManager().applyOverlays(webApp, webApp.getBaseAppFirst()); getLog().info("web.xml file = " + webApp.getDescriptor()); getLog().info("Webapp directory = " + webAppSourceDirectory.getCanonicalPath()); diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractWebAppMojo.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractWebAppMojo.java index cbc4b1fb59f..de3eefc0bbd 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractWebAppMojo.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/AbstractWebAppMojo.java @@ -48,7 +48,10 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.StringUtils; import org.eclipse.aether.RepositorySystem; -import org.eclipse.jetty.ee10.maven.plugin.utils.MavenProjectHelper; +import org.eclipse.jetty.maven.MavenProjectHelper; +import org.eclipse.jetty.maven.MavenServerConnector; +import org.eclipse.jetty.maven.PluginLog; +import org.eclipse.jetty.maven.ScanTargetPattern; import org.eclipse.jetty.security.LoginService; import org.eclipse.jetty.server.RequestLog; import org.eclipse.jetty.server.Server; @@ -563,7 +566,7 @@ public abstract class AbstractWebAppMojo extends AbstractMojo if (jettyHome == null) jetty.setJettyHomeZip(jettyHomeZip != null ? jettyHomeZip : mavenProjectHelper.resolveArtifact(JETTY_HOME_GROUPID, JETTY_HOME_ARTIFACTID, plugin.getVersion(), "zip")); - jetty.version = plugin.getVersion(); + jetty.setVersion(plugin.getVersion()); jetty.setJettyHome(jettyHome); jetty.setJettyBase(jettyBase); jetty.setBaseDir(target); diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ConsoleReader.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ConsoleReader.java deleted file mode 100644 index 298f434e2e9..00000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ConsoleReader.java +++ /dev/null @@ -1,66 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.maven.plugin; - -import java.io.Console; -import java.util.EventListener; -import java.util.HashSet; -import java.util.Set; - -/** - * ConsoleReader - * - * Reads lines from the System console and supplies them - * to ConsoleReader.Listeners. - */ -public class ConsoleReader implements Runnable -{ - public interface Listener extends EventListener - { - public void consoleEvent(String line); - } - - public Set listeners = new HashSet<>(); - - public void addListener(ConsoleReader.Listener listener) - { - listeners.add(listener); - } - - public void removeListener(ConsoleReader.Listener listener) - { - listeners.remove(listener); - } - - public void run() - { - Console console = System.console(); - if (console == null) - return; - - String line = ""; - while (true && line != null) - { - line = console.readLine("%nHit to redeploy:%n%n"); - if (line != null) - signalEvent(line); - } - } - - private void signalEvent(String line) - { - for (ConsoleReader.Listener l:listeners) - l.consoleEvent(line); - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyEmbedder.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyEmbedder.java index 95e61c06b5a..948e556a0ca 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyEmbedder.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyEmbedder.java @@ -13,220 +13,40 @@ package org.eclipse.jetty.ee10.maven.plugin; -import java.io.File; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; import java.util.List; -import java.util.Map; -import java.util.Properties; import org.eclipse.jetty.ee10.quickstart.QuickStartConfiguration; import org.eclipse.jetty.ee10.quickstart.QuickStartConfiguration.Mode; import org.eclipse.jetty.ee10.servlet.ServletHandler; -import org.eclipse.jetty.security.LoginService; -import org.eclipse.jetty.server.RequestLog; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.ShutdownMonitor; +import org.eclipse.jetty.ee10.webapp.Configurations; +import org.eclipse.jetty.maven.AbstractJettyEmbedder; +import org.eclipse.jetty.maven.ServerSupport; import org.eclipse.jetty.server.handler.ContextHandler; -import org.eclipse.jetty.util.component.AbstractLifeCycle; /** - * JettyEmbedded + * JettyEmbedder * * Starts jetty within the current process. */ -public class JettyEmbedder extends AbstractLifeCycle +public class JettyEmbedder extends AbstractJettyEmbedder { - protected List contextHandlers; - protected List loginServices; - protected RequestLog requestLog; - protected MavenServerConnector httpConnector; - protected Server server; protected MavenWebAppContext webApp; - protected boolean exitVm; - protected boolean stopAtShutdown; - protected List jettyXmlFiles; - protected Map jettyProperties; - protected ShutdownMonitor shutdownMonitor; - protected int stopPort; - protected String stopKey; - private String contextXml; - private Properties webAppProperties; public List getContextHandlers() { return contextHandlers; } - - public void setContextHandlers(List contextHandlers) - { - if (contextHandlers == null) - this.contextHandlers = null; - else - this.contextHandlers = new ArrayList<>(contextHandlers); - } - - public List getLoginServices() - { - return loginServices; - } - - public void setLoginServices(List loginServices) - { - if (loginServices == null) - this.loginServices = null; - else - this.loginServices = new ArrayList<>(loginServices); - } - - public RequestLog getRequestLog() - { - return requestLog; - } - - public void setRequestLog(RequestLog requestLog) - { - this.requestLog = requestLog; - } - - public MavenServerConnector getHttpConnector() - { - return httpConnector; - } - - public void setHttpConnector(MavenServerConnector httpConnector) - { - this.httpConnector = httpConnector; - } - - public Server getServer() - { - return server; - } - - public void setServer(Server server) - { - this.server = server; - } - - public MavenWebAppContext getWebApp() - { - return webApp; - } - - public boolean isExitVm() - { - return exitVm; - } - - public void setExitVm(boolean exitVm) - { - this.exitVm = exitVm; - } - - public boolean isStopAtShutdown() - { - return stopAtShutdown; - } - - public void setStopAtShutdown(boolean stopAtShutdown) - { - this.stopAtShutdown = stopAtShutdown; - } - - public List getJettyXmlFiles() - { - return jettyXmlFiles; - } - - public void setJettyXmlFiles(List jettyXmlFiles) - { - this.jettyXmlFiles = jettyXmlFiles; - } - - public Map getJettyProperties() - { - return jettyProperties; - } - - public void setJettyProperties(Map jettyProperties) - { - this.jettyProperties = jettyProperties; - } - - public ShutdownMonitor getShutdownMonitor() - { - return shutdownMonitor; - } - - public void setShutdownMonitor(ShutdownMonitor shutdownMonitor) - { - this.shutdownMonitor = shutdownMonitor; - } - - public int getStopPort() - { - return stopPort; - } - - public void setStopPort(int stopPort) - { - this.stopPort = stopPort; - } - - public String getStopKey() - { - return stopKey; - } - - public void setStopKey(String stopKey) - { - this.stopKey = stopKey; - } public void setWebApp(MavenWebAppContext app) { webApp = app; } - public void setWebAppProperties(Properties props) - { - if (webAppProperties != null) - webAppProperties.clear(); - - if (props != null) - { - if (webAppProperties == null) - webAppProperties = new Properties(); - - webAppProperties.putAll(props); - } - } - - public String getContextXml() - { - return contextXml; - } - - public void setContextXml(String contextXml) - { - this.contextXml = contextXml; - } - - public void doStart() throws Exception - { - super.doStart(); - - configure(); - configureShutdownMonitor(); - server.start(); - } - protected void redeployWebApp() throws Exception { - if (!webApp.isStopped()) - webApp.stop(); + stopWebApp(); //clear the ServletHandler, which may have //remembered "durable" Servlets, Filters, Listeners @@ -239,40 +59,22 @@ public class JettyEmbedder extends AbstractLifeCycle webApp.start(); } - - protected void join() throws InterruptedException + + @Override + public void stopWebApp() throws Exception { - server.join(); + if (webApp != null && !webApp.isStopped()) + webApp.stop(); } /** - * Configure the server and the webapp + * Configure the webapp * @throws Exception if there is an unspecified problem */ - private void configure() throws Exception + public void configureWebApp() throws Exception { - // apply any configs from jetty.xml files first - Server tmp = ServerSupport.applyXmlConfigurations(new Server(), jettyXmlFiles, jettyProperties); - - if (tmp != null) - server = tmp; - - server.setStopAtShutdown(stopAtShutdown); - - //ensure there's a connector - if (httpConnector != null) - httpConnector.setServer(server); - - ServerSupport.configureConnectors(server, httpConnector, jettyProperties); - - //set up handler structure - ServerSupport.configureHandlers(server, contextHandlers, requestLog); - //Set up list of default Configurations to apply to a webapp - ServerSupport.configureDefaultConfigurationClasses(server); - - // set up security realms - ServerSupport.configureLoginServices(server, loginServices); + Configurations.setServerDefault(server); /* Configure the webapp */ if (webApp == null) @@ -286,37 +88,22 @@ public class JettyEmbedder extends AbstractLifeCycle Path qs = webApp.getTempDirectory().toPath().resolve("quickstart-web.xml"); if (Files.exists(qs) && Files.isRegularFile(qs)) { - webApp.setAttribute(QuickStartConfiguration.QUICKSTART_WEB_XML, qs); webApp.addConfiguration(new MavenQuickStartConfiguration()); + webApp.setAttribute(QuickStartConfiguration.QUICKSTART_WEB_XML, qs); webApp.setAttribute(QuickStartConfiguration.MODE, Mode.QUICKSTART); } } + } + public void applyWebAppProperties() throws Exception + { + super.applyWebAppProperties(); + WebAppPropertyConverter.fromProperties(webApp, webAppProperties, server, jettyProperties); + } + + public void addWebAppToServer() throws Exception + { //add the webapp to the server ServerSupport.addWebApplication(server, webApp); } - - private void applyWebAppProperties() throws Exception - { - //apply properties to the webapp if there are any - if (contextXml != null) - { - if (webAppProperties == null) - webAppProperties = new Properties(); - - webAppProperties.put("context.xml", contextXml); - } - WebAppPropertyConverter.fromProperties(webApp, webAppProperties, server, jettyProperties); - } - - private void configureShutdownMonitor() - { - if (stopPort > 0 && stopKey != null) - { - ShutdownMonitor monitor = ShutdownMonitor.getInstance(); - monitor.setPort(stopPort); - monitor.setKey(stopKey); - monitor.setExitVm(exitVm); - } - } } diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyForkedChild.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyForkedChild.java index f868ad600ad..7f0c6ba907a 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyForkedChild.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyForkedChild.java @@ -26,6 +26,8 @@ import java.util.Objects; import java.util.Properties; import java.util.Set; +import org.eclipse.jetty.maven.AbstractForkedChild; +import org.eclipse.jetty.maven.AbstractJettyEmbedder; import org.eclipse.jetty.util.Scanner; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.component.ContainerLifeCycle; @@ -38,174 +40,23 @@ import org.slf4j.LoggerFactory; * This is the class that is executed when the jetty maven plugin * forks a process when DeploymentMode=FORKED. */ -public class JettyForkedChild extends ContainerLifeCycle +public class JettyForkedChild extends AbstractForkedChild { private static final Logger LOG = LoggerFactory.getLogger(JettyForkedChild.class); - - protected JettyEmbedder jetty; - protected File tokenFile; // TODO: convert to Path - protected Scanner scanner; - protected File webAppPropsFile; // TODO: convert to Path - protected int scanInterval; /** * @param args arguments that were passed to main * @throws Exception if unable to configure */ - public JettyForkedChild(String[] args) - throws Exception + public JettyForkedChild(String[] args) throws Exception { - jetty = new JettyEmbedder(); - configure(args); + super(args); } - /** - * Based on the args passed to the program, configure jetty. - * - * @param args args that were passed to the program. - * @throws Exception if unable to load webprops - */ - public void configure(String[] args) - throws Exception + @Override + protected AbstractJettyEmbedder newJettyEmbedder() { - Map jettyProperties = new HashMap<>(); - - for (int i = 0; i < args.length; i++) - { - //--stop-port - if ("--stop-port".equals(args[i])) - { - jetty.setStopPort(Integer.parseInt(args[++i])); - continue; - } - - //--stop-key - if ("--stop-key".equals(args[i])) - { - jetty.setStopKey(args[++i]); - continue; - } - - //--jettyXml - if ("--jetty-xml".equals(args[i])) - { - List jettyXmls = new ArrayList<>(); - String[] names = StringUtil.csvSplit(args[++i]); - for (int j = 0; names != null && j < names.length; j++) - { - jettyXmls.add(new File(names[j].trim())); - } - jetty.setJettyXmlFiles(jettyXmls); - continue; - } - //--webprops - if ("--webprops".equals(args[i])) - { - webAppPropsFile = new File(args[++i].trim()); - jetty.setWebAppProperties(loadWebAppProps()); - continue; - } - - //--token - if ("--token".equals(args[i])) - { - tokenFile = new File(args[++i].trim()); - continue; - } - - if ("--scanInterval".equals(args[i])) - { - scanInterval = Integer.parseInt(args[++i].trim()); - scanner = new Scanner(); - scanner.setReportExistingFilesOnStartup(false); - scanner.setScanInterval(scanInterval); - scanner.addListener(new Scanner.BulkListener() - { - public void filesChanged(Set changes) - { - if (!Objects.isNull(scanner)) - { - try - { - scanner.stop(); - if (!Objects.isNull(jetty.getWebApp())) - { - //stop the webapp - jetty.getWebApp().stop(); - //reload the props - jetty.setWebAppProperties(loadWebAppProps()); - jetty.setWebApp(jetty.getWebApp()); - //restart the webapp - jetty.redeployWebApp(); - - //restart the scanner - scanner.start(); - } - } - catch (Exception e) - { - LOG.error("Error reconfiguring/restarting webapp after change in watched files", e); - } - } - } - }); - - if (!Objects.isNull(webAppPropsFile)) - scanner.addFile(webAppPropsFile.toPath()); - continue; - } - - //assume everything else is a jetty property to be passed in - String[] tmp = args[i].trim().split("="); - if (tmp.length == 2) - { - jettyProperties.put(tmp[0], tmp[1]); - } - } - - jetty.setJettyProperties(jettyProperties); - jetty.setExitVm(true); - } - - /** - * Load properties from a file describing the webapp if one is - * present. - * - * @return file contents as properties - * @throws IOException if there is an IO problem - */ - private Properties loadWebAppProps() throws IOException - { - Properties props = new Properties(); - if (Objects.nonNull(webAppPropsFile)) - props.load(new FileInputStream(webAppPropsFile)); - return props; - } - - /** - * Start a jetty instance and webapp. This thread will - * wait until jetty exits. - */ - public void doStart() - throws Exception - { - super.doStart(); - - //Start the embedded jetty instance - jetty.start(); - - //touch file to signify start of jetty - Path tokenPath = tokenFile.toPath(); - Files.createFile(tokenPath); - - //Start a watcher on a file that will change if the - //webapp is regenerated; stop the webapp, apply the - //properties and restart it. - if (scanner != null) - scanner.start(); - - //wait for jetty to finish - jetty.join(); + return new JettyEmbedder(); } public static void main(String[] args) diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyForker.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyForker.java index e43637f1a1f..6fb99d624ce 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyForker.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyForker.java @@ -13,94 +13,21 @@ package org.eclipse.jetty.ee10.maven.plugin; -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.maven.AbstractServerForker; /** * JettyForker * * Uses quickstart to generate a webapp and forks a process to run it. */ -public class JettyForker extends AbstractForker +public class JettyForker extends AbstractServerForker { - protected File forkWebXml; - protected Server server; protected MavenWebAppContext webApp; - protected String containerClassPath; - protected File webAppPropsFile; - protected String contextXml; - protected int scanInterval; QuickStartGenerator generator; - /** - * @return the scan - */ - public boolean isScan() + public JettyForker() { - return scanInterval > 0; - } - - /** - * Set if true, the forked child will scan for changes at 1 second intervals. - * @param scan if true, the forked child will scan for changes at 1 second intervals - */ - public void setScan(boolean scan) - { - setScanInterval(scan ? 1 : 0); - } - - public void setScanInterval(int sec) - { - scanInterval = sec; - } - - public int getScanInterval() - { - return scanInterval; - } - - public File getWebAppPropsFile() - { - return webAppPropsFile; - } - - public void setWebAppPropsFile(File webAppPropsFile) - { - this.webAppPropsFile = webAppPropsFile; - } - - public File getForkWebXml() - { - return forkWebXml; - } - - public void setForkWebXml(File forkWebXml) - { - this.forkWebXml = forkWebXml; - } - - public String getContextXml() - { - return contextXml; - } - - public void setContextXml(String contextXml) - { - this.contextXml = contextXml; - } - - public String getContainerClassPath() - { - return containerClassPath; - } - - public void setContainerClassPath(String containerClassPath) - { - this.containerClassPath = containerClassPath; + executionClassName = JettyForkedChild.class.getCanonicalName(); } public void setWebApp(MavenWebAppContext app) @@ -108,19 +35,8 @@ public class JettyForker extends AbstractForker webApp = app; } - public Server getServer() - { - return server; - } - - public void setServer(Server server) - { - this.server = server; - } - @Override - public void doStart() - throws Exception + public void generateWebApp() throws Exception { //Run the webapp to create the quickstart file and properties file generator = new QuickStartGenerator(forkWebXml.toPath(), webApp); @@ -128,8 +44,6 @@ public class JettyForker extends AbstractForker generator.setWebAppProps(webAppPropsFile.toPath()); generator.setServer(server); generator.generate(); - - super.doStart(); } protected void redeployWebApp() @@ -139,154 +53,4 @@ public class JettyForker extends AbstractForker //which will redeploy the webapp generator.generate(); } - - public ProcessBuilder createCommand() - { - List cmd = new ArrayList(); - cmd.add(getJavaBin()); - - if (jvmArgs != null) - { - String[] args = jvmArgs.split(" "); - for (int i = 0; args != null && i < args.length; i++) - { - if (args[i] != null && !"".equals(args[i])) - cmd.add(args[i].trim()); - } - } - - if (systemProperties != null) - { - for (Map.Entry e:systemProperties.entrySet()) - { - cmd.add("-D" + e.getKey() + "=" + e.getValue()); - } - } - - if (containerClassPath != null && containerClassPath.length() > 0) - { - cmd.add("-cp"); - cmd.add(containerClassPath); - } - - cmd.add(JettyForkedChild.class.getCanonicalName()); - - if (stopPort > 0 && stopKey != null) - { - cmd.add("--stop-port"); - cmd.add(Integer.toString(stopPort)); - cmd.add("--stop-key"); - cmd.add(stopKey); - } - if (jettyXmlFiles != null) - { - cmd.add("--jetty-xml"); - StringBuilder tmp = new StringBuilder(); - for (File jettyXml:jettyXmlFiles) - { - if (tmp.length() != 0) - tmp.append(","); - tmp.append(jettyXml.getAbsolutePath()); - } - cmd.add(tmp.toString()); - } - - cmd.add("--webprops"); - cmd.add(webAppPropsFile.getAbsolutePath()); - - cmd.add("--token"); - cmd.add(tokenFile.getAbsolutePath()); - - if (scanInterval > 0) - { - cmd.add("--scanInterval"); - cmd.add(Integer.toString(scanInterval)); - } - - if (jettyProperties != null) - { - for (Map.Entry e:jettyProperties.entrySet()) - { - cmd.add(e.getKey() + "=" + e.getValue()); - } - } - - ProcessBuilder command = new ProcessBuilder(cmd); - command.directory(workDir); - - if (PluginLog.getLog().isDebugEnabled()) - PluginLog.getLog().debug("Forked cli:" + command.command()); - - PluginLog.getLog().info("Forked process starting"); - - //set up extra environment vars if there are any - if (env != null && !env.isEmpty()) - command.environment().putAll(env); - - if (waitForChild) - { - command.inheritIO(); - } - else - { - command.redirectOutput(jettyOutputFile); - command.redirectErrorStream(true); - } - return command; - } - - /** - * Get the location of the java binary. - * @return the location of the java binary - */ - private String getJavaBin() - { - String[] javaexes = new String[]{"java", "java.exe"}; - - File javaHomeDir = new File(System.getProperty("java.home")); - for (String javaexe : javaexes) - { - File javabin = new File(javaHomeDir, fileSeparators("bin/" + javaexe)); - if (javabin.exists() && javabin.isFile()) - { - return javabin.getAbsolutePath(); - } - } - - return "java"; - } - - public static String fileSeparators(String path) - { - StringBuilder ret = new StringBuilder(); - for (char c : path.toCharArray()) - { - if ((c == '/') || (c == '\\')) - { - ret.append(File.separatorChar); - } - else - { - ret.append(c); - } - } - return ret.toString(); - } - - public static String pathSeparators(String path) - { - StringBuilder ret = new StringBuilder(); - for (char c : path.toCharArray()) - { - if ((c == ',') || (c == ':')) - { - ret.append(File.pathSeparatorChar); - } - else - { - ret.append(c); - } - } - return ret.toString(); - } } diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyHomeForker.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyHomeForker.java index 2d988f8a21b..7bac2f086b2 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyHomeForker.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyHomeForker.java @@ -14,30 +14,8 @@ package org.eclipse.jetty.ee10.maven.plugin; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.nio.file.FileAlreadyExistsException; -import java.nio.file.FileSystems; -import java.nio.file.FileVisitOption; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.EnumSet; -import java.util.List; -import java.util.Map; -import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.StringUtil; -import org.eclipse.jetty.util.TypeUtil; -import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.util.resource.ResourceFactory; +import org.eclipse.jetty.maven.AbstractHomeForker; /** * JettyHomeBaseForker @@ -45,121 +23,13 @@ import org.eclipse.jetty.util.resource.ResourceFactory; * Unpacks a jetty-home and configures it with a base that allows it * to run an unassembled webapp. */ -public class JettyHomeForker extends AbstractForker +public class JettyHomeForker extends AbstractHomeForker { protected MavenWebAppContext webApp; - protected String contextXml; - - /** - * Location of existing jetty home directory - */ - protected File jettyHome; - - /** - * Zip of jetty-home - */ - protected File jettyHomeZip; - - /** - * Location of existing jetty base directory - */ - protected File jettyBase; - - protected File baseDir; - - /** - * Optional list of other modules to - * activate. - */ - protected String[] modules; - - /* - * Optional jetty commands - */ - protected String jettyOptions; - - protected List libExtJarFiles; - protected Path modulesPath; - protected Path etcPath; - protected Path libPath; - protected Path webappPath; - protected Path mavenLibPath; - protected String version; - - public void setJettyOptions(String jettyOptions) + public JettyHomeForker() { - this.jettyOptions = jettyOptions; - } - - public String getJettyOptions() - { - return jettyOptions; - } - - public List getLibExtJarFiles() - { - return libExtJarFiles; - } - - public void setLibExtJarFiles(List libExtJarFiles) - { - this.libExtJarFiles = libExtJarFiles; - } - - public File getJettyHome() - { - return jettyHome; - } - - public void setJettyHome(File jettyHome) - { - this.jettyHome = jettyHome; - } - - public File getJettyBase() - { - return jettyBase; - } - - public void setJettyBase(File jettyBase) - { - this.jettyBase = jettyBase; - } - - public String[] getModules() - { - return modules; - } - - public void setModules(String[] modules) - { - this.modules = modules; - } - - public String getContextXmlFile() - { - return contextXml; - } - - public void setContextXml(String contextXml) - { - this.contextXml = contextXml; - } - - public File getJettyHomeZip() - { - return jettyHomeZip; - } - - public void setJettyHomeZip(File jettyHomeZip) - { - this.jettyHomeZip = jettyHomeZip; - } - - public MavenWebAppContext getWebApp() - { - return webApp; + environment = "ee10"; } public void setWebApp(MavenWebAppContext webApp) @@ -177,106 +47,6 @@ public class JettyHomeForker extends AbstractForker this.baseDir = baseDir; } - @Override - protected ProcessBuilder createCommand() - { - List cmd = new ArrayList<>(); - cmd.add("java"); - - //add any args to the jvm - if (StringUtil.isNotBlank(jvmArgs)) - { - Arrays.stream(jvmArgs.split(" ")).filter(StringUtil::isNotBlank).forEach((a) -> cmd.add(a.trim())); - } - - cmd.add("-jar"); - cmd.add(new File(jettyHome, "start.jar").getAbsolutePath()); - - if (systemProperties != null) - { - for (Map.Entry e : systemProperties.entrySet()) - { - cmd.add("-D" + e.getKey() + "=" + e.getValue()); - } - } - - cmd.add("-DSTOP.PORT=" + stopPort); - if (stopKey != null) - cmd.add("-DSTOP.KEY=" + stopKey); - - //set up enabled jetty modules - StringBuilder tmp = new StringBuilder(); - tmp.append("--module="); - tmp.append("server,http,ee10-webapp,ee10-deploy"); - if (modules != null) - { - for (String m : modules) - { - if (tmp.indexOf(m) < 0) - tmp.append("," + m); - } - } - - if (libExtJarFiles != null && !libExtJarFiles.isEmpty() && tmp.indexOf("ext") < 0) - tmp.append(",ext"); - tmp.append(",ee10-maven"); - cmd.add(tmp.toString()); - - //put any other jetty options onto the command line - if (StringUtil.isNotBlank(jettyOptions)) - { - Arrays.stream(jettyOptions.split(" ")).filter(StringUtil::isNotBlank).forEach((a) -> cmd.add(a.trim())); - } - - //put any jetty properties onto the command line - if (jettyProperties != null) - { - for (Map.Entry e : jettyProperties.entrySet()) - { - cmd.add(e.getKey() + "=" + e.getValue()); - } - } - - //existence of this file signals process started - cmd.add("jetty.token.file=" + tokenFile.getAbsolutePath().toString()); - - ProcessBuilder builder = new ProcessBuilder(cmd); - builder.directory(workDir); - - PluginLog.getLog().info("Home process starting"); - - //set up extra environment vars if there are any - if (!env.isEmpty()) - builder.environment().putAll(env); - - if (waitForChild) - builder.inheritIO(); - else - { - builder.redirectOutput(jettyOutputFile); - builder.redirectErrorStream(true); - } - return builder; - } - - @Override - public void doStart() throws Exception - { - //set up a jetty-home - configureJettyHome(); - - if (jettyHome == null || !jettyHome.exists()) - throw new IllegalStateException("No jetty home"); - - //set up a jetty-base - configureJettyBase(); - - //convert the webapp to properties - generateWebAppPropertiesFile(); - - super.doStart(); - } - protected void redeployWebApp() throws Exception { @@ -284,142 +54,9 @@ public class JettyHomeForker extends AbstractForker webappPath.resolve("maven.xml").toFile().setLastModified(System.currentTimeMillis()); } - private void generateWebAppPropertiesFile() + protected void generateWebAppPropertiesFile() throws Exception { WebAppPropertyConverter.toProperties(webApp, etcPath.resolve("maven.props").toFile(), contextXml); } - - /** - * Create or configure a jetty base. - */ - private void configureJettyBase() throws Exception - { - if (jettyBase != null && !jettyBase.exists()) - throw new IllegalStateException(jettyBase.getAbsolutePath() + " does not exist"); - - File targetJettyBase = new File(baseDir, "jetty-base"); - Path targetBasePath = targetJettyBase.toPath(); - if (Files.exists(targetBasePath)) - IO.delete(targetJettyBase); - - targetJettyBase.mkdirs(); - - //jetty-base will be the working directory for the forked command - workDir = targetJettyBase; - - //if there is an existing jetty base, copy parts of it - if (jettyBase != null) - { - Path jettyBasePath = jettyBase.toPath(); - - final File contextXmlFile = (contextXml == null ? null : FileSystems.getDefault().getPath(contextXml).toFile()); - - //copy the existing jetty base - Files.walkFileTree(jettyBasePath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, - new SimpleFileVisitor() - { - @Override - public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException - { - Path targetDir = targetBasePath.resolve(jettyBasePath.relativize(dir)); - try - { - Files.copy(dir, targetDir); - } - catch (FileAlreadyExistsException e) - { - if (!Files.isDirectory(targetDir)) //ignore attempt to recreate dir - throw e; - } - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException - { - if (contextXmlFile != null && Files.isSameFile(contextXmlFile.toPath(), file)) - return FileVisitResult.CONTINUE; //skip copying the context xml file - Files.copy(file, targetBasePath.resolve(jettyBasePath.relativize(file))); - return FileVisitResult.CONTINUE; - } - }); - } - - //make the jetty base structure - modulesPath = Files.createDirectories(targetBasePath.resolve("modules")); - etcPath = Files.createDirectories(targetBasePath.resolve("etc")); - libPath = Files.createDirectories(targetBasePath.resolve("lib")); - webappPath = Files.createDirectories(targetBasePath.resolve("webapps")); - mavenLibPath = Files.createDirectories(libPath.resolve("maven-ee10")); - - //copy in the jetty-maven-plugin jar - URI thisJar = TypeUtil.getLocationOfClass(this.getClass()); - if (thisJar == null) - throw new IllegalStateException("Can't find jar for jetty-ee10-maven-plugin"); - - try (InputStream jarStream = thisJar.toURL().openStream(); - FileOutputStream fileStream = new FileOutputStream(mavenLibPath.resolve("plugin.jar").toFile())) - { - IO.copy(jarStream, fileStream); - } - - // copy in the maven.xml webapp file - try (InputStream mavenXmlStream = getClass().getClassLoader().getResourceAsStream("maven-ee10.xml"); - FileOutputStream fileStream = new FileOutputStream(webappPath.resolve("maven-ee10.xml").toFile())) - { - IO.copy(mavenXmlStream, fileStream); - } - - Files.writeString(webappPath.resolve("maven-ee10.properties"), "environment=ee10"); - - //copy in the maven.mod file - try (InputStream mavenModStream = getClass().getClassLoader().getResourceAsStream("ee10-maven.mod"); - FileOutputStream fileStream = new FileOutputStream(modulesPath.resolve("ee10-maven.mod").toFile())) - { - IO.copy(mavenModStream, fileStream); - } - - //copy in the jetty-maven.xml file - try (InputStream jettyMavenStream = getClass().getClassLoader().getResourceAsStream("jetty-ee10-maven.xml"); - FileOutputStream fileStream = new FileOutputStream(etcPath.resolve("jetty-ee10-maven.xml").toFile())) - { - IO.copy(jettyMavenStream, fileStream); - } - - //if there were plugin dependencies, copy them into lib/ext - if (libExtJarFiles != null && !libExtJarFiles.isEmpty()) - { - Path libExtPath = Files.createDirectories(libPath.resolve("ext")); - for (File f : libExtJarFiles) - { - try (InputStream jarStream = new FileInputStream(f); - FileOutputStream fileStream = new FileOutputStream(libExtPath.resolve(f.getName()).toFile())) - { - IO.copy(jarStream, fileStream); - } - } - } - } - - private void configureJettyHome() - throws Exception - { - if (jettyHome == null && jettyHomeZip == null) - throw new IllegalStateException("No jettyHome"); - - if (baseDir == null) - throw new IllegalStateException("No baseDir"); - - if (jettyHome == null) - { - try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable()) - { - Resource res = resourceFactory.newJarFileResource(jettyHomeZip.toPath().toUri()); - res.copyTo(baseDir.toPath()); // TODO: Resource.copyTo() cannot copy dir to dir, only file to file - } - //zip will unpack to target/jetty-home- - jettyHome = new File(baseDir, "jetty-home-" + version); - } - } } diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyRunMojo.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyRunMojo.java index 8374459f948..7ff6e7d8f82 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyRunMojo.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyRunMojo.java @@ -28,6 +28,7 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.eclipse.jetty.ee10.webapp.WebAppContext; +import org.eclipse.jetty.maven.ConsoleReader; import org.eclipse.jetty.util.IncludeExcludeSet; import org.eclipse.jetty.util.Scanner; import org.eclipse.jetty.util.component.LifeCycle; @@ -355,7 +356,7 @@ public class JettyRunMojo extends AbstractUnassembledWebAppMojo } } - embedder.getWebApp().stop(); + embedder.stopWebApp(); configureWebApp(); embedder.redeployWebApp(); if (scanner != null) diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyRunWarMojo.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyRunWarMojo.java index 18f5aa51ef8..a87bc4cdeaa 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyRunWarMojo.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/JettyRunWarMojo.java @@ -25,6 +25,7 @@ import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; +import org.eclipse.jetty.maven.ConsoleReader; import org.eclipse.jetty.util.Scanner; import org.eclipse.jetty.util.StringUtil; @@ -235,7 +236,7 @@ public class JettyRunWarMojo extends AbstractWebAppMojo warArtifacts = null; configureScanner(); } - embedder.getWebApp().stop(); + embedder.stopWebApp(); configureWebApp(); embedder.redeployWebApp(); scanner.start(); diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenResource.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenResource.java deleted file mode 100644 index ab2f6ca7a35..00000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenResource.java +++ /dev/null @@ -1,220 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.maven.plugin; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.nio.file.Path; -import java.time.Instant; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.util.resource.ResourceFactory; - -/** - * MavenResource - * - * A helper class to allow Resources to be used in maven pom.xml configuration by - * providing a no-arg constructor and a setter that accepts a simple string as a - * file location. This class delegates to a real Resource obtained using a - * ResourceFactory. - */ -public class MavenResource extends Resource -{ - private static final ResourceFactory __resourceFactory = ResourceFactory.root(); - private String _resourceString; - private Resource _resource; - - public MavenResource() - { - } - - @Override - public void copyTo(Path destination) throws IOException - { - if (_resource == null) - return; - _resource.copyTo(destination); - } - - @Override - public boolean exists() - { - if (_resource == null) - return false; - return _resource.exists(); - } - - @Override - public Collection getAllResources() - { - if (_resource == null) - return null; - return _resource.getAllResources(); - } - - @Override - public String getFileName() - { - if (_resource == null) - return null; - return _resource.getFileName(); - } - - @Override - public String getName() - { - if (_resource == null) - return null; - return _resource.getName(); - } - - @Override - public Path getPath() - { - if (_resource == null) - return null; - - return _resource.getPath(); - } - - @Override - public URI getRealURI() - { - if (_resource == null) - return null; - return _resource.getRealURI(); - } - - public String getResourceAsString() - { - return _resourceString; - } - - public void setResourceAsString(String resourceString) - { - _resourceString = resourceString; - _resource = __resourceFactory.newResource(_resourceString); - } - - @Override - public URI getURI() - { - if (_resource == null) - return null; - - return _resource.getURI(); - } - - @Override - public boolean isAlias() - { - if (_resource == null) - return false; - return _resource.isAlias(); - } - - @Override - public boolean isContainedIn(Resource container) - { - if (_resource == null) - return false; - return _resource.isContainedIn(container); - } - - @Override - public boolean contains(Resource other) - { - if (_resource == null) - return false; - return _resource.contains(other); - } - - @Override - public Path getPathTo(Resource other) - { - if (_resource == null) - return null; - return _resource.getPathTo(other); - } - - @Override - public boolean isDirectory() - { - if (_resource == null) - return false; - - return _resource.isDirectory(); - } - - @Override - public boolean isReadable() - { - if (_resource == null) - return false; - - return _resource.isReadable(); - } - - @Override - public Iterator iterator() - { - if (_resource == null) - return null; - return _resource.iterator(); - } - - @Override - public Instant lastModified() - { - if (_resource == null) - return null; - return _resource.lastModified(); - } - - @Override - public long length() - { - if (_resource == null) - return -1; - return _resource.length(); - } - - @Override - public List list() - { - if (_resource == null) - return null; - return _resource.list(); - } - - @Override - public InputStream newInputStream() throws IOException - { - if (_resource == null) - return null; - return _resource.newInputStream(); - } - - @Override - public Resource resolve(String subUriPath) - { - if (_resource == null) - return null; - return _resource.resolve(subUriPath); - } -} \ No newline at end of file diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenServerConnector.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenServerConnector.java deleted file mode 100644 index 7e3a721cf80..00000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenServerConnector.java +++ /dev/null @@ -1,221 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.maven.plugin; - -import java.util.Collection; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; - -import org.eclipse.jetty.io.ByteBufferPool; -import org.eclipse.jetty.io.EndPoint; -import org.eclipse.jetty.server.ConnectionFactory; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.ServerConnector; -import org.eclipse.jetty.util.annotation.ManagedAttribute; -import org.eclipse.jetty.util.component.ContainerLifeCycle; -import org.eclipse.jetty.util.thread.Scheduler; - -/** - * MavenServerConnector - * - * As the ServerConnector class does not have a no-arg constructor, and moreover requires - * the server instance passed in to all its constructors, it cannot - * be referenced in the pom.xml. This class wraps a ServerConnector, delaying setting the - * server instance. Only a few of the setters from the ServerConnector class are supported. - */ -public class MavenServerConnector extends ContainerLifeCycle implements Connector -{ - public static String PORT_SYSPROPERTY = "jetty.http.port"; - - public static final int DEFAULT_PORT = 8080; - public static final String DEFAULT_PORT_STR = String.valueOf(DEFAULT_PORT); - public static final int DEFAULT_MAX_IDLE_TIME = 30000; - - private Server server; - private volatile ServerConnector delegate; - private String host; - private String name; - private int port; - private long idleTimeout; - - public MavenServerConnector() - { - } - - public void setServer(Server server) - { - this.server = server; - } - - public void setHost(String host) - { - this.host = host; - } - - public String getHost() - { - return this.host; - } - - public void setPort(int port) - { - this.port = port; - } - - public int getPort() - { - return this.port; - } - - public void setName(String name) - { - this.name = name; - } - - public void setIdleTimeout(long idleTimeout) - { - this.idleTimeout = idleTimeout; - } - - @Override - protected void doStart() throws Exception - { - - if (this.server == null) - throw new IllegalStateException("Server not set for MavenServerConnector"); - - this.delegate = new ServerConnector(this.server); - this.delegate.setName(this.name); - this.delegate.setPort(this.port); - this.delegate.setHost(this.host); - this.delegate.setIdleTimeout(idleTimeout); - this.delegate.start(); - - super.doStart(); - } - - @Override - protected void doStop() throws Exception - { - this.delegate.stop(); - super.doStop(); - this.delegate = null; - } - - @Override - public CompletableFuture shutdown() - { - return checkDelegate().shutdown(); - } - - @Override - public boolean isShutdown() - { - return checkDelegate().isShutdown(); - } - - @Override - public Server getServer() - { - return this.server; - } - - @Override - public Executor getExecutor() - { - return checkDelegate().getExecutor(); - } - - @Override - public Scheduler getScheduler() - { - return checkDelegate().getScheduler(); - } - - @Override - public ByteBufferPool getByteBufferPool() - { - return checkDelegate().getByteBufferPool(); - } - - @Override - public ConnectionFactory getConnectionFactory(String nextProtocol) - { - return checkDelegate().getConnectionFactory(nextProtocol); - } - - @Override - public T getConnectionFactory(Class factoryType) - { - return checkDelegate().getConnectionFactory(factoryType); - } - - @Override - public ConnectionFactory getDefaultConnectionFactory() - { - return checkDelegate().getDefaultConnectionFactory(); - } - - @Override - public Collection getConnectionFactories() - { - return checkDelegate().getConnectionFactories(); - } - - @Override - public List getProtocols() - { - return checkDelegate().getProtocols(); - } - - @Override - @ManagedAttribute("maximum time a connection can be idle before being closed (in ms)") - public long getIdleTimeout() - { - return checkDelegate().getIdleTimeout(); - } - - @Override - public Object getTransport() - { - return checkDelegate().getTransport(); - } - - @Override - public Collection getConnectedEndPoints() - { - return checkDelegate().getConnectedEndPoints(); - } - - @Override - public String getName() - { - return this.name; - } - - public int getLocalPort() - { - return this.delegate.getLocalPort(); - } - - private ServerConnector checkDelegate() throws IllegalStateException - { - ServerConnector d = this.delegate; - if (d == null) - throw new IllegalStateException("MavenServerConnector delegate not ready"); - return d; - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenWebAppContext.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenWebAppContext.java index 65939e59202..8f73478cd22 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenWebAppContext.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/MavenWebAppContext.java @@ -36,6 +36,7 @@ import org.eclipse.jetty.ee10.webapp.Configuration; import org.eclipse.jetty.ee10.webapp.Configurations; import org.eclipse.jetty.ee10.webapp.MetaInfConfiguration; import org.eclipse.jetty.ee10.webapp.WebAppContext; +import org.eclipse.jetty.maven.Overlay; import org.eclipse.jetty.util.FileID; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.URIUtil; diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/Overlay.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/Overlay.java deleted file mode 100644 index 51b9a6b4357..00000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/Overlay.java +++ /dev/null @@ -1,103 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.maven.plugin; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.time.Instant; - -import org.eclipse.jetty.util.resource.Resource; - -/** - * Overlay - * - * An Overlay represents overlay information derived from the - * maven-war-plugin. - */ -public class Overlay -{ - private OverlayConfig _config; - private Resource _resource; - - public Overlay(OverlayConfig config, Resource resource) - { - _config = config; - _resource = resource; - } - - public Overlay(OverlayConfig config) - { - _config = config; - } - - public void setResource(Resource r) - { - _resource = r; - } - - public Resource getResource() - { - return _resource; - } - - public OverlayConfig getConfig() - { - return _config; - } - - @Override - public String toString() - { - StringBuilder strbuff = new StringBuilder(); - if (_resource != null) - strbuff.append(_resource); - if (_config != null) - { - strbuff.append(" ["); - strbuff.append(_config); - strbuff.append("]"); - } - return strbuff.toString(); - } - - /** - * Unpack the overlay into the given directory. Only - * unpack if the directory does not exist, or the overlay - * has been modified since the dir was created. - * - * @param dir the directory into which to unpack the overlay - * @throws IOException - */ - public void unpackTo(File dir) throws IOException // TODO: change to Path - { - if (dir == null) - throw new IllegalStateException("No overly unpack directory"); - Path pathDir = dir.toPath(); - // only unpack if the overlay is newer - if (!Files.exists(pathDir)) - { - // create directory - Files.createDirectories(pathDir); - getResource().copyTo(pathDir); - } - else - { - Instant dirLastModified = Files.getLastModifiedTime(pathDir).toInstant(); - if (getResource().lastModified().isAfter(dirLastModified)) - getResource().copyTo(pathDir); - } - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayConfig.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayConfig.java deleted file mode 100644 index 26f0342db4f..00000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayConfig.java +++ /dev/null @@ -1,337 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.maven.plugin; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.eclipse.jetty.util.StringUtil; - -/** - * OverlayConfig - * - * The configuration of a war overlay in a pom. Used to help determine which resources - * from a project's dependent war should be included. - */ -public class OverlayConfig -{ - private String targetPath; - private String groupId; - private String artifactId; - private String classifier; - private List includes; - private List excludes; - private boolean skip; - private boolean filtered; - - public OverlayConfig() - { - } - - public OverlayConfig(String fmt, List defaultIncludes, List defaultExcludes) - { - if (fmt == null) - return; - String[] atoms = StringUtil.csvSplit(fmt); - for (int i = 0; i < atoms.length; i++) - { - String s = atoms[i].trim(); - switch (i) - { - case 0: - { - if (!"".equals(s)) - groupId = s; - break; - } - case 1: - { - if (!"".equals(s)) - artifactId = s; - break; - } - case 2: - { - if (!"".equals(s)) - classifier = s; - break; - } - case 3: - { - if (!"".equals(s)) - targetPath = s; - break; - } - case 4: - { - if ("".equals(s)) - skip = false; - else - skip = Boolean.valueOf(s); - break; - } - case 5: - { - if ("".equals(s)) - filtered = false; - else - filtered = Boolean.valueOf(s); - break; - } - case 6: - { - if ("".equals(s)) - break; - String[] incs = s.split(";"); - if (incs.length > 0) - includes = Arrays.asList(incs); - break; - } - case 7: - { - if ("".equals(s)) - break; - String[] exs = s.split(";"); - if (exs.length > 0) - excludes = Arrays.asList(exs); - break; - } - default: - break; - } - } - } - - public OverlayConfig(Xpp3Dom root, List defaultIncludes, List defaultExcludes) - { - Xpp3Dom node = root.getChild("groupId"); - setGroupId(node == null ? null : node.getValue()); - - node = root.getChild("artifactId"); - setArtifactId(node == null ? null : node.getValue()); - - node = root.getChild("classifier"); - setClassifier(node == null ? null : node.getValue()); - - node = root.getChild("targetPath"); - setTargetPath(node == null ? null : node.getValue()); - - node = root.getChild("skip"); - setSkip(node == null ? false : Boolean.valueOf(node.getValue())); - - node = root.getChild("filtered"); - setFiltered(node == null ? false : Boolean.valueOf(node.getValue())); - - node = root.getChild("includes"); - List includes = null; - if (node != null && node.getChildCount() > 0) - { - Xpp3Dom[] list = node.getChildren("include"); - for (int j = 0; list != null && j < list.length; j++) - { - if (includes == null) - includes = new ArrayList<>(); - includes.add(list[j].getValue()); - } - } - if (includes == null && defaultIncludes != null) - { - includes = new ArrayList<>(); - includes.addAll(defaultIncludes); - } - setIncludes(includes); - - node = root.getChild("excludes"); - List excludes = null; - if (node != null && node.getChildCount() > 0) - { - Xpp3Dom[] list = node.getChildren("exclude"); - for (int j = 0; list != null && j < list.length; j++) - { - if (excludes == null) - excludes = new ArrayList<>(); - excludes.add(list[j].getValue()); - } - } - if (excludes == null && defaultExcludes != null) - { - excludes = new ArrayList<>(); - excludes.addAll(defaultExcludes); - } - setExcludes(excludes); - } - - public String getTargetPath() - { - return targetPath; - } - - public void setTargetPath(String targetPath) - { - this.targetPath = targetPath; - } - - public String getGroupId() - { - return groupId; - } - - public void setGroupId(String groupId) - { - this.groupId = groupId; - } - - public String getArtifactId() - { - return artifactId; - } - - public void setArtifactId(String artifactId) - { - this.artifactId = artifactId; - } - - public String getClassifier() - { - return classifier; - } - - public void setClassifier(String classifier) - { - this.classifier = classifier; - } - - public List getIncludes() - { - return includes; - } - - public void setIncludes(List includes) - { - this.includes = includes; - } - - public List getExcludes() - { - return excludes; - } - - public void setExcludes(List excludes) - { - this.excludes = excludes; - } - - public boolean isSkip() - { - return skip; - } - - public void setSkip(boolean skip) - { - this.skip = skip; - } - - public boolean isFiltered() - { - return filtered; - } - - public void setFiltered(boolean filtered) - { - this.filtered = filtered; - } - - public boolean isCurrentProject() - { - if (this.groupId == null && this.artifactId == null) - return true; - return false; - } - - /** - * Check if this overlay configuration matches an Artifact's info - * - * @param gid Artifact groupId - * @param aid Artifact artifactId - * @param cls Artifact classifier - * @return true if matched - */ - public boolean matchesArtifact(String gid, String aid, String cls) - { - if (((getGroupId() == null && gid == null) || (getGroupId() != null && getGroupId().equals(gid))) && - ((getArtifactId() == null && aid == null) || (getArtifactId() != null && getArtifactId().equals(aid))) && - ((getClassifier() == null) || (getClassifier().equals(cls)))) - return true; - - return false; - } - - /** - * Check if this overlay configuration matches an Artifact's info - * - * @param gid the group id - * @param aid the artifact id - * @return true if matched - */ - public boolean matchesArtifact(String gid, String aid) - { - if (((getGroupId() == null && gid == null) || (getGroupId() != null && getGroupId().equals(gid))) && - ((getArtifactId() == null && aid == null) || (getArtifactId() != null && getArtifactId().equals(aid)))) - return true; - - return false; - } - - @Override - public String toString() - { - StringBuilder strbuff = new StringBuilder(); - strbuff.append((groupId != null ? groupId : "") + ","); - strbuff.append((artifactId != null ? artifactId : "") + ","); - strbuff.append((classifier != null ? classifier : "") + ","); - strbuff.append((targetPath != null ? targetPath : "") + ","); - strbuff.append("" + skip + ","); - strbuff.append("" + filtered + ","); - - if (includes != null) - { - Iterator itor = includes.iterator(); - while (itor.hasNext()) - { - strbuff.append(itor.next()); - if (itor.hasNext()) - strbuff.append(";"); - } - } - - strbuff.append(", "); - - if (excludes != null) - { - Iterator itor = excludes.iterator(); - while (itor.hasNext()) - { - strbuff.append(itor.next()); - if (itor.hasNext()) - strbuff.append(";"); - } - } - - return strbuff.toString(); - } -} - diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayManager.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayManager.java deleted file mode 100644 index 40e353998d0..00000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/OverlayManager.java +++ /dev/null @@ -1,163 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.maven.plugin; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; - -import org.apache.maven.artifact.Artifact; -import org.eclipse.jetty.ee10.webapp.WebAppContext; -import org.eclipse.jetty.util.URIUtil; -import org.eclipse.jetty.util.resource.MountedPathResource; -import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.util.resource.ResourceFactory; - -/** - * OverlayManager - * - * Mediates information about overlays configured in a war plugin. - * - */ -public class OverlayManager -{ - private WarPluginInfo warPlugin; - - public OverlayManager(WarPluginInfo warPlugin) - { - this.warPlugin = warPlugin; - } - - public void applyOverlays(MavenWebAppContext webApp) throws IOException - { - Objects.requireNonNull(webApp); - List resourceBases = new ArrayList(); - - for (Overlay o : getOverlays(webApp)) - { - //can refer to the current project in list of overlays for ordering purposes - if (o.getConfig() != null && o.getConfig().isCurrentProject() && webApp.getBaseResource().exists()) - { - resourceBases.add(webApp.getBaseResource()); - continue; - } - //add in the selectively unpacked overlay in the correct order to the webapp's resource base - resourceBases.add(unpackOverlay(webApp, o)); - } - - if (!resourceBases.contains(webApp.getBaseResource()) && webApp.getBaseResource().exists()) - { - if (webApp.getBaseAppFirst()) - resourceBases.add(0, webApp.getBaseResource()); - else - resourceBases.add(webApp.getBaseResource()); - } - - webApp.setBaseResource(ResourceFactory.combine(resourceBases)); - } - - /** - * Generate an ordered list of overlays - */ - protected List getOverlays(WebAppContext webApp) - { - Set matchedWarArtifacts = new HashSet(); - List overlays = new ArrayList(); - - //Check all of the overlay configurations - for (OverlayConfig config:warPlugin.getMavenWarOverlayConfigs()) - { - //overlays can be individually skipped - if (config.isSkip()) - continue; - - //an empty overlay refers to the current project - important for ordering - if (config.isCurrentProject()) - { - Overlay overlay = new Overlay(config, null); - overlays.add(overlay); - continue; - } - - //if a war matches an overlay config - Artifact a = warPlugin.getWarArtifact(config.getGroupId(), config.getArtifactId(), config.getClassifier()); - if (a != null) - { - matchedWarArtifacts.add(a); - Resource resource = webApp.getResourceFactory().newJarFileResource(a.getFile().toPath().toUri()); - SelectiveJarResource r = new SelectiveJarResource(resource); - r.setIncludes(config.getIncludes()); - r.setExcludes(config.getExcludes()); - Overlay overlay = new Overlay(config, r); - overlays.add(overlay); - } - } - - //iterate over the left over war artifacts add them - for (Artifact a: warPlugin.getWarArtifacts()) - { - if (!matchedWarArtifacts.contains(a)) - { - Resource resource = webApp.getResourceFactory().newJarFileResource(a.getFile().toPath().toUri()); - Overlay overlay = new Overlay(null, resource); - overlays.add(overlay); - } - } - return overlays; - } - - /** - * Unpack a war overlay. - * - * @param overlay the war overlay to unpack - * @return the location to which it was unpacked - * @throws IOException if there is an IO problem - */ - protected Resource unpackOverlay(WebAppContext webApp, Overlay overlay) - throws IOException - { - Objects.requireNonNull(webApp); - - if (overlay.getResource() == null) - return null; //nothing to unpack - - //Get the name of the overlayed war and unpack it to a dir of the - //same name in the temporary directory. - //We know it is a war because it came from the maven repo - assert overlay.getResource() instanceof MountedPathResource; - - Path p = Paths.get(URIUtil.unwrapContainer(overlay.getResource().getURI())); - String name = p.getName(p.getNameCount() - 1).toString(); - name = name.replace('.', '_'); - - File overlaysDir = new File(warPlugin.getProject().getBuild().getDirectory(), "jetty_overlays"); - File dir = new File(overlaysDir, name); - - //if specified targetPath, unpack to that subdir instead - File unpackDir = dir; - if (overlay.getConfig() != null && overlay.getConfig().getTargetPath() != null) - unpackDir = new File(dir, overlay.getConfig().getTargetPath()); - - overlay.unpackTo(unpackDir); - - //use top level of unpacked content - return webApp.getResourceFactory().newResource(unpackDir.getCanonicalPath()); - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/PluginLog.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/PluginLog.java deleted file mode 100644 index 7adb0007d8d..00000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/PluginLog.java +++ /dev/null @@ -1,37 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.maven.plugin; - -import org.apache.maven.plugin.logging.Log; - -/** - * PluginLog - * - * Convenience class to provide access to the plugin - * Log for non-mojo classes. - */ -public class PluginLog -{ - private static Log log = null; - - public static void setLog(Log l) - { - log = l; - } - - public static Log getLog() - { - return log; - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/QuickStartGenerator.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/QuickStartGenerator.java index 6fde7cf5b36..1b3a712c0bc 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/QuickStartGenerator.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/QuickStartGenerator.java @@ -18,6 +18,8 @@ import java.nio.file.Path; import org.eclipse.jetty.ee10.annotations.AnnotationConfiguration; import org.eclipse.jetty.ee10.quickstart.QuickStartConfiguration; import org.eclipse.jetty.ee10.quickstart.QuickStartConfiguration.Mode; +import org.eclipse.jetty.ee10.webapp.Configurations; +import org.eclipse.jetty.maven.ServerSupport; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.util.thread.QueuedThreadPool; @@ -148,7 +150,7 @@ public class QuickStartGenerator //ensure handler structure enabled ServerSupport.configureHandlers(server, null, null); - ServerSupport.configureDefaultConfigurationClasses(server); + Configurations.setServerDefault(server); //if our server has a thread pool associated we can do annotation scanning multithreaded, //otherwise scanning will be single threaded diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ScanPattern.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ScanPattern.java deleted file mode 100644 index 889ba74f59b..00000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ScanPattern.java +++ /dev/null @@ -1,48 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.maven.plugin; - -import java.util.Collections; -import java.util.List; - -/** - * ScanPattern - * - * Ant-style pattern of includes and excludes. - */ -public class ScanPattern -{ - private List _includes = Collections.emptyList(); - private List _excludes = Collections.emptyList(); - - public void setIncludes(List includes) - { - _includes = includes; - } - - public void setExcludes(List excludes) - { - _excludes = excludes; - } - - public List getIncludes() - { - return _includes; - } - - public List getExcludes() - { - return _excludes; - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ScanTargetPattern.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ScanTargetPattern.java deleted file mode 100644 index 34e42a81891..00000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ScanTargetPattern.java +++ /dev/null @@ -1,108 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.maven.plugin; - -import java.io.File; -import java.nio.file.Path; -import java.nio.file.PathMatcher; -import java.util.Collections; -import java.util.List; - -import org.eclipse.jetty.util.IncludeExcludeSet; - -/** - * ScanTargetPattern - * - * Utility class to provide the ability for the mvn jetty:run - * mojo to be able to specify filesets of extra files to - * regularly scan for changes in order to redeploy the webapp. - * - * For example: - * - * <scanTargetPattern> - * <directory>/some/place</directory> - * <includes> - * <include>some ant pattern here </include> - * <include>some ant pattern here </include> - * </includes> - * <excludes> - * <exclude>some ant pattern here </exclude> - * <exclude>some ant pattern here </exclude> - * </excludes> - * </scanTargetPattern> - */ -public class ScanTargetPattern -{ - private File _directory; - private ScanPattern _pattern; - - /** - * Get the _directory. - * @return the _directory - */ - public File getDirectory() - { - return _directory; - } - - /** - * Set the directory to set. - * @param directory the directory to set - */ - public void setDirectory(File directory) - { - this._directory = directory; - } - - public void setIncludes(List includes) - { - if (_pattern == null) - _pattern = new ScanPattern(); - _pattern.setIncludes(includes); - } - - public void setExcludes(List excludes) - { - if (_pattern == null) - _pattern = new ScanPattern(); - _pattern.setExcludes(excludes); - } - - public List getIncludes() - { - return (_pattern == null ? Collections.emptyList() : _pattern.getIncludes()); - } - - public List getExcludes() - { - return (_pattern == null ? Collections.emptyList() : _pattern.getExcludes()); - } - - public void configureIncludesExcludeSet(IncludeExcludeSet includesExcludes) - { - for (String include:getIncludes()) - { - if (!include.startsWith("glob:")) - include = "glob:" + include; - includesExcludes.include(_directory.toPath().getFileSystem().getPathMatcher(include)); - } - - for (String exclude:getExcludes()) - { - if (!exclude.startsWith("glob:")) - exclude = "glob:" + exclude; - includesExcludes.exclude(_directory.toPath().getFileSystem().getPathMatcher(exclude)); - } - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/SelectiveJarResource.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/SelectiveJarResource.java deleted file mode 100644 index 4a874dada7c..00000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/SelectiveJarResource.java +++ /dev/null @@ -1,280 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.maven.plugin; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URI; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.attribute.FileTime; -import java.time.Instant; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.jar.JarEntry; -import java.util.jar.JarInputStream; -import java.util.jar.Manifest; - -import org.codehaus.plexus.util.SelectorUtils; -import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.URIUtil; -import org.eclipse.jetty.util.resource.Resource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * SelectiveJarResource - * - * Selectively copies resources from a jar file based on includes/excludes. - * TODO: investigate if copyTo() can instead have an IncludeExcludeSet as a parameter? - * TODO: or have a smaller ResourceWrapper jetty-core class that can be overridden for specific behavior like in this class - */ -public class SelectiveJarResource extends Resource -{ - private static final Logger LOG = LoggerFactory.getLogger(SelectiveJarResource.class); - - /** - * Default matches every resource. - */ - public static final List DEFAULT_INCLUDES = - Arrays.asList(new String[]{"**"}); - - /** - * Default is to exclude nothing. - */ - public static final List DEFAULT_EXCLUDES = Collections.emptyList(); - - final Resource _delegate; - List _includes = null; - List _excludes = null; - boolean _caseSensitive = false; - - public SelectiveJarResource(Resource resource) - { - _delegate = resource; - } - - public void setCaseSensitive(boolean caseSensitive) - { - _caseSensitive = caseSensitive; - } - - public void setIncludes(List patterns) - { - _includes = patterns; - } - - public void setExcludes(List patterns) - { - _excludes = patterns; - } - - protected boolean isIncluded(String name) - { - for (String include : _includes) - { - if (SelectorUtils.matchPath(include, name, "/", _caseSensitive)) - { - return true; - } - } - return false; - } - - protected boolean isExcluded(String name) - { - for (String exclude : _excludes) - { - if (SelectorUtils.matchPath(exclude, name, "/", _caseSensitive)) - { - return true; - } - } - return false; - } - - @Override - public Path getPath() - { - return _delegate.getPath(); - } - - @Override - public boolean isDirectory() - { - return _delegate.isDirectory(); - } - - @Override - public Instant lastModified() - { - return _delegate.lastModified(); - } - - @Override - public boolean isReadable() - { - return _delegate.isReadable(); - } - - @Override - public boolean isContainedIn(Resource container) - { - return _delegate.isContainedIn(container); - } - - @Override - public boolean contains(Resource other) - { - return _delegate.contains(other); - } - - @Override - public Path getPathTo(Resource other) - { - return _delegate.getPathTo(other); - } - - @Override - public URI getURI() - { - return _delegate.getURI(); - } - - @Override - public String getName() - { - return _delegate.getName(); - } - - @Override - public String getFileName() - { - return _delegate.getFileName(); - } - - @Override - public Resource resolve(String subUriPath) - { - return _delegate.resolve(subUriPath); - } - - @Override - public void copyTo(Path directory) throws IOException - { - if (_includes == null) - _includes = DEFAULT_INCLUDES; - if (_excludes == null) - _excludes = DEFAULT_EXCLUDES; - - //Copy contents of the jar file to the given directory, - //using the includes and excludes patterns to control which - //parts of the jar file are copied - if (!exists()) - return; - - String urlString = this.getURI().toASCIIString().trim(); - int endOfJarUrl = urlString.indexOf("!/"); - int startOfJarUrl = (endOfJarUrl >= 0 ? 4 : 0); - - if (endOfJarUrl < 0) - throw new IOException("Not a valid jar url: " + urlString); - - URL jarFileURL = new URL(urlString.substring(startOfJarUrl, endOfJarUrl)); - - try (InputStream is = jarFileURL.openConnection().getInputStream(); - JarInputStream jin = new JarInputStream(is)) - { - JarEntry entry; - - while ((entry = jin.getNextJarEntry()) != null) - { - String entryName = entry.getName(); - - LOG.debug("Looking at {}", entryName); - // make sure no access out of the root entry is present - if (URIUtil.isNotNormalWithinSelf(entryName)) - { - LOG.info("Invalid entry: {}", entryName); - continue; - } - - Path file = directory.resolve(entryName); - - if (entry.isDirectory()) - { - if (isIncluded(entryName)) - { - if (!isExcluded(entryName)) - { - // Make directory - if (!Files.exists(file)) - Files.createDirectories(file); - } - else - LOG.debug("{} dir is excluded", entryName); - } - else - LOG.debug("{} dir is NOT included", entryName); - } - else - { - //entry is a file, is it included? - if (isIncluded(entryName)) - { - if (!isExcluded(entryName)) - { - // make directory (some jars don't list dirs) - Path dir = file.getParent(); - if (!Files.exists(dir)) - Files.createDirectories(dir); - - // Make file - try (OutputStream fout = Files.newOutputStream(file)) - { - IO.copy(jin, fout); - } - - // touch the file. - if (entry.getTime() >= 0) - Files.setLastModifiedTime(file, FileTime.fromMillis(entry.getTime())); - } - else - LOG.debug("{} file is excluded", entryName); - } - else - LOG.debug("{} file is NOT included", entryName); - } - } - - Manifest manifest = jin.getManifest(); - if (manifest != null) - { - if (isIncluded("META-INF") && !isExcluded("META-INF")) - { - Path metaInf = directory.resolve("META-INF"); - Files.createDirectory(metaInf); - Path f = metaInf.resolve("MANIFEST.MF"); - try (OutputStream fout = Files.newOutputStream(f)) - { - manifest.write(fout); - } - } - } - } - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerConnectorListener.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerConnectorListener.java deleted file mode 100644 index c3c534c7d50..00000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerConnectorListener.java +++ /dev/null @@ -1,111 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.maven.plugin; - -import java.io.Writer; -import java.nio.file.AtomicMoveNotSupportedException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; - -import org.eclipse.jetty.server.ServerConnector; -import org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener; -import org.eclipse.jetty.util.component.LifeCycle; - -/** - * ServerConnectorListener - * - * This is for test support, where we need jetty to run on a random port, and we need - * a client to be able to find out which port was picked. - */ -public class ServerConnectorListener extends AbstractLifeCycleListener -{ - private String _fileName; - private String _sysPropertyName; - - @Override - public void lifeCycleStarted(LifeCycle event) - { - if (getFileName() != null) - { - try - { - Path tmp = Files.createTempFile("jettyport", ".tmp"); - try (Writer writer = Files.newBufferedWriter(tmp)) - { - writer.write(String.valueOf(((ServerConnector)event).getLocalPort())); - } - - Path path = Paths.get(getFileName()); - Files.deleteIfExists(path); - try - { - Files.move(tmp, path, StandardCopyOption.ATOMIC_MOVE); - } - catch (AtomicMoveNotSupportedException e) // can append on some os (windows).. so try again without the option - { - Files.move(tmp, path); - } - } - catch (Exception e) - { - throw new RuntimeException(e); - } - } - - if (getSysPropertyName() != null) - { - System.setProperty(_sysPropertyName, String.valueOf(((ServerConnector)event).getLocalPort())); - } - super.lifeCycleStarted(event); - } - - /** - * Get the file name. - * @return the file name - */ - public String getFileName() - { - return _fileName; - } - - /** - * Set the file name to set. - * @param name the file name to set - */ - public void setFileName(String name) - { - - _fileName = name; - } - - /** - * Get the sysPropertyName. - * @return the sysPropertyName - */ - public String getSysPropertyName() - { - return _sysPropertyName; - } - - /** - * Set the sysPropertyName to set. - * @param sysPropertyName the sysPropertyName to set - */ - public void setSysPropertyName(String sysPropertyName) - { - _sysPropertyName = sysPropertyName; - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerListener.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerListener.java deleted file mode 100644 index 940c99d606f..00000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerListener.java +++ /dev/null @@ -1,59 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.maven.plugin; - -import java.nio.file.Files; -import java.nio.file.Path; - -import org.eclipse.jetty.util.component.LifeCycle; - -/** - * ServerListener - * - * Listener to create a file that signals that the startup is completed. - * Used by the JettyRunHome maven goal to determine that the child - * process is started, and that jetty is ready. - */ -public class ServerListener implements LifeCycle.Listener -{ - private String _tokenFile; - - public void setTokenFile(String file) - { - _tokenFile = file; - } - - public String getTokenFile() - { - return _tokenFile; - } - - @Override - public void lifeCycleStarted(LifeCycle event) - { - if (_tokenFile != null) - { - try - { - // Using Path, as we need to reliably create/write a file. - Path path = Path.of(_tokenFile); - Files.createFile(path); - } - catch (Exception e) - { - throw new IllegalStateException(e); - } - } - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerSupport.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerSupport.java deleted file mode 100644 index f648dd6b449..00000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/ServerSupport.java +++ /dev/null @@ -1,236 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.maven.plugin; - -import java.io.File; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.jetty.ee10.webapp.Configurations; -import org.eclipse.jetty.ee10.webapp.WebAppContext; -import org.eclipse.jetty.security.LoginService; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.RequestLog; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.ContextHandler; -import org.eclipse.jetty.server.handler.ContextHandlerCollection; -import org.eclipse.jetty.util.resource.ResourceFactory; -import org.eclipse.jetty.xml.XmlConfiguration; - -/** - * ServerSupport - * - * Helps configure the Server instance. - */ -public class ServerSupport -{ - - public static void configureDefaultConfigurationClasses(Server server) - { - Configurations.setServerDefault(server); - } - - /** - * Set up the handler structure to receive a webapp. - * Also put in a DefaultHandler so we get a nicer page - * than a 404 if we hit the root and the webapp's - * context isn't at root. - * - * @param server the server to use - * @param contextHandlers the context handlers to include - * @param requestLog a request log to use - */ - public static void configureHandlers(Server server, List contextHandlers, RequestLog requestLog) - { - if (server == null) - throw new IllegalArgumentException("Server is null"); - - if (requestLog != null) - server.setRequestLog(requestLog); - - ContextHandlerCollection contexts = findContextHandlerCollection(server); - if (contexts == null) - { - contexts = new ContextHandlerCollection(); - server.setHandler(contexts); - } - - if (contextHandlers != null) - { - for (ContextHandler context:contextHandlers) - { - contexts.addHandler(context); - } - } - } - - /** - * Configure at least one connector for the server - * - * @param server the server - * @param connector the connector - * @param properties jetty properties - */ - public static void configureConnectors(Server server, Connector connector, Map properties) - { - if (server == null) - throw new IllegalArgumentException("Server is null"); - - //if a connector is provided, use it - if (connector != null) - { - server.addConnector(connector); - return; - } - - // if the user hasn't configured the connectors in a jetty.xml file so use a default one - Connector[] connectors = server.getConnectors(); - if (connectors == null || connectors.length == 0) - { - //Make a new default connector - MavenServerConnector tmp = new MavenServerConnector(); - //use any jetty.http.port settings provided, trying system properties before jetty properties - String port = System.getProperty(MavenServerConnector.PORT_SYSPROPERTY); - if (port == null) - port = System.getProperty("jetty.port"); - if (port == null) - port = (properties != null ? properties.get(MavenServerConnector.PORT_SYSPROPERTY) : null); - if (port == null) - port = MavenServerConnector.DEFAULT_PORT_STR; - tmp.setPort(Integer.parseInt(port.trim())); - tmp.setServer(server); - server.setConnectors(new Connector[]{tmp}); - } - } - - /** - * Set up any security LoginServices provided. - * - * @param server the server - * @param loginServices the login services - */ - public static void configureLoginServices(Server server, List loginServices) - { - if (server == null) - throw new IllegalArgumentException("Server is null"); - - if (loginServices != null) - { - for (LoginService loginService : loginServices) - { - PluginLog.getLog().debug(loginService.getClass().getName() + ": " + loginService.toString()); - server.addBean(loginService); - } - } - } - - /** - * Add a WebAppContext to a Server - * @param server the server to use - * @param webapp the webapp to add - */ - public static void addWebApplication(Server server, WebAppContext webapp) - { - if (server == null) - throw new IllegalArgumentException("Server is null"); - ContextHandlerCollection contexts = findContextHandlerCollection(server); - if (contexts == null) - throw new IllegalStateException("ContextHandlerCollection is null"); - contexts.addHandler(webapp); - } - - /** - * Locate a ContextHandlerCollection for a Server. - * - * @param server the Server to check. - * @return The ContextHandlerCollection or null if not found. - */ - public static ContextHandlerCollection findContextHandlerCollection(Server server) - { - if (server == null) - return null; - - return server.getDescendant(ContextHandlerCollection.class); - } - - /** - * Apply xml files to server instance. - * - * @param server the server to apply the xml to - * @param files the list of xml files - * @param properties list of jetty properties - * @return the Server implementation, after the xml is applied - * @throws Exception if unable to apply the xml configuration - */ - public static Server applyXmlConfigurations(Server server, List files, Map properties) - throws Exception - { - if (files == null || files.isEmpty()) - return server; - - Map lastMap = new HashMap<>(); - - if (server != null) - lastMap.put("Server", server); - - for (File xmlFile : files) - { - if (PluginLog.getLog() != null) - PluginLog.getLog().info("Configuring Jetty from xml configuration file = " + xmlFile.getCanonicalPath()); - - XmlConfiguration xmlConfiguration = new XmlConfiguration(ResourceFactory.of(server).newResource(xmlFile.toPath())); - - //add in any properties - if (properties != null) - { - for (Map.Entry e : properties.entrySet()) - { - xmlConfiguration.getProperties().put(e.getKey(), e.getValue()); - } - } - - //chain ids from one config file to another - if (lastMap != null) - xmlConfiguration.getIdMap().putAll(lastMap); - - //Set the system properties each time in case the config file set a new one - Enumeration ensysprop = System.getProperties().propertyNames(); - while (ensysprop.hasMoreElements()) - { - String name = (String)ensysprop.nextElement(); - xmlConfiguration.getProperties().put(name, System.getProperty(name)); - } - xmlConfiguration.configure(); - lastMap = xmlConfiguration.getIdMap(); - } - - return (Server)lastMap.get("Server"); - } - - /** - * Apply xml files to server instance. - * - * @param server the Server instance to configure - * @param files the xml configs to apply - * @return the Server after application of configs - * @throws Exception if there is an unspecified problem - */ - public static Server applyXmlConfigurations(Server server, List files) - throws Exception - { - return applyXmlConfigurations(server, files, null); - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/WarPluginInfo.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/WarPluginInfo.java deleted file mode 100644 index 78b566f14e1..00000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/WarPluginInfo.java +++ /dev/null @@ -1,239 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.maven.plugin; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.model.Plugin; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.eclipse.jetty.util.StringUtil; - -/** - * WarPluginInfo - * - * Information about the maven-war-plugin contained in the pom - */ -public class WarPluginInfo -{ - private MavenProject _project; - private Plugin _plugin; - private List _dependentMavenWarIncludes; - private List _dependentMavenWarExcludes; - private List _overlayConfigs; - private Set _warArtifacts; - - public WarPluginInfo(MavenProject project) - { - _project = project; - if (_project.getArtifacts() != null) - { - _warArtifacts = _project.getArtifacts() - .stream() - .filter(a -> "war".equals(a.getType()) || "zip".equals(a.getType())).collect(Collectors.toSet()); - } - else - _warArtifacts = Collections.emptySet(); - } - - /** - * Get the project. - * @return the project - */ - public MavenProject getProject() - { - return _project; - } - - /** - * Get all dependent artifacts that are wars. - * @return all artifacts of type "war" or "zip" - */ - public Set getWarArtifacts() - { - return _warArtifacts; - } - - /** - * Get an artifact of type war that matches the given coordinates. - * @param groupId the groupId to match - * @param artifactId the artifactId to match - * @param classifier the classified to match - * @return the matching Artifact or null if no match - */ - public Artifact getWarArtifact(String groupId, String artifactId, String classifier) - { - Optional o = _warArtifacts.stream() - .filter(a -> match(a, groupId, artifactId, classifier)).findFirst(); - return o.orElse(null); - } - - /** - * Find the maven-war-plugin, if one is configured - * - * @return the plugin - */ - public Plugin getWarPlugin() - { - if (_plugin == null) - { - List plugins = _project.getBuildPlugins(); - if (plugins == null) - return null; - - for (Plugin p : plugins) - { - if ("maven-war-plugin".equals(p.getArtifactId())) - { - _plugin = p; - break; - } - } - } - return _plugin; - } - - /** - * Get value of dependentWarIncludes for maven-war-plugin - * - * @return the list of dependent war includes - */ - public List getDependentMavenWarIncludes() - { - if (_dependentMavenWarIncludes == null) - { - getWarPlugin(); - - if (_plugin == null) - return null; - - Xpp3Dom node = (Xpp3Dom)_plugin.getConfiguration(); - if (node == null) - return null; - - node = node.getChild("dependentWarIncludes"); - if (node == null) - return null; - String val = node.getValue(); - _dependentMavenWarIncludes = StringUtil.csvSplit(null, val, 0, val.length()); - } - return _dependentMavenWarIncludes; - } - - /** - * Get value of dependentWarExcludes for maven-war-plugin - * - * @return the list of dependent war excludes - */ - public List getDependentMavenWarExcludes() - { - if (_dependentMavenWarExcludes == null) - { - getWarPlugin(); - - if (_plugin == null) - return null; - - Xpp3Dom node = (Xpp3Dom)_plugin.getConfiguration(); - if (node == null) - return null; - - node = node.getChild("dependentWarExcludes"); - if (node == null) - return null; - String val = node.getValue(); - _dependentMavenWarExcludes = StringUtil.csvSplit(null, val, 0, val.length()); - } - return _dependentMavenWarExcludes; - } - - /** - * Get config for any overlays that have been declared for the maven-war-plugin. - * - * @return the list of overlay configs - */ - public List getMavenWarOverlayConfigs() - { - if (_overlayConfigs == null) - { - getWarPlugin(); - - if (_plugin == null) - return Collections.emptyList(); - - getDependentMavenWarIncludes(); - getDependentMavenWarExcludes(); - - Xpp3Dom node = (Xpp3Dom)_plugin.getConfiguration(); - if (node == null) - return Collections.emptyList(); - - node = node.getChild("overlays"); - if (node == null) - return Collections.emptyList(); - - Xpp3Dom[] nodes = node.getChildren("overlay"); - if (nodes == null) - return Collections.emptyList(); - - _overlayConfigs = new ArrayList(); - for (int i = 0; i < nodes.length; i++) - { - OverlayConfig overlayConfig = new OverlayConfig(nodes[i], _dependentMavenWarIncludes, _dependentMavenWarExcludes); - _overlayConfigs.add(overlayConfig); - } - } - - return _overlayConfigs; - } - - public boolean match(Artifact a, String gid, String aid, String cls) - { - if (a == null) - return (gid == null && aid == null && cls == null); - - if (((a.getGroupId() == null && gid == null) || (a.getGroupId() != null && a.getGroupId().equals(gid))) && - ((a.getArtifactId() == null && aid == null) || (a.getArtifactId() != null && a.getArtifactId().equals(aid))) && - ((a.getClassifier() == null) || (a.getClassifier().equals(cls)))) - return true; - - return false; - } - - /** - * Check if the given artifact matches the group and artifact coordinates. - * - * @param a the artifact to check - * @param gid the group id - * @param aid the artifact id - * @return true if matched false otherwise - */ - public boolean match(Artifact a, String gid, String aid) - { - if (a == null) - return (gid == null && aid == null); - - if (((a.getGroupId() == null && gid == null) || (a.getGroupId() != null && a.getGroupId().equals(gid))) && - ((a.getArtifactId() == null && aid == null) || (a.getArtifactId() != null && a.getArtifactId().equals(aid)))) - return true; - - return false; - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/utils/MavenProjectHelper.java b/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/utils/MavenProjectHelper.java deleted file mode 100644 index 1f0c7197ea5..00000000000 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/java/org/eclipse/jetty/ee10/maven/plugin/utils/MavenProjectHelper.java +++ /dev/null @@ -1,185 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.maven.plugin.utils; - -import java.io.File; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.Function; -import java.util.stream.Collectors; - -import org.apache.maven.RepositoryUtils; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.project.MavenProject; -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.artifact.DefaultArtifact; -import org.eclipse.aether.resolution.ArtifactRequest; -import org.eclipse.aether.resolution.ArtifactResolutionException; -import org.eclipse.aether.resolution.ArtifactResult; -import org.eclipse.jetty.ee10.maven.plugin.OverlayManager; -import org.eclipse.jetty.ee10.maven.plugin.WarPluginInfo; - -/** - * MavenProjectHelper - * - * A class to facilitate interacting with the build time maven environment. - */ -public class MavenProjectHelper -{ - private MavenProject project; - private RepositorySystem repositorySystem; - private List remoteRepositories; - private MavenSession session; - private final Map artifactToReactorProjectMap; - /** - * maven-war-plugin reference - */ - private WarPluginInfo warPluginInfo; - - /** - * Helper for wrangling war overlays - */ - private OverlayManager overlayManager; - - /** - * @param project the project being built - * @param repositorySystem a resolve for artifacts - * @param remoteRepositories repositories from which to resolve artifacts - * @param session the current maven build session - */ - public MavenProjectHelper(MavenProject project, RepositorySystem repositorySystem, List remoteRepositories, MavenSession session) - { - this.project = project; - this.repositorySystem = repositorySystem; - this.remoteRepositories = remoteRepositories; - this.session = session; - //work out which dependent projects are in the reactor - Set mavenProjects = findDependenciesInReactor(project, new HashSet<>()); - artifactToReactorProjectMap = mavenProjects.stream() - .collect(Collectors.toMap(MavenProject::getId, Function.identity())); - artifactToReactorProjectMap.put(project.getArtifact().getId(), project); - warPluginInfo = new WarPluginInfo(project); - overlayManager = new OverlayManager(warPluginInfo); - } - - public MavenProject getProject() - { - return this.project; - } - - public WarPluginInfo getWarPluginInfo() - { - return warPluginInfo; - } - - public OverlayManager getOverlayManager() - { - return overlayManager; - } - - /** - * Gets the maven project represented by the artifact iff it is in - * the reactor. - * - * @param artifact the artifact of the project to get - * @return {@link MavenProject} if artifact is referenced in reactor, otherwise null - */ - public MavenProject getMavenProjectFor(Artifact artifact) - { - if (artifact == null) - return null; - return artifactToReactorProjectMap.get(artifact.getId()); - } - - /** - * Gets path to artifact. - * If the artifact is referenced in the reactor, returns path to ${project.build.outputDirectory}. - * Otherwise, returns path to location in local m2 repo. - * - * Cannot return null - maven will complain about unsatisfied dependency during project build. - * - * @param artifact maven artifact to check - * @return path to artifact - */ - public Path getPathFor(Artifact artifact) - { - Path path = artifact.getFile().toPath(); - MavenProject mavenProject = getMavenProjectFor(artifact); - if (mavenProject != null) - { - if ("test-jar".equals(artifact.getType())) - { - path = Paths.get(mavenProject.getBuild().getTestOutputDirectory()); - } - else - { - path = Paths.get(mavenProject.getBuild().getOutputDirectory()); - } - } - return path; - } - - /** - * Given the coordinates for an artifact, resolve the artifact from the - * remote repositories. - * - * @param groupId the groupId of the artifact to resolve - * @param artifactId the artifactId of the artifact to resolve - * @param version the version of the artifact to resolve - * @param type the type of the artifact to resolve - * @return a File representing the location of the artifact or null if not resolved - */ - public File resolveArtifact(String groupId, String artifactId, String version, String type) - throws ArtifactResolutionException - { - ArtifactRequest request = new ArtifactRequest(); - request.setRepositories(RepositoryUtils.toRepos(remoteRepositories)); - request.setArtifact(new DefaultArtifact(groupId, artifactId, "", type, version)); - ArtifactResult result = repositorySystem.resolveArtifact(session.getRepositorySession(), request); - - if (result.isResolved()) - return result.getArtifact().getFile(); - return null; - } - - /** - * Recursively find projects in the reactor for all dependencies of the given project. - * - * @param project the project for which to find dependencies that are in the reactor - * @param visitedProjects the set of projects already seen - * @return unified set of all related projects in the reactor - */ - private static Set findDependenciesInReactor(MavenProject project, Set visitedProjects) - { - if (visitedProjects.contains(project)) - return Collections.emptySet(); - - visitedProjects.add(project); - Collection refs = project.getProjectReferences().values(); - Set availableProjects = new HashSet<>(refs); - for (MavenProject ref : refs) - { - availableProjects.addAll(findDependenciesInReactor(ref, visitedProjects)); - } - return availableProjects; - } -} diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/resources/ee10-maven.mod b/jetty-ee10/jetty-ee10-maven-plugin/src/main/resources/ee10-maven.mod index 344d4aaaa82..ab4ed52419b 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/resources/ee10-maven.mod +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/resources/ee10-maven.mod @@ -12,7 +12,7 @@ ee10-webapp ee10-annotations [lib] -lib/maven-ee10/*.jar +lib/ee10-maven/*.jar [xml] etc/jetty-ee10-maven.xml diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/main/resources/jetty-ee10-maven.xml b/jetty-ee10/jetty-ee10-maven-plugin/src/main/resources/jetty-ee10-maven.xml index d1ba792557f..b83be87a647 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/main/resources/jetty-ee10-maven.xml +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/main/resources/jetty-ee10-maven.xml @@ -4,7 +4,7 @@ - + diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestForkedChild.java b/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestForkedChild.java index b2cc8e5f9c8..8e13f6fcb2e 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestForkedChild.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestForkedChild.java @@ -88,7 +88,7 @@ public class TestForkedChild webapp.setBaseResourceAsPath(baseDir.toPath()); WebAppPropertyConverter.toProperties(webapp, webappPropsFile, null); child = new JettyForkedChild(cmd.toArray(new String[0])); - child.jetty.setExitVm(false); //ensure jetty doesn't stop vm for testing + child.getJettyEmbedder().setExitVm(false); //ensure jetty doesn't stop vm for testing child.start(); } catch (Exception e) diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestJettyEmbedder.java b/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestJettyEmbedder.java index 7cbd78e1c09..b5bf18ed1f0 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestJettyEmbedder.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestJettyEmbedder.java @@ -19,6 +19,8 @@ import java.util.List; import java.util.Map; import org.eclipse.jetty.ee10.servlet.ListenerHolder; +import org.eclipse.jetty.maven.MavenServerConnector; +import org.eclipse.jetty.maven.ServerSupport; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ContextHandlerCollection; @@ -119,7 +121,7 @@ public class TestJettyEmbedder assertTrue(contexts.contains(webApp)); //stop the webapp and check durable listener retained - jetty.getWebApp().stop(); + jetty.stopWebApp(); boolean someListener = false; for (ListenerHolder h : webApp.getServletHandler().getListeners()) { diff --git a/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestSelectiveJarResource.java b/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestSelectiveJarResource.java index 2fb56640d90..483eb28668d 100644 --- a/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestSelectiveJarResource.java +++ b/jetty-ee10/jetty-ee10-maven-plugin/src/test/java/org/eclipse/jetty/ee10/maven/plugin/TestSelectiveJarResource.java @@ -18,6 +18,7 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import org.eclipse.jetty.maven.SelectiveJarResource; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; diff --git a/jetty-ee8/jetty-ee8-maven-plugin/pom.xml b/jetty-ee8/jetty-ee8-maven-plugin/pom.xml index fc9eaf2a258..cf75ae8a06d 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/pom.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/pom.xml @@ -86,6 +86,10 @@ jetty-jndi true + + org.eclipse.jetty + jetty-maven + org.eclipse.jetty jetty-server diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml index 5ce14c43a12..8a8f26b49f4 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml index 96f41b96416..ef0c9bcad93 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml @@ -32,7 +32,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml index 0bdfe18d525..343f5e7f99b 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee8.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee8.xml index 768db9db926..9857cb546ef 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee8.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee8.xml @@ -5,7 +5,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml index 0bdfe18d525..343f5e7f99b 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml index 0bdfe18d525..343f5e7f99b 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml index e8e0e40b005..94439d89a51 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml @@ -140,7 +140,7 @@ - + ${basedir}/src/config/login.xml diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml index 0bdfe18d525..343f5e7f99b 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml index 0bdfe18d525..343f5e7f99b 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee8.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee8.xml index 768db9db926..9857cb546ef 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee8.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee8.xml @@ -5,7 +5,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml index 0bdfe18d525..343f5e7f99b 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml index 0bdfe18d525..343f5e7f99b 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/main/resources/ee8-maven.mod b/jetty-ee8/jetty-ee8-maven-plugin/src/main/resources/ee8-maven.mod index e7f64949321..e16db22ed87 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/main/resources/ee8-maven.mod +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/main/resources/ee8-maven.mod @@ -12,7 +12,7 @@ ee8-webapp ee8-annotations [lib] -lib/maven-ee8/**.jar +lib/ee8-maven/**.jar [xml] etc/jetty-ee8-maven.xml diff --git a/jetty-ee8/jetty-ee8-maven-plugin/src/main/resources/jetty-ee8-maven.xml b/jetty-ee8/jetty-ee8-maven-plugin/src/main/resources/jetty-ee8-maven.xml index eb334cbc683..b83be87a647 100644 --- a/jetty-ee8/jetty-ee8-maven-plugin/src/main/resources/jetty-ee8-maven.xml +++ b/jetty-ee8/jetty-ee8-maven-plugin/src/main/resources/jetty-ee8-maven.xml @@ -4,7 +4,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/pom.xml b/jetty-ee9/jetty-ee9-maven-plugin/pom.xml index 25932a6e538..c7f54003b09 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/pom.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/pom.xml @@ -81,6 +81,11 @@ jetty-jndi true + + org.eclipse.jetty + jetty-maven + true + org.eclipse.jetty jetty-server diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml index 1bb69f935a7..8a8f26b49f4 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-cdi-start-forked/src/main/jetty/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-combinedresource-it/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-combinedresource-it/src/config/jetty.xml index b2e4ff6a33e..343f5e7f99b 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-combinedresource-it/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-combinedresource-it/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-effective-web-xml-it/webapp-war/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-effective-web-xml-it/webapp-war/src/config/jetty.xml index 4e43b5305df..343f5e7f99b 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-effective-web-xml-it/webapp-war/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-effective-web-xml-it/webapp-war/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml index 3ab59a4b5cb..ef0c9bcad93 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-maven-plugin-provided-module-dep/web/src/config/jetty.xml @@ -32,7 +32,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml index 72655392a8b..58c5b275121 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-run-mojo-jar-scan-it/MyWebApp/src/config/jetty.xml @@ -25,7 +25,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee9.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee9.xml index 07a874e46f0..9857cb546ef 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee9.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee9.xml @@ -5,7 +5,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml index b2e4ff6a33e..343f5e7f99b 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml index b2e4ff6a33e..343f5e7f99b 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-gwt-it/beer-server/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml index aadb236bb24..e5779619b9d 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/pom.xml @@ -112,7 +112,7 @@ - + ${basedir}/src/config/login.xml diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml index b2e4ff6a33e..343f5e7f99b 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml index b2e4ff6a33e..343f5e7f99b 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-mojo-multi-module-single-war-it/webapp-war/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-overlay-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-overlay-it/jetty-simple-webapp/src/config/jetty.xml index b2e4ff6a33e..343f5e7f99b 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-overlay-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-overlay-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee9.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee9.xml index 07a874e46f0..9857cb546ef 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee9.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-distro-mojo-it/jetty-simple-webapp/src/base/etc/test-jetty-ee9.xml @@ -5,7 +5,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml index b2e4ff6a33e..343f5e7f99b 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-forked-mojo-it/jetty-simple-webapp/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml index b2e4ff6a33e..343f5e7f99b 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/it/jetty-start-war-mojo-it/src/config/jetty.xml @@ -26,7 +26,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractUnassembledWebAppMojo.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractUnassembledWebAppMojo.java index 5185f62397e..0b23a5a9265 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractUnassembledWebAppMojo.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractUnassembledWebAppMojo.java @@ -23,6 +23,9 @@ import java.util.stream.Collectors; import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Parameter; +import org.eclipse.jetty.maven.MavenProjectHelper; +import org.eclipse.jetty.maven.Overlay; +import org.eclipse.jetty.maven.ScanPattern; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.ResourceFactory; import org.eclipse.jetty.util.resource.Resources; @@ -198,7 +201,7 @@ public abstract class AbstractUnassembledWebAppMojo extends AbstractWebAppMojo //process any overlays and the war type artifacts, and //sets up the base resource collection for the webapp - mavenProjectHelper.getOverlayManager().applyOverlays(webApp); + mavenProjectHelper.getOverlayManager().applyOverlays(webApp.getCoreContextHandler(), webApp.getBaseAppFirst()); getLog().info("web.xml file = " + webApp.getDescriptor()); getLog().info("Webapp directory = " + webAppSourceDirectory.getCanonicalPath()); diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractWebAppMojo.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractWebAppMojo.java index bd5ba9fc62d..eac0c0ce8f7 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractWebAppMojo.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/AbstractWebAppMojo.java @@ -47,7 +47,10 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.StringUtils; import org.eclipse.aether.RepositorySystem; -import org.eclipse.jetty.ee9.maven.plugin.utils.MavenProjectHelper; +import org.eclipse.jetty.maven.MavenProjectHelper; +import org.eclipse.jetty.maven.MavenServerConnector; +import org.eclipse.jetty.maven.PluginLog; +import org.eclipse.jetty.maven.ScanTargetPattern; import org.eclipse.jetty.security.LoginService; import org.eclipse.jetty.server.RequestLog; import org.eclipse.jetty.server.Server; @@ -562,7 +565,7 @@ public abstract class AbstractWebAppMojo extends AbstractMojo if (jettyHome == null) jetty.setJettyHomeZip(jettyHomeZip != null ? jettyHomeZip : mavenProjectHelper.resolveArtifact(JETTY_HOME_GROUPID, JETTY_HOME_ARTIFACTID, plugin.getVersion(), "zip")); - jetty.version = plugin.getVersion(); + jetty.setVersion(plugin.getVersion()); jetty.setJettyHome(jettyHome); jetty.setJettyBase(jettyBase); jetty.setBaseDir(target); diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyEmbedder.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyEmbedder.java index c21aad90725..5239ec1bb64 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyEmbedder.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyEmbedder.java @@ -24,6 +24,10 @@ import java.util.Properties; import org.eclipse.jetty.ee9.quickstart.QuickStartConfiguration; import org.eclipse.jetty.ee9.quickstart.QuickStartConfiguration.Mode; import org.eclipse.jetty.ee9.servlet.ServletHandler; +import org.eclipse.jetty.ee9.webapp.Configurations; +import org.eclipse.jetty.maven.AbstractJettyEmbedder; +import org.eclipse.jetty.maven.MavenServerConnector; +import org.eclipse.jetty.maven.ServerSupport; import org.eclipse.jetty.security.LoginService; import org.eclipse.jetty.server.RequestLog; import org.eclipse.jetty.server.Server; @@ -32,201 +36,21 @@ import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.component.ContainerLifeCycle; /** - * JettyEmbedded - * + * JettyEmbedder * Starts jetty within the current process. */ -public class JettyEmbedder extends ContainerLifeCycle +public class JettyEmbedder extends AbstractJettyEmbedder { - protected List contextHandlers; - protected List loginServices; - protected RequestLog requestLog; - protected MavenServerConnector httpConnector; - protected Server server; - protected MavenWebAppContext webApp; - protected boolean exitVm; - protected boolean stopAtShutdown; - protected List jettyXmlFiles; - protected Map jettyProperties; - protected ShutdownMonitor shutdownMonitor; - protected int stopPort; - protected String stopKey; - private String contextXml; - private Properties webAppProperties; + private MavenWebAppContext webApp; - public List getContextHandlers() - { - return contextHandlers; - } - - public void setContextHandlers(List contextHandlers) - { - if (contextHandlers == null) - this.contextHandlers = null; - else - this.contextHandlers = new ArrayList<>(contextHandlers); - } - - public List getLoginServices() - { - return loginServices; - } - - public void setLoginServices(List loginServices) - { - if (loginServices == null) - this.loginServices = null; - else - this.loginServices = new ArrayList<>(loginServices); - } - - public RequestLog getRequestLog() - { - return requestLog; - } - - public void setRequestLog(RequestLog requestLog) - { - this.requestLog = requestLog; - } - - public MavenServerConnector getHttpConnector() - { - return httpConnector; - } - - public void setHttpConnector(MavenServerConnector httpConnector) - { - this.httpConnector = httpConnector; - } - - public Server getServer() - { - return server; - } - - public void setServer(Server server) - { - this.server = server; - } - - public MavenWebAppContext getWebApp() - { - return webApp; - } - - public boolean isExitVm() - { - return exitVm; - } - - public void setExitVm(boolean exitVm) - { - this.exitVm = exitVm; - } - - public boolean isStopAtShutdown() - { - return stopAtShutdown; - } - - public void setStopAtShutdown(boolean stopAtShutdown) - { - this.stopAtShutdown = stopAtShutdown; - } - - public List getJettyXmlFiles() - { - return jettyXmlFiles; - } - - public void setJettyXmlFiles(List jettyXmlFiles) - { - this.jettyXmlFiles = jettyXmlFiles; - } - - public Map getJettyProperties() - { - return jettyProperties; - } - - public void setJettyProperties(Map jettyProperties) - { - this.jettyProperties = jettyProperties; - } - - public ShutdownMonitor getShutdownMonitor() - { - return shutdownMonitor; - } - - public void setShutdownMonitor(ShutdownMonitor shutdownMonitor) - { - this.shutdownMonitor = shutdownMonitor; - } - - public int getStopPort() - { - return stopPort; - } - - public void setStopPort(int stopPort) - { - this.stopPort = stopPort; - } - - public String getStopKey() - { - return stopKey; - } - - public void setStopKey(String stopKey) - { - this.stopKey = stopKey; - } - - public void setWebApp(MavenWebAppContext app) throws Exception + public void setWebApp(MavenWebAppContext app) { webApp = app; } - - public void setWebAppProperties(Properties props) - { - if (webAppProperties != null) - webAppProperties.clear(); - if (props != null) - { - if (webAppProperties == null) - webAppProperties = new Properties(); - - webAppProperties.putAll(props); - } - } - - public String getContextXml() + public void redeployWebApp() throws Exception { - return contextXml; - } - - public void setContextXml(String contextXml) - { - this.contextXml = contextXml; - } - - public void doStart() throws Exception - { - super.doStart(); - - configure(); - configureShutdownMonitor(); - server.start(); - } - - protected void redeployWebApp() throws Exception - { - if (!webApp.isStopped()) - webApp.stop(); + stopWebApp(); //clear the ServletHandler, which may have //remembered "durable" Servlets, Filters, Listeners @@ -239,40 +63,22 @@ public class JettyEmbedder extends ContainerLifeCycle webApp.start(); } - - protected void join() throws InterruptedException + + @Override + public void stopWebApp() throws Exception { - server.join(); + if (webApp != null && !webApp.isStopped()) + webApp.stop(); } /** - * Configure the server and the webapp + * Configure the webapp * @throws Exception if there is an unspecified problem */ - private void configure() throws Exception + public void configureWebApp() throws Exception { - //apply any configs from jetty.xml files first - Server tmp = ServerSupport.applyXmlConfigurations(new Server(), jettyXmlFiles, jettyProperties); - - if (tmp != null) - server = tmp; - - server.setStopAtShutdown(stopAtShutdown); - - //ensure there's a connector - if (httpConnector != null) - httpConnector.setServer(server); - - ServerSupport.configureConnectors(server, httpConnector, jettyProperties); - - //set up handler structure - ServerSupport.configureHandlers(server, contextHandlers, requestLog); - //Set up list of default Configurations to apply to a webapp - ServerSupport.configureDefaultConfigurationClasses(server); - - // set up security realms - ServerSupport.configureLoginServices(server, loginServices); + Configurations.setServerDefault(server); /* Configure the webapp */ if (webApp == null) @@ -291,32 +97,17 @@ public class JettyEmbedder extends ContainerLifeCycle webApp.setAttribute(QuickStartConfiguration.MODE, Mode.QUICKSTART); } } - - //add the webapp to the server - ServerSupport.addWebApplication(server, webApp); } - private void applyWebAppProperties() throws Exception + public void applyWebAppProperties() throws Exception { - //apply properties to the webapp if there are any - if (contextXml != null) - { - if (webAppProperties == null) - webAppProperties = new Properties(); - - webAppProperties.put("context.xml", contextXml); - } + super.applyWebAppProperties(); WebAppPropertyConverter.fromProperties(webApp, webAppProperties, server, jettyProperties); } - - private void configureShutdownMonitor() + + public void addWebAppToServer() throws Exception { - if (stopPort > 0 && stopKey != null) - { - ShutdownMonitor monitor = ShutdownMonitor.getInstance(); - monitor.setPort(stopPort); - monitor.setKey(stopKey); - monitor.setExitVm(exitVm); - } + //add the webapp to the server + ServerSupport.addWebApplication(server, webApp.getCoreContextHandler()); } } diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyForkedChild.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyForkedChild.java index ca454c304ca..ad6a54d83dc 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyForkedChild.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyForkedChild.java @@ -13,23 +13,8 @@ package org.eclipse.jetty.ee9.maven.plugin; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Properties; -import java.util.Set; - -import org.eclipse.jetty.util.Scanner; -import org.eclipse.jetty.util.StringUtil; -import org.eclipse.jetty.util.component.ContainerLifeCycle; +import org.eclipse.jetty.maven.AbstractForkedChild; +import org.eclipse.jetty.maven.AbstractJettyEmbedder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,15 +24,9 @@ import org.slf4j.LoggerFactory; * This is the class that is executed when the jetty maven plugin * forks a process when DeploymentMode=FORKED. */ -public class JettyForkedChild extends ContainerLifeCycle +public class JettyForkedChild extends AbstractForkedChild { private static final Logger LOG = LoggerFactory.getLogger(JettyForkedChild.class); - - protected JettyEmbedder jetty; - protected File tokenFile; // TODO: convert to Path - protected Scanner scanner; - protected File webAppPropsFile; // TODO: convert to Path - protected int scanInterval; /** * @param args arguments that were passed to main @@ -56,158 +35,13 @@ public class JettyForkedChild extends ContainerLifeCycle public JettyForkedChild(String[] args) throws Exception { - jetty = new JettyEmbedder(); - configure(args); + super(args); } - /** - * Based on the args passed to the program, configure jetty. - * - * @param args args that were passed to the program. - * @throws Exception if unable to load webprops - */ - public void configure(String[] args) - throws Exception + @Override + protected AbstractJettyEmbedder newJettyEmbedder() { - Map jettyProperties = new HashMap<>(); - - for (int i = 0; i < args.length; i++) - { - //--stop-port - if ("--stop-port".equals(args[i])) - { - jetty.setStopPort(Integer.parseInt(args[++i])); - continue; - } - - //--stop-key - if ("--stop-key".equals(args[i])) - { - jetty.setStopKey(args[++i]); - continue; - } - - //--jettyXml - if ("--jetty-xml".equals(args[i])) - { - List jettyXmls = new ArrayList<>(); - String[] names = StringUtil.csvSplit(args[++i]); - for (int j = 0; names != null && j < names.length; j++) - { - jettyXmls.add(new File(names[j].trim())); - } - jetty.setJettyXmlFiles(jettyXmls); - continue; - } - //--webprops - if ("--webprops".equals(args[i])) - { - webAppPropsFile = new File(args[++i].trim()); - jetty.setWebAppProperties(loadWebAppProps()); - continue; - } - - //--token - if ("--token".equals(args[i])) - { - tokenFile = new File(args[++i].trim()); - continue; - } - - if ("--scanInterval".equals(args[i])) - { - scanInterval = Integer.parseInt(args[++i].trim()); - scanner = new Scanner(); - scanner.setReportExistingFilesOnStartup(false); - scanner.setScanInterval(scanInterval); - scanner.addListener(new Scanner.BulkListener() - { - public void filesChanged(Set changes) - { - if (!Objects.isNull(scanner)) - { - try - { - scanner.stop(); - if (!Objects.isNull(jetty.getWebApp())) - { - //stop the webapp - jetty.getWebApp().stop(); - //reload the props - jetty.setWebAppProperties(loadWebAppProps()); - jetty.setWebApp(jetty.getWebApp()); - //restart the webapp - jetty.redeployWebApp(); - - //restart the scanner - scanner.start(); - } - } - catch (Exception e) - { - LOG.error("Error reconfiguring/restarting webapp after change in watched files", e); - } - } - } - }); - - if (!Objects.isNull(webAppPropsFile)) - scanner.addFile(webAppPropsFile.toPath()); - continue; - } - - //assume everything else is a jetty property to be passed in - String[] tmp = args[i].trim().split("="); - if (tmp.length == 2) - { - jettyProperties.put(tmp[0], tmp[1]); - } - } - - jetty.setJettyProperties(jettyProperties); - jetty.setExitVm(true); - } - - /** - * Load properties from a file describing the webapp if one is - * present. - * - * @return file contents as properties - * @throws FileNotFoundException if there is a file not found problem - * @throws IOException if there is an IO problem - */ - private Properties loadWebAppProps() throws FileNotFoundException, IOException - { - Properties props = new Properties(); - if (Objects.nonNull(webAppPropsFile)) - props.load(new FileInputStream(webAppPropsFile)); - return props; - } - - /** - * Start a jetty instance and webapp. This thread will - * wait until jetty exits. - */ - public void doStart() - throws Exception - { - super.doStart(); - - //Start the embedded jetty instance - jetty.start(); - - //touch file to signify start of jetty - Path tokenPath = tokenFile.toPath(); - Files.createFile(tokenPath); - - //Start a watcher on a file that will change if the - //webapp is regenerated; stop the webapp, apply the - //properties and restart it. - if (scanner != null) - scanner.start(); - - //wait for jetty to finish - jetty.join(); + return new JettyEmbedder(); } public static void main(String[] args) diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyForker.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyForker.java index 4231274bfb3..8c742ec1eb8 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyForker.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyForker.java @@ -18,108 +18,34 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.eclipse.jetty.maven.AbstractForker; +import org.eclipse.jetty.maven.AbstractServerForker; +import org.eclipse.jetty.maven.PluginLog; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.Jetty; /** * JettyForker * * Uses quickstart to generate a webapp and forks a process to run it. */ -public class JettyForker extends AbstractForker +public class JettyForker extends AbstractServerForker { - protected File forkWebXml; - protected Server server; protected MavenWebAppContext webApp; - protected String containerClassPath; - protected File webAppPropsFile; - protected String contextXml; - protected int scanInterval; QuickStartGenerator generator; - /** - * @return the scan - */ - public boolean isScan() + public JettyForker() { - return scanInterval > 0; + executionClassName = JettyForkedChild.class.getCanonicalName(); } - /** - * Set if true, the forked child will scan for changes at 1 second intervals. - * @param scan if true, the forked child will scan for changes at 1 second intervals - */ - public void setScan(boolean scan) + public void setWebApp(MavenWebAppContext webApp) { - setScanInterval(scan ? 1 : 0); - } - - public int getScanInterval() - { - return scanInterval; - } - - public void setScanInterval(int sec) - { - scanInterval = sec; - } - - public File getWebAppPropsFile() - { - return webAppPropsFile; - } - - public void setWebAppPropsFile(File webAppPropsFile) - { - this.webAppPropsFile = webAppPropsFile; - } - - public File getForkWebXml() - { - return forkWebXml; - } - - public void setForkWebXml(File forkWebXml) - { - this.forkWebXml = forkWebXml; - } - - public String getContextXml() - { - return contextXml; - } - - public void setContextXml(String contextXml) - { - this.contextXml = contextXml; - } - - public String getContainerClassPath() - { - return containerClassPath; - } - - public void setContainerClassPath(String containerClassPath) - { - this.containerClassPath = containerClassPath; - } - - public void setWebApp(MavenWebAppContext app) - { - webApp = app; - } - - public Server getServer() - { - return server; - } - - public void setServer(Server server) - { - this.server = server; + this.webApp = webApp; } @Override - public void doStart() + public void generateWebApp() throws Exception { //Run the webapp to create the quickstart file and properties file @@ -128,8 +54,6 @@ public class JettyForker extends AbstractForker generator.setWebAppPropsFile(webAppPropsFile.toPath()); generator.setServer(server); generator.generate(); - - super.doStart(); } protected void redeployWebApp() @@ -139,154 +63,4 @@ public class JettyForker extends AbstractForker //which will redeploy the webapp generator.generate(); } - - public ProcessBuilder createCommand() - { - List cmd = new ArrayList(); - cmd.add(getJavaBin()); - - if (jvmArgs != null) - { - String[] args = jvmArgs.split(" "); - for (int i = 0; args != null && i < args.length; i++) - { - if (args[i] != null && !"".equals(args[i])) - cmd.add(args[i].trim()); - } - } - - if (systemProperties != null) - { - for (Map.Entry e:systemProperties.entrySet()) - { - cmd.add("-D" + e.getKey() + "=" + e.getValue()); - } - } - - if (containerClassPath != null && containerClassPath.length() > 0) - { - cmd.add("-cp"); - cmd.add(containerClassPath); - } - - cmd.add(JettyForkedChild.class.getCanonicalName()); - - if (stopPort > 0 && stopKey != null) - { - cmd.add("--stop-port"); - cmd.add(Integer.toString(stopPort)); - cmd.add("--stop-key"); - cmd.add(stopKey); - } - if (jettyXmlFiles != null) - { - cmd.add("--jetty-xml"); - StringBuilder tmp = new StringBuilder(); - for (File jettyXml:jettyXmlFiles) - { - if (tmp.length() != 0) - tmp.append(","); - tmp.append(jettyXml.getAbsolutePath()); - } - cmd.add(tmp.toString()); - } - - cmd.add("--webprops"); - cmd.add(webAppPropsFile.getAbsolutePath()); - - cmd.add("--token"); - cmd.add(tokenFile.getAbsolutePath()); - - if (scanInterval > 0) - { - cmd.add("--scanInterval"); - cmd.add(Integer.toString(scanInterval)); - } - - if (jettyProperties != null) - { - for (Map.Entry e:jettyProperties.entrySet()) - { - cmd.add(e.getKey() + "=" + e.getValue()); - } - } - - ProcessBuilder command = new ProcessBuilder(cmd); - command.directory(workDir); - - if (PluginLog.getLog().isDebugEnabled()) - PluginLog.getLog().debug("Forked cli:" + command.command()); - - PluginLog.getLog().info("Forked process starting"); - - //set up extra environment vars if there are any - if (env != null && !env.isEmpty()) - command.environment().putAll(env); - - if (waitForChild) - { - command.inheritIO(); - } - else - { - command.redirectOutput(jettyOutputFile); - command.redirectErrorStream(true); - } - return command; - } - - /** - * Get the location of the java binary. - * @return the location of the java binary - */ - private String getJavaBin() - { - String[] javaexes = new String[]{"java", "java.exe"}; - - File javaHomeDir = new File(System.getProperty("java.home")); - for (String javaexe : javaexes) - { - File javabin = new File(javaHomeDir, fileSeparators("bin/" + javaexe)); - if (javabin.exists() && javabin.isFile()) - { - return javabin.getAbsolutePath(); - } - } - - return "java"; - } - - public static String fileSeparators(String path) - { - StringBuilder ret = new StringBuilder(); - for (char c : path.toCharArray()) - { - if ((c == '/') || (c == '\\')) - { - ret.append(File.separatorChar); - } - else - { - ret.append(c); - } - } - return ret.toString(); - } - - public static String pathSeparators(String path) - { - StringBuilder ret = new StringBuilder(); - for (char c : path.toCharArray()) - { - if ((c == ',') || (c == ':')) - { - ret.append(File.pathSeparatorChar); - } - else - { - ret.append(c); - } - } - return ret.toString(); - } } diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyHomeForker.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyHomeForker.java index c92f7be4292..d97acace38d 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyHomeForker.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyHomeForker.java @@ -13,153 +13,21 @@ package org.eclipse.jetty.ee9.maven.plugin; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.nio.file.FileAlreadyExistsException; -import java.nio.file.FileSystems; -import java.nio.file.FileVisitOption; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.EnumSet; -import java.util.List; -import java.util.Map; - -import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.StringUtil; -import org.eclipse.jetty.util.TypeUtil; -import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.util.resource.ResourceFactory; +import org.eclipse.jetty.maven.AbstractHomeForker; /** - * JettyHomeBaseForker + * JettyHomeForker * * Unpacks a jetty-home and configures it with a base that allows it * to run an unassembled webapp. */ -public class JettyHomeForker extends AbstractForker +public class JettyHomeForker extends AbstractHomeForker { protected MavenWebAppContext webApp; - protected String contextXml; - - /** - * Location of existing jetty home directory - */ - protected File jettyHome; - - /** - * Zip of jetty-home - */ - protected File jettyHomeZip; - - /** - * Location of existing jetty base directory - */ - protected File jettyBase; - - protected File baseDir; - - /** - * Optional list of other modules to - * activate. - */ - protected String[] modules; - - /* - * Optional jetty commands - */ - protected String jettyOptions; - - protected List libExtJarFiles; - protected Path modulesPath; - protected Path etcPath; - protected Path libPath; - protected Path webappPath; - protected Path mavenLibPath; - protected String version; - - public void setJettyOptions(String jettyOptions) + public JettyHomeForker() { - this.jettyOptions = jettyOptions; - } - - public String getJettyOptions() - { - return jettyOptions; - } - - public List getLibExtJarFiles() - { - return libExtJarFiles; - } - - public void setLibExtJarFiles(List libExtJarFiles) - { - this.libExtJarFiles = libExtJarFiles; - } - - public File getJettyHome() - { - return jettyHome; - } - - public void setJettyHome(File jettyHome) - { - this.jettyHome = jettyHome; - } - - public File getJettyBase() - { - return jettyBase; - } - - public void setJettyBase(File jettyBase) - { - this.jettyBase = jettyBase; - } - - public String[] getModules() - { - return modules; - } - - public void setModules(String[] modules) - { - this.modules = modules; - } - - public String getContextXmlFile() - { - return contextXml; - } - - public void setContextXml(String contextXml) - { - this.contextXml = contextXml; - } - - public File getJettyHomeZip() - { - return jettyHomeZip; - } - - public void setJettyHomeZip(File jettyHomeZip) - { - this.jettyHomeZip = jettyHomeZip; - } - - public MavenWebAppContext getWebApp() - { - return webApp; + environment = "ee9"; } public void setWebApp(MavenWebAppContext webApp) @@ -167,116 +35,6 @@ public class JettyHomeForker extends AbstractForker this.webApp = webApp; } - public File getBaseDir() - { - return baseDir; - } - - public void setBaseDir(File baseDir) - { - this.baseDir = baseDir; - } - - @Override - protected ProcessBuilder createCommand() - { - List cmd = new ArrayList<>(); - cmd.add("java"); - - //add any args to the jvm - if (StringUtil.isNotBlank(jvmArgs)) - { - Arrays.stream(jvmArgs.split(" ")).filter(a -> StringUtil.isNotBlank(a)).forEach((a) -> cmd.add(a.trim())); - } - - cmd.add("-jar"); - cmd.add(new File(jettyHome, "start.jar").getAbsolutePath()); - - if (systemProperties != null) - { - for (Map.Entry e : systemProperties.entrySet()) - { - cmd.add("-D" + e.getKey() + "=" + e.getValue()); - } - } - - cmd.add("-DSTOP.PORT=" + stopPort); - if (stopKey != null) - cmd.add("-DSTOP.KEY=" + stopKey); - - //set up enabled jetty modules - StringBuilder tmp = new StringBuilder(); - tmp.append("--module="); - tmp.append("server,http,ee9-webapp,ee9-deploy"); - if (modules != null) - { - for (String m : modules) - { - if (tmp.indexOf(m) < 0) - tmp.append("," + m); - } - } - - if (libExtJarFiles != null && !libExtJarFiles.isEmpty() && tmp.indexOf("ext") < 0) - tmp.append(",ext"); - tmp.append(",ee9-maven"); - cmd.add(tmp.toString()); - - //put any other jetty options onto the command line - if (StringUtil.isNotBlank(jettyOptions)) - { - Arrays.stream(jettyOptions.split(" ")).filter(a -> StringUtil.isNotBlank(a)).forEach((a) -> cmd.add(a.trim())); - } - - //put any jetty properties onto the command line - if (jettyProperties != null) - { - for (Map.Entry e : jettyProperties.entrySet()) - { - cmd.add(e.getKey() + "=" + e.getValue()); - } - } - - //existence of this file signals process started - cmd.add("jetty.token.file=" + tokenFile.getAbsolutePath().toString()); - - ProcessBuilder builder = new ProcessBuilder(cmd); - builder.directory(workDir); - - PluginLog.getLog().info("Home process starting"); - - //set up extra environment vars if there are any - if (!env.isEmpty()) - builder.environment().putAll(env); - - if (waitForChild) - builder.inheritIO(); - else - { - builder.redirectOutput(jettyOutputFile); - builder.redirectErrorStream(true); - } - return builder; - } - - @Override - public void doStart() throws Exception - { - //set up a jetty-home - configureJettyHome(); - - if (jettyHome == null || !jettyHome.exists()) - throw new IllegalStateException("No jetty home"); - - //set up a jetty-base - configureJettyBase(); - - //convert the webapp to properties - generateWebAppPropertiesFile(); - - super.doStart(); - } - protected void redeployWebApp() throws Exception { @@ -284,142 +42,9 @@ public class JettyHomeForker extends AbstractForker webappPath.resolve("maven.xml").toFile().setLastModified(System.currentTimeMillis()); } - private void generateWebAppPropertiesFile() + protected void generateWebAppPropertiesFile() throws Exception { WebAppPropertyConverter.toProperties(webApp, etcPath.resolve("maven.props").toFile(), contextXml); } - - /** - * Create or configure a jetty base. - */ - private void configureJettyBase() throws Exception - { - if (jettyBase != null && !jettyBase.exists()) - throw new IllegalStateException(jettyBase.getAbsolutePath() + " does not exist"); - - File targetJettyBase = new File(baseDir, "jetty-base"); - Path targetBasePath = targetJettyBase.toPath(); - if (Files.exists(targetBasePath)) - IO.delete(targetJettyBase); - - targetJettyBase.mkdirs(); - - //jetty-base will be the working directory for the forked command - workDir = targetJettyBase; - - //if there is an existing jetty base, copy parts of it - if (jettyBase != null) - { - Path jettyBasePath = jettyBase.toPath(); - - final File contextXmlFile = (contextXml == null ? null : FileSystems.getDefault().getPath(contextXml).toFile()); - - //copy the existing jetty base - Files.walkFileTree(jettyBasePath, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, - new SimpleFileVisitor() - { - @Override - public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException - { - Path targetDir = targetBasePath.resolve(jettyBasePath.relativize(dir)); - try - { - Files.copy(dir, targetDir); - } - catch (FileAlreadyExistsException e) - { - if (!Files.isDirectory(targetDir)) //ignore attempt to recreate dir - throw e; - } - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException - { - if (contextXmlFile != null && Files.isSameFile(contextXmlFile.toPath(), file)) - return FileVisitResult.CONTINUE; //skip copying the context xml file - Files.copy(file, targetBasePath.resolve(jettyBasePath.relativize(file))); - return FileVisitResult.CONTINUE; - } - }); - } - - //make the jetty base structure - modulesPath = Files.createDirectories(targetBasePath.resolve("modules")); - etcPath = Files.createDirectories(targetBasePath.resolve("etc")); - libPath = Files.createDirectories(targetBasePath.resolve("lib")); - webappPath = Files.createDirectories(targetBasePath.resolve("webapps")); - mavenLibPath = Files.createDirectories(libPath.resolve("maven-ee9")); - - //copy in the jetty-maven-plugin jar - URI thisJar = TypeUtil.getLocationOfClass(this.getClass()); - if (thisJar == null) - throw new IllegalStateException("Can't find jar for jetty-ee9-maven-plugin"); - - try (InputStream jarStream = thisJar.toURL().openStream(); - FileOutputStream fileStream = new FileOutputStream(mavenLibPath.resolve("plugin.jar").toFile())) - { - IO.copy(jarStream, fileStream); - } - - //copy in the maven.xml webapp file - try (InputStream mavenXmlStream = getClass().getClassLoader().getResourceAsStream("maven-ee9.xml"); - FileOutputStream fileStream = new FileOutputStream(webappPath.resolve("maven-ee9.xml").toFile())) - { - IO.copy(mavenXmlStream, fileStream); - } - - Files.writeString(webappPath.resolve("maven-ee9.properties"), "environment=ee9"); - - //copy in the maven.mod file - try (InputStream mavenModStream = getClass().getClassLoader().getResourceAsStream("ee9-maven.mod"); - FileOutputStream fileStream = new FileOutputStream(modulesPath.resolve("ee9-maven.mod").toFile())) - { - IO.copy(mavenModStream, fileStream); - } - - //copy in the jetty-maven.xml file - try (InputStream jettyMavenStream = getClass().getClassLoader().getResourceAsStream("jetty-ee9-maven.xml"); - FileOutputStream fileStream = new FileOutputStream(etcPath.resolve("jetty-ee9-maven.xml").toFile())) - { - IO.copy(jettyMavenStream, fileStream); - } - - //if there were plugin dependencies, copy them into lib/ext - if (libExtJarFiles != null && !libExtJarFiles.isEmpty()) - { - Path libExtPath = Files.createDirectories(libPath.resolve("ext")); - for (File f : libExtJarFiles) - { - try (InputStream jarStream = new FileInputStream(f); - FileOutputStream fileStream = new FileOutputStream(libExtPath.resolve(f.getName()).toFile())) - { - IO.copy(jarStream, fileStream); - } - } - } - } - - private void configureJettyHome() - throws Exception - { - if (jettyHome == null && jettyHomeZip == null) - throw new IllegalStateException("No jettyHome"); - - if (baseDir == null) - throw new IllegalStateException("No baseDir"); - - if (jettyHome == null) - { - try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable()) - { - Resource res = resourceFactory.newJarFileResource(jettyHomeZip.toPath().toUri()); - res.copyTo(baseDir.toPath()); - } - //zip will unpack to target/jetty-home- - jettyHome = new File(baseDir, "jetty-home-" + version); - } - } } diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyRunMojo.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyRunMojo.java index 3cfcba6891a..be4dcc1201b 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyRunMojo.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyRunMojo.java @@ -28,6 +28,7 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.eclipse.jetty.ee9.webapp.WebAppContext; +import org.eclipse.jetty.maven.ConsoleReader; import org.eclipse.jetty.util.IncludeExcludeSet; import org.eclipse.jetty.util.Scanner; import org.eclipse.jetty.util.component.LifeCycle; @@ -356,7 +357,7 @@ public class JettyRunMojo extends AbstractUnassembledWebAppMojo } } - embedder.getWebApp().stop(); + embedder.stopWebApp(); configureWebApp(); embedder.redeployWebApp(); if (scanner != null) diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyRunWarMojo.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyRunWarMojo.java index 11e2b201bf8..74df47acd19 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyRunWarMojo.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/JettyRunWarMojo.java @@ -25,6 +25,7 @@ import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; +import org.eclipse.jetty.maven.ConsoleReader; import org.eclipse.jetty.util.Scanner; import org.eclipse.jetty.util.StringUtil; @@ -235,7 +236,7 @@ public class JettyRunWarMojo extends AbstractWebAppMojo warArtifacts = null; configureScanner(); } - embedder.getWebApp().stop(); + embedder.stopWebApp(); configureWebApp(); embedder.redeployWebApp(); scanner.start(); diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenWebAppContext.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenWebAppContext.java index 0111a9457b1..15a03216616 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenWebAppContext.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/MavenWebAppContext.java @@ -37,6 +37,7 @@ import org.eclipse.jetty.ee9.webapp.Configuration; import org.eclipse.jetty.ee9.webapp.Configurations; import org.eclipse.jetty.ee9.webapp.MetaInfConfiguration; import org.eclipse.jetty.ee9.webapp.WebAppContext; +import org.eclipse.jetty.maven.Overlay; import org.eclipse.jetty.util.FileID; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.URIUtil; diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/QuickStartGenerator.java b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/QuickStartGenerator.java index 9c0fceca0c9..4fd8cdfb361 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/QuickStartGenerator.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/java/org/eclipse/jetty/ee9/maven/plugin/QuickStartGenerator.java @@ -18,6 +18,8 @@ import java.nio.file.Path; import org.eclipse.jetty.ee9.annotations.AnnotationConfiguration; import org.eclipse.jetty.ee9.quickstart.QuickStartConfiguration; import org.eclipse.jetty.ee9.quickstart.QuickStartConfiguration.Mode; +import org.eclipse.jetty.ee9.webapp.Configurations; +import org.eclipse.jetty.maven.ServerSupport; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.util.thread.QueuedThreadPool; @@ -152,7 +154,7 @@ public class QuickStartGenerator //ensure handler structure enabled ServerSupport.configureHandlers(server, null, null); - ServerSupport.configureDefaultConfigurationClasses(server); + Configurations.setServerDefault(server); //if our server has a thread pool associated we can do annotation scanning multithreaded, //otherwise scanning will be single threaded @@ -160,7 +162,7 @@ public class QuickStartGenerator tpool = server.getBean(QueuedThreadPool.class); //add webapp to our fake server instance - ServerSupport.addWebApplication(server, webApp); + ServerSupport.addWebApplication(server, webApp.getCoreContextHandler()); //leave everything unpacked for the forked process to use webApp.setPersistTempDirectory(true); diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/resources/ee9-maven.mod b/jetty-ee9/jetty-ee9-maven-plugin/src/main/resources/ee9-maven.mod index b418b19c1d1..4eee3f1211f 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/resources/ee9-maven.mod +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/resources/ee9-maven.mod @@ -12,7 +12,7 @@ ee9-webapp ee9-annotations [lib] -lib/maven-ee9/**.jar +lib/ee9-maven/**.jar [xml] etc/jetty-ee9-maven.xml diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/main/resources/jetty-ee9-maven.xml b/jetty-ee9/jetty-ee9-maven-plugin/src/main/resources/jetty-ee9-maven.xml index 4b7f403ba4a..b83be87a647 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/main/resources/jetty-ee9-maven.xml +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/main/resources/jetty-ee9-maven.xml @@ -4,7 +4,7 @@ - + diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestForkedChild.java b/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestForkedChild.java index dd26c1c1ed4..55fa53d1beb 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestForkedChild.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestForkedChild.java @@ -89,7 +89,7 @@ public class TestForkedChild webapp.setBaseResourceAsPath(baseDir.toPath()); WebAppPropertyConverter.toProperties(webapp, webappPropsFile, null); child = new JettyForkedChild(cmd.toArray(new String[0])); - child.jetty.setExitVm(false); //ensure jetty doesn't stop vm for testing + child.getJettyEmbedder().setExitVm(false); //ensure jetty doesn't stop vm for testing child.start(); } catch (Exception e) diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestJettyEmbedder.java b/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestJettyEmbedder.java index c8ac2df1722..ac4d077ec76 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestJettyEmbedder.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestJettyEmbedder.java @@ -20,6 +20,8 @@ import java.util.List; import java.util.Map; import org.eclipse.jetty.ee9.servlet.ListenerHolder; +import org.eclipse.jetty.maven.MavenServerConnector; +import org.eclipse.jetty.maven.ServerSupport; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ContextHandlerCollection; @@ -121,7 +123,7 @@ public class TestJettyEmbedder assertTrue(contexts.contains(webApp)); //stop the webapp and check durable listener retained - jetty.getWebApp().stop(); + jetty.stopWebApp(); boolean someListener = false; for (ListenerHolder h : webApp.getServletHandler().getListeners()) { diff --git a/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestSelectiveJarResource.java b/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestSelectiveJarResource.java index dba232cc86b..84538ea0ad7 100644 --- a/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestSelectiveJarResource.java +++ b/jetty-ee9/jetty-ee9-maven-plugin/src/test/java/org/eclipse/jetty/ee9/maven/plugin/TestSelectiveJarResource.java @@ -18,6 +18,7 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import org.eclipse.jetty.maven.SelectiveJarResource; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; diff --git a/pom.xml b/pom.xml index 96daf3e8f11..7a88efa4533 100644 --- a/pom.xml +++ b/pom.xml @@ -714,6 +714,11 @@ jetty-keystore ${project.version} + + org.eclipse.jetty + jetty-maven + ${project.version} + org.eclipse.jetty jetty-nosql From fd3fafca7342919cc8292b3b88266903fc1219e6 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 25 Apr 2024 20:56:30 -0500 Subject: [PATCH 15/15] [April 2024] Jetty 12 Dependency Updates (#11703) * Ensure JDK22 for eclipse-release * Updating Dependencies - April 2024 --- build/build-resources/pom.xml | 30 ++++++++++++++++++++++++++++++ build/scripts/release-jetty.sh | 2 +- pom.xml | 30 +++++++++++++++--------------- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/build/build-resources/pom.xml b/build/build-resources/pom.xml index da22d36e154..9d92e0591c7 100644 --- a/build/build-resources/pom.xml +++ b/build/build-resources/pom.xml @@ -101,4 +101,34 @@ + + + eclipse-release + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.4.1 + + + enforce-java + + enforce + + + + + [22,) + [ERROR] OLD JDK [${java.version}] in use. Jetty Release ${project.version} MUST use JDK 22 or newer + + + + + + + + + + diff --git a/build/scripts/release-jetty.sh b/build/scripts/release-jetty.sh index 952b1bfc5f0..db857d964cf 100755 --- a/build/scripts/release-jetty.sh +++ b/build/scripts/release-jetty.sh @@ -131,7 +131,7 @@ reportMavenTestFailures() { echo "" if proceedyn "Are you sure you want to release using above? (y/N)" n; then - mvn clean install -pl build -Dmaven.build.cache.enabled=false + mvn clean install -pl build -Peclipse-release -Dmaven.build.cache.enabled=false echo "" if proceedyn "Update VERSION.txt for $VER_RELEASE? (Y/n)" y; then mvn -N -Pupdate-version generate-resources -Dmaven.build.cache.enabled=false diff --git a/pom.xml b/pom.xml index 7a88efa4533..d858f707c16 100644 --- a/pom.xml +++ b/pom.xml @@ -155,13 +155,13 @@ 1.11.3 4.5.14 4.4.16 - 2.2.6 + 3.0.0 false 2.3.0 - 2.5.12 + 3.0.0-alpha.2 9.7 4.2.1 - 6.4.1 + 7.0.0 3.5.0 1.5 3.2.0 @@ -182,14 +182,14 @@ 1.6.0 2.26.1 4.0.6 - 1.62.2 + 1.63.0 2.10.1 33.1.0-jre 7.0.0 1.0.11 2.2 - 5.3.6 - 7.1.0.Final + 5.4.0 + 7.1.1.Final infinispan/server 15.0.1.Final-1 5.0.2.Final @@ -198,9 +198,9 @@ false false 2.17.0 - 0.8.11 + 0.8.12 false - 3.0.4.Final + 3.0.5.Final 3.6.1.Final 2.2.1.Final 2.2.1.Final @@ -235,13 +235,13 @@ 4.3 ${project.build.directory}/local-repo 2.23.1 - 1.5.3 + 1.5.6 9.9.2 10.3.6 3.3.3 0.13.1 1.1.0 - 3.11.0 + 3.12.0 3.1.0 3.7.1 5.1.9 @@ -257,15 +257,15 @@ 3.2.2 3.1.1 3.6.1 - 3.3.0 + 3.4.1 3.6.3 - 3.11.0 + 3.12.0 3.0.1 3.2.0 1.9.18 3.3.1 - 3.5.2 - 3.3.0 + 3.5.3 + 3.3.1 3.2.5 3.9.0 @@ -296,7 +296,7 @@ 4.13.5 2.6.14 2.2.0 - 4.0.0 + 4.0.1 4.0.3 2023-06-05T23:12:49Z UTF-8