taylor      2004/07/22 19:43:31

  Modified:    portal/src/java/org/apache/jetspeed/tools/pamanager
                        ApplicationServerPAM.java FileSystemPAM.java
               components/registry/src/java/META-INF ojb_repository.xml
               src/schema registry-schema.xml
               commons/src/java/org/apache/jetspeed/util JarHelper.java
                        DirectoryHelper.java
               jetspeed-api/src/java/org/apache/jetspeed/util
                        FileSystemHelper.java
               jetspeed-api/src/java/org/apache/jetspeed/om/common/portlet
                        MutablePortletApplication.java
               portal/src/java/org/apache/jetspeed/util/descriptor
                        PortletApplicationWar.java
               components/registry/src/java/org/apache/jetspeed/om/portlet/impl
                        PortletApplicationDefinitionImpl.java
  Added:       commons/src/java/org/apache/jetspeed/util
                        AbstractFileSystemHelper.java
  Log:
  - added checksum field to PA for re-registration
  - refactored FileSystemHelper impls to use common Abstract
  - added checksum processing to determine if an app changed
  
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.6       +1 -72     
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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ApplicationServerPAM.java 23 Jul 2004 00:29:00 -0000      1.5
  +++ ApplicationServerPAM.java 23 Jul 2004 02:43:31 -0000      1.6
  @@ -15,20 +15,13 @@
    */
   package org.apache.jetspeed.tools.pamanager;
   
  -import java.io.IOException;
  -
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.apache.jetspeed.components.persistence.store.PersistenceStore;
   import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent;
   import org.apache.jetspeed.components.portletregistry.PortletRegistryComponent;
   import org.apache.jetspeed.container.window.PortletWindowAccessor;
  -import org.apache.jetspeed.exception.RegistryException;
  -import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
  -import org.apache.jetspeed.om.common.servlet.MutableWebApplication;
   import 
org.apache.jetspeed.tools.pamanager.servletcontainer.ApplicationServerManager;
   import org.apache.jetspeed.util.ArgUtil;
  -import org.apache.jetspeed.util.FileSystemHelper;
   import org.apache.jetspeed.util.descriptor.PortletApplicationWar;
   import org.picocontainer.Startable;
   
  @@ -293,68 +286,4 @@
           }
       }
       
  -    public boolean registerPortletApplication(FileSystemHelper fileSystem, 
  -                                              String portletApplicationName)
  -    throws RegistryException
  -    {
  -        MutablePortletApplication pa = 
  -            registry.getPortletApplication(portletApplicationName);
  -        if (pa != null)
  -        {
  -            // TODO: get the deployment date
  -            return false;
  -        }
  -        
  -        PortletApplicationWar paWar = null;
  -        try
  -        {
  -            paWar = new PortletApplicationWar(fileSystem,
  -                        portletApplicationName,
  -                        "/" + portletApplicationName);
  -        }
  -        catch (IOException e)
  -        {
  -            throw new RegistryException("Failed to create PA WAR", e);
  -        }
  -    
  -        MutablePortletApplication app;
  -        PersistenceStore store = registry.getPersistenceStore();
  -        String paName = paWar.getPortletApplicationName();
  -        
  -        try
  -        {
  -            app = paWar.createPortletApp();
  -            
  -            if (app == null)
  -            {
  -                String msg = "Error loading portlet.xml: ";
  -                log.error(msg);
  -                throw new RegistryException(msg);
  -            }
  -                        
  -            app.setApplicationType(MutablePortletApplication.WEBAPP);
  -        
  -            // load the web.xml
  -            log.info("Loading web.xml into memory...." + portletApplicationName);
  -            MutableWebApplication webapp = paWar.createWebApp();
  -            paWar.validate();
  -            app.setWebApplicationDefinition(webapp);
  -            
  -            // save it to the registry
  -            log.info("Saving the portlet.xml in the registry..." + 
portletApplicationName);
  -            store.getTransaction().begin();
  -            registry.registerPortletApplication(app);
  -            log.info("Committing registry changes..."  + portletApplicationName);
  -            store.getTransaction().commit();
  -        }
  -        catch (Exception e)
  -        {
  -            String msg = "Unable to register portlet application, " + paName + ", 
through the portlet registry: "
  -            + e.toString();
  -            log.error(msg, e);
  -            store.getTransaction().rollback();
  -            throw new RegistryException(msg, e);
  -        }
  -        return true;
  -    }    
   }
  
  
  
  1.36      +89 -6     
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.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- FileSystemPAM.java        9 Jul 2004 18:28:58 -0000       1.35
  +++ FileSystemPAM.java        23 Jul 2004 02:43:31 -0000      1.36
  @@ -27,7 +27,7 @@
   import org.apache.jetspeed.components.persistence.store.PersistenceStore;
   import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent;
   import org.apache.jetspeed.components.portletregistry.PortletRegistryComponent;
  -import org.apache.jetspeed.components.portletregistry.RegistryException;
  +import org.apache.jetspeed.exception.RegistryException;
   import org.apache.jetspeed.container.JetspeedPortletContext;
   import org.apache.jetspeed.container.window.PortletWindowAccessor;
   import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
  @@ -35,9 +35,9 @@
   import org.apache.jetspeed.om.common.servlet.MutableWebApplication;
   import org.apache.jetspeed.util.ArgUtil;
   import org.apache.jetspeed.util.DirectoryHelper;
  +import org.apache.jetspeed.util.FileSystemHelper;
   import org.apache.jetspeed.util.descriptor.PortletApplicationWar;
   import org.apache.pluto.om.entity.PortletEntity;
  -import org.apache.pluto.om.entity.PortletEntityCtrl;
   import org.apache.pluto.om.portlet.PortletDefinition;
   
   /**
  @@ -47,18 +47,21 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Roger Ruttimann </a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver </a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Matt Avery </a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor </a>
    * @version $Id$
    */
   
  -public class FileSystemPAM implements PortletApplicationManagement
  +public class FileSystemPAM implements PortletApplicationManagement, 
DeploymentRegistration
   {
       // Implementation of deplyment interface
       public final int DEPLOY_WAR = 0;
       public final int UPDATE_WEB_XML = 1;
       public final int UPDATE_REGISTRY = 2;
   
  +    private static final String PORTLET_XML = "WEB-INF/portlet.xml";
  +    
       public static final String SYS_PROPS_DEPLOY_TO_DIR = 
"org.apache.jetspeed.deploy.target.dir";
  -
  +    
       private static final Log log = LogFactory.getLog("deployment");
   
       //private DeployUtilities util;
  @@ -318,7 +321,7 @@
           MutablePortletApplication app;
           PersistenceStore store = registry.getPersistenceStore();
           String paName = paWar.getPortletApplicationName();
  -
  +        
           try
           {
               app = paWar.createPortletApp();
  @@ -338,6 +341,8 @@
               {
                   app.setApplicationType(MutablePortletApplication.WEBAPP);
               }
  +            
  +            app.setChecksum(paWar.getFileSystem().getChecksum(PORTLET_XML));
   
               // load the web.xml
               log.info("Loading web.xml into memory....");
  @@ -521,4 +526,82 @@
               throw new PortletApplicationException(e);
           }
       }
  +    
  +
  +    public boolean registerPortletApplication(FileSystemHelper fileSystem,
  +            String portletApplicationName) 
  +    throws RegistryException
  +    {
  +        long checksum = fileSystem.getChecksum(PORTLET_XML);        
  +        MutablePortletApplication pa = registry
  +                .getPortletApplication(portletApplicationName);
  +        if (pa != null)
  +        {            
  +            if (checksum == pa.getChecksum())
  +            {
  +                System.out.println("PORTLET APPLICATION REGISTRATION: NO CHANGE on 
CHECKSUM for portlet.xml: " 
  +                        + portletApplicationName);
  +                
  +                return false;
  +            }
  +            System.out.println("PORTLET APPLICATION REGISTRATION: Checksum changed 
on portlet.xml: " 
  +                                + portletApplicationName);
  +        }
  +
  +        PortletApplicationWar paWar = null;
  +        try
  +        {
  +            paWar = new PortletApplicationWar(fileSystem,
  +                    portletApplicationName, "/" + portletApplicationName);
  +        } catch (IOException e)
  +        {
  +            throw new RegistryException("Failed to create PA WAR", e);
  +        }
  +
  +        MutablePortletApplication app;
  +        PersistenceStore store = registry.getPersistenceStore();
  +        String paName = paWar.getPortletApplicationName();
  +
  +        try
  +        {
  +            app = paWar.createPortletApp();
  +
  +            if (app == null)
  +            {
  +                String msg = "Error loading portlet.xml: ";
  +                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);
  +            MutableWebApplication webapp = paWar.createWebApp();
  +            paWar.validate();
  +            app.setWebApplicationDefinition(webapp);
  +
  +            // save it to the registry
  +            log.info("Saving the portlet.xml in the registry..."
  +                    + portletApplicationName);
  +            store.getTransaction().begin();
  +            registry.registerPortletApplication(app);
  +            log.info("Committing registry changes..." + portletApplicationName);
  +            store.getTransaction().commit();
  +        } catch (Exception e)
  +        {
  +            String msg = "Unable to register portlet application, " + paName
  +                    + ", through the portlet registry: " + e.toString();
  +            log.error(msg, e);
  +            store.getTransaction().rollback();
  +            throw new RegistryException(msg, e);
  +        }
  +        return true;
  +    }    
  +
  +    
  +    
   }
  
  
  
  1.10      +6 -0      
jakarta-jetspeed-2/components/registry/src/java/META-INF/ojb_repository.xml
  
  Index: ojb_repository.xml
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/components/registry/src/java/META-INF/ojb_repository.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ojb_repository.xml        9 Jul 2004 18:16:56 -0000       1.9
  +++ ojb_repository.xml        23 Jul 2004 02:43:31 -0000      1.10
  @@ -121,6 +121,12 @@
            
         />
   
  +      <field-descriptor
  +         name="checksum"
  +         column="CHECKSUM"
  +         jdbc-type="BIGINT"
  +      />
  +
         <!--conversion="org.apache.jetspeed.util.ojb.ObjectIDtoLongFieldConversion" 
-->
   
         <field-descriptor
  
  
  
  1.17      +1 -0      jakarta-jetspeed-2/src/schema/registry-schema.xml
  
  Index: registry-schema.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/src/schema/registry-schema.xml,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- registry-schema.xml       9 Jul 2004 18:32:28 -0000       1.16
  +++ registry-schema.xml       23 Jul 2004 02:43:31 -0000      1.17
  @@ -215,6 +215,7 @@
           <column name="APP_IDENTIFIER" size="80" type="VARCHAR"/>
           <column name="VERSION" size="80" type="VARCHAR"/>
           <column name="APP_TYPE" type="INTEGER"/>
  +             <column name="CHECKSUM" type="INTEGER"/>                
           <column name="DESCRIPTION" size="80" type="VARCHAR"/>
           <column name="WEB_APP_ID" required="true" type="INTEGER"/>
           <unique name="UK_APPLICATION">
  
  
  
  1.3       +5 -1      
jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/util/JarHelper.java
  
  Index: JarHelper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/util/JarHelper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JarHelper.java    15 Jul 2004 20:41:54 -0000      1.2
  +++ JarHelper.java    23 Jul 2004 02:43:31 -0000      1.3
  @@ -34,7 +34,11 @@
    * [EMAIL PROTECTED] DirectoryHelper}.
    *  
    */
  -public class JarHelper implements FileSystemHelper
  +public class JarHelper 
  +    extends
  +        AbstractFileSystemHelper
  +    implements 
  +        FileSystemHelper
   {
       protected JarFile jarFile;
       protected DirectoryHelper dirHelper;
  
  
  
  1.3       +8 -3      
jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/util/DirectoryHelper.java
  
  Index: DirectoryHelper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/util/DirectoryHelper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DirectoryHelper.java      15 Jul 2004 20:41:54 -0000      1.2
  +++ DirectoryHelper.java      23 Jul 2004 02:43:31 -0000      1.3
  @@ -21,15 +21,19 @@
   import java.io.FileNotFoundException;
   import java.io.FileOutputStream;
   import java.io.IOException;
  +import java.io.InputStream;
   import java.nio.channels.FileChannel;
  +import java.util.zip.CheckedInputStream;
   
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
    *
  - * TODO To change the template for this generated type comment go to
  - * Window - Preferences - Java - Code Generation - Code and Comments
    */
  -public class DirectoryHelper implements FileSystemHelper
  +public class DirectoryHelper
  +    extends
  +        AbstractFileSystemHelper
  +    implements 
  +        FileSystemHelper
   {
   
       protected File directory;
  @@ -210,4 +214,5 @@
       {       
           return getRootDirectory().getAbsolutePath();
       }
  +        
   }
  
  
  
  1.1                  
jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/util/AbstractFileSystemHelper.java
  
  Index: AbstractFileSystemHelper.java
  ===================================================================
  /*
   * Copyright 2000-2001,2004 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.util;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.util.zip.Adler32;
  import java.util.zip.CheckedInputStream;
  
  
  /**
   * implements common directory and jar operations
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor </a>
   * @version $Id: AbstractFileSystemHelper.java,v 1.1 2004/07/23 02:43:31 taylor Exp $
   */
  public abstract class AbstractFileSystemHelper
  {
      public abstract File getRootDirectory();
      
      public long getChecksum(String path)
      {
          File child = new File(getRootDirectory(), path);
          if (child == null || !child.exists())
          {
              return 0;
          }
          
          CheckedInputStream cis = null;        
          long checksum = 0;
          try 
          {
              cis = new CheckedInputStream(new FileInputStream(child), new Adler32());
              byte[] tempBuf = new byte[128];
              while (cis.read(tempBuf) >= 0) 
              {
              }
              checksum = cis.getChecksum().getValue();
          } 
          catch (IOException e) 
          {
              checksum = 0;
          }
          finally
          {
              if (cis != null)
              {
                  try
                  {
                      cis.close();
                  }
                  catch (IOException ioe)
                  {                    
                  }
              }
          }
          return checksum;
      }
  
  }
  
  
  
  1.2       +8 -0      
jakarta-jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/util/FileSystemHelper.java
  
  Index: FileSystemHelper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/util/FileSystemHelper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileSystemHelper.java     22 Jul 2004 23:38:39 -0000      1.1
  +++ FileSystemHelper.java     23 Jul 2004 02:43:31 -0000      1.2
  @@ -98,4 +98,12 @@
        */
       String getSourcePath();
       
  +    /**
  +     * Given a path to a resource in this file system, return a checksum 
  +     * on that resource's content.
  +     * 
  +     * @param pathToResource
  +     * @return checksum of the content of the resource
  +     */
  +    long getChecksum(String pathToResource);
   }
  
  
  
  1.6       +15 -1     
jakarta-jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/om/common/portlet/MutablePortletApplication.java
  
  Index: MutablePortletApplication.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/om/common/portlet/MutablePortletApplication.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MutablePortletApplication.java    6 Jul 2004 21:32:33 -0000       1.5
  +++ MutablePortletApplication.java    23 Jul 2004 02:43:31 -0000      1.6
  @@ -144,4 +144,18 @@
        * @param service The component service being added.
        */
       void addJetspeedService(JetspeedServiceReference service);
  +    
  +    /**
  +     * The checksum on the portlet XML from the last deployment
  +     *  
  +     * @param checksum
  +     */
  +    void setChecksum(long checksum);
  +    
  +    /**
  +     * The checksum on the portlet XML from the last deployment
  +     * 
  +     * @return
  +     */
  +    long getChecksum();
   }
  
  
  
  1.14      +5 -0      
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/util/descriptor/PortletApplicationWar.java
  
  Index: PortletApplicationWar.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/util/descriptor/PortletApplicationWar.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- PortletApplicationWar.java        19 Jul 2004 21:40:11 -0000      1.13
  +++ PortletApplicationWar.java        23 Jul 2004 02:43:31 -0000      1.14
  @@ -629,4 +629,9 @@
               return null;
           }
       }
  +    
  +    public FileSystemHelper getFileSystem()
  +    {
  +        return warStruct;
  +    }
   }
  
  
  
  1.15      +12 -1     
jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/om/portlet/impl/PortletApplicationDefinitionImpl.java
  
  Index: PortletApplicationDefinitionImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/om/portlet/impl/PortletApplicationDefinitionImpl.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- PortletApplicationDefinitionImpl.java     6 Jul 2004 23:31:54 -0000       1.14
  +++ PortletApplicationDefinitionImpl.java     23 Jul 2004 02:43:31 -0000      1.15
  @@ -83,6 +83,8 @@
   
       private int applicationType = MutablePortletApplication.WEBAPP;
       
  +    private long checksum = 0;
  +    
       /** Creates a new instance of BaseApplication */
       public PortletApplicationDefinitionImpl()
       {
  @@ -354,4 +356,13 @@
           services.add(service);
       }
   
  +    public long getChecksum()
  +    {
  +        return checksum;
  +    }
  +    
  +    public void setChecksum(long checksum)
  +    {
  +        this.checksum = checksum;
  +    }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to