Logo Search packages:      
Sourcecode: jardiff version File versions  Download package

static void org::osjava::jardiff::Main::main ( String[]  args  )  throws Exception [inline, static]

Main method to allow this to be run from the command line. This needs work, currently only takes two arguments, which are the old jar file and the new jar file.

Parameters:
args A string array of length two containing the filenames of two jar files, the first of which being the older of the two.
Exceptions:
Exception when there is an underlying exception, e.g. writing to a file caused an IOException

Definition at line 117 of file Main.java.

References org::osjava::jardiff::JarDiff::diff(), FORMATS, org::osjava::jardiff::JarDiff::loadNewClasses(), org::osjava::jardiff::JarDiff::loadOldClasses(), org::osjava::jardiff::JarDiff::setNewVersion(), org::osjava::jardiff::JarDiff::setOldVersion(), and showHelp().

                                                            {
        try {
            Options options = new Options();
            Option tmp;
            tmp = new Option("f","from",true,"from jar file");
            options.addOption(tmp);
            tmp = new Option("t","to",true,"to jar file");
            options.addOption(tmp);
            tmp = new Option("F","from-name",true,"from name");
            options.addOption(tmp);
            tmp = new Option("T","to-name",true,"to name");
            options.addOption(tmp);
            //tmp = new Option("d","dep",true,"dependency path");
            //options.addOption(tmp);
            tmp = new Option("o","output-format",true,"output format, xml or html");
            options.addOption(tmp);
            tmp = new Option("O","out",true,"output file");
            options.addOption(tmp);
            tmp = new Option("h","help",false,"print help on command line arguments");
            options.addOption(tmp);
            tmp = new Option("x","xsl",true,"custom xsl sheet to format output with");
            options.addOption(tmp);
            tmp = new Option("s","stylesheet",true,"stylesheet to link to when generating html");
            options.addOption(tmp);
            tmp = new Option("fa","from-api",true,"relative location of from api");
            options.addOption(tmp);
            tmp = new Option("ta","to-api",true,"relative location of to api");
            options.addOption(tmp);
            Parser parser = new GnuParser();
            CommandLine cli = null;
            try {
                cli = parser.parse(options, args);
            } catch (ParseException pe) {
                showHelp(options, pe.getMessage());
                return;
            }
            args = cli.getArgs();
            if(cli.hasOption('h'))
            {
                showHelp(options, null);
                return;
            }
            if(args.length > 0) {
                showHelp(options, "Additional arguments specified");
                return;
            }
            if(!cli.hasOption('f')) {
                showHelp(options, "Missing required argument: -f");
                return;
            }
            if(!cli.hasOption('t')) {
                showHelp(options, "Missing required argument: -t");
                return;
            }

            TransformerFactory tf = TransformerFactory.newInstance();
            tf.setErrorListener(
                    new ErrorListener() {
                        public void warning(TransformerException te) {
                            System.err.println("xslt warning: "+te.getMessageAndLocation());
                        }
                        public void error(TransformerException te) {
                            System.err.println("xslt error: "+te.getMessageAndLocation());
                        }
                        public void fatalError(TransformerException te) {
                            System.err.println("xslt fatal error: "+te.getMessageAndLocation());
                        }
                    });
            Transformer ot;
            if(cli.hasOption('o')) {
                if(cli.hasOption('x')) {
                    showHelp(options, "Cannot use both -x and -o");
                    return;
                }
                String val = cli.getOptionValue('o');
                if("xml".equals(val)) {
                    ot = tf.newTransformer();
                } else if(FORMATS.contains(val)) {
                    URL url = JarDiff.class.getClassLoader()
                        .getResource("style/jardiff-"+val+".xsl");
                    ot = tf.newTransformer(
                            new StreamSource( url.toString() )
                            );
                } else {
                    showHelp(options, "Invalid output format: "+val);
                    return;
                }
            } else if(cli.hasOption('x')) {
                File xsl = new File(cli.getOptionValue('x'));
                ot = tf.newTransformer(new StreamSource(xsl));
            } else {
                ot = tf.newTransformer();
            }
            if(cli.hasOption("s")) {
                ot.setParameter("stylesheet", cli.getOptionValue("s"));
            }
            if(cli.hasOption("fa")) {
                ot.setParameter("from-api", cli.getOptionValue("fa"));
            }
            if(cli.hasOption("ta")) {
                ot.setParameter("to-api", cli.getOptionValue("ta"));
            }
            OutputStream out;
            if(cli.hasOption('O')) {
                out = new FileOutputStream(cli.getOptionValue('O'));
            } else {
                out = System.out;
            }
            JarDiff jd = new JarDiff();
            File oldFile = new File(cli.getOptionValue('f'));
            File newFile = new File(cli.getOptionValue('t'));
            if(cli.hasOption('F')) {
                jd.setOldVersion(cli.getOptionValue('F'));
            } else {
                jd.setOldVersion(oldFile.getName());
            }
            if(cli.hasOption('T')) {
                jd.setNewVersion(cli.getOptionValue('T'));
            } else {
                jd.setNewVersion(newFile.getName());
            }
            jd.loadOldClasses(oldFile);
            jd.loadNewClasses(newFile);
            jd.diff(
                    new DOMDiffHandler(ot, new StreamResult(out)), 
                    new SimpleDiffCriteria()
                    );
            out.close();
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }
    }


Generated by  Doxygen 1.6.0   Back to index