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 tests.Helper; 31 32 /* 33 * @test 34 * @summary Test image creation 35 * @author Jean-Francois Denise 36 * @library ../lib 37 * @modules java.base/jdk.internal.jimage 38 * jdk.jdeps/com.sun.tools.classfile 39 * jdk.jlink/jdk.tools.jlink.internal 40 * jdk.jlink/jdk.tools.jmod 41 * jdk.jlink/jdk.tools.jimage 42 * jdk.compiler 43 * @build tests.* 44 * @run main/othervm -verbose:gc -Xmx1g JLinkPluginsTest 45 */ 46 public class JLinkPluginsTest { 47 48 private static String createProperties(String fileName, String content) throws IOException { 49 Path p = Paths.get(fileName); 50 Files.write(p, Collections.singletonList(content)); 51 return p.toAbsolutePath().toString(); 52 } 53 54 public static void main(String[] args) throws Exception { 55 Helper helper = Helper.newHelper(); 56 if (helper == null) { 57 System.err.println("Test not run"); 58 return; 59 } 60 helper.generateDefaultModules(); 61 { 62 // Skip debug 63 String[] userOptions = {"--strip-debug"}; 64 String moduleName = "skipdebugcomposite"; 65 helper.generateDefaultJModule(moduleName, "composite2"); 66 Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess(); 67 helper.checkImage(imageDir, moduleName, null, null); 68 } 69 { 70 // Filter out files 71 String[] userOptions = {"--exclude-resources", "*.jcov, */META-INF/*"}; 72 String moduleName = "excludecomposite"; 73 helper.generateDefaultJModule(moduleName, "composite2"); 74 String[] res = {".jcov", "/META-INF/"}; 75 Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess(); 76 helper.checkImage(imageDir, moduleName, res, null); 77 } 78 { 79 // Optimize Class.forName 80 String[] userOptions = {"--class-for-name"}; 81 String moduleName = "classforname"; 82 helper.generateDefaultJModule(moduleName, "composite2"); 83 Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess(); 84 helper.checkImage(imageDir, moduleName, null, null); 85 } 86 { 87 // disable generate jli classes - JDK-8160063 88 String[] userOptions = {"--disable-plugin", "generate-jli-classes"}; 89 String moduleName = "jlidisabled"; 90 helper.generateDefaultJModule(moduleName, "composite2"); 91 Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess(); 92 helper.checkImage(imageDir, moduleName, null, null); 93 } 94 { 95 // disable invalid plugin - JDK-8160063 96 String[] userOptions = {"--disable-plugin", "non-existent-plugin"}; 97 String moduleName = "invaliddisabled"; 98 helper.generateDefaultJModule(moduleName, "composite2"); 99 helper.generateDefaultImage(userOptions, moduleName). 100 assertFailure("Error: No such plugin: non-existent-plugin"); 101 } 102 } 103 }