You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ni...@apache.org on 2004/08/08 13:54:32 UTC

svn commit: rev 36082 - in avalon/trunk/planet/facilities: . console/api/src/main/org/apache/avalon/facilities/console console/blocks/default console/commands/src/main/org/apache/avalon/facilities/console/commands console/impl/src/main/org/apache/avalon/facilities/console/impl

Author: niclas
Date: Sun Aug  8 04:54:31 2004
New Revision: 36082

Added:
   avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/facilities/console/CommandException.java   (contents, props changed)
   avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/facilities/console/LoginException.java
      - copied, changed from rev 36057, avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/LoginException.java
   avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/DeployCmd.java   (contents, props changed)
   avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/RedeployCmd.java   (contents, props changed)
   avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/UndeployCmd.java   (contents, props changed)
   avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/UrlUtils.java   (contents, props changed)
Removed:
   avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/LoginException.java
Modified:
   avalon/trunk/planet/facilities/console/blocks/default/build.xml
   avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/ListCmd.java
   avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/CommandInterpreterImpl.java
   avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/ConsoleImpl.java
   avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/LoginCmd.java
   avalon/trunk/planet/facilities/index.xml
Log:
Added 'deploy block'  and 'undeploy block' commands.

Added: avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/facilities/console/CommandException.java
==============================================================================
--- (empty file)
+++ avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/facilities/console/CommandException.java	Sun Aug  8 04:54:31 2004
@@ -0,0 +1,26 @@
+/*
+ * Copyright 1997-2004 Apache Software Foundation
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avalon.facilities.console;
+
+
+public class CommandException extends Exception
+{
+    public CommandException( String message )
+    {
+        super( message );
+    }
+}
+

Copied: avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/facilities/console/LoginException.java (from rev 36057, avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/LoginException.java)
==============================================================================
--- avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/LoginException.java	(original)
+++ avalon/trunk/planet/facilities/console/api/src/main/org/apache/avalon/facilities/console/LoginException.java	Sun Aug  8 04:54:31 2004
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.avalon.facilities.console.impl;
+package org.apache.avalon.facilities.console;
 
 
 public class LoginException extends Exception

Modified: avalon/trunk/planet/facilities/console/blocks/default/build.xml
==============================================================================
--- avalon/trunk/planet/facilities/console/blocks/default/build.xml	(original)
+++ avalon/trunk/planet/facilities/console/blocks/default/build.xml	Sun Aug  8 04:54:31 2004
@@ -49,6 +49,15 @@
     
       <x:component name="select" 
                    class="org.apache.avalon.facilities.console.commands.SelectCmd"/>
+    
+      <x:component name="deploy block" 
+                   class="org.apache.avalon.facilities.console.commands.DeployCmd"/>
+      
+      <x:component name="undeploy block" 
+                   class="org.apache.avalon.facilities.console.commands.UndeployCmd"/>
+    
+      <x:component name="redeploy block" 
+                   class="org.apache.avalon.facilities.console.commands.RedeployCmd"/>
     </x:block>
   </target>
 

Added: avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/DeployCmd.java
==============================================================================
--- (empty file)
+++ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/DeployCmd.java	Sun Aug  8 04:54:31 2004
@@ -0,0 +1,102 @@
+/*
+ * Copyright 1997-2004 Apache Software Foundation
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avalon.facilities.console.commands;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+
+import java.net.URL;
+
+import org.apache.avalon.composition.model.ComponentModel;
+import org.apache.avalon.composition.model.ContainmentModel;
+import org.apache.avalon.composition.model.DeploymentModel;
+
+import org.apache.avalon.facilities.console.CommandException;
+import org.apache.avalon.facilities.console.CommandInterpreter;
+import org.apache.avalon.facilities.console.Console;
+import org.apache.avalon.facilities.console.ConsoleCommand;
+
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+
+/**
+ * @avalon.component name="console-decommissionmodel" lifestyle="singleton"
+ * @avalon.service type="org.apache.avalon.facilities.console.ConsoleCommand"
+ */
+public class DeployCmd
+    implements ConsoleCommand, Serviceable, Contextualizable
+{
+    private String m_Name;
+    private File   m_WorkingDir;
+        
+    public String getName()
+    {
+        return m_Name;
+    }
+    
+    public String getDescription()
+    {
+        String str = "usage: " + m_Name + " (url) (target-path)\n\nLoads and commissions the block at the URL into the model specified by (target-path)";
+        return str;
+    }
+    
+    /**
+     * Contextulaization of the listener by the container during 
+     * which we are supplied with the root composition model for 
+     * the application.
+     *
+     * @param ctx the supplied listener context
+     *
+     * @exception ContextException if a contextualization error occurs
+     *
+     * @avalon.entry key="urn:avalon:name" 
+     *               type="java.lang.String" 
+     * @avalon.entry key="urn:avalon:home" 
+     *               type="java.io.File" 
+     */
+    public void contextualize( Context ctx ) 
+        throws ContextException
+    {
+        m_Name = (String) ctx.get( "urn:avalon:name" );
+        m_WorkingDir = (File) ctx.get( "urn:avalon:home" );
+    }
+
+    /**
+     * @avalon.dependency type="org.apache.avalon.facilities.console.Console"
+     *                    key="console"
+     */
+    public void service( ServiceManager man )
+        throws ServiceException
+    {
+        Console console = (Console) man.lookup( "console" );
+        console.addCommand( this );
+    }
+    
+    public void execute( CommandInterpreter intp, BufferedReader input, BufferedWriter output, String[] arguments )
+        throws Exception
+    {
+        output.newLine();
+        output.flush();
+    }
+}
+ 

Modified: avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/ListCmd.java
==============================================================================
--- avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/ListCmd.java	(original)
+++ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/ListCmd.java	Sun Aug  8 04:54:31 2004
@@ -94,7 +94,7 @@
         ContainmentModel current = intp.getCurrentContainer();
         String path;
         if( arguments.length == 0 )
-            path = current.getPath();
+            path = current.getQualifiedName();
         else
             path = arguments[0];
             

Added: avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/RedeployCmd.java
==============================================================================
--- (empty file)
+++ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/RedeployCmd.java	Sun Aug  8 04:54:31 2004
@@ -0,0 +1,124 @@
+/*
+ * Copyright 1997-2004 Apache Software Foundation
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avalon.facilities.console.commands;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+
+import java.net.URL;
+
+import org.apache.avalon.composition.model.ComponentModel;
+import org.apache.avalon.composition.model.ContainmentModel;
+import org.apache.avalon.composition.model.DeploymentModel;
+
+import org.apache.avalon.facilities.console.CommandException;
+import org.apache.avalon.facilities.console.CommandInterpreter;
+import org.apache.avalon.facilities.console.Console;
+import org.apache.avalon.facilities.console.ConsoleCommand;
+
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+
+/**
+ * @avalon.component name="console-decommissionmodel" lifestyle="singleton"
+ * @avalon.service type="org.apache.avalon.facilities.console.ConsoleCommand"
+ */
+public class RedeployCmd
+    implements ConsoleCommand, Serviceable, Contextualizable
+{
+    private String m_Name;
+    private File   m_WorkingDir;
+        
+    public String getName()
+    {
+        return m_Name;
+    }
+    
+    public String getDescription()
+    {
+        String str = "usage: " + m_Name + " (url) (target-path)\n\nLoads and commissions the block at the URL into the model specified by (target-path)";
+        return str;
+    }
+    
+    /**
+     * Contextulaization of the listener by the container during 
+     * which we are supplied with the root composition model for 
+     * the application.
+     *
+     * @param ctx the supplied listener context
+     *
+     * @exception ContextException if a contextualization error occurs
+     *
+     * @avalon.entry key="urn:avalon:name" 
+     *               type="java.lang.String" 
+     * @avalon.entry key="urn:avalon:home" 
+     *               type="java.io.File" 
+     */
+    public void contextualize( Context ctx ) 
+        throws ContextException
+    {
+        m_Name = (String) ctx.get( "urn:avalon:name" );
+        m_WorkingDir = (File) ctx.get( "urn:avalon:home" );
+    }
+
+    /**
+     * @avalon.dependency type="org.apache.avalon.facilities.console.Console"
+     *                    key="console"
+     */
+    public void service( ServiceManager man )
+        throws ServiceException
+    {
+        Console console = (Console) man.lookup( "console" );
+        console.addCommand( this );
+    }
+    
+    public void execute( CommandInterpreter intp, BufferedReader input, BufferedWriter output, String[] arguments )
+        throws Exception
+    {
+        if( arguments.length == 0 )
+            throw new CommandException( "block must be specified." );
+        
+        String block = arguments[0];
+        ContainmentModel current = intp.getCurrentContainer();
+        String target = current.getQualifiedName();
+        if( arguments.length > 0 )
+            target = arguments[1];
+        DeploymentModel model = current.getModel( target );
+        if( model == null )
+            throw new CommandException( "target not found:" + target );
+
+        if( model instanceof ContainmentModel )
+        {
+            URL blockUrl = UrlUtils.resolveURL( m_WorkingDir, block );
+            ContainmentModel container = (ContainmentModel) model;
+            ContainmentModel newContainer = container.addContainmentModel( blockUrl );
+            newContainer.commission();
+            intp.setCurrentContainer( newContainer );
+        }
+        else
+            throw new CommandException( "Can only deploy into a container." );
+        output.newLine();
+        output.flush();
+    }
+}
+ 

Added: avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/UndeployCmd.java
==============================================================================
--- (empty file)
+++ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/UndeployCmd.java	Sun Aug  8 04:54:31 2004
@@ -0,0 +1,119 @@
+/*
+ * Copyright 1997-2004 Apache Software Foundation
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avalon.facilities.console.commands;
+
+import java.io.IOException;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+
+import org.apache.avalon.composition.model.ComponentModel;
+import org.apache.avalon.composition.model.ContainmentModel;
+import org.apache.avalon.composition.model.DeploymentModel;
+
+import org.apache.avalon.facilities.console.CommandException;
+import org.apache.avalon.facilities.console.CommandInterpreter;
+import org.apache.avalon.facilities.console.Console;
+import org.apache.avalon.facilities.console.ConsoleCommand;
+
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+
+/**
+ * @avalon.component name="console-decommissionmodel" lifestyle="singleton"
+ * @avalon.service type="org.apache.avalon.facilities.console.ConsoleCommand"
+ */
+public class UndeployCmd
+    implements ConsoleCommand, Serviceable, Contextualizable
+{
+    private String m_Name;
+        
+    public String getName()
+    {
+        return m_Name;
+    }
+    
+    public String getDescription()
+    {
+        String str = "usage: " + m_Name + " (target-path)\n\nDecommissions and unload the container specified by (target-path)";
+        return str;
+    }
+    
+    /**
+     * Contextulaization of the listener by the container during 
+     * which we are supplied with the root composition model for 
+     * the application.
+     *
+     * @param ctx the supplied listener context
+     *
+     * @exception ContextException if a contextualization error occurs
+     *
+     * @avalon.entry key="urn:avalon:name" 
+     *               type="java.lang.String" 
+     */
+    public void contextualize( Context ctx ) 
+        throws ContextException
+    {
+        m_Name = (String) ctx.get( "urn:avalon:name" );
+    }
+
+    /**
+     * @avalon.dependency type="org.apache.avalon.facilities.console.Console"
+     *                    key="console"
+     */
+    public void service( ServiceManager man )
+        throws ServiceException
+    {
+        Console console = (Console) man.lookup( "console" );
+        console.addCommand( this );
+    }
+    
+    public void execute( CommandInterpreter intp, BufferedReader input, BufferedWriter output, String[] arguments )
+        throws Exception
+    {
+        if( arguments.length == 0 )
+            throw new CommandException( "target must be specified." );
+        
+        String target = arguments[0];
+        ContainmentModel current = intp.getCurrentContainer();
+        ContainmentModel root = (ContainmentModel) current.getModel( "/" );
+        
+        DeploymentModel dm = current.getModel( target );
+        if( dm == null )
+            throw new CommandException( "target not found:" + target );
+            
+        if( dm instanceof ContainmentModel )
+        {
+            ContainmentModel container = (ContainmentModel) dm;
+            String name = container.getName();
+            String path = container.getPath();
+            ContainmentModel parent = (ContainmentModel) root.getModel( path );
+            container.decommission();
+            container.disassemble();
+            parent.removeModel( name );
+            intp.setCurrentContainer( root );
+        }
+        else
+            throw new CommandException( "Can only undeploy a container." );
+        output.newLine();
+        output.flush();
+    }
+}
+ 

Added: avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/UrlUtils.java
==============================================================================
--- (empty file)
+++ avalon/trunk/planet/facilities/console/commands/src/main/org/apache/avalon/facilities/console/commands/UrlUtils.java	Sun Aug  8 04:54:31 2004
@@ -0,0 +1,86 @@
+/*
+ * Copyright 1997-2004 Apache Software Foundation
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avalon.facilities.console.commands;
+
+import java.io.File;
+import java.io.IOException;
+
+import java.net.URL;
+import java.net.MalformedURLException;
+
+import org.apache.avalon.facilities.console.CommandException;
+
+import org.apache.avalon.repository.ArtifactHandler;
+import org.apache.avalon.repository.BlockHandler;
+
+public class UrlUtils
+{
+    static URL resolveURL( File base, String value )
+        throws Exception
+    {
+        if( value.startsWith( "block:" ) )
+        {
+            return blockSpecToURL( value );
+        }
+        else if( value.startsWith( "artifact:" ) )
+        {
+            return artifactSpecToURL( value );
+        }
+
+        try
+        {
+            return new URL( value );
+        }
+        catch( Exception e )
+        {
+            File target = new File( value );
+            if( target.exists() )
+            {
+                return toURL( target );
+            }
+            else
+            {
+                target = new File( base, value );
+                if( target.exists() )
+                {
+                    return toURL( target );
+                }
+                else
+                {
+                    throw new CommandException( "Unable to resolve URL: " + value );
+                }
+            }
+        }
+    }
+
+    static URL toURL( File file )
+        throws MalformedURLException, IOException
+    {
+        return file.getCanonicalFile().toURL();
+    }
+
+    static URL blockSpecToURL( String spec )   
+        throws MalformedURLException
+    {
+        return new URL( null, spec, new BlockHandler() );
+    }
+
+    static URL artifactSpecToURL( String spec )
+        throws MalformedURLException
+    {
+        return new URL( null, spec, new ArtifactHandler() );
+    }
+}

Modified: avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/CommandInterpreterImpl.java
==============================================================================
--- avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/CommandInterpreterImpl.java	(original)
+++ avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/CommandInterpreterImpl.java	Sun Aug  8 04:54:31 2004
@@ -29,6 +29,7 @@
 
 import org.apache.avalon.composition.model.ContainmentModel;
 
+import org.apache.avalon.facilities.console.LoginException;
 import org.apache.avalon.facilities.console.CommandInterpreter;
 import org.apache.avalon.facilities.console.Console;
 import org.apache.avalon.facilities.console.ConsoleCommand;

Modified: avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/ConsoleImpl.java
==============================================================================
--- avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/ConsoleImpl.java	(original)
+++ avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/ConsoleImpl.java	Sun Aug  8 04:54:31 2004
@@ -157,8 +157,12 @@
         boolean localAllow = params.getParameterAsBoolean( "allow-local", true );
         if( localAllow )
         {
-            InetAddress address = InetAddress.getByName( "127.0.0.1" );
-            m_Allows.add( address );
+            try
+            {
+                InetAddress address = InetAddress.getByName( "127.0.0.1" );
+                m_Allows.add( address );
+            } catch( UnknownHostException e )
+            {} // should not be possible, and if so, never mind.
         }
     }
     
@@ -339,8 +343,11 @@
             } catch( DeniedHostException e )
             {
                 getLogger().warn( e.getMessage() );
-                socket.close();
-                
+                try
+                {
+                    socket.close();
+                } catch( IOException ioe )
+                {}
             } catch( Exception e )
             {
                 getLogger().warn( "", e );

Modified: avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/LoginCmd.java
==============================================================================
--- avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/LoginCmd.java	(original)
+++ avalon/trunk/planet/facilities/console/impl/src/main/org/apache/avalon/facilities/console/impl/LoginCmd.java	Sun Aug  8 04:54:31 2004
@@ -19,6 +19,7 @@
 import java.io.BufferedWriter;
 import java.io.IOException;
 
+import org.apache.avalon.facilities.console.LoginException;
 import org.apache.avalon.facilities.console.CommandInterpreter;
 import org.apache.avalon.facilities.console.Console;
 import org.apache.avalon.facilities.console.ConsoleCommand;

Modified: avalon/trunk/planet/facilities/index.xml
==============================================================================
--- avalon/trunk/planet/facilities/index.xml	(original)
+++ avalon/trunk/planet/facilities/index.xml	Sun Aug  8 04:54:31 2004
@@ -546,6 +546,7 @@
       <include key="avalon-framework-api"/>
       <include key="avalon-console-api"/>
       <include key="avalon-composition-api"/>
+      <include key="avalon-repository-api"/>
     </dependencies>
     <plugins>
       <include key="avalon-meta-tools"/>

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