< prev index next >

src/jdk.jextract/share/classes/com/sun/tools/jextract/Main.java

Print this page




 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         if (options.has("C")) {
 169             options.valuesOf("C").forEach(p -> ctx.addClangArg((String) p));
 170         }
 171 
 172         if (options.has("l")) {
 173             try {
 174                 options.valuesOf("l").forEach(p -> {
 175                     String lib = (String)p;
 176                     if (lib.indexOf(File.separatorChar) != -1) {
 177                         throw new IllegalArgumentException(format("l.name.should.not.be.path", lib));
 178                     }
 179                     ctx.addLibraryName(lib);
 180                 });
 181             } catch (IllegalArgumentException iae) {
 182                 ctx.err.println(iae.getMessage());
 183                 if (Main.DEBUG) {
 184                     iae.printStackTrace(ctx.err);
 185                 }
 186                 return 1;
 187             }


 265             outputName = (String) options.valueOf("o");
 266         } else if (hasOutput) {
 267             return 0;
 268         } else {
 269             outputName =  options.nonOptionArguments().get(0) + ".jar";
 270         }
 271 
 272         try {
 273             ctx.collectJarFile(Paths.get(outputName), targetPackage);
 274         } catch (IOException ex) {
 275             ctx.err.println(format("cannot.write.jar.file", outputName, ex));
 276             if (Main.DEBUG) {
 277                 ex.printStackTrace(ctx.err);
 278             }
 279             return 3;
 280         }
 281 
 282         return 0;
 283     }
 284 




 285     public static void main(String... args) {
 286         Main instance = new Main(new Context());
 287 
 288         System.exit(instance.run(args));
 289     }
 290 
 291     public static class JextractToolProvider implements ToolProvider {
 292         @Override
 293         public String name() {
 294             return "jextract";
 295         }
 296 
 297         @Override
 298         public int run(PrintWriter out, PrintWriter err, String... args) {
 299             // defensive check to throw security exception early.
 300             // Note that the successful run of jextract under security
 301             // manager would require far more permissions like loading
 302             // library (clang), file system access etc.
 303             if (System.getSecurityManager() != null) {
 304                 System.getSecurityManager().


 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")) {
 176             try {
 177                 options.valuesOf("l").forEach(p -> {
 178                     String lib = (String)p;
 179                     if (lib.indexOf(File.separatorChar) != -1) {
 180                         throw new IllegalArgumentException(format("l.name.should.not.be.path", lib));
 181                     }
 182                     ctx.addLibraryName(lib);
 183                 });
 184             } catch (IllegalArgumentException iae) {
 185                 ctx.err.println(iae.getMessage());
 186                 if (Main.DEBUG) {
 187                     iae.printStackTrace(ctx.err);
 188                 }
 189                 return 1;
 190             }


 268             outputName = (String) options.valueOf("o");
 269         } else if (hasOutput) {
 270             return 0;
 271         } else {
 272             outputName =  options.nonOptionArguments().get(0) + ".jar";
 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().
< prev index next >