User: d_jencks
  Date: 01/09/26 14:47:03

  Modified:    src/main/org/jboss/resource RARDeployer.java
  Log:
  ServiceDeployer: added local dir support, undeploy support for depends, reworked 
classpath dependencies. Changed config files to work. REMOVE core-service.xml or 
build.sh cleancvs update -d -P >update11.log
  
  Revision  Changes    Path
  1.11      +59 -313   jbosscx/src/main/org/jboss/resource/RARDeployer.java
  
  Index: RARDeployer.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosscx/src/main/org/jboss/resource/RARDeployer.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- RARDeployer.java  2001/09/11 18:38:58     1.10
  +++ RARDeployer.java  2001/09/26 21:47:03     1.11
  @@ -17,7 +17,7 @@
   import java.net.JarURLConnection;
   import java.net.MalformedURLException;
   import java.net.URL;
  -import java.net.URLClassLoader;
  +//import java.net.URLClassLoader;Replaced with org.jboss.system.URLClassLoader.
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Enumeration;
  @@ -33,6 +33,8 @@
   import org.jboss.deployment.DeploymentException;
   import org.jboss.logging.Logger;
   import org.jboss.metadata.XmlFileLoader;
  +import org.jboss.system.ServiceLibraries;
  +import org.jboss.system.URLClassLoader;
   
   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
  @@ -46,7 +48,7 @@
   *
   * @author     Toby Allsopp ([EMAIL PROTECTED])
   * @author     <a href="mailto:[EMAIL PROTECTED]";>David Jencks</a>
  -* @version    $Revision: 1.10 $
  +* @version    $Revision: 1.11 $
   * @see        org.jboss.resource.ConnectionFactoryLoader <p>
   *
   *      <b>Revisions:</b> <p>
  @@ -74,27 +76,12 @@
   
      // Attributes ----------------------------------------------------
   
  -   /*
  -    * log4j Category for logging
  -    */
  -   private Logger category = Logger.create(RARDeployer.class);
   
      /**
  -    *  The directory that will contain local copies of deployed RARs
  -    */
  -   private File rarTmpDir;
  -
  -   /**
       *  The next sequence number to be used in notifications about (un)deployment
       */
      private int nextMessageNum = 0;
   
  -   private static String generateUniqueDirName(URL u)
  -   {
  -      int thisNum = nextNum++;
  -      return "rar." + thisNum;
  -   }
  -
      // Static --------------------------------------------------------
   
      // Constructors --------------------------------------------------
  @@ -160,121 +147,36 @@
         return null;
      }
   
  -   /**
  -    *  #Description of the Method
  -    *
  -    * @exception  Exception  Description of Exception
  -    */
  -   public void initService()
  -          throws Exception
  -   {
  -      // find the temp directory - referenced to jboss.system.home property
  -      File jbossHomeDir = new File(System.getProperty("jboss.system.home"));
  -      File tmpDir = new File(jbossHomeDir, "tmp"+File.separator);
  -
  -      // Create our temp directory
  -      File deployTmpDir = new File(tmpDir, "deploy");
  -      rarTmpDir = new File(deployTmpDir, getName());
  -      if (rarTmpDir.exists())
  -      {
  -         category.info("Found a temp directory left over from a previous run - " +
  -               "deleting it.");
  -         // What could it mean?
  -         if (!recursiveDelete(rarTmpDir))
  -         {
  -            category.warn("Unable to recursively delete temp directory '" +
  -                  rarTmpDir + "' that appears to be left over from " +
  -                  "the previous run. This might cause problems.");
  -         }
  -      }
  -      if (!rarTmpDir.exists() && !rarTmpDir.mkdirs())
  -      {
  -         throw new DeploymentException("Can't create temp directory '" +
  -               rarTmpDir + "'");
  -      }
  -   }
  -
  -   /**
  -    *  #Description of the Method
  -    */
  -   public void destroyService()
  -   {
  -      // Remove our temp directory
  -      if (!recursiveDelete(rarTmpDir))
  -      {
  -         category.warn("Unable to recursively delete the temp directory '" +
  -               rarTmpDir + "' - it should be cleaned up when the " +
  -               "server is next restarted.");
  -      }
  -   }
  -
  -   protected Object deploy(URL url)
  +    /**
  +     * The <code>deploy</code> method deploys a rar at the given url.
  +     *
  +     * @param url The <code>URL</code> location of the rar to deploy.
  +     * @return an <code>Object</code> to identify this deployment.
  +     * @exception IOException if an error occurs
  +     * @exception DeploymentException if an error occurs
  +     */
  +    protected Object deploy(URL url)
             throws IOException, DeploymentException
      {
         category.info("Attempting to deploy RAR at '" + url + "'");
  -
  -      // We want to take a local copy of the RAR so that we don't run
  -      // into problems if the original is removed/replaced. We also
  -      // need the RAR in unpacked form so that we can get at the
  -      // included JARs for classloading (I don't think URLClassLoader
  -      // deals with JARs within JARs).
  -
  -      String unpackedDirName = generateUniqueDirName(url);
  -      File unpackedDir = new File(rarTmpDir, unpackedDirName);
  -      if (unpackedDir.exists())
  -      {
  -         throw new DeploymentException("The application at URL '" + url + "' " +
  -               "appears to already have been " +
  -               "deployed because the directory '" +
  -               unpackedDir + "' exists");
  -      }
  -      unpackedDir.mkdirs();
  -
  -      if (url.getFile().endsWith("/"))
  -      {
  -         // this is a directory - we can only deal with directories in
  -         // the local filesystem (because we can't get a list of files
  -         // from a general URL)
  -         if (!url.getProtocol().equals("file"))
  -         {
  -            throw new DeploymentException("Can only deploy directories " +
  -                  "specified by 'file:' URLs");
  -         }
  -         copyDirectory(new File(url.getFile()), unpackedDir);
  -      }
  -      else
  -      {
  -         // this is a .rar file somewhere so we copy it to the temp
  -         // dir because otherwise we run into problems when we try to
  -         // open it again later
  -         File copyFile = new File(rarTmpDir, "copy" + unpackedDirName);
  -         InputStream input = url.openStream();
  -         try
  -         {
  -            OutputStream output = new FileOutputStream(copyFile);
  -            try
  -            {
  -               copy(input, output);
  -            }
  -            finally
  -            {
  -               output.close();
  -            }
  -         }
  -         finally
  -         {
  -            input.close();
  -         }
  -         // then we can inflate the copy without fear of retribution
  -         inflateJar(copyFile.toURL(), unpackedDir);
  +      File localCopy = getLocalCopy(url, null);
  +      URL localUrl =localCopy.toURL();
  +      Collection jars = new ArrayList();
  +      Collection xmls = new ArrayList();
  +      File unpackedDir = recursiveUnpack(localUrl, jars, xmls);
  +      URL ddUrl = null;
  +      Iterator i = xmls.iterator();
  +      while (i.hasNext()) 
  +      {
  +         URL xml = (URL)i.next();
  +         if (xml.getFile().endsWith("META-INF/ra.xml")) 
  +         {
  +             ddUrl = xml;
  +             break;              
  +          }
         }
  -
  -      // Right, now we can forget about URLs and just use the file
  -      // system.
  -
  -      File ddFile = new File(unpackedDir, "META-INF/ra.xml");
  -
  -      if (!ddFile.exists())
  +      
  +      if (ddUrl == null)
         {
            throw new DeploymentException("No deployment descriptor " +
                  "('META-INF/ra.xml') found in alleged " +
  @@ -284,7 +186,7 @@
         Document dd;
         try
         {
  -         dd = XmlFileLoader.getDocument(ddFile.toURL());
  +         dd = XmlFileLoader.getDocument(ddUrl);
         }
         catch (org.jboss.ejb.DeploymentException de)
         {
  @@ -297,40 +199,17 @@
         metadata.importXml(root);
   
         // Create a class loader that can load classes from any JARs
  -      // inside the RAR. First, we need to find the JARs.
  +      // inside the RAR. RecursiveUnpack found the JARs.
   
  -      Collection jars = new ArrayList();
  -
  -      FileFilter filter =
  -         new FileFilter()
  -         {
  -            /**
  -             *  #Description of the Method
  -             *
  -             * @param  file  Description of Parameter
  -             * @return       Description of the Returned Value
  -             */
  -            public boolean accept(File file)
  -            {
  -               return file.getName().endsWith(".jar");
  -            }
  -         };
  -      Collection jarFiles = recursiveFind(unpackedDir, filter);
  -      category.debug("Adding the following URLs to classpath:");
  -      for (Iterator i = jarFiles.iterator(); i.hasNext(); )
  -      {
  -         File file = (File)i.next();
  -         URL jarUrl = file.toURL();
  -         jars.add(jarUrl);
  -         category.debug(jarUrl.toString());
  -      }
   
         // Ok, now we have the URLs of the JARs contained in the RAR we
         // can create a classloader that loads classes from them
  -
  -      ClassLoader cl = new URLClassLoader(
  -            (URL[])jars.toArray(new URL[0]),
  -            Thread.currentThread().getContextClassLoader());
  +      //Note, we're using the jboss system classloader so the rar
  +      //will be universally available without unavailable interface 
  +      //problems!
  +      //We use the original (uncopied) url as the id key.
  +      ClassLoader cl = new org.jboss.system.URLClassLoader(
  +            (URL[])jars.toArray(new URL[0]), url);
   
         metadata.setClassLoader(cl);
   
  @@ -372,7 +251,18 @@
               ConnectionFactoryLoaderMBean.UNDEPLOY_NOTIFICATION, this,
               nextMessageNum++, metadata.getDisplayName());
         sendNotification(notification);
  -
  +      //unregister the classloader from the system libraries.
  +      //this is the org.jboss.system.URLClassLoader.
  +      URLClassLoader cl = (URLClassLoader)metadata.getClassLoader();
  +      try
  +      {
  +         ServiceLibraries.getLibraries().removeClassLoader(cl);
  +      }
  +      catch (Exception e)
  +      {
  +         log.error("problem removing classloader " + cl, e);
  +      }
  +      metadata.setClassLoader(null);
         // Remove the temporary copy
   
         File unpackedDir = info.unpackedDir;
  @@ -382,163 +272,19 @@
                  unpackedDir + "' - this should be cleaned up either " +
                  "when the server is shut down or when it restarts.");
         }
  -   }
  -
  -   private Collection recursiveFind(File dir, FileFilter filter)
  -   {
  -      Collection files = new ArrayList();
  -      File[] candidates = dir.listFiles();
  -      if (candidates == null)
  -      {
  -         return null;
  -      }
  -
  -      for (int i = 0; i < candidates.length; ++i)
  -      {
  -         File candidate = candidates[i];
  -         if (candidate.isDirectory())
  -         {
  -            files.addAll(recursiveFind(candidate, filter));
  -         }
  -         else if (filter.accept(candidate))
  -         {
  -            files.add(candidate);
  -         }
  -      }
  -
  -      return files;
  -   }
  -
  -   private void copyDirectory(File srcDir, File destDir)
  -          throws DeploymentException, IOException
  -   {
  -      File[] files = srcDir.listFiles();
  -      if (files == null)
  -      {
  -         throw new DeploymentException("Not a directory: '" +
  -               srcDir + "'");
  -      }
  -
  -      destDir.mkdirs();
  -      for (int i = 0; i < files.length; ++i)
  -      {
  -         File file = files[i];
  -         File dest = new File(destDir, file.getName());
  -         if (file.isDirectory())
  -         {
  -            copyDirectory(file, dest);
  -         }
  -         else
  -         {
  -            copyFile(file, dest);
  -         }
  -      }
  -   }
  -
  -   private void copyFile(File src, File dest)
  -          throws IOException
  -   {
  -      InputStream in = new FileInputStream(src);
  -      try
  -      {
  -         OutputStream out = new FileOutputStream(dest);
  -         try
  -         {
  -            copy(in, out);
  -         }
  -         finally
  -         {
  -            out.close();
  -         }
  -      }
  -      finally
  -      {
  -         in.close();
  -      }
  -   }
  -
  -   private void inflateJar(URL url, File destDir)
  -          throws DeploymentException, IOException
  -   {
  -      URL jarUrl;
  -      try
  -      {
  -         jarUrl = new URL("jar:" + url.toString() + "!/");
  -      }
  -      catch (MalformedURLException mfue)
  -      {
  -         throw new DeploymentException("Oops! Couldn't convert URL to a " +
  -               "jar URL", mfue);
  -      }
  -
  -      JarURLConnection jarConnection =
  -            (JarURLConnection)jarUrl.openConnection();
  -      JarFile jarFile = jarConnection.getJarFile();
  -
  -      try
  -      {
  -         for (Enumeration e = jarFile.entries(); e.hasMoreElements(); )
  -         {
  -            JarEntry entry = (JarEntry)e.nextElement();
  -            String name = entry.getName();
  -            File outFile = new File(destDir, name);
  -            if (entry.isDirectory())
  -            {
  -               outFile.mkdirs();
  -            }
  -            else
  -            {
  -               InputStream in = jarFile.getInputStream(entry);
  -               try
  -               {
  -                  OutputStream out = new FileOutputStream(outFile);
  -                  try
  -                  {
  -                     copy(in, out);
  -                  }
  -                  finally
  -                  {
  -                     out.close();
  -                  }
  -               }
  -               finally
  -               {
  -                  in.close();
  -               }
  -            }
  -         }
  -      }
  -      finally
  +      URL[] urls = cl.getURLs();
  +      for (int i = urls.length - 1; i>=0; i--)
         {
  -         jarFile.close();
  -      }
  -   }
  -
  -   private void copy(InputStream in, OutputStream out)
  -          throws IOException
  -   {
  -      byte[] buffer = new byte[1024];
  -      int read;
  -      while ((read = in.read(buffer)) > 0)
  -      {
  -         out.write(buffer, 0, read);
  -      }
  -   }
  -
  -   private boolean recursiveDelete(File f)
  -   {
  -      if (f.isDirectory())
  -      {
  -         File[] files = f.listFiles();
  -         for (int i = 0; i < files.length; ++i)
  +         File dir = new File(urls[i].getFile());
  +         if (!recursiveDelete(dir))
            {
  -            if (!recursiveDelete(files[i]))
  -            {
  -               return false;
  -            }
  +            category.warn("Unable to recursively delete temp directory '" +
  +               dir + "' - this should be cleaned up either " +
  +               "when the server is shut down or when it restarts.");
            }
         }
  -      return f.delete();
  + 
  +      
      }
   
      // Inner classes -------------------------------------------------
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to