X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Finspector%2Fjava%2Fmethods%2FProjectScanner.java;h=78a5e9c28773d8f43b532699aff8d1e2d9e08318;hb=c680c10ad9057106e23b149246abdd84b41775ee;hp=2674d86cc87db5797363347efeaab986ae38e7bc;hpb=7520d141e59025fdd93e43f6e86785b451975ecf;p=javainspect.git diff --git a/src/main/java/eu/svjatoslav/inspector/java/methods/ProjectScanner.java b/src/main/java/eu/svjatoslav/inspector/java/methods/ProjectScanner.java index 2674d86..78a5e9c 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/methods/ProjectScanner.java +++ b/src/main/java/eu/svjatoslav/inspector/java/methods/ProjectScanner.java @@ -9,6 +9,9 @@ package eu.svjatoslav.inspector.java.methods; +import eu.svjatoslav.commons.file.FilePathParser; +import eu.svjatoslav.commons.string.tokenizer.InvalidSyntaxException; + import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -16,71 +19,70 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import eu.svjatoslav.commons.file.FilePathParser; -import eu.svjatoslav.commons.string.tokenizer.InvalidSyntaxException; - public class ProjectScanner { - private final File scanPath; + private final File scanPath; + public List javaFiles = new ArrayList(); + Map projects = new HashMap(); - Map projects = new HashMap(); - public List javaFiles = new ArrayList(); + public ProjectScanner(final File projectPath) { + scanPath = projectPath; + parse(); + } - public ProjectScanner(final File projectPath) { - scanPath = projectPath; - parse(); - } + public List getAllClasses() { + final List result = new ArrayList(); - public List getAllClasses() { - final List result = new ArrayList(); + for (final JavaFile file : javaFiles) + for (final Clazz clazz : file.classes) + result.add(clazz); - for (final JavaFile file : javaFiles) - for (final Clazz clazz : file.classes) - result.add(clazz); + return result; + } - return result; - } + public void parse() { - public void parse() { + if (!scanPath.exists()) + System.out.println("Path not found: " + scanPath); - if (!scanPath.exists()) - System.out.println("Path not found: " + scanPath); + if (!scanPath.canRead()) + System.out.println("Cannot read path: " + scanPath); - if (!scanPath.canRead()) - System.out.println("Cannot read path: " + scanPath); + if (scanPath.isDirectory()) + parseDirectory(scanPath); - if (scanPath.isDirectory()) - parseDirectory(scanPath); + if (scanPath.isFile()) + parseFile(scanPath); + } - if (scanPath.isFile()) - parseFile(scanPath); - } + public void parseDirectory(final File file) { - public void parseDirectory(final File file) { + File[] filesList = file.listFiles(); + if (filesList == null) throw new RuntimeException("Cannot scan directory: " + file); - for (final File subFile : file.listFiles()) { + for (final File subFile : filesList) { - if (subFile.isFile()) - parseFile(subFile); + if (subFile.isFile()) + parseFile(subFile); - if (subFile.isDirectory()) - parseDirectory(subFile); - } - } + if (subFile.isDirectory()) + parseDirectory(subFile); + } + } - public void parseFile(final File file) { - final String fileExtension = FilePathParser.getFileExtension(file); - if ("java".equalsIgnoreCase(fileExtension)) - try { - final JavaFile javaFile = new JavaFile(file); - javaFiles.add(javaFile); - } catch (final IOException e) { - System.out.println("Error parsing file: " + file.toString() - + ": " + e.toString()); - } catch (final InvalidSyntaxException e) { - System.out.println("Syntax error occured while parsing file: " - + file.toString() + ": " + e.toString()); - } - } + public void parseFile(final File file) { + final String fileExtension = FilePathParser.getFileExtension(file); + if ("java".equalsIgnoreCase(fileExtension)) + try { + final JavaFile javaFile = new JavaFile(file); + javaFiles.add(javaFile); + } catch (final IOException e) { + System.out.println("Error parsing file: " + file.toString() + + ": " + e.toString()); + } catch (final InvalidSyntaxException e) { + System.out.println("Syntax error occured while parsing file: " + + file.toString() + ": " + e.toString()); + } + } }