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

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

commit d2f36df6a8592ae6c20d9ccaf754da0dc5705100
Author: Michael Osipov <micha...@apache.org>
AuthorDate: Fri Mar 17 22:52:53 2023 +0100

    [DOXIASITETOOLS-294] Replace legacy artifact resolution with Maven Resolver
    
    This closes #94
---
 .../apache/maven/doxia/tools/DefaultSiteTool.java  | 324 +++++++++------------
 .../org/apache/maven/doxia/tools/SiteTool.java     |  29 +-
 .../org/apache/maven/doxia/tools/SiteToolTest.java |  53 ++--
 .../tools/stubs/SiteToolMavenProjectStub.java      |   7 +
 4 files changed, 183 insertions(+), 230 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 b1df33f..e614788 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
@@ -40,12 +40,11 @@ import java.util.Objects;
 import java.util.StringTokenizer;
 
 import org.apache.commons.io.FilenameUtils;
+import org.apache.maven.RepositoryUtils;
 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.DefaultArtifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
 import 
org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
 import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.doxia.site.decoration.DecorationModel;
@@ -57,13 +56,8 @@ import 
org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader;
 import org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Writer;
 import org.apache.maven.model.DistributionManagement;
 import org.apache.maven.model.Plugin;
-import org.apache.maven.model.Site;
-import org.apache.maven.project.DefaultProjectBuildingRequest;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuilder;
-import org.apache.maven.project.ProjectBuildingException;
-import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.project.ProjectBuildingResult;
 import org.apache.maven.reporting.MavenReport;
 import org.codehaus.plexus.i18n.I18N;
 import org.codehaus.plexus.interpolation.EnvarBasedValueSource;
@@ -77,6 +71,13 @@ import org.codehaus.plexus.util.ReaderFactory;
 import org.codehaus.plexus.util.StringUtils;
 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.RemoteRepository;
+import org.eclipse.aether.resolution.ArtifactRequest;
+import org.eclipse.aether.resolution.ArtifactResolutionException;
+import org.eclipse.aether.resolution.ArtifactResult;
+import org.eclipse.aether.transfer.ArtifactNotFoundException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -95,16 +96,16 @@ public class DefaultSiteTool implements SiteTool {
     // ----------------------------------------------------------------------
 
     /**
-     * The component that is used to resolve additional artifacts required.
+     * The component that is used to resolve additional required artifacts.
      */
     @Inject
-    private ArtifactResolver artifactResolver;
+    protected RepositorySystem repositorySystem;
 
     /**
-     * The component used for creating artifact instances.
+     * The component used for getting artifact handlers.
      */
     @Inject
-    private ArtifactFactory artifactFactory;
+    private ArtifactHandlerManager artifactHandlerManager;
 
     /**
      * Internationalization.
@@ -128,36 +129,43 @@ public class DefaultSiteTool implements SiteTool {
     // Public methods
     // ----------------------------------------------------------------------
 
+    /** {@inheritDoc} */
     public Artifact getSkinArtifactFromRepository(
-            ArtifactRepository localRepository,
-            List<ArtifactRepository> remoteArtifactRepositories,
-            DecorationModel decoration)
+            RepositorySystemSession repoSession, List<RemoteRepository> 
remoteProjectRepositories, Skin skin)
             throws SiteToolException {
-        Objects.requireNonNull(localRepository, "localRepository cannot be 
null");
-        Objects.requireNonNull(remoteArtifactRepositories, 
"remoteArtifactRepositories cannot be null");
-        Objects.requireNonNull(decoration, "decoration cannot be null");
-        Skin skin = Objects.requireNonNull(decoration.getSkin(), 
"decoration.skin cannot be null");
+        Objects.requireNonNull(repoSession, "repoSession cannot be null");
+        Objects.requireNonNull(remoteProjectRepositories, 
"remoteProjectRepositories cannot be null");
+        Objects.requireNonNull(skin, "skin cannot be null");
 
         String version = skin.getVersion();
-        Artifact artifact;
         try {
             if (version == null) {
                 version = Artifact.RELEASE_VERSION;
             }
             VersionRange versionSpec = 
VersionRange.createFromVersionSpec(version);
-            artifact = artifactFactory.createDependencyArtifact(
-                    skin.getGroupId(), skin.getArtifactId(), versionSpec, 
"jar", null, null);
-
-            artifactResolver.resolve(artifact, remoteArtifactRepositories, 
localRepository);
+            String type = "jar";
+            Artifact artifact = new DefaultArtifact(
+                    skin.getGroupId(),
+                    skin.getArtifactId(),
+                    versionSpec,
+                    Artifact.SCOPE_RUNTIME,
+                    type,
+                    null,
+                    artifactHandlerManager.getArtifactHandler(type));
+            ArtifactRequest request =
+                    new ArtifactRequest(RepositoryUtils.toArtifact(artifact), 
remoteProjectRepositories, "remote-skin");
+            ArtifactResult result = 
repositorySystem.resolveArtifact(repoSession, request);
+
+            return RepositoryUtils.toArtifact(result.getArtifact());
         } catch (InvalidVersionSpecificationException e) {
             throw new SiteToolException("The skin version '" + version + "' is 
not valid", e);
         } catch (ArtifactResolutionException e) {
+            if (e.getCause() instanceof ArtifactNotFoundException) {
+                throw new SiteToolException("The skin does not exist", 
e.getCause());
+            }
+
             throw new SiteToolException("Unable to find skin", e);
-        } catch (ArtifactNotFoundException e) {
-            throw new SiteToolException("The skin does not exist", e);
         }
-
-        return artifact;
     }
 
     /**
@@ -325,8 +333,8 @@ public class DefaultSiteTool implements SiteTool {
      * Get a site descriptor from one of the repositories.
      *
      * @param project the Maven project, not null.
-     * @param localRepository the Maven local repository, not null.
-     * @param repositories the Maven remote repositories, not null.
+     * @param repoSession the repository system session, not null.
+     * @param remoteProjectRepositories the Maven remote project repositories, 
not null.
      * @param locale the locale wanted for the site descriptor, not null.
      * See {@link #getSiteDescriptor(File, Locale)} for details.
      * @return the site descriptor into the local repository after download of 
it from repositories or null if not
@@ -335,17 +343,17 @@ public class DefaultSiteTool implements SiteTool {
      */
     File getSiteDescriptorFromRepository(
             MavenProject project,
-            ArtifactRepository localRepository,
-            List<ArtifactRepository> repositories,
+            RepositorySystemSession repoSession,
+            List<RemoteRepository> remoteProjectRepositories,
             Locale locale)
             throws SiteToolException {
         Objects.requireNonNull(project, "project cannot be null");
-        Objects.requireNonNull(localRepository, "localRepository cannot be 
null");
-        Objects.requireNonNull(repositories, "repositories cannot be null");
+        Objects.requireNonNull(repoSession, "repoSession cannot be null");
+        Objects.requireNonNull(remoteProjectRepositories, 
"remoteProjectRepositories cannot be null");
         Objects.requireNonNull(locale, "locale cannot be null");
 
         try {
-            return resolveSiteDescriptor(project, localRepository, 
repositories, locale);
+            return resolveSiteDescriptor(project, repoSession, 
remoteProjectRepositories, locale);
         } catch (ArtifactNotFoundException e) {
             LOGGER.debug("Unable to locate site descriptor", e);
             return null;
@@ -361,21 +369,21 @@ public class DefaultSiteTool implements SiteTool {
             File siteDirectory,
             Locale locale,
             MavenProject project,
-            List<MavenProject> reactorProjects,
-            ArtifactRepository localRepository,
-            List<ArtifactRepository> repositories)
+            List<MavenProject> projectModules,
+            RepositorySystemSession repoSession,
+            List<RemoteRepository> remoteProjectRepositories)
             throws SiteToolException {
         Objects.requireNonNull(locale, "locale cannot be null");
         Objects.requireNonNull(project, "project cannot be null");
-        Objects.requireNonNull(reactorProjects, "reactorProjects cannot be 
null");
-        Objects.requireNonNull(localRepository, "localRepository cannot be 
null");
-        Objects.requireNonNull(repositories, "repositories cannot be null");
+        Objects.requireNonNull(projectModules, "projectModules cannot be 
null");
+        Objects.requireNonNull(repoSession, "repoSession cannot be null");
+        Objects.requireNonNull(remoteProjectRepositories, 
"remoteProjectRepositories cannot be null");
 
         LOGGER.debug("Computing decoration model of '" + project.getId() + "' 
for "
                 + (locale.equals(SiteTool.DEFAULT_LOCALE) ? "default locale" : 
"locale '" + locale + "'"));
 
         Map.Entry<DecorationModel, MavenProject> result =
-                getDecorationModel(0, siteDirectory, locale, project, 
reactorProjects, localRepository, repositories);
+                getDecorationModel(0, siteDirectory, locale, project, 
repoSession, remoteProjectRepositories);
         DecorationModel decorationModel = result.getKey();
         MavenProject parentProject = result.getValue();
 
@@ -397,7 +405,7 @@ public class DefaultSiteTool implements SiteTool {
         }
 
         try {
-            populateModulesMenu(decorationModel, locale, project, 
reactorProjects, localRepository, true);
+            populateModulesMenu(decorationModel, locale, project, 
projectModules, true);
         } catch (IOException e) {
             throw new SiteToolException("Error while populating modules menu", 
e);
         }
@@ -519,8 +527,7 @@ public class DefaultSiteTool implements SiteTool {
      * @param decorationModel the Doxia Sitetools DecorationModel, not null.
      * @param locale the locale used for the i18n in DecorationModel, not null.
      * @param project a Maven project, not null.
-     * @param reactorProjects the Maven reactor projects, not null.
-     * @param localRepository the Maven local repository, not null.
+     * @param projectModules the project modules, not null.
      * @param keepInheritedRefs used for inherited references.
      * @throws SiteToolException if any
      * @throws IOException
@@ -529,15 +536,13 @@ public class DefaultSiteTool implements SiteTool {
             DecorationModel decorationModel,
             Locale locale,
             MavenProject project,
-            List<MavenProject> reactorProjects,
-            ArtifactRepository localRepository,
+            List<MavenProject> projectModules,
             boolean keepInheritedRefs)
             throws SiteToolException, IOException {
         Objects.requireNonNull(decorationModel, "decorationModel cannot be 
null");
         Objects.requireNonNull(locale, "locale cannot be null");
         Objects.requireNonNull(project, "project cannot be null");
-        Objects.requireNonNull(reactorProjects, "reactorProjects cannot be 
null");
-        Objects.requireNonNull(localRepository, "localRepository cannot be 
null");
+        Objects.requireNonNull(projectModules, "projectModules cannot be 
null");
 
         Menu menu = decorationModel.getMenuRef("modules");
 
@@ -550,39 +555,12 @@ public class DefaultSiteTool implements SiteTool {
         }
 
         // we require child modules and reactors to process module menu
-        if (project.getModules().size() > 0) {
+        if (!projectModules.isEmpty()) {
             if (menu.getName() == null) {
                 menu.setName(i18n.getString("site-tool", locale, 
"decorationModel.menu.projectmodules"));
             }
 
-            for (String module : (List<String>) project.getModules()) {
-                MavenProject moduleProject = getModuleFromReactor(project, 
reactorProjects, module);
-
-                if (moduleProject == null) {
-                    LOGGER.warn("Module " + module + " not found in reactor: 
loading locally");
-
-                    File f = new File(project.getBasedir(), module + 
"/pom.xml");
-                    if (f.exists()) {
-                        try {
-                            ProjectBuildingRequest request = new 
DefaultProjectBuildingRequest();
-                            request.setLocalRepository(localRepository);
-
-                            ProjectBuildingResult result = 
projectBuilder.build(f, request);
-                            moduleProject = result.getProject();
-                        } catch (ProjectBuildingException e) {
-                            throw new SiteToolException("Unable to read local 
module POM", e);
-                        }
-                    } else {
-                        LOGGER.warn("No filesystem module POM available");
-
-                        moduleProject = new MavenProject();
-                        moduleProject.setName(module);
-                        moduleProject.setDistributionManagement(new 
DistributionManagement());
-                        moduleProject.getDistributionManagement().setSite(new 
Site());
-                        
moduleProject.getDistributionManagement().getSite().setUrl(module);
-                    }
-                }
-
+            for (MavenProject moduleProject : projectModules) {
                 final String pluginId = 
"org.apache.maven.plugins:maven-site-plugin";
                 String skipFlag = getPluginParameter(moduleProject, pluginId, 
"skip");
                 if (skipFlag == null) {
@@ -602,20 +580,6 @@ public class DefaultSiteTool implements SiteTool {
         }
     }
 
-    private static MavenProject getModuleFromReactor(
-            MavenProject project, List<MavenProject> reactorProjects, String 
module) throws IOException {
-        File moduleBasedir = new File(project.getBasedir(), 
module).getCanonicalFile();
-
-        for (MavenProject reactorProject : reactorProjects) {
-            if (moduleBasedir.equals(reactorProject.getBasedir())) {
-                return reactorProject;
-            }
-        }
-
-        // module not found in reactor
-        return null;
-    }
-
     /** {@inheritDoc} */
     public void populateReportsMenu(
             DecorationModel decorationModel, Locale locale, Map<String, 
List<MavenReport>> categories) {
@@ -786,8 +750,30 @@ public class DefaultSiteTool implements SiteTool {
 
     /**
      * @param project not null
-     * @param localRepository not null
-     * @param repositories not null
+     * @param localeStr not null
+     * @param remoteProjectRepositories not null
+     * @return the site descriptor artifact request
+     */
+    private ArtifactRequest createSiteDescriptorArtifactRequest(
+            MavenProject project, String localeStr, List<RemoteRepository> 
remoteProjectRepositories) {
+        String type = "xml";
+        ArtifactHandler artifactHandler = 
artifactHandlerManager.getArtifactHandler(type);
+        Artifact artifact = new DefaultArtifact(
+                project.getGroupId(),
+                project.getArtifactId(),
+                project.getVersion(),
+                Artifact.SCOPE_RUNTIME,
+                type,
+                "site" + (localeStr.isEmpty() ? "" : "_" + localeStr),
+                artifactHandler);
+        return new ArtifactRequest(
+                RepositoryUtils.toArtifact(artifact), 
remoteProjectRepositories, "remote-site-descriptor");
+    }
+
+    /**
+     * @param project not null
+     * @param repoSession the repository system session not null
+     * @param remoteProjectRepositories not null
      * @param locale not null
      * @return the resolved site descriptor
      * @throws IOException if any
@@ -796,128 +782,93 @@ public class DefaultSiteTool implements SiteTool {
      */
     private File resolveSiteDescriptor(
             MavenProject project,
-            ArtifactRepository localRepository,
-            List<ArtifactRepository> repositories,
+            RepositorySystemSession repoSession,
+            List<RemoteRepository> remoteProjectRepositories,
             Locale locale)
             throws IOException, ArtifactResolutionException, 
ArtifactNotFoundException {
         String variant = locale.getVariant();
         String country = locale.getCountry();
         String language = locale.getLanguage();
 
-        Artifact artifact = null;
+        String localeStr = null;
         File siteDescriptor = null;
         boolean found = false;
 
         if (!variant.isEmpty()) {
-            String localeStr = language + "_" + country + "_" + variant;
-            // TODO: this is a bit crude - proper type, or proper handling as 
metadata rather than an artifact in 2.1?
-            artifact = artifactFactory.createArtifactWithClassifier(
-                    project.getGroupId(), project.getArtifactId(), 
project.getVersion(), "xml", "site_" + localeStr);
+            localeStr = language + "_" + country + "_" + variant;
+            ArtifactRequest request =
+                    createSiteDescriptorArtifactRequest(project, localeStr, 
remoteProjectRepositories);
 
             try {
-                artifactResolver.resolve(artifact, repositories, 
localRepository);
-
-                siteDescriptor = artifact.getFile();
+                ArtifactResult result = 
repositorySystem.resolveArtifact(repoSession, request);
 
-                // we use zero length files to avoid re-resolution (see below)
-                if (siteDescriptor.length() > 0) {
-                    found = true;
-                } else {
+                siteDescriptor = result.getArtifact().getFile();
+                found = true;
+            } catch (ArtifactResolutionException e) {
+                if (e.getCause() instanceof ArtifactNotFoundException) {
                     LOGGER.debug("No site descriptor found for '" + 
project.getId() + "' for locale '" + localeStr
                             + "', trying without variant...");
+                } else {
+                    throw e;
                 }
-            } catch (ArtifactNotFoundException e) {
-                LOGGER.debug("Unable to locate site descriptor for locale '" + 
localeStr + "'", e);
-
-                // we can afford to write an empty descriptor here as we don't 
expect it to turn up later in the
-                // remote repository, because the parent was already released 
(and snapshots are updated
-                // automatically if changed)
-                siteDescriptor = new File(localRepository.getBasedir(), 
localRepository.pathOf(artifact));
-                siteDescriptor.getParentFile().mkdirs();
-                siteDescriptor.createNewFile();
             }
         }
 
         if (!found && !country.isEmpty()) {
-            String localeStr = language + "_" + country;
-            // TODO: this is a bit crude - proper type, or proper handling as 
metadata rather than an artifact in 2.1?
-            artifact = artifactFactory.createArtifactWithClassifier(
-                    project.getGroupId(), project.getArtifactId(), 
project.getVersion(), "xml", "site_" + localeStr);
+            localeStr = language + "_" + country;
+            ArtifactRequest request =
+                    createSiteDescriptorArtifactRequest(project, localeStr, 
remoteProjectRepositories);
 
             try {
-                artifactResolver.resolve(artifact, repositories, 
localRepository);
+                ArtifactResult result = 
repositorySystem.resolveArtifact(repoSession, request);
 
-                siteDescriptor = artifact.getFile();
-
-                // we use zero length files to avoid re-resolution (see below)
-                if (siteDescriptor.length() > 0) {
-                    found = true;
-                } else {
+                siteDescriptor = result.getArtifact().getFile();
+                found = true;
+            } catch (ArtifactResolutionException e) {
+                if (e.getCause() instanceof ArtifactNotFoundException) {
                     LOGGER.debug("No site descriptor found for '" + 
project.getId() + "' for locale '" + localeStr
                             + "', trying without country...");
+                } else {
+                    throw e;
                 }
-            } catch (ArtifactNotFoundException e) {
-                LOGGER.debug("Unable to locate site descriptor for locale '" + 
localeStr + "'", e);
-
-                // we can afford to write an empty descriptor here as we don't 
expect it to turn up later in the
-                // remote repository, because the parent was already released 
(and snapshots are updated
-                // automatically if changed)
-                siteDescriptor = new File(localRepository.getBasedir(), 
localRepository.pathOf(artifact));
-                siteDescriptor.getParentFile().mkdirs();
-                siteDescriptor.createNewFile();
             }
         }
 
         if (!found && !language.isEmpty()) {
-            String localeStr = language;
-            // TODO: this is a bit crude - proper type, or proper handling as 
metadata rather than an artifact in 2.1?
-            artifact = artifactFactory.createArtifactWithClassifier(
-                    project.getGroupId(), project.getArtifactId(), 
project.getVersion(), "xml", "site_" + localeStr);
+            localeStr = language;
+            ArtifactRequest request =
+                    createSiteDescriptorArtifactRequest(project, localeStr, 
remoteProjectRepositories);
 
             try {
-                artifactResolver.resolve(artifact, repositories, 
localRepository);
+                ArtifactResult result = 
repositorySystem.resolveArtifact(repoSession, request);
 
-                siteDescriptor = artifact.getFile();
-
-                // we use zero length files to avoid re-resolution (see below)
-                if (siteDescriptor.length() > 0) {
-                    found = true;
-                } else {
+                siteDescriptor = result.getArtifact().getFile();
+                found = true;
+            } catch (ArtifactResolutionException e) {
+                if (e.getCause() instanceof ArtifactNotFoundException) {
                     LOGGER.debug("No site descriptor found for '" + 
project.getId() + "' for locale '" + localeStr
-                            + "', trying default locale...");
+                            + "', trying without language (default 
locale)...");
+                } else {
+                    throw e;
                 }
-            } catch (ArtifactNotFoundException e) {
-                LOGGER.debug("Unable to locate site descriptor for locale '" + 
localeStr + "'", e);
-
-                // we can afford to write an empty descriptor here as we don't 
expect it to turn up later in the
-                // remote repository, because the parent was already released 
(and snapshots are updated
-                // automatically if changed)
-                siteDescriptor = new File(localRepository.getBasedir(), 
localRepository.pathOf(artifact));
-                siteDescriptor.getParentFile().mkdirs();
-                siteDescriptor.createNewFile();
             }
         }
 
         if (!found) {
-            artifact = artifactFactory.createArtifactWithClassifier(
-                    project.getGroupId(), project.getArtifactId(), 
project.getVersion(), "xml", "site");
+            localeStr = "";
+            ArtifactRequest request =
+                    createSiteDescriptorArtifactRequest(project, localeStr, 
remoteProjectRepositories);
             try {
-                artifactResolver.resolve(artifact, repositories, 
localRepository);
-            } catch (ArtifactNotFoundException e) {
-                // see above regarding this zero length file
-                siteDescriptor = new File(localRepository.getBasedir(), 
localRepository.pathOf(artifact));
-                siteDescriptor.getParentFile().mkdirs();
-                siteDescriptor.createNewFile();
+                ArtifactResult result = 
repositorySystem.resolveArtifact(repoSession, request);
 
-                throw e;
-            }
-
-            siteDescriptor = artifact.getFile();
+                siteDescriptor = result.getArtifact().getFile();
+            } catch (ArtifactResolutionException e) {
+                if (e.getCause() instanceof ArtifactNotFoundException) {
+                    LOGGER.debug("No site descriptor found for '" + 
project.getId() + "' with default locale.");
+                    throw (ArtifactNotFoundException) e.getCause();
+                }
 
-            // we use zero length files to avoid re-resolution (see below)
-            if (siteDescriptor.length() == 0) {
-                LOGGER.debug("No site descriptor found for '" + 
project.getId() + "' with default locale.");
-                siteDescriptor = null;
+                throw e;
             }
         }
 
@@ -929,9 +880,8 @@ public class DefaultSiteTool implements SiteTool {
      * @param siteDirectory, can be null if project.basedir is null, ie POM 
from repository
      * @param locale not null
      * @param project not null
-     * @param reactorProjects not null
-     * @param localRepository not null
-     * @param repositories not null
+     * @param repoSession not null
+     * @param remoteProjectRepositories not null
      * @return the decoration model depending the locale and the parent project
      * @throws SiteToolException if any
      */
@@ -940,16 +890,16 @@ public class DefaultSiteTool implements SiteTool {
             File siteDirectory,
             Locale locale,
             MavenProject project,
-            List<MavenProject> reactorProjects,
-            ArtifactRepository localRepository,
-            List<ArtifactRepository> repositories)
+            RepositorySystemSession repoSession,
+            List<RemoteRepository> remoteProjectRepositories)
             throws SiteToolException {
         // 1. get site descriptor File
         File siteDescriptor;
         if (project.getBasedir() == null) {
             // POM is in the repository: look into the repository for site 
descriptor
             try {
-                siteDescriptor = getSiteDescriptorFromRepository(project, 
localRepository, repositories, locale);
+                siteDescriptor =
+                        getSiteDescriptorFromRepository(project, repoSession, 
remoteProjectRepositories, locale);
             } catch (SiteToolException e) {
                 throw new SiteToolException("The site descriptor cannot be 
resolved from the repository", e);
             }
@@ -1006,13 +956,7 @@ public class DefaultSiteTool implements SiteTool {
             }
 
             DecorationModel parentDecorationModel = getDecorationModel(
-                            depth,
-                            parentSiteDirectory,
-                            locale,
-                            parentProject,
-                            reactorProjects,
-                            localRepository,
-                            repositories)
+                            depth, parentSiteDirectory, locale, parentProject, 
repoSession, remoteProjectRepositories)
                     .getKey();
 
             // MSHARED-116 requires an empty decoration model (instead of a 
null one)
diff --git 
a/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
 
b/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
index 5478915..8c915a1 100644
--- 
a/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
+++ 
b/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
@@ -24,10 +24,12 @@ import java.util.Locale;
 import java.util.Map;
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.doxia.site.decoration.DecorationModel;
+import org.apache.maven.doxia.site.decoration.Skin;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.reporting.MavenReport;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.repository.RemoteRepository;
 
 /**
  * Tool to play with <a href="http://maven.apache.org/doxia/";>Doxia</a> objects
@@ -46,17 +48,14 @@ public interface SiteTool {
     /**
      * Get a skin artifact from one of the repositories.
      *
-     * @param localRepository the Maven local repository, not null.
-     * @param remoteArtifactRepositories the Maven remote repositories, not 
null.
-     * @param decoration the Doxia site descriptor model, not null.
-     * @return the <code>Skin</code> artifact defined in a 
<code>DecorationModel</code> from a given project and a
-     * local repository
+     * @param repoSession the repository system session, not null.
+     * @param remoteProjectRepositories the Maven remote project repositories, 
not null.
+     * @param skin the Skin model, not null.
+     * @return the <code>Skin</code> artifact defined in a 
<code>DecorationModel</code> from a given project
      * @throws SiteToolException if any
      */
     Artifact getSkinArtifactFromRepository(
-            ArtifactRepository localRepository,
-            List<ArtifactRepository> remoteArtifactRepositories,
-            DecorationModel decoration)
+            RepositorySystemSession repoSession, List<RemoteRepository> 
remoteProjectRepositories, Skin skin)
             throws SiteToolException;
 
     /**
@@ -114,9 +113,9 @@ public interface SiteTool {
      * @param locale the locale used for the i18n in DecorationModel, not null.
      * See {@link #getSiteDescriptor(File, Locale)} for details.
      * @param project the Maven project, not null.
-     * @param reactorProjects the Maven reactor projects, not null.
-     * @param localRepository the Maven local repository, not null.
-     * @param repositories the Maven remote repositories, not null.
+     * @param projectModules the project modules, not null.
+     * @param repoSession the repository system session, not null.
+     * @param remoteProjectRepositories the Maven remote project repositories, 
not null.
      * @return the <code>DecorationModel</code> object corresponding to the 
<code>site.xml</code> file with some
      * interpolations.
      * @throws SiteToolException if any
@@ -126,9 +125,9 @@ public interface SiteTool {
             File siteDirectory,
             Locale locale,
             MavenProject project,
-            List<MavenProject> reactorProjects,
-            ArtifactRepository localRepository,
-            List<ArtifactRepository> repositories)
+            List<MavenProject> projectModules,
+            RepositorySystemSession repoSession,
+            List<RemoteRepository> remoteProjectRepositories)
             throws SiteToolException;
 
     /**
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 34ce2e4..9f74575 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
@@ -23,12 +23,10 @@ import javax.inject.Named;
 
 import java.io.File;
 import java.io.Writer;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Locale;
 
 import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -40,12 +38,16 @@ import org.apache.maven.doxia.site.decoration.LinkItem;
 import org.apache.maven.doxia.site.decoration.Skin;
 import org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Writer;
 import org.apache.maven.doxia.tools.stubs.SiteToolMavenProjectStub;
-import org.apache.maven.project.MavenProject;
+import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
 import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.testing.PlexusTest;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.WriterFactory;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
+import org.eclipse.aether.repository.LocalRepository;
 import org.junit.jupiter.api.Test;
 
 import static org.codehaus.plexus.testing.PlexusExtension.getTestFile;
@@ -105,6 +107,13 @@ public class SiteToolTest {
         return new File(getLocalRepo().getBasedir());
     }
 
+    protected RepositorySystemSession newRepoSession() throws Exception {
+        DefaultRepositorySystemSession repoSession = 
MavenRepositorySystemUtils.newSession();
+        repoSession.setLocalRepositoryManager(new 
SimpleLocalRepositoryManagerFactory()
+                .newInstance(repoSession, new 
LocalRepository(getLocalRepoDir())));
+        return repoSession;
+    }
+
     /**
      * @throws Exception
      */
@@ -113,13 +122,11 @@ public class SiteToolTest {
         assertNotNull(tool);
 
         SiteToolMavenProjectStub project = new 
SiteToolMavenProjectStub("site-tool-test");
-        DecorationModel decorationModel = new DecorationModel();
         Skin skin = new Skin();
         skin.setGroupId("org.apache.maven.skins");
         skin.setArtifactId("maven-stylus-skin");
-        decorationModel.setSkin(skin);
-        assertNotNull(tool.getSkinArtifactFromRepository(
-                getLocalRepo(), project.getRemoteArtifactRepositories(), 
decorationModel));
+        assertNotNull(
+                tool.getSkinArtifactFromRepository(newRepoSession(), 
project.getRemoteProjectRepositories(), skin));
     }
 
     private void checkGetRelativePathDirectory(SiteTool tool, String relative, 
String to, String from) {
@@ -330,8 +337,8 @@ public class SiteToolTest {
         assertEquals(
                 tool.getSiteDescriptorFromRepository(
                                 project,
-                                getLocalRepo(),
-                                project.getRemoteArtifactRepositories(),
+                                newRepoSession(),
+                                project.getRemoteProjectRepositories(),
                                 SiteTool.DEFAULT_LOCALE)
                         .toString(),
                 result);
@@ -345,16 +352,15 @@ public class SiteToolTest {
         assertNotNull(tool);
 
         SiteToolMavenProjectStub project = new 
SiteToolMavenProjectStub("site-tool-test");
-        List<MavenProject> reactorProjects = new ArrayList<MavenProject>();
 
         // model from current local build
         DecorationModel model = tool.getDecorationModel(
                 new File(project.getBasedir(), "src/site"),
                 SiteTool.DEFAULT_LOCALE,
                 project,
-                reactorProjects,
-                getLocalRepo(),
-                project.getRemoteArtifactRepositories());
+                Collections.emptyList(),
+                newRepoSession(),
+                project.getRemoteProjectRepositories());
         assertNotNull(model);
         assertNotNull(model.getBannerLeft());
         assertEquals("Maven Site", model.getBannerLeft().getName());
@@ -378,9 +384,9 @@ public class SiteToolTest {
                 null,
                 SiteTool.DEFAULT_LOCALE,
                 project,
-                reactorProjects,
-                getLocalRepo(),
-                project.getRemoteArtifactRepositories());
+                Collections.emptyList(),
+                newRepoSession(),
+                project.getRemoteProjectRepositories());
         assertNotNull(modelFromRepo);
         assertNotNull(modelFromRepo.getBannerLeft());
         assertEquals("dummy", modelFromRepo.getBannerLeft().getName());
@@ -400,15 +406,14 @@ public class SiteToolTest {
 
         SiteToolMavenProjectStub project = new 
SiteToolMavenProjectStub("no-site-test");
         String siteDirectory = "src/site";
-        List<MavenProject> reactorProjects = new ArrayList<MavenProject>();
 
         DecorationModel model = tool.getDecorationModel(
                 new File(project.getBasedir(), siteDirectory),
                 SiteTool.DEFAULT_LOCALE,
                 project,
-                reactorProjects,
-                getLocalRepo(),
-                project.getRemoteArtifactRepositories());
+                Collections.emptyList(),
+                newRepoSession(),
+                project.getRemoteProjectRepositories());
         assertNotNull(model);
     }
 
@@ -462,15 +467,13 @@ public class SiteToolTest {
         childProject.setParent(parentProject);
         
childProject.setDistgributionManagementSiteUrl("dav+https://davs.codehaus.org/site/child";);
 
-        List<MavenProject> reactorProjects = 
Collections.<MavenProject>singletonList(parentProject);
-
         DecorationModel model = tool.getDecorationModel(
                 new File(childProject.getBasedir(), "src/site"),
                 SiteTool.DEFAULT_LOCALE,
                 childProject,
-                reactorProjects,
-                getLocalRepo(),
-                childProject.getRemoteArtifactRepositories());
+                Collections.emptyList(),
+                newRepoSession(),
+                childProject.getRemoteProjectRepositories());
         assertNotNull(model);
 
         writeModel(model, "unit/interpolation-child-test/effective-site.xml");
diff --git 
a/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/stubs/SiteToolMavenProjectStub.java
 
b/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/stubs/SiteToolMavenProjectStub.java
index b426d4f..eecf089 100644
--- 
a/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/stubs/SiteToolMavenProjectStub.java
+++ 
b/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/stubs/SiteToolMavenProjectStub.java
@@ -25,6 +25,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
 
+import org.apache.maven.RepositoryUtils;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.DefaultArtifactRepository;
 import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
@@ -33,6 +34,7 @@ import org.apache.maven.model.DistributionManagement;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Site;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.eclipse.aether.repository.RemoteRepository;
 
 /**
  * @author <a href="mailto:vincent.sive...@gmail.com";>Vincent Siveton</a>
@@ -111,6 +113,11 @@ public class SiteToolMavenProjectStub extends 
MavenProjectStub {
         return Collections.singletonList(repository);
     }
 
+    /** {@inheritDoc} */
+    public List<RemoteRepository> getRemoteProjectRepositories() {
+        return RepositoryUtils.toRepos(getRemoteArtifactRepositories());
+    }
+
     /** {@inheritDoc} */
     public Properties getProperties() {
         return properties;


Reply via email to