Skip to content

Commit

Permalink
Convert to Guice constructor injection
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo committed Dec 13, 2024
1 parent 1694db8 commit 5a95764
Show file tree
Hide file tree
Showing 17 changed files with 274 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
Expand All @@ -61,31 +60,6 @@
* @since 2.0
*/
public abstract class AbstractProjectInfoReport extends AbstractMavenReport {
// ----------------------------------------------------------------------
// Mojo components
// ----------------------------------------------------------------------

/**
* Artifact Resolver component.
*/
@Component
protected ArtifactResolver resolver;

/**
* Artifact Factory component.
*/
@Component
RepositorySystem repositorySystem;

/**
* Internationalization component, could support also custom bundle using {@link #customBundle}.
*/
@Component
private I18N i18n;

@Component
protected ProjectBuilder projectBuilder;

// ----------------------------------------------------------------------
// Mojo parameters
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -152,6 +126,35 @@ public abstract class AbstractProjectInfoReport extends AbstractMavenReport {
@Parameter(defaultValue = "${localRepository}", readonly = true, required = true)
protected ArtifactRepository localRepository;

// ----------------------------------------------------------------------
// Mojo components
// ----------------------------------------------------------------------

/**
* Artifact Resolver component.
*/
protected final ArtifactResolver resolver;

/**
* Artifact Factory component.
*/
final RepositorySystem repositorySystem;

/**
* Internationalization component, could support also custom bundle using {@link #customBundle}.
*/
private I18N i18n;

protected final ProjectBuilder projectBuilder;

protected AbstractProjectInfoReport(
ArtifactResolver resolver, RepositorySystem repositorySystem, I18N i18n, ProjectBuilder projectBuilder) {
this.resolver = resolver;
this.repositorySystem = repositorySystem;
this.i18n = i18n;
this.projectBuilder = projectBuilder;
}

// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -209,7 +212,7 @@ protected MojoExecution getMojoExecution() {

/**
* @param pluginId The id of the plugin
* @return The information about the plugin.
* @return The information about the plugin
*/
protected Plugin getPlugin(String pluginId) {
if ((getProject().getBuild() == null) || (getProject().getBuild().getPluginsAsMap() == null)) {
Expand All @@ -232,9 +235,9 @@ protected Plugin getPlugin(String pluginId) {
}

/**
* @param pluginId The pluginId
* @param param The child which should be checked.
* @return The value of the dom tree.
* @param pluginId the pluginId
* @param param the child which should be checked
* @return the value of the dom tree
*/
protected String getPluginParameter(String pluginId, String param) {
Plugin plugin = getPlugin(pluginId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.report.projectinfo;

import javax.inject.Inject;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
Expand All @@ -29,7 +31,10 @@
import org.apache.maven.model.Model;
import org.apache.maven.model.Notifier;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver;
import org.codehaus.plexus.i18n.I18N;

/**
Expand All @@ -40,6 +45,12 @@
*/
@Mojo(name = "ci-management")
public class CiManagementReport extends AbstractProjectInfoReport {

@Inject
public CiManagementReport(
ArtifactResolver resolver, RepositorySystem repositorySystem, I18N i18n, ProjectBuilder projectBuilder) {
super(resolver, repositorySystem, i18n, projectBuilder);
}
// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*/
package org.apache.maven.report.projectinfo;

import javax.inject.Inject;
import javax.inject.Named;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
Expand All @@ -32,21 +35,24 @@
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.report.projectinfo.dependencies.Dependencies;
import org.apache.maven.report.projectinfo.dependencies.DependenciesReportConfiguration;
import org.apache.maven.report.projectinfo.dependencies.RepositoryUtils;
import org.apache.maven.report.projectinfo.dependencies.renderer.DependenciesRenderer;
import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
import org.apache.maven.shared.dependency.graph.DependencyNode;
import org.apache.maven.shared.jar.classes.JarClassesAnalysis;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver;
import org.codehaus.plexus.i18n.I18N;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;

Expand All @@ -64,6 +70,19 @@ public class DependenciesReport extends AbstractProjectInfoReport {
*/
private static final String RESOURCES_DIR = "org/apache/maven/report/projectinfo/resources";

// ----------------------------------------------------------------------
// Mojo parameters
// ----------------------------------------------------------------------

/**
* Display file details for each dependency, such as: file size, number of
* classes, number of packages etc.
*
* @since 2.1
*/
@Parameter(property = "dependency.details.enabled", defaultValue = "true")
private boolean dependencyDetailsEnabled;

// ----------------------------------------------------------------------
// Mojo components
// ----------------------------------------------------------------------
Expand All @@ -73,37 +92,36 @@ public class DependenciesReport extends AbstractProjectInfoReport {
*
* @since 2.5
*/
@Component(hint = "default")
private DependencyGraphBuilder dependencyGraphBuilder;
private final DependencyGraphBuilder dependencyGraphBuilder;

/**
* Jar classes analyzer component.
*
* @since 2.1
*/
@Component
private JarClassesAnalysis classesAnalyzer;
private final JarClassesAnalysis classesAnalyzer;

/**
* Repository metadata component.
*
* @since 2.1
*/
@Component
private RepositoryMetadataManager repositoryMetadataManager;
private final RepositoryMetadataManager repositoryMetadataManager;

// ----------------------------------------------------------------------
// Mojo parameters
// ----------------------------------------------------------------------

/**
* Display file details for each dependency, such as: file size, number of
* classes, number of packages etc.
*
* @since 2.1
*/
@Parameter(property = "dependency.details.enabled", defaultValue = "true")
private boolean dependencyDetailsEnabled;
@Inject
protected DependenciesReport(
ArtifactResolver resolver,
RepositorySystem repositorySystem,
I18N i18n,
ProjectBuilder projectBuilder,
@Named("default") DependencyGraphBuilder dependencyGraphBuilder,
JarClassesAnalysis classesAnalyzer,
RepositoryMetadataManager repositoryMetadataManager) {
super(resolver, repositorySystem, i18n, projectBuilder);
this.dependencyGraphBuilder = dependencyGraphBuilder;
this.classesAnalyzer = classesAnalyzer;
this.repositoryMetadataManager = repositoryMetadataManager;
}

// ----------------------------------------------------------------------
// Public methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.maven.report.projectinfo;

import javax.inject.Inject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -37,14 +39,15 @@
import org.apache.maven.doxia.sink.SinkEventAttributes;
import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.report.projectinfo.dependencies.DependencyVersionMap;
import org.apache.maven.report.projectinfo.dependencies.SinkSerializingDependencyNodeVisitor;
import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter;
import org.apache.maven.shared.dependency.graph.DependencyCollectorBuilder;
import org.apache.maven.shared.dependency.graph.DependencyCollectorBuilderException;
Expand All @@ -57,6 +60,8 @@
import org.apache.maven.shared.dependency.graph.traversal.CollectingDependencyNodeVisitor;
import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor;
import org.apache.maven.shared.dependency.graph.traversal.FilteringDependencyNodeVisitor;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver;
import org.codehaus.plexus.i18n.I18N;

/**
* Generates the Project Dependency Convergence report for (reactor) builds.
Expand All @@ -80,19 +85,29 @@ public class DependencyConvergenceReport extends AbstractProjectInfoReport {

private static final int FULL_CONVERGENCE = 100;

private ArtifactFilter filter = null;

private Map<MavenProject, DependencyNode> projectMap = new HashMap<>();

// ----------------------------------------------------------------------
// Mojo parameters
// ----------------------------------------------------------------------

/**
* Raw dependency collector builder, will use it to build dependency tree.
*/
@Component
private DependencyCollectorBuilder dependencyCollectorBuilder;

private ArtifactFilter filter = null;

private Map<MavenProject, DependencyNode> projectMap = new HashMap<>();
private final DependencyCollectorBuilder dependencyCollectorBuilder;

@Inject
protected DependencyConvergenceReport(
ArtifactResolver resolver,
RepositorySystem repositorySystem,
I18N i18n,
ProjectBuilder projectBuilder,
DependencyCollectorBuilder dependencyCollectorBuilder) {
super(resolver, repositorySystem, i18n, projectBuilder);
this.dependencyCollectorBuilder = dependencyCollectorBuilder;
}

// ----------------------------------------------------------------------
// Public methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@
*/
package org.apache.maven.report.projectinfo;

import javax.inject.Inject;

import java.util.Formatter;
import java.util.Locale;

import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver;
import org.codehaus.plexus.i18n.I18N;

/**
Expand All @@ -39,26 +44,24 @@ public final class DependencyInformationReport extends AbstractProjectInfoReport
private static final String JAR_PACKAGING = "jar";
private static final String PLUGIN_PACKAGING = "maven-plugin";

/**
*/
@Parameter(defaultValue = "${project.groupId}", required = true)
protected String groupId;

/**
*/
@Parameter(defaultValue = "${project.artifactId}", required = true)
protected String artifactId;

/**
*/
@Parameter(defaultValue = "${project.version}", required = true)
protected String version;

/**
*/
@Parameter(defaultValue = "${project.packaging}", required = true)
protected String packaging;

@Inject
public DependencyInformationReport(
ArtifactResolver resolver, RepositorySystem repositorySystem, I18N i18n, ProjectBuilder projectBuilder) {
super(resolver, repositorySystem, i18n, projectBuilder);
}

// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 5a95764

Please sign in to comment.