Skip to content

Commit

Permalink
[MPLUGIN-511] prepare method to list releases history
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas authored and hboutemy committed Mar 16, 2024
1 parent bf0587c commit d9f8d89
Showing 1 changed file with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
import java.util.List;
import java.util.Locale;

import org.apache.maven.RepositoryUtils;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
Expand All @@ -36,12 +39,24 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.plugin.descriptor.EnhancedPluginDescriptorBuilder;
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.AbstractMavenReport;
import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.codehaus.plexus.configuration.PlexusConfigurationException;
import org.codehaus.plexus.i18n.I18N;
import org.codehaus.plexus.util.xml.XmlStreamReader;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.resolution.VersionRangeRequest;
import org.eclipse.aether.resolution.VersionRangeResolutionException;
import org.eclipse.aether.resolution.VersionRangeResult;
import org.eclipse.aether.version.Version;

/**
* Generates the Plugin's documentation report: <code>plugin-info.html</code> plugin overview page,
Expand Down Expand Up @@ -123,6 +138,15 @@ public class PluginReport extends AbstractMavenReport {
@Parameter(property = "maven.plugin.report.disableInternalJavadocLinkValidation")
private boolean disableInternalJavadocLinkValidation;

@Component
private MavenSession mavenSession;

@Component
private RepositorySystem repositorySystem;

@Component
private ProjectBuilder projectBuilder;

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -232,4 +256,33 @@ private void generateMojosDocumentation(PluginDescriptor pluginDescriptor, Local
}
}
}

private List<Version> discoverVersions() throws VersionRangeResolutionException {
MavenProject currentProject = mavenSession.getCurrentProject();
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact(
new DefaultArtifact(currentProject.getGroupId() + ":" + currentProject.getArtifactId() + ":[0,)"));
rangeRequest.setRepositories(
RepositoryUtils.toRepos(mavenSession.getCurrentProject().getRemoteArtifactRepositories()));
VersionRangeResult rangeResult =
repositorySystem.resolveVersionRange(mavenSession.getRepositorySession(), rangeRequest);
return rangeResult.getVersions();
}

private ProjectBuildingResult buildMavenProject(String version) throws ProjectBuildingException {
MavenProject currentProject = mavenSession.getCurrentProject();
ProjectBuildingRequest buildRequest = new DefaultProjectBuildingRequest();
buildRequest.setLocalRepository(mavenSession.getLocalRepository());
buildRequest.setRemoteRepositories(mavenSession.getCurrentProject().getRemoteArtifactRepositories());
buildRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
buildRequest.setProcessPlugins(false);
buildRequest.setRepositoryMerging(ProjectBuildingRequest.RepositoryMerging.REQUEST_DOMINANT);
buildRequest.setSystemProperties(mavenSession.getSystemProperties());
buildRequest.setUserProperties(mavenSession.getUserProperties());
buildRequest.setRepositorySession(mavenSession.getRepositorySession());
return projectBuilder.build(
RepositoryUtils.toArtifact(new DefaultArtifact(
currentProject.getGroupId() + ":" + currentProject.getArtifactId() + ":pom:" + version)),
buildRequest);
}
}

0 comments on commit d9f8d89

Please sign in to comment.