morningman commented on a change in pull request #2463: Add fe plugin framework URL: https://github.com/apache/incubator-doris/pull/2463#discussion_r395094109
########## File path: fe/src/main/java/org/apache/doris/plugin/DynamicPluginLoader.java ########## @@ -0,0 +1,232 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.plugin; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.net.URL; +import java.net.URLClassLoader; +import java.nio.file.DirectoryStream; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Set; + +import org.apache.commons.io.FileUtils; +import org.apache.doris.common.UserException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class DynamicPluginLoader extends PluginLoader { + private final static Logger LOG = LogManager.getLogger(DynamicPluginLoader.class); + + protected Path tempPath; + + protected Path installPath; + + DynamicPluginLoader(String pluginPath, String source) { + super(pluginPath, source); + } + + DynamicPluginLoader(String pluginPath, PluginInfo info) { + super(pluginPath, info); + this.installPath = FileSystems.getDefault().getPath(pluginDir.toString(), pluginInfo.getName()); + this.tempPath = installPath; + } + + @Override + public boolean isDynamicPlugin() { + return true; + } + + /** + * get Plugin .zip and read plugin.properties + */ + @Override + public PluginInfo getPluginInfo() throws IOException, UserException { + // already install + if (pluginInfo != null) { + return pluginInfo; + } + + // download plugin and extract + PluginZip zip = new PluginZip(source); + Path target = Files.createTempDirectory(pluginDir, ".install_"); + + tempPath = zip.extract(target); + + pluginInfo = PluginInfo.readFromProperties(tempPath, source); + + return pluginInfo; + } + + /** + * move plugin to Doris's PLUGIN_DIR and dynamic load the plugin class + */ + public void install() throws UserException, IOException { + if (hasInstall()) { + throw new UserException("Plugin " + pluginInfo.getName() + " is already install."); + } + + getPluginInfo(); + + Path realPath = movePlugin(); + + plugin = dynamicLoadPlugin(realPath); + + pluginInstallValid(); + + plugin.init(pluginInfo, pluginContext); + } + + private boolean hasInstall() { Review comment: ```suggestion private boolean hasInstalled() { ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org