-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible for plugins to request a shared class loader
In #2280 we changed the plugin loader so that all plugins share one class loader and they can see each other. (needed for plugin inder-dependencies) This is problematic when different plugins have conflicting dependencies. (see #2436) With this change, every plugin gets its own class loader by default so we can avoid dependency clashes. Plugins which depend on other plugins can request a shared class loader via a graylog-plugin.properties file. Fixes #2436
- Loading branch information
Showing
2 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
graylog2-server/src/main/java/org/graylog2/shared/plugins/PluginProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* This file is part of Graylog. | ||
* | ||
* Graylog is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Graylog is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.graylog2.shared.plugins; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.InputStream; | ||
import java.util.Properties; | ||
import java.util.jar.JarFile; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class PluginProperties { | ||
private static final Logger LOG = LoggerFactory.getLogger(PluginProperties.class); | ||
|
||
private static final String GRAYLOG_PLUGIN_PROPERTIES = "graylog-plugin.properties"; | ||
|
||
private static final String PROPERTY_ISOLATED = "isolated"; | ||
private static final String PROPERTY_ISOLATED_DEFAULT = "true"; | ||
|
||
private final boolean isolated; | ||
|
||
public PluginProperties(Properties properties) { | ||
this.isolated = Boolean.parseBoolean((String) properties.getOrDefault(PROPERTY_ISOLATED, PROPERTY_ISOLATED_DEFAULT)); | ||
} | ||
|
||
public static PluginProperties fromJarFile(final String filename) { | ||
// Try to load the plugin properties from the JAR file. This fails for plugins which do not have the | ||
// properties file. | ||
final Properties properties = new Properties(); | ||
try { | ||
LOG.debug("Loading {} from {}", GRAYLOG_PLUGIN_PROPERTIES, filename); | ||
final JarFile jarFile = new JarFile(requireNonNull(filename)); | ||
final InputStream inputStream = jarFile.getInputStream(jarFile.getEntry(GRAYLOG_PLUGIN_PROPERTIES)); | ||
properties.load(inputStream); | ||
} catch (Exception e) { | ||
LOG.debug("Unable to load {} from plugin {}", GRAYLOG_PLUGIN_PROPERTIES, filename, e); | ||
} | ||
|
||
return new PluginProperties(properties); | ||
} | ||
|
||
public boolean isIsolated() { | ||
return this.isolated; | ||
} | ||
} |