User: d_jencks
  Date: 02/02/11 21:41:09

  Modified:    src/main/org/jboss/deployment MainDeployer.java
                        MainDeployerMBean.java DeploymentInfo.java
  Log:
  cleanup of many deployment/undployment problems including bug 515537, deploy loops 
on failed deployment
  
  Revision  Changes    Path
  1.14      +299 -215  jboss/src/main/org/jboss/deployment/MainDeployer.java
  
  Index: MainDeployer.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/deployment/MainDeployer.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- MainDeployer.java 12 Feb 2002 03:22:02 -0000      1.13
  +++ MainDeployer.java 12 Feb 2002 05:41:09 -0000      1.14
  @@ -7,65 +7,63 @@
   
   package org.jboss.deployment;
   
  +
  +
  +
  +
  +import java.io.File;
  +import java.io.FileInputStream;
  +import java.io.FileOutputStream;
  +import java.io.FilenameFilter;
  +import java.io.IOException;
  +import java.io.InputStream;
  +import java.io.OutputStream;
  +import java.net.JarURLConnection;
  +import java.net.MalformedURLException;
  +import java.net.URL;
   import java.util.ArrayList;
  -import java.util.Set;
  +import java.util.Collection;
   import java.util.Enumeration;
  -import java.util.HashSet;
  -import java.util.Map;
   import java.util.HashMap;
  +import java.util.HashSet;
   import java.util.Iterator;
  +import java.util.List;
  +import java.util.Map;
  +import java.util.Set;
   import java.util.StringTokenizer;
  -import java.util.jar.JarFile;
   import java.util.jar.Attributes;
   import java.util.jar.JarEntry;
  +import java.util.jar.JarFile;
   import java.util.jar.Manifest;
  -
  -import java.net.JarURLConnection;
  -import java.net.URL;
  -import java.net.MalformedURLException;
  -
  -import java.io.InputStream;
  -import java.io.FileInputStream;
  -import java.io.FileOutputStream;
  -import java.io.OutputStream;
  -import java.io.File;
  -import java.io.FilenameFilter;
  -import java.io.IOException;
  -
   import javax.management.MBeanServer;
  -import javax.management.ObjectName;
   import javax.management.MalformedObjectNameException;
  -
  +import javax.management.ObjectName;
   import org.jboss.system.ServiceMBeanSupport;
  -
   import org.jboss.util.DirectoryBuilder;
  -import org.jboss.util.MBeanProxy;
  -
   
   /**
  - * Takes a series of URL to watch, detects changes and calls the appropriate 
Deployers.
  - * 
  + * MainDeployer
  + *
  + * Takes a series of URL to watch, detects changes and calls the appropriate 
Deployers 
  + *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  - * @author <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
  - * @version $Revision: 1.13 $
  + * @version $Revision: 1.14 $
    */
   public class MainDeployer
      extends ServiceMBeanSupport
      implements MainDeployerMBean, Runnable
   {
  -   /** JMX Server **/
  -   private MBeanServer server;
      
      /** Deployers **/
  -   private Set deployers = new HashSet();
  +   private final Set deployers = new HashSet();
      
      /** Scanned Directories **/
  -   private ArrayList directories = new ArrayList();
  +   private final ArrayList directories = new ArrayList();
      
      /** I always feel like somebody is watching me, contains DeploymentInfo **/
  -   private Map deployments = new HashMap();
  -   private ArrayList deploymentsList = new ArrayList();
  -   
  +   private final Map deployments = new HashMap();
  +   private final ArrayList deploymentsList = new ArrayList();
  +
      /** Thread running **/
      private boolean running = false;
      
  @@ -76,16 +74,20 @@
      private int id = 0;
      
      /** Given a flat set of files, this is the order of deployment **/
  -   private String[] order = { "sar", "service.xml", "rar", "jar", "war", "ear", 
"zip" };
  +   private final String[] order = {"sar", "service.xml", "rar", "jar", "war", 
"ear", "zip"};
      
  -   public void setPeriod(int period) {
  +   /** Get on period **/
  +   public void setPeriod(int period) 
  +   { 
         this.period = period; 
      }
   
  -   public int getPeriod() { 
  -      return period; 
  +   public int getPeriod() 
  +   {
  +      return period;
      }
      
  +   
      /** 
       * Directory get set logic, these are "scanning" directories
       * on the local filesystem
  @@ -106,16 +108,17 @@
         // We are dealing with a relative path URL 
         if (!( url.startsWith("file:") || url.startsWith("http:")))
         {
  -         url = "file:" + System.getProperty("jboss.system.home") + "/" + url;
  +         url = "file:"+System.getProperty("jboss.system.home")+File.separator+url;
         }
  -
         // Only one entry
         try 
         { 
            URL dir = new URL(url);
  -         if (!directories.contains(dir)) {
  -         directories.add(dir); 
  -      }
  +         
  +         if (!directories.contains(dir)) 
  +         {
  +            directories.add(dir); 
  +         }
         }
         catch (MalformedURLException bad)
         { 
  @@ -123,8 +126,8 @@
            return;
         }
         
  -
  -      if (log.isDebugEnabled()) {
  +      if (log.isDebugEnabled())
  +      {
            log.debug("Added directory scan "+url);
         }
      }
  @@ -140,40 +143,37 @@
         try 
         { 
            int index = directories.lastIndexOf(new URL(url));
  -         if (index != -1) {
  -         directories.remove(index); 
  -      }
  +         if (index != -1) 
  +         {
  +            directories.remove(index); 
  +         }
         }
         catch (MalformedURLException bad)
         { 
  -         log.warn("Failed to remove directory scan "+url); 
  +         log.warn("Failed to remove directory scan " + url); 
            return;
         }
         
  -      if (log.isDebugEnabled()) {
  +      if (log.isDebugEnabled())
  +      {
            log.debug("Removed directory scan "+url);
         }
      }
   
  -   public String[] getDeployed()
  +   public Collection listDeployed()
      {
  -      String[] urls = new String[deployments.size()];
  -      
  -      int i = 0;
  -      Iterator iterator = deployments.keySet().iterator();
  -      while (iterator.hasNext()) 
  -      {
  -         urls[i++] = ((DeploymentInfo) iterator.next()).url.toString();
  -      }
  -      return urls;
  +      return new ArrayList(deploymentsList);
      }
      
  -   public void addDeployer(DeployerMBean deployer) {
  -      deployers.add(deployer);
  +   public void addDeployer(DeployerMBean deployer) 
  +   {
  +      log.info("adding deployer: " + deployer);
  +      deployers.add(deployer); 
      }
      
  -   public void removeDeployer(DeployerMBean deployer) {
  -      deployers.remove(deployer);
  +   public void removeDeployer(DeployerMBean deployer) 
  +   {
  +      deployers.remove(deployer); 
      }
      
      
  @@ -186,15 +186,16 @@
       */
      public String getName()
      {
  -      //
  -      // What is this used for?  Should this method be depricated?
  -      //
  -
         return "Main Deployer";
      }
      
      /**
       * Gets the ObjectName attribute of the AutoDeployer object
  +    *
  +    * @param server Description of Parameter
  +    * @param name Description of Parameter
  +    * @return The ObjectName value
  +    * @exception MalformedObjectNameException Description of Exception
       */
      protected ObjectName getObjectName(MBeanServer server, ObjectName name)
         throws MalformedObjectNameException
  @@ -210,7 +211,6 @@
         // (start/stop) only one entry is present
   
         // FIXME: Should pull this from ServerConfig
  -
         addDirectory("deploy");
         
         // Do a first pass
  @@ -229,11 +229,13 @@
         running = false;
      }
      
  -   public boolean getScan() { 
  +   public boolean getScan() 
  +   { 
         return running; 
      }
   
  -   public void setScan(boolean scan) { 
  +   public void setScan(boolean scan) 
  +   {
         running = scan; 
      }
      
  @@ -245,7 +247,6 @@
         do
         {   
            scan();
  -
            // Sleep
            try
            {
  @@ -261,49 +262,43 @@
      
      public void scan() 
      {   
  -      try 
  +      // Scan directories for new deployments 
  +      for (Iterator newDeployments = scanNew().listIterator(); 
newDeployments.hasNext();)
         {
  -      Iterator iter;
  -
  -         // Scan diretories for new deployments 
  -         iter = scanNew().listIterator();
  -         while (iter.hasNext())
  +         URL deployable = (URL) newDeployments.next();
  +         try 
            {
  -            deploy((URL)iter.next());     
  +            deploy(deployable);     
            }
  -
  -         // Undeploy and redeploy to the modified ones
  -      iter = scanModified().listIterator();
  -         
  -         while (iter.hasNext())
  +         catch (Throwable t)
            {
  -            DeploymentInfo di = (DeploymentInfo)iter.next();
  -            try
  -            {
  -               // if the url is a file that doesn't exist, it was removed -> 
undeploy
  +            log.error("Could not deploy: " + deployable, t); 
  +         } // end of try-catch
  +         
  +      }
   
  -               // TODO: check connection on http protocol and see if it is removed.
  +      // Undeploy the removed ones
  +      for (Iterator removed = scanRemoved().listIterator(); removed.hasNext();)
  +      {
  +         DeploymentInfo di = (DeploymentInfo) removed.next();
  +         // if the url is a file that doesn't exist, it was removed -> undeploy
  +         undeploy(di);
  +      }  
   
  -               if (di.url.getProtocol().startsWith("file") && !new 
File(di.url.getFile()).exists())
  -               {   
  -                  undeploy(di);
  -               }  
  -               // it is a deployment 
  -               else 
  -               {
  -                  undeploy(di); deploy(di);
  -               }
  -            }
  -            catch (Exception e)
  -            {
  -               log.warn("operation failed; ignoring", e);
  -            }
  +      // Undeploy and redeploy the modified ones
  +      for (Iterator modified = scanModified().listIterator(); modified.hasNext();)
  +      {
  +         DeploymentInfo di = (DeploymentInfo) modified.next();
  +         undeploy(di);
  +         try 
  +         {
  +            deploy(di);     
            }
  +         catch (Throwable t)
  +         {
  +            log.error("Could not deploy: " + di.url, t); 
  +         } // end of try-catch
         }
  -      catch (Exception e)
  -      {
  -         log.warn("operation failed; ignoring", e);
  -      } 
      }
   
      public void undeploy(String url)
  @@ -312,9 +307,10 @@
         {
            DeploymentInfo sdi = (DeploymentInfo) deployments.get(new URL(url));
            
  -         if (sdi!= null) {
  +         if (sdi!= null)
  +         {
               undeploy(sdi);
  -      }
  +         }
         }  
         catch (Exception e)
         {
  @@ -328,38 +324,56 @@
         log.info("Undeploying "+di.url);
   
         // First remove all sub-deployments
  -      Iterator subs = di.subDeployments.iterator();
  -      while (subs.hasNext())
  +      for (Iterator subs = di.subDeployments.iterator(); subs.hasNext();)
         {
            DeploymentInfo sub = (DeploymentInfo) subs.next();
            
  -         // undeploy((DeploymentInfo) subs.next());
            if (log.isDebugEnabled())
  -            log.debug("DEPLOYMENT OF SUB "+sub.url);
  +         {
  +            log.debug("UNDEPLOYMENT OF SUB "+sub.url);
  +         }
            undeploy(sub);      
         }
   
  -      // Them remove the deployment itself
  +      // Then remove the deployment itself
         try 
         { 
            // Tell the respective deployer to undeploy this one
            if (di.deployer != null)
  +         {
               di.deployer.undeploy(di); 
  -
  +         }
  +      }
  +      catch (Exception e)
  +      {
  +         log.error("Undeployment failed: " + di.url, e); 
  +      }
  +      catch (Throwable t)
  +      {
  +         log.error("Undeployment failed: " + di.url, t); 
  +      }
  +      try
  +      {
            // remove from local maps
            deployments.remove(di.url);
  -         if (deploymentsList.lastIndexOf(di) != -1) {
  +         if (deploymentsList.lastIndexOf(di) != -1)
  +         {
               deploymentsList.remove(deploymentsList.lastIndexOf(di));
  -      }
  +         }
               
            // Nuke my stuff, this includes the class loader
            di.cleanup(log);
            
  -      log.info("Undeployed "+di.url);
  +         log.info("Undeployed "+di.url);
  +      
         }
         catch (Exception e)
         {
  -         log.error("Undeployment failed: " + di.url, e); 
  +         log.error("Undeployment cleanup failed: " + di.url, e); 
  +      }
  +      catch (Throwable t)
  +      {
  +         log.error("Undeployment cleanup failed: " + di.url, t); 
         }
      }
      
  @@ -398,7 +412,7 @@
         }
         catch (DeploymentException e)
         {
  -         log.error("Could not deploy URL "+url, e);
  +         log.error("Couldn't deploy URL "+url, e);
         }
      }
   
  @@ -411,9 +425,12 @@
         {
            // If we are already deployed return
            if (deployments.containsKey(deployment.url))
  +         {
               return;
  +         }
   
  -      log.info("Deploying: " + deployment.url.toString());
  +         if (log.isInfoEnabled());
  +           log.info("Deploying: " + deployment.url.toString());
   
            // Create a local copy of that File, the sdi keeps track of the copy 
directory
            makeLocalCopy(deployment);
  @@ -424,47 +441,53 @@
            // What deployer is able to deploy this file
            findDeployer(deployment);
            
  -         if(deployment.deployer != null) {
  +         if(deployment.deployer != null)
  +         {
               deployment.deployer.init(deployment); 
  -      }
  +         }
   
            // create subdeployments as needed
            deploySubPackages(deployment);
            
            // Deploy this SDI, if it is a deployable type
  -         if (deployment.deployer != null) {
  +         if (deployment.deployer != null)
  +         {
               deployment.deployer.deploy(deployment);
  -      }
  +         }
   
  -         deployment.status = "Deployed";
  +         deployment.status="Deployed";
   
  -         if (debug) {
  +         if (debug)
               log.debug("Done deploying " + deployment.shortName);
  -      }
         }  
  -      catch (DeploymentException e) 
  +      catch (DeploymentException de) 
         { 
  -         deployment.status = "Deployment FAILED reason: " + e.getMessage();         
  -         throw e;
  +         log.error("could not deploy :" + deployment.url, de);
  +         deployment.status="Deployment FAILED reason: " + de.getMessage();         
  +         throw de;
  +      }
  +      catch (Throwable t) 
  +      { 
  +         log.error("could not deploy :" + deployment.url, t);
  +         deployment.status="Deployment FAILED reason: "+t.getMessage();         
  +         throw new DeploymentException("Could not deploy: " + deployment.url, t);
         }
         finally 
         {
            // whether you do it or not, for the autodeployer
            deployment.lastDeployed = System.currentTimeMillis();
            
  -         // watch it, it will be picked up as modified below, deployments is a map 
duplicates are ok
  +         //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?
  -
  -      // FIXME: Should not hardcode deployment tmp dir
  -      
  -         if 
(!deployment.url.toString().startsWith("file:"+System.getProperty("jboss.system.home")+
 "/tmp/deploy"))
  +         if 
(!deployment.url.toString().startsWith("file:"+System.getProperty("jboss.system.home")+File.separator+"tmp"+File.separator+"deploy"))
            {
               deploymentsList.add(deployment);
  -            if (debug) {
  +            if (debug)
  +            {
                  log.debug("Watching new file: " + deployment.url);  
  -         }
  +            }
            }
         }
      }
  @@ -480,22 +503,23 @@
         // To deploy directories of beans one should just name the directory
         // mybean.ear/bla...bla, so that the directory gets picked up by the right 
deployer
         //
  -
  -      Iterator iter = deployers.iterator();
  -      while (iter.hasNext())
  +      for (Iterator iterator = deployers.iterator(); iterator.hasNext(); )
         {
  -         DeployerMBean deployer = (DeployerMBean) iter.next();
  +         DeployerMBean deployer = (DeployerMBean) iterator.next();
            if (deployer.accepts(sdi))
            {
               sdi.deployer = deployer;
               if (debug)
  +            {
                  log.debug("using deployer "+deployer);
  +            }
               return;
            }
         }
  -
         if (debug)
  +      {
            log.debug("NO DEPLOYER for url "+sdi.url);
  +      }
      }
   
      public void preDeregister()
  @@ -516,12 +540,13 @@
            HashSet newDeployments = new HashSet();
            boolean trace = log.isTraceEnabled();
            // Scan directories
  -         Iterator iter = directories.listIterator();
  -         while (iter.hasNext()) 
  +         for (Iterator iterator = directories.listIterator(); iterator.hasNext();) 
            {
  -            File dir = new File(((URL) iter.next()).getFile());
  +            File dir = new File(((URL) iterator.next()).getFile());
               if (trace)
  +            {
                  log.trace("Scanning directory: " + dir);
  +            }
               File[] files = dir.listFiles();
               if (files == null)
               {
  @@ -531,10 +556,14 @@
               for (int i = 0; i < files.length; i++)
               {
                  if( trace )
  +               {
                     log.trace("Checking deployment file: "+files[i]);
  +               }
                  // It is a new file
                  if (!deployments.containsKey(files[i].toURL())) 
  +               {
                     newDeployments.add(files[i].toURL());
  +               }
               }   
            }
            
  @@ -548,52 +577,102 @@
      }
      
      /**
  +    * scanRemoved scans the existing deployments and return a 
  +    * Set with the removed deployments
  +    */
  +   protected List scanRemoved()
  +   {
  +      HashSet removed = new HashSet();
  +         
  +      if (log.isTraceEnabled())
  +      {
  +         log.trace("Scanning installed deployments");
  +      }
  +      // People already deployed, scan for modifications  
  +      for (Iterator it = deploymentsList.listIterator(); it.hasNext(); )
  +      {
  +         DeploymentInfo deployment = (DeploymentInfo) it.next();
  +         if (deployment.url.getProtocol().startsWith("file")) 
  +         {
  +            File theFile = new File(deployment.url.getFile());
  +            if (!theFile.exists())
  +            {
  +               removed.add(deployment);
  +            }
  +               
  +         } // end of if ()
  +         else
  +         {
  +            try 
  +            {
  +               deployment.url.openConnection();
  +            }
  +            catch (java.io.IOException ioe)
  +            {
  +               removed.add(deployment);
  +            } // end of try-catch
  +         }
  +      }
  +      return sortDeployments(removed);
  +   }
  +   /**
       * scanModified scans the existing deployments and return a 
       * Set with the modified deployments
       */
      protected ArrayList scanModified()
      {
  -      try
  -      {
  -         HashSet modified = new HashSet();
  -         
  -         if (log.isTraceEnabled())
  -            log.trace("Scanning installed deployments");
  -
  -         // People already deployed, scan for modifications  
  -         Iterator iter = deploymentsList.listIterator();
  +      HashSet modified = new HashSet();
            
  -         while (iter.hasNext())
  -         {
  -            DeploymentInfo deployment = (DeploymentInfo) iter.next();
  -            long lastModified = 0;
  +      if (log.isTraceEnabled())
  +      {
  +         log.trace("Scanning installed deployments");
  +      }
  +      // People already deployed, scan for modifications  
  +      for (Iterator it = deploymentsList.listIterator(); it.hasNext(); )
  +      {
  +         DeploymentInfo deployment = (DeploymentInfo) it.next();
               
  -            // Get lastModified of file from file system
  -            if (deployment.watch.getProtocol().startsWith("file"))
  +         long lastModified = 0;
  +            
  +         // if noone told us what to watch, we'll look for something...
  +         if (deployment.watch == null)
  +         {
  +            deployment.watch = deployment.url;
  +         }
  +         // Get lastModified of file from file system
  +         if (deployment.watch.getProtocol().startsWith("file"))
  +         {
  +            File theFile = new File(deployment.watch.getFile());
  +            if (theFile.exists())
               {
  -               File theFile = new File(deployment.watch.getFile());
  -               if ( ! theFile.exists()) modified.add(deployment);
  -                  
                  lastModified = theFile.lastModified();
               }
  +         }
               
  -            // Use URL connection to get lastModified on http
  -            else lastModified = deployment.watch.openConnection().getLastModified();
  +         // Use URL connection to get lastModified on http
  +         else 
  +         {
  +            try 
  +            {
  +               lastModified = deployment.watch.openConnection().getLastModified();
  +            }
  +            catch (java.io.IOException ioe)
  +            {
  +               //ignored, watch is missing.
  +            } // end of try-catch
  +         }
                  
  -            // Check the record in the DeploymentInfo against the physical one 
  -            if (deployment.lastDeployed < lastModified) 
  -               modified.add(deployment);
  +         // Check the record in the DeploymentInfo against the physical one 
  +         if (deployment.lastDeployed < lastModified) 
  +         {
  +            modified.add(deployment);
            }
            
  -         return sortDeployments(modified);
  -      }
  -      catch (Throwable t)
  -      {
  -         log.error("operation failed", t);
  -         return null;
         }
  +      return sortDeployments(modified);
      }
      
  +
      /**
       * extractPackages 
       * 
  @@ -609,8 +688,9 @@
         // FIXME do the sub deploy for directory and the move to 
         // if (di.isXML) return;
         if (di.isXML || di.isDirectory)
  +      {
            return ;
  -
  +      }
         // J2EE legacy goo in manifest
         parseManifestLibraries(di);
         
  @@ -630,7 +710,10 @@
         }
         catch (Exception e)
         {
  -         throw new DeploymentException(e);
  +
  +         //maybe this is not a jar nor a directory...
  +         log.info("deploying non-jar/xml file: " + di.url);
  +         return;
         }
   
         for (Enumeration e = jarFile.entries(); e.hasMoreElements();)
  @@ -643,22 +726,23 @@
            // b- a class in a normal directory structure
            // is a "package" and will be deployed
            if (name.endsWith(".jar")
  -             || name.endsWith(".sar")
  -             || name.endsWith(".ear")
  -             || name.endsWith(".rar")
  -             || name.endsWith(".war")
  -             || name.endsWith(".zip"))
  +            || 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 
               {
                  DirectoryBuilder builder = 
  -                  new DirectoryBuilder(System.getProperty("jboss.system.home"));
  +               new DirectoryBuilder(System.getProperty("jboss.system.home"));
                  File localCopyDir = builder.cd("tmp").cd("deploy").get();
                  
                  // We use the name of the entry as the name of the file under deploy 
  @@ -688,7 +772,7 @@
               { 
                  log.error("Error in subDeployment with name "+name, ex);
                  throw new DeploymentException
  -                  ("Could not deploy sub deployment "+name+" of deployment 
"+di.url);
  +               ("Could not deploy sub deployment "+name+" of deployment "+di.url);
               }
            }
         
  @@ -705,14 +789,11 @@
         }
         
         // Order the deployments
  -      Iterator iter = sortDeployments(subDeployments).listIterator();
  -      
  -      // Deploy them all 
  -      while (iter.hasNext()) 
  +      for (Iterator lt = sortDeployments(subDeployments).listIterator(); 
lt.hasNext();) 
         { 
            try
            { 
  -            deploy((DeploymentInfo)iter.next());
  +            deploy((DeploymentInfo) lt.next());
            }
            catch (DeploymentException e)
            {
  @@ -740,9 +821,10 @@
         {
            ArrayList tmp = new ArrayList();
            StringTokenizer st = new StringTokenizer(classPath);
  -         if (debug) {
  -            log.debug("resolveLibraries: " + classPath);
  -      }
  +         if (debug)
  +         {
  +            log.debug("resolveLibraries: "+classPath);
  +         }
   
            while (st.hasMoreTokens())
            {
  @@ -752,9 +834,10 @@
               
               DeploymentInfo sub = null;
   
  -            if (debug) {
  +            if (debug)
  +            {
                  log.debug("new manifest entry for sdi at "+sdi.shortName+" entry is 
"+tk);
  -         }
  +            }
   
               try
               {   
  @@ -771,7 +854,7 @@
               catch (Exception ignore)
               { 
                  log.warn("The manifest entry in "+sdi.url+" references URL "+lib+ 
  -                     " which could not be opened, entry ignored");
  +                  " which could not be opened, entry ignored");
               } 
            }
         }
  @@ -801,13 +884,10 @@
               sdi.localUrl = sdi.url;
               
               return;
  +            // FIXME TODO add support for Directory copying over
            }
            
            // Are we already in the localCopyDir?
  -
  -      // FIXME: Should not hard code deploy tmp dir, should also reference it as a 
URL, instead
  -      //        of this mixed mode crap (is this a file or a URL, url should not 
use File.sep)
  -
            else if 
(sdi.url.toString().indexOf(System.getProperty("jboss.system.home")+File.separator+"tmp"+File.separator+"deploy")
 != -1) 
            {
               sdi.localUrl = sdi.url;
  @@ -815,13 +895,15 @@
            }
            else
            {
  +            // return new URL("file:"+f.getCanonicalPath());
  +            
               sdi.localUrl =  new File (localCopyDir, getNextID 
()+"."+sdi.shortName).toURL();
               copy(sdi.url, sdi.localUrl);
            }
         }
         catch (Exception e)
         {
  -         log.error("Could not make local copy for " + sdi.url, e);
  +         log.error("Could not make local copy for "+sdi.url.toString(), e);
         }
      }
      
  @@ -836,10 +918,10 @@
         }
      }
      
  -   protected void copy(URL _src, URL _dest) throws IOException
  +   protected void copy (URL _src, URL _dest) throws IOException
      {
         if (!_dest.getProtocol ().equals ("file"))
  -         throw new IOException("only file: protocol is allowed as destination!");
  +         throw new IOException ("only file: protocol is allowed as destination!");
         
         InputStream in;
         OutputStream out;
  @@ -847,8 +929,10 @@
         String s = _dest.getFile ();
         File dir = new File (s.substring (0, s.lastIndexOf("/")));
         if (!dir.exists ())
  +      {
            dir.mkdirs ();
  -      
  +      }
  +
         in = _src.openStream ();
         out = new FileOutputStream (s); 
         
  @@ -876,8 +960,7 @@
         
         for (int i = 0 ; i < order.length ; i++)
         {
  -         Iterator it = urls.iterator();
  -         while (it.hasNext()) 
  +         for (Iterator it = urls.iterator(); it.hasNext();) 
            {
               URL url = (URL) it.next();
               
  @@ -900,8 +983,7 @@
         
         for (int i = 0 ; i < order.length ; i++)
         {
  -         Iterator it = urls.iterator();
  -         while (it.hasNext()) 
  +         for (Iterator it = urls.iterator(); it.hasNext();) 
            {
               DeploymentInfo di = (DeploymentInfo) it.next();
               
  @@ -914,29 +996,31 @@
         
         // Unknown types deployed at the end
         list.addAll(urls);
  -      
  +      if (log.isTraceEnabled()) 
  +      {
  +         log.trace("about to do something with: " + list);
  +      } // end of if ()
         return list;
      }
      
      public boolean isDeployed(String url) 
         throws MalformedURLException
      {
  -      DeploymentInfo di = getDeployment(new URL(url));
  -
  -      return (di != null);
  +      URL deployURL = new URL(url);
  +      DeploymentInfo di = getDeployment(deployURL);
  +      return ( di != null );
      }
   
      public DeploymentInfo getDeployment(URL url)  
      { 
  -      return (DeploymentInfo)deployments.get(url); 
  +      return (DeploymentInfo) deployments.get(url); 
      }
      
      public DeploymentInfo removeDeployment(DeploymentInfo di) 
      { 
  -      return (DeploymentInfo)deployments.remove(di.url); 
  +      return (DeploymentInfo) deployments.remove(di.url); 
      } 
      
  -   private int getNextID() { 
  -      return id++;
  -   }
  +   private int getNextID() { return id++;}
   }
  +
  
  
  
  1.4       +31 -31    jboss/src/main/org/jboss/deployment/MainDeployerMBean.java
  
  Index: MainDeployerMBean.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/deployment/MainDeployerMBean.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MainDeployerMBean.java    12 Feb 2002 03:22:02 -0000      1.3
  +++ MainDeployerMBean.java    12 Feb 2002 05:41:09 -0000      1.4
  @@ -1,53 +1,53 @@
   /*
  - * 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;
   
   import java.net.URL;
  -
  +import java.util.Collection;
   import javax.management.ObjectName;
  -
   import org.jboss.system.ServiceMBean;
   import org.jboss.util.SafeObjectNameFactory;
   
   /**
  - * This is the interface of the AutoDeployer that is exposed for
  - * administration
  - *      
  - * @author <a href="mailto:[EMAIL PROTECTED]";>Rickard Öberg</a>
  - * @author <a href="mailto:[EMAIL PROTECTED]";>Toby Allsopp</a>
  - * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  - * @version $Revision: 1.3 $
  - *
  - * <p><b>20011223 marc fleury:</b>
  - * <ul> 
  - *   <li>add/RemoveURL, added the capacity to dynamically add a URL to watch
  - *   <li>add/Removedeployer, dynamically add a new deployer
  - *   <li>Changed ObjectName to JBOSs-SYSTEM realm (from EJB realm)
  - *   <li>Rewrite
  - * </ul>
  - */
  +* This is the interface of the AutoDeployer that is exposed for
  +* administration
  +*      
  +* @see AutoDeployer
  +* 
  +* @author <a href="mailto:[EMAIL PROTECTED]";>Rickard Öberg</a>
  +* @author <a href="mailto:[EMAIL PROTECTED]";>Toby Allsopp</a>
  +* @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  +* @version $Revision: 1.4 $
  +*      <p><b>20011223 marc fleury:</b>
  +*      <ul> 
  +*      <li>add/RemoveURL, added the capacity to dynamically add a URL to watch
  +*      <li>add/Removedeployer, dynamically add a new deployer
  +*      <li>Changed ObjectName to JBOSs-SYSTEM realm (from EJB realm)
  +*      <li>Rewrite
  +*      </ul>
  +*/
   public interface MainDeployerMBean
      extends ServiceMBean
   {
      /** The default object name. */
  -   ObjectName OBJECT_NAME = SafeObjectNameFactory.create("jboss.system", 
  -                                                      "service", 
  -                                                      "MainDeployer");
  +   ObjectName OBJECT_NAME = SafeObjectNameFactory.create("jboss.system",
  +                                                     "service", 
  +                                                     "MainDeployer");
  +   
      
      /** individual URLs for dynamically deploying **/
      void deploy(String URL);
      void undeploy(String URL);
      
      void deploy(DeploymentInfo sdi)
  -      throws DeploymentException;
  +   throws DeploymentException;
      
      public void undeploy(DeploymentInfo sdi)
  -      throws DeploymentException;
  +   throws DeploymentException;
      
      
      /** Dynamically add directories to scan **/
  @@ -59,9 +59,9 @@
      void removeDeployer(DeployerMBean deployer);
      
      /** get all the watched URLs in this deployment **/
  -   String[] getDeployed();
  +   Collection listDeployed();
      
  -   /** Get set scan-period **/
  +   /** Get set scan-period**/
      void setScan( boolean scan);
      boolean getScan();
      void setPeriod(int period);
  
  
  
  1.7       +20 -6     jboss/src/main/org/jboss/deployment/DeploymentInfo.java
  
  Index: DeploymentInfo.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/deployment/DeploymentInfo.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DeploymentInfo.java       9 Feb 2002 16:09:17 -0000       1.6
  +++ DeploymentInfo.java       12 Feb 2002 05:41:09 -0000      1.7
  @@ -54,7 +54,7 @@
   * @author <a href="mailto:[EMAIL PROTECTED]";>David Jencks</a>
   * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Schulze</a>
   * @author <a href="mailto:[EMAIL PROTECTED]";>Christoph G. Jung</a>
  -* @version   $Revision: 1.6 $ <p>
  +* @version   $Revision: 1.7 $ <p>
   *
   *      <b>20011211 marc fleury:</b>
   *      <ul>
  @@ -89,6 +89,8 @@
      public String shortName;
      
      public long lastDeployed = 0;
  +
  +   public long lastModified = 0; //use for "should we redeploy failed"
      
      // A free form status for the "state" can be Deployed/failed etc etc
      public String status;
  @@ -222,12 +224,18 @@
      
      public void cleanup(Logger log)
      {
  -      if (!recursiveDelete(new File(localUrl.getFile())))
  -         if (log.isInfoEnabled())
  -            log.info("could not delete directory " + localUrl.toString()+" restart 
will delete it");
  +      if (localUrl == null || localUrl.equals(url)) 
  +      {
  +         log.info("not deleting localUrl, it is null or not a copy: " + localUrl);
  +      } // end of if ()
  +      else if (recursiveDelete(new File(localUrl.getFile())))
  +      {
  +         log.info("Cleaned Deployment "+url);
  +      }
         else 
  -         if (log.isInfoEnabled())
  -           log.info("Cleaned Deployment "+url);
  +      {
  +         log.info("could not delete directory " + localUrl.toString()+" restart 
will delete it");
  +      }
         
         if (!isXML)
            ServiceLibraries.getLibraries().removeClassLoader((UnifiedClassLoader) 
ucl);
  @@ -269,6 +277,12 @@
         }
         return false;
      }
  +
  +   public String toString()
  +   {
  +      return "DeploymentInfo:url=" + url;
  +   }
  +      
   }
   
   
  
  
  

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

Reply via email to