Main.java revision 25e96ce7b99f9736a6024d25bd65a83774c7640f
1/* 2 * Copyright (C) 2008 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 17package com.android.tools.layoutlib.create; 18 19import java.io.IOException; 20import java.util.ArrayList; 21import java.util.Set; 22 23 24 25public class Main { 26 27 public static void main(String[] args) { 28 29 Log log = new Log(); 30 31 ArrayList<String> osJarPath = new ArrayList<String>(); 32 String[] osDestJar = { null }; 33 34 if (!processArgs(log, args, osJarPath, osDestJar)) { 35 log.error("Usage: layoutlib_create [-v] output.jar input.jar ..."); 36 System.exit(1); 37 } 38 39 log.info("Output: %1$s", osDestJar[0]); 40 for (String path : osJarPath) { 41 log.info("Input : %1$s", path); 42 } 43 44 try { 45 AsmGenerator agen = new AsmGenerator(log, osDestJar[0], 46 CreateInfo.INJECTED_CLASSES, 47 CreateInfo.OVERRIDDEN_METHODS, 48 CreateInfo.RENAMED_CLASSES, 49 CreateInfo.REMOVED_METHODS 50 ); 51 52 AsmAnalyzer aa = new AsmAnalyzer(log, osJarPath, agen, 53 new String[] { "android.view.View" }, // derived from 54 new String[] { // include classes 55 "android.*", // for android.R 56 "android.util.*", 57 "com.android.internal.util.*", 58 "android.view.*", 59 "android.widget.*", 60 "com.android.internal.widget.*", 61 "android.text.**", 62 "android.graphics.*", 63 "android.graphics.drawable.*", 64 "android.content.*", 65 "android.content.res.*", 66 "org.apache.harmony.xml.*", 67 "com.android.internal.R**", 68 "android.pim.*", // for datepicker 69 "android.os.*", // for android.os.Handler 70 "android.database.ContentObserver", // for Digital clock 71 }); 72 aa.analyze(); 73 agen.generate(); 74 75 // Throw an error if any class failed to get renamed by the generator 76 // 77 // IMPORTANT: if you're building the platform and you get this error message, 78 // it means the renameClasses[] array in AsmGenerator needs to be updated: some 79 // class should have been renamed but it was not found in the input JAR files. 80 Set<String> notRenamed = agen.getClassesNotRenamed(); 81 if (notRenamed.size() > 0) { 82 // (80-column guide below for error formatting) 83 // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 84 log.error( 85 "ERROR when running layoutlib_create: the following classes are referenced\n" + 86 "by tools/layoutlib/create but were not actually found in the input JAR files.\n" + 87 "This may be due to some platform classes having been renamed."); 88 for (String fqcn : notRenamed) { 89 log.error("- Class not found: %s", fqcn.replace('/', '.')); 90 } 91 for (String path : osJarPath) { 92 log.info("- Input JAR : %1$s", path); 93 } 94 System.exit(1); 95 } 96 97 System.exit(0); 98 } catch (IOException e) { 99 log.exception(e, "Failed to load jar"); 100 } catch (LogAbortException e) { 101 e.error(log); 102 } 103 104 System.exit(1); 105 } 106 107 /** 108 * Returns true if args where properly parsed. 109 * Returns false if program should exit with command-line usage. 110 * <p/> 111 * Note: the String[0] is an output parameter wrapped in an array, since there is no 112 * "out" parameter support. 113 */ 114 private static boolean processArgs(Log log, String[] args, 115 ArrayList<String> osJarPath, String[] osDestJar) { 116 for (int i = 0; i < args.length; i++) { 117 String s = args[i]; 118 if (s.equals("-v")) { 119 log.setVerbose(true); 120 } else if (!s.startsWith("-")) { 121 if (osDestJar[0] == null) { 122 osDestJar[0] = s; 123 } else { 124 osJarPath.add(s); 125 } 126 } else { 127 log.error("Unknow argument: %s", s); 128 return false; 129 } 130 } 131 132 if (osJarPath.isEmpty()) { 133 log.error("Missing parameter: path to input jar"); 134 return false; 135 } 136 if (osDestJar[0] == null) { 137 log.error("Missing parameter: path to output jar"); 138 return false; 139 } 140 141 return true; 142 } 143 144} 145