< 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;
*** 434,444 **** .forEach(cf -> rv.putAll(cf.collect())); } return Collections.unmodifiableMap(rv); } ! void collectClassFiles(Path destDir, String... pkgs) throws IOException { try { collectClasses(pkgs).entrySet().stream().forEach(e -> { try { String path = e.getKey().replace('.', File.separatorChar) + ".class"; logger.fine(() -> "Writing " + path); --- 436,460 ---- .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(String[] args) { ! 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[] args, String... pkgs) throws IOException { try { collectClasses(pkgs).entrySet().stream().forEach(e -> { try { String path = e.getKey().replace('.', File.separatorChar) + ".class"; logger.fine(() -> "Writing " + path);
*** 450,465 **** } } catch (IOException ioe) { throw new UncheckedIOException(ioe); } }); } catch (UncheckedIOException uioe) { throw uioe.getCause(); } } ! private void writeJar(AsmCodeFactory cf, JarOutputStream jar) { cf.collect().entrySet().stream().forEach(e -> { try { String path = e.getKey().replace('.', File.separatorChar) + ".class"; logger.fine(() -> "Add " + path); jar.putNextEntry(new ZipEntry(path)); --- 466,488 ---- } } 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(args)); + fos.flush(); + } } catch (UncheckedIOException uioe) { throw uioe.getCause(); } } ! private void writeJar(AsmCodeFactory cf, JarOutputStream jar, String[] args) { cf.collect().entrySet().stream().forEach(e -> { try { String path = e.getKey().replace('.', File.separatorChar) + ".class"; logger.fine(() -> "Add " + path); jar.putNextEntry(new ZipEntry(path));
*** 469,479 **** throw new UncheckedIOException(ioe); } }); } ! public void collectJarFile(final JarOutputStream jos, String... pkgs) { final Map<String, List<AsmCodeFactory>> mapPkgCf = getPkgCfMap(); for (String pkg_name : pkgs) { // convert '.' to '/' to use as a path String entryName = Utils.toInternalName(pkg_name, ""); --- 492,502 ---- throw new UncheckedIOException(ioe); } }); } ! public void collectJarFile(final JarOutputStream jos, String[] args, String... pkgs) { final Map<String, List<AsmCodeFactory>> mapPkgCf = getPkgCfMap(); for (String pkg_name : pkgs) { // convert '.' to '/' to use as a path String entryName = Utils.toInternalName(pkg_name, "");
*** 485,503 **** throw new UncheckedIOException(ex); } } logger.fine(() -> "Produce for package " + pkg_name); mapPkgCf.getOrDefault(pkg_name, Collections.emptyList()) ! .forEach(cf -> writeJar(cf, jos)); } } ! 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); } catch (UncheckedIOException uioe) { throw uioe.getCause(); } } --- 508,534 ---- throw new UncheckedIOException(ex); } } logger.fine(() -> "Produce for package " + pkg_name); mapPkgCf.getOrDefault(pkg_name, Collections.emptyList()) ! .forEach(cf -> writeJar(cf, jos, args)); ! } ! ! try { ! jos.putNextEntry(new ZipEntry(JEXTRACT_MANIFEST)); ! jos.write(getJextractProperties(args)); ! jos.closeEntry(); ! } catch (IOException ioe) { ! throw new UncheckedIOException(ioe); } } ! void collectJarFile(final Path jar, String[] args, 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, args, pkgs); } catch (UncheckedIOException uioe) { throw uioe.getCause(); } }
< prev index next >