This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-doap-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 045e17e Use Maven Resolver intead of HTTP components (#133)
045e17e is described below
commit 045e17ed9b22d7acc2d4d5bcceb9d92f5615fb26
Author: Elliotte Rusty Harold <[email protected]>
AuthorDate: Tue Dec 16 12:17:42 2025 +0000
Use Maven Resolver intead of HTTP components (#133)
* Deprecate fetchURL
* existence check
---
pom.xml | 22 +++++--
.../org/apache/maven/plugin/doap/DoapMojo.java | 64 ++++++++++++++++--
.../org/apache/maven/plugin/doap/DoapUtil.java | 75 ++--------------------
3 files changed, 81 insertions(+), 80 deletions(-)
diff --git a/pom.xml b/pom.xml
index 33eb44d..f569dc1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,7 +63,7 @@ under the License.
<javaVersion>8</javaVersion>
<mavenVersion>3.9.11</mavenVersion>
<scmVersion>2.2.1</scmVersion>
- <resolverVersion>1.9.25</resolverVersion>
+ <resolverVersion>1.9.24</resolverVersion>
<checkstyle.violation.ignore>FileLength</checkstyle.violation.ignore>
<project.build.outputTimestamp>2025-11-24T20:16:28Z</project.build.outputTimestamp>
</properties>
@@ -118,6 +118,21 @@ under the License.
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven.resolver</groupId>
+ <artifactId>maven-resolver-api</artifactId>
+ <version>${resolverVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.resolver</groupId>
+ <artifactId>maven-resolver-impl</artifactId>
+ <version>${resolverVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.resolver</groupId>
+ <artifactId>maven-resolver-spi</artifactId>
+ <version>${resolverVersion}</version>
+ </dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
@@ -182,11 +197,6 @@ under the License.
<artifactId>jena-core</artifactId>
<version>3.17.0</version>
</dependency>
- <dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>3.1</version>
- </dependency>
<!-- test -->
<dependency>
diff --git a/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java
b/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java
index a30e450..2ef6883 100644
--- a/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java
+++ b/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java
@@ -78,6 +78,13 @@ import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.impl.RepositoryConnectorProvider;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.spi.connector.ArtifactDownload;
+import org.eclipse.aether.spi.connector.RepositoryConnector;
+import org.eclipse.aether.transfer.NoRepositoryConnectorException;
/**
* <p>
@@ -144,6 +151,9 @@ public class DoapMojo extends AbstractMojo {
@Inject
private RepositoryMetadataManager repositoryMetadataManager;
+ @Inject
+ private RepositorySystem repositorySystem;
+
/**
* Internationalization component.
*
@@ -162,6 +172,9 @@ public class DoapMojo extends AbstractMojo {
@Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
+ @Parameter(defaultValue = "${repositorySystemSession}", readonly = true)
+ private RepositorySystemSession repositorySystemSession;
+
/**
* The name of the DOAP file that will be generated.
*/
@@ -200,6 +213,9 @@ public class DoapMojo extends AbstractMojo {
@Inject
private ArtifactFactory factory;
+ @Inject
+ private RepositoryConnectorProvider connectorProvider;
+
/**
* Project builder.
*
@@ -1349,12 +1365,12 @@ public class DoapMojo extends AbstractMojo {
}
String fileRelease = repo.getUrl() + "/" +
repo.pathOf(artifactRelease);
- try {
- DoapUtil.fetchURL(settings, new URL(fileRelease));
- } catch (IOException e) {
- getLog().debug("IOException :" + e.getMessage());
+
+ if (!isArtifactInRepository(artifactRelease, repo)) {
+ getLog().debug(artifactRelease + " is not in the
repository " + repo);
continue;
}
+
DoapUtil.writeElement(writer, doapOptions.getXmlnsPrefix(),
"file-release", fileRelease);
Date releaseDate = null;
@@ -1381,6 +1397,46 @@ public class DoapMojo extends AbstractMojo {
}
}
+ private boolean isArtifactInRepository(Artifact artifact,
ArtifactRepository repository) {
+ // Convert Legacy Artifact to Aether Artifact
+ String artifactCoordinates = String.format(
+ "%s:%s:%s:%s",
+ artifact.getGroupId(), artifact.getArtifactId(),
artifact.getType(), artifact.getVersion());
+
+ org.eclipse.aether.artifact.Artifact aetherArtifact =
+ new
org.eclipse.aether.artifact.DefaultArtifact(artifactCoordinates);
+
+ // Convert Legacy ArtifactRepository to Aether RemoteRepository
+ RemoteRepository remoteRepository = new RemoteRepository.Builder(
+ repository.getId(), repository.getLayout().getId(),
repository.getUrl())
+ .build();
+
+ // set up authentication
+ remoteRepository = repositorySystem
+ .newResolutionRepositories(repositorySystemSession,
Collections.singletonList(remoteRepository))
+ .get(0);
+
+ return artifactExistsRemotely(aetherArtifact, remoteRepository);
+ }
+
+ /**
+ * Check if an artifact exists in a remote repo without downloading it.
+ */
+ private boolean
artifactExistsRemotely(org.eclipse.aether.artifact.Artifact artifact,
RemoteRepository repository) {
+ try (RepositoryConnector connector =
+
connectorProvider.newRepositoryConnector(this.repositorySystemSession,
repository)) {
+ ArtifactDownload download = new ArtifactDownload(artifact, null,
null, null);
+ download.setExistenceCheck(true);
+
+ connector.get(Collections.singleton(download), null);
+
+ return download.getException() == null;
+
+ } catch (NoRepositoryConnectorException e) {
+ return false;
+ }
+ }
+
/**
* Write all DOAP repositories.
*
diff --git a/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java
b/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java
index 3b7a9f7..99cfde4 100644
--- a/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java
+++ b/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java
@@ -19,12 +19,10 @@
package org.apache.maven.plugin.doap;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
-import java.net.SocketTimeoutException;
import java.net.URL;
import java.text.DateFormat;
import java.util.ArrayList;
@@ -43,25 +41,13 @@ import java.util.WeakHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.commons.httpclient.Credentials;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
-import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.commons.httpclient.auth.AuthScope;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.params.HttpClientParams;
-import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.RDFReader;
import org.apache.jena.rdf.model.impl.RDFDefaultErrorHandler;
import org.apache.maven.model.Contributor;
import org.apache.maven.project.MavenProject;
-import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Settings;
-import org.apache.maven.wagon.proxy.ProxyInfo;
-import org.apache.maven.wagon.proxy.ProxyUtils;
import org.codehaus.plexus.i18n.I18N;
import org.codehaus.plexus.interpolation.EnvarBasedValueSource;
import org.codehaus.plexus.interpolation.InterpolationException;
@@ -457,74 +443,23 @@ public class DoapUtil {
}
/**
- * Fetch a URL.
+ * Pings a URL.
*
- * @param settings the user settings used to fetch the URL with an active
proxy, if defined
+ * @param settings ignored
* @param url the URL to fetch
* @throws IOException if any
- * @see #DEFAULT_TIMEOUT
* @since 1.1
+ * @deprecated Use java.net.URL or a different library to load the URL.
*/
- @SuppressWarnings("checkstyle:emptyblock")
+ @Deprecated
public static void fetchURL(Settings settings, URL url) throws IOException
{
if (url == null) {
throw new IllegalArgumentException("The url is null");
}
- if ("file".equals(url.getProtocol())) {
- // [ERROR]
src/main/java/org/apache/maven/plugin/doap/DoapUtil.java:[474,53] (blocks)
EmptyBlock: Empty try
- // block.
- // Test if file exists
- try (InputStream in = url.openStream()) {}
+ try (InputStream in = url.openStream()) {
return;
}
-
- // http, https...
- HttpClient httpClient = new HttpClient(new
MultiThreadedHttpConnectionManager());
-
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(DEFAULT_TIMEOUT);
-
httpClient.getHttpConnectionManager().getParams().setSoTimeout(DEFAULT_TIMEOUT);
-
httpClient.getParams().setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS,
true);
-
- // Some web servers don't allow the default user-agent sent by
httpClient
- httpClient
- .getParams()
- .setParameter(HttpMethodParams.USER_AGENT, "Mozilla/4.0
(compatible; MSIE 6.0; Windows NT 5.0)");
-
- if (settings != null && settings.getActiveProxy() != null) {
- Proxy activeProxy = settings.getActiveProxy();
-
- ProxyInfo proxyInfo = new ProxyInfo();
- proxyInfo.setNonProxyHosts(activeProxy.getNonProxyHosts());
-
- if (StringUtils.isNotEmpty(activeProxy.getHost())
- && !ProxyUtils.validateNonProxyHosts(proxyInfo,
url.getHost())) {
-
httpClient.getHostConfiguration().setProxy(activeProxy.getHost(),
activeProxy.getPort());
-
- if (StringUtils.isNotEmpty(activeProxy.getUsername()) &&
activeProxy.getPassword() != null) {
- Credentials credentials =
- new
UsernamePasswordCredentials(activeProxy.getUsername(),
activeProxy.getPassword());
-
- httpClient.getState().setProxyCredentials(AuthScope.ANY,
credentials);
- }
- }
- }
-
- GetMethod getMethod = new GetMethod(url.toString());
- try {
- int status;
- try {
- status = httpClient.executeMethod(getMethod);
- } catch (SocketTimeoutException e) {
- // could be a sporadic failure, one more retry before we give
up
- status = httpClient.executeMethod(getMethod);
- }
-
- if (status != HttpStatus.SC_OK) {
- throw new FileNotFoundException(url.toString());
- }
- } finally {
- getMethod.releaseConnection();
- }
}
/**