Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright (c) 2013-2014 sagyf Yang. The Four Group.
   */
  
  package com.github.sog.initalizer.ctxbox;
  
 
 import java.io.File;
 import java.util.List;

Class Finder.

Author(s):
sagyf yang
Version:
1.0 2014-01-19 22:32
Since:
JDK 1.6
 
 public class ClassFinder {

    
find class files.
 
     public static void find() {
         String class_path = PathKit.getRootClassPath();
         FluentIterable<Fileiterable = Files.fileTreeTraverser().breadthFirstTraversal(new File(class_path));
         List<StringclassFileList = findClassFile(iterable);
         for (String classFile : classFileList) {
             Class<?> classInFile = Reflect.on(classFile).get();
             ClassBox.getInstance().push(classInFile);
         }
     }

    
find class files.
 
     public static void findWithTest() {
         String testRoolClassPath = PathKit.getRootClassPath();
         FluentIterable<Fileiterable = Files.fileTreeTraverser().breadthFirstTraversal(new File(testRoolClassPath));
         List<StringclassFileList = findTestClassFile(iterable);
         for (String classFile : classFileList) {
             Class<?> classInFile = Reflect.on(classFile).get();
             ClassBox.getInstance().push(classInFile);
         }
 
         String classPath = testRoolClassPath.replace("test-".);
         iterable = Files.fileTreeTraverser().breadthFirstTraversal(new File(classPath));
         classFileList = findClassFile(iterable);
         for (String classFile : classFileList) {
             Class<?> classInFile = Reflect.on(classFile).get();
             ClassBox.getInstance().push(classInFile);
         }
     }

    
Find files use Guava way to find the Class file under classpath.

Parameters:
fileFluentIterable file flunent iterable.
Returns:
class file list.
 
     private static List<StringfindClassFile(FluentIterable<FilefileFluentIterable) {
         final List<Stringfiles = Lists.newArrayList();
         for (File f : fileFluentIterable) {
             final String absolutePath = f.getAbsoluteFile().toString();
             if (f.exists() && !f.isDirectory() && f.getName().endsWith(.)) {
                 String tem = absolutePath.replaceAll("\\\\".);
                 String classname = tem.substring(tem.indexOf("/classes") + "/classes".length() + 1,
                         tem.indexOf(.));
                 if (StringUtils.startsWithIgnoreCase(classname"app")) {
                     // coc: application class into app package.
                     files.add(classname.replaceAll(..));
                 }
             }
         }
         return files;
     }

    
Find test class files use Guava way to find the Class file under classpath.

Parameters:
fileFluentIterable file flunent iterable.
Returns:
class file list.
 
     private static List<StringfindTestClassFile(FluentIterable<FilefileFluentIterable) {
         final List<Stringfiles = Lists.newArrayList();
         for (File f : fileFluentIterable) {
             final String absolutePath = f.getAbsoluteFile().toString();
             if (f.exists() && !f.isDirectory() && f.getName().endsWith(.)) {
                 String tem = absolutePath.replaceAll("\\\\".);
                String classname = tem.substring(tem.indexOf("/test-classes") + "/test-classes".length() + 1,
                        tem.indexOf(.));
                if (StringUtils.startsWithIgnoreCase(classname"app")) {
                    // coc: application class into app package.
                    files.add(classname.replaceAll(..));
                }
            }
        }
        return files;
    }
New to GrepCode? Check out our FAQ X