ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adammurd...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/classloader ClassLoaderManager.java
Date Mon, 11 Mar 2002 06:02:22 GMT
adammurdoch    02/03/10 22:02:22

  Modified:    proposal/myrmidon/src/testcases/org/apache/myrmidon/components
                        AbstractComponentTest.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer
                        DefaultDeployer.java Resources.properties
               proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor
                        DefaultEmbeddor.java Resources.properties
  Added:       proposal/myrmidon/src/java/org/apache/myrmidon/components/classloader
                        DefaultClassLoaderManager.java Resources.properties
               proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/classloader
                        ClassLoaderManager.java
  Removed:     proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer
                        ClassLoaderManager.java
                        DefaultClassLoaderManager.java
  Log:
  Move ClassLoaderManager and DefaultClassLoaderManager into their own packages.
  
  Revision  Changes    Path
  1.13      +2 -2      jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/AbstractComponentTest.java
  
  Index: AbstractComponentTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/AbstractComponentTest.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- AbstractComponentTest.java	9 Mar 2002 02:04:25 -0000	1.12
  +++ AbstractComponentTest.java	11 Mar 2002 06:02:22 -0000	1.13
  @@ -18,16 +18,16 @@
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.Serviceable;
   import org.apache.myrmidon.AbstractMyrmidonTest;
  +import org.apache.myrmidon.components.classloader.DefaultClassLoaderManager;
   import org.apache.myrmidon.components.configurer.DefaultConfigurer;
   import org.apache.myrmidon.components.converter.DefaultConverterRegistry;
   import org.apache.myrmidon.components.converter.DefaultMasterConverter;
  -import org.apache.myrmidon.components.deployer.ClassLoaderManager;
  -import org.apache.myrmidon.components.deployer.DefaultClassLoaderManager;
   import org.apache.myrmidon.components.deployer.DefaultDeployer;
   import org.apache.myrmidon.components.extensions.DefaultExtensionManager;
   import org.apache.myrmidon.components.role.DefaultRoleManager;
   import org.apache.myrmidon.components.type.DefaultTypeManager;
   import org.apache.myrmidon.components.workspace.DefaultPropertyResolver;
  +import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager;
   import org.apache.myrmidon.interfaces.configurer.Configurer;
   import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/classloader/DefaultClassLoaderManager.java
  
  Index: DefaultClassLoaderManager.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.components.classloader;
  
  import java.io.File;
  import java.net.JarURLConnection;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.net.URLClassLoader;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.HashMap;
  import java.util.Map;
  import java.util.jar.Manifest;
  import org.apache.avalon.excalibur.extension.Extension;
  import org.apache.avalon.excalibur.extension.OptionalPackage;
  import org.apache.avalon.excalibur.extension.PackageManager;
  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.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager;
  import org.apache.myrmidon.interfaces.deployer.DeploymentException;
  import org.apache.myrmidon.interfaces.extensions.ExtensionManager;
  
  /**
   * A default implementation of a classloader manager.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   */
  public class DefaultClassLoaderManager
      extends AbstractLogEnabled
      implements ClassLoaderManager, Serviceable, Initializable
  {
      private final static Resources REZ =
          ResourceManager.getPackageResources( DefaultClassLoaderManager.class );
  
      /**
       * Map from File to the ClassLoader for that file.
       */
      private final Map m_fileDeployers = new HashMap();
  
      private PackageManager m_packageManager;
      private ClassLoader m_baseClassLoader;
  
      public void initialize() throws Exception
      {
          if( null == m_baseClassLoader )
          {
              m_baseClassLoader = Thread.currentThread().getContextClassLoader();
          }
      }
  
      /**
       * Sets the ClassLoader to use as the parent for all classloaders
       * created by this ClassLoader manager.
       */
      public void setBaseClassLoader( final ClassLoader classLoader )
      {
          m_baseClassLoader = classLoader;
      }
  
      /**
       * Retrieve relevent services needed to deploy.
       */
      public void service( final ServiceManager serviceManager )
          throws ServiceException
      {
          final ExtensionManager extensionManager =
              (ExtensionManager)serviceManager.lookup( ExtensionManager.ROLE );
          m_packageManager = new PackageManager( extensionManager );
      }
  
      /**
       * Creates a class loader for a Jar file.
       */
      public ClassLoader createClassLoader( File file ) throws DeploymentException
      {
          try
          {
              final File canonFile = file.getCanonicalFile();
  
              // Locate cached classloader, creating it if necessary
              URLClassLoader classLoader = (URLClassLoader)m_fileDeployers.get( canonFile
);
              if( classLoader == null )
              {
                  checkFile( canonFile );
                  final File[] extensions = getOptionalPackagesFor( canonFile );
                  final URL[] urls = buildClasspath( canonFile, extensions );
                  classLoader = new URLClassLoader( urls, m_baseClassLoader );
                  m_fileDeployers.put( canonFile, classLoader );
              }
              return classLoader;
          }
          catch( Exception e )
          {
              final String message = REZ.getString( "create-classloader-for-file.error", file
);
              throw new DeploymentException( message );
          }
      }
  
      /**
       * Assembles a set of files into a URL classpath.
       */
      private URL[] buildClasspath( final File file, final File[] dependencies )
          throws MalformedURLException
      {
          final URL[] urls = new URL[ dependencies.length + 1 ];
  
          for( int i = 0; i < dependencies.length; i++ )
          {
              urls[ i ] = dependencies[ i ].toURL();
          }
  
          urls[ dependencies.length ] = file.toURL();
  
          return urls;
      }
  
      /**
       * Retrieve the files for the optional packages required by
       * the specified typeLibrary jar.
       *
       * @param typeLibrary the typeLibrary
       * @return the files that need to be added to ClassLoader
       */
      private File[] getOptionalPackagesFor( final File typeLibrary )
          throws Exception
      {
          final URL url = new URL( "jar:" + typeLibrary.getCanonicalFile().toURL() + "!/"
);
          final JarURLConnection connection = (JarURLConnection)url.openConnection();
          final Manifest manifest = connection.getManifest();
          final Extension[] available = Extension.getAvailable( manifest );
          final Extension[] required = Extension.getRequired( manifest );
  
          if( getLogger().isDebugEnabled() )
          {
              final String message1 =
                  REZ.getString( "available-extensions.notice", Arrays.asList( available )
);
              getLogger().debug( message1 );
              final String message2 =
                  REZ.getString( "required-extensions.notice", Arrays.asList( required ) );
              getLogger().debug( message2 );
          }
  
          final ArrayList dependencies = new ArrayList();
          final ArrayList unsatisfied = new ArrayList();
  
          m_packageManager.scanDependencies( required,
                                             available,
                                             dependencies,
                                             unsatisfied );
  
          if( 0 != unsatisfied.size() )
          {
              final String message =
                  REZ.getString( "unsatisfied.extensions.error", new Integer( unsatisfied.size()
) );
              throw new Exception( message );
          }
  
          final OptionalPackage[] packages =
              (OptionalPackage[])dependencies.toArray( new OptionalPackage[ 0 ] );
          return OptionalPackage.toFiles( packages );
      }
  
      /**
       * Ensures a file exists and is not a directory.
       */
      private void checkFile( final File file )
          throws DeploymentException
      {
          if( !file.exists() )
          {
              final String message = REZ.getString( "no-file.error", file );
              throw new DeploymentException( message );
          }
  
          if( file.isDirectory() )
          {
              final String message = REZ.getString( "file-is-dir.error", file );
              throw new DeploymentException( message );
          }
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/classloader/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  create-classloader-for-file.error=Could not create ClassLoader for file {0}.
  available-extensions.notice=The list of available extensions for type library includes;
{0}
  required-extensions.notice=The list of required extensions for type library includes; {0}
  unsatisfied.extensions.error=Missing {0} extensions for type library.
  no-file.error=Could not find type library "{0}".
  file-is-dir.error=Type library "{0}" is a directory.
  
  
  
  1.32      +2 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java
  
  Index: DefaultDeployer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- DefaultDeployer.java	1 Mar 2002 08:54:20 -0000	1.31
  +++ DefaultDeployer.java	11 Mar 2002 06:02:22 -0000	1.32
  @@ -18,6 +18,7 @@
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.Serviceable;
  +import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager;
   import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
   import org.apache.myrmidon.interfaces.deployer.ConverterDefinition;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
  @@ -35,7 +36,7 @@
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  - * @version $Revision: 1.31 $ $Date: 2002/03/01 08:54:20 $
  + * @version $Revision: 1.32 $ $Date: 2002/03/11 06:02:22 $
    */
   public class DefaultDeployer
       extends AbstractLogEnabled
  
  
  
  1.11      +0 -6      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/Resources.properties,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Resources.properties	21 Feb 2002 12:52:07 -0000	1.10
  +++ Resources.properties	11 Mar 2002 06:02:22 -0000	1.11
  @@ -13,8 +13,6 @@
   deploy-converter.error=Could not register converter that converts from {0} to {1}.
   deploy-type.error=Could not register type {0}/{1}.
   unknown-role4name.error=Unknown role "{0}".
  -no-file.error=Could not find type library "{0}".
  -file-is-dir.error=Type library "{0}" is a directory.
   typedef.no-classname.error=Must specify the classname parameter.
   typedef.no-name.error=Must specify name parameter.
   typedef.no-role.error=Must specify type parameter.
  @@ -27,7 +25,3 @@
   service-descriptor-version.error=Service descriptor version {0} is incompatible with current
version {1}.
   build-service-descriptor.error=Could not build service descriptor from "{0}".
   
  -available-extensions.notice=The list of available extensions for type library includes;
{0}
  -required-extensions.notice=The list of required extensions for type library includes; {0}
  -unsatisfied.extensions.error=Missing {0} extensions for type library.
  -create-classloader-for-file.error=Could not create ClassLoader for file {0}.
  
  
  
  1.32      +18 -10    jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java
  
  Index: DefaultEmbeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- DefaultEmbeddor.java	9 Mar 2002 02:04:26 -0000	1.31
  +++ DefaultEmbeddor.java	11 Mar 2002 06:02:22 -0000	1.32
  @@ -17,6 +17,7 @@
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.excalibur.io.ExtensionFileFilter;
   import org.apache.avalon.excalibur.io.FileUtil;
  +import org.apache.avalon.framework.CascadingException;
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  @@ -25,9 +26,9 @@
   import org.apache.avalon.framework.service.DefaultServiceManager;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.Serviceable;
  -import org.apache.myrmidon.components.deployer.ClassLoaderManager;
   import org.apache.myrmidon.interfaces.aspect.AspectManager;
   import org.apache.myrmidon.interfaces.builder.ProjectBuilder;
  +import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager;
   import org.apache.myrmidon.interfaces.configurer.Configurer;
   import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
  @@ -50,7 +51,7 @@
    * Instantiate this to embed inside other applications.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.31 $ $Date: 2002/03/09 02:04:26 $
  + * @version $Revision: 1.32 $ $Date: 2002/03/11 06:02:22 $
    */
   public class DefaultEmbeddor
       extends AbstractLogEnabled
  @@ -93,14 +94,22 @@
                                     final Parameters parameters )
           throws Exception
       {
  -        String projectType = type;
  -        if( null == projectType )
  +        try
           {
  -            projectType = FileUtil.getExtension( location );
  -        }
  +            String projectType = type;
  +            if( null == projectType )
  +            {
  +                projectType = FileUtil.getExtension( location );
  +            }
   
  -        final ProjectBuilder builder = getProjectBuilder( projectType, parameters );
  -        return builder.build( location );
  +            final ProjectBuilder builder = getProjectBuilder( projectType, parameters );
  +            return builder.build( location );
  +        }
  +        catch( final Exception e )
  +        {
  +            final String message = REZ.getString( "create-project.error", location );
  +            throw new CascadingException( message, e );
  +        }
       }
   
       /**
  @@ -110,7 +119,6 @@
                                                 final Parameters parameters )
           throws Exception
       {
  -
           final TypeFactory factory = m_typeManager.getFactory( ProjectBuilder.class );
           final ProjectBuilder builder = (ProjectBuilder)factory.create( type );
           setupObject( builder, m_workspaceServiceManager, parameters );
  @@ -253,7 +261,7 @@
           createComponent( RoleManager.class, PREFIX + "role.DefaultRoleManager" );
           createComponent( AspectManager.class, PREFIX + "aspect.DefaultAspectManager" );
           createComponent( Deployer.class, PREFIX + "deployer.DefaultDeployer" );
  -        createComponent( ClassLoaderManager.class, PREFIX + "deployer.DefaultClassLoaderManager"
);
  +        createComponent( ClassLoaderManager.class, PREFIX + "classloader.DefaultClassLoaderManager"
);
           createComponent( Executor.class, PREFIX + "executor.AspectAwareExecutor" );
           createComponent( PropertyResolver.class, PREFIX + "workspace.DefaultPropertyResolver"
);
   
  
  
  
  1.4       +2 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/Resources.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Resources.properties	20 Feb 2002 07:20:21 -0000	1.3
  +++ Resources.properties	11 Mar 2002 06:02:22 -0000	1.4
  @@ -6,4 +6,5 @@
   no-class.error=Could not find the class for {0} ({1}).
   bad-filename.error=Unable to retrieve filename for file {0}.
   home-dir.name=Myrmidon home directory
  -task-lib-dir.name=Task library directory
  \ No newline at end of file
  +task-lib-dir.name=Task library directory
  +create-project.error=Could not load the project definition from {0}.
  \ No newline at end of file
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/classloader/ClassLoaderManager.java
  
  Index: ClassLoaderManager.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.interfaces.classloader;
  
  import java.io.File;
  import org.apache.myrmidon.interfaces.deployer.DeploymentException;
  
  /**
   * Manages a classloader hierarchy.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   */
  public interface ClassLoaderManager
  {
      String ROLE = ClassLoaderManager.class.getName();
  
      /**
       * Builds the ClassLoader for a Jar file.
       */
      ClassLoader createClassLoader( File jar ) throws DeploymentException;
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message