[slf4j-dev] svn commit: r972 - in slf4j/trunk/slf4j-converter/src: main/java/org/slf4j/converter main/java/org/slf4j/converter/internal main/java/org/slf4j/converter/line test/java/org/slf4j/converter test/java/org/slf4j/converter/internal test/java/org/slf4j/converter/line
ceki at slf4j.org
ceki at slf4j.org
Wed Feb 20 21:33:14 CET 2008
Author: ceki
Date: Wed Feb 20 21:33:14 2008
New Revision: 972
Added:
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/internal/ConversionTask.java
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/internal/MigratorFrame.java
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/internal/ProgressListenerImpl.java
- copied, changed from r971, /slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/internal/ProgressLinstenerImpl.java
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/line/EmptyRuleSet.java
- copied unchanged from r970, /slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/EmptyRuleSet.java
Removed:
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/NewJFrame.java
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/XSelector.java
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/internal/ProgressLinstenerImpl.java
slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/line/EmptyRuleSet.java
Modified:
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Constant.java
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
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/RuleSetFactory.java
slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/internal/ProgressListener.java
slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/FileConverterTest.java
slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/internal/NopProgressListener.java
Log:
- added progress bar and other goodies to the migration tool
Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Constant.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Constant.java (original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Constant.java Wed Feb 20 21:33:14 2008
@@ -3,8 +3,8 @@
public class Constant {
public final static int JCL_TO_SLF4J = 0;
-
public final static int LOG4J_TO_SLF4J = 1;
+ public final static int EMPTY_RULE_SET = 2;
public final static int NB_FILES_MAX = 1;
Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/FileSelector.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/FileSelector.java (original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/FileSelector.java Wed Feb 20 21:33:14 2008
@@ -11,22 +11,23 @@
private List<File> javaFileList = new ArrayList<File>();
ProgressListener pl;
-
+
FileSelector(ProgressListener pl) {
this.pl = pl;
}
-
+
public List<File> selectJavaFilesInFolder(File folder) {
- if(folder.isDirectory()) {
+ if (folder.isDirectory()) {
selectFiles(folder);
return javaFileList;
} else {
- throw new IllegalArgumentException("["+folder+"] is not a directory");
+ throw new IllegalArgumentException("[" + folder + "] is not a directory");
}
}
-
+
private void selectFiles(File file) {
if (file.isDirectory()) {
+ pl.onDirectory(file);
File[] files = file.listFiles();
if (files != null) {
for (int i = 0; i < files.length; i++) {
@@ -35,6 +36,7 @@
}
} else {
if (file.getName().endsWith(".java")) {
+ pl.onFileAddition(file);
javaFileList.add(file);
}
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 Wed Feb 20 21:33:14 2008
@@ -11,6 +11,7 @@
import java.io.OutputStream;
import java.io.Reader;
+import org.slf4j.converter.internal.ProgressListener;
import org.slf4j.converter.line.LineConverter;
import org.slf4j.converter.line.RuleSet;
@@ -19,10 +20,12 @@
final static int BUFFER_LEN = 8 * 1024;
final LineConverter lineConverter;
final String lineTerminator;
-
- InplaceFileConverter(RuleSet ruleSet) {
+ final ProgressListener pl;
+
+ InplaceFileConverter(RuleSet ruleSet, ProgressListener pl) {
this.lineConverter = new LineConverter(ruleSet);
lineTerminator = System.getProperty("line.separator");
+ this.pl = pl;
}
private byte[] readIntoByteArray(File file) throws IOException {
@@ -42,10 +45,11 @@
byte[] originalBytes = readIntoByteArray(file);
byte[] convertedBytes = convertIntoTempByteArray(originalBytes);
if (lineConverter.atLeastOneMatchOccured()) {
- System.out.println("Converting ["+file+"]");
+ //System.out.println("Converting ["+file+"]");
writeConvertedBytesIntoFile(file, convertedBytes);
+ pl.onInplaceConversion(file);
} else {
- System.out.println("Not touching ["+file+"]");
+ //System.out.println("Not touching ["+file+"]");
}
}
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 Wed Feb 20 21:33:14 2008
@@ -66,7 +66,8 @@
public void convertProject(File folder) {
FileSelector fs = new FileSelector(progressListener);
List<File> fileList = fs.selectJavaFilesInFolder(folder);
- convertFileList(fileList);
+ scanFileList(fileList);
+ progressListener.onDone();
}
@@ -75,11 +76,13 @@
*
* @param lstFiles
*/
- private void convertFileList(List<File> lstFiles) {
+ private void scanFileList(List<File> lstFiles) {
+ progressListener.onFileScanBegin();
Iterator<File> itFile = lstFiles.iterator();
while (itFile.hasNext()) {
File currentFile = itFile.next();
- convertFile(currentFile);
+ progressListener.onFileScan(currentFile);
+ scanFile(currentFile);
}
}
@@ -89,9 +92,9 @@
*
* @param file
*/
- private void convertFile(File file) {
+ private void scanFile(File file) {
try {
- InplaceFileConverter fc = new InplaceFileConverter(ruleSet);
+ InplaceFileConverter fc = new InplaceFileConverter(ruleSet, progressListener);
fc.convert(file);
} catch (IOException exc) {
addException(new ConversionException(exc.toString()));
Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/RuleSetFactory.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/RuleSetFactory.java (original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/RuleSetFactory.java Wed Feb 20 21:33:14 2008
@@ -1,5 +1,6 @@
package org.slf4j.converter;
+import org.slf4j.converter.line.EmptyRuleSet;
import org.slf4j.converter.line.JCLRuleSet;
import org.slf4j.converter.line.Log4jRuleSet;
import org.slf4j.converter.line.RuleSet;
@@ -25,6 +26,8 @@
return new JCLRuleSet();
case Constant.LOG4J_TO_SLF4J:
return new Log4jRuleSet();
+ case Constant.EMPTY_RULE_SET:
+ return new EmptyRuleSet();
default:
return null;
}
Added: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/internal/ConversionTask.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/internal/ConversionTask.java Wed Feb 20 21:33:14 2008
@@ -0,0 +1,33 @@
+package org.slf4j.converter.internal;
+
+import java.io.File;
+
+import org.slf4j.converter.ProjectConverter;
+
+public class ConversionTask implements Runnable {
+
+ final File folder;
+ final MigratorFrame frame;
+ final int conversionType;
+
+
+ ConversionTask(File folder, MigratorFrame frame, int conversionType) {
+ this.folder = folder;
+ this.frame = frame;
+ this.conversionType = conversionType;
+ }
+
+ public void run() {
+ ProgressListener pl = new ProgressListenerImpl(folder, frame);
+ pl.onMigrationBegin();
+ ProjectConverter converter = new ProjectConverter(conversionType, pl);
+ converter.convertProject(folder);
+ }
+
+ public void launch() {
+ Thread t = new Thread(this);
+ t.setDaemon(true);
+ t.start();
+ }
+
+}
Added: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/internal/MigratorFrame.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/internal/MigratorFrame.java Wed Feb 20 21:33:14 2008
@@ -0,0 +1,354 @@
+package org.slf4j.converter.internal;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.ButtonGroup;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JFileChooser;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JProgressBar;
+import javax.swing.JRadioButton;
+import javax.swing.JTextField;
+import javax.swing.SpringLayout;
+import javax.swing.SwingUtilities;
+import javax.swing.WindowConstants;
+
+import org.slf4j.converter.Constant;
+import org.slf4j.converter.helper.SpringLayoutHelper;
+
+/**
+ * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
+ * Builder, which is free for non-commercial use. If Jigloo is being used
+ * commercially (ie, by a corporation, company or business for any purpose
+ * whatever) then you should purchase a license for each developer using Jigloo.
+ * Please visit www.cloudgarden.com for details. Use of Jigloo implies
+ * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
+ * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
+ * ANY CORPORATE OR COMMERCIAL PURPOSE.
+ */
+public class MigratorFrame extends JFrame implements ActionListener {
+ private static final long serialVersionUID = 1L;
+
+ private static final int BASIC_PADDING = 10;
+ private static final int FOLDER_COLUMNS = 40;
+ private static final String MIGRATE_COMMAND = "MIGRATE_COMMAND";
+ private static final String BROWSE_COMMAND = "BROWSE_COMMAND";
+
+ static final int X_SIZE = 700;
+ static final int Y_SIZE = 400;
+
+ private SpringLayout layoutManager = new SpringLayout();
+ private SpringLayoutHelper slh = new SpringLayoutHelper(layoutManager,
+ BASIC_PADDING);
+
+ private JLabel migrationLabel;
+
+ private JRadioButton radioLog4j;
+ private JRadioButton radioJCL;
+ private ButtonGroup buttonGroup;
+
+ private JTextField folderTextField;
+ private JLabel warningLabel;
+ private JButton migrateButton;
+ private JButton browseButton;
+ private JLabel folderLabel;
+
+ private JCheckBox awareCheckBox;
+ private JLabel awareLabel;
+
+ JLabel otherLabel;
+ JProgressBar progressBar;
+ private JFileChooser fileChooser;
+
+ public static void main(String[] args) {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ MigratorFrame inst = new MigratorFrame();
+ inst.setLocationRelativeTo(null);
+ inst.setVisible(true);
+ }
+ });
+ }
+
+ public MigratorFrame() {
+ super();
+ initGUI();
+ }
+
+
+
+ private void initGUI() {
+ try {
+ setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+ getContentPane().setLayout(layoutManager);
+ this.setTitle("SLF4J migrator");
+
+ createComponents();
+ constrainAll();
+ addAllComponentsToContextPane();
+ pack();
+ this.setSize(700, 400);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void createComponents() {
+ createMigrationLabel();
+ createRadioJCL();
+ createRadioLog4j();
+ createButtonGroup();
+ createFolderLabel();
+ createFolderTextField();
+ createBrowseButton();
+ createMigrateButton();
+ createAwareCheckbox();
+ createAwareLabel();
+ createWarningLabel();
+ createFileChooser();
+
+ otherLabel = new JLabel();
+ otherLabel.setText("");
+ createProgressBar();
+
+ }
+
+ /**
+ *
+ */
+ private void constrainAll() {
+
+ // contrain migration label
+ layoutManager.putConstraint(SpringLayout.WEST, migrationLabel,
+ BASIC_PADDING, SpringLayout.EAST, this);
+
+ layoutManager.putConstraint(SpringLayout.NORTH, migrationLabel,
+ BASIC_PADDING, SpringLayout.NORTH, this);
+
+ slh.placeToTheRight(migrationLabel, radioJCL, BASIC_PADDING,
+ -BASIC_PADDING / 2);
+ slh.placeBelow(radioJCL, radioLog4j, 0, 0);
+
+ slh.placeBelow(migrationLabel, folderLabel, 0, BASIC_PADDING * 5);
+ slh.placeToTheRight(folderLabel, folderTextField);
+ slh.placeToTheRight(folderTextField, browseButton, BASIC_PADDING, - BASIC_PADDING/2);
+
+ slh.placeBelow(folderLabel, warningLabel, 0, BASIC_PADDING * 3);
+
+ slh.placeBelow(warningLabel, awareCheckBox, 0, (int) (BASIC_PADDING * 1.5));
+ slh.placeToTheRight(awareCheckBox, awareLabel);
+
+ slh.placeBelow(awareCheckBox, migrateButton, 0, BASIC_PADDING * 3);
+
+ slh.placeBelow(migrateButton, otherLabel, 0, BASIC_PADDING * 2);
+
+
+ slh.placeBelow(otherLabel, progressBar, 0, BASIC_PADDING * 2);
+ }
+
+ private void addAllComponentsToContextPane() {
+ getContentPane().add(migrationLabel);
+ getContentPane().add(radioJCL);
+ getContentPane().add(radioLog4j);
+
+ getContentPane().add(folderLabel);
+ getContentPane().add(folderTextField);
+ getContentPane().add(browseButton);
+ getContentPane().add(migrateButton);
+
+ getContentPane().add(awareCheckBox);
+ getContentPane().add(awareLabel);
+
+ getContentPane().add(warningLabel);
+
+ getContentPane().add(otherLabel);
+ getContentPane().add(progressBar);
+ }
+
+ private void createButtonGroup() {
+ buttonGroup = new ButtonGroup();
+ buttonGroup.add(radioJCL);
+ buttonGroup.add(radioLog4j);
+ }
+
+ private void createMigrationLabel() {
+ migrationLabel = new JLabel();
+ migrationLabel.setText("Migration Type");
+ }
+
+ private void createRadioJCL() {
+ radioJCL = new JRadioButton();
+ radioJCL.setText("from Jakarta Commons Logging to SLF4J");
+ radioJCL
+ .setToolTipText("Select this button if you wish to migrate a Java project using Jakarta Commons Logging to use SLF4J.");
+ }
+
+ private void createRadioLog4j() {
+ radioLog4j = new JRadioButton();
+ radioLog4j.setText("from log4j to SLF4J ");
+ radioLog4j
+ .setToolTipText("Select this button if you wish to migrate a Java project using log4j to use SLF4J.");
+ }
+
+ private void createFolderLabel() {
+ folderLabel = new JLabel();
+ folderLabel.setText("Project Directory");
+ }
+
+ private void createFolderTextField() {
+ folderTextField = new JTextField();
+ folderTextField.setColumns(FOLDER_COLUMNS);
+ }
+
+ private void createBrowseButton() {
+ browseButton = new JButton();
+ browseButton.setText("Browse");
+ browseButton.addActionListener(this);
+ browseButton.setActionCommand(BROWSE_COMMAND);
+ browseButton
+ .setToolTipText("Click this button to browse the file systems on your computer.");
+ }
+
+ private void createAwareCheckbox() {
+ awareCheckBox = new JCheckBox();
+ awareCheckBox
+ .setToolTipText("<html><p>Check this box of you understand that the migration tool<p>will <b>not</b> backup your Java source files.</html>");
+ }
+
+ private void createAwareLabel() {
+ awareLabel = new JLabel();
+ awareLabel
+ .setText("<html>"
+ + "<p>I am aware that this tool will directly modify all Java source files</p>"
+ + "<p>in the selected folder without creating backup files.</p>"
+ + "</html>");
+ }
+
+ private void createWarningLabel() {
+ warningLabel = new JLabel();
+ warningLabel
+ .setText("<html>"
+ + "<p><span color=\"red\">WARNING:</span> This SLF4J migration tool will directly modify all Java source files</p>"
+ + "<p>in the selected project without creating a backup of the original files.</p>"
+ + "</html>");
+ }
+
+ private void createMigrateButton() {
+ migrateButton = new JButton();
+ migrateButton.setText("Migrate Project to SLF4J");
+ migrateButton
+ .setToolTipText("Click this button to initiate migration of your project.");
+ migrateButton.addActionListener(this);
+ migrateButton.setActionCommand(MIGRATE_COMMAND);
+ }
+
+
+ private void createFileChooser() {
+ fileChooser = new JFileChooser();
+ fileChooser.setDialogTitle("Source folder selector");
+ fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+ }
+
+ private void createProgressBar() {
+ progressBar = new JProgressBar(0, 1);
+ progressBar.setPreferredSize(new java.awt.Dimension((int) (X_SIZE*0.8), 5));
+ progressBar.setVisible(false);
+ }
+
+ public void disableInput() {
+ radioJCL.setEnabled(false);
+ radioLog4j.setEnabled(false);
+
+ browseButton.setEnabled(false);
+
+ folderTextField.setEnabled(false);
+ awareCheckBox.setEnabled(false);
+ migrateButton.setText("Migration in progress");
+ migrateButton.setEnabled(false);
+
+ }
+ public void actionPerformed(ActionEvent e) {
+
+ if (MIGRATE_COMMAND.equals(e.getActionCommand())) {
+
+ List<String> errorList = doSanityAnalysis();
+ if(errorList.size() > 0) {
+ showDialogBox(errorList);
+ } else {
+
+ File projectFolder = new File( folderTextField.getText());
+ ConversionTask task = new ConversionTask(projectFolder, this, Constant.EMPTY_RULE_SET);
+ task.launch();
+ }
+ } else if (BROWSE_COMMAND.equals(e.getActionCommand())) {
+ showFileChooser();
+ }
+ }
+
+ void showFileChooser() {
+ int returnVal = fileChooser.showOpenDialog(this);
+ if(returnVal == JFileChooser.APPROVE_OPTION) {
+ File selectedFile = fileChooser.getSelectedFile();
+ System.out.println(selectedFile);
+ folderTextField.setText(selectedFile.getAbsolutePath());
+ }
+ }
+
+ List<String> doSanityAnalysis() {
+
+ List<String> errorList = new ArrayList<String>();
+ if (!radioJCL.isSelected() && !radioLog4j.isSelected()) {
+ errorList.add("Please select the migration type (JCL to SLF4J or log4j to SLF4J)");
+ }
+
+ String folder = folderTextField.getText();
+
+ if (folder == null || folder.length() == 0) {
+ errorList.add("Please select the folder of the project to migrate");
+ } else if(!isDirectory(folder)) {
+ errorList.add("["+folder +"] does not look like a valid folder");
+ }
+
+ if(!awareCheckBox.isSelected()) {
+ errorList.add("Cannot initiate migration unless you acknowledge<p>that files will be modified without creating backup files");
+ }
+ return errorList;
+ }
+
+ void showDialogBox(List<String> errorList) {
+ StringBuffer buf = new StringBuffer();
+ buf.append("<html>");
+ int i = 1;
+ for(String msg: errorList) {
+ buf.append("<p>");
+ buf.append(i);
+ buf.append(". ");
+ buf.append(msg);
+ buf.append("</p>");
+ i++;
+ }
+ buf.append("</html>");
+
+ JOptionPane.showMessageDialog(this,
+ buf.toString(), "",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ boolean isDirectory(String filename) {
+ if(filename == null) {
+ return false;
+ }
+ File file = new File(filename);
+ if(file.exists() && file.isDirectory()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/internal/ProgressListener.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/internal/ProgressListener.java (original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/internal/ProgressListener.java Wed Feb 20 21:33:14 2008
@@ -4,9 +4,12 @@
public interface ProgressListener {
+ public void onMigrationBegin();
public void onDirectory(File file);
public void onFileAddition(File file);
- public void onFileConversion(File file);
+ public void onFileScanBegin();
+ public void onFileScan(File file);
+ public void onInplaceConversion(File file);
public void onDone();
}
Copied: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/internal/ProgressListenerImpl.java (from r971, /slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/internal/ProgressLinstenerImpl.java)
==============================================================================
--- /slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/internal/ProgressLinstenerImpl.java (original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/internal/ProgressListenerImpl.java Wed Feb 20 21:33:14 2008
@@ -3,44 +3,71 @@
import java.io.File;
import java.io.IOException;
-import javax.swing.JLabel;
-
import org.slf4j.converter.helper.Abbreviator;
-public class ProgressLinstenerImpl implements ProgressListener {
+public class ProgressListenerImpl implements ProgressListener {
+ static final int TARGET_FILE_LENGTH = 85;
int addFileCount = 0;
- int conversionCount = 0;
- final JLabel jLabel;
-
+ int scanFileCount = 0;
+ int inplaceConversionCount = 0;
+ final MigratorFrame frame;
+
Abbreviator abbr;
-
- public ProgressLinstenerImpl(File projectFolder, JLabel jLabel) {
- this.jLabel = jLabel;
- this.abbr = new Abbreviator((int) projectFolder.length(), 50, File.separatorChar);
+
+ public ProgressListenerImpl(File projectFolder, MigratorFrame frame) {
+ this.frame = frame;
+ this.abbr = new Abbreviator((int) projectFolder.length(),
+ TARGET_FILE_LENGTH, File.separatorChar);
+ }
+
+ public void onMigrationBegin() {
+ frame.disableInput();
}
-
public void onDirectory(File file) {
- String abbreviatedName;
- try {
- abbreviatedName = abbr.abbreviate(file.getCanonicalPath());
- } catch (IOException e) {
- abbreviatedName = file.toString();
- }
- jLabel.setText("Searching folder ["+abbreviatedName+"]");
+ String abbreviatedName = getShortName(file);
+ frame.otherLabel.setText("<html><p>Searching folder [" + abbreviatedName
+ + "]<p>Found " + addFileCount + " java files to scan.</html>");
}
public void onDone() {
+ frame.otherLabel.setText("<html><font color='BLUE'>Scanned " + addFileCount + " java files, "+inplaceConversionCount+" files were modified.</font></html>");
+
+ System.out.println("<html><FONT COLOR=BLUE>Scanned "+addFileCount+", converted="+inplaceConversionCount);
+ frame.progressBar.setVisible(false);
}
public void onFileAddition(File file) {
addFileCount++;
}
- public void onFileConversion(File file) {
- // TODO Auto-generated method stub
+ public void onFileScan(File file) {
+ String abbreviatedName = getShortName(file);
+ scanFileCount++;
+
+ frame.otherLabel.setText("<html><p>Scanning file [" + abbreviatedName + "]<p>File "
+ + scanFileCount + " out of "+ addFileCount+" files to scan."+ inplaceConversionCount+ " files converted.</html>");
+ frame.progressBar.setValue(scanFileCount);
+ }
+
+ public void onInplaceConversion(File file) {
+ inplaceConversionCount++;
+ }
+
+ String getShortName(File file) {
+ try {
+ return abbr.abbreviate(file.getCanonicalPath());
+ } catch (IOException e) {
+ return file.toString();
+ }
+ }
+ public void onFileScanBegin() {
+ frame.progressBar.setMaximum(addFileCount);
+ frame.progressBar.setValue(0);
+ frame.progressBar.setVisible(true);
}
+
}
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 Wed Feb 20 21:33:14 2008
@@ -5,6 +5,7 @@
import junit.framework.TestCase;
+import org.slf4j.converter.internal.NopProgressListener;
import org.slf4j.converter.line.EmptyRuleSet;
public class FileConverterTest extends TestCase {
@@ -26,7 +27,7 @@
public void XtestNOP() throws IOException {
- InplaceFileConverter fc = new InplaceFileConverter(new EmptyRuleSet());
+ InplaceFileConverter fc = new InplaceFileConverter(new EmptyRuleSet(), new NopProgressListener());
fc.convert(new File("c:/varargs.txt"));
}
}
Modified: slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/internal/NopProgressListener.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/internal/NopProgressListener.java (original)
+++ slf4j/trunk/slf4j-converter/src/test/java/org/slf4j/converter/internal/NopProgressListener.java Wed Feb 20 21:33:14 2008
@@ -13,7 +13,16 @@
public void onFileAddition(File file) {
}
- public void onFileConversion(File file) {
+ public void onFileScan(File file) {
+ }
+
+ public void onInplaceConversion(File file) {
+ }
+
+ public void onFileScanBegin() {
+ }
+
+ public void onMigrationBegin() {
}
}
More information about the slf4j-dev
mailing list