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 c3e415d  Update to non deprecated APIs
c3e415d is described below

commit c3e415dbc24d71031b2d36bfc2ddff1e1ddf6ffc
Author: remm <[email protected]>
AuthorDate: Mon May 4 08:32:53 2026 +0200

    Update to non deprecated APIs
    
    Co authored using OpenCode.
---
 .../maven/plugin/tomcat/AbstractCatalinaMojo.java  | 20 ++---
 .../plugin/tomcat/run/AbstractExecWarMojo.java     | 86 ++++++++++++-------
 .../maven/plugin/tomcat/run/AbstractRunMojo.java   | 96 ++++++++++------------
 .../tomcat/run/AbstractStandaloneWarMojo.java      | 65 ++++++++++++---
 4 files changed, 161 insertions(+), 106 deletions(-)

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 b0ffe31..1cffaeb 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
@@ -18,11 +18,9 @@
  */
 package org.apache.tomcat.maven.plugin.tomcat;
 
-import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.wagon.authentication.AuthenticationInfo;
+import org.apache.maven.settings.Server;
 import org.apache.tomcat.maven.common.deployer.TomcatManager;
 import org.apache.tomcat.maven.common.deployer.TomcatManagerException;
 
@@ -64,12 +62,6 @@ public abstract class AbstractCatalinaMojo
     // Mojo Parameters
     // ----------------------------------------------------------------------
 
-    /**
-     * The Maven Wagon manager to use when obtaining server authentication 
details.
-     */
-    @Component
-    private WagonManager wagonManager;
-
     /**
      * The full URL of the Tomcat manager instance to use.
      */
@@ -185,16 +177,16 @@ public abstract class AbstractCatalinaMojo
             }
             else
             {
-                // obtain authenication details for specified server from wagon
-                AuthenticationInfo info = wagonManager.getAuthenticationInfo( 
server );
-                if ( info == null )
+                // obtain authentication details for specified server from 
settings
+                Server s = settings.getServer( server );
+                if ( s == null )
                 {
                     throw new MojoExecutionException(
                         messagesProvider.getMessage( 
"AbstractCatalinaMojo.unknownServer", server ) );
                 }
 
                 // derive username
-                userName = info.getUserName();
+                userName = s.getUsername();
                 if ( userName == null )
                 {
                     getLog().debug( messagesProvider.getMessage( 
"AbstractCatalinaMojo.defaultUserName" ) );
@@ -202,7 +194,7 @@ public abstract class AbstractCatalinaMojo
                 }
 
                 // derive password
-                password = info.getPassword();
+                password = s.getPassword();
                 if ( password == null )
                 {
                     getLog().debug( messagesProvider.getMessage( 
"AbstractCatalinaMojo.defaultPassword" ) );
diff --git 
a/src/main/java/org/apache/tomcat/maven/plugin/tomcat/run/AbstractExecWarMojo.java
 
b/src/main/java/org/apache/tomcat/maven/plugin/tomcat/run/AbstractExecWarMojo.java
index 25b108f..5544edf 100644
--- 
a/src/main/java/org/apache/tomcat/maven/plugin/tomcat/run/AbstractExecWarMojo.java
+++ 
b/src/main/java/org/apache/tomcat/maven/plugin/tomcat/run/AbstractExecWarMojo.java
@@ -38,13 +38,8 @@ import 
org.apache.commons.compress.archivers.ArchiveStreamFactory;
 import org.apache.commons.compress.archivers.jar.JarArchiveEntry;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
-
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -59,6 +54,10 @@ import org.codehaus.plexus.archiver.jar.Manifest;
 import org.codehaus.plexus.archiver.jar.ManifestException;
 import org.codehaus.plexus.util.DirectoryScanner;
 import org.codehaus.plexus.util.SelectorUtils;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.resolution.ArtifactRequest;
+import org.eclipse.aether.resolution.ArtifactResult;
 
 /**
  * @author Olivier Lamy
@@ -121,13 +120,7 @@ public abstract class AbstractExecWarMojo
     protected List<WarRunDependency> warRunDependencies;
 
     @Component
-    protected ArtifactResolver artifactResolver;
-
-    /**
-     * Maven Artifact Factory component.
-     */
-    @Component
-    protected ArtifactFactory artifactFactory;
+    protected RepositorySystem repositorySystem;
 
     /**
      * Location of the local repository.
@@ -141,6 +134,9 @@ public abstract class AbstractExecWarMojo
     @Parameter( defaultValue = "${project.remoteArtifactRepositories}", 
required = true, readonly = true )
     protected List<ArtifactRepository> remoteRepos;
 
+    @Parameter( defaultValue = "${session}", readonly = true, required = true )
+    protected org.apache.maven.execution.MavenSession session;
+
     @Component
     protected MavenProjectHelper projectHelper;
 
@@ -324,13 +320,7 @@ public abstract class AbstractExecWarMojo
                                 "Dependency '" + dependency.getGroupId() + 
"':'" + dependency.getArtifactId()
                                     + "' does not have version specified" );
                         }
-                        Artifact artifact = 
artifactFactory.createArtifactWithClassifier( dependency.getGroupId(), //
-                                                                               
           dependency.getArtifactId(), //
-                                                                               
           version, //
-                                                                               
           dependency.getType(), //
-                                                                               
           dependency.getClassifier() );
-
-                        artifactResolver.resolve( artifact, this.remoteRepos, 
this.local );
+                       Artifact artifact = toMavenArtifact( 
dependency.getGroupId(), dependency.getArtifactId(), version, 
dependency.getType(), dependency.getClassifier() );
 
                         File warFileToBundle = new File( 
resolvePluginWorkDir(), artifact.getFile().getName() );
                         FileUtils.copyFile( artifact.getFile(), 
warFileToBundle );
@@ -415,14 +405,7 @@ public abstract class AbstractExecWarMojo
                                 + "' does not have version specified" );
                     }
 
-                    // String groupId, String artifactId, String version, 
String scope, String type
-                    Artifact artifact = artifactFactory.createArtifact( 
dependency.getGroupId(), //
-                                                                        
dependency.getArtifactId(), //
-                                                                        
version, //
-                                                                        
dependency.getScope(), //
-                                                                        
dependency.getType() );
-
-                    artifactResolver.resolve( artifact, this.remoteRepos, 
this.local );
+                    Artifact artifact = toMavenArtifact( 
dependency.getGroupId(), dependency.getArtifactId(), version, 
dependency.getType(), null );
                     JarFile jarFile = new JarFile( artifact.getFile() );
                     extractJarToArchive( jarFile, os, this.excludes );
                 }
@@ -480,7 +463,7 @@ public abstract class AbstractExecWarMojo
             }
 
         }
-        catch (ManifestException | IOException | ArtifactNotFoundException | 
ArtifactResolutionException e )
+        catch (ManifestException | IOException e )
         {
             throw new MojoExecutionException( e.getMessage(), e );
         }
@@ -662,4 +645,51 @@ public abstract class AbstractExecWarMojo
         }
         file.close();
     }
+
+    private Artifact toMavenArtifact( String groupId, String artifactId, 
String version, String type, String classifier )
+        throws MojoExecutionException
+    {
+        try
+        {
+            org.eclipse.aether.artifact.Artifact aetherArtifact = new 
DefaultArtifact(
+                    groupId,
+                    artifactId,
+                    classifier != null && !classifier.isEmpty() ? classifier : 
type,
+                    type,
+                    version
+            );
+
+            ArtifactRequest req = new ArtifactRequest();
+            req.setArtifact( aetherArtifact );
+
+            List<org.eclipse.aether.repository.RemoteRepository> aetherRepos = 
new ArrayList<>();
+            for ( ArtifactRepository repo : remoteRepos )
+            {
+                org.eclipse.aether.repository.RemoteRepository aetherRepo = 
new org.eclipse.aether.repository.RemoteRepository.Builder(
+                        repo.getId(), "default", repo.getUrl() )
+                        .build();
+                aetherRepos.add( aetherRepo );
+            }
+            req.setRepositories( aetherRepos );
+
+            ArtifactResult result = repositorySystem.resolveArtifact( 
session.getRepositorySession(), req );
+            org.eclipse.aether.artifact.Artifact resolved = 
result.getArtifact();
+
+            Artifact mavenArtifact = new 
org.apache.maven.artifact.DefaultArtifact(
+                    groupId,
+                    artifactId,
+                    version,
+                    Artifact.SCOPE_COMPILE,
+                    type,
+                    classifier != null && !classifier.isEmpty() ? classifier : 
"",
+                    new 
org.apache.maven.artifact.handler.DefaultArtifactHandler( type )
+            );
+            mavenArtifact.setFile( resolved.getFile() );
+            return mavenArtifact;
+        }
+        catch ( Exception e )
+        {
+            throw new MojoExecutionException( "Unable to resolve artifact: " + 
e.getMessage(), e );
+        }
+    }
 }
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 b31aa94..4841a01 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
@@ -57,16 +57,9 @@ import org.apache.catalina.startup.CatalinaProperties;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.valves.AccessLogValve;
 import org.apache.commons.io.IOUtils;
-
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
-import 
org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
-import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -91,6 +84,10 @@ import org.codehaus.plexus.classworlds.realm.ClassRealm;
 import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
 import org.codehaus.plexus.util.DirectoryScanner;
 import org.codehaus.plexus.util.FileUtils;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.resolution.ArtifactRequest;
+import org.eclipse.aether.resolution.ArtifactResult;
 import org.w3c.dom.Document;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
@@ -107,23 +104,14 @@ public abstract class AbstractRunMojo
     // Mojo Components
     // ---------------------------------------------------------------------
 
-    /**
-     * Used to look up Artifacts in the remote repository.
-     */
-    @Component
-    protected ArtifactFactory factory;
-
     /**
      * Location of the local repository.
      */
     @Parameter( defaultValue = "${localRepository}", required = true, readonly 
= true )
     private ArtifactRepository local;
 
-    /**
-     * Used to look up Artifacts in the remote repository.
-     */
     @Component
-    protected ArtifactResolver resolver;
+    protected RepositorySystem repositorySystem;
 
     // ----------------------------------------------------------------------
     // Mojo Parameters
@@ -1215,13 +1203,13 @@ public abstract class AbstractRunMojo
 
                 portProperties.put( "tomcat.maven.http.port", 
Integer.toString( connector.getLocalPort() ) );
 
-                session.getExecutionProperties().put( "tomcat.maven.http.port",
+                session.getUserProperties().setProperty( 
"tomcat.maven.http.port",
                                                       Integer.toString( 
connector.getLocalPort() ) );
                 System.setProperty( "tomcat.maven.http.port", 
Integer.toString( connector.getLocalPort() ) );
 
                 if ( httpsConnector != null )
                 {
-                    session.getExecutionProperties().put( 
"tomcat.maven.https.port",
+                    session.getUserProperties().setProperty( 
"tomcat.maven.https.port",
                                                           Integer.toString( 
httpsConnector.getLocalPort() ) );
                     portProperties.put( "tomcat.maven.https.port", 
Integer.toString( httpsConnector.getLocalPort() ) );
                     System.setProperty( "tomcat.maven.https.port", 
Integer.toString( httpsConnector.getLocalPort() ) );
@@ -1229,7 +1217,7 @@ public abstract class AbstractRunMojo
 
                 if ( ajpConnector != null )
                 {
-                    session.getExecutionProperties().put( 
"tomcat.maven.ajp.port",
+                    session.getUserProperties().setProperty( 
"tomcat.maven.ajp.port",
                                                           Integer.toString( 
ajpConnector.getLocalPort() ) );
                     portProperties.put( "tomcat.maven.ajp.port", 
Integer.toString( ajpConnector.getLocalPort() ) );
                     System.setProperty( "tomcat.maven.ajp.port", 
Integer.toString( ajpConnector.getLocalPort() ) );
@@ -1485,46 +1473,50 @@ public abstract class AbstractRunMojo
     protected Artifact getArtifact( Webapp additionalWebapp )
         throws MojoExecutionException
     {
-
-        Artifact artifact;
-        VersionRange vr;
-        try
-        {
-            vr = VersionRange.createFromVersionSpec( 
additionalWebapp.getVersion() );
-        }
-        catch ( InvalidVersionSpecificationException e )
+        String classifier = additionalWebapp.getClassifier();
+        String version = additionalWebapp.getVersion();
+
+        org.eclipse.aether.artifact.Artifact aetherArtifact = new 
DefaultArtifact(
+                additionalWebapp.getGroupId(),
+                additionalWebapp.getArtifactId(),
+                classifier != null && !classifier.isEmpty() ? classifier : "",
+                additionalWebapp.getType(),
+                version
+        );
+
+        ArtifactRequest artifactRequest = new ArtifactRequest();
+        artifactRequest.setArtifact( aetherArtifact );
+
+        List<org.eclipse.aether.repository.RemoteRepository> aetherRepos = new 
ArrayList<>();
+        for ( org.apache.maven.artifact.repository.ArtifactRepository repo : 
project.getRemoteArtifactRepositories() )
         {
-            getLog().warn( "fail to create versionRange from version: " + 
additionalWebapp.getVersion(), e );
-            vr = VersionRange.createFromVersion( additionalWebapp.getVersion() 
);
-        }
-
-        if ( additionalWebapp.getClassifier() == null || 
additionalWebapp.getClassifier().isEmpty() )
-        {
-            artifact =
-                factory.createDependencyArtifact( 
additionalWebapp.getGroupId(), additionalWebapp.getArtifactId(), vr,
-                                                  additionalWebapp.getType(), 
null, Artifact.SCOPE_COMPILE );
-        }
-        else
-        {
-            artifact =
-                factory.createDependencyArtifact( 
additionalWebapp.getGroupId(), additionalWebapp.getArtifactId(), vr,
-                                                  additionalWebapp.getType(), 
additionalWebapp.getClassifier(),
-                                                  Artifact.SCOPE_COMPILE );
+            org.eclipse.aether.repository.RemoteRepository aetherRepo = new 
org.eclipse.aether.repository.RemoteRepository.Builder(
+                    repo.getId(), "default", repo.getUrl() )
+                    .build();
+            aetherRepos.add( aetherRepo );
         }
+        artifactRequest.setRepositories( aetherRepos );
 
         try
         {
-            resolver.resolve( artifact, 
project.getRemoteArtifactRepositories(), this.local );
+            ArtifactResult artifactResult = repositorySystem.resolveArtifact( 
session.getRepositorySession(), artifactRequest );
+            org.eclipse.aether.artifact.Artifact resolved = 
artifactResult.getArtifact();
+
+            Artifact artifact = new org.apache.maven.artifact.DefaultArtifact(
+                    additionalWebapp.getGroupId(),
+                    additionalWebapp.getArtifactId(),
+                    version,
+                    Artifact.SCOPE_COMPILE,
+                    additionalWebapp.getType(),
+                    classifier != null && !classifier.isEmpty() ? classifier : 
"",
+                    new 
org.apache.maven.artifact.handler.DefaultArtifactHandler( 
additionalWebapp.getType() )
+            );
+            artifact.setFile( resolved.getFile() );
+            return artifact;
         }
-        catch ( ArtifactResolutionException e )
+        catch ( Exception e )
         {
             throw new MojoExecutionException( "Unable to resolve artifact.", e 
);
         }
-        catch ( ArtifactNotFoundException e )
-        {
-            throw new MojoExecutionException( "Unable to find artifact.", e );
-        }
-
-        return artifact;
     }
 }
diff --git 
a/src/main/java/org/apache/tomcat/maven/plugin/tomcat/run/AbstractStandaloneWarMojo.java
 
b/src/main/java/org/apache/tomcat/maven/plugin/tomcat/run/AbstractStandaloneWarMojo.java
index a6a1e41..205aced 100644
--- 
a/src/main/java/org/apache/tomcat/maven/plugin/tomcat/run/AbstractStandaloneWarMojo.java
+++ 
b/src/main/java/org/apache/tomcat/maven/plugin/tomcat/run/AbstractStandaloneWarMojo.java
@@ -23,6 +23,8 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Properties;
 import java.util.jar.JarFile;
 
@@ -32,9 +34,12 @@ import 
org.apache.commons.compress.archivers.jar.JarArchiveEntry;
 import org.apache.commons.io.IOUtils;
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.model.Dependency;
+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.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.Parameter;
@@ -204,13 +209,12 @@ public abstract class AbstractStandaloneWarMojo
                                 + "' does not have version specified" );
                     }
                     // String groupId, String artifactId, String version, 
String scope, String type
-                    Artifact artifact = artifactFactory.createArtifact( 
dependency.getGroupId(), //
-                                                                        
dependency.getArtifactId(), //
-                                                                        
version, //
-                                                                        
dependency.getScope(), //
-                                                                        
dependency.getType() );
+                    Artifact artifact = resolveDependencyArtifact( 
dependency.getGroupId(), //
+                                                                  
dependency.getArtifactId(), //
+                                                                  version, //
+                                                                  
dependency.getType(), //
+                                                                  null );
 
-                    artifactResolver.resolve( artifact, this.remoteRepos, 
this.local );
                     JarFile jarFile = new JarFile( artifact.getFile() );
                     extractJarToArchive( jarFile, os, excludes );
                 }
@@ -275,10 +279,6 @@ public abstract class AbstractStandaloneWarMojo
         {
             throw new MojoExecutionException( e.getMessage(), e );
         }
-        catch ( ArtifactNotFoundException e )
-        {
-            throw new MojoExecutionException( e.getMessage(), e );
-        }
         catch ( ArtifactResolutionException e )
         {
             throw new MojoExecutionException( e.getMessage(), e );
@@ -292,4 +292,45 @@ public abstract class AbstractStandaloneWarMojo
         }
 
     }
+
+    protected Artifact resolveDependencyArtifact( String groupId, String 
artifactId, String version, String type, String classifier )
+        throws ArtifactResolutionException, IOException
+    {
+        org.eclipse.aether.artifact.Artifact aetherArtifact = new 
DefaultArtifact(
+                groupId,
+                artifactId,
+                classifier != null && !classifier.isEmpty() ? classifier : 
type,
+                type,
+                version
+        );
+
+        ArtifactRequest req = new ArtifactRequest();
+        req.setArtifact( aetherArtifact );
+
+        List<org.eclipse.aether.repository.RemoteRepository> aetherRepos = new 
ArrayList<>();
+        for ( ArtifactRepository repo : this.remoteRepos )
+        {
+            org.eclipse.aether.repository.RemoteRepository aetherRepo = new 
org.eclipse.aether.repository.RemoteRepository.Builder(
+                    repo.getId(), "default", repo.getUrl() )
+                    .build();
+            aetherRepos.add( aetherRepo );
+        }
+        req.setRepositories( aetherRepos );
+
+        ArtifactResult result = repositorySystem.resolveArtifact( 
session.getRepositorySession(), req );
+        org.eclipse.aether.artifact.Artifact resolved = result.getArtifact();
+
+        Artifact mavenArtifact = new org.apache.maven.artifact.DefaultArtifact(
+                groupId,
+                artifactId,
+                version,
+                null,
+                type,
+                classifier,
+                null
+        );
+        mavenArtifact.setFile( resolved.getFile() );
+
+        return mavenArtifact;
+    }
 }


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

Reply via email to