[slf4j-dev] svn commit: r945 - 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
Tue Jan 15 21:07:28 CET 2008
Author: ceki
Date: Tue Jan 15 21:07:27 2008
New Revision: 945
Modified:
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/InplaceFileConverter.java
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ProjectConverter.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/test/java/org/slf4j/converter/FileConverterTest.java
slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/ProjectConverterTest.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
slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/TrivialMatcherTest.java
Log:
- We now avoid touching files that do not need converting to SLF4J.
- All tests pass
Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/InplaceFileConverter.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/InplaceFileConverter.java (original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/InplaceFileConverter.java Tue Jan 15 21:07:27 2008
@@ -5,13 +5,14 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.io.Reader;
-import java.io.Writer;
import org.slf4j.converter.line.LineConverter;
+import org.slf4j.converter.line.RuleSet;
public class InplaceFileConverter {
@@ -19,12 +20,12 @@
final LineConverter lineConverter;
final String lineTerminator;
- InplaceFileConverter(LineConverter lineConverter) {
- this.lineConverter = lineConverter;
+ InplaceFileConverter(RuleSet ruleSet) {
+ this.lineConverter = new LineConverter(ruleSet);
lineTerminator = System.getProperty("line.separator");
}
- byte[] readFile(File file) throws IOException {
+ private byte[] readIntoByteArray(File file) throws IOException {
FileInputStream fis = new FileInputStream(file);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int n = 0;
@@ -35,30 +36,48 @@
}
fis.close();
return baos.toByteArray();
+ }
+
+ void convert(File file) throws IOException {
+ byte[] originalBytes = readIntoByteArray(file);
+ byte[] convertedBytes = convertIntoTempByteArray(originalBytes);
+ if (lineConverter.atLeastOneMatchOccured()) {
+ System.out.println("Converting ["+file+"]");
+ writeConvertedBytesIntoFile(file, convertedBytes);
+ } else {
+ System.out.println("Not replacing ["+file+"]");
+ }
+ }
+ private void writeConvertedBytesIntoFile(File file, byte[] convertedBytes) throws IOException {
+ FileOutputStream fos = new FileOutputStream(file);
+ fos.write(convertedBytes);
+ fos.flush();
+ fos.close();
}
- void convert(File file, byte[] input) throws IOException {
+ private byte[] convertIntoTempByteArray(byte[] input) throws IOException {
ByteArrayInputStream bais = new ByteArrayInputStream(input);
Reader reader = new InputStreamReader(bais);
BufferedReader breader = new BufferedReader(reader);
- FileWriter fileWriter = new FileWriter(file);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
while (true) {
String line = breader.readLine();
if (line != null) {
String[] replacement = lineConverter.getReplacement(line);
- writeReplacement(fileWriter, replacement);
+ writeReplacement(baos, replacement);
} else {
- fileWriter.close();
break;
}
}
+ return baos.toByteArray();
}
- void writeReplacement(Writer writer, String[] replacement) throws IOException {
+ private void writeReplacement(OutputStream os, String[] replacement)
+ throws IOException {
for (int i = 0; i < replacement.length; i++) {
- writer.write(replacement[i]);
- writer.write(lineTerminator);
+ os.write(replacement[i].getBytes());
+ os.write(lineTerminator.getBytes());
}
}
}
Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ProjectConverter.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ProjectConverter.java (original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/ProjectConverter.java Tue Jan 15 21:07:27 2008
@@ -6,12 +6,11 @@
import java.util.Iterator;
import java.util.List;
-import org.slf4j.converter.line.LineConverter;
import org.slf4j.converter.line.RuleSet;
public class ProjectConverter {
- private LineConverter lineConverter;
+ private RuleSet ruleSet;
private List<ConversionException> exception;
public static void main(String[] args) throws IOException {
@@ -29,11 +28,10 @@
* @throws IOException
*/
public ProjectConverter(int conversionType) {
- RuleSet ruleSet = RuleSetFactory.getMatcherImpl(conversionType);
+ ruleSet = RuleSetFactory.getMatcherImpl(conversionType);
if (ruleSet == null) {
addException(new ConversionException(ConversionException.NOT_IMPLEMENTED));
}
- lineConverter = new LineConverter(ruleSet);
}
@@ -65,9 +63,8 @@
*/
private void convertFile(File file) {
try {
- InplaceFileConverter fc = new InplaceFileConverter(lineConverter);
- byte[] ba = fc.readFile(file);
- fc.convert(file, ba);
+ InplaceFileConverter fc = new InplaceFileConverter(ruleSet);
+ fc.convert(file);
} catch (IOException exc) {
addException(new ConversionException(exc.toString()));
}
Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/LineConverter.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/LineConverter.java (original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/LineConverter.java Tue Jan 15 21:07:27 2008
@@ -1,13 +1,15 @@
package org.slf4j.converter.line;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-public class LineConverter {
+public class LineConverter {
final RuleSet ruleSet;
+ boolean atLeastOneMatchOccured = false;
public LineConverter(RuleSet ruleSet) {
this.ruleSet = ruleSet;
@@ -34,7 +36,8 @@
pattern = conversionRule.getPattern();
matcher = pattern.matcher(text);
if (matcher.find()) {
- System.out.println("matching " + text);
+ // System.out.println("matching " + text);
+ atLeastOneMatchOccured = true;
String replacementText = conversionRule.replace(matcher);
text = matcher.replaceAll(replacementText);
if(conversionRule.getAdditionalLine() != null) {
@@ -49,4 +52,16 @@
return new String[] {text, additionalLine};
}
}
+
+ public String getOneLineReplacement(String text) {
+ String[] r = getReplacement(text);
+ if(r.length != 1) {
+ throw new IllegalStateException("Expecting a single string but got "+Arrays.toString(r));
+ } else {
+ return r[0];
+ }
+ }
+ public boolean atLeastOneMatchOccured() {
+ return atLeastOneMatchOccured;
+ }
}
Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/Log4jRuleSet.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/Log4jRuleSet.java (original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/Log4jRuleSet.java Tue Jan 15 21:07:27 2008
@@ -11,28 +11,39 @@
public Log4jRuleSet() {
- SingleConversionRule cr0 = new SingleConversionRule(Pattern
+
+ SingleConversionRule crImport0 = new SingleConversionRule(Pattern
.compile("import\\s*+org.apache.log4j.Logger;"),
"import org.slf4j.Logger;",
"import org.slf4j.LoggerFactory;");
- SingleConversionRule cr1 = new SingleConversionRule(Pattern
+ SingleConversionRule crImport1 = new SingleConversionRule(Pattern
.compile("import\\s*+org.apache.log4j.LogManager;"),
"import org.slf4j.LoggerFactory;");
+ SingleConversionRule crImport2 = new SingleConversionRule(Pattern
+ .compile("import\\s*+org.apache.log4j.*;"),
+ "import org.slf4j.Logger;",
+ "import org.slf4j.LoggerFactory;");
+
+ SingleConversionRule crImportMDC = new SingleConversionRule(Pattern
+ .compile("import\\s*+org.apache.log4j.MDC;"),
+ "import org.slf4j.MDC;");
- SingleConversionRule cr2 = new SingleConversionRule(Pattern
+ SingleConversionRule crFactory0 = new SingleConversionRule(Pattern
.compile("Logger.getLogger\\("), "LoggerFactory.getLogger(");
- SingleConversionRule cr3 = new SingleConversionRule(Pattern
+ SingleConversionRule crFactory1 = new SingleConversionRule(Pattern
.compile("LogManager.getLogger\\("), "LoggerFactory.getLogger(");
conversionRuleList = new ArrayList<ConversionRule>();
- conversionRuleList.add(cr0);
- conversionRuleList.add(cr1);
- conversionRuleList.add(cr2);
- conversionRuleList.add(cr3);
+ conversionRuleList.add(crImport0);
+ conversionRuleList.add(crImport1);
+ conversionRuleList.add(crImport2);
+ conversionRuleList.add(crImportMDC);
+ conversionRuleList.add(crFactory0);
+ conversionRuleList.add(crFactory1);
}
public Iterator<ConversionRule> iterator() {
Modified: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/FileConverterTest.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/FileConverterTest.java (original)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/FileConverterTest.java Tue Jan 15 21:07:27 2008
@@ -6,7 +6,6 @@
import junit.framework.TestCase;
import org.slf4j.converter.line.EmptyRuleSet;
-import org.slf4j.converter.line.LineConverter;
public class FileConverterTest extends TestCase {
@@ -27,8 +26,7 @@
public void XtestNOP() throws IOException {
- InplaceFileConverter fc = new InplaceFileConverter(new LineConverter(new EmptyRuleSet()));
- byte[] ba = fc.readFile(new File("c:/varargs.txt"));
- fc.convert(new File("c:/varargs.txt"), ba);
+ InplaceFileConverter fc = new InplaceFileConverter(new EmptyRuleSet());
+ fc.convert(new File("c:/varargs.txt"));
}
}
Modified: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/ProjectConverterTest.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/ProjectConverterTest.java (original)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/ProjectConverterTest.java Tue Jan 15 21:07:27 2008
@@ -1,7 +1,6 @@
package org.slf4j.converter;
import java.io.File;
-import java.util.List;
import junit.framework.TestCase;
@@ -11,17 +10,9 @@
public void test() {
}
- public void Xtest() {
- ProjectConverter pc = new ProjectConverter(Constant.JCL_TO_SLF4J);
-
- File projectFolder = new File("c:/home/ceki//Varia/vfs");
- FileSelector fs = new FileSelector();
- List<File> fileList = fs.selectJavaFilesInFolder(projectFolder);
-
- for(File f : fileList) {
- System.out.println(f);
- }
- System.out.println(fileList.size());
+ public void testBarracuda() {
+ ProjectConverter pc = new ProjectConverter(Constant.LOG4J_TO_SLF4J);
+ File projectFolder = new File("c:/home/ceki//Varia/Barracuda");
pc.convertProject(projectFolder);
}
}
Modified: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/JCLRuleSetTest.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/JCLRuleSetTest.java (original)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/JCLRuleSetTest.java Tue Jan 15 21:07:27 2008
@@ -12,48 +12,48 @@
public void testImportReplacement() {
// LogFactory import replacement
assertEquals("import org.slf4j.LoggerFactory;", jclConverter
- .getReplacement("import org.apache.commons.logging.LogFactory;"));
+ .getOneLineReplacement("import org.apache.commons.logging.LogFactory;"));
// Log import replacement
assertEquals("import org.slf4j.Logger;", jclConverter
- .getReplacement("import org.apache.commons.logging.Log;"));
+ .getOneLineReplacement("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);"));
+ .getOneLineReplacement(" 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);"));
+ .getOneLineReplacement("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);"));
+ .getOneLineReplacement("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"));
+ .getOneLineReplacement("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"));
+ .getOneLineReplacement(" 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);"));
+ .getOneLineReplacement("//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"));
+ .getOneLineReplacement("// myLog = LogFactory.getLog(MyClass.class);//logger instanciation"));
}
public void testLogFactoryGetFactoryReplacement() {
@@ -62,74 +62,74 @@
assertEquals(
"Logger l = LoggerFactory.getLogger(MyClass.class);",
jclConverter
- .getReplacement("Log l = LogFactory.getFactory().getInstance(MyClass.class);"));
+ .getOneLineReplacement("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);"));
+ .getOneLineReplacement("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);"));
+ .getOneLineReplacement("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"));
+ .getOneLineReplacement("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"));
+ .getOneLineReplacement(" 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);"));
+ .getOneLineReplacement("//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"));
+ .getOneLineReplacement("// myLog = LogFactory.getFactory().getInstance(MyClass.class);//logger instanciation"));
}
public void testLogDeclarationReplacement() {
// simple Logger declaration
- assertEquals("Logger mylog;", jclConverter.getReplacement("Log mylog;"));
+ assertEquals("Logger mylog;", jclConverter.getOneLineReplacement("Log mylog;"));
// Logger declaration with a modifier
assertEquals("private Logger mylog;", jclConverter
- .getReplacement("private Log mylog;"));
+ .getOneLineReplacement("private Log mylog;"));
// Logger declaration with modifiers
assertEquals("public static final Logger myLog;", jclConverter
- .getReplacement("public static final Log myLog;"));
+ .getOneLineReplacement("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"));
+ .getOneLineReplacement("public Log myLog;//logger declaration"));
// commented Logger declaration
assertEquals("//private Logger myLog;", jclConverter
- .getReplacement("//private Log myLog;"));
+ .getOneLineReplacement("//private Log myLog;"));
}
public void testMultiLineReplacement() {
// Logger declaration on a line
assertEquals("protected Logger log =", jclConverter
- .getReplacement("protected Log log ="));
+ .getOneLineReplacement("protected Log log ="));
// Logger instanciation on the next line
assertEquals(" LoggerFactory.getLogger(MyComponent.class);", jclConverter
- .getReplacement(" LogFactory.getLog(MyComponent.class);"));
+ .getOneLineReplacement(" LogFactory.getLog(MyComponent.class);"));
// Logger declaration on a line
assertEquals("protected Logger log ", jclConverter
- .getReplacement("protected Log log "));
+ .getOneLineReplacement("protected Log log "));
// Logger instanciation on the next line
assertEquals(
" = LoggerFactory.getLogger(MyComponent.class);",
jclConverter
- .getReplacement(" = LogFactory.getFactory().getInstance(MyComponent.class);"));
+ .getOneLineReplacement(" = LogFactory.getFactory().getInstance(MyComponent.class);"));
}
}
Modified: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/Log4jRuleSetTest.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/Log4jRuleSetTest.java (original)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/Log4jRuleSetTest.java Tue Jan 15 21:07:27 2008
@@ -1,5 +1,7 @@
package org.slf4j.converter.line;
+import java.util.Arrays;
+
import org.slf4j.converter.line.LineConverter;
import org.slf4j.converter.line.Log4jRuleSet;
@@ -12,121 +14,122 @@
public void testImportReplacement() {
// LogFactory import replacement
assertEquals("import org.slf4j.LoggerFactory;", log4jConverter
- .getReplacement("import org.apache.log4j.LogManager;"));
+ .getOneLineReplacement("import org.apache.log4j.LogManager;"));
// Log import replacement
- assertEquals("import org.slf4j.Logger;", log4jConverter
- .getReplacement("import org.apache.log4j.Logger;"));
+ assertTrue(Arrays.equals(
+ new String[] {"import org.slf4j.Logger;", "import org.slf4j.LoggerFactory;" },
+ 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);"));
+ .getOneLineReplacement(" 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);"));
+ .getOneLineReplacement("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);"));
+ .getOneLineReplacement("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"));
+ .getOneLineReplacement("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"));
+ .getOneLineReplacement(" 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);"));
+ .getOneLineReplacement("//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"));
+ .getOneLineReplacement("// 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);"));
+ .getOneLineReplacement("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);"));
+ .getOneLineReplacement("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);"));
+ .getOneLineReplacement("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"));
+ .getOneLineReplacement("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"));
+ .getOneLineReplacement(" 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);"));
+ .getOneLineReplacement("//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"));
+ .getOneLineReplacement("// myLog = Logger.getLogger(MyClass.class);//logger instanciation"));
}
public void testLogDeclarationReplacement() {
// simple Logger declaration
- assertEquals("Logger mylog;", log4jConverter.getReplacement("Logger mylog;"));
+ assertEquals("Logger mylog;", log4jConverter.getOneLineReplacement("Logger mylog;"));
// Logger declaration with a modifier
assertEquals("private Logger mylog;", log4jConverter
- .getReplacement("private Logger mylog;"));
+ .getOneLineReplacement("private Logger mylog;"));
// Logger declaration with modifiers
assertEquals("public static final Logger myLog;", log4jConverter
- .getReplacement("public static final Logger myLog;"));
+ .getOneLineReplacement("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"));
+ .getOneLineReplacement("public Logger myLog;//logger declaration"));
// commented Logger declaration
assertEquals("//private Logger myLog;", log4jConverter
- .getReplacement("//private Logger myLog;"));
+ .getOneLineReplacement("//private Logger myLog;"));
}
public void testMultiLineReplacement() {
// Logger declaration on a line
assertEquals("protected Logger log =", log4jConverter
- .getReplacement("protected Logger log ="));
+ .getOneLineReplacement("protected Logger log ="));
// Logger instanciation on the next line
assertEquals(" LoggerFactory.getLogger(MyComponent.class);", log4jConverter
- .getReplacement(" LogManager.getLogger(MyComponent.class);"));
+ .getOneLineReplacement(" LogManager.getLogger(MyComponent.class);"));
// Logger declaration on a line
assertEquals("protected Logger log ", log4jConverter
- .getReplacement("protected Logger log "));
+ .getOneLineReplacement("protected Logger log "));
// Logger instanciation on the next line
assertEquals(
" = LoggerFactory.getLogger(MyComponent.class);",
log4jConverter
- .getReplacement(" = LogManager.getLogger(MyComponent.class);"));
+ .getOneLineReplacement(" = LogManager.getLogger(MyComponent.class);"));
}
}
Modified: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/NoConversionTest.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/NoConversionTest.java (original)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/NoConversionTest.java Tue Jan 15 21:07:27 2008
@@ -18,20 +18,20 @@
LineConverter jclLineConverter = new LineConverter(new JCLRuleSet());
// no changes on log4j.LogManager import
assertEquals("import org.apache.log4j.LogManager;", jclLineConverter
- .getReplacement("import org.apache.log4j.LogManager;"));
+ .getOneLineReplacement("import org.apache.log4j.LogManager;"));
// no changes on log4j.Logger import
assertEquals("import org.apache.log4j.Logger;", jclLineConverter
- .getReplacement("import org.apache.log4j.Logger;"));
+ .getOneLineReplacement("import org.apache.log4j.Logger;"));
// no changes on Logger instanciation using LogManager
assertEquals(
"Logger log = LogManager.getLogger(MyClass.class);",
jclLineConverter
- .getReplacement("Logger log = LogManager.getLogger(MyClass.class);"));
+ .getOneLineReplacement("Logger log = LogManager.getLogger(MyClass.class);"));
// no changes on Logger instanciation using Logger.getLogger
assertEquals(
"public static Logger mylog1 = Logger.getLogger(MyClass.class);",
jclLineConverter
- .getReplacement("public static Logger mylog1 = Logger.getLogger(MyClass.class);"));
+ .getOneLineReplacement("public static Logger mylog1 = Logger.getLogger(MyClass.class);"));
}
/**
@@ -44,20 +44,20 @@
// no changes on LogFactory import
assertEquals("import org.apache.commons.logging.LogFactory;", log4jConverter
- .getReplacement("import org.apache.commons.logging.LogFactory;"));
+ .getOneLineReplacement("import org.apache.commons.logging.LogFactory;"));
// no changes on Log import
assertEquals("import org.apache.commons.logging.Log;", log4jConverter
- .getReplacement("import org.apache.commons.logging.Log;"));
+ .getOneLineReplacement("import org.apache.commons.logging.Log;"));
// no changes on Log instanciation using Logfactory.getLog
assertEquals(
"public static Log mylog1 = LogFactory.getLog(MyClass.class);",
log4jConverter
- .getReplacement("public static Log mylog1 = LogFactory.getLog(MyClass.class);"));
+ .getOneLineReplacement("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);",
log4jConverter
- .getReplacement("public Log mylog=LogFactory.getFactory().getInstance(MyClass.class);"));
+ .getOneLineReplacement("public Log mylog=LogFactory.getFactory().getInstance(MyClass.class);"));
}
}
Modified: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/TrivialMatcherTest.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/TrivialMatcherTest.java (original)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/TrivialMatcherTest.java Tue Jan 15 21:07:27 2008
@@ -13,10 +13,10 @@
// "import org.slf4j.converter" -- > simple replacement with an unique
// capturing group
assertEquals("simple replacement with an unique capturing group",
- trivialLC.getReplacement("import org.slf4j.converter"));
+ trivialLC.getOneLineReplacement("import org.slf4j.converter"));
assertEquals("1st group second group 4th group", trivialLC
- .getReplacement("first group second group third group 4th group"));
+ .getOneLineReplacement("first group second group third group 4th group"));
}
More information about the slf4j-dev
mailing list