[Clirr-devel] CVS: clirr/src/java/net/sf/clirr/cli Clirr.java,1.1,1.2
Status: Alpha
Brought to you by:
lkuehne
From: <lk...@us...> - 2004-06-13 10:26:12
|
Update of /cvsroot/clirr/clirr/src/java/net/sf/clirr/cli In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12592 Modified Files: Clirr.java Log Message: cleanup - remove unused imports - avoid unused variable showAll - trailing spaces, brace position and indentation Index: Clirr.java =================================================================== RCS file: /cvsroot/clirr/clirr/src/java/net/sf/clirr/cli/Clirr.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Clirr.java 11 Jun 2004 00:03:49 -0000 1.1 +++ Clirr.java 13 Jun 2004 10:26:02 -0000 1.2 @@ -1,6 +1,6 @@ ////////////////////////////////////////////////////////////////////////////// // Clirr: compares two versions of a java library for binary compatibility -// Copyright (C) 2003 - 2004 Lars K?hne +// Copyright (C) 2003 - 2004 Lars Kühne // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -19,119 +19,115 @@ package net.sf.clirr.cli; +import net.sf.clirr.Checker; +import net.sf.clirr.event.DiffListener; +import net.sf.clirr.event.PlainDiffListener; +import net.sf.clirr.event.XmlDiffListener; +import net.sf.clirr.framework.CheckerException; +import net.sf.clirr.framework.ClassSelector; import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Options; import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import java.io.File; -import java.io.PrintWriter; import java.io.IOException; - -import java.util.Arrays; -import java.util.ArrayList; +import java.io.PrintWriter; import java.net.URL; -import java.net.MalformedURLException; import java.net.URLClassLoader; - -import net.sf.clirr.Checker; -import net.sf.clirr.event.DiffListener; -import net.sf.clirr.event.PlainDiffListener; -import net.sf.clirr.event.XmlDiffListener; -import net.sf.clirr.event.ScopeSelector; -import net.sf.clirr.framework.ClassSelector; -import net.sf.clirr.framework.CheckerException; +import java.util.ArrayList; /** * Commandline interface for generating a difference report or checking * for binary compatibility between two versions of the same application. */ - public class Clirr { +public class Clirr +{ + + private static final File[] EMPTY_FILE_ARRAY = new File[]{}; - private static final File[] EMPTY_FILE_ARRAY = new File[]{}; - // =================================================================== - - public static void main(String[] args) - { - new Clirr().run(args); - } - - // =================================================================== - - private void run(String[] args) - { + + public static void main(String[] args) + { + new Clirr().run(args); + } + + // =================================================================== + + private void run(String[] args) + { System.out.println("reporting diffs.."); - BasicParser parser = new BasicParser(); - Options options = new Options(); - options.addOption("o", "oldversion", true, "jar files of old version"); - options.addOption("n", "newversion", true, "jar files of new version"); - options.addOption("s", "style", true, "output style"); - options.addOption("a", "show-all-scopes", false, "show private and package classes"); - options.addOption("f", "output-file", true, "output file name"); - - CommandLine cmdline = null; - try - { - cmdline = parser.parse(options, args); - } - catch(ParseException ex) - { - System.err.println("Invalid command line arguments."); - usage(options); - System.exit(-1); - } - - // TODO: provide commandline options that allow the user to - // specify which packages/classes should be checked - // - ClassSelector classSelector = new ClassSelector(ClassSelector.MODE_UNLESS); - - String oldPath = cmdline.getOptionValue('o'); - String newPath = cmdline.getOptionValue('n'); - String style = cmdline.getOptionValue('s', "text"); - String outputFileName = cmdline.getOptionValue('f'); - boolean showAll = cmdline.hasOption('a'); - - if ((oldPath == null) || (newPath == null)) - { - usage(options); - System.exit(-1); - } - + BasicParser parser = new BasicParser(); + Options options = new Options(); + options.addOption("o", "oldversion", true, "jar files of old version"); + options.addOption("n", "newversion", true, "jar files of new version"); + options.addOption("s", "style", true, "output style"); + options.addOption("a", "show-all-scopes", false, "show private and package classes"); + options.addOption("f", "output-file", true, "output file name"); + + CommandLine cmdline = null; + try + { + cmdline = parser.parse(options, args); + } + catch (ParseException ex) + { + System.err.println("Invalid command line arguments."); + usage(options); + System.exit(-1); + } + + // TODO: provide commandline options that allow the user to + // specify which packages/classes should be checked + // + ClassSelector classSelector = new ClassSelector(ClassSelector.MODE_UNLESS); + + String oldPath = cmdline.getOptionValue('o'); + String newPath = cmdline.getOptionValue('n'); + String style = cmdline.getOptionValue('s', "text"); + String outputFileName = cmdline.getOptionValue('f'); + boolean showAll = cmdline.hasOption('a'); + + if ((oldPath == null) || (newPath == null)) + { + usage(options); + System.exit(-1); + } + Checker checker = new Checker(); - if (cmdline.hasOption('a')) + if (showAll) { - checker.getScopeSelector().selectPrivate(true); - checker.getScopeSelector().selectPackage(true); + checker.getScopeSelector().selectPrivate(true); + checker.getScopeSelector().selectPackage(true); } - - DiffListener diffListener = null; - if (style.equals("text")) + + DiffListener diffListener = null; + if (style.equals("text")) { try { diffListener = new PlainDiffListener(outputFileName); } - catch(IOException ex) + catch (IOException ex) { System.err.println("Invalid output file name."); } - } - else if (style.equals("xml")) + } + else if (style.equals("xml")) { try { diffListener = new XmlDiffListener(outputFileName); } - catch(IOException ex) + catch (IOException ex) { System.err.println("Invalid output file name."); } - } - else + } + else { System.err.println("Invalid style option. Must be one of 'text', 'xml'."); usage(options); @@ -140,51 +136,50 @@ File[] origJars = pathToFileArray(oldPath); File[] newJars = pathToFileArray(newPath); - - ClassLoader loader1 = new URLClassLoader(new URL[] {}); - ClassLoader loader2 = new URLClassLoader(new URL[] {}); + + ClassLoader loader1 = new URLClassLoader(new URL[]{}); + ClassLoader loader2 = new URLClassLoader(new URL[]{}); checker.addDiffListener(diffListener); - + try { checker.reportDiffs(origJars, newJars, loader1, loader2, classSelector); } - catch(CheckerException ex) + catch (CheckerException ex) { System.err.println("Unable to complete checks:" + ex.getMessage()); System.exit(1); } - } - - private void usage(Options options) - { - HelpFormatter hf = new HelpFormatter(); - PrintWriter out = new PrintWriter(System.err); - hf.printHelp( - 75, - "java net.sf.clirr.cmdline.CheckRunner -o path -n path [options]", - null, options, null); - } - - private File[] pathToFileArray(String path) - { - ArrayList files = new ArrayList(); - - int pos = 0; - while (pos < path.length()) - { - int colonPos = path.indexOf(pos, ':'); - if (colonPos == -1) - { - files.add(new File(path.substring(pos))); - break; - } - - files.add(new File(path.substring(pos, colonPos))); - pos = colonPos + 1; - } - - return (File[]) files.toArray(EMPTY_FILE_ARRAY); - } -} \ No newline at end of file + } + + private void usage(Options options) + { + HelpFormatter hf = new HelpFormatter(); + PrintWriter out = new PrintWriter(System.err); + hf.printHelp(75, + "java " + getClass().getName() + " -o path -n path [options]", + null, options, null); + } + + private File[] pathToFileArray(String path) + { + ArrayList files = new ArrayList(); + + int pos = 0; + while (pos < path.length()) + { + int colonPos = path.indexOf(pos, ':'); + if (colonPos == -1) + { + files.add(new File(path.substring(pos))); + break; + } + + files.add(new File(path.substring(pos, colonPos))); + pos = colonPos + 1; + } + + return (File[]) files.toArray(EMPTY_FILE_ARRAY); + } +} |