/*
 * Copyright (C) 2012-present the original author or authors.
 *
 * Licensed 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.pf4j.plugin;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Path;
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.
 *
 * @author Decebal Suiu
 */
public class PluginZip {

    private final Path path;
    private final String pluginId;
    private final String pluginVersion;

    protected PluginZip(Builder builder) {
        this.path = builder.path;
        this.pluginId = builder.pluginId;
        this.pluginVersion = builder.pluginVersion;
    }

    public Path path() {
        return path;
    }

    public String pluginId() {
        return pluginId;
    }

    public String pluginVersion() {
        return pluginVersion;
    }

    public Path unzippedPath() {
        Path path = path();
        String fileName = path.getFileName().toString();

        return path.getParent().resolve(fileName.substring(0, fileName.length() - 4)); // without ".zip" suffix
    }

    public static class Builder {

        private final Path path;
        private final String pluginId;

        private String pluginVersion;

        public Builder(Path path, String pluginId) {
            this.path = path;
            this.pluginId = pluginId;
        }

        public Builder pluginVersion(String pluginVersion) {
            this.pluginVersion = pluginVersion;

            return this;
        }

        public PluginZip build() throws IOException {
            createPropertiesFile();

            return new PluginZip(this);
        }

        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");

            ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(path.toFile()));
            ZipEntry propertiesFile = new ZipEntry("plugin.properties");
            outputStream.putNextEntry(propertiesFile);
            properties.store(outputStream, "");
            outputStream.closeEntry();
            outputStream.close();
        }

    }

}

@@ -735,16 +735,38 @@
 e.Path;%0A
+import java.util.Map;%0A
 import j
@@ -887,15 +887,19 @@
 gin 
-zip/jar
+%7B@code zip%7D
  fil
@@ -908,17 +908,23 @@
 %0A * The 
-%22
+%7B@code 
 plugin.p
@@ -932,17 +932,17 @@
 operties
-%22
+%7D
  file is
@@ -994,23 +994,31 @@
 lied in 
+%7B@link 
 Builder
+%7D
 .%0A *%0A * 
@@ -1915,32 +1915,80 @@
 g pluginVersion;
+%0A        private Map%3CString, String%3E properties;
 %0A%0A        public
@@ -2243,32 +2243,267 @@
 his;%0A        %7D%0A%0A
+        /**%0A         * Add extra properties to the %7B@code properties%7D file.%0A         */%0A        public Builder properties(Map%3CString, String%3E properties) %7B%0A            this.properties = properties;%0A%0A            return this;%0A        %7D%0A%0A
         public P
@@ -2718,29 +2718,24 @@
 perties prop
-ertie
 s = new Prop
@@ -2752,37 +2752,32 @@
             prop
-ertie
 s.setProperty(%22p
@@ -2806,37 +2806,32 @@
             prop
-ertie
 s.setProperty(%22p
@@ -2878,21 +2878,16 @@
     prop
-ertie
 s.setPro
@@ -2938,16 +2938,110 @@
 lugin%22);
+%0A            if (properties != null) %7B%0A                props.putAll(properties);%0A            %7D
 %0A%0A      
@@ -3279,21 +3279,16 @@
     prop
-ertie
 s.store(

Add possibility to add extra properties