All Downloads are FREE. Search and download functionalities are using the official Maven repository.

play.modules.gtengineplugin.PrecompileTemplates Maven / Gradle / Ivy

Go to download

RePlay is a fork of the Play1 framework, made and maintained by Codeborne.

The newest version!
package play.modules.gtengineplugin;

import play.Play;
import play.PlayPlugin;
import play.plugins.PluginCollection;
import play.templates.Template;
import play.templates.TemplateLoader;
import play.vfs.VirtualFile;

import java.util.Map;
import java.util.Optional;

public class PrecompileTemplates {
  public static void main(String[] args) {
    System.setProperty("precompile", "true");
    loadPrecompiledJavaClasses();
    precompileTemplates();
  }

  private static void loadPrecompiledJavaClasses() {
    System.setProperty("precompiled", "true");
    Play play = new Play();
    play.pluginCollection = new SinglePluginCollection();
    play.init("prod");
    Play.usePrecompiled = false;
  }

  private static void precompileTemplates() {
    TemplateLoader.getAllTemplate();
  }

  private static class SinglePluginCollection extends PluginCollection {
    @Override public void loadPlugins() {
      IgnoreOtherTemplatesPlugin otherTemplatesPlugin = new IgnoreOtherTemplatesPlugin();
      otherTemplatesPlugin.index = 1;
      addPlugin(otherTemplatesPlugin);

      GTEnginePlugin plugin = new GTEnginePlugin();
      plugin.index = 2;
      plugin.onLoad();
      addPlugin(plugin);
    }
  }

  private static class IgnoreOtherTemplatesPlugin extends PlayPlugin {
    private final DummyTemplate dummyTemplate = new DummyTemplate();

    @Override public Optional