Home | History | Annotate | Download | only in converter
      1 /*
      2  * Copyright (C) 2009 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 
     17 package signature.converter;
     18 
     19 import signature.UsageException;
     20 import signature.converter.dex.DexFactory;
     21 import signature.converter.doclet.DocletFactory;
     22 import signature.io.IApiLoader;
     23 import signature.io.IApiExternalizer;
     24 import signature.io.impl.BinaryApi;
     25 
     26 import java.io.IOException;
     27 import java.util.HashSet;
     28 import java.util.Set;
     29 
     30 public class Main {
     31     // (doclet | dex) sourcefiles --out file --name name --packages packageName{
     32     // packageName}" +
     33     public static void main(String[] args) throws IOException {
     34         String type = args[0];
     35         Set<String> sources = new HashSet<String>();
     36         int at = 1;
     37         for (/* at */; at < args.length; at++) {
     38             if ("--out".equals(args[at])) {
     39                 break;
     40             }
     41             sources.add(args[at]);
     42         }
     43 
     44         if (!"--out".equals(args[at])) {
     45             throw new UsageException();
     46         }
     47         String targetFile = args[++at];
     48 
     49         if (!"--name".equals(args[++at])) {
     50             throw new UsageException();
     51         }
     52         String name = args[++at];
     53 
     54         if (!"--packages".equals(args[++at])) {
     55             throw new UsageException();
     56         }
     57         Set<String> packages = new HashSet<String>();
     58         ++at;
     59         for (/* at */; at < args.length; at++) {
     60             packages.add(args[at]);
     61         }
     62 
     63         IApiExternalizer externalizer = new BinaryApi();
     64         IApiLoader factory = null;
     65 
     66         if ("doclet".equals(type)) {
     67             factory = new DocletFactory();
     68         } else if ("dex".equals(type)) {
     69             factory = new DexFactory();
     70         } else {
     71             throw new UsageException();
     72         }
     73 
     74         externalizer.externalizeApi(targetFile, factory.loadApi(name,
     75                 Visibility.PROTECTED, sources, packages));
     76     }
     77 }
     78