Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.junit.extensions.dynamicsuite.engine;
  
  
  import java.io.File;
  import java.net.URL;
 import java.util.List;
Copyright 2011 Christof Schoell

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

 
 public class ClassPathScanner implements ClassScanner {
 
     private List<StringfoundClasses = new ArrayList<String>();
 
     private final boolean includeJars;
 
     public ClassPathScanner(boolean includeJars) {
         this. = includeJars;
         init();
 
     }
 
     @Override
     public List<StringlistClassNames() {
         return ;
     }
 
     public boolean isIncludeJars() {
         return ;
     }
 
     private void init() {
         List<StringclassPathEntries = getClassPathEntries();
         scanForClasses(classPathEntries);
     }
 
     private List<StringgetClassPathEntries() {
         String separator = getPathSeparator();
         String classpath = getClassPathString();
 
         StringTokenizer tokenizer = new StringTokenizer(classpathseparator);
         List<StringclassPathEntries = new ArrayList<String>();
 
         while(tokenizer.hasMoreElements()) {
             String entry = tokenizer.nextToken();
             classPathEntries.add(entry);
         }
         return classPathEntries;
     }
 
     private void scanForClasses(List<StringclassPathEntries) {
         for (String entry : classPathEntries) {
             File entryFile = new File(entry);
             if (entryFile.isDirectory()) {
                 addDirectory(entryFile);
             } else if () {
                 addJar(entryFile);
             }
 
 
         }
     }
 
     private void addDirectory(File entryFile) {
         DirectoryScanner directoryScanner = new DirectoryScanner(entryFile);
         .addAll(directoryScanner.listClassNames());
     }
 
     private void addJar(File fromFile) {
 
         JarFile jar = loadJarFile(fromFile);
 
         if (jar != null) {
             loadJarEntries(jar);
         }
     }
 
     private void loadJarEntries(JarFile jar) {
         Enumeration<JarEntryentries = jar.entries();
         while (entries.hasMoreElements()) {
            JarEntry element = entries.nextElement();
            String name = element.getName();
            if (name.toLowerCase().endsWith(".class")) {
                String className = StringUtils.replace(name"/"".");
                className = StringUtils.removeEnd(className".class");
                .add(className);
            }
        }
    }
    private JarFile loadJarFile(File jarFile) {
        try {
            URL jarURL = new URL ("file:/" + jarFile.getCanonicalPath ());
            jarURL = new URL("jar:" + jarURL.toExternalForm () + "!/");
			return conn.getJarFile();
		}
		catch (Exception e) {
            return null;
        }
    }
    protected String getClassPathString() {
        return System.getProperty("java.class.path");
    }
    protected String getPathSeparator() {
        return System.getProperty("path.separator");
    }
New to GrepCode? Check out our FAQ X