< prev index next >

src/jdk.jlink/share/classes/jdk/tools/jlink/internal/packager/AppRuntimeImageBuilder.java

Print this page




  32 import jdk.tools.jlink.plugin.Plugin;
  33 
  34 import java.io.File;
  35 import java.io.IOException;
  36 import java.lang.module.ModuleFinder;
  37 import java.nio.file.Path;
  38 import java.util.ArrayList;
  39 import java.util.Collections;
  40 import java.util.List;
  41 import java.util.Map;
  42 import java.util.Set;
  43 
  44 /**
  45  * AppRuntimeImageBuilder is a private API used only by the Java Packager to generate
  46  * a Java runtime image using jlink. AppRuntimeImageBuilder encapsulates the
  47  * arguments that jlink requires to generate this image. To create the image call the
  48  * build() method.
  49  */
  50 public final class AppRuntimeImageBuilder {
  51     private Path outputDir = null;

  52     private List<Path> modulePath = null;
  53     private Set<String> addModules = null;
  54     private Set<String> limitModules = null;
  55     private String excludeFileList = null;
  56     private Map<String, String> userArguments = null;
  57     private Boolean stripNativeCommands = null;
  58 
  59     public AppRuntimeImageBuilder() {}
  60 
  61     public void setOutputDir(Path value) {
  62         outputDir = value;
  63     }
  64 




  65     public void setModulePath(List<Path> value) {
  66         modulePath = value;
  67     }
  68 
  69     public void setAddModules(Set<String> value) {
  70         addModules = value;
  71     }
  72 
  73     public void setLimitModules(Set<String> value) {
  74         limitModules = value;
  75     }
  76 
  77     public void setExcludeFileList(String value) {
  78         excludeFileList = value;
  79     }
  80 
  81     public void setStripNativeCommands(boolean value) {
  82         stripNativeCommands = value;
  83     }
  84 


 103         }
 104 
 105         if (excludeFileList != null && !excludeFileList.isEmpty()) {
 106             plugins.add(Jlink.newPlugin(
 107                         "exclude-files",
 108                         Collections.singletonMap("exclude-files", excludeFileList),
 109                         null));
 110         }
 111 
 112         // add user supplied jlink arguments
 113         for (Map.Entry<String, String> entry : userArguments.entrySet()) {
 114             String key = entry.getKey();
 115             String value = entry.getValue();
 116             plugins.add(Jlink.newPlugin(key,
 117                                         Collections.singletonMap(key, value),
 118                                         null));
 119         }
 120 
 121         // build the image
 122         Jlink.PluginsConfiguration pluginConfig = new Jlink.PluginsConfiguration(
 123             plugins, new DefaultImageBuilder(outputDir), null);
 124         Jlink jlink = new Jlink();
 125         jlink.build(jlinkConfig, pluginConfig);
 126     }
 127 
 128     /*
 129      * Returns a ModuleFinder that limits observability to the given root
 130      * modules, their transitive dependences, plus a set of other modules.
 131      */
 132     public static ModuleFinder moduleFinder(List<Path> modulepaths,
 133                                             Set<String> roots,
 134                                             Set<String> otherModules) {
 135         return JlinkTask.newModuleFinder(modulepaths, roots, otherModules);
 136     }
 137 }


  32 import jdk.tools.jlink.plugin.Plugin;
  33 
  34 import java.io.File;
  35 import java.io.IOException;
  36 import java.lang.module.ModuleFinder;
  37 import java.nio.file.Path;
  38 import java.util.ArrayList;
  39 import java.util.Collections;
  40 import java.util.List;
  41 import java.util.Map;
  42 import java.util.Set;
  43 
  44 /**
  45  * AppRuntimeImageBuilder is a private API used only by the Java Packager to generate
  46  * a Java runtime image using jlink. AppRuntimeImageBuilder encapsulates the
  47  * arguments that jlink requires to generate this image. To create the image call the
  48  * build() method.
  49  */
  50 public final class AppRuntimeImageBuilder {
  51     private Path outputDir = null;
  52     private Map<String, String> launchers = Collections.emptyMap();
  53     private List<Path> modulePath = null;
  54     private Set<String> addModules = null;
  55     private Set<String> limitModules = null;
  56     private String excludeFileList = null;
  57     private Map<String, String> userArguments = null;
  58     private Boolean stripNativeCommands = null;
  59 
  60     public AppRuntimeImageBuilder() {}
  61 
  62     public void setOutputDir(Path value) {
  63         outputDir = value;
  64     }
  65 
  66     public void setLaunchers(Map<String, String> value) {
  67         launchers = value;
  68     }
  69 
  70     public void setModulePath(List<Path> value) {
  71         modulePath = value;
  72     }
  73 
  74     public void setAddModules(Set<String> value) {
  75         addModules = value;
  76     }
  77 
  78     public void setLimitModules(Set<String> value) {
  79         limitModules = value;
  80     }
  81 
  82     public void setExcludeFileList(String value) {
  83         excludeFileList = value;
  84     }
  85 
  86     public void setStripNativeCommands(boolean value) {
  87         stripNativeCommands = value;
  88     }
  89 


 108         }
 109 
 110         if (excludeFileList != null && !excludeFileList.isEmpty()) {
 111             plugins.add(Jlink.newPlugin(
 112                         "exclude-files",
 113                         Collections.singletonMap("exclude-files", excludeFileList),
 114                         null));
 115         }
 116 
 117         // add user supplied jlink arguments
 118         for (Map.Entry<String, String> entry : userArguments.entrySet()) {
 119             String key = entry.getKey();
 120             String value = entry.getValue();
 121             plugins.add(Jlink.newPlugin(key,
 122                                         Collections.singletonMap(key, value),
 123                                         null));
 124         }
 125 
 126         // build the image
 127         Jlink.PluginsConfiguration pluginConfig = new Jlink.PluginsConfiguration(
 128             plugins, new DefaultImageBuilder(outputDir, launchers), null);
 129         Jlink jlink = new Jlink();
 130         jlink.build(jlinkConfig, pluginConfig);
 131     }
 132 
 133     /*
 134      * Returns a ModuleFinder that limits observability to the given root
 135      * modules, their transitive dependences, plus a set of other modules.
 136      */
 137     public static ModuleFinder moduleFinder(List<Path> modulepaths,
 138                                             Set<String> roots,
 139                                             Set<String> otherModules) {
 140         return JlinkTask.newModuleFinder(modulepaths, roots, otherModules);
 141     }
 142 }
< prev index next >