Beispiel #1
0
 /*
  * This function inspects a .class file for a given .java file,
  * infers the package name and all used classes, and adds to "all"
  * the class file names of those classes used that have been found
  * in the same class path.
  */
 protected void java2classFiles(
     String java, File cwd, File buildDir, List<String> result, Set<String> all) {
   if (java.endsWith(".java")) java = java.substring(0, java.length() - 5) + ".class";
   else if (!java.endsWith(".class")) {
     if (!all.contains(java)) {
       if (buildDir == null) sortClassesAtEnd(result);
       result.add(java);
       all.add(java);
     }
     return;
   }
   byte[] buffer = Util.readFile(Util.makePath(cwd, java));
   if (buffer == null) {
     if (!java.endsWith("/package-info.class"))
       err.println("Warning: " + java + " does not exist.  Skipping...");
     return;
   }
   ByteCodeAnalyzer analyzer = new ByteCodeAnalyzer(buffer);
   String fullClass = analyzer.getPathForClass() + ".class";
   if (!java.endsWith(fullClass))
     throw new RuntimeException("Huh? " + fullClass + " is not a suffix of " + java);
   java = java.substring(0, java.length() - fullClass.length());
   for (String className : analyzer.getClassNames()) {
     String path = java + className + ".class";
     if (new File(Util.makePath(cwd, path)).exists() && !all.contains(path)) {
       result.add(path);
       all.add(path);
       java2classFiles(path, cwd, buildDir, result, all);
     }
   }
 }
Beispiel #2
0
 /* discovers all the .class files for a given set of .java files */
 protected List<String> java2classFiles(
     List<String> javas, File cwd, File buildDir, Set<String> exclude, Set<String> noCompile)
     throws FakeException {
   List<String> result = new ArrayList<String>();
   Set<String> all = new HashSet<String>();
   if (buildDir != null) {
     addRecursively(buildDir, result, all);
     Collections.sort(result);
   }
   String lastJava = null;
   for (String file : javas) {
     if (exclude.contains(file)) continue;
     boolean dontCompile = noCompile.contains(file);
     if (buildDir != null) {
       if (!dontCompile && file.endsWith(".java")) {
         lastJava = file;
         continue;
       }
       if (lastJava != null) {
         String prefix = getPrefix(cwd, lastJava);
         if (prefix != null) result.add(prefix);
         else err.println("Error: " + lastJava);
         lastJava = null;
       }
     }
     if (dontCompile) {
       if (!all.contains(file)) {
         result.add(file);
         all.add(file);
       }
       continue;
     }
     java2classFiles(file, cwd, buildDir, result, all);
   }
   if (buildDir == null) sortClassesAtEnd(result);
   return result;
 }