User: mnf999  
  Date: 02/02/01 08:32:20

  Modified:    src/main/org/jboss/deployment DeploymentInfo.java
                        MainDeployer.java
  Log:
  Fix to prevent cycling on failure.
  
  A failed deployment is seen as a deployment with status "Failed" stored as a free 
string (should move to XML for that status)
  
  Revision  Changes    Path
  1.2       +4 -1      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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DeploymentInfo.java       2002/01/20 03:40:16     1.1
  +++ DeploymentInfo.java       2002/02/01 16:32:20     1.2
  @@ -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.1 $ <p>
  +* @version   $Revision: 1.2 $ <p>
   *
   *      <b>20011211 marc fleury:</b>
   *      <ul>
  @@ -89,6 +89,9 @@
      public String shortName;
      
      public long lastDeployed = 0;
  +   
  +   // A free form status for the "state" can be Deployed/failed etc etc
  +   public String status;
      
      //   public List dirs = new ArrayList();
      
  
  
  
  1.4       +99 -96    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MainDeployer.java 2002/01/30 02:32:29     1.3
  +++ MainDeployer.java 2002/02/01 16:32:20     1.4
  @@ -42,7 +42,7 @@
   * Takes a series of URL to watch, detects changes and calls the appropriate 
Deployers 
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  -* @version $Revision: 1.3 $
  +* @version $Revision: 1.4 $
   *
   *
   */
  @@ -261,17 +261,20 @@
            {
               DeploymentInfo di = (DeploymentInfo) modified.next();
               
  -            // if the url is a file that doesn't exist, it was removed -> undeploy
  -            // TODO: check connection on http protocol and see if it is removed.
  -            if (di.url.getProtocol().startsWith("file") && !new 
File(di.url.getFile()).exists())
  -            {   
  -               undeploy(di);
  -            }  
  -            // it is a deployment 
  -            else 
  -            {
  -               undeploy(di); deploy(di);
  +            try {
  +               // if the url is a file that doesn't exist, it was removed -> 
undeploy
  +               // TODO: check connection on http protocol and see if it is removed.
  +               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 ignoreIt) {log.info("exception ", ignoreIt);} 
            }
         }
         catch (Exception ignored) {log.info ("exception ", ignored);} 
  @@ -351,6 +354,7 @@
      }
      
      public void deploy(DeploymentInfo deployment) 
  +   throws DeploymentException
      {      
         try {
            // If we are already deployed return
  @@ -375,31 +379,32 @@
            // Deploy this SDI, if it is a deployable type
            if (deployment.deployer != null) deployment.deployer.deploy(deployment);
               
  -         // whether you do it or not, for the autodeployer
  -         deployment.lastDeployed = System.currentTimeMillis();
  +         deployment.status="Deployed";
            
  -         //watch it, it will be picked up as modified below, deployments is a map 
duplicates are ok
  -         //don't add if part of the directories
  -         deployments.put(deployment.url, deployment);
  -         deploymentsList.add(deployment);
  -         
  -         if (log.isDebugEnabled()) log.debug("Watching new file: " + 
deployment.url);  
  -            
            log.info("Done deploying "+deployment.shortName);
         
         }  
  -      catch (Exception e) 
  +      catch (DeploymentException e) 
         { 
            log.error("Deployment failed: "+ deployment.url,e); 
            
  +         deployment.status="Deployment FAILED reason: "+e.getMessage();
  +         
  +         throw e;
  +      }
  +      
  +      finally 
  +      {
            // whether you do it or not, for the autodeployer
            deployment.lastDeployed = System.currentTimeMillis();
            
  -         deployments.remove(deployment.url);
  -         if (deploymentsList.lastIndexOf(deployment) != -1) 
  -            deploymentsList.remove(deploymentsList.lastIndexOf(deployment));
  +         //watch it, it will be picked up as modified below, deployments is a map 
duplicates are ok
  +         //don't add if part of the directories
  +         deployments.put(deployment.url, deployment);
  +         deploymentsList.add(deployment);
  +         
  +         if (log.isDebugEnabled()) log.debug("Watching new file: " + 
deployment.url);  
            
  -         deployment.cleanup(log);
         }
      }
      
  @@ -540,81 +545,75 @@
         JarFile jarFile =null;
         
         // Then the packages inside the package being deployed
  -      try 
  -      {
  -         
  -         // marcf FIXME FIXME FIXME add support for directories not just jar files
  -         
  -         // Do we have a jar file jar:<theURL>!/..
  -         try {jarFile = ((JarURLConnection)new 
URL("jar:"+di.localUrl.toString()+"!/").openConnection()).getJarFile();}
  -            catch (Exception ignored) {return;}
  -         
  -         for (Enumeration e = jarFile.entries(); e.hasMoreElements(); )
  +      
  +      // marcf FIXME FIXME FIXME add support for directories not just jar files
  +      
  +      // Do we have a jar file jar:<theURL>!/..
  +      try {jarFile = ((JarURLConnection)new 
URL("jar:"+di.localUrl.toString()+"!/").openConnection()).getJarFile();}
  +         catch (Exception ignored) {throw new 
DeploymentException(ignored.getMessage());}
  +      
  +      for (Enumeration e = jarFile.entries(); e.hasMoreElements(); )
  +      {
  +         JarEntry entry = (JarEntry)e.nextElement();
  +         String name = entry.getName();
  +         
  +         // Everything that is not 
  +         // a- an XML file
  +         // 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"))
            {
  -            JarEntry entry = (JarEntry)e.nextElement();
  -            String name = entry.getName();
               
  -            // Everything that is not 
  -            // a- an XML file
  -            // 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"))
  +            try 
               {
  +               File localCopyDir = new 
File(System.getProperty("jboss.system.home")+File.separator+"tmp"+File.separator+"deploy");
                  
  -               try 
  -               {
  -                  File localCopyDir = new 
File(System.getProperty("jboss.system.home")+File.separator+"tmp"+File.separator+"deploy");
  -                  
  -                  // We use the name of the entry as the name of the file under 
deploy 
  -                  // (marcf note: I don't think we need the getNextID, not 
important)
  -                  File outFile = new File(localCopyDir, 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 = new URL("file:" + outFile.toString());
  -                  DeploymentInfo sub = new DeploymentInfo(subURL, di);
  -                  
  -                  // And deploy it, this call is recursive
  -                  deploy(sub);
  -               }
  -               catch (Exception e2) 
  -               { 
  -                  log.error("Error in subDeployment", e2);
  +               // We use the name of the entry as the name of the file under deploy 
  +               // (marcf note: I don't think we need the getNextID, not important)
  +               File outFile = new File(localCopyDir, name);
  +               
  +               // Copy in and out 
  +               OutputStream out = new FileOutputStream(outFile); 
  +               InputStream in = jarFile.getInputStream(entry);
  +               
  +               try { copy(in, out);}
                     
  -                  throw new DeploymentException("Could not deploy sub deployment 
"+name+" of deployment "+di.url);
  -               }
  +               finally { out.close(); }
  +               
  +               // It is a sub-deployment
  +               URL subURL = new URL("file:" + outFile.toString());
  +               DeploymentInfo sub = new DeploymentInfo(subURL, di);
  +               
  +               // And deploy it, this call is recursive
  +               deploy(sub);
               }
  +            catch (DeploymentException e3) { throw e3;} //just throw
  +            catch (Exception e2) 
  +            { 
  +               log.error("Error in subDeployment with name "+name);
  +               
  +               throw new DeploymentException("Could not deploy sub deployment 
"+name+" of deployment "+di.url);
  +            }
            }
  +         
  +         // WARNING: Do not close the jarFile let it hang until undeployment 
  +         // The reason is that if you close the jarFile you cannot open streams 
  +         // to files inside. The bug can be seen as follow 
  +         // Thread.currentThread().getContextClassLoader().getResource("a text file 
in jar").openStream())
  +         // Doesn't work while
  +         // Thread.currentThread().getContextClassLoader().loadClass("a class in 
the jar")
  +         // works
  +         // We should encapsulate "opening and closing of the jarFile" in the 
DeploymentInfo
  +         // Here we let it be open and cached
         }
  -      catch (Exception e) 
  -      {
  -         log.error("Could not open the jar file ", e); 
  -         throw new DeploymentException("Could not open jar file "+di.url);
  -      }
  -      
  -      // WARNING: Do not close the jarFile let it hang until undeployment 
  -      // The reason is that if you close the jarFile you cannot open streams 
  -      // to files inside. The bug can be seen as follow 
  -      // Thread.currentThread().getContextClassLoader().getResource("a text file in 
jar").openStream())
  -      // Doesn't work while
  -      // Thread.currentThread().getContextClassLoader().loadClass("a class in the 
jar")
  -      // works
  -      // We should encapsulate "opening and closing of the jarFile" in the 
DeploymentInfo
  -      // Here we let it be open and cached
      }
      
  +   
      protected void copy(InputStream in, OutputStream out)
      throws IOException
      {
  @@ -706,7 +705,7 @@
         in.close ();
      }
      
  -   public void parseManifestLibraries(DeploymentInfo sdi)
  +   public void parseManifestLibraries(DeploymentInfo sdi) throws DeploymentException
      {
         String classPath = null;
         
  @@ -726,10 +725,13 @@
            log.debug("resolveLibraries: "+classPath);
            while (st.hasMoreTokens())
            {
  -            String tk = st.nextToken();
  -            try
  +            URL lib = null;
  +            
  +            try 
               {
  -               URL lib = new URL(sdi.url, tk);
  +               String tk = st.nextToken();
  +               
  +               lib = new URL(sdi.url, tk);
                  
                  log.debug("new manifest entry for sdi at "+sdi.shortName+" entry is 
"+tk);
                  
  @@ -743,8 +745,9 @@
                     sdi.subDeployments.add(sub);
                  }
               }
  -            // Don't waste too much time with the manifest libraries
  -            catch (Exception ignored) {}
  +            catch (Exception ignore) { 
  +               log.error("The manifest entry in "+sdi.url+" references URL "+lib+ " 
which could not be opened, entry ignored, please fix classpath in manifest.mf");
  +            } 
            }
         }
      }   
  
  
  

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

Reply via email to