Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
Expand Down Expand Up @@ -125,11 +126,25 @@ private static Set<MavenPlugin> getAllPlugins(
DependencyCollectorBuilder dependencyCollectorBuilder,
AbstractChecksumCalculator checksumCalculator) {
Set<MavenPlugin> plugins = new TreeSet<>(Comparator.comparing(MavenPlugin::getChecksum));
Map<String, Plugin> pluginConfigMap = new HashMap<>();
if (project.getBuild() != null && project.getBuild().getPlugins() != null) {
pluginConfigMap = project.getBuild().getPlugins().stream()
.collect(Collectors.toMap(p -> p.getGroupId() + ":" + p.getArtifactId(), p -> p));
}

for (Artifact pluginArtifact : project.getPluginArtifacts()) {
String key = pluginArtifact.getGroupId() + ":" + pluginArtifact.getArtifactId();
Plugin pluginConfig = pluginConfigMap.get(key);

RepositoryInformation repositoryInformation = checksumCalculator.getPluginResolvedField(pluginArtifact);
Set<io.github.chains_project.maven_lockfile.graph.DependencyNode> pluginDependencies =
resolvePluginDependencies(
pluginArtifact, session, project, dependencyCollectorBuilder, checksumCalculator);
pluginArtifact,
pluginConfig,
session,
project,
dependencyCollectorBuilder,
checksumCalculator);
plugins.add(new MavenPlugin(
GroupId.of(pluginArtifact.getGroupId()),
ArtifactId.of(pluginArtifact.getArtifactId()),
Expand All @@ -147,6 +162,7 @@ private static Set<MavenPlugin> getAllPlugins(
* Resolve the dependencies of a Maven plugin.
*
* @param pluginArtifact The plugin artifact to resolve dependencies for
* @param pluginConfig The plugin configuration from the project POM (may be null)
* @param session The Maven session
* @param project The current Maven project (for repository configuration)
* @param dependencyCollectorBuilder The dependency collector builder
Expand All @@ -155,6 +171,7 @@ private static Set<MavenPlugin> getAllPlugins(
*/
private static Set<io.github.chains_project.maven_lockfile.graph.DependencyNode> resolvePluginDependencies(
Artifact pluginArtifact,
Plugin pluginConfig,
MavenSession session,
MavenProject project,
DependencyCollectorBuilder dependencyCollectorBuilder,
Expand Down Expand Up @@ -267,6 +284,13 @@ private static Set<io.github.chains_project.maven_lockfile.graph.DependencyNode>
return Collections.emptySet();
}

// Use plugin dependencies from project POM if declared
if (pluginConfig != null
&& pluginConfig.getDependencies() != null
&& !pluginConfig.getDependencies().isEmpty()) {
pluginProject.setDependencies(pluginConfig.getDependencies());
}

int declaredDeps = pluginProject.getDependencies() != null
? pluginProject.getDependencies().size()
: 0;
Expand Down Expand Up @@ -302,6 +326,8 @@ private static Set<io.github.chains_project.maven_lockfile.graph.DependencyNode>

// Get root dependency nodes (excluding the plugin project itself)
Set<io.github.chains_project.maven_lockfile.graph.DependencyNode> roots = dependencyGraph.getRoots();
roots = filterPluginDependencyScopes(roots);

PluginLogManager.getLog()
.info(String.format("Resolved %4d dependencies for plugin %s", roots.size(), pluginArtifact));
return roots;
Expand All @@ -313,6 +339,20 @@ private static Set<io.github.chains_project.maven_lockfile.graph.DependencyNode>
}
}

/**
* Filters plugin dependencies to only include valid scopes (compile, runtime, system).
*/
private static Set<io.github.chains_project.maven_lockfile.graph.DependencyNode> filterPluginDependencyScopes(
Set<io.github.chains_project.maven_lockfile.graph.DependencyNode> dependencies) {
return dependencies.stream()
.filter(dep -> {
String scope = dep.getScope().getValue();
return scope.equals("compile") || scope.equals("runtime") || scope.equals("system");
})
.collect(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(
io.github.chains_project.maven_lockfile.graph.DependencyNode::getComparatorString))));
}

private static DependencyGraph graph(
MavenSession session,
MavenProject project,
Expand Down
Loading