1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
package com.jeantessier.dependencyfinder.cli; |
34 | |
|
35 | |
import java.util.*; |
36 | |
|
37 | |
import com.jeantessier.commandline.*; |
38 | |
import com.jeantessier.dependency.*; |
39 | |
|
40 | 1 | public class DependencyMetrics extends DependencyGraphCommand { |
41 | |
protected void populateCommandLineSwitches() { |
42 | 20 | super.populateCommandLineSwitches(); |
43 | |
|
44 | 20 | populateCommandLineSwitchesForScoping(); |
45 | 20 | populateCommandLineSwitchesForFiltering(); |
46 | |
|
47 | 20 | getCommandLine().addAliasSwitch("p2p", "package-scope", "package-filter"); |
48 | 20 | getCommandLine().addAliasSwitch("c2p", "class-scope", "package-filter"); |
49 | 20 | getCommandLine().addAliasSwitch("c2c", "class-scope", "class-filter"); |
50 | 20 | getCommandLine().addAliasSwitch("f2f", "feature-scope", "feature-filter"); |
51 | 20 | getCommandLine().addAliasSwitch("includes", "scope-includes", "filter-includes"); |
52 | 20 | getCommandLine().addAliasSwitch("excludes", "scope-excludes", "filter-excludes"); |
53 | |
|
54 | 20 | getCommandLine().addToggleSwitch("list"); |
55 | 20 | getCommandLine().addToggleSwitch("chart-classes-per-package"); |
56 | 20 | getCommandLine().addToggleSwitch("chart-features-per-class"); |
57 | 20 | getCommandLine().addToggleSwitch("chart-inbounds-per-package"); |
58 | 20 | getCommandLine().addToggleSwitch("chart-outbounds-per-package"); |
59 | 20 | getCommandLine().addToggleSwitch("chart-inbounds-per-class"); |
60 | 20 | getCommandLine().addToggleSwitch("chart-outbounds-per-class"); |
61 | 20 | getCommandLine().addToggleSwitch("chart-inbounds-per-feature"); |
62 | 20 | getCommandLine().addToggleSwitch("chart-outbounds-per-feature"); |
63 | |
|
64 | 20 | getCommandLine().addAliasSwitch("chart-inbounds", "chart-inbounds-per-package", "chart-inbounds-per-class", "chart-inbounds-per-feature"); |
65 | 20 | getCommandLine().addAliasSwitch("chart-outbounds", "chart-outbounds-per-package", "chart-outbounds-per-class", "chart-outbounds-per-feature"); |
66 | 20 | getCommandLine().addAliasSwitch("chart-packages", "chart-classes-per-package", "chart-inbounds-per-package", "chart-outbounds-per-package"); |
67 | 20 | getCommandLine().addAliasSwitch("chart-classes", "chart-features-per-class", "chart-inbounds-per-class", "chart-outbounds-per-class"); |
68 | 20 | getCommandLine().addAliasSwitch("chart-features", "chart-inbounds-per-feature", "chart-outbounds-per-feature"); |
69 | 20 | getCommandLine().addAliasSwitch("chart-all", "chart-classes-per-package", "chart-features-per-class", "chart-inbounds-per-package", "chart-outbounds-per-package", "chart-inbounds-per-class", "chart-outbounds-per-class", "chart-inbounds-per-feature", "chart-outbounds-per-feature"); |
70 | 20 | } |
71 | |
|
72 | |
protected Collection<CommandLineException> parseCommandLine(String[] args) { |
73 | 19 | Collection<CommandLineException> exceptions = super.parseCommandLine(args); |
74 | |
|
75 | 19 | exceptions.addAll(validateCommandLineForScoping()); |
76 | 19 | exceptions.addAll(validateCommandLineForFiltering()); |
77 | |
|
78 | 19 | return exceptions; |
79 | |
} |
80 | |
|
81 | |
public void doProcessing() throws Exception { |
82 | 0 | MetricsReport reporter = new MetricsReport(getOut()); |
83 | |
|
84 | 0 | reporter.setListingElements(getCommandLine().getToggleSwitch("list")); |
85 | 0 | reporter.setChartingClassesPerPackage(getCommandLine().getToggleSwitch("chart-classes-per-package")); |
86 | 0 | reporter.setChartingFeaturesPerClass(getCommandLine().getToggleSwitch("chart-features-per-class")); |
87 | 0 | reporter.setChartingInboundsPerPackage(getCommandLine().getToggleSwitch("chart-inbounds-per-package")); |
88 | 0 | reporter.setChartingOutboundsPerPackage(getCommandLine().getToggleSwitch("chart-outbounds-per-package")); |
89 | 0 | reporter.setChartingInboundsPerClass(getCommandLine().getToggleSwitch("chart-inbounds-per-class")); |
90 | 0 | reporter.setChartingOutboundsPerClass(getCommandLine().getToggleSwitch("chart-outbounds-per-class")); |
91 | 0 | reporter.setChartingInboundsPerFeature(getCommandLine().getToggleSwitch("chart-inbounds-per-feature")); |
92 | 0 | reporter.setChartingOutboundsPerFeature(getCommandLine().getToggleSwitch("chart-outbounds-per-feature")); |
93 | |
|
94 | 0 | SelectionCriteria scopeCriteria = getScopeCriteria(); |
95 | 0 | SelectionCriteria filterCriteria = getFilterCriteria(); |
96 | |
|
97 | 0 | getVerboseListener().print("Generating report ..."); |
98 | |
|
99 | 0 | MetricsGatherer metrics = new MetricsGatherer(new SelectiveTraversalStrategy(scopeCriteria, filterCriteria)); |
100 | 0 | metrics.traverseNodes(loadGraph().getPackages().values()); |
101 | 0 | reporter.process(metrics); |
102 | 0 | } |
103 | |
|
104 | |
public static void main(String[] args) throws Exception { |
105 | 0 | new DependencyMetrics().run(args); |
106 | 0 | } |
107 | |
} |