home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / VCAFE.3.0A / Main.bin / JARArchiver.java < prev    next >
Text File  |  1998-11-03  |  3KB  |  134 lines

  1. package com.symantec.itools.tools.archive;
  2.  
  3.  
  4. import java.io.BufferedReader;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileReader;
  7. import java.io.IOException;
  8. import com.symantec.itools.lang.Classpath;
  9. import com.symantec.itools.lang.NotJavaNameException;
  10. import com.symantec.itools.io.FileSystem;
  11. import com.symantec.itools.lang.Debug;
  12. import com.symantec.itools.lang.ProcessManager;
  13.  
  14.  
  15. /**
  16.  * @author Symantec Internet Tools Division
  17.  * @version 1.0
  18.  * @since VCafe 3.0
  19.  */
  20.  
  21. public class JARArchiver
  22.     extends TypeArchiver
  23. {
  24.     /**
  25.      * @since VCafe 3.0
  26.      */
  27.     protected ProcessManager processManager;
  28.  
  29.     public JARArchiver(Options options)
  30.     {
  31.         super(options);
  32.     }
  33.  
  34.     /**
  35.      * @param errorMsg TODO
  36.      * @since VCafe 3.0
  37.      */
  38.     public boolean create(StringBuffer errorMsg)
  39.     {
  40.         if(options.isSigning())
  41.         {
  42.             if(options.getSigner().equals("netscape"))
  43.             {
  44.                 return (createUsingNetscapeJAR(errorMsg));
  45.             }
  46.         }
  47.  
  48.         return (createUsingSunJAR(errorMsg));
  49.     }
  50.  
  51.     /**
  52.      * @param errorMsg TODO
  53.      * @since VCafe 3.0
  54.      */
  55.     protected boolean createUsingNetscapeJAR(StringBuffer errorMsg)
  56.     {
  57.         DirectoryArchiver archiver;
  58.         String            outFile;
  59.         StringBuffer      command;
  60.  
  61.         outFile = options.getOutputLocation();
  62.         options.setOutputLocation(options.getTempDir());
  63.         archiver = new DirectoryArchiver(options);
  64.  
  65.         if(!(archiver.create(errorMsg)))
  66.         {
  67.             return (false);
  68.         }
  69.  
  70.         options.setOutputLocation(outFile);
  71.  
  72.         return (true);
  73.     }
  74.  
  75.     /**
  76.      * @param errorMsg TODO
  77.      * @since VCafe 3.0
  78.      * @deprecated
  79.      */
  80.  
  81.     protected boolean createUsingSunJAR(StringBuffer errorMsg)
  82.     {
  83.         DirectoryArchiver archiver;
  84.         String            outFile;
  85.         StringBuffer      command;
  86.         String            tempDir; 
  87.  
  88.         outFile = options.getOutputLocation();
  89.         tempDir = options.getTempDir();
  90.         options.setOutputLocation(tempDir);
  91.         archiver = new DirectoryArchiver(options);
  92.  
  93.         if(!(archiver.create(errorMsg)))
  94.         {
  95.             return (false);
  96.         }
  97.  
  98.         options.setOutputLocation(outFile);
  99.         command = new StringBuffer(FileSystem.quoteIfNeeded(FileSystem.getCanonicalPath(options.getSunTools(), true) + "jar.exe"));
  100.         command.append(' ').append(options.getArchiverArgs());
  101.         
  102.         try
  103.         {
  104.             processManager = new ProcessManager();
  105.             
  106.             if(processManager.monitorLaunchedProcess(Runtime.getRuntime().exec(command.toString())) != 0)
  107.             {
  108.                 errorMsg.append("Failed to create " + options.getOutputLocation());
  109.                 return (false);
  110.             }
  111.         }
  112.         catch(IOException ex)
  113.         {
  114.             errorMsg.append("Failed to run " + FileSystem.getCanonicalPath(options.getSunTools(), true)).append("jar.exe");
  115.             Debug.logException(ex);
  116.             return (false);
  117.         }
  118.  
  119.         return (true);
  120.     }
  121.  
  122.     /**
  123.      * @since VCafe 3.0
  124.      */
  125.  
  126.     public void cancel()
  127.     {
  128.         if(processManager != null)
  129.         {
  130.             processManager.destroyProcess();
  131.             processManager = null;
  132.         }
  133.     }    
  134. }