mvn-tree-visualizer 1.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mvn_tree_visualizer/__main__.py +71 -0
- mvn_tree_visualizer/diagram.py +73 -0
- mvn_tree_visualizer/get_dependencies_in_one_file.py +11 -0
- mvn_tree_visualizer-1.0.1.dist-info/METADATA +32 -0
- mvn_tree_visualizer-1.0.1.dist-info/RECORD +7 -0
- mvn_tree_visualizer-1.0.1.dist-info/WHEEL +5 -0
- mvn_tree_visualizer-1.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from .diagram import create_diagram
|
|
5
|
+
from .get_dependencies_in_one_file import merge_files
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main():
|
|
9
|
+
pass
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
if __name__ == "__main__":
|
|
13
|
+
parser = argparse.ArgumentParser(
|
|
14
|
+
prog="mvn-tree-visualizer",
|
|
15
|
+
description="Generate a dependency diagram from a file.",
|
|
16
|
+
)
|
|
17
|
+
parser.add_argument(
|
|
18
|
+
"directory",
|
|
19
|
+
type=str,
|
|
20
|
+
nargs="?",
|
|
21
|
+
default=".",
|
|
22
|
+
help="The directory to scan for the Maven dependency file(s). Default is the current directory.",
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
parser.add_argument(
|
|
26
|
+
"-o",
|
|
27
|
+
"--output",
|
|
28
|
+
type=str,
|
|
29
|
+
default="diagram.html",
|
|
30
|
+
help="The output file for the generated diagram. Default is 'diagram.html'.",
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
parser.add_argument(
|
|
34
|
+
"-f",
|
|
35
|
+
"--filename",
|
|
36
|
+
type=str,
|
|
37
|
+
default="maven_dependency_file",
|
|
38
|
+
help="The name of the file to read the Maven dependencies from. Default is 'maven_dependency_file'.",
|
|
39
|
+
)
|
|
40
|
+
parser.add_argument(
|
|
41
|
+
"--keep-tree",
|
|
42
|
+
type=bool,
|
|
43
|
+
default=False,
|
|
44
|
+
help="Keep the dependency tree file after generating the diagram. Default is False.",
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
args = parser.parse_args()
|
|
48
|
+
directory: str = args.directory
|
|
49
|
+
output_file: str = args.output
|
|
50
|
+
filename: str = args.filename
|
|
51
|
+
keep_tree: bool = args.keep_tree
|
|
52
|
+
|
|
53
|
+
dir_to_create_files = Path(output_file).parent
|
|
54
|
+
|
|
55
|
+
dir_to_create_intermediate_files = Path(dir_to_create_files)
|
|
56
|
+
|
|
57
|
+
merge_files(
|
|
58
|
+
output_file=dir_to_create_intermediate_files / "dependency_tree.txt",
|
|
59
|
+
root_dir=directory,
|
|
60
|
+
target_filename=filename,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
create_diagram(
|
|
64
|
+
keep_tree=keep_tree,
|
|
65
|
+
intermediate_filename="dependency_tree.txt",
|
|
66
|
+
output_filename=output_file,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
print(f"Diagram generated and saved to {output_file}")
|
|
70
|
+
print("You can open it in your browser to view the dependency tree.")
|
|
71
|
+
print("Thank you for using mvn-tree-visualizer!")
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from jinja2 import Environment, FileSystemLoader
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def _convert_to_mermaid(dependency_tree: str) -> str:
|
|
7
|
+
# generate a `graph LR` format for Mermaid
|
|
8
|
+
lines = dependency_tree.strip().split("\n")
|
|
9
|
+
mermaid_lines = set()
|
|
10
|
+
|
|
11
|
+
previous_dependency = []
|
|
12
|
+
|
|
13
|
+
for line in lines:
|
|
14
|
+
if not line or line.startswith("[INFO]"):
|
|
15
|
+
continue
|
|
16
|
+
parts = line.split(":")
|
|
17
|
+
|
|
18
|
+
if len(parts) < 3:
|
|
19
|
+
continue
|
|
20
|
+
|
|
21
|
+
if len(parts) == 4:
|
|
22
|
+
group_id, artifact_id, app, version = parts
|
|
23
|
+
mermaid_lines.add(f"\t{artifact_id};")
|
|
24
|
+
|
|
25
|
+
if previous_dependency: # Re initialize the list if it wasn't empty
|
|
26
|
+
previous_dependency = []
|
|
27
|
+
|
|
28
|
+
previous_dependency.append((artifact_id, 0)) # The second element is the depth
|
|
29
|
+
else:
|
|
30
|
+
depth = len(parts[0].split(" ")) - 1
|
|
31
|
+
|
|
32
|
+
if len(parts) == 6:
|
|
33
|
+
dirty_group_id, artifact_id, app, ejb_client, version, dependency = parts
|
|
34
|
+
else:
|
|
35
|
+
dirty_group_id, artifact_id, app, version, dependency = parts
|
|
36
|
+
|
|
37
|
+
if previous_dependency[-1][1] < depth:
|
|
38
|
+
mermaid_lines.add(f"\t{previous_dependency[-1][0]} --> {artifact_id};")
|
|
39
|
+
previous_dependency.append((artifact_id, depth))
|
|
40
|
+
else:
|
|
41
|
+
# remove all dependencies that are deeper or equal to the current depth
|
|
42
|
+
while previous_dependency and previous_dependency[-1][1] >= depth:
|
|
43
|
+
previous_dependency.pop()
|
|
44
|
+
|
|
45
|
+
mermaid_lines.add(f"\t{previous_dependency[-1][0]} --> {artifact_id};")
|
|
46
|
+
previous_dependency.append((artifact_id, depth))
|
|
47
|
+
|
|
48
|
+
mermaid_diagram = f"graph LR\n{'\n'.join(sorted(mermaid_lines))}"
|
|
49
|
+
return mermaid_diagram
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def create_diagram(keep_tree: bool = False, intermediate_filename: str = "dependency_tree.txt", output_filename: str = "diagram.html"):
|
|
53
|
+
with open(intermediate_filename, "r") as file:
|
|
54
|
+
dependency_tree = file.read()
|
|
55
|
+
|
|
56
|
+
mermaid_diagram = _convert_to_mermaid(dependency_tree)
|
|
57
|
+
|
|
58
|
+
env = Environment(loader=FileSystemLoader("./src/mvn_tree_visualizer"))
|
|
59
|
+
template = env.get_template("dependency_diagram_template.j2")
|
|
60
|
+
rendered = template.render(diagram_definition=mermaid_diagram)
|
|
61
|
+
|
|
62
|
+
parent_dir = Path(output_filename).parent
|
|
63
|
+
|
|
64
|
+
if not parent_dir.exists():
|
|
65
|
+
parent_dir.mkdir(parents=True, exist_ok=True)
|
|
66
|
+
|
|
67
|
+
with open(output_filename, "w") as f:
|
|
68
|
+
f.write(rendered)
|
|
69
|
+
|
|
70
|
+
if not keep_tree:
|
|
71
|
+
import os
|
|
72
|
+
|
|
73
|
+
os.remove(intermediate_filename)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def merge_files(output_file: str, root_dir: str = ".", target_filename: str = "maven_dependency_file"):
|
|
5
|
+
with open(output_file, "w", encoding="utf-8") as outfile:
|
|
6
|
+
for dirpath, _, filenames in os.walk(root_dir):
|
|
7
|
+
for fname in filenames:
|
|
8
|
+
if fname == target_filename:
|
|
9
|
+
file_path = os.path.join(dirpath, fname)
|
|
10
|
+
with open(file_path, "r", encoding="utf-8") as infile:
|
|
11
|
+
outfile.write(infile.read())
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mvn-tree-visualizer
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: A simple command line tool to visualize the dependency tree of a Maven project in a graphical format.
|
|
5
|
+
Author-email: Iraklis Konsoulas <dyka3773@gmail.com>
|
|
6
|
+
Requires-Python: >=3.13
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: jinja2>=3.1.6
|
|
9
|
+
|
|
10
|
+
# mvn-tree-visualizer
|
|
11
|
+
|
|
12
|
+
This project provides a simple command line tool to visualize the dependency tree of a Maven project in a graphical format.
|
|
13
|
+
|
|
14
|
+
## How to Use
|
|
15
|
+
1. Run the following command in your terminal to generate the dependency tree and save it to a file:
|
|
16
|
+
```bash
|
|
17
|
+
mvn dependency:tree -DoutputFile=maven_dependency_file -DappendOutput=true
|
|
18
|
+
```
|
|
19
|
+
> Feel free to add other options to the command as needed. eg `-Dincludes="org.example"`
|
|
20
|
+
2. Use the `mvn-tree-visualizer` command to visualize the dependency tree:
|
|
21
|
+
```bash
|
|
22
|
+
mvn-tree-visualizer --filename "maven_dependency_file" --output "diagram.html"
|
|
23
|
+
```
|
|
24
|
+
3. Open the generated `diagram.html` file in your web browser to view the dependency tree.
|
|
25
|
+
|
|
26
|
+
## Options
|
|
27
|
+
- `--filename`: The name of the file containing the Maven dependency tree. Default is `maven_dependency_file`.
|
|
28
|
+
- `--output`: The name of the output HTML file. Default is `diagram.html`.
|
|
29
|
+
- `--directory`: The directory to scan for the Maven dependency file(s). Default is the current directory.
|
|
30
|
+
- `--keep-tree`: Keep the tree structure file when processing is complete in the same directory as the output file. Default is false.
|
|
31
|
+
- `--help`: Show help message and exit.
|
|
32
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
mvn_tree_visualizer/__main__.py,sha256=DiYSKezcZRs-AKWTlv7LyfDs7znx9SEbvLXg82swQSM,2036
|
|
2
|
+
mvn_tree_visualizer/diagram.py,sha256=4zElrTDnoh1GWJkxmb50O30G-0CNz6hiR1faFr77VAQ,2567
|
|
3
|
+
mvn_tree_visualizer/get_dependencies_in_one_file.py,sha256=d0ldXC0sYvDKLXozD0JgHsMcID_gN4xjeCUdk5TCiV4,515
|
|
4
|
+
mvn_tree_visualizer-1.0.1.dist-info/METADATA,sha256=frZ836AGAyfauaBQDn9HYP-oDBxFx2F5Cfz4-7ZtGvY,1552
|
|
5
|
+
mvn_tree_visualizer-1.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
6
|
+
mvn_tree_visualizer-1.0.1.dist-info/top_level.txt,sha256=HnFdJDMoJlvQhMTolib_U5UawIdRfkNk8andYnM5lMk,20
|
|
7
|
+
mvn_tree_visualizer-1.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mvn_tree_visualizer
|