< prev index next >

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

Print this page

        

*** 23,32 **** --- 23,33 ---- package com.sun.tools.jextract; import jdk.internal.clang.*; import jdk.internal.foreign.LibrariesHelper; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; import java.io.UncheckedIOException;
*** 38,47 **** --- 39,49 ---- import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; + import java.util.Properties; import java.util.Set; import java.util.TreeSet; import java.util.function.Function; import java.util.function.Predicate; import java.util.jar.JarOutputStream;
*** 77,96 **** // Symbol patterns to be excluded private final List<Pattern> excludeSymbols; final PrintWriter out; final PrintWriter err; private Predicate<String> symChecker; private Predicate<String> symFilter; private final MacroParser macroParser; private final static String defaultPkg = "jextract.dump"; final Logger logger = Logger.getLogger(getClass().getPackage().getName()); ! public Context(PrintWriter out, PrintWriter err) { this.tdMap = new HashMap<>(); this.pkgMap = new HashMap<>(); this.headerMap = new HashMap<>(); this.clangArgs = new ArrayList<>(); this.sources = new TreeSet<>(); --- 79,99 ---- // Symbol patterns to be excluded private final List<Pattern> excludeSymbols; final PrintWriter out; final PrintWriter err; + final String[] args; private Predicate<String> symChecker; private Predicate<String> symFilter; private final MacroParser macroParser; private final static String defaultPkg = "jextract.dump"; final Logger logger = Logger.getLogger(getClass().getPackage().getName()); ! public Context(PrintWriter out, PrintWriter err, String[] args) { this.tdMap = new HashMap<>(); this.pkgMap = new HashMap<>(); this.headerMap = new HashMap<>(); this.clangArgs = new ArrayList<>(); this.sources = new TreeSet<>();
*** 99,112 **** this.linkCheckPaths = new ArrayList<>(); this.excludeSymbols = new ArrayList<>(); this.macroParser = new MacroParser(); this.out = out; this.err = err; } ! public Context() { ! this(new PrintWriter(System.out, true), new PrintWriter(System.err, true)); } TypeDictionary typeDictionaryFor(String pkg) { return tdMap.computeIfAbsent(pkg, p->new TypeDictionary(this, p)); } --- 102,116 ---- this.linkCheckPaths = new ArrayList<>(); this.excludeSymbols = new ArrayList<>(); this.macroParser = new MacroParser(); this.out = out; this.err = err; + this.args = args; } ! public Context(String[] args) { ! this(new PrintWriter(System.out, true), new PrintWriter(System.err, true), args); } TypeDictionary typeDictionaryFor(String pkg) { return tdMap.computeIfAbsent(pkg, p->new TypeDictionary(this, p)); }
*** 434,443 **** --- 438,461 ---- .forEach(cf -> rv.putAll(cf.collect())); } return Collections.unmodifiableMap(rv); } + private static final String JEXTRACT_MANIFEST = "META-INFO" + File.separatorChar + "jextract.properties"; + + @SuppressWarnings("deprecation") + private byte[] getJextractProperties() { + Properties props = new Properties(); + props.setProperty("os.name", System.getProperty("os.name")); + props.setProperty("os.version", System.getProperty("os.version")); + props.setProperty("os.arch", System.getProperty("os.arch")); + props.setProperty("jextract.args", Arrays.toString(args)); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + props.save(baos, "jextract meta data"); + return baos.toByteArray(); + } + void collectClassFiles(Path destDir, String... pkgs) throws IOException { try { collectClasses(pkgs).entrySet().stream().forEach(e -> { try { String path = e.getKey().replace('.', File.separatorChar) + ".class";
*** 450,459 **** --- 468,484 ---- } } catch (IOException ioe) { throw new UncheckedIOException(ioe); } }); + + Path propsPath = destDir.resolve(JEXTRACT_MANIFEST).normalize(); + Files.createDirectories(propsPath.getParent()); + try (OutputStream fos = Files.newOutputStream(propsPath)) { + fos.write(getJextractProperties()); + fos.flush(); + } } catch (UncheckedIOException uioe) { throw uioe.getCause(); } }
*** 494,503 **** --- 519,531 ---- void collectJarFile(final Path jar, String... pkgs) throws IOException { logger.info(() -> "Collecting jar file " + jar); try (OutputStream os = Files.newOutputStream(jar, CREATE, TRUNCATE_EXISTING, WRITE); JarOutputStream jo = new JarOutputStream(os)) { collectJarFile(jo, pkgs); + jo.putNextEntry(new ZipEntry(JEXTRACT_MANIFEST)); + jo.write(getJextractProperties()); + jo.closeEntry(); } catch (UncheckedIOException uioe) { throw uioe.getCause(); } }
< prev index next >