You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2026/09/26 08:09:35 UTC
(maven-indexer) branch master updated: Locate the main artifact only next to its POM
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-indexer.git
The following commit(s) were added to refs/heads/master by this push:
new 5911ddd2 Locate the main artifact only next to its POM
5911ddd2 is described below
commit 5911ddd221167e241bc0baee285c6aef0c638683
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Sat Sep 26 01:57:34 2026 +0200
Locate the main artifact only next to its POM
---
.../index/DefaultArtifactContextProducer.java | 7 ++++-
.../maven/index/locator/ArtifactLocator.java | 5 ++++
.../maven/index/locator/ArtifactLocatorTest.java | 34 ++++++++++++++++++++++
3 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/indexer-core/src/main/java/org/apache/maven/index/DefaultArtifactContextProducer.java b/indexer-core/src/main/java/org/apache/maven/index/DefaultArtifactContextProducer.java
index b366f889..36f9da7f 100644
--- a/indexer-core/src/main/java/org/apache/maven/index/DefaultArtifactContextProducer.java
+++ b/indexer-core/src/main/java/org/apache/maven/index/DefaultArtifactContextProducer.java
@@ -88,7 +88,12 @@ public class DefaultArtifactContextProducer implements ArtifactContextProducer {
// If we found the matching artifact, switch over to indexing that, instead of the pom
if (artifact != null) {
- gav = getGavFromPath(context, repositoryPath, artifact.getAbsolutePath());
+ Gav artifactGav = getGavFromPath(context, repositoryPath, artifact.getAbsolutePath());
+ if (artifactGav != null) {
+ gav = artifactGav;
+ } else {
+ artifact = null;
+ }
}
pom = file;
diff --git a/indexer-core/src/main/java/org/apache/maven/index/locator/ArtifactLocator.java b/indexer-core/src/main/java/org/apache/maven/index/locator/ArtifactLocator.java
index ad536c38..601ebb7f 100644
--- a/indexer-core/src/main/java/org/apache/maven/index/locator/ArtifactLocator.java
+++ b/indexer-core/src/main/java/org/apache/maven/index/locator/ArtifactLocator.java
@@ -69,6 +69,11 @@ public class ArtifactLocator implements GavHelpedLocator {
String artifactName = gav.getArtifactId() + "-" + gav.getVersion() + "."
+ mapper.getExtensionForPackaging(model.getPackaging());
+ // the artifact is a sibling of the POM
+ if (artifactName.indexOf('/') >= 0 || artifactName.indexOf('\\') >= 0) {
+ return null;
+ }
+
File artifact = source.toPath().resolveSibling(artifactName).toFile();
if (!artifact.exists()) {
diff --git a/indexer-core/src/test/java/org/apache/maven/index/locator/ArtifactLocatorTest.java b/indexer-core/src/test/java/org/apache/maven/index/locator/ArtifactLocatorTest.java
index 369be5a3..d55ad5cc 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/locator/ArtifactLocatorTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/locator/ArtifactLocatorTest.java
@@ -19,16 +19,23 @@
package org.apache.maven.index.locator;
import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
import org.apache.maven.index.AbstractNexusIndexerTest;
import org.apache.maven.index.ArtifactContext;
import org.apache.maven.index.ArtifactContextProducer;
import org.apache.maven.index.NexusIndexer;
import org.apache.maven.index.artifact.ArtifactPackagingMapper;
+import org.apache.maven.index.artifact.DefaultArtifactPackagingMapper;
import org.apache.maven.index.artifact.Gav;
import org.apache.maven.index.artifact.M2GavCalculator;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class ArtifactLocatorTest extends AbstractNexusIndexerTest {
@@ -77,4 +84,31 @@ public class ArtifactLocatorTest extends AbstractNexusIndexerTest {
assertTrue(artifactFile != null, "Artifact file was not located!");
assertTrue(artifactFile.exists(), "Artifact file was not located!");
}
+
+ @Test
+ public void testArtifactLocatorFindsSibling(@TempDir Path dir) throws IOException {
+ Files.createFile(dir.resolve("a-1.0.zip"));
+
+ assertEquals(dir.resolve("a-1.0.zip").toFile(), locate(dir, "zip"));
+ }
+
+ @Test
+ public void testArtifactLocatorIgnoresPackagingWithPathSeparator(@TempDir Path dir) throws IOException {
+ Files.createDirectories(dir.resolve("a-1.0.zip"));
+ Files.createFile(dir.resolve("a-1.0.zip").resolve("b"));
+
+ assertNull(locate(dir, "zip/b"));
+ }
+
+ private static File locate(Path dir, String packaging) throws IOException {
+ Path pom = dir.resolve("a-1.0.pom");
+ Files.writeString(
+ pom,
+ "<project><modelVersion>4.0.0</modelVersion><groupId>g</groupId><artifactId>a</artifactId>"
+ + "<version>1.0</version><packaging>" + packaging + "</packaging></project>");
+
+ M2GavCalculator gavCalculator = new M2GavCalculator();
+ Gav gav = gavCalculator.pathToGav("g/a/1.0/a-1.0.pom");
+ return new ArtifactLocator(new DefaultArtifactPackagingMapper()).locate(pom.toFile(), gavCalculator, gav);
+ }
}