mcconnell    2004/01/15 16:09:13

  Modified:    
merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl
                        DefaultContainmentModel.java
               merlin/kernel/api/src/java/org/apache/avalon/merlin
                        KernelCriteria.java
               merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl
                        DefaultCriteria.java DefaultFactory.java
               merlin/kernel/unit/src/java/org/apache/avalon/merlin/unit
                        package.html
  Added:       merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl
                        ArtifactHandler.java ArtifactURLConnection.java
  Log:
  Add "artifact" url handling capability.
  
  Revision  Changes    Path
  1.18      +19 -1     
avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java
  
  Index: DefaultContainmentModel.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- DefaultContainmentModel.java      13 Jan 2004 11:41:25 -0000      1.17
  +++ DefaultContainmentModel.java      16 Jan 2004 00:09:12 -0000      1.18
  @@ -1279,6 +1279,24 @@
       private ContainmentModel createContainmentModel( String name, URL url )
         throws ModelException
       {
  +        if( url.getProtocol().equals( "artifact" ) )
  +        {
  +            try
  +            {
  +                Artifact artifact = (Artifact) url.getContent();
  +                URL target = 
  +                  m_context.getSystemContext().getRepository().getResource( 
  +                    artifact );
  +                return createContainmentModel( name, target );
  +            }
  +            catch( Throwable e )
  +            {
  +                final String error = 
  +                  "Unresolvable artifact reference [" + url + "].";
  +                throw new ModelException( error, e );
  +            }
  +        }
  +
           final String path = url.toString();
   
           try
  
  
  
  1.2       +3 -1      
avalon/merlin/kernel/api/src/java/org/apache/avalon/merlin/KernelCriteria.java
  
  Index: KernelCriteria.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/merlin/kernel/api/src/java/org/apache/avalon/merlin/KernelCriteria.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- KernelCriteria.java       8 Dec 2003 15:37:12 -0000       1.1
  +++ KernelCriteria.java       16 Jan 2004 00:09:12 -0000      1.2
  @@ -192,6 +192,8 @@
   
      /**
       * Return the set of block URLs to be included in the root application
  +    * 
  +    * @param repository a repository against which artifact url may be resolved
       * @return the block deployment urls
       */
       URL[] getDeploymentURLs();
  
  
  
  1.13      +16 -6     
avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultCriteria.java
  
  Index: DefaultCriteria.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultCriteria.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- DefaultCriteria.java      21 Dec 2003 23:11:39 -0000      1.12
  +++ DefaultCriteria.java      16 Jan 2004 00:09:12 -0000      1.13
  @@ -708,6 +708,11 @@
   
       private URL resolveURL( File base, String value ) throws Exception
       {
  +        if( value.startsWith( "artifact:" ) )
  +        {
  +            return new URL( null, value, new ArtifactHandler() );
  +        }
  +
           try
           {
               return new URL( value );
  @@ -722,13 +727,18 @@
               else
               {
                   target = new File( base, value );
  -                if( target.exists() ) return toURL( target );
  +                if( target.exists() )
  +                {
  +                    return toURL( target );
  +                }
  +                else
  +                {
  +                    final String error = 
  +                      "Unable to resolve the block path [" + value + "].";
  +                    throw new KernelRuntimeException( error, e );
  +                }
               }
           }
  -
  -        final String error = 
  -          "Unable to resolve the block path [" + value + "].";
  -        throw new KernelRuntimeException( error );
       }
   
       private URL toURL( File file )
  
  
  
  1.16      +13 -11    
avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultFactory.java
  
  Index: DefaultFactory.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultFactory.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- DefaultFactory.java       15 Jan 2004 09:45:14 -0000      1.15
  +++ DefaultFactory.java       16 Jan 2004 00:09:12 -0000      1.16
  @@ -243,6 +243,15 @@
             logging.getLoggerForCategory( name );
           getLogger().debug( "logging system established" );
   
  +
  +        //
  +        // Create the system context.
  +        //
  +
  +        SystemContext systemContext = 
  +          createSystemContext( 
  +            m_context, criteria, logging, kernelConfig, name );
  +
           //
           // with the logging system established, check if the 
           // info listing mode is set and if so, generate a report
  @@ -256,14 +265,6 @@
           }
   
           //
  -        // Create the system context.
  -        //
  -
  -        SystemContext systemContext = 
  -          createSystemContext( 
  -            m_context, criteria, logging, kernelConfig, name );
  -
  -        //
           // Create the application model.  Normally the application 
           // model is empty and we will not get any errors in this 
           // process.  Development errors will normally occur when 
  @@ -373,9 +374,6 @@
           // instantiate the kernel
           //
   
  -        //Kernel kernel = 
  -        //  createKernel( getLogger(), criteria, systemContext, application );
  -
           if( criteria.isAutostartEnabled() )
           {
               getLogger().debug( "startup phase" );
  @@ -396,6 +394,10 @@
                   try
                   {
                       kernel.shutdown();
  +                    if( kernel instanceof Disposable )
  +                    {
  +                        ((Disposable)kernel).dispose();
  +                    }
                   }
                   catch( Throwable e )
                   {
  
  
  
  1.1                  
avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/ArtifactHandler.java
  
  Index: ArtifactHandler.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 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 "Jakarta", "Apache Avalon", "Avalon Framework" 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 [EMAIL PROTECTED]
  
   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.merlin.impl;
  
  import java.io.IOException;
  import java.net.URL;
  import java.net.URLConnection;
  import java.net.URLStreamHandler;
  
  import org.apache.avalon.repository.Repository;
  
  
  /**
   * Repository URL protocol handler.  
   */
  public class ArtifactHandler extends URLStreamHandler
  {
      /**
       * Opens a connection to the specified URL.
       *
       * @param url A URL to open a connection to.
       * @return The established connection.
       * @throws IOException If a connection failure occurs.
       */
      protected URLConnection openConnection( final URL url )
        throws IOException
      {
          return new ArtifactURLConnection( url );
      }
  
      protected int getDefaultPort()
      {
          return 0;
      }
  
      protected String toExternalForm( URL url )
      {
          StringBuffer result = new StringBuffer( "artifact:" );
          if (url.getFile() != null )
          {
              result.append(url.getFile());
          }
          if (url.getQuery() != null ) 
          {
              result.append("?");
              result.append(url.getQuery());
          }
          if (url.getRef() != null ) 
          {
              result.append("#");
              result.append(url.getRef());
          }
          return result.toString();
      }
  }
  
  
  
  1.1                  
avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl/ArtifactURLConnection.java
  
  Index: ArtifactURLConnection.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 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 "Jakarta", "Apache Avalon", "Avalon Framework" 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 [EMAIL PROTECTED]
  
   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.merlin.impl;
  
  import java.io.IOException;
  import java.net.URL;
  import java.net.URLConnection;
  import java.net.URLStreamHandler;
  import java.net.MalformedURLException;
  import java.util.StringTokenizer;
  
  import org.apache.avalon.repository.Artifact;
  import org.apache.avalon.activation.appliance.CascadingIOException;
  
  /**
   * Repository URL protocol handler.  
   */
  public class ArtifactURLConnection extends URLConnection
  {
      /**
       * the url
       */
       private URL m_url;
  
      /**
       * Creation of a new handler. 
       * @param context the initial context
       * @exception NullPointerException if the supplied repository argument is null
       */
       ArtifactURLConnection( URL url ) 
         throws NullPointerException, IOException
       {
           super( url );
  
           String path = url.getPath();
           int i = path.lastIndexOf( "/" );
           if( i<0 )
           {
               final String error = 
                 "Artifact specification does not contain a [group]/[name] seperator.";
               throw new MalformedURLException( error );
           }
           m_url = url;
       }
  
       public void connect()
       {
           // nothing to do
       }
  
      /**
       * Return the Artifact specified by this URL.
       * @return the artifact instance
       */
       public Object getContent() throws IOException
       {
           try
           {
               final String path = m_url.getPath();
               final int i = path.lastIndexOf( "/" );
               final String group = path.substring( 0, i );
               final String name = path.substring( i+1 );
               final String type = getType( url );
               final String version = getVersion( url );
               return Artifact.createArtifact( group, name, version, type );
           }
           catch( Throwable e )
           {
               final String error = 
                 "Unexpected exception while resolving url [" + m_url + "].";
               throw new CascadingIOException( error );
           }
       }
  
      /**
       * Return the Artifact specified by this URL.
       * @param classes a set of classes (ignored)
       * @return the artifact instance
       */
       public Object getContent( Class[] classes ) throws IOException
       {
           return getContent();
       }
  
       private String getVersion( URL url )
       {
           return getQueryField( url, "version", null );
       } 
  
       private String getType( URL url )
       {
           return getQueryField( url, "type", "jar" );
       } 
  
       private String getQueryField( URL url, String field, String fallback )
       {
           String query = url.getQuery();
           if( null != query ) 
           {
               StringTokenizer tokenizer = new StringTokenizer( query, "&" );
               while( tokenizer.hasMoreElements() )
               {
                   String token = tokenizer.nextToken();
                   if( token.startsWith( field + "=" ) )
                   {
                       return token.substring( (field.length() + 1) );
                   }
               }
           }
           return fallback;
       }
  }
  
  
  
  1.3       +1 -1      
avalon/merlin/kernel/unit/src/java/org/apache/avalon/merlin/unit/package.html
  
  Index: package.html
  ===================================================================
  RCS file: 
/home/cvs/avalon/merlin/kernel/unit/src/java/org/apache/avalon/merlin/unit/package.html,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- package.html      13 Oct 2003 01:28:27 -0000      1.2
  +++ package.html      16 Jan 2004 00:09:13 -0000      1.3
  @@ -1,7 +1,7 @@
   
   <body>
   <p>
  -Pending.
  +Merlin kernel embedded in a UnitTest.
   </p>
   </body>
   
  
  
  

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

Reply via email to