| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
package org.eclipse.swtbot.generator; |
| 12 | |
|
| 13 | |
import java.io.BufferedReader; |
| 14 | |
import java.io.BufferedWriter; |
| 15 | |
import java.io.File; |
| 16 | |
import java.io.FileNotFoundException; |
| 17 | |
import java.io.FileReader; |
| 18 | |
import java.io.FileWriter; |
| 19 | |
import java.io.IOException; |
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | 0 | public class MatcherGeneratorMain { |
| 26 | |
|
| 27 | |
private static final String newLine = "\n"; |
| 28 | |
|
| 29 | |
public static void main(String[] args) { |
| 30 | |
try { |
| 31 | 0 | org.hamcrest.generator.config.XmlConfigurator.main(new String[] { "swtbot-matchers.xml", "../org.eclipse.swtbot.swt.finder/src", |
| 32 | 0 | "org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory_Original", "../org.eclipse.swtbot.swt.finder/src" }); |
| 33 | |
|
| 34 | 0 | org.hamcrest.generator.config.XmlConfigurator.main(new String[] { "swtbot-eclipse-matchers.xml", |
| 35 | 0 | "../org.eclipse.swtbot.eclipse.finder/src", "org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory_Original", |
| 36 | 0 | "../org.eclipse.swtbot.eclipse.finder/src" }); |
| 37 | |
|
| 38 | 0 | makeEclipseWidgetMatcherFactoryExtendSWTBotWidgetMatcherFactory(); |
| 39 | 0 | makeWidgetMatcherFactoryAbstract(); |
| 40 | |
|
| 41 | 0 | } catch (Throwable e) { |
| 42 | 0 | e.printStackTrace(); |
| 43 | |
} |
| 44 | 0 | } |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
private static void makeEclipseWidgetMatcherFactoryExtendSWTBotWidgetMatcherFactory() throws FileNotFoundException, IOException { |
| 51 | 0 | String sourceFile = "../org.eclipse.swtbot.eclipse.finder/src/org/eclipse/swtbot/eclipse/finder/matchers/WidgetMatcherFactory_Original.java"; |
| 52 | 0 | BufferedReader reader = new BufferedReader(new FileReader(sourceFile)); |
| 53 | |
|
| 54 | 0 | BufferedWriter writer = new BufferedWriter(new FileWriter( |
| 55 | 0 | "../org.eclipse.swtbot.eclipse.finder/src/org/eclipse/swtbot/eclipse/finder/matchers/WidgetMatcherFactory.java")); |
| 56 | 0 | writer.append("// Generated source. DO NOT MODIFY.").append(newLine); |
| 57 | 0 | writer.append("// To add new new methods, please see README file in the generator plugin.").append(newLine); |
| 58 | |
|
| 59 | 0 | while (reader.ready()) { |
| 60 | 0 | String line = reader.readLine(); |
| 61 | 0 | line = line.replaceAll("^// Generated source.$", ""); |
| 62 | 0 | line = line.replaceAll("public class WidgetMatcherFactory_Original \\{", |
| 63 | 0 | "public abstract class WidgetMatcherFactory extends org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory {"); |
| 64 | 0 | writer.write(line); |
| 65 | 0 | writer.write("\n"); |
| 66 | |
} |
| 67 | 0 | writer.close(); |
| 68 | 0 | reader.close(); |
| 69 | 0 | new File(sourceFile).delete(); |
| 70 | 0 | } |
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
private static void makeWidgetMatcherFactoryAbstract() throws FileNotFoundException, IOException { |
| 77 | 0 | String sourceFile = "../org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/matchers/WidgetMatcherFactory_Original.java"; |
| 78 | 0 | BufferedReader reader = new BufferedReader(new FileReader(sourceFile)); |
| 79 | |
|
| 80 | 0 | BufferedWriter writer = new BufferedWriter(new FileWriter( |
| 81 | 0 | "../org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/matchers/WidgetMatcherFactory.java")); |
| 82 | 0 | writer.append("// Generated source. DO NOT MODIFY.").append(newLine); |
| 83 | 0 | writer.append("// To add new new methods, please see README file in the generator plugin.").append(newLine); |
| 84 | |
|
| 85 | 0 | while (reader.ready()) { |
| 86 | 0 | String line = reader.readLine(); |
| 87 | 0 | line = line.replaceAll("^// Generated source.$", ""); |
| 88 | 0 | line = line.replaceAll("public class WidgetMatcherFactory_Original \\{", "public abstract class WidgetMatcherFactory {"); |
| 89 | 0 | writer.write(line); |
| 90 | 0 | writer.write("\n"); |
| 91 | |
} |
| 92 | 0 | writer.close(); |
| 93 | 0 | reader.close(); |
| 94 | 0 | new File(sourceFile).delete(); |
| 95 | 0 | } |
| 96 | |
} |