All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.codingdebugallday.integration.pf4j.DefaultPf4jFactory Maven / Gradle / Ivy

The newest version!
package com.github.codingdebugallday.integration.pf4j;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;

import com.github.codingdebugallday.exceptions.PluginException;
import com.github.codingdebugallday.integration.IntegrationConfiguration;
import org.pf4j.*;

/**
 * 

* 默认的插件集成工厂 *

* * @author isaac 2020/6/16 15:55 * @since 1.0 */ public class DefaultPf4jFactory implements Pf4jFactory { private final IntegrationConfiguration configuration; public DefaultPf4jFactory(IntegrationConfiguration configuration) { this.configuration = configuration; } @Override public PluginManager getPluginManager() { if (configuration == null) { throw new NullPointerException("IntegrationConfiguration is null"); } RuntimeMode environment = configuration.environment(); if (environment == null) { throw new PluginException("Configuration RuntimeMode is null" + configuration.environment()); } if (RuntimeMode.DEVELOPMENT == environment) { // 开发环境下的插件管理者 Path path = Paths.get(getDevPluginDir(configuration)); return new DefaultPluginManager(path) { @Override public RuntimeMode getRuntimeMode() { System.setProperty("pf4j.mode", RuntimeMode.DEVELOPMENT.toString()); return RuntimeMode.DEVELOPMENT; } @Override protected PluginDescriptorFinder createPluginDescriptorFinder() { return new CompoundPluginDescriptorFinder() .add(new ResolvePropertiesPluginDescriptorFinder()) .add(new ManifestPluginDescriptorFinder()); } }; } else if (RuntimeMode.DEPLOYMENT == environment) { // 运行环境下的插件管理者 Path path = Paths.get(getProdPluginDir(configuration)); return new DefaultPluginManager(path) { @Override protected PluginRepository createPluginRepository() { return new CompoundPluginRepository() .add(new JarPluginRepository(getPluginsRoot())); } }; } else { throw new PluginException("Not found run environment " + configuration.environment()); } } private String getDevPluginDir(IntegrationConfiguration configuration) { String pluginDir = configuration.pluginPath(); if (Objects.equals("", pluginDir)) { pluginDir = "./plugins/"; } return pluginDir; } private String getProdPluginDir(IntegrationConfiguration configuration) { String pluginDir = configuration.pluginPath(); if (Objects.equals("", pluginDir)) { pluginDir = "plugins"; } return pluginDir; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy