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 package org.slf4j.migrator;
26
27 import java.io.File;
28 import java.io.IOException;
29 import java.util.ArrayList;
30 import java.util.List;
31
32 import javax.swing.SwingUtilities;
33
34 import org.slf4j.migrator.internal.MigratorFrame;
35 import org.slf4j.migrator.internal.ProgressListener;
36 import org.slf4j.migrator.line.RuleSet;
37
38 public class ProjectConverter {
39
40 private final RuleSet ruleSet;
41 private List<ConversionException> exception;
42
43 ProgressListener progressListener;
44
45 public static void main(String[] args) {
46 SwingUtilities.invokeLater(() -> {
47 MigratorFrame inst = new MigratorFrame();
48 inst.setLocationRelativeTo(null);
49 inst.setVisible(true);
50 });
51 }
52
53
54
55
56
57
58
59
60
61 public ProjectConverter(int conversionType, ProgressListener progressListener) {
62 this.progressListener = progressListener;
63 ruleSet = RuleSetFactory.getMatcherImpl(conversionType);
64 if (ruleSet == null) {
65 addException(new ConversionException(ConversionException.NOT_IMPLEMENTED));
66 }
67 }
68
69 public void convertProject(File folder) {
70 FileSelector fs = new FileSelector(progressListener);
71 List<File> fileList = fs.selectJavaFilesInFolder(folder);
72 scanFileList(fileList);
73 progressListener.onDone();
74 }
75
76
77
78
79
80
81 private void scanFileList(List<File> lstFiles) {
82 progressListener.onFileScanBegin();
83 for (File currentFile : lstFiles) {
84 progressListener.onFileScan(currentFile);
85 scanFile(currentFile);
86 }
87 }
88
89
90
91
92
93
94
95 private void scanFile(File file) {
96 try {
97 InplaceFileConverter fc = new InplaceFileConverter(ruleSet, progressListener);
98 fc.convert(file);
99 } catch (IOException exc) {
100 addException(new ConversionException(exc.toString()));
101 }
102 }
103
104 public void addException(ConversionException exc) {
105 if (exception == null) {
106 exception = new ArrayList<>();
107 }
108 exception.add(exc);
109 }
110
111 public void printException() {
112 if (exception != null) {
113 for (ConversionException exc : exception) {
114 exc.print();
115 }
116 exception = null;
117 }
118 }
119 }