ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/manifest selftest-extension1.mf selftest.mf selftest-ant-descriptor.xml
Date Mon, 26 Nov 2001 11:11:44 GMT
donaldp     01/11/26 03:11:44

  Modified:    proposal/myrmidon build.xml
               proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer
                        DefaultDeployer.java Resources.properties
               proposal/myrmidon/src/make primitive-tests.ant sample.ant
               proposal/myrmidon/src/manifest selftest-ant-descriptor.xml
  Added:       proposal/myrmidon/src/java/org/apache/myrmidon/libs/selftest
                        ExtensionsTest.java
               proposal/myrmidon/src/java/org/apache/myrmidon/libs/selftest/extension1
                        ExtensionsLoadedClass.java
               proposal/myrmidon/src/manifest selftest-extension1.mf
                        selftest.mf
  Log:
  Added code to allow type libraries to depend upon "Optional Packages" aka "Extensions".
  
  Also add code to seltest type library so that it verifies that classes loaded from extension
are available in the same ClassLoader as the tasks.
  
  Revision  Changes    Path
  1.23      +11 -1     jakarta-ant/proposal/myrmidon/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/build.xml,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- build.xml	2001/11/06 08:09:59	1.22
  +++ build.xml	2001/11/26 11:11:43	1.23
  @@ -164,13 +164,22 @@
         </zipfileset>
       </jar>
   
  -    <jar jarfile="${build.lib}/selftest.atl" basedir="${build.classes}">
  +    <jar jarfile="${build.lib}/selftest.atl" 
  +         basedir="${build.classes}"
  +         manifest="${manifest.dir}/selftest.mf">
         <include name="org/apache/myrmidon/libs/selftest/**" />
  +      <exclude name="org/apache/myrmidon/libs/selftest/extension1/**" />
         <zipfileset dir="${manifest.dir}" fullpath="META-INF/ant-descriptor.xml">
           <include name="selftest-ant-descriptor.xml"/>
         </zipfileset>
       </jar>
   
  +    <jar jarfile="${build.lib}/selftest-extension1.jar" 
  +         basedir="${build.classes}"
  +         manifest="${manifest.dir}/selftest-extension1.mf">
  +      <include name="org/apache/myrmidon/libs/selftest/extension1/**" />
  +    </jar>
  +
       <jar jarfile="${build.lib}/runtime.atl" basedir="${build.classes}">
         <include name="org/apache/myrmidon/libs/runtime/**"/>
         <zipfileset dir="${manifest.dir}" fullpath="META-INF/ant-descriptor.xml">
  @@ -209,6 +218,7 @@
       <copy todir="${dist.ext}">
         <fileset dir="${build.lib}">
           <include name="selftest.atl"/>
  +        <include name="selftest-extension1.jar"/>
         </fileset>
       </copy>
   
  
  
  
  1.8       +107 -12   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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DefaultDeployer.java	2001/11/19 12:37:25	1.7
  +++ DefaultDeployer.java	2001/11/26 11:11:43	1.8
  @@ -9,28 +9,37 @@
   
   import java.io.File;
   import java.net.URL;
  +import java.net.MalformedURLException;
   import java.net.URLClassLoader;
  +import java.net.JarURLConnection;
  +import java.util.Arrays;
  +import java.util.ArrayList;
   import java.util.Enumeration;
  +import java.util.jar.Manifest;
   import java.util.HashMap;
   import javax.xml.parsers.SAXParser;
   import javax.xml.parsers.SAXParserFactory;
  +import org.apache.avalon.excalibur.extension.PackageManager;
  +import org.apache.avalon.excalibur.extension.OptionalPackage;
  +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.framework.activity.Initializable;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.Composable;
  +import org.apache.avalon.framework.configuration.ClassicSAXConfigurationHandler;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.avalon.framework.configuration.SAXConfigurationHandler;
   import org.apache.avalon.framework.logger.AbstractLoggable;
   import org.apache.myrmidon.api.Task;
  -import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
   import org.apache.myrmidon.converter.Converter;
   import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
   import org.apache.myrmidon.interfaces.deployer.DeploymentException;
  +import org.apache.myrmidon.interfaces.extensions.ExtensionManager;
   import org.apache.myrmidon.interfaces.role.RoleManager;
  +import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
   import org.apache.myrmidon.interfaces.type.TypeManager;
   import org.xml.sax.SAXException;
   import org.xml.sax.XMLReader;
  @@ -49,9 +58,10 @@
   
       private final static String TYPE_DESCRIPTOR = "META-INF/ant-types.xml";
   
  -    private ConverterRegistry            m_converterRegistry;
  -    private TypeManager                  m_typeManager;
  -    private RoleManager                  m_roleManager;
  +    private ConverterRegistry    m_converterRegistry;
  +    private TypeManager          m_typeManager;
  +    private RoleManager          m_roleManager;
  +    private PackageManager       m_packageManager;
   
       /**
        * Retrieve relevent services needed to deploy.
  @@ -65,6 +75,10 @@
           m_converterRegistry = (ConverterRegistry)componentManager.lookup( ConverterRegistry.ROLE
);
           m_typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE );
           m_roleManager = (RoleManager)componentManager.lookup( RoleManager.ROLE );
  +
  +        final ExtensionManager extensionManager =
  +            (ExtensionManager)componentManager.lookup( ExtensionManager.ROLE );
  +        m_packageManager = new PackageManager( extensionManager );
       }
   
       public void initialize()
  @@ -75,7 +89,7 @@
           final XMLReader parser = saxParser.getXMLReader();
           //parser.setFeature( "http://xml.org/sax/features/namespace-prefixes", false );
   
  -        final SAXConfigurationHandler handler = new SAXConfigurationHandler();
  +        final ClassicSAXConfigurationHandler handler = new ClassicSAXConfigurationHandler();
           parser.setContentHandler( handler );
           parser.setErrorHandler( handler );
   
  @@ -106,14 +120,16 @@
   
           checkFile( file );
   
  -        final Deployment deployment = new Deployment( file );
  -        final Configuration descriptor = deployment.getDescriptor();
  -        final URL[] urls = new URL[] { deployment.getURL() };
  -        final URLClassLoader classLoader =
  -            new URLClassLoader( urls, Thread.currentThread().getContextClassLoader() );
  -
           try
           {
  +            final File[] extensions = getOptionalPackagesFor( file );
  +            final URL[] urls = buildClasspath( file, extensions );
  +            final Deployment deployment = new Deployment( file );
  +            final Configuration descriptor = deployment.getDescriptor();
  +            
  +            final URLClassLoader classLoader =
  +                new URLClassLoader( urls, Thread.currentThread().getContextClassLoader()
);
  +
               deployFromDescriptor( descriptor, classLoader, deployment.getURL() );
           }
           catch( final DeploymentException de )
  @@ -196,6 +212,85 @@
               final String message = REZ.getString( "deploy-type.error", name );
               throw new DeploymentException( message, e );
           }
  +    }
  +
  +    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", Arrays.asList( available ) );
  +            getLogger().debug( message1 );
  +            final String message2 = 
  +                REZ.getString( "required-extensions", 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 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 );
  +                getLogger().warn( message );
  +            }
  +
  +            final String message =
  +                REZ.getString( "unsatisfied.extensions", new Integer( size ) );
  +            throw new Exception( message );
  +        }
  +
  +        final OptionalPackage[] packages =
  +            (OptionalPackage[])dependencies.toArray( new OptionalPackage[ 0 ] );
  +        return OptionalPackage.toFiles( packages );
       }
   
       private void deployFromDescriptor( final Configuration descriptor,
  
  
  
  1.4       +7 -0      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Resources.properties	2001/11/19 12:37:25	1.3
  +++ Resources.properties	2001/11/26 11:11:43	1.4
  @@ -15,3 +15,10 @@
   bad-url.error=Unable to form url from file {0}.
   bad-parser.error=Error configuring parser.
   bad-read.error=Error reading configuration.
  +
  +available-extensions=The list of available extensions for Type Library includes; {0}
  +required-extensions=The list of required extensions for Type Library includes; {0}
  +optional-packages-added=The list of "Optional Packages" added to the Type Library includes;
{0}
  +classpath-entries=The list of classpath entrys for the Type Library includes; {0}
  +missing.extension=Unable to locate an extension that is required by Type Library.\nExtension
Name: {0}\nSpecification Vendor: {1}\nSpecification Version: {2}\nImplementation Vendor: {3}\nImplementation
Vendor-Id: {4}\nImplementation Version: {5}\nImplementation URL: {6}
  +unsatisfied.extensions=Missing {0} extensions and thus can not build ClassLoader for Type
Library.
  \ No newline at end of file
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/libs/selftest/ExtensionsTest.java
  
  Index: ExtensionsTest.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 file.
   */
  package org.apache.myrmidon.libs.selftest;
  
  import org.apache.myrmidon.api.AbstractTask;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.libs.selftest.extension1.ExtensionsLoadedClass;
  
  /**
   * This is to test whether extension is loaded.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public class ExtensionsTest
      extends AbstractTask
  {
      public void execute()
          throws TaskException
      {
          ExtensionsLoadedClass.doSomething();
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/libs/selftest/extension1/ExtensionsLoadedClass.java
  
  Index: ExtensionsLoadedClass.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 file.
   */
  package org.apache.myrmidon.libs.selftest.extension1;
  
  import org.apache.myrmidon.api.AbstractTask;
  import org.apache.myrmidon.api.TaskException;
  
  /**
   * This is to test whether extension is loaded.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public class ExtensionsLoadedClass
  {
      public static void doSomething()
      {
          System.out.println( "This was loaded via an extension - yea!" );
      }
  }
  
  
  
  1.5       +5 -1      jakarta-ant/proposal/myrmidon/src/make/primitive-tests.ant
  
  Index: primitive-tests.ant
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/make/primitive-tests.ant,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- primitive-tests.ant	2001/08/29 16:13:33	1.4
  +++ primitive-tests.ant	2001/11/26 11:11:44	1.5
  @@ -41,7 +41,7 @@
       <echo message="No tests done here"/>
     </target>
   
  -  <target name="test-target" depends="no-test-target" unless="no-do-tests">
  +  <target name="test-target" depends="no-test-target,extensions-test" unless="no-do-tests">
   
       <echo message="Tests away"/>
   
  @@ -70,6 +70,10 @@
       
       <content-test>123</content-test>
       
  +  </target>
  +
  +  <target name="extensions-test">
  +    <extensions-test/>
     </target>
   
   </project>
  
  
  
  1.15      +2 -2      jakarta-ant/proposal/myrmidon/src/make/sample.ant
  
  Index: sample.ant
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/make/sample.ant,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- sample.ant	2001/11/06 08:09:59	1.14
  +++ sample.ant	2001/11/26 11:11:44	1.15
  @@ -6,7 +6,7 @@
    Sample build file
   
   Authors:
  - Peter Donald <donaldp@apache.org>
  + Peter Donald <peterp@apache.org>
   
   Legal:
     Copyright (c) 2000 The Apache Software Foundation. All Rights Reserved.
  @@ -20,7 +20,7 @@
   
     <property name="year" value="2000"/>
   
  -  <target name="main" depends="typedef-test, converterdef-test, datatype-test, namespace-test,
ant1-tasklib-test, prim->file-manip" />
  +  <target name="main" depends="typedef-test, converterdef-test, datatype-test, namespace-test,
ant1-tasklib-test, prim->file-manip, prim->extensions-test" />
   
     <target name="xp-deployer-test" depends="typedef-test, prim->undefined-task" />
   
  
  
  
  1.4       +1 -0      jakarta-ant/proposal/myrmidon/src/manifest/selftest-ant-descriptor.xml
  
  Index: selftest-ant-descriptor.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/manifest/selftest-ant-descriptor.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- selftest-ant-descriptor.xml	2001/07/08 07:29:24	1.3
  +++ selftest-ant-descriptor.xml	2001/11/26 11:11:44	1.4
  @@ -6,5 +6,6 @@
       <task name="conf-test" classname="org.apache.myrmidon.libs.selftest.ConfigurationTest"
/>
       <task name="content-test" classname="org.apache.myrmidon.libs.selftest.ContentTest"
/>
       <task name="file-manip-test" classname="org.apache.myrmidon.libs.selftest.FileManipulationTest"
/>
  +    <task name="extensions-test" classname="org.apache.myrmidon.libs.selftest.ExtensionsTest"
/>
     </types>
   </ant-lib>
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/manifest/selftest-extension1.mf
  
  Index: selftest-extension1.mf
  ===================================================================
  Manifest-Version: 1.0
  Extension-Name: cornerstone.test.extension
  Specification-Title: Avalon Cornerstone Test Extension
  Specification-Version: 1.1
  Specification-Vendor: Jakarta Apache
  Implementation-Vendor-Id: org.apache.avalon
  Implementation-Vendor: Apache Avalon Project
  Implementation-Version: 1.0.2
  
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/manifest/selftest.mf
  
  Index: selftest.mf
  ===================================================================
  Manifest-Version: 1.0
  Created-By: Apache Avalon Project
  Extension-Name: cornerstone.demo.simple
  Specification-Title: Avalon Cornerstone SimpleServer Demo Extension
  Implementation-Vendor-Id: org.apache.avalon
  Implementation-Vendor: Apache Avalon Project
  Extension-List: required1 
  required1-Extension-Name: cornerstone.test.extension
  required1-Specification-Version: 1.0
  required1-Implementation-Version: 1.0.2
  required1-Implementation-Vendor-Id: org.apache.avalon
  
  
  

--
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