001 /* 002 Copyright (C) 2004 Laurent Martelli <laurent@aopsys.com> 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public 015 License along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 017 USA */ 018 019 package org.objectweb.jac.util; 020 021 import java.io.FilenameFilter; 022 import java.io.IOException; 023 import java.util.Iterator; 024 import java.util.List; 025 import net.sf.just4log.JustLog; 026 import org.apache.log4j.BasicConfigurator; 027 import org.apache.log4j.Level; 028 import org.apache.log4j.Logger; 029 import org.objectweb.jac.util.File; 030 import org.objectweb.jac.util.Files; 031 032 /** 033 * Command line tool to perform log optimization with just4log 034 */ 035 public class SpeedLog { 036 /** 037 * Usage: <code>java org.objectweb.jac.util.SpeedLog <dir> [<dir> ...]</code> 038 * 039 * <p>Recursively optimize the loger invocations of in all .class files.</p> 040 */ 041 public static void main(String[] args) throws IOException { 042 BasicConfigurator.configure(); 043 Logger.getRootLogger().setLevel(Level.WARN); 044 045 for (int i=0; i<args.length; i++) 046 { 047 File file = new File(args[i]); 048 if (file.isDirectory()) { 049 List classes = 050 file.listFilesRecursively( 051 Files.extensionFilenamFilter(".class")); 052 Iterator it = classes.iterator(); 053 while(it.hasNext()) { 054 File classFile = (File)it.next(); 055 try { 056 JustLog.speedup(classFile,classFile); 057 } catch(Exception e) { 058 System.out.println("Failed to speed "+classFile); 059 } 060 } 061 } else { 062 try { 063 JustLog.speedup(file,file); 064 } catch(Exception e) { 065 System.out.println("Failed to speed "+file); 066 } 067 } 068 } 069 } 070 }