KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > compiler > Compiler


1 /*
2  * $Id: Compiler.java 1708 2007-01-13 18:31:26Z jponge $
3  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
4  *
5  * http://www.izforge.com/izpack/
6  * http://developer.berlios.de/projects/izpack/
7  *
8  * Copyright 2001 Johannes Lehtinen
9  * Copyright 2002 Paul Wilkinson
10  * Copyright 2004 Gaganis Giorgos
11  *
12  *
13  * Licensed under the Apache License, Version 2.0 (the "License");
14  * you may not use this file except in compliance with the License.
15  * You may obtain a copy of the License at
16  *
17  * http://www.apache.org/licenses/LICENSE-2.0
18  *
19  * Unless required by applicable law or agreed to in writing, software
20  * distributed under the License is distributed on an "AS IS" BASIS,
21  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22  * See the License for the specific language governing permissions and
23  * limitations under the License.
24  */

25
26 package com.izforge.izpack.compiler;
27
28 import java.io.File JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.net.MalformedURLException JavaDoc;
31 import java.net.URL JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.Arrays JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.List JavaDoc;
37 import java.util.Map JavaDoc;
38 import java.util.Properties JavaDoc;
39 import java.util.Set JavaDoc;
40 import java.util.jar.JarInputStream JavaDoc;
41 import java.util.zip.ZipEntry JavaDoc;
42
43 import com.izforge.izpack.CustomData;
44 import com.izforge.izpack.GUIPrefs;
45 import com.izforge.izpack.Info;
46 import com.izforge.izpack.Pack;
47 import com.izforge.izpack.Panel;
48 import com.izforge.izpack.compressor.PackCompressor;
49 import com.izforge.izpack.util.Debug;
50 import com.izforge.izpack.util.VariableSubstitutor;
51
52 /**
53  * The IzPack compiler class. This is now a java bean style class that can be
54  * configured using the object representations of the install.xml
55  * configuration. The install.xml configuration is now handled by the
56  * CompilerConfig class.
57  *
58  * @see CompilerConfig
59  *
60  * @author Julien Ponge
61  * @author Tino Schwarze
62  * @author Chadwick McHenry
63  */

64 public class Compiler extends Thread JavaDoc
65 {
66     /** The IzPack version. */
67     public final static String JavaDoc IZPACK_VERSION = "3.10.0";
68
69     /** The IzPack home directory. */
70     public static String JavaDoc IZPACK_HOME = ".";
71
72     /** The base directory. */
73     protected String JavaDoc basedir;
74
75     /** The installer kind. */
76     protected String JavaDoc kind;
77
78     /** The output jar filename. */
79     protected String JavaDoc output;
80
81     /** Collects and packs files into installation jars, as told. */
82     private IPackager packager = null;
83
84     /** Error code, set to true if compilation succeeded. */
85     private boolean compileFailed = true;
86
87     /** Key/values which are substituted at compile time in the install data */
88     private Properties JavaDoc properties;
89
90     /** Replaces the properties in the install.xml file prior to compiling */
91     private VariableSubstitutor propertySubstitutor;
92     
93     private String JavaDoc compr_format;
94     private int compr_level;
95     private PackagerListener packagerlistener;
96
97     /**
98      * Set the IzPack home directory
99      * @param izHome - the izpack home directory
100      */

101     public static void setIzpackHome(String JavaDoc izHome)
102     {
103         IZPACK_HOME = izHome;
104     }
105
106     /**
107      * The constructor.
108      *
109      * @param basedir The base directory.
110      * @param kind The installer kind.
111      * @param output The installer filename.
112      * @throws CompilerException
113      */

114     public Compiler(String JavaDoc basedir, String JavaDoc kind, String JavaDoc output) throws CompilerException
115     {
116         this(basedir,kind,output,"default");
117     }
118
119     /**
120      * The constructor.
121      *
122      * @param basedir The base directory.
123      * @param kind The installer kind.
124      * @param output The installer filename.
125      * @param compr_format The format which should be used for the packs.
126      * @throws CompilerException
127      */

128     public Compiler(String JavaDoc basedir, String JavaDoc kind, String JavaDoc output, String JavaDoc compr_format) throws CompilerException
129     {
130         this(basedir,kind,output, compr_format, -1);
131     }
132
133     /**
134      * The constructor.
135      *
136      * @param basedir The base directory.
137      * @param kind The installer kind.
138      * @param output The installer filename.
139      * @param compr_format The format which should be used for the packs.
140      * @param compr_level Compression level to be used if supported.
141      * @throws CompilerException
142      */

143     public Compiler(String JavaDoc basedir, String JavaDoc kind, String JavaDoc output,
144             String JavaDoc compr_format, int compr_level) throws CompilerException
145     {
146         // Default initialisation
147
this.basedir = basedir;
148         this.kind = kind;
149         this.output = output;
150
151         // initialize backed by system properties
152
properties = new Properties JavaDoc(System.getProperties());
153         propertySubstitutor = new VariableSubstitutor(properties);
154
155         // add izpack built in property
156
setProperty("izpack.version", IZPACK_VERSION);
157         setProperty("basedir", basedir);
158         
159         this.compr_format = compr_format;
160         this.compr_level = compr_level;
161     }
162
163     /**
164      * Initializes the given packager class
165      * @param classname
166      * @throws CompilerException
167      */

168     public void initPackager(String JavaDoc classname) throws CompilerException{
169         try {
170             packager = PackagerFactory.getPackager(classname);
171             packager.initPackCompressor(this.compr_format, this.compr_level);
172             PackCompressor compressor = packager.getCompressor();
173             if (compressor != null){
174                 compressor.setCompiler(this);
175             }
176             if (this.packagerlistener != null){
177                 packager.setPackagerListener(this.packagerlistener);
178             }
179         }
180         catch (Exception JavaDoc e){
181             Debug.trace(e);
182             throw new CompilerException("Error loading packager class: " + classname);
183         }
184     }
185     
186     /**
187      * Returns the packager listener.
188      * @return the packager listener
189      */

190     public PackagerListener getPackagerListener()
191     {
192         return packager.getPackagerListener();
193     }
194     /**
195      * Sets the packager listener.
196      *
197      * @param listener The listener.
198      */

199     public void setPackagerListener(PackagerListener listener)
200     {
201         if (packager != null){
202             packager.setPackagerListener(listener);
203         }
204         else {
205             this.packagerlistener = listener;
206         }
207     }
208
209     /**
210      * Access the installation kind.
211      * @return the installation kind.
212      */

213     public String JavaDoc getKind()
214     {
215         return kind;
216     }
217     /**
218      * Get the packager variables.
219      * @return the packager variables
220      */

221     public Properties JavaDoc getVariables()
222     {
223         return packager.getVariables();
224     }
225
226     /** Compiles. */
227     public void compile()
228     {
229         start();
230     }
231
232     /** The run() method. */
233     public void run()
234     {
235         try
236         {
237             createInstaller(); // Execute the compiler - may send info to
238
// System.out
239
}
240         catch (CompilerException ce)
241         {
242             System.out.println(ce.getMessage() + "\n");
243         }
244         catch (Exception JavaDoc e)
245         {
246             if (Debug.stackTracing())
247             {
248                 e.printStackTrace();
249             }
250             else
251             {
252                 System.out.println("ERROR: " + e.getMessage());
253             }
254         }
255     }
256
257     /**
258      * Compiles the installation.
259      *
260      * @exception Exception Description of the Exception
261      */

262     public void createInstaller() throws Exception JavaDoc
263     {
264         // Add the class files from the chosen compressor.
265
if( packager.getCompressor().getContainerPaths() != null )
266         {
267             String JavaDoc [] containerPaths = packager.getCompressor().getContainerPaths();
268             String JavaDoc [][] decoderClassNames = packager.getCompressor().getDecoderClassNames();
269             for( int i = 0; i < containerPaths.length; ++i)
270             {
271                 URL JavaDoc compressorURL = null;
272                 if( containerPaths[i] != null )
273                     compressorURL = findIzPackResource(containerPaths[i],"pack compression Jar file");
274                 if( decoderClassNames[i] != null && decoderClassNames[i].length > 0)
275                     addJarContent(compressorURL, Arrays.asList(decoderClassNames[i]));
276             }
277             
278             
279         }
280   
281         // We ask the packager to create the installer
282
packager.createInstaller(new File JavaDoc(output));
283         this.compileFailed = false;
284     }
285
286     /**
287      * Returns whether the installation was successful or not.
288      * @return whether the installation was successful or not
289      */

290     public boolean wasSuccessful()
291     {
292         return !this.compileFailed;
293     }
294
295     /**
296      * Replaces placeholder in the given string with the associated strings.
297      * @param value to be substituted
298      * @return the substituted string
299      */

300     public String JavaDoc replaceProperties(String JavaDoc value)
301     {
302         return propertySubstitutor.substitute(value, "at");
303     }
304
305     /**
306      * Sets GUI preferences to the packager.
307      * @param prefs preferences to be set
308      */

309     public void setGUIPrefs(GUIPrefs prefs)
310     {
311         packager.setGUIPrefs(prefs);
312     }
313     /**
314      * Sets an Info object to the packager.
315      * @param info Info object to be set
316      * @throws Exception
317      */

318     public void setInfo(Info info) throws Exception JavaDoc
319     {
320         packager.setInfo(info);
321     }
322
323     /**
324      * Returns the install packager.
325      * @return the install packager.
326      */

327     public IPackager getPackager()
328     {
329         return packager;
330     }
331     /**
332      * Returns the properties currently known to the compileer.
333      * @return the properties currently known to the compileer
334      */

335     public Properties JavaDoc getProperties()
336     {
337         return properties;
338     }
339
340     /**
341      * Get the value of a property currerntly known to izpack.
342      *
343      * @param name the name of the property
344      * @return the value of the property, or null
345      */

346     public String JavaDoc getProperty(String JavaDoc name)
347     {
348         return properties.getProperty(name);
349     }
350
351     /**
352      * Add a name value pair to the project property set. Overwriting any existing value except system properties.
353      *
354      * @param name the name of the property
355      * @param value the value to set
356      * @return an indicator if the name value pair was added.
357      */

358     public boolean setProperty(String JavaDoc name, String JavaDoc value)
359     {
360         if (System.getProperties().containsKey(name)) {
361             return false;
362         }
363         properties.put(name, value);
364         return true;
365     }
366
367     /**
368      * Add a name value pair to the project property set. It is <i>not</i> replaced it is already
369      * in the set of properties.
370      *
371      * @param name the name of the property
372      * @param value the value to set
373      * @return true if the property was not already set
374      */

375     public boolean addProperty(String JavaDoc name, String JavaDoc value)
376     {
377         String JavaDoc old = properties.getProperty(name);
378         if (old == null)
379         {
380             properties.put(name, value);
381             return true;
382         }
383         return false;
384     }
385
386     /**
387      * Add jar content to the installation.
388      * @param content
389      */

390     public void addJarContent(URL JavaDoc content)
391     {
392         packager.addJarContent(content);
393     }
394
395     /**
396      * Adds a jar file content to the installer. Package structure is maintained. Need mechanism to
397      * copy over signed entry information. If the given file list is null the hole contents of the
398      * jar file will be copied else only the listed.
399      *
400      * @param content The url of the jar to add to the installer. We use a URL so the jar may be
401      * nested within another.
402      * @param files to be copied
403      */

404     public void addJarContent(URL JavaDoc content, List JavaDoc files)
405     {
406         packager.addJarContent(content, files);
407     }
408
409     /**
410      * Add a custom jar to the installation.
411      *
412      * @param ca
413      * @param url
414      */

415     public void addCustomJar(CustomData ca, URL JavaDoc url)
416     {
417         packager.addCustomJar(ca, url);
418     }
419     /**
420      * Add a lang pack to the installation.
421      * @param iso3
422      * @param iso3xmlURL
423      * @param iso3FlagURL
424      */

425     public void addLangPack(String JavaDoc iso3, URL JavaDoc iso3xmlURL, URL JavaDoc iso3FlagURL)
426     {
427         packager.addLangPack(iso3, iso3xmlURL, iso3FlagURL);
428     }
429     /**
430      * Add a native library to the installation.
431      * @param name
432      * @param url
433      * @throws Exception
434      */

435     public void addNativeLibrary(String JavaDoc name, URL JavaDoc url) throws Exception JavaDoc
436     {
437         packager.addNativeLibrary(name, url);
438     }
439     /**
440      * Add an unistaller library.
441      * @param data
442      */

443     public void addNativeUninstallerLibrary(CustomData data)
444     {
445         packager.addNativeUninstallerLibrary(data);
446     }
447     /**
448      * Add a pack to the installation.
449      * @param pack
450      */

451     public void addPack(PackInfo pack)
452     {
453         packager.addPack(pack);
454     }
455     /**
456      * Add a panel jar to the installation.
457      * @param panel
458      * @param url
459      */

460     public void addPanelJar(Panel panel, URL JavaDoc url)
461     {
462         packager.addPanelJar(panel, url);
463     }
464     /**
465      * Add a resource to the installation.
466      * @param name
467      * @param url
468      */

469     public void addResource(String JavaDoc name, URL JavaDoc url)
470     {
471         packager.addResource(name, url);
472     }
473
474     /**
475      * Checks whether the dependencies stated in the configuration file are correct. Specifically it
476      * checks that no pack point to a non existent pack and also that there are no circular
477      * dependencies in the packs.
478      * @throws CompilerException
479      */

480     public void checkDependencies() throws CompilerException
481     {
482         checkDependencies(packager.getPacksList());
483     }
484     
485     /**
486      * Checks whether the excluded packs exist. (simply calles the other function)
487      * @throws CompilerException
488      */

489     public void checkExcludes() throws CompilerException
490     {
491        checkExcludes(packager.getPacksList());
492     }
493     
494     /**
495      * This checks if there are more than one preselected packs per excludeGroup.
496      * @param packs list of packs which should be checked
497      * @throws CompilerException
498      */

499     public void checkExcludes(List JavaDoc packs) throws CompilerException
500     {
501         for(int q=0; q<packs.size(); q++)
502         {
503             PackInfo packinfo1 = (PackInfo) packs.get(q);
504             Pack pack1 = packinfo1.getPack();
505             for(int w = 0; w < q; w++)
506             {
507
508                 PackInfo packinfo2 = (PackInfo) packs.get(w);
509                 Pack pack2 = packinfo2.getPack();
510                 if(pack1.excludeGroup != null && pack2.excludeGroup != null)
511                 {
512                     if(pack1.excludeGroup.equals(pack2.excludeGroup))
513                     {
514                         if(pack1.preselected && pack2.preselected)
515                         {
516                             parseError("Packs "+pack1.name+" and "+pack2.name+
517                                     " belong to the same excludeGroup "+pack1.excludeGroup+
518                             " and are both preselected. This is not allowed.");
519                         }
520                     }
521                 }
522             }
523             
524         }
525     }
526     /**
527      * Checks whether the dependencies among the given Packs. Specifically it
528      * checks that no pack point to a non existent pack and also that there are no circular
529      * dependencies in the packs.
530      * @param packs - List<Pack> representing the packs in the installation
531      * @throws CompilerException
532      */

533     public void checkDependencies(List JavaDoc packs) throws CompilerException
534     {
535         // Because we use package names in the configuration file we assosiate
536
// the names with the objects
537
Map JavaDoc names = new HashMap JavaDoc();
538         for (int i = 0; i < packs.size(); i++)
539         {
540             PackInfo pack = (PackInfo) packs.get(i);
541             names.put(pack.getPack().name, pack);
542         }
543         int result = dfs(packs, names);
544         // @todo More informative messages to include the source of the error
545
if (result == -2)
546             parseError("Circular dependency detected");
547         else if (result == -1) parseError("A dependency doesn't exist");
548     }
549
550     /**
551      * We use the dfs graph search algorithm to check whether the graph is acyclic as described in:
552      * Thomas H. Cormen, Charles Leiserson, Ronald Rivest and Clifford Stein. Introduction to
553      * algorithms 2nd Edition 540-549,MIT Press, 2001
554      *
555      * @param packs The graph
556      * @param names The name map
557      * @return -2 if back edges exist, else 0
558      */

559     private int dfs(List JavaDoc packs, Map JavaDoc names)
560     {
561         Map JavaDoc edges = new HashMap JavaDoc();
562         for (int i = 0; i < packs.size(); i++)
563         {
564             PackInfo pack = (PackInfo) packs.get(i);
565             if (pack.colour == PackInfo.WHITE)
566             {
567                 if (dfsVisit(pack, names, edges) != 0) return -1;
568             }
569
570         }
571         return checkBackEdges(edges);
572     }
573
574     /**
575      * This function checks for the existence of back edges.
576      * @param edges map to be checked
577      * @return -2 if back edges exist, else 0
578      */

579     private int checkBackEdges(Map JavaDoc edges)
580     {
581         Set JavaDoc keys = edges.keySet();
582         for (Iterator JavaDoc iterator = keys.iterator(); iterator.hasNext();)
583         {
584             final Object JavaDoc key = iterator.next();
585             int color = ((Integer JavaDoc) edges.get(key)).intValue();
586             if (color == PackInfo.GREY) { return -2; }
587         }
588         return 0;
589
590     }
591
592     /**
593      * This class is used for the classification of the edges
594      */

595     private class Edge
596     {
597
598         PackInfo u;
599
600         PackInfo v;
601
602         Edge(PackInfo u, PackInfo v)
603         {
604             this.u = u;
605             this.v = v;
606         }
607     }
608
609     private int dfsVisit(PackInfo u, Map JavaDoc names, Map JavaDoc edges)
610     {
611         u.colour = PackInfo.GREY;
612         List JavaDoc deps = u.getDependencies();
613         if (deps != null)
614         {
615             for (int i = 0; i < deps.size(); i++)
616             {
617                 String JavaDoc name = (String JavaDoc) deps.get(i);
618                 PackInfo v = (PackInfo) names.get(name);
619                 if (v == null)
620                 {
621                     System.out.println("Failed to find dependency: "+name);
622                     return -1;
623                 }
624                 Edge edge = new Edge(u, v);
625                 if (edges.get(edge) == null) edges.put(edge, new Integer JavaDoc(v.colour));
626
627                 if (v.colour == PackInfo.WHITE)
628                 {
629
630                     final int result = dfsVisit(v, names, edges);
631                     if (result != 0) return result;
632                 }
633             }
634         }
635         u.colour = PackInfo.BLACK;
636         return 0;
637     }
638
639     /**
640      * Look for an IzPack resource either in the compiler jar, or within IZPACK_HOME. The path must
641      * not be absolute. The path must use '/' as the fileSeparator (it's used to access the jar
642      * file). If the resource is not found, a CompilerException is thrown indicating fault in the
643      * parent element.
644      *
645      * @param path the relative path (using '/' as separator) to the resource.
646      * @param desc the description of the resource used to report errors
647      * @return a URL to the resource.
648      * @throws CompilerException
649      */

650     public URL JavaDoc findIzPackResource(String JavaDoc path, String JavaDoc desc)
651             throws CompilerException
652     {
653         URL JavaDoc url = getClass().getResource("/" + path);
654         if (url == null)
655         {
656             File JavaDoc resource = new File JavaDoc(path);
657             if (!resource.isAbsolute()) resource = new File JavaDoc(IZPACK_HOME, path);
658
659             if (!resource.exists()) // fatal
660
parseError(desc + " not found: " + resource);
661
662             try
663             {
664                 url = resource.toURL();
665             }
666             catch (MalformedURLException JavaDoc how)
667             {
668                 parseError(desc + "(" + resource + ")", how);
669             }
670         }
671
672         return url;
673     }
674
675     /**
676      * Create parse error with consistent messages. Includes file name. For use When parent is
677      * unknown.
678      *
679      * @param message Brief message explaining error
680      * @throws CompilerException
681      */

682     public void parseError(String JavaDoc message) throws CompilerException
683     {
684         this.compileFailed = true;
685         throw new CompilerException(message);
686     }
687     /**
688      * Create parse error with consistent messages. Includes file name. For use When parent is
689      * unknown.
690      *
691      * @param message Brief message explaining error
692      * @param how throwable which was catched
693      * @throws CompilerException
694      */

695     public void parseError(String JavaDoc message, Throwable JavaDoc how) throws CompilerException
696     {
697         this.compileFailed = true;
698         throw new CompilerException(message, how);
699     }
700
701     /**
702      * The main method if the compiler is invoked by a command-line call.
703      * This simply calls the CompilerConfig.main method.
704      *
705      * @param args The arguments passed on the command-line.
706      */

707     public static void main(String JavaDoc[] args)
708     {
709         CompilerConfig.main(args);
710     }
711
712     // -------------------------------------------------------------------------
713
// ------------- Listener stuff ------------------------- START ------------
714

715     /**
716      * This method parses install.xml for defined listeners and put them in the right position. If
717      * posible, the listeners will be validated. Listener declaration is a fragmention in
718      * install.xml like : &lt;listeners&gt; &lt;listener compiler="PermissionCompilerListener"
719      * installer="PermissionInstallerListener"/1gt; &lt;/listeners&gt;
720      *
721      * @param type The listener type.
722      * @param className The class name.
723      * @param jarPath The jar path.
724      * @param constraints The list of constraints.
725      * @throws Exception Thrown in case an error occurs.
726      */

727     public void addCustomListener(int type, String JavaDoc className, String JavaDoc jarPath, List JavaDoc constraints) throws Exception JavaDoc
728     {
729         jarPath = replaceProperties(jarPath);
730         URL JavaDoc url = findIzPackResource(jarPath, "CustomAction jar file");
731         List JavaDoc filePaths = getContainedFilePaths(url);
732         String JavaDoc fullClassName = getFullClassName(url, className);
733         CustomData ca = new CustomData(fullClassName, filePaths, constraints, type);
734         packager.addCustomJar(ca, url);
735     }
736
737     /**
738      * Returns a list which contains the pathes of all files which are included in the given url.
739      * This method expects as the url param a jar.
740      *
741      * @param url url of the jar file
742      * @return full qualified paths of the contained files
743      * @throws Exception
744      */

745     private List JavaDoc getContainedFilePaths(URL JavaDoc url) throws Exception JavaDoc
746     {
747         JarInputStream JavaDoc jis = new JarInputStream JavaDoc(url.openStream());
748         ZipEntry JavaDoc zentry = null;
749         ArrayList JavaDoc fullNames = new ArrayList JavaDoc();
750         while ((zentry = jis.getNextEntry()) != null)
751         {
752             String JavaDoc name = zentry.getName();
753             // Add only files, no directory entries.
754
if (!zentry.isDirectory()) fullNames.add(name);
755         }
756         jis.close();
757         return (fullNames);
758     }
759
760     /**
761      * Returns the qualified class name for the given class. This method expects as the url param a
762      * jar file which contains the given class. It scans the zip entries of the jar file.
763      *
764      * @param url url of the jar file which contains the class
765      * @param className short name of the class for which the full name should be resolved
766      * @return full qualified class name
767      * @throws Exception
768      */

769     private String JavaDoc getFullClassName(URL JavaDoc url, String JavaDoc className) throws Exception JavaDoc
770     {
771         JarInputStream JavaDoc jis = new JarInputStream JavaDoc(url.openStream());
772         ZipEntry JavaDoc zentry = null;
773         while ((zentry = jis.getNextEntry()) != null)
774         {
775             String JavaDoc name = zentry.getName();
776             int lastPos = name.lastIndexOf(".class");
777             if (lastPos < 0)
778             {
779                 continue; // No class file.
780
}
781             name = name.replace('/', '.');
782             int pos = -1;
783             if (className != null)
784             {
785                 pos = name.indexOf(className);
786             }
787             if (name.length() == pos + className.length() + 6) // "Main" class
788
// found
789
{
790                 jis.close();
791                 return (name.substring(0, lastPos));
792             }
793         }
794         jis.close();
795         return (null);
796     }
797
798     // -------------------------------------------------------------------------
799
// ------------- Listener stuff ------------------------- END ------------
800

801     /**
802      * Used to handle the packager messages in the command-line mode.
803      *
804      * @author julien created October 26, 2002
805      */

806     static class CmdlinePackagerListener implements PackagerListener
807     {
808
809         /**
810          * Print a message to the console at default priority (MSG_INFO).
811          *
812          * @param info The information.
813          */

814         public void packagerMsg(String JavaDoc info)
815         {
816             packagerMsg(info, MSG_INFO);
817         }
818
819         /**
820          * Print a message to the console at the specified priority.
821          *
822          * @param info The information.
823          * @param priority priority to be used for the message prefix
824          */

825         public void packagerMsg(String JavaDoc info, int priority)
826         {
827             final String JavaDoc prefix;
828             switch (priority)
829             {
830             case MSG_DEBUG:
831                 prefix = "[ DEBUG ] ";
832                 break;
833             case MSG_ERR:
834                 prefix = "[ ERROR ] ";
835                 break;
836             case MSG_WARN:
837                 prefix = "[ WARNING ] ";
838                 break;
839             case MSG_INFO:
840             case MSG_VERBOSE:
841             default: // don't die, but don't prepend anything
842
prefix = "";
843             }
844
845             System.out.println(prefix + info);
846         }
847
848         /** Called when the packager starts. */
849         public void packagerStart()
850         {
851             System.out.println("[ Begin ]");
852             System.out.println();
853         }
854
855         /** Called when the packager stops. */
856         public void packagerStop()
857         {
858             System.out.println();
859             System.out.println("[ End ]");
860         }
861     }
862
863 }
864
Popular Tags