1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.cts.javascanner; 17 18 import java.io.File; 19 import java.util.Arrays; 20 21 /** 22 * Class that searches a source directory for native gTests and outputs a 23 * list of test classes and methods. 24 */ 25 public class CtsJavaScanner { 26 27 private static void usage(String[] args) { 28 System.err.println("Arguments: " + Arrays.asList(args)); 29 System.err.println("Usage: cts-java-scanner -s SOURCE_DIR -d DOCLET_PATH"); 30 System.exit(1); 31 } 32 33 public static void main(String[] args) throws Exception { 34 File sourceDir = null; 35 File docletPath = null; 36 37 for (int i = 0; i < args.length; i++) { 38 if ("-s".equals(args[i])) { 39 sourceDir = new File(getArg(args, ++i, "Missing value for source directory")); 40 } else if ("-d".equals(args[i])) { 41 docletPath = new File(getArg(args, ++i, "Missing value for docletPath")); 42 } else { 43 System.err.println("Unsupported flag: " + args[i]); 44 usage(args); 45 } 46 } 47 48 if (sourceDir == null) { 49 System.err.println("Source directory is required"); 50 usage(args); 51 } 52 53 if (docletPath == null) { 54 System.err.println("Doclet path is required"); 55 usage(args); 56 } 57 58 DocletRunner runner = new DocletRunner(sourceDir, docletPath); 59 System.exit(runner.runJavaDoc()); 60 } 61 62 private static String getArg(String[] args, int index, String message) { 63 if (index < args.length) { 64 return args[index]; 65 } else { 66 System.err.println(message); 67 usage(args); 68 return null; 69 } 70 } 71 } 72