FileDocCategorySizeDatePackage
ApiCheck.javaAPI DocAndroid 1.5 API12719Wed May 06 22:41:00 BST 2009com.android.apicheck

ApiCheck

public class ApiCheck extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] originalArgs)

            // translate to an ArrayList<String> for munging
            ArrayList<String> args = new ArrayList<String>(originalArgs.length);
            for (String a: originalArgs) {
                args.add(a);
            }

            ArrayList<String[]> flags = ApiCheck.parseFlags(args);
            for (String[] a: flags) {
                if (a[0].equals("-error") || a[0].equals("-warning")
                        || a[0].equals("-hide")) {
                    try {
                        int level = -1;
                        if (a[0].equals("-error")) {
                            level = Errors.ERROR;
                        }
                        else if (a[0].equals("-warning")) {
                            level = Errors.WARNING;
                        }
                        else if (a[0].equals("-hide")) {
                            level = Errors.HIDDEN;
                        }
                        Errors.setErrorLevel(Integer.parseInt(a[1]), level);
                    }
                    catch (NumberFormatException e) {
                        System.err.println("Bad argument: " + a[0] + " " + a[1]);
                        System.exit(2);
                    }
                }
            }

            String xmlFileName = args.get(0);
            String xmlFileNameNew = args.get(1);
            XMLReader xmlreader = null;
            try {
                // parse the XML files into our data structures
                xmlreader = XMLReaderFactory.createXMLReader();
                ApiCheck acheck = new ApiCheck();
                MakeHandler handler = acheck.new MakeHandler();
                xmlreader.setContentHandler(handler);
                xmlreader.setErrorHandler(handler);
                FileReader filereader = new FileReader(xmlFileName);
                xmlreader.parse(new InputSource(filereader));
                FileReader filereaderNew = new FileReader(xmlFileNameNew);
                xmlreader.parse(new InputSource(filereaderNew));

                // establish the superclass relationships
                handler.getOldApi().resolveSuperclasses();
                handler.getNewApi().resolveSuperclasses();
                
                // finally, run the consistency check
                handler.getOldApi().isConsistent(handler.getNewApi());

            } catch (SAXParseException e) {
                Errors.error(Errors.PARSE_ERROR,
                        new SourcePositionInfo(xmlFileName, e.getLineNumber(), 0),
                        e.getMessage());
            } catch (Exception e) {
                e.printStackTrace();
                Errors.error(Errors.PARSE_ERROR,
                        new SourcePositionInfo(xmlFileName, 0, 0),
                        e.getMessage());
            } 

            Errors.printErrors();
            System.exit(Errors.hadError ? 1 : 0);
        
private static java.util.ArrayListparseFlags(java.util.ArrayList allArgs)

            ArrayList<String[]> ret = new ArrayList<String[]>();

            int i;
            for (i = 0; i < allArgs.size(); i++) {
                // flags with one value attached
                String flag = allArgs.get(i);
                if (flag.equals("-error")
                        || flag.equals("-warning")
                        || flag.equals("-hide")) {
                    String[] arg = new String[2];
                    arg[0] = flag;
                    arg[1] = allArgs.get(++i);
                    ret.add(arg);
                } else {
                    // we've consumed all of the -whatever args, so we're done
                    break;
                }
            }

            // i now points to the first non-flag arg; strip what came before
            for (; i > 0; i--) {
                allArgs.remove(0);
            }
            return ret;