callgraph/src/main/java/org/netbeans/lib/callgraph/Arguments.java
changeset 18374 04a79821e760
parent 18372 25e1d840480b
child 18400 c87c223efe6a
     1.1 --- a/callgraph/src/main/java/org/netbeans/lib/callgraph/Arguments.java	Mon Aug 29 05:21:59 2016 -0400
     1.2 +++ b/callgraph/src/main/java/org/netbeans/lib/callgraph/Arguments.java	Sat Sep 03 02:41:36 2016 -0400
     1.3 @@ -63,6 +63,8 @@
     1.4      private static final Command[] commands = new Command[]{
     1.5          new NoSelfReferencesCommand(),
     1.6          new ShortNamesCommand(),
     1.7 +        new ExtendedPropertiesCommand(),
     1.8 +        new AntCommand(),
     1.9          new MavenCommand(),
    1.10          new GradleCommand(),
    1.11          new IgnoreCommand(),
    1.12 @@ -75,12 +77,16 @@
    1.13          new OmitAbstractCommand(),
    1.14          new QuietCommand(),
    1.15          new ReverseCommand(),
    1.16 +        new AggressiveCommand(),
    1.17          new VerboseCommand()
    1.18      };
    1.19      private boolean noSelfReferences = false;
    1.20      private boolean shortNames = false;
    1.21      private boolean maven = false;
    1.22      private boolean gradle = false;
    1.23 +    private boolean ant = false;
    1.24 +    private boolean xprop = false;
    1.25 +    private boolean aggressive = false;
    1.26      private File outfile;
    1.27      private Set<String> exclude = new HashSet<>();
    1.28      private Set<String> ignore = new HashSet<>();
    1.29 @@ -141,13 +147,14 @@
    1.30                  }
    1.31              }
    1.32          }
    1.33 -        Set<String> origFolders = folders;
    1.34 -        if (maven && gradle) {
    1.35 -            errors.add("--maven and --gradle are mutually exclusive");
    1.36 +        if ((maven && gradle) || (ant && gradle) || (ant && maven)) {
    1.37 +            errors.add("--maven, --ant and --gradle are mutually exclusive");
    1.38          } else if (maven) {
    1.39              findMavenSubfolders(errors);
    1.40          } else if (gradle) {
    1.41              findGradleSubfolders(errors);
    1.42 +        } else if (ant) {
    1.43 +            findAntSubfolders(errors);
    1.44          }
    1.45          Set<File> toIgnore = new HashSet<>();
    1.46          for (String ig : ignore) {
    1.47 @@ -193,6 +200,12 @@
    1.48              }
    1.49          }
    1.50          this.folders.removeAll(toIgnore);
    1.51 +        if (verbose && !this.folders.isEmpty()) {
    1.52 +            System.err.println("Will scan the following source roots:");
    1.53 +            for (File f : folders()) {
    1.54 +                System.err.println("  " + f.getAbsolutePath());
    1.55 +            }
    1.56 +        }
    1.57  
    1.58          if (packageGraphFile != null) {
    1.59              File parent = packageGraphFile.getParentFile();
    1.60 @@ -250,6 +263,36 @@
    1.61          return pom.exists() && pom.isFile() && pom.canRead();
    1.62      }
    1.63  
    1.64 +    void findAntSubfolders(List<String> errors) {
    1.65 +        Set<File> flds = new HashSet<>(this.folders);
    1.66 +        this.folders.clear();
    1.67 +        for (File f : flds) {
    1.68 +            recurseSubfoldersLookingForAntProjects(f);
    1.69 +        }
    1.70 +        if (this.folders.isEmpty()) {
    1.71 +            errors.add("Did not find any ant projects (looked for build.xml and src/ in all subfolders of folder list)");
    1.72 +        }
    1.73 +    }
    1.74 +
    1.75 +    private void recurseSubfoldersLookingForAntProjects(File file) {
    1.76 +        if (file.isDirectory()) {
    1.77 +            if (hasBuildXml(file)) {
    1.78 +                File sources = new File(file, "src");
    1.79 +                if (sources.exists() && sources.isDirectory()) {
    1.80 +                    this.folders.add(sources);
    1.81 +                }
    1.82 +            }
    1.83 +            for (File child : file.listFiles()) {
    1.84 +                recurseSubfoldersLookingForAntProjects(child);
    1.85 +            }
    1.86 +        }
    1.87 +    }
    1.88 +
    1.89 +    private boolean hasBuildXml(File fld) {
    1.90 +        File pom = new File(fld, "build.xml");
    1.91 +        return pom.exists() && pom.isFile() && pom.canRead();
    1.92 +    }
    1.93 +
    1.94      void findGradleSubfolders(List<String> errors) {
    1.95          Set<File> flds = new HashSet<>(this.folders);
    1.96          this.folders.clear();
    1.97 @@ -333,6 +376,20 @@
    1.98      }
    1.99  
   1.100      @Override
   1.101 +    public boolean isAnt() {
   1.102 +        return ant;
   1.103 +    }
   1.104 +
   1.105 +    @Override
   1.106 +    public boolean isExtendedProperties() {
   1.107 +        return xprop;
   1.108 +    }
   1.109 +
   1.110 +    public boolean isAggressive() {
   1.111 +        return aggressive;
   1.112 +    }
   1.113 +
   1.114 +    @Override
   1.115      public File classGraphFile() {
   1.116          return classGraphFile;
   1.117      }
   1.118 @@ -467,7 +524,7 @@
   1.119  
   1.120          @Override
   1.121          protected String help() {
   1.122 -            return "Disable string memory optimizations - runs faster but may run out of memory";
   1.123 +            return "Disable string memory optimizations - runs faster and supports unicode class names, but may run out of memory";
   1.124          }
   1.125      }
   1.126  
   1.127 @@ -489,6 +546,25 @@
   1.128          }
   1.129      }
   1.130  
   1.131 +    private static final class AggressiveCommand extends Command {
   1.132 +
   1.133 +        AggressiveCommand() {
   1.134 +            super(CMD_AGGRESSIVE_MEMORY, "z", true, false);
   1.135 +        }
   1.136 +
   1.137 +        @Override
   1.138 +        protected int doParse(int i, String[] args, Arguments toSet) {
   1.139 +            toSet.aggressive = true;
   1.140 +            return 1;
   1.141 +        }
   1.142 +
   1.143 +        @Override
   1.144 +        protected String help() {
   1.145 +            return "Aggressively optimize the 8-bit string intern table "
   1.146 +                    + "for large graphs, sacrificing performace for space";
   1.147 +        }
   1.148 +    }
   1.149 +
   1.150      private static final class ShortNamesCommand extends Command {
   1.151  
   1.152          ShortNamesCommand() {
   1.153 @@ -507,6 +583,42 @@
   1.154          }
   1.155      }
   1.156  
   1.157 +    private static final class ExtendedPropertiesCommand extends Command {
   1.158 +
   1.159 +        ExtendedPropertiesCommand() {
   1.160 +            super(CMD_EXTENDED_PROPERTIES, "x", true, false);
   1.161 +        }
   1.162 +
   1.163 +        @Override
   1.164 +        protected int doParse(int i, String[] args, Arguments toSet) {
   1.165 +            toSet.xprop = true;
   1.166 +            return 1;
   1.167 +        }
   1.168 +
   1.169 +        @Override
   1.170 +        protected String help() {
   1.171 +            return "Find all maven projects that are children of the passed folders, and scan their src/main/java subfolders";
   1.172 +        }
   1.173 +    }
   1.174 +
   1.175 +    private static final class AntCommand extends Command {
   1.176 +
   1.177 +        AntCommand() {
   1.178 +            super(CMD_ANT, "a", true, false);
   1.179 +        }
   1.180 +
   1.181 +        @Override
   1.182 +        protected int doParse(int i, String[] args, Arguments toSet) {
   1.183 +            toSet.ant = true;
   1.184 +            return 1;
   1.185 +        }
   1.186 +
   1.187 +        @Override
   1.188 +        protected String help() {
   1.189 +            return "Find all ant projects that are children of the passed folders, and scan their src/ subfolders";
   1.190 +        }
   1.191 +    }
   1.192 +
   1.193      private static final class MavenCommand extends Command {
   1.194  
   1.195          MavenCommand() {