Coverage Report - org.eclipse.swtbot.generator.MatcherGeneratorMain
 
Classes in this File Line Coverage Branch Coverage Complexity
MatcherGeneratorMain
0%
0/44
0%
0/4
2
 
 1  
 /*******************************************************************************
 2  
  * Copyright (c) 2008 Ketan Padegaonkar and others.
 3  
  * All rights reserved. This program and the accompanying materials
 4  
  * are made available under the terms of the Eclipse Public License v1.0
 5  
  * which accompanies this distribution, and is available at
 6  
  * http://www.eclipse.org/legal/epl-v10.html
 7  
  * 
 8  
  * Contributors:
 9  
  *     Ketan Padegaonkar - initial API and implementation
 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  
  * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
 23  
  * @version $Id$
 24  
  */
 25  0
 public class MatcherGeneratorMain {
 26  
 
 27  
         private static final String                newLine        = "\n"; //$NON-NLS-1$
 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", //$NON-NLS-1$ //$NON-NLS-2$
 32  0
                                         "org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory_Original", "../org.eclipse.swtbot.swt.finder/src" }); //$NON-NLS-1$ //$NON-NLS-2$
 33  
 
 34  0
                         org.hamcrest.generator.config.XmlConfigurator.main(new String[] { "swtbot-eclipse-matchers.xml", //$NON-NLS-1$
 35  0
                                         "../org.eclipse.swtbot.eclipse.finder/src", "org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory_Original", //$NON-NLS-1$ //$NON-NLS-2$
 36  0
                                         "../org.eclipse.swtbot.eclipse.finder/src" }); //$NON-NLS-1$
 37  
 
 38  0
                         makeEclipseWidgetMatcherFactoryExtendSWTBotWidgetMatcherFactory();
 39  0
                         makeWidgetMatcherFactoryAbstract();
 40  
 
 41  0
                 } catch (Throwable e) {
 42  0
                         e.printStackTrace();
 43  
                 }
 44  0
         }
 45  
 
 46  
         /**
 47  
          * @throws FileNotFoundException
 48  
          * @throws IOException
 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"; //$NON-NLS-1$
 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")); //$NON-NLS-1$
 56  0
                 writer.append("// Generated source. DO NOT MODIFY.").append(newLine); //$NON-NLS-1$
 57  0
                 writer.append("// To add new new methods, please see README file in the generator plugin.").append(newLine); //$NON-NLS-1$
 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 \\{", //$NON-NLS-1$
 63  0
                                         "public abstract class WidgetMatcherFactory extends org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory {"); //$NON-NLS-1$
 64  0
                         writer.write(line);
 65  0
                         writer.write("\n"); //$NON-NLS-1$
 66  
                 }
 67  0
                 writer.close();
 68  0
                 reader.close();
 69  0
                 new File(sourceFile).delete();
 70  0
         }
 71  
 
 72  
         /**
 73  
          * @throws FileNotFoundException
 74  
          * @throws IOException
 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"; //$NON-NLS-1$
 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")); //$NON-NLS-1$
 82  0
                 writer.append("// Generated source. DO NOT MODIFY.").append(newLine); //$NON-NLS-1$
 83  0
                 writer.append("// To add new new methods, please see README file in the generator plugin.").append(newLine); //$NON-NLS-1$
 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 {"); //$NON-NLS-1$ //$NON-NLS-2$
 89  0
                         writer.write(line);
 90  0
                         writer.write("\n"); //$NON-NLS-1$
 91  
                 }
 92  0
                 writer.close();
 93  0
                 reader.close();
 94  0
                 new File(sourceFile).delete();
 95  0
         }
 96  
 }