public static void setup() throws Exception { workSpaceDir = Jazmin.environment.getString("deploy.workspace", "./workspace/"); deployHostname = Jazmin.environment.getString("deploy.hostname", "localhost"); repoPath = Jazmin.environment.getString("deploy.repo.dir", "./repo"); antPath = Jazmin.environment.getString("deploy.ant", "ant"); antCommonLibPath = Jazmin.environment.getString("deploy.ant.lib", "./lib"); WebServer ws = Jazmin.getServer(WebServer.class); if (ws != null) { deployHostport = ws.getPort(); } checkWorkspace(); Velocity.init(); }
private static String renderTemplate(Instance instance) { VelocityContext ctx = new VelocityContext(); WebServer ws = Jazmin.getServer(WebServer.class); if (ws != null) { ctx.put("deployServerPort", ws.getPort()); } ctx.put("env", Jazmin.environment.envs()); ctx.put("instances", getInstances()); ctx.put("instanceMap", instanceMap); ctx.put("machines", getMachines()); ctx.put("machineMap", machineMap); ctx.put("applications", getApplications()); ctx.put("applicationMap", applicationMap); ctx.put("instance", instance); // Map<String, String> properties = new HashMap<String, String>(); properties.putAll(instance.properties); properties.putAll(instance.application.properties); properties.putAll(instance.machine.properties); // ctx.put("properties", properties); StringWriter sw = new StringWriter(); String templateDir = workSpaceDir; templateDir += "template"; File file = new File(templateDir + "/" + instance.appId + ".vm"); if (!file.exists()) { logger.info("can not find {} use Default.vm to render", file); file = new File(templateDir + "/Default.vm"); } if (!file.exists()) { logger.warn("can not find template {}", file); return null; } Velocity.mergeTemplate(file.getPath(), "UTF-8", ctx, sw); return sw.toString(); }