donaldp     02/05/10 08:32:14

  Modified:    src/java/org/apache/avalon/phoenix/components/deployer
                        DefaultDeployer.java Resources.properties
               src/java/org/apache/avalon/phoenix/tools/installer
                        Installer.java
  Log:
  Rework deployer so that it creates a work directory where it will store some 
temp/extracted files.
  
  Revision  Changes    Path
  1.25      +75 -2     
jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/deployer/DefaultDeployer.java
  
  Index: DefaultDeployer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/deployer/DefaultDeployer.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- DefaultDeployer.java      10 May 2002 14:16:53 -0000      1.24
  +++ DefaultDeployer.java      10 May 2002 15:32:14 -0000      1.25
  @@ -8,16 +8,20 @@
   package org.apache.avalon.phoenix.components.deployer;
   
   import java.io.File;
  +import java.io.IOException;
   import java.net.MalformedURLException;
   import java.net.URL;
  -import java.util.Map;
   import java.util.Hashtable;
  +import java.util.Map;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.avalon.framework.parameters.ParameterException;
  +import org.apache.avalon.framework.parameters.Parameterizable;
  +import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.Serviceable;
  @@ -47,7 +51,7 @@
    */
   public class DefaultDeployer
       extends AbstractLogEnabled
  -    implements Deployer, Serviceable, Initializable, DeployerMBean
  +    implements Deployer, Parameterizable, Serviceable, Initializable, 
DeployerMBean
   {
       private static final Resources REZ =
           ResourceManager.getPackageResources( DefaultDeployer.class );
  @@ -63,6 +67,39 @@
       private ClassLoaderManager m_classLoaderManager;
   
       /**
  +     * The directory which is used as the base for
  +     * extracting all temporary files from archives. It is
  +     * expected that the temporary files will be deleted when
  +     * the .sar file is undeployed.
  +     */
  +    private File m_baseWorkDirectory;
  +
  +    /**
  +     * Retrieve parameter that specifies work directory.
  +     *
  +     * @param parameters the parameters to read
  +     * @throws ParameterException if invlaid work directory
  +     */
  +    public void parameterize( final Parameters parameters )
  +        throws ParameterException
  +    {
  +        final String phoenixHome = parameters.getParameter( "phoenix.home" );
  +        final String defaultWorkDir = phoenixHome + File.separator + "work";
  +        final String rawWorkDir =
  +            parameters.getParameter( "phoenix.work.dir", defaultWorkDir );
  +
  +        final File dir = new File( rawWorkDir );
  +        try
  +        {
  +            m_baseWorkDirectory = dir.getCanonicalFile();
  +        }
  +        catch( final IOException ioe )
  +        {
  +            m_baseWorkDirectory = dir.getAbsoluteFile();
  +        }
  +    }
  +
  +    /**
        * Retrieve relevant services needed to deploy.
        *
        * @param serviceManager the ComponentManager
  @@ -80,6 +117,8 @@
       public void initialize()
           throws Exception
       {
  +        initWorkDirectory();
  +
           setupLogger( m_installer );
           setupLogger( m_assembler );
           setupLogger( m_verifier );
  @@ -155,6 +194,7 @@
       {
           try
           {
  +            //m_baseWorkDirectory
               final Installation installation = m_installer.install( location 
);
   
               final Configuration config = getConfigurationFor( 
installation.getConfig() );
  @@ -302,5 +342,38 @@
           }
   
           return false;
  +    }
  +
  +    /**
  +     * Make sure that the work directory is created and not a file.
  +     *
  +     * @throws Exception if work directory can not be created or is a file
  +     */
  +    private void initWorkDirectory()
  +        throws Exception
  +    {
  +        if( !m_baseWorkDirectory.exists() )
  +        {
  +            final String message =
  +                REZ.getString( "deploy.create-dir.notice",
  +                               m_baseWorkDirectory );
  +            getLogger().info( message );
  +
  +            if( !m_baseWorkDirectory.mkdirs() )
  +            {
  +                final String error =
  +                    REZ.getString( "deploy.workdir-nocreate.error",
  +                                   m_baseWorkDirectory );
  +                throw new Exception( error );
  +            }
  +        }
  +
  +        if( !m_baseWorkDirectory.isDirectory() )
  +        {
  +            final String message =
  +                REZ.getString( "deploy.workdir-notadir.error",
  +                               m_baseWorkDirectory );
  +            throw new Exception( message );
  +        }
       }
   }
  
  
  
  1.12      +5 -5      
jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/deployer/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/deployer/Resources.properties,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Resources.properties      10 May 2002 14:16:53 -0000      1.11
  +++ Resources.properties      10 May 2002 15:32:14 -0000      1.12
  @@ -1,10 +1,10 @@
   deploy.notice.sar.add=Adding SarEntry named "{0}" to Kernel with ClassPath = 
{1}.
   deploy.error.config.create=Error building configuration from {0}.
  -recorder.notice.rebuild.successful=Rebuilt application "{0}" installation 
digest from {1} file.
  -recorder.notice.persist.successful=Saved application "{0}" installation 
digest to {1} file.
  -recorder.warn.persist.failed=Cannot persist installation digest for {0}.
  -recorder.warn.rebuild.failed=Cannot rebuild installation digest for {0}.
   deploy.error.sar.add=Error adding component entry ({0}) to container.
   deploy.error.deploy.failed=Failed to deploy {0} from {1}.
   deploy.error.extra.config=There is no coresponding Block or Listener for 
configuration data in element "{0}".
  -deploy.no-deployment.error=No deployment by name of "{0}".
  \ No newline at end of file
  +deploy.no-deployment.error=No deployment by name of "{0}".
  +deploy.bad-workdir.error=Bad work directory "{0}" specified.
  +deploy.workdir-nocreate.error=Failed to create work directory {0}.
  +deploy.workdir-notadir.error=Work directory {0} is not a directory.
  +deploy.create-dir.notice=Work directory does not exist, attempting to create 
directory {0}.
  \ No newline at end of file
  
  
  
  1.34      +9 -4      
jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/installer/Installer.java
  
  Index: Installer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/installer/Installer.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- Installer.java    10 May 2002 15:07:30 -0000      1.33
  +++ Installer.java    10 May 2002 15:32:14 -0000      1.34
  @@ -34,7 +34,7 @@
    * and installing it as appropriate.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
  - * @version $Revision: 1.33 $ $Date: 2002/05/10 15:07:30 $
  + * @version $Revision: 1.34 $ $Date: 2002/05/10 15:32:14 $
    */
   public class Installer
       extends AbstractLogEnabled
  @@ -98,7 +98,10 @@
                       }
   
                       file.delete();
  -                    if( 0 == parent.list().length ) parent.delete();
  +                    if( 0 == parent.list().length )
  +                    {
  +                        parent.delete();
  +                    }
                   }
               }
           }
  @@ -122,7 +125,8 @@
               final File file = getFileFor( url );
               if( file.isDirectory() )
               {
  -                final String message = REZ.getString( 
"deprecated-sar-format", url );
  +                final String message =
  +                    REZ.getString( "deprecated-sar-format", url );
                   System.err.println( message );
                   getLogger().warn( message );
                   return installDeprecated( file );
  @@ -132,7 +136,8 @@
               final ZipFile zipFile = new ZipFile( file );
               if( isDeprecated( zipFile ) )
               {
  -                final String message = REZ.getString( 
"deprecated-sar-format", url );
  +                final String message =
  +                    REZ.getString( "deprecated-sar-format", url );
                   System.err.println( message );
                   getLogger().warn( message );
                   return installDeprecated( url, file, zipFile );
  
  
  

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

Reply via email to