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.ArrayList; 20 import java.util.Arrays; 21 import java.util.List; 22 23 /** 24 * Class that searches a source directory for native gTests and outputs a 25 * list of test classes and methods. 26 */ 27 public class CtsJavaScanner { 28 usage(String[] args)29 private static void usage(String[] args) { 30 System.err.println("Arguments: " + Arrays.asList(args)); 31 System.err.println("Usage: cts-java-scanner -s SOURCE_DIR -d DOCLET_PATH"); 32 System.exit(1); 33 } 34 main(String[] args)35 public static void main(String[] args) throws Exception { 36 List<File> sourceDirs = new ArrayList<File>(); 37 File docletPath = null; 38 39 for (int i = 0; i < args.length; i++) { 40 if ("-s".equals(args[i])) { 41 sourceDirs.add(new File(getArg(args, ++i, "Missing value for source directory"))); 42 } else if ("-d".equals(args[i])) { 43 docletPath = new File(getArg(args, ++i, "Missing value for docletPath")); 44 } else { 45 System.err.println("Unsupported flag: " + args[i]); 46 usage(args); 47 } 48 } 49 50 if (sourceDirs.isEmpty()) { 51 System.err.println("Source directory is required"); 52 usage(args); 53 } 54 55 if (docletPath == null) { 56 System.err.println("Doclet path is required"); 57 usage(args); 58 } 59 60 DocletRunner runner = new DocletRunner(sourceDirs, docletPath); 61 System.exit(runner.runJavaDoc()); 62 } 63 getArg(String[] args, int index, String message)64 private static String getArg(String[] args, int index, String message) { 65 if (index < args.length) { 66 return args[index]; 67 } else { 68 System.err.println(message); 69 usage(args); 70 return null; 71 } 72 } 73 } 74