1 Reply Latest reply on Jul 28, 2005 11:53 PM by starksm64

    additionaldata, I don't get it

    acoliver

      How does the additionaldata tag work?

      I have:

      ...
       <pack name="Base" required="yes">
       <description>The base files</description>
       <file src="README.txt" targetdir="$INSTALL_PATH"/>
       <file src="license/jbmail.license" targetdir="$INSTALL_PATH"/>
       <fileset dir="build/deploy/dev"
       targetdir="$INSTALL_PATH/server/$SERVER_CONFIG/deploy">
       <include name="mail.ear/**"/>
       <additionaldata key="jboss-service.xml" value="mail.ear/mail.sar/META-INF/jboss-service.xml.vm" />
       </fileset>
       <!--file src="script.bat" targetdir="$INSTALL_PATH"/-->
       <!--parsable targetfile="$INSTALL_PATH/script.bat"/--> <!-- The file will be parsed -->
       </pack>
      ...
      
      yet the .vm file has no effect (it is supposed to omit a section if smtp is not enabled)...
      
      I have the jboss listeners and crap and the JBoss izpack:
      
       <listeners>
       <listener installer="SummaryLoggerInstallerListener"/>
       <listener
       compiler="org.jboss.install.CompileListener"
       installer="org.jboss.install.PackageListener"
       jar="lib/jboss-listeners.jar"
       />
       </listeners>
      
       <jar src="src/GRAPHICAL/templates.jar" />
       <jar src="lib/velocity.jar" />
       <jar src="lib/commons-collections.jar" />
       <jar src="lib/logkit.jar" />
      


      Questions:

      1. Any clues on how that works? (additionaldata)
      2. Where can I find the jboss install package/friends? (additionaldata in particular)

        • 1. Re: additionaldata, I don't get it
          starksm64

          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 Scott.Stark@jboss.org
           * @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:starksm@cvs.forge.jboss.com:/cvsroot/jboss co -d -P jboss-izpack