2 * JavaInspect - Utility to visualize java software
3 * Copyright (C) 2013-2015, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 3 of the GNU Lesser General Public License
7 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.inspector.java.methods;
12 import eu.svjatoslav.commons.file.FilePathParser;
13 import eu.svjatoslav.commons.string.tokenizer.InvalidSyntaxException;
16 import java.io.IOException;
17 import java.util.ArrayList;
18 import java.util.HashMap;
19 import java.util.List;
22 public class ProjectScanner {
24 private final File scanPath;
25 public List<JavaFile> javaFiles = new ArrayList<JavaFile>();
26 Map<File, Project> projects = new HashMap<File, Project>();
28 public ProjectScanner(final File projectPath) {
29 scanPath = projectPath;
33 public List<Clazz> getAllClasses() {
34 final List<Clazz> result = new ArrayList<Clazz>();
36 for (final JavaFile file : javaFiles)
37 for (final Clazz clazz : file.classes)
45 if (!scanPath.exists())
46 System.out.println("Path not found: " + scanPath);
48 if (!scanPath.canRead())
49 System.out.println("Cannot read path: " + scanPath);
51 if (scanPath.isDirectory())
52 parseDirectory(scanPath);
54 if (scanPath.isFile())
58 public void parseDirectory(final File file) {
60 File[] filesList = file.listFiles();
61 if (filesList == null) throw new RuntimeException("Cannot scan directory: " + file);
63 for (final File subFile : filesList) {
68 if (subFile.isDirectory())
69 parseDirectory(subFile);
73 public void parseFile(final File file) {
74 final String fileExtension = FilePathParser.getFileExtension(file);
75 if ("java".equalsIgnoreCase(fileExtension))
77 final JavaFile javaFile = new JavaFile(file);
78 javaFiles.add(javaFile);
79 } catch (final IOException e) {
80 System.out.println("Error parsing file: " + file.toString()
81 + ": " + e.toString());
82 } catch (final InvalidSyntaxException e) {
83 System.out.println("Syntax error occured while parsing file: "
84 + file.toString() + ": " + e.toString());