You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by rw...@apache.org on 2005/02/02 04:12:36 UTC

cvs commit: jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager WarInfusionPAM.java ApplicationServerPAM.java FileSystemPAM.java

rwatler     2005/02/01 19:12:36

  Modified:    portal/src/java/org/apache/jetspeed/tools/pamanager
                        ApplicationServerPAM.java FileSystemPAM.java
  Added:       portal/src/java/org/apache/jetspeed/tools/pamanager
                        WarInfusionPAM.java
  Log:
  War Infusion PAM Implementation
  
  Revision  Changes    Path
  1.12      +9 -5      jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/ApplicationServerPAM.java
  
  Index: ApplicationServerPAM.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/ApplicationServerPAM.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ApplicationServerPAM.java	1 Feb 2005 16:55:28 -0000	1.11
  +++ ApplicationServerPAM.java	2 Feb 2005 03:12:36 -0000	1.12
  @@ -21,6 +21,7 @@
   import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent;
   import org.apache.jetspeed.components.portletregistry.PortletRegistry;
   import org.apache.jetspeed.container.window.PortletWindowAccessor;
  +import org.apache.jetspeed.factory.PortletFactory;
   import org.apache.jetspeed.tools.pamanager.servletcontainer.ApplicationServerManager;
   import org.apache.jetspeed.util.ArgUtil;
   import org.apache.jetspeed.util.descriptor.PortletApplicationWar;
  @@ -47,16 +48,19 @@
       private boolean started;
   
       /**
  +     * ApplicationServerPAM
        * 
        * @param webAppsDir
        * @param registry
  -     * @param fsManager
        * @param entityAccess
  +     * @param windowAccess
        * @param appServerManager
  +     * @param portletCachs
  +     * @param portletFactory
        */
  -    public ApplicationServerPAM( String webAppsDir, PortletRegistry registry, PortletEntityAccessComponent entityAccess, PortletWindowAccessor windowAccess, ApplicationServerManager appServerManager, PortletCache portletCache )
  +    public ApplicationServerPAM( String webAppsDir, PortletRegistry registry, PortletEntityAccessComponent entityAccess, PortletWindowAccessor windowAccess, ApplicationServerManager appServerManager, PortletCache portletCache, PortletFactory portletFactory )
       {       
  -        super(webAppsDir, registry, entityAccess, windowAccess, portletCache, appServerManager);
  +        super(webAppsDir, registry, entityAccess, windowAccess, portletCache, portletFactory, appServerManager);
           ArgUtil.assertNotNull(ApplicationServerManager.class, appServerManager, this);
       }
   
  @@ -302,4 +306,4 @@
           }
       }
       
  -}
  \ No newline at end of file
  +}
  
  
  
  1.48      +100 -74   jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/FileSystemPAM.java
  
  Index: FileSystemPAM.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/FileSystemPAM.java,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- FileSystemPAM.java	1 Feb 2005 16:59:19 -0000	1.47
  +++ FileSystemPAM.java	2 Feb 2005 03:12:36 -0000	1.48
  @@ -34,6 +34,7 @@
   import org.apache.jetspeed.container.JetspeedPortletContext;
   import org.apache.jetspeed.container.window.PortletWindowAccessor;
   import org.apache.jetspeed.exception.RegistryException;
  +import org.apache.jetspeed.factory.PortletFactory;
   import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
   import org.apache.jetspeed.om.common.portlet.MutablePortletEntity;
   import org.apache.jetspeed.om.common.servlet.MutableWebApplication;
  @@ -80,8 +81,9 @@
       protected String webAppsDir;
       protected PortletEntityAccessComponent entityAccess;
       protected PortletWindowAccessor windowAccess;
  -    private PortletCache portletCache;
  -    private SearchEngine searchEngine;
  +    protected PortletCache portletCache;
  +    protected PortletFactory portletFactory;
  +    protected SearchEngine searchEngine;
   
       protected ApplicationServerManager appServerManager;
      
  @@ -90,6 +92,7 @@
                             PortletEntityAccessComponent entityAccess, 
                             PortletWindowAccessor windowAccess, 
                             PortletCache portletCache,
  +                          PortletFactory portletFactory,
                             ApplicationServerManager appServerManager)                          
       {
           super();
  @@ -100,6 +103,7 @@
           this.entityAccess = entityAccess;
           this.webAppsDir = webAppsDir;
           this.portletCache = portletCache;
  +        this.portletFactory = portletFactory;
           this.windowAccess = windowAccess;
           this.appServerManager = appServerManager;      
       }
  @@ -349,69 +353,55 @@
   
       }
       
  -    protected void registerApplication( PortletApplicationWar paWar ) throws PortletApplicationException,
  -            RegistryException
  +    protected void registerApplication(PortletApplicationWar paWar) throws PortletApplicationException, RegistryException
       {
  -        MutablePortletApplication app;
  -        
           String paName = paWar.getPortletApplicationName();
  -        
  +        MutablePortletApplication app = (MutablePortletApplication) registry.getPortletApplication(paName);
           try
           {
  -            app = paWar.createPortletApp();
  -
               if (app == null)
               {
  -                String msg = "Error loading portlet.xml: ";
  -                log.error(msg);
  -                throw new PortletApplicationException(msg);
  -            }
  -
  -            if (webAppsDir.indexOf(JetspeedPortletContext.LOCAL_PA_ROOT) > -1)
  -            {
  -                app.setApplicationType(MutablePortletApplication.LOCAL);
  +                app = paWar.createPortletApp();
  +                if (app == null)
  +                {
  +                    String msg = "Error loading portlet.xml: ";
  +                    log.error(msg);
  +                    throw new PortletApplicationException(msg);
  +                }
  +                if (webAppsDir.indexOf(JetspeedPortletContext.LOCAL_PA_ROOT) > -1)
  +                {
  +                    app.setApplicationType(MutablePortletApplication.LOCAL);
  +                }
  +                else
  +                {
  +                    app.setApplicationType(MutablePortletApplication.WEBAPP);
  +                }
  +                
  +                app.setChecksum(paWar.getFileSystem().getChecksum(PORTLET_XML));
  +                
  +                // load the web.xml
  +                log.info("Loading web.xml into memory...." + paName);
  +                MutableWebApplication webapp = paWar.createWebApp();
  +                paWar.validate();
  +                app.setWebApplicationDefinition(webapp);
  +                
  +                // register the portlet application
  +                registerPortletApplication(app, paName, paWar);
               }
               else
               {
  -                app.setApplicationType(MutablePortletApplication.WEBAPP);
  -            }
  -            
  -            app.setChecksum(paWar.getFileSystem().getChecksum(PORTLET_XML));
  -
  -            // load the web.xml
  -            log.info("Loading web.xml into memory....");
  -            MutableWebApplication webapp = paWar.createWebApp();
  -            paWar.validate();
  -            app.setWebApplicationDefinition(webapp);
  -
  -            // save it to the registry
  -            log.info("Saving the portlet.xml in the registry...");
  -         
  -            if(registry.namedPortletApplicationExists(app.getName()))
  -            {
  -                log.warn("Deployment has found an app with the application name, "+app.getName()+
  -                        ".  The existing app will be removed in favor of this one.");
  -                undeploy(paWar);
  -            }
  -            registry.registerPortletApplication(app);
  -            log.info("Committing registry changes...");
  -            
  -            
  -            if(searchEngine != null)
  -            {
  -                searchEngine.add(app);
  -                searchEngine.add(app.getPortletDefinitions());
  +                // complete registration of the the portlet application
  +                registerPortletApplication(app, paName, paWar);         
               }
           }
           catch (Exception e)
           {
               String msg = "Unable to register portlet application, " + paName + ", through the portlet registry: "
  -                    + e.toString();
  +                + e.toString();
               log.error(msg, e);
               
               throw new RegistryException(msg, e);
           }
  -
       }
   
       protected void rollback( int nState, PortletApplicationWar paWar, MutablePortletApplication app )
  @@ -504,7 +494,7 @@
       {
           if (webAppPath != null)
           {
  -            return webAppsDir + webAppPath;
  +            return webAppsDir + "/" + webAppPath;
           }
           else
           {
  @@ -575,12 +565,12 @@
       
   
       public boolean registerPortletApplication(FileSystemHelper fileSystem,
  -            String portletApplicationName) 
  +                                              String portletApplicationName) 
       throws RegistryException
       {        
           long checksum = fileSystem.getChecksum(PORTLET_XML);
           MutablePortletApplication pa = registry
  -                .getPortletApplication(portletApplicationName);
  +            .getPortletApplication(portletApplicationName);
           if (pa != null)
           {
               System.out.println("CHECKSUM from APP Server: " + checksum);
  @@ -628,25 +618,19 @@
                   log.error(msg);
                   throw new RegistryException(msg);
               }
  -
               app.setApplicationType(MutablePortletApplication.WEBAPP);
               app.setChecksum(checksum);
   
               // load the web.xml
  -            log.info("Loading web.xml into memory...."
  -                            + portletApplicationName);
  +            log.info("Loading web.xml into memory...." + paName);
               MutableWebApplication webapp = paWar.createWebApp();
               paWar.validate();
               app.setWebApplicationDefinition(webapp);
   
  -            // save it to the registry
  -            log.info("Saving the portlet.xml in the registry..."
  -                    + portletApplicationName);
  -            
  -            registry.registerPortletApplication(app);
  -            log.info("Committing registry changes..." + portletApplicationName);
  -            
  -        } catch (Exception e)
  +            // register the portlet application
  +            registerPortletApplication(app, paName, paWar);
  +        }
  +        catch (Exception e)
           {
               String msg = "Unable to register portlet application, " + paName
                       + ", through the portlet registry: " + e.toString();
  @@ -672,23 +656,15 @@
                   log.error(msg);
                   throw new RegistryException(msg);
               }
  -
               app.setApplicationType(MutablePortletApplication.WEBAPP);
  -            //app.setChecksum(checksum);
   
               // load the web.xml
  -            log.info("Loading web.xml into memory...."
  -                            + portletApplicationName);
  +            log.info("Loading web.xml into memory...." + portletApplicationName);
               MutableWebApplication webapp = createWebApp(contextName, context);
               app.setWebApplicationDefinition(webapp);
   
  -            // save it to the registry
  -            log.info("Saving the portlet.xml in the registry..."
  -                    + portletApplicationName);
  -            
  -            registry.registerPortletApplication(app);
  -            log.info("Committing registry changes..." + portletApplicationName);
  -            
  +            // register the portlet application
  +            registerPortletApplication(app, portletApplicationName, null);
           } 
           catch (Exception e)
           {
  @@ -824,10 +800,60 @@
       }
      
       /**
  +     * <p>
  +     * registerPortletApplication
  +     * </p>
  +     * 
  +     * @param app
  +     * @param paName
  +     * @param paWar
  +     * throws Exception
  +     */
  +    private void registerPortletApplication(MutablePortletApplication app, String paName, PortletApplicationWar paWar) throws Exception
  +    {
  +        // save app to the registry if not already done
  +        if (registry.getPortletApplication(paName) == null)
  +        {
  +            registry.registerPortletApplication(app);
  +            log.info("Registered the portlet app... " + paName);
  +        }
  +
  +        // validate portlet app war file descriptor
  +        // used to configure class loader: load directly
  +        // from "local" jetspeed portlet apps or from
  +        // deployed portlet app directories
  +        if ((paWar == null) || !paWar.getFileSystem().getRootDirectory().getName().startsWith("jetspeed-"))
  +        {
  +            // use expanded portlet app war file deployment directory
  +            File deploymentDirectory = new File(getDeploymentPath(paName));
  +            if (deploymentDirectory.isDirectory())
  +            {
  +                FileSystemHelper paDirectory = new DirectoryHelper(deploymentDirectory);
  +                paWar = new PortletApplicationWar(paDirectory, paName, "/" + paName);
  +            }
  +            else
  +            {
  +                throw new RuntimeException("Unable to configure class loader: missing portlet app deployment directory for " + paName);
  +            }
  +        }
  +        // create and register class loader for portlet app
  +        portletFactory.addClassLoader(app.getId().toString(), paWar.createClassloader(getClass().getClassLoader()));
  +        log.info("Registered portlet app in the class loader registry... " + paName);
  +
  +        // add to search engine result
  +        if (searchEngine != null)
  +        {
  +            searchEngine.add(app);
  +            searchEngine.add(app.getPortletDefinitions());
  +            log.info("Registered portlet app in the search engine... " + paName);
  +        }
  +    }
  +
  +    /**
        * @param searchEngine The searchEngine to set.
        */
       public void setSearchEngine(SearchEngine searchEngine)
       {
           this.searchEngine = searchEngine;
       }
  -}
  \ No newline at end of file
  +}
  
  
  
  1.1                  jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/WarInfusionPAM.java
  
  Index: WarInfusionPAM.java
  ===================================================================
  /*
   * Copyright 2000-2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.tools.pamanager;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.io.InputStream;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import java.util.jar.JarEntry;
  import java.util.jar.JarInputStream;
  import java.util.jar.JarOutputStream;
  import java.util.jar.Manifest;
  
  import javax.servlet.ServletContext;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.jetspeed.cache.PortletCache;
  import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent;
  import org.apache.jetspeed.components.portletregistry.PortletRegistry;
  import org.apache.jetspeed.container.window.PortletWindowAccessor;
  import org.apache.jetspeed.exception.RegistryException;
  import org.apache.jetspeed.factory.PortletFactory;
  import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
  import org.apache.jetspeed.tools.deploy.Deploy;
  import org.apache.jetspeed.tools.deploy.DeployFactory;
  import org.apache.jetspeed.tools.pamanager.servletcontainer.ApplicationServerManager;
  import org.apache.jetspeed.util.DirectoryHelper;
  import org.apache.jetspeed.util.FileSystemHelper;
  import org.apache.jetspeed.util.descriptor.PortletApplicationWar;
  
  /**
   * This is a test implementation of the deploy-tool based WAR file infusion
   * using JetspeedContainerServlet registration to deploy and undeploy Portlet
   * Applications.
   * 
   * @version $Id: WarInfusionPAM.java,v 1.1 2005/02/02 03:12:36 rwatler Exp $
   */
  
  public class WarInfusionPAM extends FileSystemPAM implements PortletApplicationManagement, DeploymentRegistration
  {
      protected static final Log log = LogFactory.getLog("deployment");
  
      private File tempDirectory;
      private boolean deployExpandedWars;
      private DeployFactory deployFactory;
  
      /**
       * WarInfusionPAM
       *
       * @param webAppsDir
       * @param registry
       * @param entityAccess
       * @param windowAccess
       * @param portletCache
       * @param portletFactory
       * @param deployFactory
       */
      public WarInfusionPAM(String webAppsDir, PortletRegistry registry, PortletEntityAccessComponent entityAccess, PortletWindowAccessor windowAccess, PortletCache portletCache, PortletFactory portletFactory, DeployFactory deployFactory)
      {
          // construct base FileSystemPAM implementation
          super(webAppsDir, registry, entityAccess, windowAccess, portletCache, portletFactory, new ApplicationServerManagerStub());
  
          // deploy factory component
          this.deployFactory = deployFactory;
  
          // configure temporary directory used in deployment
          this.tempDirectory = new File(System.getProperty("java.io.tmpdir"), "jetspeed-WarInfusionPAM");
          if (!this.tempDirectory.isDirectory())
          {
              this.tempDirectory.mkdirs();
          }
          this.tempDirectory.deleteOnExit();
  
          // determine if other context.xml files exist in
          // deployment directory, (this assumes that jetspeed
          // itself will deploy with a context file), to
          // choose expanded or war file deployment
          File [] deployedFiles = (new File(webAppsDir)).listFiles();
          for (int i = 0; ((i < deployedFiles.length) && !this.deployExpandedWars); i++)
          {
              String deployedFileName = deployedFiles[i].getName();
              if (deployedFileName.endsWith(".xml"))
              {
                  String deployedWebAppName = deployedFileName.substring(0, deployedFileName.length() - 4);
                  for (int j = 0; ((j < deployedFiles.length) && !this.deployExpandedWars); j++)
                  {
                      if (deployedFiles[j].getName().equals(deployedWebAppName))
                      {
                          this.deployExpandedWars = true;
                      }
                  }
              }
          }
      }
  
      /**
       * WarInfusionPAM
       *
       * @param webAppsDir
       * @param registry
       * @param entityAccess
       * @param windowAccess
       * @param portletCache
       * @param portletFactory
       * @param deployExpandedWars
       */
      public WarInfusionPAM(String webAppsDir, PortletRegistry registry, PortletEntityAccessComponent entityAccess, PortletWindowAccessor windowAccess, PortletCache portletCache, PortletFactory portletFactory, DeployFactory deployFactory, boolean deployExpandedWars)
      {
          // construct base WarInfusionPAM implementation,
          // overriding deploy expanded wars configuration
          this(webAppsDir, registry, entityAccess, windowAccess, portletCache, portletFactory, deployFactory);
          this.deployExpandedWars = deployExpandedWars;
      }
  
      /**
       * Registers a portlet app deployed at the specified file system location
       * 
       * @see org.apache.jetspeed.tools.pamanager.PortletApplicationManagement#registerPortletApplication(org.apache.jetspeed.util.FileSystemHelper, java.lang.String)
       * @param fileSystem The deployed portlet application location
       * @param paName The name of the portlet application to be registered
       * @throws RegistryException
       */
      public boolean registerPortletApplication(FileSystemHelper fileSystem, String paName) throws RegistryException
      {
          // cross context invocation expected: explicitly manage class loaders
          ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader();
          ClassLoader thisClassLoader = getClass().getClassLoader();
          try
          {
              // localize class loader
              if (threadClassLoader != thisClassLoader)
              {
                  Thread.currentThread().setContextClassLoader(thisClassLoader);
              }
  
              // invoke base FileSystemPAM implementation
              return super.registerPortletApplication(fileSystem, paName);
          }
          finally
          {
              // restore class loader
              if (threadClassLoader != thisClassLoader)
              {
                  Thread.currentThread().setContextClassLoader(threadClassLoader);
              }
          }
      }
      
      /**
       * Registers a deployed portlet app
       * 
       * @see org.apache.jetspeed.tools.pamanager.PortletApplicationManagement#registerPortletApplication(java.lang.String, java.lang.String, javax.servlet.ServletContext)
       * @param paName The name of the portlet application to be registered
       * @param contextName The deployed portlet context name
       * @param context The deployed portlet servlet context
       * @throws RegistryException
       */
      public boolean registerPortletApplication(String paName, String contextName, ServletContext context) throws RegistryException
      {
          // cross context invocation expected: explicitly manage class loaders
          ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader();
          ClassLoader thisClassLoader = getClass().getClassLoader();
          try
          {
              // localize class loader
              if (threadClassLoader != thisClassLoader)
              {
                  Thread.currentThread().setContextClassLoader(thisClassLoader);
              }
  
              // invoke base FileSystemPAM implementation
              return super.registerPortletApplication(paName, contextName, context);
          }
          finally
          {
              // restore class loader
              if (threadClassLoader != thisClassLoader)
              {
                  Thread.currentThread().setContextClassLoader(threadClassLoader);
              }
          }
      }
  
      /**
       * Deploys the specified war file to the webapps directory specified.
       * 
       * @see org.apache.jetspeed.tools.pamanager.Deployment#deploy(org.apache.jetspeed.util.descriptor.PortletApplicationWar)
       * @param paWar PortletApplicationWar to deploy
       * @throws PortletApplicationException
       */
      public void deploy(PortletApplicationWar paWar) throws PortletApplicationException
      {
          // invoke base FileSystemPAM implementation
          super.deploy(paWar);
      }
      
      /**
       * Undeploys application.
       * 
       * @see org.apache.jetspeed.tools.pamanager.Deployment#undeploy(org.apache.jetspeed.util.descriptor.PortletApplicationWar)
       * @param paWar PortletApplicationWar to undeploy
       * @throws PortletApplicationException
       */
      public void undeploy(PortletApplicationWar paWar) throws PortletApplicationException
      {
          // invoke base FileSystemPAM implementation
          super.undeploy(paWar);
  
          // undeploy portlet app from webapps container
          // deployment directory as atomically as possible
          String paName = paWar.getPortletApplicationName();
          File deployPortletAppDirectory = new File(webAppsDir + "/" + paName);
          File deployPortletAppWarFile = new File(webAppsDir + "/" + paName + ".war");
          File deployPortletAppContextFile = new File(webAppsDir + "/" + paName + ".xml");
          deployPortletAppWarFile.delete();
          deployPortletAppContextFile.delete();
          deleteDirectory(deployPortletAppDirectory);
          if (!deployPortletAppContextFile.exists() && !deployPortletAppDirectory.exists() && !deployPortletAppWarFile.exists())
          {
              log.info("Portlet application undeployment from " + deployPortletAppWarFile.getAbsolutePath() + " complete.");
          }
          else
          {
              log.error("Portlet application undeployment from " + deployPortletAppWarFile.getAbsolutePath() + " failed, unable to undeploy.");
          }
      }
          
      /**
       * Redeploys application.
       * 
       * @see org.apache.jetspeed.tools.pamanager.Deployment#redeploy(org.apache.jetspeed.util.descriptor.PortletApplicationWar)
       * @param paWar PortletApplicationWar to undeploy
       * @throws PortletApplicationException
       */
      public void redeploy(PortletApplicationWar paWar) throws PortletApplicationException
      {
          // invoke base FileSystemPAM implementation
          super.redeploy(paWar);
      }
  
      /**
       * Get deployment path for a portlet application.
       * 
       * @see org.apache.jetspeed.tools.pamanager.Deployment#getDeploymentPath(java.lang.String)
       * @param paName  The name of the portlet application to locate
       * @throws PortletApplicationException
       */
      public String getDeploymentPath(String paName)
      {
          // invoke base FileSystemPAM implementation
          return super.getDeploymentPath(paName);
      }
  
      /**
       * Register a portlet application into the registry.
       * 
       * @see org.apache.jetspeed.tools.pamanager.Registration#register(org.apache.jetspeed.util.descriptor.PortletApplicationWar)
       * @param paWar PortletApplicationWar to register
       * @throws PortletApplicationException
       */
      public void register(PortletApplicationWar paWar) throws PortletApplicationException
      {
          // invoke base FileSystemPAM implementation
          super.register(paWar);
      }
          
      /**
       * Unregister a portlet application from the registry.
       * 
       * @see org.apache.jetspeed.tools.pamanager.Registration#unregister(java.lang.String)
       * @param paName The name of the portlet application to be unregistered
       * @throws PortletApplicationException
       */
      public void unregister(String paName) throws PortletApplicationException
      {
          // invoke base FileSystemPAM implementation
          super.unregister(paName);
      }
  
      /**
       * FileSystemPAM deployment protocol implementation: infuse
       * JetspeedContainerServlet and other edits into war file before
       * deploying and rely on servlet to register application asynchronously
       * 
       * @param paWar PortletApplicationWar to deploy
       * @param startState deployment state
       * @throws PortletApplicationException
       */
      protected void sysDeploy(PortletApplicationWar paWar, int startState) throws PortletApplicationException
      {
          int nState = 0;
          MutablePortletApplication app = null;
          String paName = paWar.getPortletApplicationName();
          try
          {
              // stepwise deployment states:
              // 0 Initial state
              // 1 Archive deployed
              // 2 WEB XML updated
              // 3 Registry updated
  
              // infuse and deploy portlet app war if required
              nState = DEPLOY_WAR;
              if (startState <= nState)
              {
                  // infuse and copy portlet app war file to container
                  // webapps directory
                  File sourcePortletAppWarFile = paWar.getFileSystem().getRootDirectory();
                  File deployPortletAppDirectory = new File(webAppsDir + "/" + paName);
                  File deployPortletAppWarFile = new File(webAppsDir + "/" + paName + ".war");
                  File deployPortletAppContextFile = new File(webAppsDir + "/" + paName + ".xml");
                  log.info("Portlet application deploying from " + sourcePortletAppWarFile.getAbsolutePath() + " to " + deployPortletAppWarFile.getAbsolutePath() + " ...");
                  File tempSourcePortletAppWarFile = null;
                  String sourcePortletAppWar = null;
                  if (sourcePortletAppWarFile.isDirectory())
                  {
                      // war file is expanded directory, create temporary war file
                      tempSourcePortletAppWarFile = new File(tempDirectory, sourcePortletAppWarFile.getName() + ".jar-" + getUniqueId());
                      try
                      {
                          Map warFiles = new HashMap();
                          List warFilePaths = new ArrayList();
                          File [] rootWarFiles = sourcePortletAppWarFile.listFiles();
                          for (int i = 0; (i < rootWarFiles.length); i++)
                          {
                              addToWarFile(rootWarFiles[i], "", warFiles, warFilePaths); 
                          }
  
                          Manifest tempWarManifest = null;
                          File tempWarManifestFile = (File) warFiles.get("META-INF/MANIFEST.MF");
                          if (tempWarManifestFile != null)
                          {
                              tempWarManifest = new Manifest(new FileInputStream(tempWarManifestFile));
                          }
                          else
                          {
                              tempWarManifest = new Manifest();
                          }
                          warFiles.remove("META-INF/MANIFEST.MF");
                          warFilePaths.remove("META-INF/MANIFEST.MF");
  
                          JarOutputStream tempWar = new JarOutputStream(new FileOutputStream(tempSourcePortletAppWarFile), tempWarManifest);
                          byte[] buffer = new byte[1024];
                          int bytesRead;
                          Iterator filePathsIter = warFilePaths.iterator();
                          while (filePathsIter.hasNext())
                          {
                              String path = (String)filePathsIter.next();
                              JarEntry entry = new JarEntry(path);
                              File file = (File)warFiles.get(path);
                              if (file != null)
                              {
                                  entry.setSize(file.length());
                                  entry.setTime(file.lastModified());
                                  tempWar.putNextEntry(entry);
                                  FileInputStream read = new FileInputStream(file);
                                  while ((bytesRead = read.read(buffer)) != -1)
                                  {
                                      tempWar.write(buffer, 0, bytesRead);
                                  }
                                  read.close();
                              }
                              else
                              {
                                  tempWar.putNextEntry(entry);
                              }
                              tempWar.closeEntry();
                          }
                          tempWar.close();
                      }
                      catch (Exception e)
                      {
                          log.error("Unable to create temporary war file", e);
                      }
                      sourcePortletAppWar = tempSourcePortletAppWarFile.getAbsolutePath();
                  }
                  else
                  {
                      sourcePortletAppWar = sourcePortletAppWarFile.getAbsolutePath();
                  }
  
                  // infuse JetspeedContainerServlet web.xml, portlet.xml,
                  // portlet.tld, and context.xml into portlet app war file;
                  // note that name of source file must match name of
                  // destination war
                  File tempDeployPortletAppWarFile = new File(tempDirectory, deployPortletAppWarFile.getName() + "-" + getUniqueId());
                  Deploy warInfuser = deployFactory.getInstance(sourcePortletAppWar, tempDeployPortletAppWarFile.getAbsolutePath(), true);
                  if (tempSourcePortletAppWarFile != null)
                  {
                      tempSourcePortletAppWarFile.delete();
                  }
  
                  // extract context.xml and portlet app directory for deployment
                  // if deploying expanded war files
                  File tempDeployPortletAppContextFile = null;
                  File tempDeployPortletAppDirectory = null;                
                  if (deployExpandedWars)
                  {
                      // expand portlet app directory
                      tempDeployPortletAppDirectory = new File(tempDirectory, deployPortletAppDirectory.getName() + "-" + getUniqueId());
                      byte[] buffer = new byte[1024];
                      int bytesRead;
                      JarInputStream tempWar = new JarInputStream(new FileInputStream(tempDeployPortletAppWarFile));
                      JarEntry entry = null;
                      while ((entry = tempWar.getNextJarEntry()) != null) 
                      {
                          File writeFile = new File(tempDeployPortletAppDirectory, entry.getName());
                          if (!entry.getName().endsWith("/"))
                          {
                              writeFile.getParentFile().mkdirs();
                              FileOutputStream write = new FileOutputStream(writeFile);
                              while ((bytesRead = tempWar.read(buffer)) != -1)
                              {
                                  write.write(buffer, 0, bytesRead);
                              }
                              write.close();
                          }
                          else
                          {
                              writeFile.mkdirs();
                          }
                      }
                      tempWar.close();
  
                      // copy portlet app context.xml
                      File contextXmlFile = new File(tempDeployPortletAppDirectory, "META-INF/context.xml");
                      if (contextXmlFile.exists())
                      {
                          tempDeployPortletAppContextFile = new File(tempDirectory, deployPortletAppContextFile.getName() + "-" + getUniqueId());
                          FileInputStream read = new FileInputStream(contextXmlFile);
                          FileOutputStream copy = new FileOutputStream(tempDeployPortletAppContextFile);
                          while ((bytesRead = read.read(buffer)) != -1)
                          {
                              copy.write(buffer, 0, bytesRead);
                          }
                          copy.close();
                          read.close();
                      }
                          
                      // delete expanded portlet app war file
                      tempDeployPortletAppWarFile.delete();
                      tempDeployPortletAppWarFile = null;
                  }
  
                  // undeploy any existing artifacts; move new portlet app
                  // context and expanded war file or war file into webapps
                  // container deployment directory as atomically as possible
                  deployPortletAppWarFile.delete();
                  deployPortletAppContextFile.delete();
                  deleteDirectory(deployPortletAppDirectory);
                  if (!deployPortletAppContextFile.exists() && !deployPortletAppDirectory.exists() && !deployPortletAppWarFile.exists())
                  {
                      if (tempDeployPortletAppWarFile != null)
                      {
                          // deploy portlet app war file
                          tempDeployPortletAppWarFile.renameTo(deployPortletAppWarFile);
                          if (deployPortletAppWarFile.exists())
                          {
                              log.info("Portlet application deployment to " + deployPortletAppWarFile.getAbsolutePath() + " complete.");
                          }
                          else
                          {
                              log.error("Portlet application deployment to " + deployPortletAppWarFile.getAbsolutePath() + " failed, unable to deploy.");
                          }
                      }
                      else if ((tempDeployPortletAppContextFile != null) && (tempDeployPortletAppDirectory != null))
                      {
                          // deploy portlet app context.xml and expanded war file directory
                          tempDeployPortletAppContextFile.renameTo(deployPortletAppContextFile);
                          tempDeployPortletAppDirectory.renameTo(deployPortletAppDirectory);
                          if (deployPortletAppContextFile.exists() && deployPortletAppDirectory.exists())
                          {
                              log.info("Expanded portlet application deployment to " + deployPortletAppContextFile.getAbsolutePath() + " and " + deployPortletAppDirectory.getAbsolutePath() + " complete.");
                          }
                          else
                          {
                              deployPortletAppContextFile.delete();
                              deleteDirectory(deployPortletAppDirectory);
                              log.error("Expanded portlet application deployment to " + deployPortletAppContextFile.getAbsolutePath() + " and " + deployPortletAppDirectory.getAbsolutePath() + " failed, unable to deploy.");
                          }
                      }
                      else if (tempDeployPortletAppDirectory != null)
                      {
                          // deploy portlet app expanded war file directory
                          tempDeployPortletAppDirectory.renameTo(deployPortletAppDirectory);
                          if (deployPortletAppDirectory.exists())
                          {
                              log.info("Expanded portlet application deployment to " + deployPortletAppDirectory.getAbsolutePath() + " complete.");
                          }
                          else
                          {
                              log.error("Expanded portlet application deployment to " + deployPortletAppDirectory.getAbsolutePath() + " failed, unable to deploy.");
                          }
                      }
                  }
                  else
                  {
                      log.error("Portlet application deployment to " + deployPortletAppWarFile.getAbsolutePath() + ", " + deployPortletAppContextFile.getAbsolutePath() + ", and/or " + deployPortletAppDirectory.getAbsolutePath() + " failed, unable to undeploy.");
                  }
  
                  // do not complete registration synchronously: infused
                  // JetspeedContainerServlet will register when webapp
                  // is auto/live deployed in container.
                  return;
              }
  
              // register portlet app if required
              nState = UPDATE_REGISTRY;
              if (startState <= nState)
              {
                  // register portlet app in place
                  log.info("Portlet application registration target is " + paWar.getPortletApplicationName() + " ...");
                  registerApplication(paWar);
                  app = (MutablePortletApplication) registry.getPortletApplication(paName);
                  log.info("Portlet application registration of " + paWar.getPortletApplicationName() + " complete.");
              }
          }
          catch (PortletApplicationException pae)
          {
              log.error("PortletApplicationException encountered deploying portlet application: " + pae.toString() + " attempting rollback...", pae);
              rollback(nState, paWar, app);
              throw pae;
          }
          catch (Throwable t)
          {
              log.error("Unexpected exception deploying portlet application: " + t.toString() + " attempting rollback...", t);
              rollback(nState, paWar, app);
              throw new PortletApplicationException(t);
          }
          finally
          {
              if (paWar != null)
              {
                  try
                  {
                      paWar.close();
                  }
                  catch (IOException e)
                  {
  
                  }
              }
          }
      }
  
      /**
       * FileSystemPAM deployment protocol implementation: drop class loader
       * 
       * @param paName portlet app name to unregister
       * @param purgeEntityInfo delete flag
       * @throws PortletApplicationException
       */
      protected void doUnregister(String paName, boolean purgeEntityInfo) throws PortletApplicationException
      {
          // invoke base FileSystemPAM implementation
          super.doUnregister(paName, purgeEntityInfo);
      }
  
      /**
       * deleteDirectory
       *
       * @param directory
       */
      private boolean deleteDirectory(File directory)
      {
          // move to tempDirectory if possible and delete
          if (directory.isDirectory())
          {
              File delete = new File(tempDirectory, directory.getName() + ".delete-" + getUniqueId());
              if (directory.renameTo(delete))
              {
                  return (new DirectoryHelper(delete)).remove();
              }
              return (new DirectoryHelper(directory)).remove();
          }
          return directory.delete();
      }
  
      /**
       * getUniqueId - used for temporary file creation
       *
       * @return new unique id
       */
      private static long uniqueId = System.currentTimeMillis();
      private synchronized static long getUniqueId()
      {
          return uniqueId++;
      }
  
      /**
       * addToWarFile - recursively add a file system directory
       * of files to a list and map of File objects to be added
       * to a war file archive
       *
       * @param file
       * @param path
       * @param warFiles
       * @param warFilePaths
       */
      private static void addToWarFile(File file, String path, Map warFiles, List warFilePaths)
      {
          if (file.isDirectory())
          {
              String dirPath = path + file.getName() + "/" ;
              File [] files = file.listFiles();
              for (int i = 0; (i < files.length); i++)
              {
                  addToWarFile(files[i], dirPath, warFiles, warFilePaths); 
              }
              warFilePaths.add(dirPath);
          }
          else
          {
              String filePath = path + file.getName();
              warFiles.put(filePath, file);
              warFilePaths.add(filePath);
          }
      } 
  
      /**
       * ApplicationServerManager stub implementation
       */
      private static class ApplicationServerManagerStub implements ApplicationServerManager
      {
          public String start(String appPath) {return null;}
          public String stop(String appPath) {return null;}
          public String reload(String appPath) {return null;}
          public String remove(String appPath) {return null;}
          public String install(String warPath, String contexPath) {return null;}
          public String deploy(String appPath, InputStream is, int size) {return null;}
          public int getHostPort() {return -1;}
          public String getHostUrl() {return null;}
          public boolean isConnected() {return true;}
          public String getAppServerTarget(String appName) {return appName;}
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org