[slf4j-dev] svn commit: r937 - in slf4j/trunk/slf4j-converter/src: main/java/org/slf4j/converter main/java/org/slf4j/converter/line test/java/org/slf4j/converter test/java/org/slf4j/converter/line

ceki at slf4j.org ceki at slf4j.org
Thu Jan 10 21:24:36 CET 2008


Author: ceki
Date: Thu Jan 10 21:24:36 2008
New Revision: 937

Added:
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/FileSelector.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/InplaceFileConverter.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ProjectConverter.java
      - copied, changed from r936, /slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Converter.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/RuleSetFactory.java
      - copied, changed from r936, /slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/AbstractMatcher.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/ConversionRule.java
      - copied, changed from r936, /slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ConversionRule.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/JCLRuleSet.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/LineConverter.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/Log4jRuleSet.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/MultiGroupConversionRule.java
      - copied, changed from r936, /slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/MultiGroupConversionRule.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/RuleSet.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/SingleConversionRule.java
      - copied, changed from r936, /slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/SingleConversionRule.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/EmptyRuleSet.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/JCLRuleSetTest.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/Log4jRuleSetTest.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/NoConversionTest.java
      - copied, changed from r936, /slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/NoConversionTest.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/PackageTest.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/TrivialMatcherTest.java
      - copied, changed from r936, /slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/TrivialMatcherTest.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/TriviialMatcher.java
      - copied, changed from r936, /slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/TriviialMatcher.java
Removed:
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/AbstractMatcher.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ConversionRule.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Converter.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/JCLMatcher.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Log4jMatcher.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/MultiGroupConversionRule.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/SingleConversionRule.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/JCLMatcherTest.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/Log4jMatcherTest.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/NoConversionTest.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/TrivialMatcherTest.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/TriviialMatcher.java
Modified:
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ConverterFrame.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Writer.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/AllTest.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/AternativeApproach.java
   slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/PackageTest.java

Log:

- Serious refactoring of slf4j-converter. 

The idea remains the same, responsibilities are moved around. 
Here is a brief summary of the changes:

1) Conversions of files is done in-place. This means that a Java file is read into memory. 
It is then reopened write-mode where the converted lines are written to it. There is no "backup" 
copy of the converted file. 

2) The main entry to the converter, is now ProjectConverter, which converts all Java files under a folder. 
Each file is converted using an InpalceFileConcerter.


Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ConverterFrame.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ConverterFrame.java	(original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ConverterFrame.java	Thu Jan 10 21:24:36 2008
@@ -22,11 +22,8 @@
 
 public class ConverterFrame extends JFrame implements ActionListener {
 
-  /**
-   * 
-   */
-  private static final long serialVersionUID = 1L;
-  private Converter converter;
+  private static final long serialVersionUID = -1535809047324769347L;
+
   private JButton butCancel;
   private JButton butNext;
   private JComboBox combo;
@@ -37,10 +34,9 @@
 
   private String conversionMode[] = { "JCL to SLF4J", "Log4J to SLF4J" };
 
-  public ConverterFrame(Converter parent) {
-    this.converter = parent;
+  public ConverterFrame() {
     buildFrame();
-    
+
     ConverterStream printStream = new ConverterStream(System.out);
     printStream.setOut(console);
     System.setOut(printStream);
@@ -50,7 +46,7 @@
     setTitle("SLF4J CONVERTER");
     // setIconImage()
     setLocationRelativeTo(null);
-    this.setPreferredSize(new Dimension(512,384));
+    this.setPreferredSize(new Dimension(512, 384));
     setResizable(false);
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
@@ -60,8 +56,8 @@
   private void buildComponents() {
     principalPan = new JPanel();
     principalPan.setLayout(new BorderLayout());
-    
-    conversionPan = new JPanel(new GridLayout(2,2,10,10));
+
+    conversionPan = new JPanel(new GridLayout(2, 2, 10, 10));
     JLabel lab = new JLabel("Conversion Mode");
     conversionPan.add(lab);
 
@@ -71,19 +67,19 @@
     butCancel = new JButton("Cancel");
     butCancel.addActionListener(this);
     conversionPan.add(butCancel);
-    
+
     butNext = new JButton("Next");
     butNext.addActionListener(this);
     conversionPan.add(butNext);
- 
-    consolePan = new JScrollPane(); 
-    console  = new JTextArea();
+
+    consolePan = new JScrollPane();
+    console = new JTextArea();
     console.setEditable(false);
     console.setLineWrap(true);
     console.setMargin(new Insets(5, 5, 5, 5));
     consolePan.setViewportView(console);
-    
-    principalPan.add(conversionPan,BorderLayout.NORTH);
+
+    principalPan.add(conversionPan, BorderLayout.NORTH);
     principalPan.add(consolePan, BorderLayout.CENTER);
     setContentPane(principalPan);
     pack();
@@ -97,7 +93,6 @@
     }
   }
 
-  
   private void showFolderSelector() {
     JFileChooser selector = new JFileChooser();
     selector.setDialogTitle("Source folder selector");
@@ -105,48 +100,39 @@
     int res = selector.showOpenDialog(this);
     if (res == JFileChooser.APPROVE_OPTION) {
       File folder = selector.getSelectedFile();
-      if (!converter.init(folder.getAbsolutePath(), combo.getSelectedIndex())) {
-        showException();
-      } else {
-        showConfirmDialog(converter.selectFiles(), folder.getAbsolutePath());
-      }
+      ProjectConverter converter = new ProjectConverter(combo
+          .getSelectedIndex());
+      showConfirmDialog(converter, folder);
     }
   }
 
-  
-  private void showConfirmDialog(int nbFiles, String folder) {
+  private void showConfirmDialog(ProjectConverter converter, File folder) {
     int reponse = JOptionPane.showConfirmDialog(null,
-        "RUNNING CONVERTER WILL REPLACE "+nbFiles+" JAVA FILES INTO "+folder, "CONVERSION CONFIRMATION",
-        JOptionPane.YES_NO_OPTION);
+        "RUNNING CONVERTER WILL REPLACE JAVA FILES INTO " + folder,
+        "CONVERSION CONFIRMATION", JOptionPane.YES_NO_OPTION);
     if (reponse == JOptionPane.YES_OPTION) {
-      converter.convert();
-      showException();
+      converter.convertProject(folder);
+      converter.printException();
     } else {
       dispose();
     }
   }
-  
-  
-  private void showException(){
-    converter.printException();
-  }
-  
-  private class ConverterStream extends PrintStream{
+
+  private class ConverterStream extends PrintStream {
 
     JTextArea console;
-    
+
     public ConverterStream(OutputStream out) {
       super(out);
     }
-    
-    public void setOut(JTextArea console){
+
+    public void setOut(JTextArea console) {
       this.console = console;
     }
-    
-    public void println(String string){
+
+    public void println(String string) {
       console.setText(console.getText() + string + "\n");
     }
   }
-  
 
 }
\ No newline at end of file

Added: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/FileSelector.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/FileSelector.java	Thu Jan 10 21:24:36 2008
@@ -0,0 +1,35 @@
+package org.slf4j.converter;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+public class FileSelector {
+
+  private List<File> javaFileList = new ArrayList<File>();
+
+  public List<File> selectJavaFilesInFolder(File folder) {
+    if(folder.isDirectory()) {
+      selectFiles(folder);
+      return javaFileList;
+    } else {
+      throw new IllegalArgumentException("["+folder+"] is not a directory");
+    }
+  }
+  
+  private void selectFiles(File file) {
+    if (file.isDirectory()) {
+      File[] files = file.listFiles();
+      if (files != null) {
+        for (int i = 0; i < files.length; i++) {
+          selectFiles(files[i]);
+        }
+      }
+    } else {
+      if (file.getName().endsWith(".java")) {
+        javaFileList.add(file);
+      }
+
+    }
+  }
+}

Added: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/InplaceFileConverter.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/InplaceFileConverter.java	Thu Jan 10 21:24:36 2008
@@ -0,0 +1,58 @@
+package org.slf4j.converter;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import org.slf4j.converter.line.LineConverter;
+
+public class InplaceFileConverter {
+
+  
+  final static int BUFFER_LEN = 8 * 1024;
+  final LineConverter lineConverter;
+  final String lineTerminator;
+  
+  InplaceFileConverter(LineConverter lineConverter) {
+    this.lineConverter = lineConverter;
+    lineTerminator = System.getProperty("line.separator");
+  }
+  
+  byte[] readFile(File file) throws IOException {
+    FileInputStream fis = new FileInputStream(file);
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    int n = 0;
+    byte[] buffer = new byte[BUFFER_LEN];
+    while ((n = fis.read(buffer)) != -1) {
+      // System.out.println("ba="+new String(buffer, "UTF-8"));
+      baos.write(buffer, 0, n);
+    }
+    fis.close();
+    return baos.toByteArray();
+
+  }
+  
+  void convert(File file, byte[] input) throws IOException {
+    ByteArrayInputStream bais = new ByteArrayInputStream(input);
+    Reader reader = new InputStreamReader(bais);
+    BufferedReader breader = new BufferedReader(reader);
+    FileWriter fileWriter = new FileWriter(file);
+    while (true) {
+      String line = breader.readLine();
+      if (line != null) {
+        String newLine = lineConverter.getReplacement(line);
+        fileWriter.write(newLine);
+        fileWriter.write(lineTerminator);
+      } else {
+        fileWriter.close();
+        break;
+      }
+    }
+  }
+}

Copied: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ProjectConverter.java (from r936, /slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Converter.java)
==============================================================================
--- /slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Converter.java	(original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ProjectConverter.java	Thu Jan 10 21:24:36 2008
@@ -1,42 +1,22 @@
 package org.slf4j.converter;
 
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileReader;
 import java.io.IOException;
-import java.nio.channels.FileChannel;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
-public class Converter {
+import org.slf4j.converter.line.LineConverter;
+import org.slf4j.converter.line.RuleSet;
 
-  private List<File> javaFiles;
-
-  private AbstractMatcher matcher;
-
-  private Writer writer;
-
-  private File fileSource;
+public class ProjectConverter {
 
+  private LineConverter lineConverter;
   private List<ConversionException> exception;
 
-  /**
-   * Run JCL to SLF4J conversion
-   * 
-   * @param args
-   *          source folder directory optional
-   * @throws IOException
-   * @throws IOException
-   */
   public static void main(String[] args) throws IOException {
 
-    Converter converter = new Converter();
-
-    ConverterFrame frame = new ConverterFrame(converter);
+    ConverterFrame frame = new ConverterFrame();
     frame.setVisible(true);
   }
 
@@ -48,115 +28,32 @@
    * @return true if init operation complete
    * @throws IOException
    */
-  public boolean init(String source, int conversionType) {
-    matcher = AbstractMatcher.getMatcherImpl(conversionType);
-    if (matcher == null) {
+  public ProjectConverter(int conversionType) {
+    RuleSet ruleSet = RuleSetFactory.getMatcherImpl(conversionType);
+    if (ruleSet == null) {
       addException(new ConversionException(ConversionException.NOT_IMPLEMENTED));
-      return false;
-    }
-
-    writer = new Writer(this);
-
-    fileSource = new File(source);
-    if (!fileSource.isDirectory()) {
-      addException(new ConversionException(
-          ConversionException.INVALID_DIRECTORY));
-      return false;
-    } else {
-      return true;
-    }
-  }
-
-  /**
-   * delete a file
-   * 
-   * @param fdest
-   */
-  private void delete(File fdest) {
-    if (fdest.isDirectory()) {
-      File[] files = fdest.listFiles();
-      if (files != null) {
-        for (int i = 0; i < files.length; i++) {
-          delete(files[i]);
-        }
-      }
-      fdest.delete();
-    } else {
-      fdest.delete();
-    }
-  }
-
-  /**
-   * copy a file from source to destination
-   * 
-   * @param fsource
-   * @param fdest
-   */
-  private void copy(File fsource, File fdest) {
-    try {
-      FileInputStream fis = new FileInputStream(fsource);
-      FileOutputStream fos = new FileOutputStream(fdest);
-      FileChannel channelSource = fis.getChannel();
-      FileChannel channelDest = fos.getChannel();
-      if (channelSource.isOpen() && channelDest.isOpen()) {
-        channelSource.transferTo(0, channelSource.size(), channelDest);
-        channelSource.close();
-        channelDest.close();
-      } else {
-        addException(new ConversionException(ConversionException.FILE_COPY,
-            fsource.getAbsolutePath()));
-      }
-
-    } catch (FileNotFoundException exc) {
-      addException(new ConversionException(exc.toString()));
-    } catch (IOException e) {
-      addException(new ConversionException(e.toString()));
     }
+    lineConverter = new LineConverter(ruleSet);
   }
 
-  /**
-   * Select java files to be converted
-   * 
-   * @param file
-   * @return
-   */
-  private List<File> selectFiles(File file) {
-    if (javaFiles == null) {
-      javaFiles = new ArrayList<File>();
-    }
-    if (file.isDirectory()) {
-      File[] files = file.listFiles();
-      if (files != null) {
-        for (int i = 0; i < files.length; i++) {
-          selectFiles(files[i]);
-        }
-      }
-    } else {
-      if (file.getName().endsWith(".java")) {
-        javaFiles.add(file);
-      }
-    }
-    return javaFiles;
-  }
 
-  public void convert() {
-    convert(javaFiles);
+  public void convertProject(File folder) {
+    FileSelector fs = new FileSelector();
+    List<File> fileList = fs.selectJavaFilesInFolder(folder);
+    convertFileList(fileList);
   }
 
-  public int selectFiles() {
-    return selectFiles(fileSource).size();
-  }
 
   /**
    * Convert a list of files
    * 
    * @param lstFiles
    */
-  private void convert(List<File> lstFiles) {
+  private void convertFileList(List<File> lstFiles) {
     Iterator<File> itFile = lstFiles.iterator();
     while (itFile.hasNext()) {
       File currentFile = itFile.next();
-      convert(currentFile);
+      convertFile(currentFile);
     }
   }
 
@@ -166,27 +63,11 @@
    * 
    * @param file
    */
-  private void convert(File file) {
-    File newFile = new File(file.getAbsolutePath() + "new");
+  private void convertFile(File file) {
     try {
-      boolean isEmpty = false;
-      writer.initFileWriter(newFile);
-      FileReader freader = new FileReader(file);
-      BufferedReader breader = new BufferedReader(freader);
-      String line;
-      String newLine;
-      while (!isEmpty) {
-        line = breader.readLine();
-        if (line != null) {
-          newLine = matcher.getReplacement(line);
-          writer.write(newLine);
-        } else {
-          isEmpty = true;
-          writer.closeFileWriter();
-          copy(newFile, file);
-          delete(newFile);
-        }
-      }
+      InplaceFileConverter fc = new InplaceFileConverter(lineConverter);
+      byte[] ba = fc.readFile(file);
+      fc.convert(file, ba);
     } catch (IOException exc) {
       addException(new ConversionException(exc.toString()));
     }

Copied: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/RuleSetFactory.java (from r936, /slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/AbstractMatcher.java)
==============================================================================
--- /slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/AbstractMatcher.java	(original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/RuleSetFactory.java	Thu Jan 10 21:24:36 2008
@@ -1,68 +1,32 @@
 package org.slf4j.converter;
 
-import java.util.Iterator;
-import java.util.ArrayList;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import org.slf4j.converter.line.JCLRuleSet;
+import org.slf4j.converter.line.Log4jRuleSet;
+import org.slf4j.converter.line.RuleSet;
 
 /**
  * This class runs Pattern matching with java.util.regex using Patterns defined
- * in concretes implementations
+ * in concrete implementations
  * 
  * @author jean-noelcharpin
  * 
  */
-public abstract class AbstractMatcher {
+public abstract class RuleSetFactory {
 
-  protected ArrayList<ConversionRule> rules;
-
-  protected boolean blockComment = false;
-
-  public AbstractMatcher() {
-  }
-
-  /**
+   /**
    * Return matcher implementation depending on the conversion mode
    * 
    * @param conversionType
    * @return AbstractMatcher implementation
    */
-  public static AbstractMatcher getMatcherImpl(int conversionType) {
+  public static RuleSet getMatcherImpl(int conversionType) {
     switch (conversionType) {
     case Constant.JCL_TO_SLF4J:
-      return new JCLMatcher();
+      return new JCLRuleSet();
     case Constant.LOG4J_TO_SLF4J:
-      return new Log4jMatcher();
+      return new Log4jRuleSet();
     default:
       return null;
     }
   }
-
-  /**
-   * Check if the specified text is matching some conversions rules If a
-   * rule is resolved, ask for replacement If no rule can be applied the text is
-   * returned without change
-   * 
-   * @param text
-   * @return String
-   */
-  public String getReplacement(String text) {
-    ConversionRule conversionRule;
-    Pattern pattern;
-    Matcher matcher;
-    Iterator rulesIter = rules.iterator();
-    while (rulesIter.hasNext()) {
-      conversionRule = (ConversionRule) rulesIter.next();
-      pattern = conversionRule.getPattern();
-      matcher = pattern.matcher(text);
-      if (matcher.find()) {
-        System.out.println("matching " + text);
-        String replacementText = conversionRule.replace(matcher);
-        text = matcher.replaceAll(replacementText);
-      }
-    }
-    return text;
-  }
-
-  protected abstract void initRules();
 }

Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Writer.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Writer.java	(original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Writer.java	Thu Jan 10 21:24:36 2008
@@ -4,17 +4,16 @@
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.util.regex.Matcher;
 
 public class Writer {
 
-  Converter converter;
-  
+  ProjectConverter converter;
+
   BufferedWriter bwriter;
 
   boolean isFirstLine;
 
-  public Writer(Converter converter) {
+  public Writer(ProjectConverter converter) {
     this.converter = converter;
   }
 
@@ -24,7 +23,8 @@
       bwriter = new BufferedWriter(fileWriter);
       isFirstLine = true;
     } catch (Exception exc) {
-      converter.addException(new ConversionException(exc.toString(),file.getAbsolutePath()));
+      converter.addException(new ConversionException(exc.toString(), file
+          .getAbsolutePath()));
     }
   }
 
@@ -39,22 +39,6 @@
     }
   }
 
-  public void rewrite(Matcher matcher, String replacement) {
-    String text = matcher.replaceAll(replacement);
-    if (bwriter != null) {
-      try {
-        if (!isFirstLine) {
-          bwriter.newLine();
-        } else {
-          isFirstLine = false;
-        }
-        bwriter.write(text);
-      } catch (IOException exc) {
-        converter.addException(new ConversionException(exc.toString()));
-      }
-    }
-  }
-
   public void write(String text) {
     if (bwriter != null) {
       try {

Copied: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/ConversionRule.java (from r936, /slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ConversionRule.java)
==============================================================================
--- /slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ConversionRule.java	(original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/ConversionRule.java	Thu Jan 10 21:24:36 2008
@@ -22,7 +22,7 @@
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
-package org.slf4j.converter;
+package org.slf4j.converter.line;
 
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;

Added: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/JCLRuleSet.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/JCLRuleSet.java	Thu Jan 10 21:24:36 2008
@@ -0,0 +1,56 @@
+package org.slf4j.converter.line;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.regex.Pattern;
+
+
+/**
+ * This class represents JCL to SLF4J conversion rules
+ * 
+ * @author jean-noelcharpin
+ * 
+ */
+public class JCLRuleSet implements RuleSet {
+
+  private ArrayList<ConversionRule> conversionRuleList;
+  
+  public JCLRuleSet() {
+    // matching : import org.apache.commons.logging.LogFactory;
+    SingleConversionRule cr0 = new SingleConversionRule(Pattern
+        .compile("import\\s*+org.apache.commons.logging.LogFactory;"),
+        "import org.slf4j.LoggerFactory;");
+
+    // matching : import org.apache.commons.logging.Log;
+    SingleConversionRule cr1 = new SingleConversionRule(Pattern
+        .compile("import\\s*+org.apache.commons.logging.Log;"), 
+        "import org.slf4j.Logger;");
+    
+    SingleConversionRule cr2 = new SingleConversionRule(Pattern
+        .compile("(\\sLog\\b)")," Logger");
+    
+    SingleConversionRule cr3 = new SingleConversionRule(Pattern
+        .compile("(^Log\\b)"),"Logger");
+    
+    SingleConversionRule cr4 = new SingleConversionRule(Pattern
+        .compile("LogFactory.getFactory\\(\\).getInstance\\("),
+            "LoggerFactory.getLogger(");
+
+    SingleConversionRule cr5 = new SingleConversionRule(Pattern
+        .compile("LogFactory.getLog\\("),"LoggerFactory.getLogger(");
+    
+
+    conversionRuleList = new ArrayList<ConversionRule>();
+    conversionRuleList.add(cr0);
+    conversionRuleList.add(cr1);
+    conversionRuleList.add(cr2);
+    conversionRuleList.add(cr3);
+    conversionRuleList.add(cr4);
+    conversionRuleList.add(cr5);
+  }
+
+
+  public Iterator<ConversionRule> iterator() {
+    return conversionRuleList.iterator();
+  }
+}

Added: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/LineConverter.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/LineConverter.java	Thu Jan 10 21:24:36 2008
@@ -0,0 +1,43 @@
+package org.slf4j.converter.line;
+
+import java.util.Iterator;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+
+public  class LineConverter {
+
+  final RuleSet ruleSet;
+  
+  public LineConverter(RuleSet ruleSet) {
+    this.ruleSet = ruleSet;
+  }
+
+  /**
+   * Check if the specified text is matching some conversions rules. 
+   * If a rule matches, ask for line replacement.
+   * 
+   * <p>In case no rule can be applied, then the input text is
+   * returned without change.
+   * 
+   * @param text
+   * @return String
+   */
+  public String getReplacement(String text) {
+    ConversionRule conversionRule;
+    Pattern pattern;
+    Matcher matcher;
+    Iterator<ConversionRule> conversionRuleIterator = ruleSet.iterator();
+    while (conversionRuleIterator.hasNext()) {
+      conversionRule = conversionRuleIterator.next();
+      pattern = conversionRule.getPattern();
+      matcher = pattern.matcher(text);
+      if (matcher.find()) {
+        System.out.println("matching " + text);
+        String replacementText = conversionRule.replace(matcher);
+        text = matcher.replaceAll(replacementText);
+      }
+    }
+    return text;
+  }
+}

Added: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/Log4jRuleSet.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/Log4jRuleSet.java	Thu Jan 10 21:24:36 2008
@@ -0,0 +1,38 @@
+package org.slf4j.converter.line;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.regex.Pattern;
+
+
+public class Log4jRuleSet implements RuleSet {
+
+  private ArrayList<ConversionRule> conversionRuleList;
+  
+  public Log4jRuleSet() {
+    SingleConversionRule cr0 = new SingleConversionRule(Pattern
+        .compile("import\\s*+org.apache.log4j.LogManager;"),
+        "import org.slf4j.LoggerFactory;");
+
+    SingleConversionRule cr1 = new SingleConversionRule(Pattern
+        .compile("import\\s*+org.apache.log4j.Logger;"),
+        "import org.slf4j.Logger;");
+
+    SingleConversionRule cr2 = new SingleConversionRule(Pattern
+        .compile("Logger.getLogger\\("), "LoggerFactory.getLogger(");
+
+    SingleConversionRule cr3 = new SingleConversionRule(Pattern
+        .compile("LogManager.getLogger\\("), "LoggerFactory.getLogger(");
+
+    conversionRuleList = new ArrayList<ConversionRule>();
+    conversionRuleList.add(cr0);
+    conversionRuleList.add(cr1);
+    conversionRuleList.add(cr2);
+    conversionRuleList.add(cr3);
+  }
+
+  public Iterator<ConversionRule> iterator() {
+    return conversionRuleList.iterator();
+  }
+
+}

Copied: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/MultiGroupConversionRule.java (from r936, /slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/MultiGroupConversionRule.java)
==============================================================================
--- /slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/MultiGroupConversionRule.java	(original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/MultiGroupConversionRule.java	Thu Jan 10 21:24:36 2008
@@ -22,11 +22,12 @@
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
-package org.slf4j.converter;
+package org.slf4j.converter.line;
 
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+
 /**
  * This class represents a conversion rule It uses a Pattern and defines for
  * each capturing group of this Pattern a replacement text

Added: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/RuleSet.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/RuleSet.java	Thu Jan 10 21:24:36 2008
@@ -0,0 +1,10 @@
+package org.slf4j.converter.line;
+
+import java.util.Iterator;
+
+
+public interface RuleSet {
+
+  Iterator<ConversionRule> iterator();
+  
+}

Copied: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/SingleConversionRule.java (from r936, /slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/SingleConversionRule.java)
==============================================================================
--- /slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/SingleConversionRule.java	(original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/SingleConversionRule.java	Thu Jan 10 21:24:36 2008
@@ -22,11 +22,12 @@
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
-package org.slf4j.converter;
+package org.slf4j.converter.line;
 
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+
 /**
  * This class represents a conversion rule It uses a Pattern and defines for
  * each capturing group of this Pattern a replacement text

Modified: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/AllTest.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/AllTest.java	(original)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/AllTest.java	Thu Jan 10 21:24:36 2008
@@ -33,7 +33,8 @@
   public static Test suite() {
     TestSuite suite = new TestSuite();
     suite.addTest(org.slf4j.converter.PackageTest.suite());
-
+    suite.addTest(org.slf4j.converter.line.PackageTest.suite());
+    
     return suite;
   }
 }

Modified: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/AternativeApproach.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/AternativeApproach.java	(original)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/AternativeApproach.java	Thu Jan 10 21:24:36 2008
@@ -3,6 +3,8 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.slf4j.converter.line.MultiGroupConversionRule;
+
 import junit.framework.TestCase;
 
 public class AternativeApproach extends TestCase {

Modified: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/PackageTest.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/PackageTest.java	(original)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/PackageTest.java	Thu Jan 10 21:24:36 2008
@@ -32,11 +32,7 @@
 
   public static Test suite() {
     TestSuite suite = new TestSuite();
-    suite.addTestSuite(TrivialMatcherTest.class);
-    suite.addTestSuite(JCLMatcherTest.class);
     suite.addTestSuite(AternativeApproach.class);
-    suite.addTestSuite(Log4jMatcherTest.class);
-    suite.addTestSuite(NoConversionTest.class);
     return suite;
   }
 }
\ No newline at end of file

Added: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/EmptyRuleSet.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/EmptyRuleSet.java	Thu Jan 10 21:24:36 2008
@@ -0,0 +1,15 @@
+package org.slf4j.converter.line;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class EmptyRuleSet implements RuleSet {
+
+  List<ConversionRule> list = new ArrayList<ConversionRule>();
+  
+  public Iterator<ConversionRule> iterator() {
+    return list.iterator();
+  }
+  
+}

Added: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/JCLRuleSetTest.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/JCLRuleSetTest.java	Thu Jan 10 21:24:36 2008
@@ -0,0 +1,135 @@
+package org.slf4j.converter.line;
+
+import org.slf4j.converter.line.JCLRuleSet;
+import org.slf4j.converter.line.LineConverter;
+
+import junit.framework.TestCase;
+
+public class JCLRuleSetTest extends TestCase {
+
+  LineConverter jclConverter = new LineConverter(new JCLRuleSet());
+  
+  public void testImportReplacement() {
+    // LogFactory import replacement
+    assertEquals("import org.slf4j.LoggerFactory;", jclConverter
+        .getReplacement("import org.apache.commons.logging.LogFactory;"));
+    // Log import replacement
+    assertEquals("import org.slf4j.Logger;", jclConverter
+        .getReplacement("import org.apache.commons.logging.Log;"));
+  }
+
+  public void testLogFactoryGetLogReplacement() {
+    // Logger declaration and instanciation without modifier
+    assertEquals("  Logger   l = LoggerFactory.getLogger(MyClass.class);",
+        jclConverter
+            .getReplacement("  Log   l = LogFactory.getLog(MyClass.class);"));
+    // Logger declaration and instanciation with one modifier
+    assertEquals(
+        "public Logger mylog=LoggerFactory.getLogger(MyClass.class);",
+        jclConverter
+            .getReplacement("public Log mylog=LogFactory.getLog(MyClass.class);"));
+    // Logger declaration and instanciation with two modifier
+    assertEquals(
+        "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
+        jclConverter
+            .getReplacement("public static Log mylog1 = LogFactory.getLog(MyClass.class);"));
+    // Logger declaration and instanciation with two modifier and comment at the
+    // end of line
+    assertEquals(
+        "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class); //logger instanciation and declaration",
+        jclConverter
+            .getReplacement("public static Log mylog1 = LogFactory.getLog(MyClass.class); //logger instanciation and declaration"));
+    // Logger instanciation without declaration and comment at the end of line
+    assertEquals(
+        " myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",
+        jclConverter
+            .getReplacement(" myLog = LogFactory.getLog(MyClass.class);//logger instanciation"));
+    // commented Logger declaration and instanciation with two modifier
+    assertEquals(
+        "//public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
+        jclConverter
+            .getReplacement("//public static Log mylog1 = LogFactory.getLog(MyClass.class);"));
+    // commented Logger instanciation without declaration
+    assertEquals(
+        "// myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",
+        jclConverter
+            .getReplacement("// myLog = LogFactory.getLog(MyClass.class);//logger instanciation"));
+  }
+
+  public void testLogFactoryGetFactoryReplacement() {
+   
+    // Logger declaration and instanciation without modifier
+    assertEquals(
+        "Logger l = LoggerFactory.getLogger(MyClass.class);",
+        jclConverter
+            .getReplacement("Log l = LogFactory.getFactory().getInstance(MyClass.class);"));
+    // Logger declaration and instanciation with one modifier
+    assertEquals(
+        "public Logger mylog=LoggerFactory.getLogger(MyClass.class);",
+        jclConverter
+            .getReplacement("public Log mylog=LogFactory.getFactory().getInstance(MyClass.class);"));
+    // Logger declaration and instanciation with modifiers
+    assertEquals(
+        "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
+        jclConverter
+            .getReplacement("public static Log mylog1 = LogFactory.getFactory().getInstance(MyClass.class);"));
+    // Logger declaration and instanciation with two modifier and comment at the
+    // end of line
+    assertEquals(
+        "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class); //logger instanciation and declaration",
+        jclConverter
+            .getReplacement("public static Log mylog1 = LogFactory.getFactory().getInstance(MyClass.class); //logger instanciation and declaration"));
+    // Logger instanciation without declaration and comment at the end of line
+    assertEquals(
+        " myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",
+        jclConverter
+            .getReplacement(" myLog = LogFactory.getFactory().getInstance(MyClass.class);//logger instanciation"));
+    // commented Logger declaration and instanciation with two modifier
+    assertEquals(
+        "//public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
+        jclConverter
+            .getReplacement("//public static Log mylog1 = LogFactory.getFactory().getInstance(MyClass.class);"));
+    // commented Logger instanciation without declaration
+    assertEquals(
+        "// myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",
+        jclConverter
+            .getReplacement("// myLog = LogFactory.getFactory().getInstance(MyClass.class);//logger instanciation"));
+  }
+
+  public void testLogDeclarationReplacement() {
+   
+    // simple Logger declaration
+    assertEquals("Logger mylog;", jclConverter.getReplacement("Log mylog;"));
+    // Logger declaration with a modifier
+    assertEquals("private Logger mylog;", jclConverter
+        .getReplacement("private Log mylog;"));
+
+    // Logger declaration with modifiers
+    assertEquals("public static final Logger myLog;", jclConverter
+        .getReplacement("public static final Log myLog;"));
+    // Logger declaration with modifiers and comment at the end of line
+    assertEquals("public Logger myLog;//logger declaration", jclConverter
+        .getReplacement("public Log myLog;//logger declaration"));
+    // commented Logger declaration
+    assertEquals("//private Logger myLog;", jclConverter
+        .getReplacement("//private Log myLog;"));
+  }
+
+  public void testMultiLineReplacement() {
+    // Logger declaration on a line
+    assertEquals("protected Logger log =", jclConverter
+        .getReplacement("protected Log log ="));
+
+    // Logger instanciation on the next line
+    assertEquals(" LoggerFactory.getLogger(MyComponent.class);", jclConverter
+        .getReplacement(" LogFactory.getLog(MyComponent.class);"));
+    // Logger declaration on a line
+    assertEquals("protected Logger log ", jclConverter
+        .getReplacement("protected Log log "));
+    // Logger instanciation on the next line
+    assertEquals(
+        " = LoggerFactory.getLogger(MyComponent.class);",
+        jclConverter
+            .getReplacement(" = LogFactory.getFactory().getInstance(MyComponent.class);"));
+  }
+}

Added: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/Log4jRuleSetTest.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/Log4jRuleSetTest.java	Thu Jan 10 21:24:36 2008
@@ -0,0 +1,132 @@
+package org.slf4j.converter.line;
+
+import org.slf4j.converter.line.LineConverter;
+import org.slf4j.converter.line.Log4jRuleSet;
+
+import junit.framework.TestCase;
+
+public class Log4jRuleSetTest extends TestCase {
+
+  LineConverter log4jConverter = new LineConverter(new Log4jRuleSet());
+  
+  public void testImportReplacement() {
+    // LogFactory import replacement
+    assertEquals("import org.slf4j.LoggerFactory;", log4jConverter
+        .getReplacement("import org.apache.log4j.LogManager;"));
+    // Log import replacement
+    assertEquals("import org.slf4j.Logger;", log4jConverter
+        .getReplacement("import org.apache.log4j.Logger;"));
+  }
+
+  public void testLogManagerGetLoggerReplacement() {
+    // Logger declaration and instanciation without modifier
+    assertEquals(" Logger l = LoggerFactory.getLogger(MyClass.class);",
+        log4jConverter
+            .getReplacement(" Logger l = LogManager.getLogger(MyClass.class);"));
+    // Logger declaration and instanciation with one modifier
+    assertEquals(
+        "public Logger mylog=LoggerFactory.getLogger(MyClass.class);",
+        log4jConverter
+            .getReplacement("public Logger mylog=LogManager.getLogger(MyClass.class);"));
+    // Logger declaration and instanciation with two modifier
+    assertEquals(
+        "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
+        log4jConverter
+            .getReplacement("public static Logger mylog1 = LogManager.getLogger(MyClass.class);"));
+    // Logger declaration and instanciation with two modifier and comment at the
+    // end of line
+    assertEquals(
+        "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);//logger instanciation and declaration",
+        log4jConverter
+            .getReplacement("public static Logger mylog1 = LogManager.getLogger(MyClass.class);//logger instanciation and declaration"));
+    // Logger instanciation without declaration and comment at the end of line
+    assertEquals(
+        " myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",
+        log4jConverter
+            .getReplacement(" myLog = LogManager.getLogger(MyClass.class);//logger instanciation"));
+    // commented Logger declaration and instanciation with two modifier
+    assertEquals(
+        "//public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
+        log4jConverter
+            .getReplacement("//public static Logger mylog1 = LogManager.getLogger(MyClass.class);"));
+    // commented Logger instanciation without declaration
+    assertEquals(
+        "// myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",
+        log4jConverter
+            .getReplacement("// myLog = LogManager.getLogger(MyClass.class);//logger instanciation"));
+  }
+
+  public void testLoggerGetLoggerReplacement() {
+    // Logger declaration and instanciation without modifier
+    assertEquals("Logger l = LoggerFactory.getLogger(MyClass.class);",
+        log4jConverter
+            .getReplacement("Logger l = Logger.getLogger(MyClass.class);"));
+    // Logger declaration and instanciation with one modifier
+    assertEquals(
+        "public Logger mylog=LoggerFactory.getLogger(MyClass.class);",
+        log4jConverter
+            .getReplacement("public Logger mylog=Logger.getLogger(MyClass.class);"));
+    // Logger declaration and instanciation with modifiers
+    assertEquals(
+        "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
+        log4jConverter
+            .getReplacement("public static Logger mylog1 = Logger.getLogger(MyClass.class);"));
+    // Logger declaration and instanciation with two modifier and comment at the
+    // end of line
+    assertEquals(
+        "public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class); // logger instanciation and declaration",
+        log4jConverter
+            .getReplacement("public static Logger mylog1 = Logger.getLogger(MyClass.class); // logger instanciation and declaration"));
+    // Logger instanciation without declaration and comment at the end of line
+    assertEquals(
+        " myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",
+        log4jConverter
+            .getReplacement(" myLog = Logger.getLogger(MyClass.class);//logger instanciation"));
+    // commented Logger declaration and instanciation with two modifier
+    assertEquals(
+        "//public static Logger mylog1 = LoggerFactory.getLogger(MyClass.class);",
+        log4jConverter
+            .getReplacement("//public static Logger mylog1 = Logger.getLogger(MyClass.class);"));
+    // commented Logger instanciation without declaration
+    assertEquals(
+        "// myLog = LoggerFactory.getLogger(MyClass.class);//logger instanciation",
+        log4jConverter
+            .getReplacement("// myLog = Logger.getLogger(MyClass.class);//logger instanciation"));
+  }
+
+  public void testLogDeclarationReplacement() {
+    // simple Logger declaration
+    assertEquals("Logger mylog;", log4jConverter.getReplacement("Logger mylog;"));
+    // Logger declaration with a modifier
+    assertEquals("private Logger mylog;", log4jConverter
+        .getReplacement("private Logger mylog;"));
+
+    // Logger declaration with modifiers
+    assertEquals("public static final Logger myLog;", log4jConverter
+        .getReplacement("public static final Logger myLog;"));
+    // Logger declaration with modifiers and comment at the end of line
+    assertEquals("public Logger myLog;//logger declaration", log4jConverter
+        .getReplacement("public Logger myLog;//logger declaration"));
+    // commented Logger declaration
+    assertEquals("//private Logger myLog;", log4jConverter
+        .getReplacement("//private Logger myLog;"));
+  }
+
+  public void testMultiLineReplacement()  {
+   // Logger declaration on a line
+   assertEquals("protected Logger log =", log4jConverter
+   .getReplacement("protected Logger log ="));
+    
+   // Logger instanciation on the next line
+   assertEquals(" LoggerFactory.getLogger(MyComponent.class);", log4jConverter
+   .getReplacement(" LogManager.getLogger(MyComponent.class);"));
+   // Logger declaration on a line
+   assertEquals("protected Logger log ", log4jConverter
+   .getReplacement("protected Logger log "));
+   // Logger instanciation on the next line
+   assertEquals(
+   " = LoggerFactory.getLogger(MyComponent.class);",
+   log4jConverter
+   .getReplacement(" = LogManager.getLogger(MyComponent.class);"));
+   }
+}

Copied: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/NoConversionTest.java (from r936, /slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/NoConversionTest.java)
==============================================================================
--- /slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/NoConversionTest.java	(original)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/NoConversionTest.java	Thu Jan 10 21:24:36 2008
@@ -1,4 +1,8 @@
-package org.slf4j.converter;
+package org.slf4j.converter.line;
+
+import org.slf4j.converter.line.JCLRuleSet;
+import org.slf4j.converter.line.LineConverter;
+import org.slf4j.converter.line.Log4jRuleSet;
 
 import junit.framework.TestCase;
 
@@ -10,22 +14,23 @@
    */
   public void testJclOverLog4jConversion() {
     // running jcl to slf4j conversion
-    JCLMatcher jclMatcher = new JCLMatcher();
+    //JCLMatcher jclMatcher = 
+    LineConverter jclLineConverter = new LineConverter(new JCLRuleSet());
     // no changes on log4j.LogManager import
-    assertEquals("import org.apache.log4j.LogManager;", jclMatcher
+    assertEquals("import org.apache.log4j.LogManager;", jclLineConverter
         .getReplacement("import org.apache.log4j.LogManager;"));
     // no changes on log4j.Logger import
-    assertEquals("import org.apache.log4j.Logger;", jclMatcher
+    assertEquals("import org.apache.log4j.Logger;", jclLineConverter
         .getReplacement("import org.apache.log4j.Logger;"));
     // no changes on Logger instanciation using LogManager
     assertEquals(
         "Logger log = LogManager.getLogger(MyClass.class);",
-        jclMatcher
+        jclLineConverter
             .getReplacement("Logger log = LogManager.getLogger(MyClass.class);"));
     // no changes on Logger instanciation using Logger.getLogger
     assertEquals(
         "public static Logger mylog1 = Logger.getLogger(MyClass.class);",
-        jclMatcher
+        jclLineConverter
             .getReplacement("public static Logger mylog1 = Logger.getLogger(MyClass.class);"));
   }
 
@@ -35,22 +40,23 @@
    */
   public void testLog4jOverJclConversion() {
     // running log4j to slf4j conversion
-    Log4jMatcher log4jMatcher = new Log4jMatcher();
+    LineConverter log4jConverter = new LineConverter(new Log4jRuleSet());
+    
     // no changes on LogFactory import
-    assertEquals("import org.apache.commons.logging.LogFactory;", log4jMatcher
+    assertEquals("import org.apache.commons.logging.LogFactory;", log4jConverter
         .getReplacement("import org.apache.commons.logging.LogFactory;"));
     // no changes on Log import
-    assertEquals("import org.apache.commons.logging.Log;", log4jMatcher
+    assertEquals("import org.apache.commons.logging.Log;", log4jConverter
         .getReplacement("import org.apache.commons.logging.Log;"));
     // no changes on Log instanciation using Logfactory.getLog
     assertEquals(
         "public static Log mylog1 = LogFactory.getLog(MyClass.class);",
-        log4jMatcher
+        log4jConverter
             .getReplacement("public static Log mylog1 = LogFactory.getLog(MyClass.class);"));
     // no changes on log instanciation using LogFactory.getFactory().getInstance
     assertEquals(
         "public Log mylog=LogFactory.getFactory().getInstance(MyClass.class);",
-        log4jMatcher
+        log4jConverter
             .getReplacement("public Log mylog=LogFactory.getFactory().getInstance(MyClass.class);"));
 
   }

Added: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/PackageTest.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/PackageTest.java	Thu Jan 10 21:24:36 2008
@@ -0,0 +1,44 @@
+/* 
+ * Copyright (c) 2004-2007 QOS.ch
+ * All rights reserved.
+ * 
+ * Permission is hereby granted, free  of charge, to any person obtaining
+ * a  copy  of this  software  and  associated  documentation files  (the
+ * "Software"), to  deal in  the Software without  restriction, including
+ * without limitation  the rights to  use, copy, modify,  merge, publish,
+ * distribute,  sublicense, and/or sell  copies of  the Software,  and to
+ * permit persons to whom the Software  is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The  above  copyright  notice  and  this permission  notice  shall  be
+ * included in all copies or substantial portions of the Software.
+ * 
+ * THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
+ * EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
+ * MERCHANTABILITY,    FITNESS    FOR    A   PARTICULAR    PURPOSE    AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package org.slf4j.converter.line;
+
+import org.slf4j.converter.line.JCLRuleSetTest;
+import org.slf4j.converter.line.Log4jRuleSetTest;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class PackageTest extends TestCase {
+
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    suite.addTestSuite(TrivialMatcherTest.class);
+    suite.addTestSuite(JCLRuleSetTest.class);
+    suite.addTestSuite(Log4jRuleSetTest.class);
+    suite.addTestSuite(NoConversionTest.class);
+    return suite;
+  }
+}
\ No newline at end of file

Copied: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/TrivialMatcherTest.java (from r936, /slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/TrivialMatcherTest.java)
==============================================================================
--- /slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/TrivialMatcherTest.java	(original)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/TrivialMatcherTest.java	Thu Jan 10 21:24:36 2008
@@ -1,19 +1,21 @@
-package org.slf4j.converter;
+package org.slf4j.converter.line;
+
+import org.slf4j.converter.line.LineConverter;
 
 import junit.framework.TestCase;
 
 public class TrivialMatcherTest extends TestCase {
 
   public void testSimpleReplacement() {
-    TrivialMatcher trivialMatcher = new TrivialMatcher();
-    trivialMatcher.initRules();
+    LineConverter trivialLC = new LineConverter(new TrivialMatcher());
+
 
     // "import org.slf4j.converter" -- > simple replacement with an unique
     // capturing group
     assertEquals("simple replacement with an unique capturing group",
-        trivialMatcher.getReplacement("import org.slf4j.converter"));
+        trivialLC.getReplacement("import org.slf4j.converter"));
 
-    assertEquals("1st group second group 4th group", trivialMatcher
+    assertEquals("1st group second group 4th group", trivialLC
         .getReplacement("first group second group third group 4th group"));
 
   }

Copied: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/TriviialMatcher.java (from r936, /slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/TriviialMatcher.java)
==============================================================================
--- /slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/TriviialMatcher.java	(original)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/TriviialMatcher.java	Thu Jan 10 21:24:36 2008
@@ -22,14 +22,22 @@
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
-package org.slf4j.converter;
+package org.slf4j.converter.line;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.regex.Pattern;
 
-class TrivialMatcher extends AbstractMatcher{
+import org.slf4j.converter.line.ConversionRule;
+import org.slf4j.converter.line.MultiGroupConversionRule;
+import org.slf4j.converter.line.RuleSet;
+import org.slf4j.converter.line.SingleConversionRule;
+
+class TrivialMatcher implements RuleSet {
  
-  protected void initRules() {
+  private ArrayList<ConversionRule> conversionRuleList;
+  
+  public TrivialMatcher() {
     //simple rule no capturing group is defined, we use default capturing group which is group zero
     SingleConversionRule cr = new SingleConversionRule(Pattern.compile("import org.slf4j.converter"), 
         "simple replacement with an unique capturing group");
@@ -44,9 +52,14 @@
     cr1.addReplacement(3, "");
     //no replacement for the third group it will remains the same
     
-    rules = new ArrayList<ConversionRule>();
-    rules.add(cr);
-    rules.add(cr1);
+    conversionRuleList = new ArrayList<ConversionRule>();
+    conversionRuleList.add(cr);
+    conversionRuleList.add(cr1);
   }
+
+  public Iterator<ConversionRule> iterator() {
+    return conversionRuleList.iterator();
+  }
+  
   
 }
\ No newline at end of file



More information about the slf4j-dev mailing list