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

rmaucher 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 7c14d19  Replace deprecated URL constructors
7c14d19 is described below

commit 7c14d190d3302ff5dfbabd6376d06b8e9e27bb6b
Author: remm <[email protected]>
AuthorDate: Mon Apr 20 15:14:34 2026 +0200

    Replace deprecated URL constructors
---
 .../tomcat/maven/common/deployer/TomcatManager.java      | 16 ++++++++++++++--
 .../tomcat/maven/plugin/tomcat/AbstractCatalinaMojo.java |  7 ++++++-
 .../tomcat/maven/plugin/tomcat/run/AbstractRunMojo.java  |  9 +++++++--
 .../org/apache/tomcat/maven/runner/TomcatRunner.java     |  9 ++++++++-
 .../org/apache/tomcat/maven/it/AbstractWarProjectIT.java | 14 +++++++++++---
 5 files changed, 46 insertions(+), 9 deletions(-)

diff --git 
a/src/main/java/org/apache/tomcat/maven/common/deployer/TomcatManager.java 
b/src/main/java/org/apache/tomcat/maven/common/deployer/TomcatManager.java
index c64f196..19ecc57 100644
--- a/src/main/java/org/apache/tomcat/maven/common/deployer/TomcatManager.java
+++ b/src/main/java/org/apache/tomcat/maven/common/deployer/TomcatManager.java
@@ -25,6 +25,9 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.HttpURLConnection;
 import java.net.InetSocketAddress;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
@@ -766,7 +769,11 @@ public class TomcatManager
             case SC_MOVED_TEMPORARILY: // 302
             case SC_SEE_OTHER: // 303
                 relocateUrl = calculateRelocatedUrl( connection );
-                this.url = new URL( relocateUrl );
+                try {
+                    this.url = new URI(relocateUrl).toURL();
+                } catch (URISyntaxException e) {
+                    throw new MalformedURLException(e.getMessage());
+                }
                 return invoke( path, data, length );
         }
 
@@ -791,7 +798,12 @@ public class TomcatManager
 
     private HttpURLConnection openConnection( String urlString ) throws 
IOException
     {
-        URL url = new URL( urlString );
+        URL url = null;
+        try {
+            url = new URI(urlString).toURL();
+        } catch (URISyntaxException e) {
+            throw new MalformedURLException(e.getMessage());
+        }
         java.net.Proxy netProxy = java.net.Proxy.NO_PROXY;
 
         if ( proxySettings != null )
diff --git 
a/src/main/java/org/apache/tomcat/maven/plugin/tomcat/AbstractCatalinaMojo.java 
b/src/main/java/org/apache/tomcat/maven/plugin/tomcat/AbstractCatalinaMojo.java
index 438f7ec..b0ffe31 100644
--- 
a/src/main/java/org/apache/tomcat/maven/plugin/tomcat/AbstractCatalinaMojo.java
+++ 
b/src/main/java/org/apache/tomcat/maven/plugin/tomcat/AbstractCatalinaMojo.java
@@ -29,6 +29,7 @@ import 
org.apache.tomcat.maven.common.deployer.TomcatManagerException;
 
 import java.io.IOException;
 import java.net.MalformedURLException;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.StringTokenizer;
 
@@ -253,7 +254,11 @@ public abstract class AbstractCatalinaMojo
     protected URL getDeployedURL()
         throws MalformedURLException
     {
-        return new URL( getURL(), getPath() );
+        try {
+            return getURL().toURI().resolve(getPath()).toURL();
+        } catch (URISyntaxException e) {
+            throw new MalformedURLException(e.getMessage());
+        }
     }
 
     /**
diff --git 
a/src/main/java/org/apache/tomcat/maven/plugin/tomcat/run/AbstractRunMojo.java 
b/src/main/java/org/apache/tomcat/maven/plugin/tomcat/run/AbstractRunMojo.java
index 0db4a8c..b31aa94 100644
--- 
a/src/main/java/org/apache/tomcat/maven/plugin/tomcat/run/AbstractRunMojo.java
+++ 
b/src/main/java/org/apache/tomcat/maven/plugin/tomcat/run/AbstractRunMojo.java
@@ -24,11 +24,12 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -874,7 +875,11 @@ public abstract class AbstractRunMojo
     private URL getWebappUrl()
         throws MalformedURLException
     {
-        return new URL( "http", "localhost", port, getPath() );
+        try {
+            return (new URI("http", null, "localhost", port, getPath(), null, 
null)).toURL();
+        } catch (URISyntaxException e) {
+            throw new MalformedURLException(e.getMessage());
+        }
     }
 
     /**
diff --git a/src/main/java/org/apache/tomcat/maven/runner/TomcatRunner.java 
b/src/main/java/org/apache/tomcat/maven/runner/TomcatRunner.java
index 5377810..b26593c 100644
--- a/src/main/java/org/apache/tomcat/maven/runner/TomcatRunner.java
+++ b/src/main/java/org/apache/tomcat/maven/runner/TomcatRunner.java
@@ -25,6 +25,8 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.security.AccessController;
@@ -434,7 +436,12 @@ public class TomcatRunner
         {
             String urlStr = "jar:file:" + warPath + "!/META-INF/context.xml";
             debugMessage( "search context.xml in url:'" + urlStr + "'" );
-            URL url = new URL( urlStr );
+            URL url = null;
+            try {
+                url = new URI(urlStr).toURL();
+            } catch (URISyntaxException e) {
+                throw new MalformedURLException(e.getMessage());
+            }
             inputStream = url.openConnection().getInputStream();
             if ( inputStream != null )
             {
diff --git a/src/test/java/org/apache/tomcat/maven/it/AbstractWarProjectIT.java 
b/src/test/java/org/apache/tomcat/maven/it/AbstractWarProjectIT.java
index 6594f9c..aa0cd77 100644
--- a/src/test/java/org/apache/tomcat/maven/it/AbstractWarProjectIT.java
+++ b/src/test/java/org/apache/tomcat/maven/it/AbstractWarProjectIT.java
@@ -22,6 +22,9 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.util.Collections;
@@ -179,7 +182,12 @@ public abstract class AbstractWarProjectIT
     private String getResponseBody()
         throws IOException
     {
-        URL url = new URL( getWebappUrl() );
+        URL url;
+        try {
+            url = new URI(getWebappUrl()).toURL();
+        } catch (URISyntaxException e) {
+            throw new MalformedURLException(e.getMessage());
+        }
         HttpURLConnection connection = (HttpURLConnection) 
url.openConnection();
         connection.setConnectTimeout( getTimeout() );
         connection.setReadTimeout( getTimeout() );
@@ -198,9 +206,9 @@ public abstract class AbstractWarProjectIT
         final URL url;
         try
         {
-            url = new URL( getWebappUrl() );
+            url = new URI(getWebappUrl()).toURL();
         }
-        catch ( IOException e )
+        catch (IOException | URISyntaxException e)
         {
             logger.log(Level.FINE, "Ignoring exception while pinging URL " + 
getWebappUrl(), e );
             return -1;


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

Reply via email to