< prev index next >
src/jdk.jextract/share/classes/com/sun/tools/jextract/Main.java
Print this page
*** 28,46 ****
--- 28,62 ----
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+ import java.text.MessageFormat;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
+ import java.util.Locale;
+ import java.util.ResourceBundle;
public final class Main {
+ public static final boolean DEBUG = Boolean.getBoolean("jextract.debug");
+
// FIXME: Remove this if/when the macros support is deemed stable
public static boolean INCLUDE_MACROS = Boolean.parseBoolean(System.getProperty("jextract.INCLUDE_MACROS", "true"));
+ private static final String MESSAGES_RESOURCE = "com.sun.tools.jextract.resources.Messages";
+
+ private static final ResourceBundle MESSAGES_BUNDLE;
+ static {
+ MESSAGES_BUNDLE = ResourceBundle.getBundle(MESSAGES_RESOURCE, Locale.getDefault());
+ }
+
+ public static String format(String msgId, Object... args) {
+ return new MessageFormat(MESSAGES_BUNDLE.getString(msgId)).format(args);
+ }
+
final Context ctx;
String targetPackage;
public Main(Context ctx) {
this.ctx = ctx;
*** 56,77 ****
KeyValuePair kv = KeyValuePair.valueOf(str);
p = Paths.get(kv.key);
pkgName = kv.value;
if (!Files.isDirectory(p)) {
! throw new IllegalArgumentException("Not a directory: " + kv.key);
}
}
Validators.validPackageName(pkgName);
ctx.usePackageForFolder(p, pkgName);
}
private void processHeader(Object header) {
Path p = Paths.get((String) header);
if (!Files.isReadable(p)) {
! throw new IllegalArgumentException("Cannot read the file: " + header);
}
p = p.toAbsolutePath();
ctx.usePackageForFolder(p.getParent(), targetPackage);
ctx.sources.add(p);
}
--- 72,93 ----
KeyValuePair kv = KeyValuePair.valueOf(str);
p = Paths.get(kv.key);
pkgName = kv.value;
if (!Files.isDirectory(p)) {
! throw new IllegalArgumentException(format("not.a.directory", kv.key));
}
}
Validators.validPackageName(pkgName);
ctx.usePackageForFolder(p, pkgName);
}
private void processHeader(Object header) {
Path p = Paths.get((String) header);
if (!Files.isReadable(p)) {
! throw new IllegalArgumentException(format("cannot.read.header.file", header));
}
p = p.toAbsolutePath();
ctx.usePackageForFolder(p.getParent(), targetPackage);
ctx.sources.add(p);
}
*** 105,120 ****
--- 121,141 ----
if (args.length == 0 || options.has("h") || options.has("?")) {
try {
parser.printHelpOn(System.out);
} catch (IOException ex) {
+ if (Main.DEBUG) {
+ ex.printStackTrace(System.err);
+ }
}
System.exit(1);
}
if (options.has("log")) {
setupLogging(Level.parse((String) options.valueOf("log")));
+ } else {
+ setupLogging(Level.WARNING);
}
if (options.has("I")) {
options.valuesOf("I").forEach(p -> ctx.clangArgs.add("-I" + p));
}
*** 130,154 ****
if (options.has("m")) {
options.valuesOf("m").forEach(this::processPackageMapping);
}
- options.nonOptionArguments().stream().forEach(this::processHeader);
try {
ctx.parse(AsmCodeFactory::new);
} catch (RuntimeException re) {
re.printStackTrace(System.err);
System.exit(2);
}
if (options.has("o")) {
Path jar = Paths.get((String) options.valueOf("o"));
try {
ctx.collectJarFile(jar, targetPackage);
} catch (IOException ex) {
! System.out.println("Error occurred producing jar file.");
ex.printStackTrace(System.err);
System.exit(3);
}
}
}
--- 151,180 ----
if (options.has("m")) {
options.valuesOf("m").forEach(this::processPackageMapping);
}
try {
+ options.nonOptionArguments().stream().forEach(this::processHeader);
ctx.parse(AsmCodeFactory::new);
} catch (RuntimeException re) {
+ System.err.println(re.getMessage());
+ if (Main.DEBUG) {
re.printStackTrace(System.err);
+ }
System.exit(2);
}
if (options.has("o")) {
Path jar = Paths.get((String) options.valueOf("o"));
try {
ctx.collectJarFile(jar, targetPackage);
} catch (IOException ex) {
! System.err.println(format("cannot.write.jar.file", jar, ex));
! if (Main.DEBUG) {
ex.printStackTrace(System.err);
+ }
System.exit(3);
}
}
}
< prev index next >