-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathMain.java
More file actions
64 lines (51 loc) · 2.1 KB
/
Copy pathMain.java
File metadata and controls
64 lines (51 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package org.example;
import org.example.analyzer.JarMetricsAnalyzer;
import org.example.model.Metrics;
import org.example.output.ConsoleOutputFormatter;
import org.example.output.JsonOutputFormatter;
import java.io.File;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
if (args.length == 0) {
System.exit(1);
}
String jarFilePath = args[0];
String outputFilePath = null;
for (int i = 1; i < args.length; i++) {
if (args[i].equals("--output") && i + 1 < args.length) {
outputFilePath = args[i + 1];
i++;
}
}
File jarFile = new File(jarFilePath);
if (!jarFile.exists()) {
System.err.println("Ошибка: JAR файл не найден: " + jarFilePath);
System.exit(1);
}
if (!jarFile.isFile()) {
System.err.println("Ошибка: Указанный путь не является файлом: " + jarFilePath);
System.exit(1);
}
try {
System.out.println("Анализ JAR файла: " + jarFilePath);
JarMetricsAnalyzer analyzer = new JarMetricsAnalyzer();
Metrics metrics = analyzer.analyze(jarFilePath);
ConsoleOutputFormatter consoleFormatter = new ConsoleOutputFormatter();
consoleFormatter.print(metrics);
if (outputFilePath != null) {
JsonOutputFormatter jsonFormatter = new JsonOutputFormatter();
jsonFormatter.writeToFile(metrics, outputFilePath);
System.out.println("Метрики сохранены в файл: " + outputFilePath);
}
} catch (IOException e) {
System.err.println("Ошибка при анализе JAR файла: " + e.getMessage());
e.printStackTrace();
System.exit(1);
} catch (Exception e) {
System.err.println("Неожиданная ошибка: " + e.getMessage());
e.printStackTrace();
System.exit(1);
}
}
}