< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.tools.jlink.internal.packager;
  27 
  28 
  29 import jdk.tools.jlink.builder.DefaultImageBuilder;
  30 import jdk.tools.jlink.internal.Jlink;
  31 import jdk.tools.jlink.internal.JlinkTask;
  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;


  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 
  90     public void setUserArguments(Map<String, String> value) {
  91         userArguments = value;
  92     }
  93 
  94     public void build() throws IOException {
  95         // jlink main arguments
  96         Jlink.JlinkConfiguration jlinkConfig = new Jlink.JlinkConfiguration(
  97             new File("").toPath(), // Unused
  98             modulePath, addModules, limitModules);



  99 
 100         // plugin configuration
 101         List<Plugin> plugins = new ArrayList<Plugin>();
 102 
 103         if (stripNativeCommands) {
 104             plugins.add(Jlink.newPlugin(
 105                         "strip-native-commands",
 106                         Collections.singletonMap("strip-native-commands", "on"),
 107                         null));
 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()) {


   1 /*
   2  * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.tools.jlink.internal.packager;
  27 
  28 
  29 import jdk.tools.jlink.builder.DefaultImageBuilder;
  30 import jdk.tools.jlink.internal.Jlink;
  31 import jdk.tools.jlink.internal.JlinkTask;
  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.ByteOrder;
  38 import java.nio.file.Path;
  39 import java.util.ArrayList;
  40 import java.util.Collections;
  41 import java.util.List;
  42 import java.util.Map;
  43 import java.util.Set;
  44 
  45 /**
  46  * AppRuntimeImageBuilder is a private API used only by the Java Packager to generate
  47  * a Java runtime image using jlink. AppRuntimeImageBuilder encapsulates the
  48  * arguments that jlink requires to generate this image. To create the image call the
  49  * build() method.
  50  */
  51 public final class AppRuntimeImageBuilder {
  52     private Path outputDir = null;
  53     private Map<String, String> launchers = Collections.emptyMap();
  54     private List<Path> modulePath = null;
  55     private Set<String> addModules = null;
  56     private Set<String> limitModules = null;
  57     private String excludeFileList = null;


  77     }
  78 
  79     public void setLimitModules(Set<String> value) {
  80         limitModules = value;
  81     }
  82 
  83     public void setExcludeFileList(String value) {
  84         excludeFileList = value;
  85     }
  86 
  87     public void setStripNativeCommands(boolean value) {
  88         stripNativeCommands = value;
  89     }
  90 
  91     public void setUserArguments(Map<String, String> value) {
  92         userArguments = value;
  93     }
  94 
  95     public void build() throws IOException {
  96         // jlink main arguments
  97         Jlink.JlinkConfiguration jlinkConfig =
  98             new Jlink.JlinkConfiguration(new File("").toPath(), // Unused
  99                                          modulePath,
 100                                          addModules,
 101                                          limitModules,
 102                                          ByteOrder.nativeOrder());
 103 
 104         // plugin configuration
 105         List<Plugin> plugins = new ArrayList<Plugin>();
 106 
 107         if (stripNativeCommands) {
 108             plugins.add(Jlink.newPlugin(
 109                         "strip-native-commands",
 110                         Collections.singletonMap("strip-native-commands", "on"),
 111                         null));
 112         }
 113 
 114         if (excludeFileList != null && !excludeFileList.isEmpty()) {
 115             plugins.add(Jlink.newPlugin(
 116                         "exclude-files",
 117                         Collections.singletonMap("exclude-files", excludeFileList),
 118                         null));
 119         }
 120 
 121         // add user supplied jlink arguments
 122         for (Map.Entry<String, String> entry : userArguments.entrySet()) {


< prev index next >