< prev index next >

test/tools/jlink/IntegrationTest.java

Print this page




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.io.File;
  25 import java.io.FileReader;
  26 import java.io.IOException;
  27 import java.io.UncheckedIOException;

  28 import java.nio.file.Files;
  29 import java.nio.file.Path;
  30 import java.nio.file.Paths;
  31 import java.util.ArrayList;
  32 import java.util.Collections;
  33 import java.util.HashMap;
  34 import java.util.HashSet;
  35 import java.util.List;
  36 import java.util.Map;
  37 import java.util.Properties;
  38 import java.util.Set;
  39 import java.util.function.Function;
  40 import jdk.tools.jlink.internal.Jlink;
  41 import jdk.tools.jlink.builder.DefaultImageBuilder;
  42 import jdk.tools.jlink.plugin.ResourcePool;
  43 import jdk.tools.jlink.plugin.ResourcePoolBuilder;
  44 import jdk.tools.jlink.plugin.Plugin;
  45 import jdk.tools.jlink.internal.ExecutableImage;
  46 import jdk.tools.jlink.internal.Jlink.JlinkConfiguration;
  47 import jdk.tools.jlink.internal.Jlink.PluginsConfiguration;


 118         }
 119         apitest();
 120         test();
 121     }
 122 
 123     private static void apitest() throws Exception {
 124         boolean failed = false;
 125         Jlink jl = new Jlink();
 126 
 127         try {
 128             jl.build(null);
 129             failed = true;
 130         } catch (Exception ex) {
 131             // XXX OK
 132         }
 133         if (failed) {
 134             throw new Exception("Should have failed");
 135         }
 136         System.out.println(jl);
 137 
 138         JlinkConfiguration config
 139                 = new JlinkConfiguration(null, null, null, null);
 140 
 141         System.out.println(config);
 142 
 143         Plugin p = Jlink.newPlugin("toto", Collections.emptyMap(), null);
 144         if (p != null) {
 145             throw new Exception("Plugin should be null");
 146         }
 147 
 148         Plugin p2 = Jlink.newPlugin("compress", Map.of("compress", "1"), null);
 149         if (p2 == null) {
 150             throw new Exception("Plugin should not be null");
 151         }
 152     }
 153 
 154     private static void test() throws Exception {
 155         Jlink jlink = new Jlink();
 156         Path output = Paths.get("integrationout");
 157         List<Path> modulePaths = new ArrayList<>();
 158         File jmods
 159                 = JImageGenerator.getJModsDir(new File(System.getProperty("test.jdk")));
 160         modulePaths.add(jmods.toPath());
 161         Set<String> mods = new HashSet<>();
 162         mods.add("java.management");
 163         Set<String> limits = new HashSet<>();
 164         limits.add("java.management");
 165         JlinkConfiguration config = new Jlink.JlinkConfiguration(output,
 166                 modulePaths, mods, limits, null);
 167 
 168         List<Plugin> lst = new ArrayList<>();
 169 
 170         //Strip debug
 171         {
 172             Map<String, String> config1 = new HashMap<>();
 173             config1.put(StripDebugPlugin.NAME, "");
 174             Plugin strip = Jlink.newPlugin("strip-debug", config1, null);
 175             lst.add(strip);
 176         }
 177         // compress
 178         {
 179             Map<String, String> config1 = new HashMap<>();
 180             config1.put(DefaultCompressPlugin.NAME, "2");
 181             Plugin compress
 182                     = Jlink.newPlugin("compress", config1, null);
 183             lst.add(compress);
 184         }
 185         // Post processor
 186         {




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.io.File;
  25 import java.io.FileReader;
  26 import java.io.IOException;
  27 import java.io.UncheckedIOException;
  28 import java.nio.ByteOrder;
  29 import java.nio.file.Files;
  30 import java.nio.file.Path;
  31 import java.nio.file.Paths;
  32 import java.util.ArrayList;
  33 import java.util.Collections;
  34 import java.util.HashMap;
  35 import java.util.HashSet;
  36 import java.util.List;
  37 import java.util.Map;
  38 import java.util.Properties;
  39 import java.util.Set;
  40 import java.util.function.Function;
  41 import jdk.tools.jlink.internal.Jlink;
  42 import jdk.tools.jlink.builder.DefaultImageBuilder;
  43 import jdk.tools.jlink.plugin.ResourcePool;
  44 import jdk.tools.jlink.plugin.ResourcePoolBuilder;
  45 import jdk.tools.jlink.plugin.Plugin;
  46 import jdk.tools.jlink.internal.ExecutableImage;
  47 import jdk.tools.jlink.internal.Jlink.JlinkConfiguration;
  48 import jdk.tools.jlink.internal.Jlink.PluginsConfiguration;


 119         }
 120         apitest();
 121         test();
 122     }
 123 
 124     private static void apitest() throws Exception {
 125         boolean failed = false;
 126         Jlink jl = new Jlink();
 127 
 128         try {
 129             jl.build(null);
 130             failed = true;
 131         } catch (Exception ex) {
 132             // XXX OK
 133         }
 134         if (failed) {
 135             throw new Exception("Should have failed");
 136         }
 137         System.out.println(jl);
 138 





 139         Plugin p = Jlink.newPlugin("toto", Collections.emptyMap(), null);
 140         if (p != null) {
 141             throw new Exception("Plugin should be null");
 142         }
 143 
 144         Plugin p2 = Jlink.newPlugin("compress", Map.of("compress", "1"), null);
 145         if (p2 == null) {
 146             throw new Exception("Plugin should not be null");
 147         }
 148     }
 149 
 150     private static void test() throws Exception {
 151         Jlink jlink = new Jlink();
 152         Path output = Paths.get("integrationout");
 153         List<Path> modulePaths = new ArrayList<>();
 154         File jmods
 155                 = JImageGenerator.getJModsDir(new File(System.getProperty("test.jdk")));
 156         modulePaths.add(jmods.toPath());
 157         Set<String> mods = new HashSet<>();
 158         mods.add("java.management");
 159         Set<String> limits = new HashSet<>();
 160         limits.add("java.management");
 161         JlinkConfiguration config = new Jlink.JlinkConfiguration(output,
 162                 modulePaths, mods, limits, ByteOrder.nativeOrder());
 163 
 164         List<Plugin> lst = new ArrayList<>();
 165 
 166         //Strip debug
 167         {
 168             Map<String, String> config1 = new HashMap<>();
 169             config1.put(StripDebugPlugin.NAME, "");
 170             Plugin strip = Jlink.newPlugin("strip-debug", config1, null);
 171             lst.add(strip);
 172         }
 173         // compress
 174         {
 175             Map<String, String> config1 = new HashMap<>();
 176             config1.put(DefaultCompressPlugin.NAME, "2");
 177             Plugin compress
 178                     = Jlink.newPlugin("compress", config1, null);
 179             lst.add(compress);
 180         }
 181         // Post processor
 182         {


< prev index next >