102 Logger logger = ctx.logger; 103 logger.setUseParentHandlers(false); 104 ConsoleHandler log = new ConsoleHandler(); 105 System.setProperty("java.util.logging.SimpleFormatter.format", "%4$s: %5$s%n"); 106 log.setFormatter(new SimpleFormatter()); 107 logger.setLevel(level); 108 log.setLevel(level); 109 logger.addHandler(log); 110 } 111 112 private void printHelp(OptionParser parser) { 113 try { 114 parser.printHelpOn(ctx.err); 115 } catch (IOException ex) { 116 if (Main.DEBUG) { 117 ex.printStackTrace(ctx.err); 118 } 119 } 120 } 121 122 public int run(String[] args) { 123 OptionParser parser = new OptionParser(); 124 parser.accepts("dry-run", format("help.dry_run")); 125 parser.accepts("I", format("help.I")).withRequiredArg(); 126 // option is expected to specify paths to load shared libraries 127 // to check & warn missing symbols during jextract session. 128 parser.accepts("L", format("help.L")).withRequiredArg(); 129 parser.accepts("l", format("help.l")).withRequiredArg(); 130 parser.accepts("d", format("help.d")).withRequiredArg(); 131 parser.acceptsAll(List.of("o", "jar"), format("help.o")).withRequiredArg(); 132 parser.acceptsAll(List.of("t", "target-package"), format("help.t")).withRequiredArg(); 133 parser.acceptsAll(List.of("m", "package-map"), format("help.m")).withRequiredArg(); 134 parser.acceptsAll(List.of("?", "h", "help"), format("help.h")).forHelp(); 135 parser.accepts("C", format("help.C")).withRequiredArg(); 136 parser.accepts("log", format("help.log")).withRequiredArg(); 137 parser.accepts("exclude-symbols", format("help.exclude_symbols")).withRequiredArg(); 138 parser.accepts("rpath", format("help.rpath")).withRequiredArg(); 139 parser.nonOptions(format("help.non.option")); 140 141 OptionSet options = null; 142 try { 143 options = parser.parse(args); 144 } catch (OptionException oe) { 145 ctx.err.println(oe.getMessage()); 146 if (Main.DEBUG) { 147 oe.printStackTrace(ctx.err); 148 } 149 printHelp(parser); 150 return 1; 151 } 152 153 if (args.length == 0 || options.has("h")) { 154 printHelp(parser); 155 return args.length == 0? 1 : 0; 156 } 157 158 if (options.has("log")) { 159 setupLogging(Level.parse((String) options.valueOf("log"))); 160 } else { 161 setupLogging(Level.WARNING); 162 } 163 164 if (options.has("I")) { 165 options.valuesOf("I").forEach(p -> ctx.addClangArg("-I" + p)); 166 } 167 168 // append the built-in headers directory 169 ctx.addClangArg("-I" + getBuiltinHeadersDir()); 170 171 if (options.has("C")) { 172 options.valuesOf("C").forEach(p -> ctx.addClangArg((String) p)); 173 } 174 175 if (options.has("l")) { 273 } 274 275 try { 276 ctx.collectJarFile(Paths.get(outputName), targetPackage); 277 } catch (IOException ex) { 278 ctx.err.println(format("cannot.write.jar.file", outputName, ex)); 279 if (Main.DEBUG) { 280 ex.printStackTrace(ctx.err); 281 } 282 return 3; 283 } 284 285 return 0; 286 } 287 288 private static Path getBuiltinHeadersDir() { 289 return Paths.get(System.getProperty("java.home"), "conf", "jextract"); 290 } 291 292 public static void main(String... args) { 293 Main instance = new Main(new Context()); 294 295 System.exit(instance.run(args)); 296 } 297 298 public static class JextractToolProvider implements ToolProvider { 299 @Override 300 public String name() { 301 return "jextract"; 302 } 303 304 @Override 305 public int run(PrintWriter out, PrintWriter err, String... args) { 306 // defensive check to throw security exception early. 307 // Note that the successful run of jextract under security 308 // manager would require far more permissions like loading 309 // library (clang), file system access etc. 310 if (System.getSecurityManager() != null) { 311 System.getSecurityManager(). 312 checkPermission(new RuntimePermission("jextract")); 313 } 314 315 Main instance = new Main(new Context(out, err)); 316 return instance.run(args); 317 } 318 } 319 } | 102 Logger logger = ctx.logger; 103 logger.setUseParentHandlers(false); 104 ConsoleHandler log = new ConsoleHandler(); 105 System.setProperty("java.util.logging.SimpleFormatter.format", "%4$s: %5$s%n"); 106 log.setFormatter(new SimpleFormatter()); 107 logger.setLevel(level); 108 log.setLevel(level); 109 logger.addHandler(log); 110 } 111 112 private void printHelp(OptionParser parser) { 113 try { 114 parser.printHelpOn(ctx.err); 115 } catch (IOException ex) { 116 if (Main.DEBUG) { 117 ex.printStackTrace(ctx.err); 118 } 119 } 120 } 121 122 public int run() { 123 OptionParser parser = new OptionParser(); 124 parser.accepts("dry-run", format("help.dry_run")); 125 parser.accepts("I", format("help.I")).withRequiredArg(); 126 // option is expected to specify paths to load shared libraries 127 // to check & warn missing symbols during jextract session. 128 parser.accepts("L", format("help.L")).withRequiredArg(); 129 parser.accepts("l", format("help.l")).withRequiredArg(); 130 parser.accepts("d", format("help.d")).withRequiredArg(); 131 parser.acceptsAll(List.of("o", "jar"), format("help.o")).withRequiredArg(); 132 parser.acceptsAll(List.of("t", "target-package"), format("help.t")).withRequiredArg(); 133 parser.acceptsAll(List.of("m", "package-map"), format("help.m")).withRequiredArg(); 134 parser.acceptsAll(List.of("?", "h", "help"), format("help.h")).forHelp(); 135 parser.accepts("C", format("help.C")).withRequiredArg(); 136 parser.accepts("log", format("help.log")).withRequiredArg(); 137 parser.accepts("exclude-symbols", format("help.exclude_symbols")).withRequiredArg(); 138 parser.accepts("rpath", format("help.rpath")).withRequiredArg(); 139 parser.nonOptions(format("help.non.option")); 140 141 OptionSet options = null; 142 try { 143 options = parser.parse(ctx.args); 144 } catch (OptionException oe) { 145 ctx.err.println(oe.getMessage()); 146 if (Main.DEBUG) { 147 oe.printStackTrace(ctx.err); 148 } 149 printHelp(parser); 150 return 1; 151 } 152 153 if (ctx.args.length == 0 || options.has("h")) { 154 printHelp(parser); 155 return ctx.args.length == 0? 1 : 0; 156 } 157 158 if (options.has("log")) { 159 setupLogging(Level.parse((String) options.valueOf("log"))); 160 } else { 161 setupLogging(Level.WARNING); 162 } 163 164 if (options.has("I")) { 165 options.valuesOf("I").forEach(p -> ctx.addClangArg("-I" + p)); 166 } 167 168 // append the built-in headers directory 169 ctx.addClangArg("-I" + getBuiltinHeadersDir()); 170 171 if (options.has("C")) { 172 options.valuesOf("C").forEach(p -> ctx.addClangArg((String) p)); 173 } 174 175 if (options.has("l")) { 273 } 274 275 try { 276 ctx.collectJarFile(Paths.get(outputName), targetPackage); 277 } catch (IOException ex) { 278 ctx.err.println(format("cannot.write.jar.file", outputName, ex)); 279 if (Main.DEBUG) { 280 ex.printStackTrace(ctx.err); 281 } 282 return 3; 283 } 284 285 return 0; 286 } 287 288 private static Path getBuiltinHeadersDir() { 289 return Paths.get(System.getProperty("java.home"), "conf", "jextract"); 290 } 291 292 public static void main(String... args) { 293 Main instance = new Main(new Context(args)); 294 295 System.exit(instance.run()); 296 } 297 298 public static class JextractToolProvider implements ToolProvider { 299 @Override 300 public String name() { 301 return "jextract"; 302 } 303 304 @Override 305 public int run(PrintWriter out, PrintWriter err, String... args) { 306 // defensive check to throw security exception early. 307 // Note that the successful run of jextract under security 308 // manager would require far more permissions like loading 309 // library (clang), file system access etc. 310 if (System.getSecurityManager() != null) { 311 System.getSecurityManager(). 312 checkPermission(new RuntimePermission("jextract")); 313 } 314 315 Main instance = new Main(new Context(out, err, args)); 316 return instance.run(); 317 } 318 } 319 } |