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.util.ArrayList;
  24 import java.util.List;
  25 import java.util.Map;
  26 import java.util.Set;
  27 import jdk.tools.jlink.plugin.ResourcePool;
  28 import jdk.tools.jlink.plugin.ResourcePoolBuilder;
  29 import jdk.tools.jlink.internal.PluginRepository;
  30 import jdk.tools.jlink.plugin.Plugin;
  31 
  32 import tests.Helper;
  33 
  34 /*
  35  * @test
  36  * @summary Test jlink options
  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.internal
  42  *          jdk.jlink/jdk.tools.jlink.plugin
  43  *          jdk.jlink/jdk.tools.jmod
  44  *          jdk.jlink/jdk.tools.jimage
  45  *          jdk.compiler
  46  * @build tests.*
  47  * @run main JLinkOptionsTest
  48  */
  49 public class JLinkOptionsTest {
  50 
  51     private static class TestPlugin implements Plugin {
  52         private final String name;
  53         private final String option;
  54 
  55         private TestPlugin(String name, String option) {
  56             this.name = name;
  57             this.option = option;
  58         }
  59 
  60 
  61         @Override
  62         public String getOption() {
  63             return option;
  64         }
  65 
  66         @Override
  67         public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) {
  68             return out.build();
  69         }
  70 
  71         @Override
  72         public String getName() {
  73             return name;
  74         }
  75 
  76         @Override
  77         public String getDescription() {
  78             return name;
  79         }
  80     }
  81 
  82     public static void main(String[] args) throws Exception {
  83         Helper helper = Helper.newHelper();
  84         if (helper == null) {
  85             System.err.println("Test not run");
  86             return;
  87         }
  88         helper.generateDefaultModules();
  89         {
  90             // multiple plugins with same option
  91 
  92             PluginRepository.
  93                     registerPlugin(new TestPlugin("test1", "test1"));
  94             PluginRepository.
  95                     registerPlugin(new TestPlugin("test2", "test1"));
  96             helper.generateDefaultImage("composite2").assertFailure("Error: More than one plugin enabled by test1 option");
  97             PluginRepository.unregisterPlugin("test1");
  98             PluginRepository.unregisterPlugin("test2");
  99         }
 100     }
 101 }