You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2023/04/10 18:32:08 UTC

[maven-doxia-sitetools] branch DOXIASITETOOLS-301 created (now 0d9aafe)

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

michaelo pushed a change to branch DOXIASITETOOLS-301
in repository https://gitbox.apache.org/repos/asf/maven-doxia-sitetools.git


      at 0d9aafe  [DOXIASITETOOLS-301] Automatically remove the 0-byte site descriptors from the local repo

This branch includes the following new commits:

     new 0d9aafe  [DOXIASITETOOLS-301] Automatically remove the 0-byte site descriptors from the local repo

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-doxia-sitetools] 01/01: [DOXIASITETOOLS-301] Automatically remove the 0-byte site descriptors from the local repo

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch DOXIASITETOOLS-301
in repository https://gitbox.apache.org/repos/asf/maven-doxia-sitetools.git

commit 0d9aafe5a5b65ec588ace13096611f0a913dcdde
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Mon Apr 10 20:31:38 2023 +0200

    [DOXIASITETOOLS-301] Automatically remove the 0-byte site descriptors from the local repo
    
    This solution is not forever and is *not* concurrency-safe since we cannot
    obtain a sync context for it.
    
    This closes #104
---
 .../apache/maven/doxia/tools/DefaultSiteTool.java  | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)

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 fdbfcd1..bc7ed41 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
@@ -29,6 +29,8 @@ import java.io.StringReader;
 import java.io.StringWriter;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.AbstractMap;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -74,6 +76,8 @@ import org.codehaus.plexus.util.xml.Xpp3Dom;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 import org.eclipse.aether.RepositorySystem;
 import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.repository.LocalRepository;
+import org.eclipse.aether.repository.LocalRepositoryManager;
 import org.eclipse.aether.repository.RemoteRepository;
 import org.eclipse.aether.resolution.ArtifactRequest;
 import org.eclipse.aether.resolution.ArtifactResolutionException;
@@ -835,6 +839,8 @@ public class DefaultSiteTool implements SiteTool {
             ArtifactRequest request =
                     createSiteDescriptorArtifactRequest(project, localeStr, remoteProjectRepositories);
 
+            deletePseudoSiteDescriptorMarkerFile(repoSession, request);
+
             try {
                 ArtifactResult result = repositorySystem.resolveArtifact(repoSession, request);
 
@@ -855,6 +861,8 @@ public class DefaultSiteTool implements SiteTool {
             ArtifactRequest request =
                     createSiteDescriptorArtifactRequest(project, localeStr, remoteProjectRepositories);
 
+            deletePseudoSiteDescriptorMarkerFile(repoSession, request);
+
             try {
                 ArtifactResult result = repositorySystem.resolveArtifact(repoSession, request);
 
@@ -875,6 +883,8 @@ public class DefaultSiteTool implements SiteTool {
             ArtifactRequest request =
                     createSiteDescriptorArtifactRequest(project, localeStr, remoteProjectRepositories);
 
+            deletePseudoSiteDescriptorMarkerFile(repoSession, request);
+
             try {
                 ArtifactResult result = repositorySystem.resolveArtifact(repoSession, request);
 
@@ -894,6 +904,9 @@ public class DefaultSiteTool implements SiteTool {
             localeStr = SiteTool.DEFAULT_LOCALE.toString();
             ArtifactRequest request =
                     createSiteDescriptorArtifactRequest(project, localeStr, remoteProjectRepositories);
+
+            deletePseudoSiteDescriptorMarkerFile(repoSession, request);
+
             try {
                 ArtifactResult result = repositorySystem.resolveArtifact(repoSession, request);
 
@@ -911,6 +924,27 @@ public class DefaultSiteTool implements SiteTool {
         return siteDescriptor;
     }
 
+    // TODO Remove this transient method when everyone has migrated to Maven Site Plugin 4.0.0+
+    private void deletePseudoSiteDescriptorMarkerFile(RepositorySystemSession repoSession, ArtifactRequest request) {
+        LocalRepository localRepository = repoSession.getLocalRepository();
+        LocalRepositoryManager lrm = repoSession.getLocalRepositoryManager();
+
+        String relativeLocalArtifactPath = lrm.getPathForLocalArtifact(request.getArtifact());
+        Path localArtifactPath = localRepository.getBasedir().toPath().resolve(relativeLocalArtifactPath);
+
+        try {
+            if (Files.exists(localArtifactPath) && Files.size(localArtifactPath) == 0L) {
+                LOGGER.debug(
+                        "Deleting 0-byte pseudo marker file for artifact '{}' at '{}'",
+                        request.getArtifact(),
+                        localArtifactPath);
+                Files.delete(localArtifactPath);
+            }
+        } catch (IOException e) {
+            // swallow
+        }
+    }
+
     /**
      * @param depth depth of project
      * @param siteDirectory, can be null if project.basedir is null, ie POM from repository