[slf4j-dev] svn commit: r862 - slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter

jncharpin at slf4j.org jncharpin at slf4j.org
Fri Aug 3 15:18:22 CEST 2007


Author: jncharpin
Date: Fri Aug  3 15:18:22 2007
New Revision: 862

Modified:
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/AbstractMatcher.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Converter.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Writer.java

Log:
minor changes in paths ans params management.
resolving bug during files copy when source repository contains destination repository.

Modified: 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/AbstractMatcher.java	Fri Aug  3 15:18:22 2007
@@ -58,8 +58,6 @@
 							replacementBuffer.append(replacementText);
 						} 
 						else if (group > 0) {
-						System.out.println("conserving group " + group + " : "
-						 + matcher.group(group));
 						replacementBuffer.append(matcher.group(group));
 						}
 					}

Modified: 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/Converter.java	Fri Aug  3 15:18:22 2007
@@ -12,7 +12,6 @@
 import java.util.List;
 import java.util.ArrayList;
 
-
 public class Converter {
 
 	private List<File> javaFiles;
@@ -24,11 +23,11 @@
 	private String source;
 
 	private String destination;
-	
+
 	private boolean delDestination;
-	
-	private int conversionType; 
-	
+
+	private int conversionType;
+
 	private boolean commentConversion;
 
 	/**
@@ -37,54 +36,58 @@
 	public static void main(String[] args) {
 
 		Converter converter = new Converter();
-		
-		int params = args.length;
-		String param;
-		for(int i=0; i<params; i++){
-			param = args[i];
-			if(param.startsWith("src=")){
-				converter.source = param.substring(4);
-			}
-			else if(param.startsWith("dest=")){
-				converter.destination = param.substring(5);
-			}
-			else if(param.startsWith("del=")){
-				converter.delDestination = Boolean.parseBoolean(param.substring(4));
+
+		if (args.length > 0) {
+			converter.source = args[0];
+			converter.destination = converter.source + "/converted";
+			if (args.length > 1) {
+				converter.destination = args[1];
 			}
-			else if(param.startsWith("all=")){
-				converter.commentConversion = Boolean.parseBoolean(param.substring(4));
+			if (args.length > 2) {
+				converter.delDestination = Boolean.parseBoolean(args[2]);
 			}
+		} else {
+			converter.source = new File("").getAbsolutePath();
+			converter.destination = new File(converter.source + "/converted")
+					.getAbsolutePath();
 		}
-		
+
 		converter.conversionType = Constant.JCL_TO_SLF4J;
-		if(converter.init()){
+		if (converter.init()) {
 			File fileSource = converter.initSource();
 			File fileDest = converter.initDestination();
-			converter.copy(fileSource);
-			converter.selectFiles(fileDest);
-			converter.convert(converter.javaFiles);
+			if (fileSource != null && fileDest != null) {
+				converter.copy(fileSource);
+				converter.selectFiles(fileDest);
+				converter.convert(converter.javaFiles);
+			}
 		}
 	}
 
+	/**
+	 * 
+	 * @return
+	 */
 	public boolean init() {
 		matcher = AbstractMatcher.getMatcherImpl(conversionType);
-		if(matcher==null){
+		if (matcher == null) {
 			return false;
 		}
 		matcher.setCommentConversion(commentConversion);
-		writer = new Writer();		
+		writer = new Writer();
 		return true;
 	}
 
-
 	/**
 	 * 
 	 * @return
 	 */
 	private File initSource() {
+		System.out.println("source " + source);
 		File fileSource = new File(source);
 		if (!fileSource.isDirectory()) {
 			System.out.println("source path is not a valid source directory");
+			return null;
 		}
 		return fileSource;
 	}
@@ -94,11 +97,19 @@
 	 * @return
 	 */
 	private File initDestination() {
+		System.out.println("dest " + destination);
 		File fileDest = new File(destination);
-		if (fileDest.exists() && delDestination) {
-			delete(fileDest);
+		if (!fileDest.isDirectory()) {
+			System.out.println("dest path is not a valid source directory");
+			return null;
+		}
+		if (fileDest.exists()) {
+			if (delDestination) {
+				delete(fileDest);
+			} else {
+				System.out.println("Destination file already exists");
+			}
 		}
-		fileDest.mkdir();
 		return fileDest;
 	}
 
@@ -128,9 +139,10 @@
 		String curentFileName = fsource.getAbsolutePath().substring(
 				source.length());
 		File fdest = new File(destination + "/" + curentFileName);
+		;
 		if (fsource.isDirectory()) {
-			fdest.mkdir();
 			File[] files = fsource.listFiles();
+			fdest.mkdir();
 			if (files != null) {
 				for (int i = 0; i < files.length; i++) {
 					copy(files[i]);
@@ -157,7 +169,8 @@
 				channelSource.close();
 				channelDest.close();
 			} else {
-				System.out.println("error copying file " + fsource.getAbsolutePath());
+				System.out.println("error copying file "
+						+ fsource.getAbsolutePath());
 			}
 
 		} catch (FileNotFoundException exc) {
@@ -202,12 +215,12 @@
 			convert(currentFile);
 		}
 	}
-	
+
 	/**
 	 * 
 	 * @param file
 	 */
-	private void convert(File file){
+	private void convert(File file) {
 		File newFile = new File(file.getAbsolutePath() + "new");
 		try {
 			boolean isEmpty = false;

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	Fri Aug  3 15:18:22 2007
@@ -48,7 +48,7 @@
 					isFirstLine = false;
 				}
 				bwriter.write(text);
-				System.out.println("new entry " + text);
+				//System.out.println("new entry " + text);
 			} catch (IOException exc) {
 				System.out.println("error writing file " + bwriter.toString());
 			}
@@ -64,7 +64,7 @@
 					isFirstLine = false;
 				}
 				bwriter.write(text);
-				System.out.println("new entry " + text);
+				//System.out.println("new entry " + text);
 			} catch (IOException exc) {
 				System.out.println("error writing file " + bwriter.toString());
 			}



More information about the slf4j-dev mailing list