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 0ac0242531422b0c47418ac2a678d69eab7f2b00 Author: Michael Osipov <micha...@apache.org> AuthorDate: Sun Mar 12 22:42:29 2023 +0100 Use Maven Resolver --- .../apache/maven/doxia/tools/DefaultSiteTool.java | 330 +++++++++------------ .../org/apache/maven/doxia/tools/SiteTool.java | 23 +- .../org/apache/maven/doxia/tools/SiteToolTest.java | 43 ++- pom.xml | 2 +- 4 files changed, 168 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 7b95cb8..4bf1808 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,12 @@ 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.DefaultArtifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; 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.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.doxia.site.decoration.DecorationModel; @@ -57,13 +57,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 +72,12 @@ 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.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,46 @@ public class DefaultSiteTool implements SiteTool { // Public methods // ---------------------------------------------------------------------- + /** {@inheritDoc} */ public Artifact getSkinArtifactFromRepository( - ArtifactRepository localRepository, - List<ArtifactRepository> remoteArtifactRepositories, - DecorationModel decoration) + RepositorySystemSession repoSession, List<ArtifactRepository> remoteArtifactRepositories, Skin skin) throws SiteToolException { - Objects.requireNonNull(localRepository, "localRepository cannot be null"); + Objects.requireNonNull(repoSession, "repoSession 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(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), + RepositoryUtils.toRepos(remoteArtifactRepositories), + "remote-skin"); + ArtifactResult result = repositorySystem.resolveArtifact(repoSession, request); + + // TODO Can "result.isMissing()" happen here? + 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 +336,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 remoteArtifactRepositories the Maven remote 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 +346,17 @@ public class DefaultSiteTool implements SiteTool { */ File getSiteDescriptorFromRepository( MavenProject project, - ArtifactRepository localRepository, - List<ArtifactRepository> repositories, + RepositorySystemSession repoSession, + List<ArtifactRepository> remoteArtifactRepositories, 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(remoteArtifactRepositories, "remoteArtifactRepositories cannot be null"); Objects.requireNonNull(locale, "locale cannot be null"); try { - return resolveSiteDescriptor(project, localRepository, repositories, locale); + return resolveSiteDescriptor(project, repoSession, remoteArtifactRepositories, locale); } catch (ArtifactNotFoundException e) { LOGGER.debug("Unable to locate site descriptor", e); return null; @@ -361,21 +372,19 @@ public class DefaultSiteTool implements SiteTool { File siteDirectory, Locale locale, MavenProject project, - List<MavenProject> reactorProjects, - ArtifactRepository localRepository, - List<ArtifactRepository> repositories) + RepositorySystemSession repoSession, + List<ArtifactRepository> remoteArtifactRepositories) 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(repoSession, "repoSession cannot be null"); + Objects.requireNonNull(remoteArtifactRepositories, "remoteArtifactRepositories 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, remoteArtifactRepositories); DecorationModel decorationModel = result.getKey(); MavenProject parentProject = result.getValue(); @@ -397,7 +406,7 @@ public class DefaultSiteTool implements SiteTool { } try { - populateModulesMenu(decorationModel, locale, project, reactorProjects, localRepository, true); + populateModulesMenu(decorationModel, locale, project, true); } catch (IOException e) { throw new SiteToolException("Error while populating modules menu", e); } @@ -529,25 +538,16 @@ 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 keepInheritedRefs used for inherited references. * @throws SiteToolException if any * @throws IOException */ private void populateModulesMenu( - DecorationModel decorationModel, - Locale locale, - MavenProject project, - List<MavenProject> reactorProjects, - ArtifactRepository localRepository, - boolean keepInheritedRefs) + DecorationModel decorationModel, Locale locale, MavenProject project, 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"); Menu menu = decorationModel.getMenuRef("modules"); @@ -560,39 +560,13 @@ public class DefaultSiteTool implements SiteTool { } // we require child modules and reactors to process module menu - if (project.getModules().size() > 0) { + List<MavenProject> projectModules = project.getCollectedProjects(); + if (projectModules != null && !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) { @@ -612,20 +586,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) { @@ -796,8 +756,32 @@ public class DefaultSiteTool implements SiteTool { /** * @param project not null - * @param localRepository not null - * @param repositories not null + * @param localeStr could be null + * @param remoteArtifactRepositories not null + * @return the site descriptor artifact request + */ + private ArtifactRequest createSiteDescriptorArtifactRequest( + MavenProject project, String localeStr, List<ArtifactRepository> remoteArtifactRepositories) { + String type = "xml"; + ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(type); + Artifact artifact = new DefaultArtifact( + project.getGroupId(), + project.getArtifactId(), + project.getVersion(), + Artifact.SCOPE_RUNTIME, + type, + (localeStr == null || localeStr.isEmpty()) ? "site" : "site_" + localeStr, + artifactHandler); + return new ArtifactRequest( + RepositoryUtils.toArtifact(artifact), + RepositoryUtils.toRepos(remoteArtifactRepositories), + "remote-site-descriptor"); + } + + /** + * @param project not null + * @param repoSession the repository system session not null + * @param remoteArtifactRepositories not null * @param locale not null * @return the resolved site descriptor * @throws IOException if any @@ -806,129 +790,98 @@ public class DefaultSiteTool implements SiteTool { */ private File resolveSiteDescriptor( MavenProject project, - ArtifactRepository localRepository, - List<ArtifactRepository> repositories, + RepositorySystemSession repoSession, + List<ArtifactRepository> remoteArtifactRepositories, 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, remoteArtifactRepositories); 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 { + // TODO Can "result.isMissing()" happen here? + 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, remoteArtifactRepositories); 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 { + // TODO Can "result.isMissing()" happen here? + 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, remoteArtifactRepositories); 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 { + // TODO Can "result.isMissing()" happen here? + 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, remoteArtifactRepositories); 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); + + // TODO Can "result.isMissing()" happen here? + 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(); + } throw e; } - - siteDescriptor = artifact.getFile(); - - // 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; - } } return siteDescriptor; @@ -939,9 +892,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 remoteArtifactRepositories not null * @return the decoration model depending the locale and the parent project * @throws SiteToolException if any */ @@ -950,16 +902,16 @@ public class DefaultSiteTool implements SiteTool { File siteDirectory, Locale locale, MavenProject project, - List<MavenProject> reactorProjects, - ArtifactRepository localRepository, - List<ArtifactRepository> repositories) + RepositorySystemSession repoSession, + List<ArtifactRepository> remoteArtifactRepositories) 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, remoteArtifactRepositories, locale); } catch (SiteToolException e) { throw new SiteToolException("The site descriptor cannot be resolved from the repository", e); } @@ -1016,13 +968,7 @@ public class DefaultSiteTool implements SiteTool { } DecorationModel parentDecorationModel = getDecorationModel( - depth, - parentSiteDirectory, - locale, - parentProject, - reactorProjects, - localRepository, - repositories) + depth, parentSiteDirectory, locale, parentProject, repoSession, remoteArtifactRepositories) .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 c31d30e..632e8c1 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 @@ -26,8 +26,10 @@ 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; /** * 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 repoSession the repository system session, 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 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<ArtifactRepository> remoteArtifactRepositories, Skin skin) throws SiteToolException; /** @@ -114,9 +113,8 @@ 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 repoSession the repository system session, not null. + * @param remoteArtifactRepositories the Maven remote 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 +124,8 @@ public interface SiteTool { File siteDirectory, Locale locale, MavenProject project, - List<MavenProject> reactorProjects, - ArtifactRepository localRepository, - List<ArtifactRepository> repositories) + RepositorySystemSession repoSession, + List<ArtifactRepository> remoteArtifactRepositories) 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..22c50ff 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.getRemoteArtifactRepositories(), skin)); } private void checkGetRelativePathDirectory(SiteTool tool, String relative, String to, String from) { @@ -330,7 +337,7 @@ public class SiteToolTest { assertEquals( tool.getSiteDescriptorFromRepository( project, - getLocalRepo(), + newRepoSession(), project.getRemoteArtifactRepositories(), SiteTool.DEFAULT_LOCALE) .toString(), @@ -345,15 +352,13 @@ 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(), + newRepoSession(), project.getRemoteArtifactRepositories()); assertNotNull(model); assertNotNull(model.getBannerLeft()); @@ -375,12 +380,7 @@ public class SiteToolTest { project.setArtifactId("maven"); project.setVersion("3.8.6"); DecorationModel modelFromRepo = tool.getDecorationModel( - null, - SiteTool.DEFAULT_LOCALE, - project, - reactorProjects, - getLocalRepo(), - project.getRemoteArtifactRepositories()); + null, SiteTool.DEFAULT_LOCALE, project, newRepoSession(), project.getRemoteArtifactRepositories()); assertNotNull(modelFromRepo); assertNotNull(modelFromRepo.getBannerLeft()); assertEquals("dummy", modelFromRepo.getBannerLeft().getName()); @@ -400,14 +400,12 @@ 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(), + newRepoSession(), project.getRemoteArtifactRepositories()); assertNotNull(model); } @@ -462,14 +460,11 @@ 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(), + newRepoSession(), childProject.getRemoteArtifactRepositories()); assertNotNull(model); diff --git a/pom.xml b/pom.xml index 4feb04c..d2de753 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ under the License. <properties> <javaVersion>8</javaVersion> - <doxiaVersion>2.0.0-M5</doxiaVersion> + <doxiaVersion>2.0.0-M6-SNAPSHOT</doxiaVersion> <slf4jVersion>1.7.36</slf4jVersion> <mavenVersion>3.2.5</mavenVersion> <aetherVersion>1.0.0.v20140518</aetherVersion>