2 * JavaInspect - Utility to visualize java software
3 * Copyright (C) 2013-2018, 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 public final List<JavaFile> javaFiles = new ArrayList<>();
25 private final File scanPath;
26 Map<File, Project> projects = new HashMap<>();
28 public ProjectScanner(final File projectPath) {
29 scanPath = projectPath;
33 public List<Clazz> getAllClasses() {
34 final List<Clazz> result = new ArrayList<>();
36 for (final JavaFile file : javaFiles)
37 result.addAll(file.classes);
44 if (!scanPath.exists())
45 System.out.println("Path not found: " + scanPath);
47 if (!scanPath.canRead())
48 System.out.println("Cannot read path: " + scanPath);
50 if (scanPath.isDirectory())
51 parseDirectory(scanPath);
53 if (scanPath.isFile())
57 public void parseDirectory(final File file) {
59 File[] filesList = file.listFiles();
60 if (filesList == null) throw new RuntimeException("Cannot scan directory: " + file);
62 for (final File subFile : filesList) {
67 if (subFile.isDirectory())
68 parseDirectory(subFile);
72 public void parseFile(final File file) {
73 final String fileExtension = FilePathParser.getFileExtension(file);
74 if ("java".equalsIgnoreCase(fileExtension))
76 final JavaFile javaFile = new JavaFile(file);
77 javaFiles.add(javaFile);
78 } catch (final IOException e) {
79 System.out.println("Error parsing file: " + file.toString()
80 + ": " + e.toString());
81 } catch (final InvalidSyntaxException e) {
82 System.out.println("Syntax error occured while parsing file: "
83 + file.toString() + ": " + e.toString());