From: Decebal Suiu Date: Fri, 12 Apr 2019 18:29:50 +0000 (+0300) Subject: Add possibility to add extra properties X-Git-Tag: release-3.0.0~2^2~35 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=78a7802793806c84546a1f3b874e70b91b025829;p=pf4j.git Add possibility to add extra properties --- diff --git a/pf4j/src/test/java/org/pf4j/plugin/PluginZip.java b/pf4j/src/test/java/org/pf4j/plugin/PluginZip.java index 72e3241..ee665d7 100644 --- a/pf4j/src/test/java/org/pf4j/plugin/PluginZip.java +++ b/pf4j/src/test/java/org/pf4j/plugin/PluginZip.java @@ -18,13 +18,14 @@ package org.pf4j.plugin; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Path; +import java.util.Map; import java.util.Properties; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; /** - * Represents a plugin zip/jar file. - * The "plugin.properties" file is created on the fly from the information supplied in Builder. + * Represents a plugin {@code zip} file. + * The {@code plugin.properties} file is created on the fly from the information supplied in {@link Builder}. * * @author Decebal Suiu */ @@ -65,6 +66,7 @@ public class PluginZip { private final String pluginId; private String pluginVersion; + private Map properties; public Builder(Path path, String pluginId) { this.path = path; @@ -77,6 +79,15 @@ public class PluginZip { return this; } + /** + * Add extra properties to the {@code properties} file. + */ + public Builder properties(Map properties) { + this.properties = properties; + + return this; + } + public PluginZip build() throws IOException { createPropertiesFile(); @@ -84,15 +95,18 @@ public class PluginZip { } protected void createPropertiesFile() throws IOException { - Properties properties = new Properties(); - properties.setProperty("plugin.id", pluginId); - properties.setProperty("plugin.version", pluginVersion); - properties.setProperty("plugin.class", "org.pf4j.plugin.TestPlugin"); + Properties props = new Properties(); + props.setProperty("plugin.id", pluginId); + props.setProperty("plugin.version", pluginVersion); + props.setProperty("plugin.class", "org.pf4j.plugin.TestPlugin"); + if (properties != null) { + props.putAll(properties); + } ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(path.toFile())); ZipEntry propertiesFile = new ZipEntry("plugin.properties"); outputStream.putNextEntry(propertiesFile); - properties.store(outputStream, ""); + props.store(outputStream, ""); outputStream.closeEntry(); outputStream.close(); }