Author: mcconnell
Date: Sun Jun 27 17:12:28 2004
New Revision: 22204

Added:
   avalon/trunk/central/laboratory/cache/etc/deliverables/
   avalon/trunk/central/laboratory/cache/etc/deliverables/blocks/
   avalon/trunk/central/laboratory/cache/etc/deliverables/blocks/avalon-cache.xml
Modified:
   avalon/trunk/central/laboratory/cache/   (props changed)
   avalon/trunk/central/laboratory/cache/build.xml
   avalon/trunk/central/laboratory/cache/etc/main/BLOCK-INF/block.xml
   avalon/trunk/central/system/index.xml
   avalon/trunk/runtime/merlin/cli/src/java/org/apache/avalon/merlin/cli/Main.java
   
avalon/trunk/runtime/merlin/impl/src/java/org/apache/avalon/merlin/impl/DefaultKernel.java
   
avalon/trunk/runtime/repository/util/src/java/org/apache/avalon/repository/util/LoaderUtils.java
   
avalon/trunk/runtime/util/defaults/src/java/org/apache/avalon/util/defaults/DefaultsBuilder.java
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Home.java
   avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Resource.java
Log:


Modified: avalon/trunk/central/laboratory/cache/build.xml
==============================================================================
--- avalon/trunk/central/laboratory/cache/build.xml     (original)
+++ avalon/trunk/central/laboratory/cache/build.xml     Sun Jun 27 17:12:28 2004
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>

 

-<project name="avalon-planet-cache" default="install" basedir="." 

+<project name="avalon-cache" default="install" basedir="." 

     xmlns:x="antlib:org.apache.avalon.tools">

 

   <x:home index="../../system/index.xml"/>


Added: avalon/trunk/central/laboratory/cache/etc/deliverables/blocks/avalon-cache.xml
==============================================================================
--- (empty file)
+++ avalon/trunk/central/laboratory/cache/etc/deliverables/blocks/avalon-cache.xml     
 Sun Jun 27 17:12:28 2004
@@ -0,0 +1,33 @@
+

+<!--

+Embedded block directive for cache component.

+-->

+

+<container name="repository">

+

+   <!-- TODO: figure out how to put the classpath in automatically -->

+

+   <classloader>

+     <classpath>

+       <artifact>jar:avalon/framework/avalon-framework-api#4.3.0-DEV</artifact>

+       <artifact>jar:avalon/repository/avalon-repository-main#2.1.0-DEV</artifact>

+       <artifact>jar:avalon/repository/avalon-repository-spi#2.0.0</artifact>

+       <artifact>jar:avalon/repository/avalon-repository-api#2.1.0-DEV</artifact>

+       <artifact>jar:avalon/repository/avalon-repository-util#2.0.0</artifact>

+       <artifact>jar:avalon/util/avalon-util-exception#1.0.0</artifact>

+       <artifact>jar:avalon/util/avalon-util-env#1.1.1</artifact>

+       <artifact>jar:avalon/util/avalon-util-i18n#1.0.0</artifact>

+       <artifact>jar:avalon/util/avalon-util-criteria#1.1.0</artifact>

+       <artifact>jar:avalon/util/avalon-util-defaults#1.2.1</artifact>

+       <artifact>jar:avalon/planet/avalon-cache#1.0.0-DEV</artifact>

+     </classpath>

+   </classloader>

+

+   <services>

+     <service type="org.apache.avalon.repository.Repository"/>

+   </services>

+

+   <component name="cache"

+       class="org.apache.avalon.cache.DefaultCache"/>

+

+</container>


Modified: avalon/trunk/central/laboratory/cache/etc/main/BLOCK-INF/block.xml
==============================================================================
--- avalon/trunk/central/laboratory/cache/etc/main/BLOCK-INF/block.xml  (original)
+++ avalon/trunk/central/laboratory/cache/etc/main/BLOCK-INF/block.xml  Sun Jun 27 
17:12:28 2004
@@ -19,7 +19,7 @@
        <artifact>jar:avalon/util/avalon-util-i18n#1.0.0</artifact>

        <artifact>jar:avalon/util/avalon-util-criteria#1.1.0</artifact>

        <artifact>jar:avalon/util/avalon-util-defaults#1.2.1</artifact>

-       <artifact>jar:avalon/planet/avalon-planet-cache#1.0.0-DEV</artifact>

+       <artifact>jar:avalon/planet/avalon-cache#1.0.0-DEV</artifact>

      </classpath>

    </classloader>

 


Modified: avalon/trunk/central/system/index.xml
==============================================================================
--- avalon/trunk/central/system/index.xml       (original)
+++ avalon/trunk/central/system/index.xml       Sun Jun 27 17:12:28 2004
@@ -227,7 +227,8 @@
     <info>

       <group>avalon/util</group>

       <name>avalon-util-defaults</name>

-      <version>1.2.1</version>

+      <version>1.2.2</version> <!-- bumped to 1.2.2 to fix bug accessing Env variable 
-->

+      <status>SNAPSHOT</status> 

     </info>

     <dependencies>

       <include key="avalon-util-env"/>

@@ -869,6 +870,27 @@
       <include key="jms"/>

     </dependencies>

   </project>

+

+  <!--

+  Avalon Laboratory.

+  -->

+

+  <project basedir="../laboratory/cache">

+    <info>

+      <group>avalon/planet</group>

+      <name>avalon-cache</name>

+      <version>1.0.0</version>

+      <status>SNAPSHOT</status>

+    </info>

+    <dependencies>

+      <include key="avalon-framework-api"/>

+      <include key="avalon-repository-main"/>

+    </dependencies>

+    <plugins>

+      <include key="avalon-meta-tools"/>

+    </plugins>

+  </project>

+

 

   <!--

   <project basedir="../../runtime/merlin/unit">


Modified: 
avalon/trunk/runtime/merlin/cli/src/java/org/apache/avalon/merlin/cli/Main.java
==============================================================================
--- avalon/trunk/runtime/merlin/cli/src/java/org/apache/avalon/merlin/cli/Main.java    
 (original)
+++ avalon/trunk/runtime/merlin/cli/src/java/org/apache/avalon/merlin/cli/Main.java    
 Sun Jun 27 17:12:28 2004
@@ -197,7 +197,8 @@
     * @param args the command line arguments
     */
     public static void main( String[] args )
-    {
+    {

+        boolean debug = false;
         try
         {
             //
@@ -210,6 +211,8 @@
             File dir = getWorkingDirectory( line );
             File cache = getMerlinSystemRepository( line );
             Artifact artifact = getDefaultImplementation( dir, line );
+

+            debug = line.hasOption( "debug" );

 
             if( line.hasOption( "version" ) )
             {
@@ -253,22 +256,31 @@
                 //
 
                 MAIN = new Main( context, artifact, line );
-            }
-        }
-        catch( Throwable e )
-        {
-            String msg = 
-              ExceptionHelper.packException( e, true );
-            System.err.println( msg );
-            System.exit( -1 );
-        }
+            }

+        }

+        catch( Exception exception )

+        {

+            String msg = 

+              ExceptionHelper.packException( exception, debug );

+            System.err.println( msg );

+            System.exit( -1 );

+        }

+        catch( Throwable throwable )

+        {

+            String msg = 

+              ExceptionHelper.packException( throwable, true );

+            System.err.println( msg );

+            System.exit( -1 );

+        }

     }
 
     //----------------------------------------------------------
     // immutable state
     //----------------------------------------------------------
 
-    private final Object m_kernel;
+    private final Object m_kernel;

+

+    private boolean m_debug;
 
     //----------------------------------------------------------
     // constructor
@@ -286,7 +298,7 @@
     {
         Builder builder = context.newBuilder( artifact );
         Factory factory = builder.getFactory();
-        Map criteria = factory.createDefaultCriteria();
+        Map criteria = factory.createDefaultCriteria();

 
         //
         // update the criteria using the command line information
@@ -388,7 +400,7 @@
     {
         if( line.hasOption( "debug" ) )
         {
-            criteria.put( "merlin.debug", new Boolean( true ) );
+            criteria.put( "merlin.debug", new Boolean( true ) );

         }
     }
 

Modified: 
avalon/trunk/runtime/merlin/impl/src/java/org/apache/avalon/merlin/impl/DefaultKernel.java
==============================================================================
--- 
avalon/trunk/runtime/merlin/impl/src/java/org/apache/avalon/merlin/impl/DefaultKernel.java
  (original)
+++ 
avalon/trunk/runtime/merlin/impl/src/java/org/apache/avalon/merlin/impl/DefaultKernel.java
  Sun Jun 27 17:12:28 2004
@@ -23,7 +23,8 @@
 import org.apache.avalon.merlin.Kernel;
 import org.apache.avalon.merlin.KernelContext;
 import org.apache.avalon.merlin.KernelError;
-import org.apache.avalon.merlin.KernelException;
+import org.apache.avalon.merlin.KernelException;

+import org.apache.avalon.merlin.KernelRuntimeException;

 import org.apache.avalon.merlin.event.KernelEventListener;
 import org.apache.avalon.merlin.event.KernelStateEvent;
 
@@ -66,8 +67,6 @@
 
     private final KernelContext m_context;
 
-    //private final Block m_application;
-
     private final State m_state;
 
     //--------------------------------------------------------------
@@ -92,8 +91,6 @@
         try
         {
             m_model = context.getApplicationModel();
-            //m_application = 
-            //  new DefaultBlock( context.getApplicationModel() );
         }
         catch( Throwable e )
         {
@@ -185,13 +182,20 @@
                 setState( ASSEMBLY );
                 m_model.assemble();
             }
-            catch( Throwable e )
+            catch( Exception e )
             {
                 setState( INITIALIZED );
                 final String error =
-                  "Cannot assemble application.";
+                  "Cannot assemble application due to exception.";
                 throw new KernelException( error, e );
             }
+            catch( Throwable e )

+            {

+                setState( INITIALIZED );

+                final String error =

+                  "Cannot assemble application due to throwable.";

+                throw new KernelRuntimeException( error, e );

+            }

 
             if( getLogger().isDebugEnabled() )
             {
@@ -203,13 +207,20 @@
                 setState( DEPLOYMENT );
                 m_model.commission();
             }
-            catch( Throwable e )
+            catch( Exception e )
             {
                 setState( INITIALIZED );
                 final String error =
                   "Cannot deploy application.";
                 throw new KernelException( error, e );
             }
+            catch( Throwable e )

+            {

+                setState( INITIALIZED );

+                final String error =

+                  "Cannot deploy application.";

+                throw new KernelRuntimeException( error, e );

+            }

             
             setState( STARTED );
         }

Modified: 
avalon/trunk/runtime/repository/util/src/java/org/apache/avalon/repository/util/LoaderUtils.java
==============================================================================
--- 
avalon/trunk/runtime/repository/util/src/java/org/apache/avalon/repository/util/LoaderUtils.java
    (original)
+++ 
avalon/trunk/runtime/repository/util/src/java/org/apache/avalon/repository/util/LoaderUtils.java
    Sun Jun 27 17:12:28 2004
@@ -30,6 +30,7 @@
 
 import org.apache.avalon.repository.Artifact;
 import org.apache.avalon.repository.RepositoryException;
+import org.apache.avalon.repository.RepositoryRuntimeException;

 
 
 /**
@@ -64,8 +65,6 @@
         String [] repositories, File root, boolean timestamping ) 
         throws RepositoryException
     {
-        Exception cause = null;
-
         File destination = new File( root, artifact.getPath() );
 
         if( !m_online )
@@ -95,23 +94,18 @@
                 return getResource( url, destination, timestamping ) ;
             }
             catch ( Exception e )
-            {
-                cause = e ;
+            {

+                // ignore

             }
         }
 
         if( destination.exists() ) return getURL( destination );
-        
-        StringBuffer buffer = new StringBuffer();
-        buffer.append(
-          "Failed to download artifact to local cache file " 
-          + destination.getAbsolutePath() 
-          + " from hosts: " );
-        for( int i=0; i<repositories.length; i++ )
-        {
-            buffer.append( "\n  " + repositories[i] );
-        }
-        throw new RepositoryException( buffer.toString(), cause );
+        

+        final String error =

+          "Unknown artifact: [" 

+          + artifact 

+          + "].";

+        throw new RepositoryException( error );

     }
 
     /**
@@ -143,8 +137,6 @@
         if( null == repositories ) 
           throw new NullPointerException( "repositories" );
 
-        Exception cause = null;
-
         File destination = 
           new File( root, artifact.getPath() + "." + mime );
         
@@ -177,22 +169,19 @@
             }
             catch ( Exception e )
             {
-                cause = e ;
+                // ignore
             }
         }
 
         if( destination.exists() ) return getURL( destination );
         
-        StringBuffer buffer = new StringBuffer();
-        buffer.append(
-          "Failed to download mime artifact to local cache file " 
-          + destination.getAbsolutePath() 
-          + " from hosts: " );
-        for( int i=0; i<repositories.length; i++ )
-        {
-            buffer.append( "\n  " + repositories[i] );
-        }
-        throw new RepositoryException( buffer.toString(), cause );
+        final String error =

+          "Unknown artifact: [" 

+          + artifact 

+          + "." 

+          + mime 

+          + "].";

+        throw new RepositoryException( error );
     }
     
     /**
@@ -206,7 +195,7 @@
      */
     public URL getResource( 
       String url, File destination, boolean timestamping ) 
-      throws Exception
+      throws RepositoryException, IOException
     {
 
         boolean update = destination.exists();
@@ -242,7 +231,9 @@
             }
             catch( Throwable e )
             {
-                e.printStackTrace();
+                final String error = 

+                  "Unexpected error while handling resource request.";

+                throw new RepositoryRuntimeException( error, e );
             }
         }
 
@@ -336,7 +327,7 @@
             if ( httpConnection.getResponseCode() == 
                     HttpURLConnection.HTTP_UNAUTHORIZED )
             {
-                throw new Exception( "Not authorized." ) ;
+                throw new IOException( "Not authorized." ) ;
             }
         }
 
@@ -361,7 +352,7 @@
         if ( in == null )
         {
             final String error = 
-              "Connection returned a null input stream: " + url ;
+              "Unknown resource: " + url ;
             throw new IOException( error ) ;
         }
 

Modified: 
avalon/trunk/runtime/util/defaults/src/java/org/apache/avalon/util/defaults/DefaultsBuilder.java
==============================================================================
--- 
avalon/trunk/runtime/util/defaults/src/java/org/apache/avalon/util/defaults/DefaultsBuilder.java
    (original)
+++ 
avalon/trunk/runtime/util/defaults/src/java/org/apache/avalon/util/defaults/DefaultsBuilder.java
    Sun Jun 27 17:12:28 2004
@@ -59,7 +59,7 @@
         final String home = 
           System.getProperty( 
             homeKey, 
-            Env.getEnvVariable( symbol ) );
+            getEnvironmentVariable( symbol ) );
 
         if( null != home )
         {
@@ -72,6 +72,18 @@
             final String path = "." + key;
             return new File( user, path ).getCanonicalFile();
         }
+    }

+

+    private static String getEnvironmentVariable( String symbol )

+    {

+        try

+        {

+            return Env.getEnvVariable( symbol );

+        }

+        catch( Throwable e )

+        {

+            return null;

+        }

     }
 
    /**

Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Home.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Home.java   
(original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Home.java   Sun 
Jun 27 17:12:28 2004
@@ -20,12 +20,14 @@
 import org.apache.tools.ant.BuildException;

 import org.apache.tools.ant.BuildListener;

 import org.apache.tools.ant.Project;

+import org.apache.tools.ant.taskdefs.Get;

 import org.apache.tools.ant.taskdefs.Property;

 import org.apache.tools.ant.types.DataType;

 import org.w3c.dom.Element;

 

 import java.io.File;

 import java.io.IOException;

+import java.net.URL;

 import java.util.ArrayList;

 import java.util.Hashtable;

 

@@ -212,10 +214,37 @@
                   + " key=" + key, Project.MSG_VERBOSE );

             }

             else if( "import".equals( element.getTagName() ) )

-            { 

-                final String path = element.getAttribute( "index" );

-                final File index = Context.getFile( system, path );

-                buildList( index, true );

+            {

+                final String path = element.getAttribute( "href" );

+                if(( null != path ) && ( !"".equals( path ) ))

+                {

+                    File index = createTempFile();

+                    index.deleteOnExit(); // safety harness in case we abort

+                    final URL url = createURL( path );

+                    final Get get = (Get) project.createTask( "get" );

+                    get.setSrc( url );

+                    get.setDest( index );

+                    get.setIgnoreErrors( false );

+                    get.setUseTimestamp( true );

+                    get.setVerbose( false );

+                    get.execute();

+                    buildList( index, true );

+                }

+                else

+                {

+                    final String filename = element.getAttribute( "index" );

+                    if(( null != filename ) && ( !"".equals( filename ) ))

+                    {

+                        final File index = Context.getFile( system, path );

+                        buildList( index, true );

+                    }

+                    else

+                    {

+                        final String error = 

+                          "Invalid import - no href or index attribute.";

+                        throw new BuildException( error );

+                    }

+                }

             }

             else

             {

@@ -223,6 +252,30 @@
                   "Unrecognized element type \"" + tag + "\".";

                 throw new BuildException( error );

             }

+        }

+    }

+

+    private URL createURL( String path )

+    {

+        try

+        {

+            return new URL( path );

+        }

+        catch( IOException ioe )

+        {

+            throw new BuildException( ioe );

+        }

+    }

+

+    private File createTempFile()

+    {

+        try

+        {

+            return File.createTempFile( "~magic", ".tmp" );

+        }

+        catch( IOException ioe )

+        {

+            throw new BuildException( ioe );

         }

     }

 


Modified: avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Resource.java
==============================================================================
--- avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Resource.java      
 (original)
+++ avalon/trunk/tools/magic/src/main/org/apache/avalon/tools/model/Resource.java      
 Sun Jun 27 17:12:28 2004
@@ -99,7 +99,7 @@
                 final Get get = (Get) project.createTask( "get" );

                 get.setSrc( source );

                 get.setDest( target );

-                get.setIgnoreErrors( false );

+                get.setIgnoreErrors( true );

                 get.setUseTimestamp( true );

                 get.setVerbose( false );

                 get.execute();


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

Reply via email to