1 /* 2 * Copyright (c) 2015, 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. 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.IOException; 25 import java.nio.file.Files; 26 import java.nio.file.Path; 27 import java.nio.file.Paths; 28 import java.util.Collections; 29 30 import jdk.tools.jlink.internal.ImagePluginConfiguration; 31 import jdk.tools.jlink.plugins.CmdPluginProvider; 32 import tests.Helper; 33 34 /* 35 * @test 36 * @summary Test image creation 37 * @author Jean-Francois Denise 38 * @library ../lib 39 * @modules java.base/jdk.internal.jimage 40 * jdk.jdeps/com.sun.tools.classfile 41 * jdk.jlink/jdk.tools.jlink 42 * jdk.jlink/jdk.tools.jlink.internal 43 * jdk.jlink/jdk.tools.jmod 44 * jdk.jlink/jdk.tools.jimage 45 * @build tests.* 46 * @run main/othervm -verbose:gc -Xmx1g JLinkPluginsTest 47 */ 48 public class JLinkPluginsTest { 49 50 private static String createProperties(String fileName, String content) throws IOException { 51 Path p = Paths.get(fileName); 52 Files.write(p, Collections.singletonList(content)); 53 return p.toAbsolutePath().toString(); 54 } 55 56 public static void main(String[] args) throws Exception { 57 Helper helper = Helper.newHelper(); 58 if (helper == null) { 59 System.err.println("Test not run"); 60 return; 61 } 62 helper.generateDefaultModules(); 63 { 64 // zip 65 String[] userOptions = {"--zip", "toto"}; 66 String moduleName = "zipfiltercomposite"; 67 helper.generateDefaultJModule(moduleName, "composite2"); 68 Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess(); 69 helper.checkImage(imageDir, moduleName, null, null); 70 } 71 { 72 // Skip debug 73 String[] userOptions = {"--strip-java-debug", "on"}; 74 String moduleName = "skipdebugcomposite"; 75 helper.generateDefaultJModule(moduleName, "composite2"); 76 Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess(); 77 helper.checkImage(imageDir, moduleName, null, null); 78 } 79 { 80 // Filter out files 81 String[] userOptions = {"--exclude-resources", "*.jcov, */META-INF/*"}; 82 String moduleName = "excludecomposite"; 83 helper.generateDefaultJModule(moduleName, "composite2"); 84 String[] res = {".jcov", "/META-INF/"}; 85 Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess(); 86 helper.checkImage(imageDir, moduleName, res, null); 87 } 88 { 89 // Shared UTF_8 Constant Pool entries 90 String[] userOptions = {"--compact-cp", "*"}; 91 String moduleName = "cpccomposite"; 92 helper.generateDefaultJModule(moduleName, "composite2"); 93 Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess(); 94 helper.checkImage(imageDir, moduleName, null, null); 95 } 96 { 97 // Ordered zip and constant cp 98 String[] userOptions = {"--zip:1", "*", "--compact-cp:0", "*"}; 99 String moduleName = "zipcpccomposite"; 100 helper.generateDefaultJModule(moduleName, "composite2"); 101 Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess(); 102 helper.checkImage(imageDir, moduleName, null, null); 103 } 104 } 105 }