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
*/
private final String pluginId;
private String pluginVersion;
+ private Map<String, String> properties;
public Builder(Path path, String pluginId) {
this.path = path;
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();
}
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();
}