当前位置: 首页>>代码示例>>Java>>正文


Java Plugin类代码示例

本文整理汇总了Java中jdk.tools.jlink.plugin.Plugin的典型用法代码示例。如果您正苦于以下问题:Java Plugin类的具体用法?Java Plugin怎么用?Java Plugin使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Plugin类属于jdk.tools.jlink.plugin包,在下文中一共展示了Plugin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addAutoEnabledPlugins

import jdk.tools.jlink.plugin.Plugin; //导入依赖的package包/类
private PluginsConfiguration addAutoEnabledPlugins(PluginsConfiguration pluginsConfig) {
    List<Plugin> plugins = new ArrayList<>(pluginsConfig.getPlugins());
    List<Plugin> bootPlugins = PluginRepository.getPlugins(ModuleLayer.boot());
    for (Plugin bp : bootPlugins) {
        if (Utils.isAutoEnabled(bp)) {
            try {
                bp.configure(Collections.emptyMap());
            } catch (IllegalArgumentException e) {
                if (JlinkTask.DEBUG) {
                    System.err.println("Plugin " + bp.getName() + " threw exception with config: {}");
                    e.printStackTrace();
                }
                throw e;
            }
            plugins.add(bp);
        }
    }
    return new PluginsConfiguration(plugins, pluginsConfig.getImageBuilder(),
        pluginsConfig.getLastSorterPluginName());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:Jlink.java

示例2: newPlugin

import jdk.tools.jlink.plugin.Plugin; //导入依赖的package包/类
/**
 * Build plugin for the passed name.
 *
 * @param config Optional config.
 * @param name Non null name.
 * @param pluginsLayer
 * @return A plugin or null if no plugin found.
 */
public static Plugin newPlugin(Map<String, String> config, String name,
        ModuleLayer pluginsLayer) {
    Objects.requireNonNull(name);
    Objects.requireNonNull(pluginsLayer);
    Plugin plugin = getPlugin(name, pluginsLayer);
    if (plugin != null) {
        try {
            plugin.configure(config);
        } catch (IllegalArgumentException e) {
            if (JlinkTask.DEBUG) {
                System.err.println("Plugin " + plugin.getName() + " threw exception with config: " + config);
                e.printStackTrace();
            }
            throw e;
        }
    }
    return plugin;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:PluginRepository.java

示例3: getPlugin

import jdk.tools.jlink.plugin.Plugin; //导入依赖的package包/类
private static <T extends Plugin> T getPlugin(Class<T> clazz, String name,
        ModuleLayer pluginsLayer) {
    Objects.requireNonNull(name);
    Objects.requireNonNull(pluginsLayer);
    @SuppressWarnings("unchecked")
    T provider = null;
    List<T> javaProviders = getPlugins(clazz, pluginsLayer);
    for(T factory : javaProviders) {
        if (factory.getName().equals(name)) {
            if (provider != null) {
                throw new PluginException("Multiple plugin "
                        + "for the name " + name);
            }
            provider = factory;
        }
    }
    return provider;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:PluginRepository.java

示例4: getPlugins

import jdk.tools.jlink.plugin.Plugin; //导入依赖的package包/类
/**
 * The plugins accessible in the current context.
 *
 * @param pluginsLayer
 * @return The list of plugins.
 */
private static <T extends Plugin> List<T> getPlugins(Class<T> clazz, ModuleLayer pluginsLayer) {
    Objects.requireNonNull(pluginsLayer);
    List<T> factories = new ArrayList<>();
    try {
        Iterator<T> providers
                = ServiceLoader.load(pluginsLayer, clazz).iterator();
        while (providers.hasNext()) {
            factories.add(providers.next());
        }
        registeredPlugins.values().stream().forEach((fact) -> {
            if (clazz.isInstance(fact)) {
                @SuppressWarnings("unchecked")
                T trans = (T) fact;
                factories.add(trans);
            }
        });
        return factories;
    } catch (Exception ex) {
        throw new PluginException(ex);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:PluginRepository.java

示例5: apitest

import jdk.tools.jlink.plugin.Plugin; //导入依赖的package包/类
private static void apitest() throws Exception {
    boolean failed = false;
    Jlink jl = new Jlink();

    try {
        jl.build(null);
        failed = true;
    } catch (Exception ex) {
        // XXX OK
    }
    if (failed) {
        throw new Exception("Should have failed");
    }
    System.out.println(jl);

    Plugin p = Jlink.newPlugin("toto", Collections.emptyMap(), null);
    if (p != null) {
        throw new Exception("Plugin should be null");
    }

    Plugin p2 = Jlink.newPlugin("compress", Map.of("compress", "1"), null);
    if (p2 == null) {
        throw new Exception("Plugin should not be null");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:IntegrationTest.java

示例6: testOptions

import jdk.tools.jlink.plugin.Plugin; //导入依赖的package包/类
private static void testOptions() throws Exception {
    List<Plugin> builtInPlugins = new ArrayList<>();
    builtInPlugins.addAll(PluginRepository.getPlugins(ModuleLayer.boot()));
    if(builtInPlugins.isEmpty()) {
        throw new Exception("No builtin plugins");
    }
    List<String> options = new ArrayList<>();
    for (Plugin p : builtInPlugins) {
        if (p.getOption() == null) {
            throw new Exception("Null option for " + p.getName());
        }
        if (options.contains(p.getName())) {
            throw new Exception("Option " + p.getOption() + " used more than once");
        }
        options.add(p.getName());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:JLink2Test.java

示例7: test

import jdk.tools.jlink.plugin.Plugin; //导入依赖的package包/类
public void test() throws Exception {
    CustomPlugin plugin = new CustomPlugin();
    PluginRepository.registerPlugin(plugin);
    List<Plugin> plugins = new ArrayList<>();
    plugins.add(createPlugin(CustomPlugin.NAME));
    ImagePluginStack stack = ImagePluginConfiguration.parseConfiguration(new Jlink.PluginsConfiguration(plugins,
            null, null));
    ResourcePoolManager inResources = new ResourcePoolManager(ByteOrder.nativeOrder(), new CustomStringTable());
    inResources.add(ResourcePoolEntry.create("/aaa/bbb/res1.class", new byte[90]));
    inResources.add(ResourcePoolEntry.create("/aaa/bbb/res2.class", new byte[90]));
    inResources.add(ResourcePoolEntry.create("/aaa/bbb/res3.class", new byte[90]));
    inResources.add(ResourcePoolEntry.create("/aaa/ddd/res1.class", new byte[90]));
    inResources.add(ResourcePoolEntry.create("/aaa/res1.class", new byte[90]));
    ResourcePool outResources = stack.visitResources(inResources);
    Collection<String> input = inResources.entries()
            .map(Object::toString)
            .collect(Collectors.toList());
    Collection<String> output = outResources.entries()
            .map(Object::toString)
            .collect(Collectors.toList());
    if (!input.equals(output)) {
        throw new AssertionError("Input and output resources differ: input: "
                + input + ", output: " + output);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:PrevisitorTest.java

示例8: checkTwoLastSorters

import jdk.tools.jlink.plugin.Plugin; //导入依赖的package包/类
private void checkTwoLastSorters() throws Exception {
    List<Plugin> plugins = new ArrayList<>();
    plugins.add(createPlugin("sorterplugin5", "/a"));
    plugins.add(createPlugin("sorterplugin6", "/a"));
    PluginsConfiguration config = new Jlink.PluginsConfiguration(plugins,
            null, "sorterplugin5");

    ImagePluginStack stack = ImagePluginConfiguration.parseConfiguration(config);

    // check order
    ResourcePoolManager res = fillOutResourceResourcePool();

    try {
        stack.visitResources(res);
        throw new AssertionError("Exception expected: Order of resources is already frozen." +
                "Plugin sorterplugin6 is badly located");
    } catch (Exception e) {
        // expected
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:LastSorterTest.java

示例9: checkPositiveCase

import jdk.tools.jlink.plugin.Plugin; //导入依赖的package包/类
private void checkPositiveCase() throws Exception {
    List<Plugin> plugins = new ArrayList<>();
    plugins.add(createPlugin("sorterplugin1", "/c"));
    plugins.add(createPlugin("sorterplugin2", "/b"));
    plugins.add(createPlugin("sorterplugin3", "/a"));

    PluginsConfiguration config = new Jlink.PluginsConfiguration(plugins,
            null, "sorterplugin3");

    ImagePluginStack stack = ImagePluginConfiguration.parseConfiguration(config);

    // check order
    ResourcePoolManager res = fillOutResourceResourcePool();

    stack.visitResources(res);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:LastSorterTest.java

示例10: checkUnknownPlugin

import jdk.tools.jlink.plugin.Plugin; //导入依赖的package包/类
private void checkUnknownPlugin() {
    List<Plugin> plugins = new ArrayList<>();
    plugins.add(createPlugin("sorterplugin1", "/1"));
    plugins.add(createPlugin("sorterplugin2", "/1"));
    plugins.add(createPlugin("sorterplugin3", "/1"));
    plugins.add(createPlugin("sorterplugin4", "/1"));

    PluginsConfiguration config = new Jlink.PluginsConfiguration(plugins,
            null, "sorterplugin5");
    try {
        ImagePluginConfiguration.parseConfiguration(config);
        throw new AssertionError("Unknown plugin should have failed.");
    } catch (Exception ex) {
        // XXX OK expected
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:LastSorterTest.java

示例11: checkOrderAfterLastSorter

import jdk.tools.jlink.plugin.Plugin; //导入依赖的package包/类
private void checkOrderAfterLastSorter() throws Exception {
    List<Plugin> plugins = new ArrayList<>();
    plugins.add(createPlugin("sorterplugin1", "/c"));
    plugins.add(createPlugin("sorterplugin2", "/b"));
    plugins.add(createPlugin("sorterplugin3", "/a"));
    plugins.add(createPlugin("sorterplugin4", "/d"));

    PluginsConfiguration config = new Jlink.PluginsConfiguration(plugins,
            null, "sorterplugin3");

    ImagePluginStack stack = ImagePluginConfiguration.parseConfiguration(config);

    // check order
    ResourcePoolManager res = fillOutResourceResourcePool();
    try {
        stack.visitResources(res);
        throw new AssertionError("Order was changed after the last sorter, but no exception occurred");
    } catch (Exception ex) {
        // XXX OK expected
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:LastSorterTest.java

示例12: getPlugin

import jdk.tools.jlink.plugin.Plugin; //导入依赖的package包/类
private static <T extends Plugin> T getPlugin(Class<T> clazz, String name,
        Layer pluginsLayer) {
    Objects.requireNonNull(name);
    Objects.requireNonNull(pluginsLayer);
    @SuppressWarnings("unchecked")
    T provider = null;
    List<T> javaProviders = getPlugins(clazz, pluginsLayer);
    for(T factory : javaProviders) {
        if (factory.getName().equals(name)) {
            if (provider != null) {
                throw new PluginException("Multiple plugin "
                        + "for the name " + name);
            }
            provider = factory;
        }
    }
    return provider;
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:19,代码来源:PluginRepository.java

示例13: getPlugins

import jdk.tools.jlink.plugin.Plugin; //导入依赖的package包/类
/**
 * The post processors accessible in the current context.
 *
 * @param pluginsLayer
 * @return The list of post processors.
 */
private static <T extends Plugin> List<T> getPlugins(Class<T> clazz, Layer pluginsLayer) {
    Objects.requireNonNull(pluginsLayer);
    List<T> factories = new ArrayList<>();
    try {
        Iterator<T> providers
                = ServiceLoader.load(pluginsLayer, clazz).iterator();
        while (providers.hasNext()) {
            factories.add(providers.next());
        }
        registeredPlugins.values().stream().forEach((fact) -> {
            if (clazz.isInstance(fact)) {
                @SuppressWarnings("unchecked")
                T trans = (T) fact;
                factories.add(trans);
            }
        });
        return factories;
    } catch (Exception ex) {
        throw new PluginException(ex);
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:28,代码来源:PluginRepository.java

示例14: testOptions

import jdk.tools.jlink.plugin.Plugin; //导入依赖的package包/类
private static void testOptions() throws Exception {
    List<Plugin> builtInPlugins = new ArrayList<>();
    builtInPlugins.addAll(PluginRepository.getPlugins(Layer.boot()));
    if(builtInPlugins.isEmpty()) {
        throw new Exception("No builtin plugins");
    }
    List<String> options = new ArrayList<>();
    for (Plugin p : builtInPlugins) {
        if (p.getOption() == null) {
            throw new Exception("Null option for " + p.getName());
        }
        if (options.contains(p.getName())) {
            throw new Exception("Option " + p.getOption() + " used more than once");
        }
        options.add(p.getName());
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:18,代码来源:JLink2Test.java

示例15: test

import jdk.tools.jlink.plugin.Plugin; //导入依赖的package包/类
public void test() throws Exception {
    CustomPlugin plugin = new CustomPlugin();
    PluginRepository.registerPlugin(plugin);
    List<Plugin> plugins = new ArrayList<>();
    plugins.add(createPlugin(CustomPlugin.NAME));
    ImagePluginStack stack = ImagePluginConfiguration.parseConfiguration(new Jlink.PluginsConfiguration(plugins,
            null, null));
    ModulePoolImpl inResources = new ModulePoolImpl(ByteOrder.nativeOrder(), new CustomStringTable());
    inResources.add(ModuleEntry.create("/aaa/bbb/res1.class", new byte[90]));
    inResources.add(ModuleEntry.create("/aaa/bbb/res2.class", new byte[90]));
    inResources.add(ModuleEntry.create("/aaa/bbb/res3.class", new byte[90]));
    inResources.add(ModuleEntry.create("/aaa/ddd/res1.class", new byte[90]));
    inResources.add(ModuleEntry.create("/aaa/res1.class", new byte[90]));
    ModulePool outResources = stack.visitResources(inResources);
    Collection<String> input = inResources.entries()
            .map(Object::toString)
            .collect(Collectors.toList());
    Collection<String> output = outResources.entries()
            .map(Object::toString)
            .collect(Collectors.toList());
    if (!input.equals(output)) {
        throw new AssertionError("Input and output resources differ: input: "
                + input + ", output: " + output);
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:26,代码来源:PrevisitorTest.java


注:本文中的jdk.tools.jlink.plugin.Plugin类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。