001 package com.khubla.pragmatach.contrib.clientproxygenerator; 002 003 import java.io.FileInputStream; 004 import java.util.List; 005 006 import org.apache.commons.cli.CommandLine; 007 import org.apache.commons.cli.CommandLineParser; 008 import org.apache.commons.cli.HelpFormatter; 009 import org.apache.commons.cli.Option; 010 import org.apache.commons.cli.OptionBuilder; 011 import org.apache.commons.cli.Options; 012 import org.apache.commons.cli.PosixParser; 013 014 /** 015 * @author tome 016 */ 017 public class ClientProxyGenerator { 018 /** 019 * controllers file option 020 */ 021 private static final String FILE_OPTION = "file"; 022 /** 023 * target option 024 */ 025 private static final String NAMESPACE_OPTION = "namespace"; 026 027 /** 028 * test the routes 029 */ 030 private static void generateProxies(List<RouteUrl> controllerUrls, String namespace) throws Exception { 031 try { 032 final ClientGenerator clientGenerator = new ClientGenerator("target/pragmatach/"); 033 for (final RouteUrl routeUrl : controllerUrls) { 034 clientGenerator.generate(routeUrl, namespace); 035 } 036 } catch (final Exception e) { 037 throw new Exception("Exception in testUrls", e); 038 } 039 } 040 041 /** 042 * the usual 043 */ 044 @SuppressWarnings("static-access") 045 public static void main(String[] args) { 046 try { 047 /* 048 * options for commons-cli 049 */ 050 final Options options = new Options(); 051 final Option fo = OptionBuilder.withArgName(FILE_OPTION).isRequired(true).withType(String.class).hasArg().withDescription("controllers file").create(FILE_OPTION); 052 options.addOption(fo); 053 final Option uo = OptionBuilder.withArgName(NAMESPACE_OPTION).isRequired(true).withType(String.class).hasArg().withDescription("namespace").create(NAMESPACE_OPTION); 054 options.addOption(uo); 055 /* 056 * parse 057 */ 058 final CommandLineParser parser = new PosixParser(); 059 CommandLine cmd = null; 060 try { 061 cmd = parser.parse(options, args); 062 } catch (final Exception e) { 063 e.printStackTrace(); 064 final HelpFormatter formatter = new HelpFormatter(); 065 formatter.printHelp("posix", options); 066 System.exit(0); 067 } 068 /* 069 * vars 070 */ 071 final String namespace = cmd.getOptionValue(NAMESPACE_OPTION); 072 final String file = cmd.getOptionValue(FILE_OPTION); 073 /* 074 * read 075 */ 076 final List<RouteUrl> controllerUrls = RouteUrl.readRoutes(new FileInputStream(file)); 077 /* 078 * test 079 */ 080 generateProxies(controllerUrls, namespace); 081 } catch (final Exception e) { 082 e.printStackTrace(); 083 } 084 } 085 }