avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: avalon-phoenix/src/java/org/apache/avalon/phoenix/components/extensions DefaultExtensionManager.java
Date Wed, 30 Apr 2003 10:15:20 GMT
donaldp     2003/04/30 03:15:20

  Modified:    src/conf kernel.xml
               src/java/org/apache/avalon/phoenix/components/classloader
                        DefaultClassLoaderManager.java
                        PolicyClassLoader.java SarLoaderResolver.java
               src/java/org/apache/avalon/phoenix/components/creator
                        PhoenixConfig.java
               src/java/org/apache/avalon/phoenix/components/embeddor
                        ManagementRegistration.java
               src/java/org/apache/avalon/phoenix/components/extensions
                        DefaultExtensionManager.java
  Added:       src/java/org/apache/avalon/phoenix/components/classloader
                        DefaultLoaderResolver.java
                        SimpleLoaderResolver.java
  Log:
  Migrate to using Phoenix specific PackageManager files.
  
  Revision  Changes    Path
  1.39      +4 -4      avalon-phoenix/src/conf/kernel.xml
  
  Index: kernel.xml
  ===================================================================
  RCS file: /home/cvs/avalon-phoenix/src/conf/kernel.xml,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- kernel.xml	25 Apr 2003 14:26:13 -0000	1.38
  +++ kernel.xml	30 Apr 2003 10:15:18 -0000	1.39
  @@ -40,7 +40,7 @@
   
               <!--
                 By default the Mx4J Http Adaptor will bind a webserver to a
  -              single network interface, localhost. If you wish to restrict it to 
  +              single network interface, localhost. If you wish to restrict it to
                 only one a different interface, include that below. To bind to all
                 interfaces, use 0.0.0.0 as the value.
               -->
  @@ -179,12 +179,12 @@
           <component role="org.apache.avalon.phoenix.interfaces.ClassLoaderManager"
               class="org.apache.avalon.phoenix.components.classloader.DefaultClassLoaderManager"
               logger="classes"/>
  -        <component role="org.apache.avalon.excalibur.packagemanager.ExtensionManager"
  +        <component role="org.apache.avalon.phoenix.components.extensions.pkgmgr.ExtensionManager"
               class="org.apache.avalon.phoenix.components.extensions.DefaultExtensionManager"
               logger="packages"/>
           <!--
  -                <component role="org.apache.avalon.excalibur.packagemanager.ExtensionManager"
  -                    class="org.apache.avalon.excalibur.packagemanager.impl.NoopPackageRepository"
  +                <component role="org.apache.avalon.phoenix.components.extensions.pkgmgr.ExtensionManager"
  +                    class="org.apache.avalon.phoenix.components.extensions.pkgmgr.impl.NoopPackageRepository"
                       logger="packages"/>
           -->
   
  
  
  
  1.57      +2 -2      avalon-phoenix/src/java/org/apache/avalon/phoenix/components/classloader/DefaultClassLoaderManager.java
  
  Index: DefaultClassLoaderManager.java
  ===================================================================
  RCS file: /home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/classloader/DefaultClassLoaderManager.java,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- DefaultClassLoaderManager.java	25 Apr 2003 01:38:37 -0000	1.56
  +++ DefaultClassLoaderManager.java	30 Apr 2003 10:15:18 -0000	1.57
  @@ -57,8 +57,6 @@
   import java.util.HashMap;
   import java.util.Map;
   import org.apache.avalon.excalibur.extension.Extension;
  -import org.apache.avalon.excalibur.packagemanager.ExtensionManager;
  -import org.apache.avalon.excalibur.packagemanager.PackageManager;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  @@ -72,6 +70,8 @@
   import org.apache.avalon.framework.service.Serviceable;
   import org.apache.avalon.phoenix.interfaces.ClassLoaderManager;
   import org.apache.avalon.phoenix.interfaces.ClassLoaderSet;
  +import org.apache.avalon.phoenix.components.extensions.pkgmgr.PackageManager;
  +import org.apache.avalon.phoenix.components.extensions.pkgmgr.ExtensionManager;
   import org.realityforge.classman.builder.LoaderBuilder;
   import org.realityforge.classman.builder.LoaderResolver;
   import org.realityforge.classman.metadata.ClassLoaderMetaData;
  
  
  
  1.25      +0 -1      avalon-phoenix/src/java/org/apache/avalon/phoenix/components/classloader/PolicyClassLoader.java
  
  Index: PolicyClassLoader.java
  ===================================================================
  RCS file: /home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/classloader/PolicyClassLoader.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- PolicyClassLoader.java	22 Mar 2003 12:07:08 -0000	1.24
  +++ PolicyClassLoader.java	30 Apr 2003 10:15:18 -0000	1.25
  @@ -47,7 +47,6 @@
    Apache Software Foundation, please see <http://www.apache.org/>.
   
   */
  -
   package org.apache.avalon.phoenix.components.classloader;
   
   import java.io.IOException;
  
  
  
  1.7       +2 -3      avalon-phoenix/src/java/org/apache/avalon/phoenix/components/classloader/SarLoaderResolver.java
  
  Index: SarLoaderResolver.java
  ===================================================================
  RCS file: /home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/classloader/SarLoaderResolver.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SarLoaderResolver.java	11 Apr 2003 06:49:37 -0000	1.6
  +++ SarLoaderResolver.java	30 Apr 2003 10:15:19 -0000	1.7
  @@ -56,12 +56,11 @@
   import java.util.Arrays;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  -import org.apache.avalon.excalibur.packagemanager.PackageManager;
   import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.phoenix.components.util.ResourceUtil;
  -import org.realityforge.classman.builder.DefaultLoaderResolver;
  +import org.apache.avalon.phoenix.components.extensions.pkgmgr.PackageManager;
   
   /**
    * a LoaderResolver that knows about Phoenixs environment,
  
  
  
  1.1                  avalon-phoenix/src/java/org/apache/avalon/phoenix/components/classloader/DefaultLoaderResolver.java
  
  Index: DefaultLoaderResolver.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1997-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Avalon", "Phoenix" and "Apache Software Foundation"
      must  not be  used to  endorse or  promote products derived  from this
      software without prior written permission. For written permission, please
      contact apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.phoenix.components.classloader;
  
  import java.io.File;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.ArrayList;
  import org.realityforge.classman.util.PathMatcher;
  import org.apache.avalon.phoenix.components.extensions.pkgmgr.PackageManager;
  
  /**
   * This resolver has all the same properties as the
   * {@link SimpleLoaderResolver} except that it also implements
   * scanning of filesets. It scans filesets based on classes
   * {@link #m_baseDirectory} value.
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/04/30 10:15:18 $
   * @deprecated Convert to ClassMan SimpleLoaderResolver when it updates
   *             dependecy to latest Excalibur-Extension
   */
  class DefaultLoaderResolver
      extends SimpleLoaderResolver
  {
      /**
       * Create a resolver that resolves all files according to specied
       * baseDirectory and using specified {@link PackageManager} to aquire
       * {@link org.apache.avalon.excalibur.extension.Extension} objects.
       *
       * @param baseDirectory the base directory
       * @param manager the {@link PackageManager}
       */
      public DefaultLoaderResolver( final File baseDirectory,
                                    final PackageManager manager )
      {
          super( baseDirectory, manager );
      }
  
      /**
       * Resolve a fileset.
       *
       * @param baseDirectory the base directory of fileset
       * @param includes the list of ant-style includes
       * @param excludes the list of ant style excludes
       * @return the URLs contained within fileset
       * @throws Exception if unable to resolve fileset
       */
      public URL[] resolveFileSet( final String baseDirectory,
                                   final String[] includes,
                                   final String[] excludes )
          throws Exception
      {
          final File base = getFileFor( "." );
          return resolveFileSet( base, baseDirectory, includes, excludes );
      }
  
      /**
       * Resolve a fileset in a particular hierarchy.
       *
       * @param base the file hierarchy to use
       * @param baseDirectory the base directory (relative to base)
       * @param includes the ant-style include patterns
       * @param excludes the ant-style exclude patterns
       * @return the resolved URLs for fileset
       */
      protected final URL[] resolveFileSet( final File base,
                                            final String baseDirectory,
                                            final String[] includes,
                                            final String[] excludes )
      {
          //woefully inefficient .. but then again - no need
          //for efficency here
          final String newBaseDirectory = normalize( baseDirectory );
          final String[] newIncludes = prefixPatterns( newBaseDirectory, includes );
          final String[] newExcludes = prefixPatterns( newBaseDirectory, excludes );
          final PathMatcher matcher = new PathMatcher( newIncludes, newExcludes );
          final ArrayList urls = new ArrayList();
  
          scanDir( base, matcher, "", urls );
  
          return (URL[])urls.toArray( new URL[ urls.size() ] );
      }
  
      /**
       * Scan a directory trying to match files with matcher
       * and adding them to list of result urls if they match.
       * Recurse into sub-directorys.
       *
       * @param dir the directory to scan
       * @param matcher the matcher to use
       * @param path the virtual path to the current directory
       * @param urls the list of result URLs
       */
      private void scanDir( final File dir,
                            final PathMatcher matcher,
                            final String path,
                            final ArrayList urls )
      {
          final File[] files = dir.listFiles();
          if( null == files )
          {
              final String message = "Bad dir specified: " + dir;
              throw new IllegalArgumentException( message );
          }
  
          String prefix = "";
          if( 0 != path.length() )
          {
              prefix = path + "/";
          }
  
          for( int i = 0; i < files.length; i++ )
          {
              final File file = files[ i ];
              final String newPath = prefix + file.getName();
              if( file.isDirectory() )
              {
                  scanDir( file, matcher, newPath, urls );
              }
              else
              {
                  if( matcher.match( newPath ) )
                  {
                      try
                      {
                          urls.add( file.toURL() );
                      }
                      catch( final MalformedURLException mue )
                      {
                          final String message = "Error converting " +
                              file + " to url. Reason: " + mue;
                          throw new IllegalArgumentException( message );
                      }
                  }
              }
          }
      }
  
      /**
       * Return a new array with specified prefix added to start of
       * every element in supplied array.
       *
       * @param prefix the prefix
       * @param patterns the source array
       * @return a new array with all elements having prefix added
       */
      private String[] prefixPatterns( final String prefix,
                                       final String[] patterns )
      {
          if( 0 == prefix.length() )
          {
              return patterns;
          }
  
          final String[] newPatterns = new String[ patterns.length ];
          for( int i = 0; i < newPatterns.length; i++ )
          {
              newPatterns[ i ] = prefix + "/" + patterns[ i ];
          }
          return newPatterns;
      }
  
      /**
       * Normalize a path. That means:
       * <ul>
       *   <li>changes to unix style if under windows</li>
       *   <li>eliminates "/../" and "/./"</li>
       *   <li>if path is absolute (starts with '/') and there are
       *   too many occurences of "../" (would then have some kind
       *   of 'negative' path) returns null.</li>
       *   <li>If path is relative, the exceeding ../ are kept at
       *   the begining of the path.</li>
       * </ul>
       * <br><br>
       *
       * <b>Note:</b> note that this method has been tested with unix and windows
only.
       *
       * <p>Eg:</p>
       * <pre>
       * /foo//               -->     /foo/
       * /foo/./              -->     /foo/
       * /foo/../bar          -->     /bar
       * /foo/../bar/         -->     /bar/
       * /foo/../bar/../baz   -->     /baz
       * //foo//./bar         -->     /foo/bar
       * /../                 -->     null
       * </pre>
       *
       * @param path the path to be normalized.
       * @return the normalized path or null.
       * @throws NullPointerException if path is null.
       */
      private static final String normalize( String path )
      {
          if( ".".equals( path ) || "./".equals( path ) )
          {
              return "";
          }
          else if( path.length() < 2 )
          {
              return path;
          }
  
          StringBuffer buff = new StringBuffer( path );
  
          int length = path.length();
  
          // this whole prefix thing is for windows compatibility only.
          String prefix = null;
  
          if( length > 2 && buff.charAt( 1 ) == ':' )
          {
              prefix = path.substring( 0, 2 );
              buff.delete( 0, 2 );
              path = path.substring( 2 );
              length -= 2;
          }
  
          boolean startsWithSlash = length > 0 && ( buff.charAt( 0 ) == '/' ||
buff.charAt( 0 ) == '\\' );
  
          boolean expStart = true;
          int ptCount = 0;
          int lastSlash = length + 1;
          int upLevel = 0;
  
          for( int i = length - 1; i >= 0; i-- )
              switch( path.charAt( i ) )
              {
                  case '\\':
                      buff.setCharAt( i, '/' );
                  case '/':
                      if( lastSlash == i + 1 )
                      {
                          buff.deleteCharAt( i );
                      }
  
                      switch( ptCount )
                      {
                          case 1:
                              buff.delete( i, lastSlash );
                              break;
  
                          case 2:
                              upLevel++;
                              break;
  
                          default:
                              if( upLevel > 0 && lastSlash != i + 1 )
                              {
                                  buff.delete( i, lastSlash + 3 );
                                  upLevel--;
                              }
                              break;
                      }
  
                      ptCount = 0;
                      expStart = true;
                      lastSlash = i;
                      break;
  
                  case '.':
                      if( expStart )
                      {
                          ptCount++;
                      }
                      break;
  
                  default:
                      ptCount = 0;
                      expStart = false;
                      break;
              }
  
          switch( ptCount )
          {
              case 1:
                  buff.delete( 0, lastSlash );
                  break;
  
              case 2:
                  break;
  
              default:
                  if( upLevel > 0 )
                  {
                      if( startsWithSlash )
                      {
                          return null;
                      }
                      else
                      {
                          upLevel = 1;
                      }
                  }
  
                  while( upLevel > 0 )
                  {
                      buff.delete( 0, lastSlash + 3 );
                      upLevel--;
                  }
                  break;
          }
  
          length = buff.length();
          boolean isLengthNull = length == 0;
          char firstChar = isLengthNull?(char)0:buff.charAt( 0 );
  
          if( !startsWithSlash && !isLengthNull && firstChar == '/' )
          {
              buff.deleteCharAt( 0 );
          }
          else if( startsWithSlash &&
              ( isLengthNull || ( !isLengthNull && firstChar != '/' ) ) )
          {
              buff.insert( 0, '/' );
          }
  
          if( prefix != null )
          {
              buff.insert( 0, prefix );
          }
  
          return buff.toString();
      }
  }
  
  
  
  1.1                  avalon-phoenix/src/java/org/apache/avalon/phoenix/components/classloader/SimpleLoaderResolver.java
  
  Index: SimpleLoaderResolver.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1997-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Avalon", "Phoenix" and "Apache Software Foundation"
      must  not be  used to  endorse or  promote products derived  from this
      software without prior written permission. For written permission, please
      contact apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.phoenix.components.classloader;
  
  import java.io.File;
  import java.io.IOException;
  import java.net.JarURLConnection;
  import java.net.URL;
  import java.net.URLClassLoader;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.jar.Manifest;
  import org.apache.avalon.excalibur.extension.Extension;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.phoenix.components.extensions.pkgmgr.PackageManager;
  import org.apache.avalon.phoenix.components.extensions.pkgmgr.OptionalPackage;
  import org.realityforge.classman.runtime.JoinClassLoader;
  import org.realityforge.classman.builder.LoaderResolver;
  
  /**
   * This is a class that performs resolver that;
   * <ul>
   *   <li>creates "Join" ClassLoaders using the  {@link JoinClassLoader}
   *       class</li>
   *   <li>creates normal ClassLoaders using a {@link URLClassLoader}. It
   *       also makes sure that all dependencies of jars (as declared using
   *       the JDK1.3 "Optional Pakcages" Spec) are present in classloader.</li>
   *   <li>The locations are resolved to a single base directiory.</li>
   *   <li>The Extensions are resolved accoriding to a specified
   *       {@link PackageManager}.</li>
   *   <li>FileSets are currently unsupported and throw a
   *       {@link UnsupportedOperationException} if attempt to be constructed.</li>
   * </ul>
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/04/30 10:15:19 $
   * @deprecated Convert to ClassMan SimpleLoaderResolver when it updates
   *             dependecy to latest Excalibur-Extension
   */
  class SimpleLoaderResolver
      implements LoaderResolver
  {
      private final static Resources REZ =
          ResourceManager.getPackageResources( SimpleLoaderResolver.class );
  
      /**
       * The base directory relative to which to aquire files.
       */
      private File m_baseDirectory;
  
      /**
       * The PackageManager to use to resolve Extensions.
       */
      private PackageManager m_manager;
  
      /**
       * Create a resolver that resolves all files according to specied
       * baseDirectory and using specified {@link PackageManager} to aquire
       * {@link Extension} objects.
       *
       * @param baseDirectory the base directory
       * @param manager the {@link PackageManager}
       */
      public SimpleLoaderResolver( final File baseDirectory,
                                   final PackageManager manager )
      {
          setBaseDirectory( baseDirectory );
          setManager( manager );
      }
  
      /**
       * Retrieve a URL for specified extension.
       *
       * @param extension the extension
       * @return the URL
       * @throws Exception if unable to locate URL for extension
       */
      public URL resolveExtension( final Extension extension )
          throws Exception
      {
          if( null == getManager() )
          {
              final String message =
                  REZ.getString( "missing-packagemanager" );
              throw new IllegalStateException( message );
          }
          final OptionalPackage optionalPackage =
              getManager().getOptionalPackage( extension );
          return optionalPackage.getFile().toURL();
      }
  
      /**
       * Resolve a location to a particular URL.
       *
       * @param location the location
       * @return the URL
       * @throws Exception if unable to resolve location
       */
      public URL resolveURL( final String location )
          throws Exception
      {
          final File file = getFileFor( location );
          String url = file.toURL().toString();
          if( file.isDirectory() )
          {
              url += "/";
          }
          return new URL( url );
      }
  
      /**
       * Resolve all URLs in a particular fileset.
       *
       * @param baseDirectory the basedirectory
       * @param includes the pattern for includes
       * @param excludes the pattern for excludes
       * @return an array of URLs in fileset
       * @throws Exception if unable to aquire URLs.
       */
      public URL[] resolveFileSet( final String baseDirectory,
                                   final String[] includes,
                                   final String[] excludes )
          throws Exception
      {
          throw new UnsupportedOperationException();
      }
  
      /**
       * Create a Join ClassLoader for specified ClassLoaders.
       * Use {@link JoinClassLoader} to implement functionality.
       *
       * @param classLoaders the ClassLoaders to "join"
       * @return the joined ClassLoader
       * @throws Exception if unable to create classloader
       */
      public ClassLoader createJoinClassLoader( final ClassLoader[] classLoaders )
          throws Exception
      {
          return new JoinClassLoader( classLoaders,
                                      ClassLoader.getSystemClassLoader() );
      }
  
      /**
       * Create a ClassLoader with specified parent and
       * containing specified URLs. This implementation just creates
       * it using the default URLClassLoader.
       *
       * @param parent the parent classloader
       * @param urls the URLs that the ClassLoader should contain
       * @return the newly created ClassLoader
       * @throws Exception if unable to create classloader
       */
      public ClassLoader createClassLoader( final ClassLoader parent,
                                            final URL[] urls )
          throws Exception
      {
          final URL[] classpath = determineCompleteClasspath( urls );
          return new URLClassLoader( classpath, parent );
      }
  
      /**
       * Retrieve the complete classpath given an input set of URLs.
       * The complete classpath includes all URLs for extensions
       * required by the jars (according to the "Optional Package"
       * Spec).
       *
       * @param urls the urls
       * @return the complete set of URLs for classpath
       * @throws Exception if unable to determine complete classpath set
       */
      protected final URL[] determineCompleteClasspath( final URL[] urls )
          throws Exception
      {
          final ArrayList classpathSet = new ArrayList();
  
          //Add all supplied URLS to classpath
          for( int i = 0; i < urls.length; i++ )
          {
              final URL url = urls[ i ];
              classpathSet.add( url );
          }
  
          //Add all the optional packages that are declared as
          // dependencies of class path elements
          final File[] files = getOptionalPackagesFor( urls );
          for( int i = 0; i < files.length; i++ )
          {
              final File file = files[ i ];
              classpathSet.add( file.toURL() );
          }
  
          //Define final classpath with all dependencies added
          return (URL[])classpathSet.toArray( new URL[ classpathSet.size() ] );
      }
  
      /**
       * Utility class to retrieve a file object for specified location.
       *
       * @param location which to get file for.
       * @return the file for specified location
       */
      protected File getFileFor( final String location )
          throws IOException
      {
          File base = getBaseDirectory();
          if( null == base )
          {
              base = new File( "." );
          }
  
          return new File( base, location ).getCanonicalFile();
      }
  
      /**
       * Return the base directory against which to resolve relative files.
       *
       * @return the base directory against which to resolve relative files.
       */
      protected File getBaseDirectory()
      {
          return m_baseDirectory;
      }
  
      /**
       * Set the base directory.
       *
       * @param baseDirectory the base directory.
       */
      protected void setBaseDirectory( File baseDirectory )
      {
          m_baseDirectory = baseDirectory;
      }
  
      /**
       * Return the PackageManager for resolver.
       *
       * @return the PackageManager for resolver.
       */
      protected PackageManager getManager()
      {
          return m_manager;
      }
  
      /**
       * Set the PackageManager for resolver.
       *
       * @param manager the PackageManager for resolver.
       */
      protected void setManager( final PackageManager manager )
      {
          m_manager = manager;
      }
  
      /**
       * Retrieve the files for the optional packages required by
       * the jars in ClassPath.
       *
       * @param classPath the Classpath array
       * @return the files that need to be added to ClassLoader
       */
      protected final File[] getOptionalPackagesFor( final URL[] classPath )
          throws Exception
      {
          final Manifest[] manifests = getManifests( classPath );
          final Extension[] available = Extension.getAvailable( manifests );
          final Extension[] required = Extension.getRequired( manifests );
  
          if( isDebugEnabled() )
          {
              final String message1 =
                  REZ.getString( "available-extensions",
                                 Arrays.asList( available ) );
              debug( message1 );
              final String message2 =
                  REZ.getString( "required-extensions",
                                 Arrays.asList( required ) );
              debug( message2 );
          }
  
          if( 0 == required.length )
          {
              return new File[ 0 ];
          }
  
          final ArrayList dependencies = new ArrayList();
          final ArrayList unsatisfied = new ArrayList();
  
          if( null == getManager() )
          {
              final String message =
                  REZ.getString( "missing-packagemanager" );
              throw new IllegalStateException( message );
          }
  
          m_manager.scanDependencies( required,
                                      available,
                                      dependencies,
                                      unsatisfied );
  
          if( 0 != unsatisfied.size() )
          {
              final int size = unsatisfied.size();
              for( int i = 0; i < size; i++ )
              {
                  final Extension extension = (Extension)unsatisfied.get( i );
                  final Object[] params = new Object[]
                  {
                      extension.getExtensionName(),
                      extension.getSpecificationVendor(),
                      extension.getSpecificationVersion(),
                      extension.getImplementationVendor(),
                      extension.getImplementationVendorID(),
                      extension.getImplementationVersion(),
                      extension.getImplementationURL()
                  };
                  final String message = REZ.format( "missing.extension", params );
                  warn( message );
              }
  
              final String message =
                  REZ.getString( "unsatisfied.extensions", new Integer( size ) );
              throw new Exception( message );
          }
  
          if( isDebugEnabled() )
          {
              final String message =
                  REZ.getString( "optional-packages-added", dependencies );
              debug( message );
          }
  
          final OptionalPackage[] packages =
              (OptionalPackage[])dependencies.toArray( new OptionalPackage[ 0 ] );
          return OptionalPackage.toFiles( packages );
      }
  
      /**
       * write out a warning message. Subclasses may overide this
       * method to redirect logging as appropriate.
       *
       * @param message the warning message
       */
      protected void warn( final String message )
      {
      }
  
      /**
       * Determine if debug messages are turned on.
       * Subclasses should overide this method.
       *
       * @return true if debugging enabled.
       */
      protected boolean isDebugEnabled()
      {
          return false;
      }
  
      /**
       * write out a debug message. Subclasses may overide this
       * method to redirect logging as appropriate.
       *
       * @param message the debug message
       */
      protected void debug( final String message )
      {
      }
  
      /**
       * Retrieve all the Manifests from the specified Classlpath.
       *
       * @param classPath the classpath
       * @return the set of manifests on the classpath
       * @throws Exception if there is an error reading manifests
       *                   from files on classpath
       */
      private Manifest[] getManifests( final URL[] classPath )
          throws Exception
      {
          final ArrayList manifests = new ArrayList();
  
          for( int i = 0; i < classPath.length; i++ )
          {
              final URL element = classPath[ i ];
              if( element.getFile().endsWith( ".jar" ) )
              {
                  try
                  {
                      final URL url = new URL( "jar:" + element + "!/" );
                      final JarURLConnection connection =
                          (JarURLConnection)url.openConnection();
                      final Manifest manifest = connection.getManifest();
                      if( null != manifest )
                      {
                          manifests.add( manifest );
                      }
                  }
                  catch( final IOException ioe )
                  {
                      final String message =
                          REZ.getString( "bad-classpath-entry", element );
                      throw new Exception( message );
                  }
              }
          }
  
          return (Manifest[])manifests.toArray( new Manifest[ 0 ] );
      }
  }
  
  
  
  1.2       +4 -2      avalon-phoenix/src/java/org/apache/avalon/phoenix/components/creator/PhoenixConfig.java
  
  Index: PhoenixConfig.java
  ===================================================================
  RCS file: /home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/creator/PhoenixConfig.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PhoenixConfig.java	11 Apr 2003 01:06:57 -0000	1.1
  +++ PhoenixConfig.java	30 Apr 2003 10:15:19 -0000	1.2
  @@ -53,6 +53,8 @@
   import java.util.HashMap;
   
   /**
  + * Utility classed used to creat the initial configuration for a Phoenix
  + * container.
    *
    * @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
    * @version $Revision$ $Date$
  @@ -72,7 +74,7 @@
           validate();
           return m_data;
       }
  -        
  +
       private void validate()
       {
       }
  
  
  
  1.13      +1 -1      avalon-phoenix/src/java/org/apache/avalon/phoenix/components/embeddor/ManagementRegistration.java
  
  Index: ManagementRegistration.java
  ===================================================================
  RCS file: /home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/embeddor/ManagementRegistration.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ManagementRegistration.java	6 Apr 2003 11:23:22 -0000	1.12
  +++ ManagementRegistration.java	30 Apr 2003 10:15:19 -0000	1.13
  @@ -52,7 +52,6 @@
   
   import java.util.HashMap;
   import java.util.Map;
  -import org.apache.avalon.excalibur.packagemanager.ExtensionManager;
   import org.apache.avalon.phoenix.interfaces.Deployer;
   import org.apache.avalon.phoenix.interfaces.DeployerMBean;
   import org.apache.avalon.phoenix.interfaces.Embeddor;
  @@ -61,6 +60,7 @@
   import org.apache.avalon.phoenix.interfaces.Kernel;
   import org.apache.avalon.phoenix.interfaces.KernelMBean;
   import org.apache.avalon.phoenix.interfaces.LogManager;
  +import org.apache.avalon.phoenix.components.extensions.pkgmgr.ExtensionManager;
   
   /**
    *
  
  
  
  1.10      +4 -5      avalon-phoenix/src/java/org/apache/avalon/phoenix/components/extensions/DefaultExtensionManager.java
  
  Index: DefaultExtensionManager.java
  ===================================================================
  RCS file: /home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/extensions/DefaultExtensionManager.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DefaultExtensionManager.java	22 Mar 2003 12:07:09 -0000	1.9
  +++ DefaultExtensionManager.java	30 Apr 2003 10:15:19 -0000	1.10
  @@ -47,15 +47,12 @@
    Apache Software Foundation, please see <http://www.apache.org/>.
   
   */
  -
   package org.apache.avalon.phoenix.components.extensions;
   
   import java.io.File;
   import java.util.ArrayList;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  -import org.apache.avalon.excalibur.packagemanager.ExtensionManager;
  -import org.apache.avalon.excalibur.packagemanager.OptionalPackage;
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.logger.LogEnabled;
  @@ -64,13 +61,15 @@
   import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.phoenix.interfaces.ExtensionManagerMBean;
  +import org.apache.avalon.phoenix.components.extensions.pkgmgr.ExtensionManager;
  +import org.apache.avalon.phoenix.components.extensions.pkgmgr.OptionalPackage;
   
   /**
    * @author <a href="mailto:peter at apache.org">Peter Donald</a>
    * @version $Revision$ $Date$
    */
   public class DefaultExtensionManager
  -    extends org.apache.avalon.excalibur.packagemanager.impl.DefaultExtensionManager
  +    extends org.apache.avalon.phoenix.components.extensions.pkgmgr.impl.DefaultExtensionManager
       implements LogEnabled, Parameterizable, Initializable, Disposable,
       ExtensionManager, ExtensionManagerMBean
   {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message