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