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-doxia-sitetools.git
The following commit(s) were added to refs/heads/master by this push:
new 677fa62 Find the site descriptor of a parent Maven 4 built from a
repository
677fa62 is described below
commit 677fa62e69fc71a39cb83d76e015e912e3e3829e
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Sun Sep 20 15:09:12 2026 +0200
Find the site descriptor of a parent Maven 4 built from a repository
Maven 3 leaves basedir unset for a parent resolved from a repository, and
DefaultSiteTool used that to decide between the site_xml artifact and a
src/site lookup. Maven 4 builds such parents from the repository copy of
the POM, so basedir points into the (project-)local repository and the
site descriptor is never found: site.xml inheritance from a released
parent silently stops working under Maven 4. A repository POM is always
named <artifactId>-<version>.pom, a checkout's never is; the parent menu
link uses the same test so it does not point into the repository.
---
.../apache/maven/doxia/tools/DefaultSiteTool.java | 23 ++++++++++++---
.../org/apache/maven/doxia/tools/SiteToolTest.java | 33 ++++++++++++++++++++++
2 files changed, 52 insertions(+), 4 deletions(-)
diff --git
a/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
b/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
index e2f1e41..c24080c 100644
---
a/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
+++
b/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
@@ -571,8 +571,8 @@ public class DefaultSiteTool implements SiteTool {
} else {
// parent has no url, assume relative path is given by site
structure
File parentBasedir = parentProject.getBasedir();
- // First make sure that the parent is available on the file system
- if (parentBasedir != null) {
+ // First make sure that the parent is a checkout on the file
system, not a repository copy
+ if (parentBasedir != null && !isFromRepository(parentProject)) {
// Try to find the relative path to the parent via the file
system
String parentPath = parentBasedir.getAbsolutePath();
String projectPath = project.getBasedir().getAbsolutePath();
@@ -859,6 +859,21 @@ public class DefaultSiteTool implements SiteTool {
return new ArtifactRequest(artifact, remoteProjectRepositories,
"remote-site-descriptor");
}
+ /**
+ * Tells whether a project was built from a POM taken out of a repository
rather than from a checkout. Maven 3
+ * leaves {@code basedir} unset for such projects; Maven 4 builds them
from the repository copy of the POM (local
+ * or project-local repository), whose file is always named {@code
<artifactId>-<version>.pom}, so the basedir
+ * alone no longer says where the POM came from. The version is not
compared: a snapshot's file carries the
+ * timestamped version while the model carries {@code -SNAPSHOT}.
+ */
+ static boolean isFromRepository(MavenProject project) {
+ if (project.getBasedir() == null) {
+ return true;
+ }
+ File pom = project.getFile();
+ return pom != null && pom.getName().endsWith(".pom") &&
pom.getName().startsWith(project.getArtifactId() + "-");
+ }
+
/**
* @param project not null
* @param repoSession the repository system session not null
@@ -1002,7 +1017,7 @@ public class DefaultSiteTool implements SiteTool {
throws SiteToolException {
// 1. get site descriptor File
File siteDescriptor;
- if (project.getBasedir() == null) {
+ if (isFromRepository(project)) {
// POM is in the repository: look into the repository for site
descriptor
try {
siteDescriptor =
@@ -1052,7 +1067,7 @@ public class DefaultSiteTool implements SiteTool {
LOGGER.debug("Looking for site descriptor of level " + depth + "
parent project: " + parentProject.getId());
File parentSiteDirectory = null;
- if (parentProject.getBasedir() != null) {
+ if (!isFromRepository(parentProject)) {
// extrapolate parent project site directory
String siteRelativePath = getRelativeFilePath(
project.getBasedir().getAbsolutePath(),
diff --git
a/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java
b/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java
index a009cc7..f1a5dba 100644
---
a/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java
+++
b/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java
@@ -420,6 +420,39 @@ class SiteToolTest {
modelFromRepo.getBannerLeft().getImage().getSrc());
assertEquals("https://maven.apache.org/",
modelFromRepo.getBannerLeft().getHref());
assertNull(modelFromRepo.getBannerRight());
+
+ // Maven 4 builds a repository project from its repository copy, so
basedir is set and the POM is the .pom
+ project.setBasedir(new File(getLocalRepoDir(),
"org/apache/maven/maven/3.8.6"));
+ project.setFile(new File(project.getBasedir(), "maven-3.8.6.pom"));
+ SiteModel modelFromRepoWithBasedir = tool.getSiteModel(
+ null,
+ SiteTool.DEFAULT_LOCALE,
+ new DefaultMavenExecutionRequest(),
+ project,
+ reactorProjects,
+ newRepoSession(),
+ project.getRemoteProjectRepositories());
+ assertEquals("dummy",
modelFromRepoWithBasedir.getBannerLeft().getName());
+ }
+
+ @Test
+ void isFromRepository() {
+ SiteToolMavenProjectStub project = new
SiteToolMavenProjectStub("site-tool-test");
+ project.setArtifactId("maven");
+ assertFalse(DefaultSiteTool.isFromRepository(project), "a checkout has
a basedir and a pom.xml");
+
+ project.setFile(new File(project.getBasedir(), "build.pom"));
+ assertFalse(DefaultSiteTool.isFromRepository(project), "a build file
named .pom is still a checkout");
+
+ project.setFile(new File(project.getBasedir(), "maven-3.8.6.pom"));
+ assertTrue(DefaultSiteTool.isFromRepository(project), "a repository
copy");
+
+ project.setFile(new File(project.getBasedir(),
"maven-3.9.0-20240101.010101-1.pom"));
+ assertTrue(DefaultSiteTool.isFromRepository(project), "a timestamped
snapshot copy");
+
+ project.setFile(new File(project.getBasedir(), "pom.xml"));
+ project.setBasedir(null);
+ assertTrue(DefaultSiteTool.isFromRepository(project), "Maven 3: no
basedir");
}
/**