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 import java.io.IOException; 24 import java.util.HashMap; 25 import java.util.Map; 26 import jdk.tools.jlink.internal.ImagePluginProviderRepository; 27 import jdk.tools.jlink.plugins.CmdResourcePluginProvider; 28 import jdk.tools.jlink.plugins.ResourcePlugin; 29 import tests.Helper; 30 31 /* 32 * @test 33 * @summary Test jlink options 34 * @author Jean-Francois Denise 35 * @library ../lib 36 * @modules java.base/jdk.internal.jimage 37 * jdk.jdeps/com.sun.tools.classfile 38 * jdk.jlink/jdk.tools.jlink 39 * jdk.jlink/jdk.tools.jlink.internal 40 * jdk.jlink/jdk.tools.jmod 41 * jdk.jlink/jdk.tools.jimage 42 * @build tests.* 43 * @run main JLinkOptionsTest 44 */ 45 public class JLinkOptionsTest { 46 47 private static class TestProvider extends CmdResourcePluginProvider { 48 49 private final String option; 50 private final Map<String, String> options; 51 52 private TestProvider(String name, String option, 53 Map<String, String> options) { 54 super(name, ""); 55 this.option = option; 56 this.options = options; 57 } 58 59 @Override 60 public ResourcePlugin[] newPlugins(String[] arguments, 61 Map<String, String> otherOptions) throws IOException { 62 return null; 63 } 64 65 @Override 66 public String getCategory() { 67 return null; 68 } 69 70 @Override 71 public String getToolArgument() { 72 return null; 73 } 74 75 @Override 76 public String getToolOption() { 77 return option; 78 79 } 80 81 @Override 82 public Map<String, String> getAdditionalOptions() { 83 return options; 84 } 85 } 86 87 public static void main(String[] args) throws Exception { 88 Helper helper = Helper.newHelper(); 89 if (helper == null) { 90 System.err.println("Test not run"); 91 return; 92 } 93 helper.generateDefaultModules(); 94 { 95 // multiple plugins with same option 96 String option = "test1"; 97 ImagePluginProviderRepository. 98 registerPluginProvider(new TestProvider("test1", option, null)); 99 ImagePluginProviderRepository. 100 registerPluginProvider(new TestProvider("test2", option, null)); 101 helper.generateDefaultImage("composite2").assertFailure("Error: More than one plugin enabled by test1 option"); 102 ImagePluginProviderRepository.unregisterPluginProvider("test1"); 103 ImagePluginProviderRepository.unregisterPluginProvider("test2"); 104 } 105 106 { 107 // option and optional options collision 108 Map<String, String> options = new HashMap<>(); 109 options.put("test1", ""); 110 ImagePluginProviderRepository. 111 registerPluginProvider(new TestProvider("test1", "test1", null)); 112 ImagePluginProviderRepository. 113 registerPluginProvider(new TestProvider("test2", "test2", options)); 114 115 helper.generateDefaultImage("composite2").assertFailure("Error: More than one plugin enabled by test1 option"); 116 ImagePluginProviderRepository.unregisterPluginProvider("test1"); 117 ImagePluginProviderRepository.unregisterPluginProvider("test2"); 118 } 119 } 120 }