89 + " Class.forName(clazz, false, Thread.currentThread().getContextClassLoader());\n"
90 + " total_time+= System.currentTimeMillis()-t;\n"
91 + " num_classes+=1;\n"
92 + " } catch (IllegalAccessError ex) {\n"
93 + " // Security exceptions can occur, this is not what we are testing\n"
94 + " System.err.println(\"Access error, OK \" + clazz);\n"
95 + " } catch (Exception ex) {\n"
96 + " System.err.println(\"ERROR \" + clazz);\n"
97 + " throw new RuntimeException(ex);\n"
98 + " }\n"
99 + " });\n"
100 + " double res = (double) total_time / num_classes;\n"
101 + " // System.out.println(\"Total time \" + total_time + \" num classes \" + num_classes + \" average \" + res);\n"
102 + " }\n"
103 + "}\n";
104
105 private static final String OUTPUT_OPTION = "--output";
106 private static final String POST_PROCESS_OPTION = "--post-process-path";
107 private static final String MAIN_CLASS_OPTION = "--main-class";
108 private static final String CLASS_PATH_OPTION = "--class-path";
109 private static final String MODULE_PATH_OPTION = "--modulepath";
110 private static final String ADD_MODS_OPTION = "--addmods";
111 private static final String LIMIT_MODS_OPTION = "--limitmods";
112 private static final String PLUGINS_MODULE_PATH = "--plugin-module-path";
113
114 private static final String CMDS_OPTION = "--cmds";
115 private static final String CONFIG_OPTION = "--config";
116 private static final String HASH_MODULES_OPTION = "--hash-modules";
117 private static final String LIBS_OPTION = "--libs";
118 private static final String MODULE_VERSION_OPTION = "--module-version";
119
120 private JImageGenerator() {}
121
122 private static String optionsPrettyPrint(String... args) {
123 return Stream.of(args).collect(Collectors.joining(" "));
124 }
125
126 public static File getJModsDir(File jdkHome) {
127 File jdkjmods = new File(jdkHome, "jmods");
128 if (!jdkjmods.exists()) {
129 return null;
130 }
131 return jdkjmods;
132 }
517
518 public JImageTask option(String o) {
519 this.options.add(o);
520 return this;
521 }
522
523 private String toPath(List<Path> paths) {
524 return paths.stream()
525 .map(Path::toString)
526 .collect(Collectors.joining(File.pathSeparator));
527 }
528
529 private String[] optionsJImage(String cmd) {
530 List<String> options = new ArrayList<>();
531 options.add(cmd);
532 if (dir != null) {
533 options.add("--dir");
534 options.add(dir.toString());
535 }
536 if (!pluginModulePath.isEmpty()) {
537 options.add(PLUGINS_MODULE_PATH);
538 options.add(toPath(pluginModulePath));
539 }
540 options.addAll(this.options);
541 options.add(image.toString());
542 return options.toArray(new String[options.size()]);
543 }
544
545 private Result cmd(String cmd, Path returnPath) {
546 String[] args = optionsJImage(cmd);
547 System.err.println("jimage options: " + optionsPrettyPrint(args));
548 StringWriter writer = new StringWriter();
549 int exitCode = jdk.tools.jimage.Main.run(args, new PrintWriter(writer));
550 return new Result(exitCode, writer.toString(), returnPath);
551 }
552
553 public Result extract() {
554 return cmd("extract", dir);
555 }
556 }
557
615 private String modulePath() {
616 // This is expect FIRST jmods THEN jars, if you change this, some tests could fail
617 String jmods = toPath(this.jmods);
618 String jars = toPath(this.jars);
619 return jmods + File.pathSeparator + jars;
620 }
621
622 private String toPath(List<Path> paths) {
623 return paths.stream()
624 .map(Path::toString)
625 .collect(Collectors.joining(File.pathSeparator));
626 }
627
628 private String[] optionsJLink() {
629 List<String> options = new ArrayList<>();
630 if (output != null) {
631 options.add(OUTPUT_OPTION);
632 options.add(output.toString());
633 }
634 if (!addMods.isEmpty()) {
635 options.add(ADD_MODS_OPTION);
636 options.add(addMods.stream().collect(Collectors.joining(",")));
637 }
638 if (!limitMods.isEmpty()) {
639 options.add(LIMIT_MODS_OPTION);
640 options.add(limitMods.stream().collect(Collectors.joining(",")));
641 }
642 if (!jars.isEmpty() || !jmods.isEmpty()) {
643 options.add(MODULE_PATH_OPTION);
644 options.add(modulePath());
645 }
646 if (modulePath != null) {
647 options.add(MODULE_PATH_OPTION);
648 options.add(modulePath);
649 }
650 if (!pluginModulePath.isEmpty()) {
651 options.add(PLUGINS_MODULE_PATH);
652 options.add(toPath(pluginModulePath));
653 }
654 options.addAll(this.options);
655 return options.toArray(new String[options.size()]);
656 }
657
658 private String[] optionsPostProcessJLink() {
659 List<String> options = new ArrayList<>();
660 if (existing != null) {
661 options.add(POST_PROCESS_OPTION);
662 options.add(existing.toString());
663 }
664 options.addAll(this.options);
665 return options.toArray(new String[options.size()]);
666 }
667
668 public Result call() {
669 String[] args = optionsJLink();
670 System.err.println("jlink options: " + optionsPrettyPrint(args));
671 StringWriter writer = new StringWriter();
|
89 + " Class.forName(clazz, false, Thread.currentThread().getContextClassLoader());\n"
90 + " total_time+= System.currentTimeMillis()-t;\n"
91 + " num_classes+=1;\n"
92 + " } catch (IllegalAccessError ex) {\n"
93 + " // Security exceptions can occur, this is not what we are testing\n"
94 + " System.err.println(\"Access error, OK \" + clazz);\n"
95 + " } catch (Exception ex) {\n"
96 + " System.err.println(\"ERROR \" + clazz);\n"
97 + " throw new RuntimeException(ex);\n"
98 + " }\n"
99 + " });\n"
100 + " double res = (double) total_time / num_classes;\n"
101 + " // System.out.println(\"Total time \" + total_time + \" num classes \" + num_classes + \" average \" + res);\n"
102 + " }\n"
103 + "}\n";
104
105 private static final String OUTPUT_OPTION = "--output";
106 private static final String POST_PROCESS_OPTION = "--post-process-path";
107 private static final String MAIN_CLASS_OPTION = "--main-class";
108 private static final String CLASS_PATH_OPTION = "--class-path";
109 private static final String MODULE_PATH_OPTION = "--module-path";
110 private static final String ADD_MODULES_OPTION = "--add-modules";
111 private static final String LIMIT_MODULES_OPTION = "--limit-modules";
112 private static final String PLUGIN_MODULE_PATH = "--plugin-module-path";
113
114 private static final String CMDS_OPTION = "--cmds";
115 private static final String CONFIG_OPTION = "--config";
116 private static final String HASH_MODULES_OPTION = "--hash-modules";
117 private static final String LIBS_OPTION = "--libs";
118 private static final String MODULE_VERSION_OPTION = "--module-version";
119
120 private JImageGenerator() {}
121
122 private static String optionsPrettyPrint(String... args) {
123 return Stream.of(args).collect(Collectors.joining(" "));
124 }
125
126 public static File getJModsDir(File jdkHome) {
127 File jdkjmods = new File(jdkHome, "jmods");
128 if (!jdkjmods.exists()) {
129 return null;
130 }
131 return jdkjmods;
132 }
517
518 public JImageTask option(String o) {
519 this.options.add(o);
520 return this;
521 }
522
523 private String toPath(List<Path> paths) {
524 return paths.stream()
525 .map(Path::toString)
526 .collect(Collectors.joining(File.pathSeparator));
527 }
528
529 private String[] optionsJImage(String cmd) {
530 List<String> options = new ArrayList<>();
531 options.add(cmd);
532 if (dir != null) {
533 options.add("--dir");
534 options.add(dir.toString());
535 }
536 if (!pluginModulePath.isEmpty()) {
537 options.add(PLUGIN_MODULE_PATH);
538 options.add(toPath(pluginModulePath));
539 }
540 options.addAll(this.options);
541 options.add(image.toString());
542 return options.toArray(new String[options.size()]);
543 }
544
545 private Result cmd(String cmd, Path returnPath) {
546 String[] args = optionsJImage(cmd);
547 System.err.println("jimage options: " + optionsPrettyPrint(args));
548 StringWriter writer = new StringWriter();
549 int exitCode = jdk.tools.jimage.Main.run(args, new PrintWriter(writer));
550 return new Result(exitCode, writer.toString(), returnPath);
551 }
552
553 public Result extract() {
554 return cmd("extract", dir);
555 }
556 }
557
615 private String modulePath() {
616 // This is expect FIRST jmods THEN jars, if you change this, some tests could fail
617 String jmods = toPath(this.jmods);
618 String jars = toPath(this.jars);
619 return jmods + File.pathSeparator + jars;
620 }
621
622 private String toPath(List<Path> paths) {
623 return paths.stream()
624 .map(Path::toString)
625 .collect(Collectors.joining(File.pathSeparator));
626 }
627
628 private String[] optionsJLink() {
629 List<String> options = new ArrayList<>();
630 if (output != null) {
631 options.add(OUTPUT_OPTION);
632 options.add(output.toString());
633 }
634 if (!addMods.isEmpty()) {
635 options.add(ADD_MODULES_OPTION);
636 options.add(addMods.stream().collect(Collectors.joining(",")));
637 }
638 if (!limitMods.isEmpty()) {
639 options.add(LIMIT_MODULES_OPTION);
640 options.add(limitMods.stream().collect(Collectors.joining(",")));
641 }
642 if (!jars.isEmpty() || !jmods.isEmpty()) {
643 options.add(MODULE_PATH_OPTION);
644 options.add(modulePath());
645 }
646 if (modulePath != null) {
647 options.add(MODULE_PATH_OPTION);
648 options.add(modulePath);
649 }
650 if (!pluginModulePath.isEmpty()) {
651 options.add(PLUGIN_MODULE_PATH);
652 options.add(toPath(pluginModulePath));
653 }
654 options.addAll(this.options);
655 return options.toArray(new String[options.size()]);
656 }
657
658 private String[] optionsPostProcessJLink() {
659 List<String> options = new ArrayList<>();
660 if (existing != null) {
661 options.add(POST_PROCESS_OPTION);
662 options.add(existing.toString());
663 }
664 options.addAll(this.options);
665 return options.toArray(new String[options.size()]);
666 }
667
668 public Result call() {
669 String[] args = optionsJLink();
670 System.err.println("jlink options: " + optionsPrettyPrint(args));
671 StringWriter writer = new StringWriter();
|