User: d_jencks
  Date: 02/02/24 10:07:16

  Modified:    src/main/org/jboss/deployment MainDeployer.java
  Log:
  Changed from unpacking to using Hiram's njar protocol. Added support for unpacking 
and loading native libraries.  Wars are still unpacked.
  
  Revision  Changes    Path
  1.2       +130 -56   jboss-system/src/main/org/jboss/deployment/MainDeployer.java
  
  Index: MainDeployer.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss-system/src/main/org/jboss/deployment/MainDeployer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MainDeployer.java 24 Feb 2002 10:24:33 -0000      1.1
  +++ MainDeployer.java 24 Feb 2002 18:07:16 -0000      1.2
  @@ -1,11 +1,9 @@
  -/***************************************
  - *                                     *
  - *  JBoss: The OpenSource J2EE WebOS   *
  - *                                     *
  - *  Distributable under LGPL license.  *
  - *  See terms of license at gnu.org.   *
  - *                                     *
  - ***************************************/
  +/*
  + * JBoss, the OpenSource J2EE webOS
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
   
   package org.jboss.deployment;
   
  @@ -17,6 +15,7 @@
   import java.io.InputStream;
   import java.io.OutputStream;
   import java.net.JarURLConnection;
  +import java.net.URLConnection;
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.util.ArrayList;
  @@ -41,6 +40,8 @@
   
   import org.jboss.util.jmx.MBeanProxy;
   
  +import org.jboss.net.protocol.nestedjar.NestedJarURLHandlerFactory;
  +
   /**
    * MainDeployer
    *
  @@ -48,7 +49,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Scott Stark</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class MainDeployer
      extends ServiceMBeanSupport
  @@ -82,9 +83,20 @@
      /** The string naming the tempDir **/
      private String tempDirString;
   
  +   private File tempNativeDir;
  +
      /** The system home directory (for dealing with relative file names). */
      private File homeDir;
   
  +   /**
  +    *  variables <code>nativePrefix</code> and <code>nativeSuffix</code> hold the 
  +    * prefix and suffix of native libraries on this system.  They are determined by 
  +    * examining the result of System.mapLibraryName("XxX").
  +    *
  +    */
  +   private String nativePrefix;
  +   private String nativeSuffix;
  +
      public void setPeriod(int period) {
         this.period = period; 
      }
  @@ -94,7 +106,10 @@
         return period;
      }
      
  -   
  +   //static, load our url handler.
  +   {
  +      NestedJarURLHandlerFactory.start();
  +   }
      /** 
       * Directory get set logic, these are "scanning" directories
       * on the local filesystem
  @@ -205,6 +220,9 @@
         tempDir = new 
File((File)server.getAttribute(ServerConfigImplMBean.OBJECT_NAME, "TempDir"),
                            "deploy");
   
  +      tempNativeDir = new 
File((File)server.getAttribute(ServerConfigImplMBean.OBJECT_NAME, "TempDir"),
  +                         "native");
  +
         //used in isWatched
         tempDirString = tempDir.toURL().toString(); 
   
  @@ -525,6 +543,24 @@
         {
            throw new DeploymentException("exception in init of " + deployment.url, e);
         } // end of try-catch
  +      finally 
  +      {
  +         // whether you do it or not, for the autodeployer
  +         deployment.lastDeployed = System.currentTimeMillis();
  +         
  +         synchronized (deploymentsList)
  +         {
  +            //watch it, it will be picked up as modified below, deployments is a 
map duplicates are ok
  +            deployments.put(deployment.url, deployment);
  +            
  +            // Do we watch it? Watch only urls outside our copy directory.
  +            if (!inLocalCopyDir(deployment.url)) 
  +            {
  +               deploymentsList.add(deployment);
  +               log.debug("Watching new file: " + deployment.url);  
  +            }
  +         }
  +      }
      }
   
      /**
  @@ -564,24 +600,6 @@
            deployment.status = "Deployment FAILED reason: " + t.getMessage();         
            throw new DeploymentException("Could not create deployment: " + 
deployment.url, t);
         }
  -      finally 
  -      {
  -         // whether you do it or not, for the autodeployer
  -         deployment.lastDeployed = System.currentTimeMillis();
  -         
  -         synchronized (deploymentsList)
  -         {
  -            //watch it, it will be picked up as modified below, deployments is a 
map duplicates are ok
  -            deployments.put(deployment.url, deployment);
  -            
  -            // Do we watch it? Watch only urls outside our copy directory.
  -            if (!deployment.url.toString().startsWith(tempDirString)) 
  -            {
  -               deploymentsList.add(deployment);
  -               log.debug("Watching new file: " + deployment.url);  
  -            }
  -         }
  -      }
      }
   
      /**
  @@ -836,15 +854,16 @@
         // marcf FIXME FIXME FIXME add support for directories not just jar files
         
         // Do we have a jar file jar:<theURL>!/..
  +      String jarURLString = "njar:"+di.localUrl.toString()+"^/";
         try
         {
  -         URL jarURL = new URL("jar:"+di.localUrl.toString()+"!/");
  -         JarURLConnection jarConn = (JarURLConnection) jarURL.openConnection();
  +         URL jarURL = new URL(jarURLString);
  +         URLConnection con = jarURL.openConnection();
  +         JarURLConnection jarConn = (JarURLConnection)con;
            jarFile = jarConn.getJarFile();
         }
         catch (Exception e)
         {
  -
            //maybe this is not a jar nor a directory...
            log.info("deploying non-jar/xml file: " + di.url);
            return;
  @@ -863,35 +882,12 @@
               || name.endsWith(".sar")
               || name.endsWith(".ear")
               || name.endsWith(".rar")
  -            || name.endsWith(".war")
               || name.endsWith(".zip"))
            {
  -            // Make sure the name is flat no directory structure in subs name
  -            // example war's WEBINF/lib/myjar.jar appears as myjar.jar in 
  -            // the tmp directory
  -            if (name.lastIndexOf("/") != -1)  
  -            {
  -               name = name.substring(name.lastIndexOf("/")+1);
  -            }
  -            
               try 
               {
  -               // We use the name of the entry as the name of the file under deploy 
  -               File outFile = new File(tempDir, getNextID() + "." + name);
  -               
  -               // Copy in and out 
  -               OutputStream out = new FileOutputStream(outFile); 
  -               InputStream in = jarFile.getInputStream(entry);
  -               
  -               try {
  -                  copy(in, out);
  -               }
  -               finally {
  -                  out.close(); 
  -               }
  -
                  // It is a sub-deployment
  -               URL subURL = outFile.toURL();
  +               URL subURL = new URL("njar:" + di.localUrl.toString() + "^/" + name);
                  DeploymentInfo sub = new DeploymentInfo(subURL, di);
                  
                  // And deploy it, this call is recursive
  @@ -914,6 +910,72 @@
            // works
            // We should encapsulate "opening and closing of the jarFile" in the 
DeploymentInfo
            // Here we let it be open and cached
  +         else if (name.endsWith(".war")) 
  +         {
  +            /**we need to copy wars to a real file, no one else will understand our 
njar:...^/
  +             *  protocol... not even jetty
  +             */
  +            try 
  +            {
  +               URL subUrl = new URL("njar:" + di.localUrl.toString() + "^/" + name);
  +               //!!!!!!!!!!!!!!!!NONONONONO FIXME TODO etc etc
  +               //this is not where the dest file should be
  +               File destFile = new File(tempDir, name);
  +               URL destUrl = destFile.toURL();
  +               //System.out.println("war copy: subUrl: " + subUrl);
  +               //System.out.println("war copy: destFile: " + destFile);
  +
  +               log.debug("copying war to: " + destUrl.toString());
  +               copy(subUrl, destUrl);
  +               DeploymentInfo sub = new DeploymentInfo(destUrl, di);
  +            }
  +            catch (Exception ware)
  +            {
  +               throw new DeploymentException("Problem copying war: " + di.localUrl, 
ware);
  +            } // end of try-catch
  +         } // end of if ()
  +         else
  +         {
  +            //is it a native library?
  +            if (nativeSuffix == null) 
  +            {
  +               String nativex = System.mapLibraryName("XxX");
  +               int xPos = nativex.indexOf("XxX"); //hope "XxX' is not part of any 
native lib goo!
  +               nativePrefix = nativex.substring(0, xPos);
  +               nativeSuffix = nativex.substring(xPos + 3);        
  +            } // end of if ()
  +
  +            if (name.endsWith(nativeSuffix)) 
  +            {
  +               int i = name.lastIndexOf("/");
  +               if (name.substring(Math.max(i, 0)).startsWith(nativePrefix)) 
  +               {
  +                  try 
  +                  {
  +                     //it's a native library for our system (we hope!), copy it.
  +                     URL subUrl = new URL("njar:" + di.localUrl.toString() + "^/" + 
name);
  +                     File destFile = new File(tempNativeDir, name);
  +                     log.info("Loading native library: " + destFile.toString());
  +                     URL destUrl = destFile.toURL(); 
  +                     copy(subUrl, destUrl);
  +                     System.load(destFile.toString());
  +                  }
  +                  catch (Exception nativee)
  +                  {
  +                     throw new DeploymentException("error with native library! " + 
di.localUrl, nativee);
  +                  } // end of try-catch
  +                  
  +                  
  +               } // end of if ()
  +               
  +               
  +            } // end of if ()
  +            
  +
  +            
  +
  +         } // end of else
  +         
         }
      }
   
  @@ -999,14 +1061,14 @@
            }
            
            // Are we already in the localCopyDir?
  -         else if (sdi.url.toString().indexOf(tempDir.toString()) != -1)
  +         else if (inLocalCopyDir(sdi.url))
            {
               sdi.localUrl = sdi.url;
               return;
            }
            else
            {
  -            sdi.localUrl =  new File(tempDir, getNextID() + "." + 
sdi.shortName).toURL();
  +            sdi.localUrl =  new File(tempDir,  sdi.url.getFile()).toURL();
               copy(sdi.url, sdi.localUrl);
            }
         }
  @@ -1014,6 +1076,18 @@
         {
            log.error("Could not make local copy for "+sdi.url.toString(), e);
         }
  +   }
  +
  +   private boolean inLocalCopyDir(URL url)
  +   {
  +      int i = 0;
  +      String urlTest = url.toString();
  +      while (urlTest.startsWith("njar:", i))
  +      {
  +         i += "njar:".length();
  +      } // end of while ()
  +      
  +      return urlTest.startsWith(tempDirString, i); 
      }
      
      protected void copy(InputStream in, OutputStream out)
  
  
  

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

Reply via email to