]> source.dussan.org Git - pf4j.git/commitdiff
Add possibility to add extra properties
authorDecebal Suiu <decebal.suiu@gmail.com>
Fri, 12 Apr 2019 18:29:50 +0000 (21:29 +0300)
committerDecebal Suiu <decebal.suiu@gmail.com>
Fri, 12 Apr 2019 18:29:50 +0000 (21:29 +0300)
pf4j/src/test/java/org/pf4j/plugin/PluginZip.java

index 72e32416e4f866864d6cd859dcdad38c4eac3bdb..ee665d7edb973ff7e7ce533627b92c2375bff3cc 100644 (file)
@@ -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<String, String> 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<String, String> 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();
         }