package io.playpen.core.utils;

import io.playpen.core.Bootstrap;
import io.playpen.core.p3.P3Package;
import io.playpen.core.p3.PackageContext;
import org.stringtemplate.v4.ST;

import java.nio.file.Paths;
import java.util.Map;

public class STUtils {

    public static void buildSTProperties(P3Package p3, PackageContext ctx, ST template) {
        template.add("package-id", p3.getId());
        template.add("package-version", p3.getVersion());
        template.add("resources", ctx.getResources());
        template.add("asset_path", Paths.get(Bootstrap.getHomeDir().getPath(), "assets").toFile().getAbsolutePath());
        template.add("server_path", ctx.getDestination().getAbsolutePath());

        for(Map.Entry<String, String> entry : ctx.getProperties().entrySet()) {
            template.add(entry.getKey(), entry.getValue());
        }
    }

    private STUtils() {}
}

@@ -170,16 +170,61 @@
 e.v4.ST;
+%0Aimport org.stringtemplate.v4.misc.Aggregate;
 %0A%0Aimport
@@ -245,16 +245,42 @@
 .Paths;%0A
+import java.util.HashMap;%0A
 import j
@@ -914,16 +914,319 @@
        %7D
+%0A%0A        Map%3CString, String%3E versions = new HashMap%3C%3E();%0A        for (P3Package p3Package : ctx.getDependencyChain()) %7B%0A            versions.put(p3Package.getId(), p3Package.getVersion());%0A        %7D%0A        versions.put(p3.getId(), p3.getVersion());%0A%0A        template.add(%22package_versions%22, versions);
 %0A    %7D%0A%0A

Add package versions in STUtils