From: <sco...@jb...> - 2005-07-29 03:53:25
|
additionaldata only applies to filesets. See the jboss-izpack module that contains the project source/build for the jboss-listeners.jar. Only the PackageListener.afterFile event callback applies templates if there is associated additional data: | /* | * JBoss, Home of Professional Open Source | * | * Distributable under LGPL license. | * See terms of license at gnu.org. | */ | | package org.jboss.install; | | import java.io.File; | import java.io.BufferedWriter; | import java.io.FileWriter; | import java.util.List; | import java.util.Map; | | import com.izforge.izpack.event.InstallerListener; | import com.izforge.izpack.installer.AutomatedInstallData; | import com.izforge.izpack.Pack; | import com.izforge.izpack.PackFile; | import com.izforge.izpack.util.AbstractUIProgressHandler; | import com.izforge.izpack.util.Debug; | import org.apache.velocity.app.VelocityEngine; | import org.apache.velocity.VelocityContext; | | /** | * An InstallerListener that performs transforms of files marked with | * additional data in the afterFile event. | * | * @author Sco...@jb... | * @version $Revision:$ | */ | public class PackageListener | implements InstallerListener | { | private AutomatedInstallData installData; | private List activeDependencies; | private String installDir; | private VelocityEngine ve; | | public PackageListener() | { | File log = new File("install.log"); | System.out.println("PackageListener, install.log="+log.getAbsolutePath()); | Debug.initDebugLogFile(log.getAbsolutePath()); | } | | /** | * Object the selected packs and add the service dependencies. | * @param data | * @param id | * @param handler | * @throws Exception | */ | public void beforePacks(AutomatedInstallData data, | Integer id, AbstractUIProgressHandler handler) | throws Exception | { | installData = data; | StringBuffer tmp = new StringBuffer("beforePacks, selectedPacks:\n"); | List selectedPacks = (List) data.selectedPacks; | for(int n = 0; n < selectedPacks.size(); n ++) | { | Pack p = (Pack) selectedPacks.get(n); | tmp.append("Pack["); | tmp.append(p); | tmp.append("depends: "); | tmp.append(p.depString()); | tmp.append("]\n"); | } | tmp.append(", variables: "+installData.getVariables()); | Debug.trace(tmp.toString()); | installDir = installData.getInstallPath(); | Debug.trace("installDir="+installDir); | | // Initialise velocity engine | ve = new VelocityEngine(); | ve.setProperty("runtime.log.logsystem.class", | "org.apache.velocity.runtime.log.SimpleLog4JLogSystem"); | ve.setProperty("runtime.log.logsystem.log4j.category", | "testSecureJmxConsole.VelocityEngine"); | ve.setProperty("resource.loader", "class"); | ve.setProperty("class.resource.loader.class", | "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); | ve.init(); | Debug.trace("Initialized VelocityEngine"); | } | | public void beforePack(Pack pack, Integer n, AbstractUIProgressHandler handler) | throws Exception | { | Debug.trace("beforePack, pack="+pack.name); | activeDependencies = pack.getDependencies(); | } | | public boolean isFileListener() | { | return true; | } | | public void beforeDir(File file, PackFile packFile) | throws Exception | { | Debug.trace("beforeDir, file="+file+", packFile="+packFile.sourcePath); | } | | public void afterDir(File file, PackFile packFile) | throws Exception | { | Debug.trace("afterDir, file="+file+", packFile="+packFile.sourcePath); | } | | public void beforeFile(File file, PackFile packFile) | throws Exception | { | Debug.trace("beforeFile, file="+file+", packFile="+packFile.sourcePath); | } | | public void afterFile(File file, PackFile packFile) | throws Exception | { | Map data = packFile.getAdditionals(); | Debug.trace("afterFile, file="+file+", sourcePath="+packFile.sourcePath | +", targetPath="+packFile.getTargetPath()+", data="+data); | if( data != null ) | { | String template = (String) data.get(file.getName()); | Debug.trace("template="+template); | if( template != null ) | { | Debug.trace("Saw template:"+template); | String filePath = file.toURI().getPath(); | String templatePath = filePath + ".vm"; | if( templatePath.endsWith(template) == true ) | { | templatePath = "templates/" + template; | applyTemplate(templatePath, file, packFile, data); | } | } | } | } | | public void afterPack(Pack pack, Integer n, | AbstractUIProgressHandler abstractUIProgressHandler) | throws Exception | { | Debug.trace("afterPack, pack="+pack.name); | } | | public void afterPacks(AutomatedInstallData automatedInstallData, | AbstractUIProgressHandler handler) | throws Exception | { | Debug.trace("afterPacks"); | } | | private void applyTemplate(String template, File file, PackFile packFile, Map data) | { | try | { | Debug.trace("applyTemplate, template="+template); | VelocityContext vc = new VelocityContext(installData.getVariables()); | vc.put("template-error", ""); | Debug.trace("VC.secureJmxConsole = "+vc.get("secureJmxConsole")); | | BufferedWriter out = new BufferedWriter(new FileWriter(file)); | boolean success = ve.mergeTemplate(template, vc, out); | out.close(); | Debug.trace("Applied template: "+template+", success="+success); | } | catch(Throwable e) | { | Debug.error("Failed to apply: "+template); | Debug.error(e); | } | } | } | The jboss-izpack module can be checkes out from cvs.forge.jboss.com | cvs -z4 -d :ext:st...@cv...:/cvsroot/jboss co -d -P jboss-izpack | View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3887199#3887199 Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3887199 |