Skip to content

Commit

Permalink
Dirty tree Mojo (#171)
Browse files Browse the repository at this point in the history
Ditry tree mojo. And a fix, dirty tree likely has cycles, ignore them to avoid SO
  • Loading branch information
cstamas authored Feb 15, 2025
1 parent e038fc3 commit 3d9f281
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -852,11 +852,11 @@ public boolean accept(DependencyNode node, List<DependencyNode> parents) {
}));

DependencyNode clone = cloningDependencyVisitor.getRootNode();
clone.accept(new DependencyGraphDumper(
clone.accept(new TreeDependencyVisitor(new DependencyGraphDumper(
output::tell,
DependencyGraphDumper.defaultsWith(DependencyGraphDumper.premanagedProperties()),
output.tool(
DependencyGraphDecorators.TreeDecorator.class, DependencyGraphDecorators.defaultSupplier())));
DependencyGraphDecorators.TreeDecorator.class, DependencyGraphDecorators.defaultSupplier()))));
collectResult.setRoot(clone);
return Result.success(collectResult);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2023-2024 Maveniverse Org.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*/
package eu.maveniverse.maven.toolbox.plugin.mp;

import eu.maveniverse.maven.toolbox.plugin.MPMojoSupport;
import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
import eu.maveniverse.maven.toolbox.shared.Result;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.eclipse.aether.collection.CollectResult;

/**
* Displays dependency dirty tree of Maven Project.
*/
@Mojo(name = "dirty-tree", threadSafe = true)
public class DirtyTreeMojo extends MPMojoSupport {
/**
* The resolution scope to display, accepted values are "runtime", "compile", "test", etc.
*/
@Parameter(property = "scope", defaultValue = "runtime", required = true)
private String scope;

/**
* The dependency matcher if you want to filter as eager as Lenny wants.
*/
@Parameter(property = "dependencyMatcher", defaultValue = "any()", required = true)
private String dependencyMatcher;

/**
* Set it {@code true} for verbose tree.
*/
@Parameter(property = "verboseTree", defaultValue = "false", required = true)
private boolean verboseTree;

/**
* The level up to you want to see dirty tree. Note: keep it low, otherwise this call is OOM pronect.
* Default: 3
*/
@Parameter(property = "dirtyLevel", defaultValue = "3", required = true)
private int dirtyLevel;

@Override
protected Result<CollectResult> doExecute() throws Exception {
ToolboxCommando toolboxCommando = getToolboxCommando();
return toolboxCommando.dirtyTree(
ResolutionScope.parse(scope),
projectAsResolutionRoot(),
dirtyLevel,
verboseTree,
toolboxCommando.parseDependencyMatcherSpec(dependencyMatcher));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.eclipse.aether.collection.CollectResult;

/**
* Collects project and output its dependency tree.
* Displays dependency tree of Maven Project.
*/
@Mojo(name = "tree", threadSafe = true)
public class TreeMojo extends MPMojoSupport {
Expand Down

0 comments on commit 3d9f281

Please sign in to comment.