• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Libphonenumber Authors
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 com.google.i18n.phonenumbers.buildtools;
18 
19 import com.google.i18n.phonenumbers.Command;
20 
21 import java.io.File;
22 import java.io.IOException;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 
26 /**
27  * Entry point class used to invoke the generation of the binary phone prefix data files.
28  */
29 public class GeneratePhonePrefixDataEntryPoint extends Command {
30 
31   private static final Logger logger = Logger.getLogger(GeneratePhonePrefixData.class.getName());
32   private static final String USAGE_DESCRIPTION =
33       "usage: GeneratePhonePrefixData /path/to/input/directory /path/to/output/directory"
34           + " [outputJarName]";
35 
36   @Override
getCommandName()37   public String getCommandName() {
38     return "GeneratePhonePrefixData";
39   }
40 
41   @Override
start()42   public boolean start() {
43     String[] args = getArgs();
44 
45     if (args.length < 3 || args.length > 4) {
46       logger.log(Level.SEVERE, USAGE_DESCRIPTION);
47       return false;
48     }
49     try {
50       File inputPath = new File(args[1]);
51       File outputPath = new File(args[2]);
52       AbstractPhonePrefixDataIOHandler ioHandler =
53           args.length == 3
54               ? new PhonePrefixDataIOHandler(outputPath)
55               : new JarPhonePrefixDataIOHandler(
56                   outputPath, args[3], GeneratePhonePrefixData.class.getPackage());
57       GeneratePhonePrefixData dataGenerator = new GeneratePhonePrefixData(inputPath, ioHandler);
58       dataGenerator.run();
59     } catch (IOException e) {
60       logger.log(Level.SEVERE, e.getMessage());
61       return false;
62     }
63     return true;
64   }
65 }
66