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:18:32 UTC

cvs commit: jakarta-turbine-maven/src/java/org/apache/maven/importscrubber ClassParserWrapper.java ConsoleProgressMonitor.java FilePair.java FindCommand.java GoCommand.java ImportScrubber.java

sbailliez    02/02/24 04:18:32

  Modified:    src/java/org/apache/maven/importscrubber
                        ClassParserWrapper.java ConsoleProgressMonitor.java
                        FilePair.java FindCommand.java GoCommand.java
                        ImportScrubber.java
  Log:
  Apply Turbine coding style
  
  Revision  Changes    Path
  1.3       +211 -171  jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/ClassParserWrapper.java
  
  Index: ClassParserWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/ClassParserWrapper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ClassParserWrapper.java	21 Feb 2002 14:00:16 -0000	1.2
  +++ ClassParserWrapper.java	24 Feb 2002 12:18:31 -0000	1.3
  @@ -58,12 +58,12 @@
   import java.io.File;
   import java.io.FileInputStream;
   import java.io.FileNotFoundException;
  -import java.io.InputStream;
   import java.io.IOException;
   import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.List;
   import java.util.StringTokenizer;
  +
   import org.apache.bcel.classfile.ClassParser;
   import org.apache.bcel.classfile.Constant;
   import org.apache.bcel.classfile.ConstantClass;
  @@ -73,179 +73,219 @@
   import org.apache.bcel.classfile.DescendingVisitor;
   import org.apache.bcel.classfile.EmptyVisitor;
   import org.apache.bcel.classfile.JavaClass;
  -import org.apache.bcel.classfile.Visitor;
   
   /**
    * This class encapsulates whatever utility we are using to parse the class file
    */
  -public class ClassParserWrapper {
  -   private static final char[] SIGNATURE_CHARS = new char[] {'L', 'Z', '(', ')', '[', ']', 'I', 'C', 'D'};
  -   private static final String STD_PREAMBLE = "\"CONSTANT_Utf8[1](\"";
  -
  -   private static class ClassRefVisitor extends EmptyVisitor {
  -      private IReferenceFoundListener listener;
  -      private ConstantPool constantPool;
  -      private List excludedIndexes;
  -
  -      public ClassRefVisitor(ConstantPool constantPool, IReferenceFoundListener aListener, List excludedIndexes) {
  -         this.listener = aListener;
  -         this.constantPool = constantPool;
  -         this.excludedIndexes = excludedIndexes;
  -      }
  -
  -      public void visitConstantClass(ConstantClass obj) {
  -         String current = constantPool.constantToString(obj);
  -         if (current.indexOf(';') != -1) {
  -            current = cleanSignature(current);
  -         }
  -         if (current.indexOf('(') != -1 || current.indexOf(')') != -1 || inJavaLang(current)) {
  -            return;
  -         }
  -         listener.referenceFound(current);
  -      }
  -
  -      public void visitConstantUtf8(ConstantUtf8 obj) {
  -         
  -         // skip the ones which we know are referred to by constant strings
  -         for(Iterator iter = excludedIndexes.iterator(); iter.hasNext();)
  -         {
  -            Constant constant = constantPool.getConstant(((Integer)iter.next()).intValue());
  -            if(constant.equals(obj))
  -            {
  -               return;
  -            }
  -         }
  -         
  -         if (obj.toString().indexOf('$') != -1) {
  -            String current = removePreamble(obj).replace('$', '.');
  -            if (current.startsWith("class.")) {
  -               current = current.substring("class.".length());
  -            }
  -            if (current.length() == 0 || current.startsWith("array") || current.startsWith("access") || current.startsWith("this") || current.startsWith(".") || current.startsWith("constructor") || current.endsWith(".1") || current.endsWith(".2") || current.endsWith(".3") || current.endsWith(".4") || current.endsWith(".5") || current.startsWith("L")) {
  -               return;
  -            }
  -            for (int i=0; i<SIGNATURE_CHARS.length; i++) {
  -               if (current.charAt(0) == SIGNATURE_CHARS[i]) {
  -                  return;
  -               }
  -            }
  -            if (isGoodReference(current)) {
  -               listener.referenceFound(current);
  -            }
  -            return;
  -         }
  -
  -         if (obj.toString().indexOf('/') == -1) {
  -            return;
  -         }
  -
  -         String name = removePreamble(obj);
  -
  -         if (name.startsWith(".")) {
  -            return;
  -         }
  -
  -         if (name.indexOf(';') != -1) {
  -            StringTokenizer st = new StringTokenizer(name, ";");
  -            while (st.hasMoreTokens()) {
  -               String current = dropType(st.nextToken());
  -               if (isGoodReference(current)) {
  -                  listener.referenceFound(current);
  -               }
  -            }
  -            return;
  -         }
  -         if (isGoodReference(name)) {
  -            listener.referenceFound(name);
  -         }
  -      }
  -
  -      private boolean isGoodReference(String in) {
  -         if (in == null || in.length() == 0) {
  -            return false;
  -         }
  -         if (inJavaLang(in)) {
  -            return false;
  -         }
  -         if (in.endsWith(".")) {
  -            return false;
  -         }
  -         if (in.indexOf(' ') != -1 || in.indexOf('\'') != -1 || in.indexOf('*') != -1 || in.indexOf(':') != -1 || in.indexOf('(') != -1 || in.indexOf(')') != -1 || in.indexOf('<') != -1 || in.indexOf('>') != -1) {
  -            return false;
  -         }
  -         if (Character.isUpperCase(in.charAt(0))) {
  -            return false;
  -         }
  -         return true;
  -      }
  -
  -      private String cleanSignature(String in) {
  -         return dropType(slashToDot(dropSemicolon(in)));
  -      }
  -      private String dropSemicolon(String in) {
  -         return in.substring(0, in.length()-1);
  -      }
  -
  -      private String slashToDot(String in) {
  -         return in.replace('/', '.');
  -      }
  -      private String dropType(String in) {
  -         boolean foundSigChar = true;
  -         while (foundSigChar) {
  -            foundSigChar = false;
  -            if (in.length() == 0) {
  -               return in;
  -            }
  -            char current = in.charAt(0);
  -            for (int i=0; i<SIGNATURE_CHARS.length;i++) {
  -               if (current == SIGNATURE_CHARS[i]) {
  -                  in = in.substring(1);
  -                  foundSigChar = true;
  -                  break;
  -               }
  -            }
  -         }
  -         return in;
  -      }
  -
  -      private String removePreamble(Constant in) {
  -         return in.toString().substring(STD_PREAMBLE.length()-1,in.toString().length()-2).replace('/', '.');
  -      }
  -
  -      private boolean inJavaLang(String in) {
  -         return(in.startsWith("java.lang") && in.indexOf("java.lang.reflect") == -1 && in.indexOf("java.lang.ref") == -1);
  -      }
  -   }
  -
  -   public static void parse(File file, IReferenceFoundListener aListener) throws IOException, FileNotFoundException 
  -   {
  -      BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
  -      ClassParser parser = new ClassParser(bis, "hello");
  -      JavaClass clazz = parser.parse();
  -      ConstantPool pool = clazz.getConstantPool();
  -
  -      List excluded = new ArrayList();
  -      for (int i=0; i< pool.getLength(); i++)
  -      {
  -         if(pool.getConstant(i) instanceof ConstantString)
  -         {
  -            excluded.add(new Integer(((ConstantString)pool.getConstant(i)).getStringIndex()));
  -         }
  -      }
  -      bis.close();
  -      ClassRefVisitor visitor = new ClassRefVisitor(pool, aListener,excluded);
  -      DescendingVisitor vehicle = new DescendingVisitor(clazz, visitor);
  -      vehicle.visit();
  -   }
  -
  -   public static void main(String[] args) {
  -      try {
  -         parse(new File("d:\\importscrubber\\etc\\FunctionalTest.class"), new PrintListener());
  -         //parse(new File("D:\\importscrubber\\src\\net\\sourceforge\\importscrubber\\WorkingCellRenderer.class"), new PrintListener());
  -         //parse(new File("D:\\tmp\\src\\com\\arthurandersen\\storage\\UseCaseEJBStorage.class"), new PrintListener());
  -      } catch (Exception e) {
  -         e.printStackTrace();
  -      }
  -   }
  +public class ClassParserWrapper
  +{
  +    private static final char[] SIGNATURE_CHARS = new char[]{'L', 'Z', '(', ')', '[', ']', 'I', 'C', 'D'};
  +    private static final String STD_PREAMBLE = "\"CONSTANT_Utf8[1](\"";
  +
  +    private static class ClassRefVisitor extends EmptyVisitor
  +    {
  +        private IReferenceFoundListener listener;
  +        private ConstantPool constantPool;
  +        private List excludedIndexes;
  +
  +        public ClassRefVisitor(ConstantPool constantPool, IReferenceFoundListener aListener, List excludedIndexes)
  +        {
  +            this.listener = aListener;
  +            this.constantPool = constantPool;
  +            this.excludedIndexes = excludedIndexes;
  +        }
  +
  +        public void visitConstantClass(ConstantClass obj)
  +        {
  +            String current = constantPool.constantToString(obj);
  +            if (current.indexOf(';') != -1)
  +            {
  +                current = cleanSignature(current);
  +            }
  +            if (current.indexOf('(') != -1 || current.indexOf(')') != -1 || inJavaLang(current))
  +            {
  +                return;
  +            }
  +            listener.referenceFound(current);
  +        }
  +
  +        public void visitConstantUtf8(ConstantUtf8 obj)
  +        {
  +
  +            // skip the ones which we know are referred to by constant strings
  +            for (Iterator iter = excludedIndexes.iterator(); iter.hasNext();)
  +            {
  +                Constant constant = constantPool.getConstant(((Integer) iter.next()).intValue());
  +                if (constant.equals(obj))
  +                {
  +                    return;
  +                }
  +            }
  +
  +            if (obj.toString().indexOf('$') != -1)
  +            {
  +                String current = removePreamble(obj).replace('$', '.');
  +                if (current.startsWith("class."))
  +                {
  +                    current = current.substring("class.".length());
  +                }
  +                if (current.length() == 0 || current.startsWith("array") || current.startsWith("access") || current.startsWith("this") || current.startsWith(".") || current.startsWith("constructor") || current.endsWith(".1") || current.endsWith(".2") || current.endsWith(".3") || current.endsWith(".4") || current.endsWith(".5") || current.startsWith("L"))
  +                {
  +                    return;
  +                }
  +                for (int i = 0; i < SIGNATURE_CHARS.length; i++)
  +                {
  +                    if (current.charAt(0) == SIGNATURE_CHARS[i])
  +                    {
  +                        return;
  +                    }
  +                }
  +                if (isGoodReference(current))
  +                {
  +                    listener.referenceFound(current);
  +                }
  +                return;
  +            }
  +
  +            if (obj.toString().indexOf('/') == -1)
  +            {
  +                return;
  +            }
  +
  +            String name = removePreamble(obj);
  +
  +            if (name.startsWith("."))
  +            {
  +                return;
  +            }
  +
  +            if (name.indexOf(';') != -1)
  +            {
  +                StringTokenizer st = new StringTokenizer(name, ";");
  +                while (st.hasMoreTokens())
  +                {
  +                    String current = dropType(st.nextToken());
  +                    if (isGoodReference(current))
  +                    {
  +                        listener.referenceFound(current);
  +                    }
  +                }
  +                return;
  +            }
  +            if (isGoodReference(name))
  +            {
  +                listener.referenceFound(name);
  +            }
  +        }
  +
  +        private boolean isGoodReference(String in)
  +        {
  +            if (in == null || in.length() == 0)
  +            {
  +                return false;
  +            }
  +            if (inJavaLang(in))
  +            {
  +                return false;
  +            }
  +            if (in.endsWith("."))
  +            {
  +                return false;
  +            }
  +            if (in.indexOf(' ') != -1 || in.indexOf('\'') != -1 || in.indexOf('*') != -1 || in.indexOf(':') != -1 || in.indexOf('(') != -1 || in.indexOf(')') != -1 || in.indexOf('<') != -1 || in.indexOf('>') != -1)
  +            {
  +                return false;
  +            }
  +            if (Character.isUpperCase(in.charAt(0)))
  +            {
  +                return false;
  +            }
  +            return true;
  +        }
  +
  +        private String cleanSignature(String in)
  +        {
  +            return dropType(slashToDot(dropSemicolon(in)));
  +        }
  +
  +        private String dropSemicolon(String in)
  +        {
  +            return in.substring(0, in.length() - 1);
  +        }
  +
  +        private String slashToDot(String in)
  +        {
  +            return in.replace('/', '.');
  +        }
  +
  +        private String dropType(String in)
  +        {
  +            boolean foundSigChar = true;
  +            while (foundSigChar)
  +            {
  +                foundSigChar = false;
  +                if (in.length() == 0)
  +                {
  +                    return in;
  +                }
  +                char current = in.charAt(0);
  +                for (int i = 0; i < SIGNATURE_CHARS.length; i++)
  +                {
  +                    if (current == SIGNATURE_CHARS[i])
  +                    {
  +                        in = in.substring(1);
  +                        foundSigChar = true;
  +                        break;
  +                    }
  +                }
  +            }
  +            return in;
  +        }
  +
  +        private String removePreamble(Constant in)
  +        {
  +            return in.toString().substring(STD_PREAMBLE.length() - 1, in.toString().length() - 2).replace('/', '.');
  +        }
  +
  +        private boolean inJavaLang(String in)
  +        {
  +            return (in.startsWith("java.lang") && in.indexOf("java.lang.reflect") == -1 && in.indexOf("java.lang.ref") == -1);
  +        }
  +    }
  +
  +    public static void parse(File file, IReferenceFoundListener aListener) throws IOException, FileNotFoundException
  +    {
  +        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
  +        ClassParser parser = new ClassParser(bis, "hello");
  +        JavaClass clazz = parser.parse();
  +        ConstantPool pool = clazz.getConstantPool();
  +
  +        List excluded = new ArrayList();
  +        for (int i = 0; i < pool.getLength(); i++)
  +        {
  +            if (pool.getConstant(i) instanceof ConstantString)
  +            {
  +                excluded.add(new Integer(((ConstantString) pool.getConstant(i)).getStringIndex()));
  +            }
  +        }
  +        bis.close();
  +        ClassRefVisitor visitor = new ClassRefVisitor(pool, aListener, excluded);
  +        DescendingVisitor vehicle = new DescendingVisitor(clazz, visitor);
  +        vehicle.visit();
  +    }
  +
  +    public static void main(String[] args)
  +    {
  +        try
  +        {
  +            parse(new File("d:\\importscrubber\\etc\\FunctionalTest.class"), new PrintListener());
  +            //parse(new File("D:\\importscrubber\\src\\net\\sourceforge\\importscrubber\\WorkingCellRenderer.class"), new PrintListener());
  +            //parse(new File("D:\\tmp\\src\\com\\arthurandersen\\storage\\UseCaseEJBStorage.class"), new PrintListener());
  +        }
  +        catch (Exception e)
  +        {
  +            e.printStackTrace();
  +        }
  +    }
   }
   
  
  
  
  1.3       +8 -4      jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/ConsoleProgressMonitor.java
  
  Index: ConsoleProgressMonitor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/ConsoleProgressMonitor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ConsoleProgressMonitor.java	21 Feb 2002 14:00:16 -0000	1.2
  +++ ConsoleProgressMonitor.java	24 Feb 2002 12:18:32 -0000	1.3
  @@ -56,10 +56,14 @@
   
   public class ConsoleProgressMonitor implements IProgressMonitor
   {
  -   public void taskStarted(ScrubTask task) {
  -      System.out.print(".");
  -   }
  -   public void taskComplete(ScrubTask task) {}
  +    public void taskStarted(ScrubTask task)
  +    {
  +        System.out.print(".");
  +    }
  +
  +    public void taskComplete(ScrubTask task)
  +    {
  +    }
   }
   
   
  
  
  
  1.3       +50 -49    jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/FilePair.java
  
  Index: FilePair.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/FilePair.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FilePair.java	21 Feb 2002 14:00:16 -0000	1.2
  +++ FilePair.java	24 Feb 2002 12:18:32 -0000	1.3
  @@ -67,57 +67,58 @@
   public class FilePair
   {
   
  -   /**
  -    * A filter which only accepts inner classes.
  -    */
  -   private class InnerClassFilter implements FilenameFilter
  -   {
  -      public boolean accept(File dir, String name) 
  -      {
  -         // make sure we only get inner classes
  -         if (name.indexOf("$") == -1)
  -         {
  -            return false;
  -         }
  -         // make sure we get this class's inner classes
  -         String className = _classFile.getName();
  -         className = className.substring(0, className.indexOf("."));
  -         return name.startsWith(className);
  -      }
  -   }
  -   private File _sourceFile;
  -   private File _classFile;
  +    /**
  +     * A filter which only accepts inner classes.
  +     */
  +    private class InnerClassFilter implements FilenameFilter
  +    {
  +        public boolean accept(File dir, String name)
  +        {
  +            // make sure we only get inner classes
  +            if (name.indexOf("$") == -1)
  +            {
  +                return false;
  +            }
  +            // make sure we get this class's inner classes
  +            String className = _classFile.getName();
  +            className = className.substring(0, className.indexOf("."));
  +            return name.startsWith(className);
  +        }
  +    }
   
  -   /**
  -    * 
  -    * @param sourceFile
  -    * @param classFile
  -    */
  -   public FilePair(File sourceFile, File classFile)
  -   {
  -      _sourceFile = sourceFile;
  -      _classFile = classFile;
  -   }
  +    private File _sourceFile;
  +    private File _classFile;
   
  -   public File getSourceFile()
  -   {
  -      return _sourceFile;
  -   }
  +    /**
  +     *
  +     * @param sourceFile
  +     * @param classFile
  +     */
  +    public FilePair(File sourceFile, File classFile)
  +    {
  +        _sourceFile = sourceFile;
  +        _classFile = classFile;
  +    }
   
  -   public ListIterator getClassFiles()
  -   {
  -      List files = new ArrayList();
  -      files.add(_classFile);
  -      if (_classFile.getParent() != null)
  -      {
  -         File dir = new File(_classFile.getParent());
  -         files.addAll(Arrays.asList(dir.listFiles(new InnerClassFilter())));
  -      }
  -      return files.listIterator();
  -   }
  +    public File getSourceFile()
  +    {
  +        return _sourceFile;
  +    }
   
  -   public String toString()
  -   {
  -      return _sourceFile.getAbsolutePath();
  -   }
  +    public ListIterator getClassFiles()
  +    {
  +        List files = new ArrayList();
  +        files.add(_classFile);
  +        if (_classFile.getParent() != null)
  +        {
  +            File dir = new File(_classFile.getParent());
  +            files.addAll(Arrays.asList(dir.listFiles(new InnerClassFilter())));
  +        }
  +        return files.listIterator();
  +    }
  +
  +    public String toString()
  +    {
  +        return _sourceFile.getAbsolutePath();
  +    }
   }
  
  
  
  1.3       +11 -8     jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/FindCommand.java
  
  Index: FindCommand.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/FindCommand.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FindCommand.java	21 Feb 2002 14:00:16 -0000	1.2
  +++ FindCommand.java	24 Feb 2002 12:18:32 -0000	1.3
  @@ -62,13 +62,16 @@
    */
   public class FindCommand implements ActionListener
   {
  -   private ImportScrubberGUI receiver;
  -   public FindCommand(ImportScrubberGUI receiver) {
  -      this.receiver = receiver;
  -   }
  -   public void actionPerformed(ActionEvent e) 
  -   {
  -      receiver.find();
  -   }
  +    private ImportScrubberGUI receiver;
  +
  +    public FindCommand(ImportScrubberGUI receiver)
  +    {
  +        this.receiver = receiver;
  +    }
  +
  +    public void actionPerformed(ActionEvent e)
  +    {
  +        receiver.find();
  +    }
   }
   
  
  
  
  1.3       +11 -8     jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/GoCommand.java
  
  Index: GoCommand.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/GoCommand.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GoCommand.java	21 Feb 2002 14:00:16 -0000	1.2
  +++ GoCommand.java	24 Feb 2002 12:18:32 -0000	1.3
  @@ -62,13 +62,16 @@
    */
   public class GoCommand implements ActionListener
   {
  -   private ImportScrubberGUI receiver;
  -   public GoCommand(ImportScrubberGUI receiver) {
  -      this.receiver = receiver;
  -   }
  -   public void actionPerformed(ActionEvent e) 
  -   {
  -      receiver.go();
  -   }
  +    private ImportScrubberGUI receiver;
  +
  +    public GoCommand(ImportScrubberGUI receiver)
  +    {
  +        this.receiver = receiver;
  +    }
  +
  +    public void actionPerformed(ActionEvent e)
  +    {
  +        receiver.go();
  +    }
   }
   
  
  
  
  1.3       +176 -157  jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/ImportScrubber.java
  
  Index: ImportScrubber.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/importscrubber/ImportScrubber.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ImportScrubber.java	21 Feb 2002 14:00:16 -0000	1.2
  +++ ImportScrubber.java	24 Feb 2002 12:18:32 -0000	1.3
  @@ -59,6 +59,7 @@
   import java.util.ArrayList;
   import java.util.List;
   import java.util.ListIterator;
  +
   import org.apache.maven.importscrubber.filechooser.AllInDirectoryFileChooser;
   import org.apache.maven.importscrubber.filechooser.DualRootSingleFileChooser;
   import org.apache.maven.importscrubber.filechooser.IFileChooser;
  @@ -72,162 +73,180 @@
    */
   public class ImportScrubber
   {
  -   public static final String FILE_SEPARATOR = System.getProperty("file.separator");
  -   public static final String LINE_SEPARATOR = System.getProperty("line.separator");
  -   public static boolean DEBUG = false;
  -   private IFileChooser _fileChooser;
  -   private List _tasks = new ArrayList();
  -   private IStatementFormat _format;
  -
  -   public void setFileRoot(String filename, boolean recurse)
  -   {
  -      File file = new File(filename);
  -      if (file.isDirectory())
  -      {
  -         if (recurse)
  -         {
  -            _fileChooser = new RecursiveFileChooser();
  -         }
  -         else
  -         {
  -            _fileChooser = new AllInDirectoryFileChooser();
  -         }
  -      }
  -      else
  -      {
  -         _fileChooser = new SingleFileChooser();
  -      }
  -      _fileChooser.setRoot(filename);
  -   }
  -
  -   public void setFileRoot(String sourceRoot, String classRoot, String fileName)
  -   {
  -      _fileChooser = new DualRootSingleFileChooser(sourceRoot, classRoot, fileName);
  -   }
  -   
  -   public void setFormat(IStatementFormat format) {
  -      _format = format;
  -   }
  -
  -   public void debugOff() {
  -      DEBUG = false;
  -   }
  -
  -   public void debug() {
  -      DEBUG = true;
  -   }
  -
  -   public int getTaskCount() {
  -      return _tasks.size();
  -   }
  -
  -   public List getFiles() {
  -      return _fileChooser.getFiles();
  -   }
  -
  -   public void buildTasks() throws IOException {
  -      List list = _fileChooser.getFiles();
  -      for (ListIterator iter = list.listIterator(); iter.hasNext();)
  -      {
  -         FilePair pair = (FilePair)iter.next();
  -         _tasks.add(new ScrubTask(pair, _format));
  -      }
  -   }
  -
  -   public void runTasks(IProgressMonitor monitor) throws IOException {
  -      for (ListIterator iter = _tasks.listIterator(); iter.hasNext();)
  -      {
  -         ScrubTask task = (ScrubTask)iter.next();
  -         monitor.taskStarted(task);
  -         task.run();
  -         monitor.taskComplete(task);
  -      }
  -      _tasks.clear();
  -   }
  -
  -   public static void main(String[] args)
  -   {
  -      if (argExists("g",args))
  -      {
  -         ImportScrubberGUI gui = new ImportScrubberGUI();
  -         return;
  -      }
  -      if (!argExists("root", args))
  -      {
  -         usage();
  -         System.exit(0);
  -      }
  -      String root = findArg("root",args);
  -      if (!(new File(root).exists()))
  -      {
  -         System.out.println("Root: " + root + " does not exist");
  -         usage();
  -         System.exit(0);
  -      }
  -      boolean recurse = argExists("recurse", args);
  -      IStatementFormat format = null;
  -      if (!argExists("format", args)) {
  -         format = StatementFormatFactory.getInstance().createStatementFormat(StatementFormatFactory.DEFAULT);
  -      } else {
  -         format = StatementFormatFactory.getInstance().createStatementFormat(findArg("format",args));
  -      }
  -      format.sortJavaLibsHigh(argExists("sortjavalibshigh", args));
  -
  -      try {
  -         ImportScrubber scrubber = new ImportScrubber();
  -         
  -         if(argExists("classesRoot", args) )
  -         {
  -           String sourcesRootStr = findArg( "sourcesRoot", args );
  -           String classesRootStr= findArg( "classesRoot", args );
  -           String sourceFilenameStr = root;
  -           scrubber.setFileRoot(sourcesRootStr, classesRootStr, sourceFilenameStr); 
  -         }  else
  -         {
  -            scrubber.setFileRoot(root, recurse);
  -         }
  -
  -         scrubber.setFormat(format);
  -         System.out.println("Building file list");
  -         List files = scrubber.getFiles();
  -         System.out.println("Building tasks");
  -         scrubber.buildTasks();
  -         System.out.println("Processing " + files.size() + " files");
  -         scrubber.runTasks(new ConsoleProgressMonitor());
  -         System.out.println(LINE_SEPARATOR + "All done!");
  -      } catch (Exception e) {
  -         e.printStackTrace();
  -      }
  -   }
  -   
  -   private static boolean argExists(String argFlag, String[] args)
  -   {
  -      for (int i=0; i<args.length; i++) {
  -         if (args[i].equals("-"+argFlag)) {
  -            return true;
  -         }
  -      }
  -      return false;
  -   }    
  -
  -   private static String findArg(String argFlag, String[] args)
  -   {
  -      for (int i=0; i<args.length; i++) {
  -         if (args[i].equals("-"+argFlag)) {
  -            return args[i+1];
  -         }
  -      }
  -      throw new IllegalArgumentException("Couldn't find " + argFlag);
  -   }
  -
  -   private static void usage()
  -   {
  -      System.out.println("Usage: java org.apache.maven.importscrubber.ImportScrubber -root [rootDir | file] [-recurse] [-format each|top|nobreaks] [-g]");
  -      System.out.println("Ex: java org.apache.maven.importscrubber.ImportScrubber -root /home/me/myproject/src -recurse -format nobreaks -sortjavalibshigh");
  -      System.out.println("Ex: java org.apache.maven.importscrubber.ImportScrubber -root d:\\project\\src\\Foo.java");
  -      System.out.println("Ex: java org.apache.maven.importscrubber.ImportScrubber -root d:\\importscrubber\\etc\\FunctionalTest.java -classesRoot d:\\importscrubber\\build -sourcesRoot d:\\importscrubber\\etc\\ ");
  -      System.out.println("\r\nOR, TO USE THE GUI:\r\n");
  -      System.out.println("java org.apache.maven.importscrubber.ImportScrubber -g");
  -   }
  +    public static final String FILE_SEPARATOR = System.getProperty("file.separator");
  +    public static final String LINE_SEPARATOR = System.getProperty("line.separator");
  +    public static boolean DEBUG = false;
  +    private IFileChooser _fileChooser;
  +    private List _tasks = new ArrayList();
  +    private IStatementFormat _format;
  +
  +    public void setFileRoot(String filename, boolean recurse)
  +    {
  +        File file = new File(filename);
  +        if (file.isDirectory())
  +        {
  +            if (recurse)
  +            {
  +                _fileChooser = new RecursiveFileChooser();
  +            }
  +            else
  +            {
  +                _fileChooser = new AllInDirectoryFileChooser();
  +            }
  +        }
  +        else
  +        {
  +            _fileChooser = new SingleFileChooser();
  +        }
  +        _fileChooser.setRoot(filename);
  +    }
  +
  +    public void setFileRoot(String sourceRoot, String classRoot, String fileName)
  +    {
  +        _fileChooser = new DualRootSingleFileChooser(sourceRoot, classRoot, fileName);
  +    }
  +
  +    public void setFormat(IStatementFormat format)
  +    {
  +        _format = format;
  +    }
  +
  +    public void debugOff()
  +    {
  +        DEBUG = false;
  +    }
  +
  +    public void debug()
  +    {
  +        DEBUG = true;
  +    }
  +
  +    public int getTaskCount()
  +    {
  +        return _tasks.size();
  +    }
  +
  +    public List getFiles()
  +    {
  +        return _fileChooser.getFiles();
  +    }
  +
  +    public void buildTasks() throws IOException
  +    {
  +        List list = _fileChooser.getFiles();
  +        for (ListIterator iter = list.listIterator(); iter.hasNext();)
  +        {
  +            FilePair pair = (FilePair) iter.next();
  +            _tasks.add(new ScrubTask(pair, _format));
  +        }
  +    }
  +
  +    public void runTasks(IProgressMonitor monitor) throws IOException
  +    {
  +        for (ListIterator iter = _tasks.listIterator(); iter.hasNext();)
  +        {
  +            ScrubTask task = (ScrubTask) iter.next();
  +            monitor.taskStarted(task);
  +            task.run();
  +            monitor.taskComplete(task);
  +        }
  +        _tasks.clear();
  +    }
  +
  +    public static void main(String[] args)
  +    {
  +        if (argExists("g", args))
  +        {
  +            ImportScrubberGUI gui = new ImportScrubberGUI();
  +            return;
  +        }
  +        if (!argExists("root", args))
  +        {
  +            usage();
  +            System.exit(0);
  +        }
  +        String root = findArg("root", args);
  +        if (!(new File(root).exists()))
  +        {
  +            System.out.println("Root: " + root + " does not exist");
  +            usage();
  +            System.exit(0);
  +        }
  +        boolean recurse = argExists("recurse", args);
  +        IStatementFormat format = null;
  +        if (!argExists("format", args))
  +        {
  +            format = StatementFormatFactory.getInstance().createStatementFormat(StatementFormatFactory.DEFAULT);
  +        }
  +        else
  +        {
  +            format = StatementFormatFactory.getInstance().createStatementFormat(findArg("format", args));
  +        }
  +        format.sortJavaLibsHigh(argExists("sortjavalibshigh", args));
  +
  +        try
  +        {
  +            ImportScrubber scrubber = new ImportScrubber();
  +
  +            if (argExists("classesRoot", args))
  +            {
  +                String sourcesRootStr = findArg("sourcesRoot", args);
  +                String classesRootStr = findArg("classesRoot", args);
  +                String sourceFilenameStr = root;
  +                scrubber.setFileRoot(sourcesRootStr, classesRootStr, sourceFilenameStr);
  +            }
  +            else
  +            {
  +                scrubber.setFileRoot(root, recurse);
  +            }
  +
  +            scrubber.setFormat(format);
  +            System.out.println("Building file list");
  +            List files = scrubber.getFiles();
  +            System.out.println("Building tasks");
  +            scrubber.buildTasks();
  +            System.out.println("Processing " + files.size() + " files");
  +            scrubber.runTasks(new ConsoleProgressMonitor());
  +            System.out.println(LINE_SEPARATOR + "All done!");
  +        }
  +        catch (Exception e)
  +        {
  +            e.printStackTrace();
  +        }
  +    }
  +
  +    private static boolean argExists(String argFlag, String[] args)
  +    {
  +        for (int i = 0; i < args.length; i++)
  +        {
  +            if (args[i].equals("-" + argFlag))
  +            {
  +                return true;
  +            }
  +        }
  +        return false;
  +    }
  +
  +    private static String findArg(String argFlag, String[] args)
  +    {
  +        for (int i = 0; i < args.length; i++)
  +        {
  +            if (args[i].equals("-" + argFlag))
  +            {
  +                return args[i + 1];
  +            }
  +        }
  +        throw new IllegalArgumentException("Couldn't find " + argFlag);
  +    }
  +
  +    private static void usage()
  +    {
  +        System.out.println("Usage: java org.apache.maven.importscrubber.ImportScrubber -root [rootDir | file] [-recurse] [-format each|top|nobreaks] [-g]");
  +        System.out.println("Ex: java org.apache.maven.importscrubber.ImportScrubber -root /home/me/myproject/src -recurse -format nobreaks -sortjavalibshigh");
  +        System.out.println("Ex: java org.apache.maven.importscrubber.ImportScrubber -root d:\\project\\src\\Foo.java");
  +        System.out.println("Ex: java org.apache.maven.importscrubber.ImportScrubber -root d:\\importscrubber\\etc\\FunctionalTest.java -classesRoot d:\\importscrubber\\build -sourcesRoot d:\\importscrubber\\etc\\ ");
  +        System.out.println("\r\nOR, TO USE THE GUI:\r\n");
  +        System.out.println("java org.apache.maven.importscrubber.ImportScrubber -g");
  +    }
   }
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>