You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

DependsCommand.java 6.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. MIT License
  3. Copyright (c) 2018-2019 Gang ZHANG
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. */
  20. package depends;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. import depends.deptypes.DependencyType;
  24. import depends.extractor.LangProcessorRegistration;
  25. import picocli.CommandLine.Command;
  26. import picocli.CommandLine.Option;
  27. import picocli.CommandLine.Parameters;
  28. @Command(name = "depends")
  29. public class DependsCommand {
  30. public static class SupportedLangs extends ArrayList<String> {
  31. private static final long serialVersionUID = 1L;
  32. public SupportedLangs() { super( LangProcessorRegistration.getRegistry().getLangs()); }
  33. }
  34. public static class SupportedTypes extends ArrayList<String> {
  35. private static final long serialVersionUID = 1L;
  36. public SupportedTypes() { super( DependencyType.allDependencies()); }
  37. }
  38. @Parameters(index = "0", completionCandidates = DependsCommand.SupportedLangs.class, description = "The lanauge of project files: [${COMPLETION-CANDIDATES}]")
  39. private String lang;
  40. @Parameters(index = "1", description = "The directory to be analyzed")
  41. private String src;
  42. @Parameters(index = "2", description = "The output file name")
  43. private String output;
  44. @Option(names = {"-f", "--format"},split=",", description = "the output format: [json(default),xml,excel,detail,dot,plantuml]")
  45. private String[] format=new String[]{"json"};
  46. @Option(names = {"-d", "--dir"}, description = "The output directory")
  47. private String dir;
  48. @Option(names = {"-m", "--map"}, description = "Output DV8 dependency map file.")
  49. private boolean dv8map = true;
  50. @Option(names = {"-s", "--strip-leading-path"}, description = "Strip the leading path.")
  51. private boolean stripLeadingPath = false;
  52. @Option(names = {"--strip-paths"}, split=",", description = "The path(s) to be stripped. if -s enabled, the path(s) start after <src>. "
  53. + "Otherwise, the path(s) should be valid.")
  54. private String[] strippedPaths = new String[]{};
  55. @Option(names = {"-g", "--granularity"}, description = "Granularity of dependency.[file(default),method,structure,L#(the level of folder. e.g. L1=1st level folder)]")
  56. private String granularity="file";
  57. @Option(names = {"-p", "--namepattern"}, description = "The name path pattern.[dot(.), unix(/) or windows(\\)")
  58. private String namePathPattern="";
  59. @Option(names = {"-i","--includes"},split=",", description = "The files of searching path")
  60. private String[] includes = new String[] {};
  61. @Option(names = {"--auto-include"},split=",", description = "auto include all paths under the source path (please notice the potential side effect)")
  62. private boolean autoInclude = false;
  63. @Option(names = {"--detail"},split=",", description = "add detail dependency information to output (only applicable for JSON output format)")
  64. private boolean detail = false;
  65. @Option(names = {"--auto-stub"},split=",", description = "create stub files for unsolved symbols (exprimental feature, only for java)")
  66. private boolean autoStub = false;
  67. @Option(names = {"--type-filter"},split=",", completionCandidates = DependsCommand.SupportedTypes.class, description = "only filter the listed dependency types[${COMPLETION-CANDIDATES}]")
  68. private String[] typeFilter=new String[]{};
  69. @Option(names = {"--external-deps"}, description = "Output external dependencies")
  70. private boolean outputExternalDependencies = false;
  71. @Option(names = {"--duck-typing-deduce"}, description = "Deduce implicit variable types")
  72. private boolean duckTypingDeduce = true;
  73. @Option(names = {"-h","--help"}, usageHelp = true, description = "display this help and exit")
  74. boolean help;
  75. public DependsCommand() {
  76. }
  77. public String getLang() {
  78. return lang;
  79. }
  80. public void setLang(String lang) {
  81. this.lang = lang;
  82. }
  83. public String getSrc() {
  84. return src;
  85. }
  86. public void setSrc(String src) {
  87. this.src = src;
  88. }
  89. public String getOutputName() {
  90. return output;
  91. }
  92. public void setOutput(String output) {
  93. this.output = output;
  94. }
  95. public String[] getFormat() {
  96. return format;
  97. }
  98. public String getOutputDir() {
  99. if (dir==null) {
  100. dir = System.getProperty("user.dir");
  101. }
  102. return dir;
  103. }
  104. public boolean isDv8map() {
  105. return dv8map;
  106. }
  107. public String[] getIncludes() {
  108. return includes;
  109. }
  110. public boolean isHelp() {
  111. return help;
  112. }
  113. public String getGranularity() {
  114. return granularity;
  115. }
  116. public String getNamePathPattern() {
  117. return namePathPattern;
  118. }
  119. public boolean isStripLeadingPath() {
  120. return stripLeadingPath;
  121. }
  122. public boolean isAutoInclude () {
  123. return autoInclude;
  124. }
  125. public boolean isDetail () {
  126. return detail;
  127. }
  128. public String[] getStrippedPaths() {
  129. return strippedPaths;
  130. }
  131. public void setStrippedPaths(String[] strippedPaths) {
  132. this.strippedPaths = strippedPaths;
  133. }
  134. public boolean isAutoStub() {
  135. return autoStub;
  136. }
  137. public List<String> getTypeFilter() {
  138. if (typeFilter.length==0) {
  139. return DependencyType.allDependencies();
  140. }
  141. return java.util.Arrays.asList(typeFilter);
  142. }
  143. public boolean isOutputExternalDependencies() {
  144. return outputExternalDependencies;
  145. }
  146. public boolean isDuckTypingDeduce() {
  147. return this.duckTypingDeduce;
  148. }
  149. }

人工智能研发终端

Contributors (2)