You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by sb...@apache.org on 2002/02/24 13:17:01 UTC
cvs commit: jakarta-turbine-maven/src/java/org/apache/maven/importscrubber ImportScrubberGUI.java ImportScrubberMenu.java ImportStatement.java ImportStatementComparator.java ImportStatements.java IProgressMonitor.java IReferenceFoundListener.java JavaFileFilter.java
sbailliez 02/02/24 04:17:01
Modified: src/java/org/apache/maven/importscrubber
ImportScrubberGUI.java ImportScrubberMenu.java
ImportStatement.java ImportStatementComparator.java
ImportStatements.java IProgressMonitor.java
IReferenceFoundListener.java JavaFileFilter.java
Log:
Apply Turbine coding style
Revision Changes Path
1.3 +174 -170 jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/ImportScrubberGUI.java
Index: ImportScrubberGUI.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/ImportScrubberGUI.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ImportScrubberGUI.java 21 Feb 2002 14:00:16 -0000 1.2
+++ ImportScrubberGUI.java 24 Feb 2002 12:17:01 -0000 1.3
@@ -54,189 +54,193 @@
* <http://www.apache.org/>.
*/
-import java.awt.BorderLayout;
-import java.awt.FlowLayout;
-import java.awt.Graphics;
-import java.awt.Window;
+import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
import java.io.File;
import java.util.Enumeration;
-import java.util.List;
import java.util.ListIterator;
import java.util.ResourceBundle;
-import javax.swing.DefaultListModel;
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JComboBox;
-import javax.swing.JFileChooser;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JList;
-import javax.swing.JMenuBar;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JTextField;
-import javax.swing.ListModel;
+import javax.swing.*;
+
import org.apache.maven.importscrubber.format.IStatementFormat;
/**
* Enacapsulates the Importscrubber GUI. Serves as a Mediator (GOF, p 273) for all GUI components.
*/
-public class ImportScrubberGUI implements IProgressMonitor {
+public class ImportScrubberGUI implements IProgressMonitor
+{
- private class BrowseListener implements ActionListener {
- private final File START = new File(System.getProperty("user.home"));
- public void actionPerformed(ActionEvent e) {
- JFileChooser chooser = new JFileChooser(START);
-
- chooser.setDialogTitle(ResourceBundle.getBundle("org.apache.maven.importscrubber.Resources").getString(Resources.FILE_BROWSER_TITLE));
- chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
- chooser.showOpenDialog(_mainFrame);
- if (chooser.getSelectedFile() != null) {
- _fileSpecField.setText(chooser.getSelectedFile().getAbsolutePath());
- }
- }
- }
-
- private class BasicWindowMonitor extends WindowAdapter {
- public void windowClosing(WindowEvent we) {
- destroy();
- }
- }
-
-
- private JTextField _fileSpecField;
- private JFrame _mainFrame;
- private JCheckBox _recurseCheckbox;
- private JList _fileList;
- private ImportScrubber _scrubber;
- private JComboBox _formats;
- private JCheckBox _sortStdLibsHighCheckbox;
-
- public static void main(String[] args) {
- ImportScrubberGUI gui = new ImportScrubberGUI();
- }
-
- public ImportScrubberGUI() {
- ResourceBundle res = ResourceBundle.getBundle("org.apache.maven.importscrubber.Resources");
-
- _mainFrame = new JFrame(res.getString(Resources.VERSION_ID));
- _mainFrame.setLocation(200, 150);
- _mainFrame.setSize(600,450);
- _mainFrame.addWindowListener(new BasicWindowMonitor());
- _mainFrame.getContentPane().setLayout(new FlowLayout());
- _fileSpecField = new JTextField(30);
- JButton browseButton = new JButton(res.getString(Resources.BROWSE_LABEL));
- browseButton.setMnemonic('B');
- browseButton.addActionListener(new BrowseListener());
- _recurseCheckbox = new JCheckBox();
-
- JPanel browsePanel = new JPanel(new FlowLayout());
- browsePanel.add(new JLabel(res.getString(Resources.RECURSE_LABEL)));
- browsePanel.add(_recurseCheckbox);
- browsePanel.add(_fileSpecField);
- browsePanel.add(browseButton);
-
- _formats = new JComboBox(new StatementFormatModel());
- _sortStdLibsHighCheckbox = new JCheckBox(Resources.SORT_JAVA_LIBS_LABEL);
- JPanel formatPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
- formatPanel.add(_formats);
- formatPanel.add(_sortStdLibsHighCheckbox);
-
- _fileList = new JList(new DefaultListModel());
- _fileList.setCellRenderer(new WorkingCellRenderer());
-
- JButton findFilesButton = new JButton(res.getString(Resources.FIND_FILES_LABEL));
- findFilesButton.setMnemonic('i');
- findFilesButton.addActionListener(new FindCommand(this));
- JPanel findButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
- findButtonPanel.add(findFilesButton);
-
- JPanel settingsTopPanel = new JPanel(new BorderLayout());
- settingsTopPanel.add(findButtonPanel, BorderLayout.NORTH);
- settingsTopPanel.add(formatPanel, BorderLayout.SOUTH);
-
- JPanel goButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
- JButton goButton = new JButton(res.getString(Resources.GO_LABEL));
- goButton.setMnemonic('G');
- goButton.addActionListener(new GoCommand(this));
- goButtonPanel.add(goButton, BorderLayout.NORTH);
-
- JPanel allSettingsPanel = new JPanel(new BorderLayout());
- allSettingsPanel.add(settingsTopPanel, BorderLayout.NORTH);
- allSettingsPanel.add(goButtonPanel, BorderLayout.SOUTH);
-
- JPanel resultsPanel = new JPanel(new BorderLayout());
- JScrollPane listPane = new JScrollPane(_fileList);
- listPane.setSize(resultsPanel.getWidth()-40, resultsPanel.getHeight()-10);
- resultsPanel.add(listPane);
-
- JPanel bottom = new JPanel(new BorderLayout());
- bottom.add(allSettingsPanel, BorderLayout.NORTH);
- bottom.add(resultsPanel, BorderLayout.SOUTH);
-
- _mainFrame.setJMenuBar(new ImportScrubberMenu(this));
- _mainFrame.getContentPane().add(browsePanel);
- _mainFrame.getContentPane().add(bottom);
-
- _scrubber = new ImportScrubber();
- _mainFrame.setVisible(true);
- }
-
- public void go() {
- if (_fileList.getModel().getSize() == 0) {
- return;
- }
- ResourceBundle res = ResourceBundle.getBundle("org.apache.maven.importscrubber.Resources");
- try {
- IStatementFormat format = (IStatementFormat)_formats.getSelectedItem();
- format.sortJavaLibsHigh(_sortStdLibsHighCheckbox.isSelected());
- _scrubber.setFormat(format);
- _scrubber.buildTasks();
- _scrubber.runTasks(this);
- JOptionPane.showMessageDialog(null, res.getString(Resources.ALL_DONE), res.getString(Resources.APP_NAME), JOptionPane.INFORMATION_MESSAGE);
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, res.getString(Resources.ERR_UNABLE_TO_FINISH) + e.getMessage(), res.getString(Resources.APP_NAME), JOptionPane.ERROR_MESSAGE);
- e.printStackTrace();
- }
- }
-
- public void find() {
- _scrubber.setFileRoot(_fileSpecField.getText(), _recurseCheckbox.isSelected());
- DefaultListModel model = (DefaultListModel)_fileList.getModel();
- model.removeAllElements();
- for (ListIterator iter = _scrubber.getFiles().listIterator(); iter.hasNext();) {
- model.addElement(iter.next());
- }
- _mainFrame.paintAll(_mainFrame.getGraphics());
- }
-
- public void destroy() {
- _mainFrame.setVisible(false);
- _mainFrame.dispose();
- System.exit(0);
- }
-
- // ITaskListener
- public void taskStarted(ScrubTask task) {
- DefaultListModel model = (DefaultListModel)_fileList.getModel();
- for (Enumeration e = model.elements(); e.hasMoreElements();) {
- FilePair pair = (FilePair)e.nextElement();
- if (pair.getSourceFile().getAbsolutePath().equals(task.getSourcePath())) {
- _fileList.setSelectedValue(pair, true);
- }
- }
- _fileList.paint(_fileList.getGraphics());
- }
-
- public void taskComplete(ScrubTask task) {
- _fileList.clearSelection();
- }
- // ITaskListener
+ private class BrowseListener implements ActionListener
+ {
+ private final File START = new File(System.getProperty("user.home"));
+
+ public void actionPerformed(ActionEvent e)
+ {
+ JFileChooser chooser = new JFileChooser(START);
+
+ chooser.setDialogTitle(ResourceBundle.getBundle("org.apache.maven.importscrubber.Resources").getString(Resources.FILE_BROWSER_TITLE));
+ chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
+ chooser.showOpenDialog(_mainFrame);
+ if (chooser.getSelectedFile() != null)
+ {
+ _fileSpecField.setText(chooser.getSelectedFile().getAbsolutePath());
+ }
+ }
+ }
+
+ private class BasicWindowMonitor extends WindowAdapter
+ {
+ public void windowClosing(WindowEvent we)
+ {
+ destroy();
+ }
+ }
+
+
+ private JTextField _fileSpecField;
+ private JFrame _mainFrame;
+ private JCheckBox _recurseCheckbox;
+ private JList _fileList;
+ private ImportScrubber _scrubber;
+ private JComboBox _formats;
+ private JCheckBox _sortStdLibsHighCheckbox;
+
+ public static void main(String[] args)
+ {
+ ImportScrubberGUI gui = new ImportScrubberGUI();
+ }
+
+ public ImportScrubberGUI()
+ {
+ ResourceBundle res = ResourceBundle.getBundle("org.apache.maven.importscrubber.Resources");
+
+ _mainFrame = new JFrame(res.getString(Resources.VERSION_ID));
+ _mainFrame.setLocation(200, 150);
+ _mainFrame.setSize(600, 450);
+ _mainFrame.addWindowListener(new BasicWindowMonitor());
+ _mainFrame.getContentPane().setLayout(new FlowLayout());
+ _fileSpecField = new JTextField(30);
+ JButton browseButton = new JButton(res.getString(Resources.BROWSE_LABEL));
+ browseButton.setMnemonic('B');
+ browseButton.addActionListener(new BrowseListener());
+ _recurseCheckbox = new JCheckBox();
+
+ JPanel browsePanel = new JPanel(new FlowLayout());
+ browsePanel.add(new JLabel(res.getString(Resources.RECURSE_LABEL)));
+ browsePanel.add(_recurseCheckbox);
+ browsePanel.add(_fileSpecField);
+ browsePanel.add(browseButton);
+
+ _formats = new JComboBox(new StatementFormatModel());
+ _sortStdLibsHighCheckbox = new JCheckBox(Resources.SORT_JAVA_LIBS_LABEL);
+ JPanel formatPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ formatPanel.add(_formats);
+ formatPanel.add(_sortStdLibsHighCheckbox);
+
+ _fileList = new JList(new DefaultListModel());
+ _fileList.setCellRenderer(new WorkingCellRenderer());
+
+ JButton findFilesButton = new JButton(res.getString(Resources.FIND_FILES_LABEL));
+ findFilesButton.setMnemonic('i');
+ findFilesButton.addActionListener(new FindCommand(this));
+ JPanel findButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ findButtonPanel.add(findFilesButton);
+
+ JPanel settingsTopPanel = new JPanel(new BorderLayout());
+ settingsTopPanel.add(findButtonPanel, BorderLayout.NORTH);
+ settingsTopPanel.add(formatPanel, BorderLayout.SOUTH);
+
+ JPanel goButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ JButton goButton = new JButton(res.getString(Resources.GO_LABEL));
+ goButton.setMnemonic('G');
+ goButton.addActionListener(new GoCommand(this));
+ goButtonPanel.add(goButton, BorderLayout.NORTH);
+
+ JPanel allSettingsPanel = new JPanel(new BorderLayout());
+ allSettingsPanel.add(settingsTopPanel, BorderLayout.NORTH);
+ allSettingsPanel.add(goButtonPanel, BorderLayout.SOUTH);
+
+ JPanel resultsPanel = new JPanel(new BorderLayout());
+ JScrollPane listPane = new JScrollPane(_fileList);
+ listPane.setSize(resultsPanel.getWidth() - 40, resultsPanel.getHeight() - 10);
+ resultsPanel.add(listPane);
+
+ JPanel bottom = new JPanel(new BorderLayout());
+ bottom.add(allSettingsPanel, BorderLayout.NORTH);
+ bottom.add(resultsPanel, BorderLayout.SOUTH);
+
+ _mainFrame.setJMenuBar(new ImportScrubberMenu(this));
+ _mainFrame.getContentPane().add(browsePanel);
+ _mainFrame.getContentPane().add(bottom);
+
+ _scrubber = new ImportScrubber();
+ _mainFrame.setVisible(true);
+ }
+
+ public void go()
+ {
+ if (_fileList.getModel().getSize() == 0)
+ {
+ return;
+ }
+ ResourceBundle res = ResourceBundle.getBundle("org.apache.maven.importscrubber.Resources");
+ try
+ {
+ IStatementFormat format = (IStatementFormat) _formats.getSelectedItem();
+ format.sortJavaLibsHigh(_sortStdLibsHighCheckbox.isSelected());
+ _scrubber.setFormat(format);
+ _scrubber.buildTasks();
+ _scrubber.runTasks(this);
+ JOptionPane.showMessageDialog(null, res.getString(Resources.ALL_DONE), res.getString(Resources.APP_NAME), JOptionPane.INFORMATION_MESSAGE);
+ }
+ catch (Exception e)
+ {
+ JOptionPane.showMessageDialog(null, res.getString(Resources.ERR_UNABLE_TO_FINISH) + e.getMessage(), res.getString(Resources.APP_NAME), JOptionPane.ERROR_MESSAGE);
+ e.printStackTrace();
+ }
+ }
+
+ public void find()
+ {
+ _scrubber.setFileRoot(_fileSpecField.getText(), _recurseCheckbox.isSelected());
+ DefaultListModel model = (DefaultListModel) _fileList.getModel();
+ model.removeAllElements();
+ for (ListIterator iter = _scrubber.getFiles().listIterator(); iter.hasNext();)
+ {
+ model.addElement(iter.next());
+ }
+ _mainFrame.paintAll(_mainFrame.getGraphics());
+ }
+
+ public void destroy()
+ {
+ _mainFrame.setVisible(false);
+ _mainFrame.dispose();
+ System.exit(0);
+ }
+
+ // ITaskListener
+ public void taskStarted(ScrubTask task)
+ {
+ DefaultListModel model = (DefaultListModel) _fileList.getModel();
+ for (Enumeration e = model.elements(); e.hasMoreElements();)
+ {
+ FilePair pair = (FilePair) e.nextElement();
+ if (pair.getSourceFile().getAbsolutePath().equals(task.getSourcePath()))
+ {
+ _fileList.setSelectedValue(pair, true);
+ }
+ }
+ _fileList.paint(_fileList.getGraphics());
+ }
+
+ public void taskComplete(ScrubTask task)
+ {
+ _fileList.clearSelection();
+ }
+ // ITaskListener
}
1.3 +47 -49 jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/ImportScrubberMenu.java
Index: ImportScrubberMenu.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/ImportScrubberMenu.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ImportScrubberMenu.java 21 Feb 2002 14:00:16 -0000 1.2
+++ ImportScrubberMenu.java 24 Feb 2002 12:17:01 -0000 1.3
@@ -57,59 +57,57 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
+import javax.swing.*;
/**
* Encapsulates the ImportScrubber GUI menu.
*/
public class ImportScrubberMenu extends JMenuBar
{
-
- private class MyAboutWindow implements ActionListener
- {
- public void actionPerformed(ActionEvent e)
- {
- JOptionPane.showMessageDialog(ImportScrubberMenu.this, _helpMsg);
- }
- }
-
- private class ExitActionListener implements ActionListener
- {
- public void actionPerformed(ActionEvent e)
- {
- _frame.destroy();
- }
-
- }
- private ImportScrubberGUI _frame;
- private String _helpMsg;
-
- public ImportScrubberMenu(ImportScrubberGUI frame)
- {
- _frame = frame;
-
- ResourceBundle res = ResourceBundle.getBundle("org.apache.maven.importscrubber.Resources");
-
- _helpMsg = res.getString(Resources.HELP_MESSAGE);
-
- JMenu lFileMenu = new JMenu(res.getString(Resources.FILE_LABEL));
- lFileMenu.setMnemonic('f');
- JMenuItem lExitItem = new JMenuItem(res.getString(Resources.EXIT_LABEL));
- lExitItem.setMnemonic('x');
- lExitItem.addActionListener(new ExitActionListener());
- lFileMenu.add(lExitItem);
-
- JMenu lHelpMenu = new JMenu(res.getString(Resources.HELP_LABEL));
- lHelpMenu.setMnemonic('h');
- JMenuItem lAboutItem = new JMenuItem(res.getString(Resources.ABOUT_LABEL));
- lAboutItem.setMnemonic('a');
- lAboutItem.addActionListener(new MyAboutWindow());
- lHelpMenu.add(lAboutItem);
-
- add(lFileMenu);
- add(lHelpMenu);
- }
+
+ private class MyAboutWindow implements ActionListener
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ JOptionPane.showMessageDialog(ImportScrubberMenu.this, _helpMsg);
+ }
+ }
+
+ private class ExitActionListener implements ActionListener
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ _frame.destroy();
+ }
+
+ }
+
+ private ImportScrubberGUI _frame;
+ private String _helpMsg;
+
+ public ImportScrubberMenu(ImportScrubberGUI frame)
+ {
+ _frame = frame;
+
+ ResourceBundle res = ResourceBundle.getBundle("org.apache.maven.importscrubber.Resources");
+
+ _helpMsg = res.getString(Resources.HELP_MESSAGE);
+
+ JMenu lFileMenu = new JMenu(res.getString(Resources.FILE_LABEL));
+ lFileMenu.setMnemonic('f');
+ JMenuItem lExitItem = new JMenuItem(res.getString(Resources.EXIT_LABEL));
+ lExitItem.setMnemonic('x');
+ lExitItem.addActionListener(new ExitActionListener());
+ lFileMenu.add(lExitItem);
+
+ JMenu lHelpMenu = new JMenu(res.getString(Resources.HELP_LABEL));
+ lHelpMenu.setMnemonic('h');
+ JMenuItem lAboutItem = new JMenuItem(res.getString(Resources.ABOUT_LABEL));
+ lAboutItem.setMnemonic('a');
+ lAboutItem.addActionListener(new MyAboutWindow());
+ lHelpMenu.add(lAboutItem);
+
+ add(lFileMenu);
+ add(lHelpMenu);
+ }
}
1.3 +93 -93 jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/ImportStatement.java
Index: ImportStatement.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/ImportStatement.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ImportStatement.java 21 Feb 2002 14:00:16 -0000 1.2
+++ ImportStatement.java 24 Feb 2002 12:17:01 -0000 1.3
@@ -54,100 +54,100 @@
* <http://www.apache.org/>.
*/
-public class ImportStatement implements Comparable
+public class ImportStatement implements Comparable
{
- private String className;
+ private String className;
- public ImportStatement(String className)
- {
- this.className = className;
- }
-
- public String getFullyQualifiedClassName()
- {
- return className;
- }
-
- public int hashCode()
- {
- return className.hashCode();
- }
-
- public boolean isInDefaultPackage()
- {
- return className.lastIndexOf(".") == -1;
- }
-
- public String getPackage()
- {
- return className.substring(0, className.lastIndexOf("."));
- }
-
- public boolean equals(Object other)
- {
- if(!(other instanceof ImportStatement) || other == null)
- {
- return false;
- }
- ImportStatement otherStmt = (ImportStatement)other;
- return otherStmt.getFullyQualifiedClassName().equals(className);
- }
-
- public String getClassName()
- {
- int lastDot = className.lastIndexOf(".");
- return className.substring(lastDot + 1, className.length());
- }
-
- public boolean isInStdJavaLibrary()
- {
- return className.startsWith("java.");
- }
-
- public boolean isInStdJavaExtensionLibrary()
- {
- return className.startsWith("javax.");
- }
-
- public StringBuffer getFormattedStmt()
- {
- StringBuffer result = new StringBuffer();
- result.append(ImportStatements.MARKER);
- result.append(className);
- result.append(";");
- result.append(ImportScrubber.LINE_SEPARATOR);
- return result;
- }
-
- // Comparable
- public int compareTo(Object in)
- {
- if(in == null)
- {
- throw new IllegalArgumentException("Can't compare this to null!");
- }
- // If they are the same then simple comparison will suffice. If not,
- // we'd like to put something like java.awt.Toolkit before
- // java.awt.print.Pageable which a simple comparison won't do.
- ImportStatement otherImport = (ImportStatement)in;
-
- if (!getPackage().equals(otherImport.getPackage()))
- {
- if (getPackage().startsWith(otherImport.getPackage()))
- {
- return 1;
-
- }
- else if (otherImport.getPackage().startsWith(getPackage()))
- {
- return -1;
- }
- }
-
- // same package, so just do simple comparison
- return className.toLowerCase().compareTo(otherImport.getFullyQualifiedClassName().toLowerCase());
- }
- // Comparable
+ public ImportStatement(String className)
+ {
+ this.className = className;
+ }
+
+ public String getFullyQualifiedClassName()
+ {
+ return className;
+ }
+
+ public int hashCode()
+ {
+ return className.hashCode();
+ }
+
+ public boolean isInDefaultPackage()
+ {
+ return className.lastIndexOf(".") == -1;
+ }
+
+ public String getPackage()
+ {
+ return className.substring(0, className.lastIndexOf("."));
+ }
+
+ public boolean equals(Object other)
+ {
+ if (!(other instanceof ImportStatement) || other == null)
+ {
+ return false;
+ }
+ ImportStatement otherStmt = (ImportStatement) other;
+ return otherStmt.getFullyQualifiedClassName().equals(className);
+ }
+
+ public String getClassName()
+ {
+ int lastDot = className.lastIndexOf(".");
+ return className.substring(lastDot + 1, className.length());
+ }
+
+ public boolean isInStdJavaLibrary()
+ {
+ return className.startsWith("java.");
+ }
+
+ public boolean isInStdJavaExtensionLibrary()
+ {
+ return className.startsWith("javax.");
+ }
+
+ public StringBuffer getFormattedStmt()
+ {
+ StringBuffer result = new StringBuffer();
+ result.append(ImportStatements.MARKER);
+ result.append(className);
+ result.append(";");
+ result.append(ImportScrubber.LINE_SEPARATOR);
+ return result;
+ }
+
+ // Comparable
+ public int compareTo(Object in)
+ {
+ if (in == null)
+ {
+ throw new IllegalArgumentException("Can't compare this to null!");
+ }
+ // If they are the same then simple comparison will suffice. If not,
+ // we'd like to put something like java.awt.Toolkit before
+ // java.awt.print.Pageable which a simple comparison won't do.
+ ImportStatement otherImport = (ImportStatement) in;
+
+ if (!getPackage().equals(otherImport.getPackage()))
+ {
+ if (getPackage().startsWith(otherImport.getPackage()))
+ {
+ return 1;
+
+ }
+ else if (otherImport.getPackage().startsWith(getPackage()))
+ {
+ return -1;
+ }
+ }
+
+ // same package, so just do simple comparison
+ return className.toLowerCase().compareTo(otherImport.getFullyQualifiedClassName().toLowerCase());
+ }
+ // Comparable
}
-
+
1.3 +41 -41 jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/ImportStatementComparator.java
Index: ImportStatementComparator.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/ImportStatementComparator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ImportStatementComparator.java 21 Feb 2002 14:00:16 -0000 1.2
+++ ImportStatementComparator.java 24 Feb 2002 12:17:01 -0000 1.3
@@ -58,47 +58,47 @@
public class ImportStatementComparator implements Comparator
{
- private boolean _sortStdLibsHigh;
+ private boolean _sortStdLibsHigh;
- public ImportStatementComparator(boolean sortStdLibsHigh)
- {
- _sortStdLibsHigh = sortStdLibsHigh;
- }
-
- public int compare(Object first, Object second)
- {
- if(first == null || second == null )
- {
- throw new IllegalArgumentException("Either " + first + " or " + second + " is null");
- }
-
- ImportStatement firstImport = (ImportStatement)first;
- ImportStatement secondImport = (ImportStatement)second;
-
- if (_sortStdLibsHigh)
- {
- if (firstImport.isInStdJavaLibrary() && !secondImport.isInStdJavaLibrary())
- {
- return -1;
- }
-
- if (!firstImport.isInStdJavaLibrary() && secondImport.isInStdJavaLibrary())
- {
- return 1;
- }
-
- if (firstImport.isInStdJavaExtensionLibrary() && !secondImport.isInStdJavaExtensionLibrary())
- {
- return -1;
- }
-
- if (!firstImport.isInStdJavaExtensionLibrary() && secondImport.isInStdJavaExtensionLibrary())
- {
- return 1;
- }
- }
+ public ImportStatementComparator(boolean sortStdLibsHigh)
+ {
+ _sortStdLibsHigh = sortStdLibsHigh;
+ }
- return firstImport.compareTo(secondImport);
- }
+ public int compare(Object first, Object second)
+ {
+ if (first == null || second == null)
+ {
+ throw new IllegalArgumentException("Either " + first + " or " + second + " is null");
+ }
+
+ ImportStatement firstImport = (ImportStatement) first;
+ ImportStatement secondImport = (ImportStatement) second;
+
+ if (_sortStdLibsHigh)
+ {
+ if (firstImport.isInStdJavaLibrary() && !secondImport.isInStdJavaLibrary())
+ {
+ return -1;
+ }
+
+ if (!firstImport.isInStdJavaLibrary() && secondImport.isInStdJavaLibrary())
+ {
+ return 1;
+ }
+
+ if (firstImport.isInStdJavaExtensionLibrary() && !secondImport.isInStdJavaExtensionLibrary())
+ {
+ return -1;
+ }
+
+ if (!firstImport.isInStdJavaExtensionLibrary() && secondImport.isInStdJavaExtensionLibrary())
+ {
+ return 1;
+ }
+ }
+
+ return firstImport.compareTo(secondImport);
+ }
}
-
+
1.3 +74 -72 jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/ImportStatements.java
Index: ImportStatements.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/ImportStatements.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ImportStatements.java 21 Feb 2002 14:00:16 -0000 1.2
+++ ImportStatements.java 24 Feb 2002 12:17:01 -0000 1.3
@@ -56,9 +56,9 @@
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
+
import org.apache.maven.importscrubber.format.IStatementFormat;
/**
@@ -66,78 +66,80 @@
*/
public class ImportStatements
{
- public static final String MARKER = "import ";
- private List _stmts = new ArrayList();
+ public static final String MARKER = "import ";
+ private List _stmts = new ArrayList();
+
+ public void add(String candidateString)
+ {
+ ImportStatement candidateImport = new ImportStatement(candidateString);
+
+ if (candidateImport.isInDefaultPackage() || _stmts.contains(candidateImport))
+ {
+ return;
+ }
+
+ _stmts.add(candidateImport);
+ }
+
+ public StringBuffer getOutput(IStatementFormat format)
+ {
+ Collections.sort(_stmts, new ImportStatementComparator(format.sortJavaLibsHigh()));
+ return format.applyFormat(_stmts.iterator());
+ }
+
+ public int getCount()
+ {
+ return _stmts.size();
+ }
+
+ /**
+ * Remove imports for classes in the same package as the current class
+ */
+ public void removeLocalToPackage(PackageStmt packageStmt)
+ {
+ for (Iterator i = _stmts.iterator(); i.hasNext();)
+ {
+ if (packageStmt.isInSamePackageAs((ImportStatement) i.next()))
+ {
+ i.remove();
+ }
+ }
+ }
- public void add(String candidateString)
- {
- ImportStatement candidateImport = new ImportStatement(candidateString);
-
- if(candidateImport.isInDefaultPackage() || _stmts.contains(candidateImport))
- {
- return;
- }
-
- _stmts.add(candidateImport);
- }
-
- public StringBuffer getOutput(IStatementFormat format)
- {
- Collections.sort(_stmts, new ImportStatementComparator(format.sortJavaLibsHigh()));
- return format.applyFormat(_stmts.iterator());
- }
-
- public int getCount()
- {
- return _stmts.size();
- }
-
- /**
- * Remove imports for classes in the same package as the current class
- */
- public void removeLocalToPackage(PackageStmt packageStmt)
- {
- for (Iterator i = _stmts.iterator(); i.hasNext();)
- {
- if (packageStmt.isInSamePackageAs((ImportStatement)i.next()))
- {
- i.remove();
- }
- }
- }
-
- /**
- * Remove those imports which appear in the class file
- * byte code but are not directly referenced in the source code
- */
- public void removeUnreferenced(String classBody)
- {
- for (Iterator i = _stmts.iterator(); i.hasNext();)
- {
- ImportStatement importStmt = (ImportStatement)i.next();
- // is that class name mentioned somewhere in the class?
- if (classBody.indexOf(importStmt.getClassName()) == -1)
- {
- // nope, so remove it
- if (ImportScrubber.DEBUG) {
- System.out.println("Removing unreferenced import:" + importStmt.getClassName());
+ /**
+ * Remove those imports which appear in the class file
+ * byte code but are not directly referenced in the source code
+ */
+ public void removeUnreferenced(String classBody)
+ {
+ for (Iterator i = _stmts.iterator(); i.hasNext();)
+ {
+ ImportStatement importStmt = (ImportStatement) i.next();
+ // is that class name mentioned somewhere in the class?
+ if (classBody.indexOf(importStmt.getClassName()) == -1)
+ {
+ // nope, so remove it
+ if (ImportScrubber.DEBUG)
+ {
+ System.out.println("Removing unreferenced import:" + importStmt.getClassName());
+ }
+ i.remove();
}
- i.remove();
- }
- }
-
- for (Iterator i = _stmts.iterator(); i.hasNext();)
- {
- ImportStatement importStmt = (ImportStatement)i.next();
- // is that class used as a fully qualified name in the class body somewhere?
- if (classBody.indexOf(importStmt.getFullyQualifiedClassName()) != -1)
- {
- // nope, so remove it
- if (ImportScrubber.DEBUG) {
- System.out.println("Removing fully qualified import:" + importStmt.getClassName());
+ }
+
+ for (Iterator i = _stmts.iterator(); i.hasNext();)
+ {
+ ImportStatement importStmt = (ImportStatement) i.next();
+ // is that class used as a fully qualified name in the class body somewhere?
+ if (classBody.indexOf(importStmt.getFullyQualifiedClassName()) != -1)
+ {
+ // nope, so remove it
+ if (ImportScrubber.DEBUG)
+ {
+ System.out.println("Removing fully qualified import:" + importStmt.getClassName());
+ }
+ i.remove();
}
- i.remove();
- }
- }
- }
+ }
+ }
}
1.3 +4 -3 jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/IProgressMonitor.java
Index: IProgressMonitor.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/IProgressMonitor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- IProgressMonitor.java 21 Feb 2002 14:00:16 -0000 1.2
+++ IProgressMonitor.java 24 Feb 2002 12:17:01 -0000 1.3
@@ -55,13 +55,14 @@
*/
/**
- * Defines the behavior of by an object which wishes
+ * Defines the behavior of by an object which wishes
* to be notified when a task is started or completed.
*/
public interface IProgressMonitor
{
- public void taskStarted(ScrubTask task);
- public void taskComplete(ScrubTask task);
+ public void taskStarted(ScrubTask task);
+
+ public void taskComplete(ScrubTask task);
}
1.3 +1 -1 jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/IReferenceFoundListener.java
Index: IReferenceFoundListener.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/IReferenceFoundListener.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- IReferenceFoundListener.java 21 Feb 2002 14:00:16 -0000 1.2
+++ IReferenceFoundListener.java 24 Feb 2002 12:17:01 -0000 1.3
@@ -60,7 +60,7 @@
*/
public interface IReferenceFoundListener
{
- public void referenceFound(String className);
+ public void referenceFound(String className);
}
1.3 +14 -14 jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/JavaFileFilter.java
Index: JavaFileFilter.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/JavaFileFilter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JavaFileFilter.java 21 Feb 2002 14:00:16 -0000 1.2
+++ JavaFileFilter.java 24 Feb 2002 12:17:01 -0000 1.3
@@ -62,20 +62,20 @@
*/
public class JavaFileFilter implements FilenameFilter
{
- public boolean accept(File dir, String name)
- {
- File file = new File(dir + ImportScrubber.FILE_SEPARATOR + name);
- if (file.isDirectory())
- {
- return true;
- }
- if (!file.exists() || !name.endsWith(".java"))
- {
- return false;
- }
+ public boolean accept(File dir, String name)
+ {
+ File file = new File(dir + ImportScrubber.FILE_SEPARATOR + name);
+ if (file.isDirectory())
+ {
+ return true;
+ }
+ if (!file.exists() || !name.endsWith(".java"))
+ {
+ return false;
+ }
- File classFile = new File(dir + ImportScrubber.FILE_SEPARATOR + name.substring(0, name.length()-5) + ".class");
- return classFile.exists();
- }
+ File classFile = new File(dir + ImportScrubber.FILE_SEPARATOR + name.substring(0, name.length() - 5) + ".class");
+ return classFile.exists();
+ }
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>