This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/tomcat-maven-plugin.git


The following commit(s) were added to refs/heads/trunk by this push:
     new bdf7755  Add wait goal
bdf7755 is described below

commit bdf77556f477f8f2845d3888cfaf26fe6a5d220d
Author: remm <[email protected]>
AuthorDate: Fri Apr 17 09:07:40 2026 +0200

    Add wait goal
    
    This allows waiting for deployments that have been forked to complete.
---
 README.md                                          |  12 +-
 .../maven/plugin/tomcat/deploy/WaitMojo.java       | 122 +++++++++++++++++++++
 .../maven/common/messages/messages.properties      |   6 +
 src/site/apt/context-goals.apt                     |   8 ++
 src/test/resources/context-goals-test/pom.xml      |   1 +
 5 files changed, 147 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 19e65d5..dc25900 100644
--- a/README.md
+++ b/README.md
@@ -26,13 +26,13 @@ mvn clean install
 To run integration tests:
 
 ```bash
-mvn clean install -Prun-its
+./run-its.sh
 ```
 
 Override default ports for integration tests:
 
 ```bash
-mvn clean install -Prun-its -Dits.http.port=8080 -Dits.ajp.port=8009
+./run-its.sh -Dits.http.port=8080 -Dits.ajp.port=8009
 ```
 
 ## Basic Usage
@@ -155,6 +155,8 @@ mvn tomcat:serverinfo
 mvn tomcat:resources
 ```
 
+### Context Goals
+
 **reload** - Reload a web application:
 
 ```bash
@@ -179,6 +181,12 @@ mvn tomcat:start
 mvn tomcat:stop
 ```
 
+**wait** - Wait for a specific webapp to become available:
+
+```bash
+mvn tomcat:wait
+```
+
 ## Configuration
 
 ### Deploy to Tomcat
diff --git 
a/src/main/java/org/apache/tomcat/maven/plugin/tomcat/deploy/WaitMojo.java 
b/src/main/java/org/apache/tomcat/maven/plugin/tomcat/deploy/WaitMojo.java
new file mode 100644
index 0000000..61b8196
--- /dev/null
+++ b/src/main/java/org/apache/tomcat/maven/plugin/tomcat/deploy/WaitMojo.java
@@ -0,0 +1,122 @@
+package org.apache.tomcat.maven.plugin.tomcat.deploy;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.tomcat.maven.common.deployer.TomcatManagerException;
+import org.apache.tomcat.maven.plugin.tomcat.AbstractCatalinaMojo;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Wait for the Tomcat server to become responsive.
+ *
+ * @since 3.0
+ */
+@Mojo(name = "wait", threadSafe = true)
+public class WaitMojo extends AbstractCatalinaMojo {
+    // ----------------------------------------------------------------------
+    // Mojo Parameters
+    // ----------------------------------------------------------------------
+
+    /**
+     * The maximum time to wait for the server to become responsive, in 
milliseconds.
+     */
+    @Parameter(property = "maven.tomcat.wait.timeout", defaultValue = "60000")
+    private long timeout = 60000;
+
+    /**
+     * The interval between checks, in milliseconds.
+     */
+    @Parameter(property = "maven.tomcat.wait.interval", defaultValue = "1000")
+    private long interval = 1000;
+
+    /**
+     * The HTTP status code to wait for.
+     */
+    @Parameter(property = "maven.tomcat.wait.status", defaultValue = "200")
+    private int status = 200;
+
+    // ----------------------------------------------------------------------
+    // Protected Methods
+    // ----------------------------------------------------------------------
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void invokeManager() throws MojoExecutionException, 
TomcatManagerException, IOException {
+        URL deployedURL = getDeployedURL();
+
+        getLog().info(messagesProvider.getMessage("WaitMojo.waitingForApp", 
deployedURL, timeout));
+
+        long startTime = System.currentTimeMillis();
+
+        while (true) {
+            try {
+                if (isServerResponsive(deployedURL)) {
+                    
getLog().info(messagesProvider.getMessage("WaitMojo.appReady", deployedURL));
+                    return;
+                }
+            } catch (IOException e) {
+                getLog().debug("Server not yet responsive: " + e.getMessage());
+            }
+
+            if (System.currentTimeMillis() - startTime > timeout) {
+                throw new 
MojoExecutionException(messagesProvider.getMessage("WaitMojo.timeout", 
deployedURL, timeout));
+            }
+
+            try {
+                TimeUnit.MILLISECONDS.sleep(interval);
+            } catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
+                throw new MojoExecutionException("Wait interrupted", e);
+            }
+        }
+    }
+
+    /**
+     * Checks if the server is responsive by making an HTTP request.
+     *
+     * @param url the URL to check
+     * 
+     * @return true if the server responds with the expected status code
+     * 
+     * @throws IOException if an I/O error occurs
+     */
+    private boolean isServerResponsive(URL url) throws IOException {
+        HttpURLConnection connection = (HttpURLConnection) 
url.openConnection();
+        connection.setConnectTimeout((int) interval);
+        connection.setReadTimeout((int) interval);
+        connection.setRequestMethod("HEAD");
+
+        try {
+            int responseCode = connection.getResponseCode();
+            return responseCode == status;
+        } finally {
+            connection.disconnect();
+        }
+    }
+}
\ No newline at end of file
diff --git 
a/src/main/resources/org/apache/tomcat/maven/common/messages/messages.properties
 
b/src/main/resources/org/apache/tomcat/maven/common/messages/messages.properties
index 7339cda..b176c32 100644
--- 
a/src/main/resources/org/apache/tomcat/maven/common/messages/messages.properties
+++ 
b/src/main/resources/org/apache/tomcat/maven/common/messages/messages.properties
@@ -110,3 +110,9 @@ ReloadMojo.reloadingApp = Reloading application at {0}
 
 tomcatHttpBodyError = Tomcat returned HTTP body error: {0}
 tomcatHttpStatusError = Tomcat returned HTTP status error: {0}, Reason Phrase: 
{1}
+
+# WaitMojo
+
+WaitMojo.waitingForApp = Waiting up to {1}ms for application at {0} to be ready
+WaitMojo.appReady = Application at {0} is ready
+WaitMojo.timeout = Application at {0} is not ready after {1}ms
diff --git a/src/site/apt/context-goals.apt b/src/site/apt/context-goals.apt
index d65ef07..28f58ab 100644
--- a/src/site/apt/context-goals.apt
+++ b/src/site/apt/context-goals.apt
@@ -88,6 +88,14 @@ mvn tomcat:stop
 mvn tomcat:reload
 +--
 
+* {Waiting for a WAR project to be available}
+
+  To wait for the end of the deployment of a WAR in Tomcat you can type:
+
++--
+mvn tomcat:wait
++--
+
 * {Listing session statistics}
 
   To list the session statistics for a deployed WAR project you can type:
diff --git a/src/test/resources/context-goals-test/pom.xml 
b/src/test/resources/context-goals-test/pom.xml
index 948e8bb..8f8f799 100644
--- a/src/test/resources/context-goals-test/pom.xml
+++ b/src/test/resources/context-goals-test/pom.xml
@@ -68,6 +68,7 @@
                         <id>tomcat-context-goals</id>
                         <phase>integration-test</phase>
                         <goals>
+                            <goal>wait</goal>
                             <goal>stop</goal>
                             <goal>start</goal>
                             <goal>reload</goal>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to