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 we...@apache.org on 2004/06/23 20:41:26 UTC

cvs commit: jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl CatalinaAutoDeploymentServiceImpl.java DeployPortletAppEventListener.java

weaver      2004/06/23 11:41:26

  Modified:    portal/src/java/org/apache/jetspeed/deployment/impl
                        CatalinaAutoDeploymentServiceImpl.java
                        DeployPortletAppEventListener.java
  Log:
  removed usage of "Jetspeed" object and use dep injection instead
  
  Revision  Changes    Path
  1.9       +53 -34    jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/CatalinaAutoDeploymentServiceImpl.java
  
  Index: CatalinaAutoDeploymentServiceImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/CatalinaAutoDeploymentServiceImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- CatalinaAutoDeploymentServiceImpl.java	18 Jun 2004 20:47:37 -0000	1.8
  +++ CatalinaAutoDeploymentServiceImpl.java	23 Jun 2004 18:41:26 -0000	1.9
  @@ -11,19 +11,19 @@
   import java.net.Socket;
   import java.net.UnknownHostException;
   import java.util.HashMap;
  +import java.util.Locale;
   import java.util.Map;
   
   import org.apache.commons.configuration.Configuration;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.apache.fulcrum.InitializationException;
  -import org.apache.jetspeed.cps.BaseCommonService;
  -import org.apache.jetspeed.deployment.AutoDeploymentService;
  +import org.apache.jetspeed.components.portletregistry.PortletRegistryComponent;
   import org.apache.jetspeed.deployment.DeploymentEventDispatcher;
   import org.apache.jetspeed.deployment.fs.FileSystemScanner;
   import org.apache.jetspeed.deployment.fs.JARObjectHandlerImpl;
   import org.apache.jetspeed.tools.pamanager.CatalinaPAM;
   import org.apache.jetspeed.tools.pamanager.PortletApplicationManagement;
  +import org.picocontainer.Startable;
   
   /**
    * <p>
  @@ -34,49 +34,65 @@
    * @version $Id$
    *
    */
  -public class CatalinaAutoDeploymentServiceImpl extends BaseCommonService implements AutoDeploymentService
  +public class CatalinaAutoDeploymentServiceImpl implements Startable
   {
       protected Log log = LogFactory.getLog("deployment");
   
       protected FileSystemScanner scanner;
   
  +    protected Configuration conf;
  +
  +    protected Locale defaultLocale;
  +
  +    protected PortletRegistryComponent registry;
  +
  +    protected PortletApplicationManagement pam;
  +    
  +    public CatalinaAutoDeploymentServiceImpl(Configuration conf, Locale defaultLocale, PortletRegistryComponent registry, PortletApplicationManagement pam)
  +    {
  +        this.conf = conf;
  +        this.defaultLocale = defaultLocale;
  +        this.registry = registry;
  +        this.pam = pam; 
  +    }
  +
       /**
        * @see org.apache.fulcrum.Service#init()
        */
  -    public void init() throws InitializationException
  +    public void start() 
       {
  -        Configuration conf = getConfiguration();
  +       
           log.info("Starting auto deployment service: " + getClass().getName());
  -        long delay = conf.getLong("delay", 10000);
  +        long delay = conf.getLong("autodeployment.delay", 10000);
           log.info("Deployment scanning delay: " + delay);
   
  -        String server = conf.getString("server", "localhost");
  +        String server = conf.getString("autodeployment.server", "localhost");
           log.info("Deployment server: " + server);
  -        int port = conf.getInt("port", 8080);
  +        int port = conf.getInt("autodeployment.port", 8080);
           log.info("Deployment server port: " + port);
  -        String userName = conf.getString("user");
  +        String userName = conf.getString("autodeployment.user");
           log.info("Deployment server user name: " + userName);
  -        String password = conf.getString("password");
  -        String stagingDir = conf.getString("staging.dir", "WEB-INF/deploy");
  +        String password = conf.getString("autodeployment.password");
  +        String stagingDir = conf.getString("autodeployment.staging.dir", "${applicationRoot}/WEB-INF/deploy");
           log.info("Deployment staging directory: " + stagingDir);
  -        String targetDir = conf.getString("target.dir", "../");
  +        String targetDir = conf.getString("autodeployment.target.dir", "${applicationRoot}/../");
           log.info("Deployment target directory: " + targetDir);
   
  -        File stagingDirFile = new File(getRealPath(stagingDir));
  -        File targetDirFile = new File(getRealPath(targetDir));
  +        File stagingDirFile = new File(stagingDir);
  +        File targetDirFile = new File(targetDir);
           if (!targetDirFile.exists())
           {
               log.error(targetDirFile.getAbsolutePath() + " does not exist, auto deployment disabled.");
  -            setInit(false);
  -            shutdown();
  +            
  +            stop();
               return;
           }
   
           if (!stagingDirFile.exists())
           {
               log.error(targetDirFile.getAbsolutePath() + " does not exist, auto deployment disabled.");
  -            setInit(false);
  -            shutdown();
  +            
  +            stop();
               return;
           }
   
  @@ -87,16 +103,14 @@
           }
           catch (UnknownHostException e1)
           {
  -        	log.warn("Unknown server, auto deployment will be disabled: " + e1.toString());
  -            setInit(false);
  -            shutdown();
  +        	log.warn("Unknown server, auto deployment will be disabled: " + e1.toString());            
  +            stop();
               return;
           }
           catch (IOException e1)
           {
               log.warn("IOException, auto deployment will be disabled: " + e1.toString());
  -            setInit(false);
  -            shutdown();
  +            stop();
               return;
           }
           finally
  @@ -117,8 +131,7 @@
   
           try
           {
  -            String deployerClass = conf.getString("deployer", "org.apache.jetspeed.pamanager.CatalinaPAM");
  -            PortletApplicationManagement pam = (PortletApplicationManagement)Class.forName(deployerClass).newInstance();
  +           
   
               Map map = new HashMap();
               map.put(CatalinaPAM.PAM_PROPERTY_SERVER, server);
  @@ -128,7 +141,7 @@
               
               pam.connect(map);
               
  -            DeployPortletAppEventListener dpal = new DeployPortletAppEventListener(targetDirFile.getCanonicalPath(), pam);
  +            DeployPortletAppEventListener dpal = new DeployPortletAppEventListener(targetDirFile.getCanonicalPath(), pam, registry, defaultLocale);
               DeploymentEventDispatcher dispatcher = new DeploymentEventDispatcher(targetDirFile.getCanonicalPath());
               dispatcher.addDeploymentListener(dpal);
               HashMap handlers = new HashMap();
  @@ -142,23 +155,29 @@
           catch (Exception e)
           {
               log.warn("Unable to intialize Catalina Portlet Application Manager.  Auto deployment will be disabled: " + e.toString(), e);
  -            setInit(false);
  -            shutdown();
  +            
  +            stop();
               return;
           }
   
       }
   
       /**
  -     * @see org.apache.fulcrum.Service#shutdown()
  +     * 
  +     * <p>
  +     * stop
  +     * </p>
  +     *
  +     * @see org.picocontainer.Startable#stop()
  +     *
        */
  -    public void shutdown()
  +    public void stop()
       {
           if (scanner != null)
           {
               scanner.safeStop();
  -        }
  -        super.shutdown();
  +        }        
       }
   
  +   
   }
  
  
  
  1.13      +13 -10    jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/DeployPortletAppEventListener.java
  
  Index: DeployPortletAppEventListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/deployment/impl/DeployPortletAppEventListener.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- DeployPortletAppEventListener.java	11 Jun 2004 20:02:52 -0000	1.12
  +++ DeployPortletAppEventListener.java	23 Jun 2004 18:41:26 -0000	1.13
  @@ -9,11 +9,11 @@
   import java.io.File;
   import java.io.InputStream;
   import java.util.HashMap;
  +import java.util.Locale;
   import java.util.Map;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.apache.jetspeed.Jetspeed;
   import org.apache.jetspeed.cache.PortletCache;
   import org.apache.jetspeed.components.portletregistry.PortletRegistryComponent;
   import org.apache.jetspeed.deployment.DeploymentEvent;
  @@ -21,7 +21,6 @@
   import org.apache.jetspeed.deployment.DeploymentException;
   import org.apache.jetspeed.deployment.fs.FSObjectHandler;
   import org.apache.jetspeed.factory.JetspeedPortletFactory;
  -import org.apache.jetspeed.tools.pamanager.PortletApplicationException;
   import org.apache.jetspeed.tools.pamanager.PortletApplicationManagement;
   import org.apache.jetspeed.util.descriptor.PortletApplicationWar;
   import org.apache.pluto.om.portlet.PortletApplicationDefinition;
  @@ -45,13 +44,17 @@
       private String webAppDir;
       private  PortletApplicationManagement pam;
       private Map appNameToFile;
  +    protected PortletRegistryComponent registry;
  +    protected Locale defaultLocale;
   
   
  -    public DeployPortletAppEventListener(String webAppDir, PortletApplicationManagement pam)
  +    public DeployPortletAppEventListener(String webAppDir, PortletApplicationManagement pam, PortletRegistryComponent registry, Locale defaultLocale)
       {
           this.webAppDir = webAppDir;
           this.pam = pam;
   		this.appNameToFile = new HashMap();
  +		this.registry = registry;
  +		this.defaultLocale = defaultLocale;
       }
   
       /**
  @@ -85,15 +88,15 @@
                           id = warFileName.substring(0, extensionIdx);
                           log.info("Application id not defined in portlet.xml so using war name "+id);
                       }
  -					PortletRegistryComponent regsitry = (PortletRegistryComponent) Jetspeed.getComponentManager().getComponent(PortletRegistryComponent.class);
  -                    if (regsitry.getPortletApplicationByIdentifier(id) != null)
  +					
  +                    if (registry.getPortletApplicationByIdentifier(id) != null)
                       {
                           log.info("Portlet application \"" + id + "\"" + " already been registered.  Skipping initial deployment.");
                           // still need to register the filename to the app name so undeploy works correctly
   						appNameToFile.put(handler.getFile().getName(), id);
   						if(isLocal)
   						{
  -						    PortletApplicationWar paWar = new PortletApplicationWar(handler.getPath(), id, "/"+id, Jetspeed.getDefaultLocale(),  id, null );
  +						    PortletApplicationWar paWar = new PortletApplicationWar(handler.getPath(), id, "/"+id, defaultLocale,  id, null );
   	                         JetspeedPortletFactory.addClassLoader(paWar.createClassloader(getClass().getClassLoader()));						    
   						}
                           return;
  @@ -105,7 +108,7 @@
                       {
                            log.info(handler.getFile().getName()+" will be registered as a local portlet applicaiton.");
                            pam.register(id, id, handler.getPath());
  -                         PortletApplicationWar paWar = new PortletApplicationWar(handler.getPath(), id, "/"+id, Jetspeed.getDefaultLocale(),  id, null );
  +                         PortletApplicationWar paWar = new PortletApplicationWar(handler.getPath(), id, "/"+id, defaultLocale,  id, null );
                            JetspeedPortletFactory.addClassLoader(paWar.createClassloader(getClass().getClassLoader()));
                       }
                       else
  @@ -145,8 +148,8 @@
                   	throw new DeploymentException(msg);
                   }
                   
  -                PortletRegistryComponent regsitry = (PortletRegistryComponent) Jetspeed.getComponentManager().getComponent(PortletRegistryComponent.class);
  -                PortletApplicationDefinition pa = regsitry.getPortletApplicationByIdentifier(paName);
  +               
  +                PortletApplicationDefinition pa = registry.getPortletApplicationByIdentifier(paName);
                   if(pa != null)
                   {
                       log.info("Removing a portlets from the PortletCache that belong to portlet application "+paName);
  
  
  

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