Skip to Content.
Sympa Menu

notify-dpml - r1184 - in trunk/main: . depot/core depot/core/src depot/core/src/main depot/core/src/main/net depot/core/src/main/net/dpml depot/core/src/main/net/dpml/depot depot/core/src/test depot/core/src/test/net depot/core/src/test/net/dpml depot/core/src/test/net/dpml/depot depot/library/src/main/net/dpml/library/impl

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: r1184 - in trunk/main: . depot/core depot/core/src depot/core/src/main depot/core/src/main/net depot/core/src/main/net/dpml depot/core/src/main/net/dpml/depot depot/core/src/test depot/core/src/test/net depot/core/src/test/net/dpml depot/core/src/test/net/dpml/depot depot/library/src/main/net/dpml/library/impl
  • Date: Tue, 14 Mar 2006 21:09:42 +0100

Author: mcconnell
Date: 2006-03-14 21:09:36 +0100 (Tue, 14 Mar 2006)
New Revision: 1184

Added:
trunk/main/depot/core/src/main/
trunk/main/depot/core/src/main/net/
trunk/main/depot/core/src/main/net/dpml/
trunk/main/depot/core/src/main/net/dpml/depot/
trunk/main/depot/core/src/main/net/dpml/depot/CLIHelper.java
trunk/main/depot/core/src/main/net/dpml/depot/DepotHandler.java

trunk/main/depot/core/src/main/net/dpml/depot/DepotLoggingConfiguration.java
trunk/main/depot/core/src/main/net/dpml/depot/DepotRMIClassLoaderSpi.java
trunk/main/depot/core/src/main/net/dpml/depot/GeneralException.java
trunk/main/depot/core/src/main/net/dpml/depot/Main.java
trunk/main/depot/core/src/main/net/dpml/depot/package.html
trunk/main/depot/core/src/test/
trunk/main/depot/core/src/test/net/
trunk/main/depot/core/src/test/net/dpml/
trunk/main/depot/core/src/test/net/dpml/depot/
trunk/main/depot/core/src/test/net/dpml/depot/CLIHelperTestCase.java
Modified:
trunk/main/bootstrap
trunk/main/bootstrap.bat
trunk/main/depot/core/
trunk/main/depot/library/src/main/net/dpml/library/impl/LibraryBuilder.java
Log:
resolve svn linked issue

Modified: trunk/main/bootstrap
===================================================================
--- trunk/main/bootstrap 2006-03-14 19:40:35 UTC (rev 1183)
+++ trunk/main/bootstrap 2006-03-14 20:09:36 UTC (rev 1184)
@@ -137,7 +137,7 @@

depotCoreConsole()
{
- cd depot/core/console
+ cd depot/core
build clean install
cd ../../..
}

Modified: trunk/main/bootstrap.bat
===================================================================
--- trunk/main/bootstrap.bat 2006-03-14 19:40:35 UTC (rev 1183)
+++ trunk/main/bootstrap.bat 2006-03-14 20:09:36 UTC (rev 1184)
@@ -41,7 +41,7 @@
IF ERRORLEVEL 1 GOTO :exit
CALL :depot-build
IF ERRORLEVEL 1 GOTO :exit
-CALL :depot-core-console
+CALL :depot-core
IF ERRORLEVEL 1 GOTO :exit
ECHO BOOTSTRAP SUCCESSFUL

@@ -139,8 +139,8 @@
POPD
GOTO :EOF

-:depot-core-console
-PUSHD depot\core\console
+:depot-core
+PUSHD depot\core
CALL :build clean install
POPD
GOTO :EOF


Property changes on: trunk/main/depot/core
___________________________________________________________________
Name: svn:ignore
+ target


Added: trunk/main/depot/core/src/main/net/dpml/depot/CLIHelper.java
===================================================================
--- trunk/main/depot/core/src/main/net/dpml/depot/CLIHelper.java
2006-03-14 19:40:35 UTC (rev 1183)
+++ trunk/main/depot/core/src/main/net/dpml/depot/CLIHelper.java
2006-03-14 20:09:36 UTC (rev 1184)
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2005 Stephen J. McConnell.
+ *
+ * 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 net.dpml.depot;
+
+import java.util.ArrayList;
+
+/**
+ * CLI hander for the depot package.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+final class CLIHelper
+{
+ private CLIHelper()
+ {
+ // static utility
+ }
+
+ /**
+ * Utility operation to consolidate a supplied array of command line
arguments
+ * by removal of the supplied argument.
+ *
+ * @param args the command line arguments to consolidate
+ * @param argument the argument to remove
+ * @return the consolidated argument array
+ */
+ public static String[] consolidate( String [] args, String argument )
+ {
+ return consolidate( args, argument, 0 );
+ }
+
+ /**
+ * Utility operation to consolidate a supplied array of command line
arguments
+ * by removal of the supplied argument and the subsequent parameter
values.
+ *
+ * @param args the command line arguments to consolidate
+ * @param argument the argument to remove
+ * @param n the number of parameters to consolidate
+ * @return the consolidated argument array
+ */
+ public static String[] consolidate( String [] args, String argument, int
n )
+ {
+ boolean flag = false;
+ ArrayList list = new ArrayList();
+ for( int i=0; i < args.length; i++ )
+ {
+ String arg = args[i];
+ if( flag )
+ {
+ list.add( arg );
+ }
+ else
+ {
+ if( arg.equals( argument ) )
+ {
+ flag = true;
+ i = i+n;
+ }
+ else
+ {
+ list.add( arg );
+ }
+ }
+ }
+ return (String[]) list.toArray( new String[0] );
+ }
+
+ /**
+ * Test is the supplied option is present in the set of supplied command
line
+ * arguments.
+ *
+ * @param args the set of command line arguments to test against
+ * @param flag the command line option to test for
+ * @return TRUE if one of the command line options matching the supplied
falg argument
+ */
+ public static boolean isOptionPresent( String[] args, String flag )
+ {
+ for( int i=0; i < args.length; i++ )
+ {
+ String arg = args[i];
+ if( arg.equals( flag ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return a command line argument immediately following an option.
+ * @param args an array of command line arguments
+ * @param option the command line option used as the key to locate the
option value
+ * @return the option argument value
+ */
+ public static String getOption( String[] args, String option )
+ {
+ for( int i=0; i < args.length; i++ )
+ {
+ String arg = args[i];
+ if( arg.equals( option ) )
+ {
+ try
+ {
+ return args[i+1];
+ }
+ catch( IndexOutOfBoundsException e )
+ {
+ final String error =
+ "Requestion option ["
+ + option
+ + "] is not followed by an argument value.";
+ throw new IllegalArgumentException( error );
+ }
+ }
+ }
+ final String error =
+ "Option does not exist within the supplied commandline.";
+ throw new IllegalArgumentException( error );
+ }
+}
+

Added: trunk/main/depot/core/src/main/net/dpml/depot/DepotHandler.java
===================================================================
--- trunk/main/depot/core/src/main/net/dpml/depot/DepotHandler.java
2006-03-14 19:40:35 UTC (rev 1183)
+++ trunk/main/depot/core/src/main/net/dpml/depot/DepotHandler.java
2006-03-14 20:09:36 UTC (rev 1184)
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2005 Stephen McConnell.
+ *
+ * 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 net.dpml.depot;
+
+import java.net.URL;
+import java.rmi.RemoteException;
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+
+import net.dpml.transit.PID;
+import net.dpml.transit.LoggingService;
+
+/**
+ * Logging message handler that redirects log messages from a subprocess to
+ * a remote logging system.
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class DepotHandler extends Handler
+{
+ private static final PID ID = new PID();
+
+ private final LoggingService m_system;
+
+ /**
+ * Creation of a new handler instance.
+ * @exception Exception if an error occurs during resolution of the
logging service
+ */
+ public DepotHandler() throws Exception
+ {
+ m_system = getLoggingService();
+ }
+
+ /**
+ * Flush the handler.
+ */
+ public void flush()
+ {
+ }
+
+ /**
+ * Close the log record handler.
+ */
+ public void close()
+ {
+ }
+
+ /**
+ * Publish a log record.
+ * @param record the log record
+ */
+ public void publish( LogRecord record )
+ {
+ try
+ {
+ m_system.log( ID, record );
+ }
+ catch( RemoteException e )
+ {
+ System.err.println( e.toString() );
+ }
+ }
+
+ private LoggingService getLoggingService() throws Exception
+ {
+ ClassLoader classloader =
Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(
getClass().getClassLoader() );
+ try
+ {
+ String key = "registry:" + LoggingService.LOGGING_KEY;
+ String remote = System.getProperty( "net.dpml.logging.service",
key );
+ URL url = new URL( remote );
+ return (LoggingService) url.getContent();
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader( classloader );
+ }
+ }
+
+}
+

Added:
trunk/main/depot/core/src/main/net/dpml/depot/DepotLoggingConfiguration.java
===================================================================
---
trunk/main/depot/core/src/main/net/dpml/depot/DepotLoggingConfiguration.java
2006-03-14 19:40:35 UTC (rev 1183)
+++
trunk/main/depot/core/src/main/net/dpml/depot/DepotLoggingConfiguration.java
2006-03-14 20:09:36 UTC (rev 1184)
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2005 Stephen McConnell.
+ *
+ * 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 net.dpml.depot;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.Properties;
+import java.util.logging.LogManager;
+
+/**
+ * Utility class used to establish the logging configuration for managed
subprocesses.
+ * The handler redirects logging records to a remote LoggingService via RMI
that
+ * aggregates logging messages from multiple JVM within a local domain.
This
+ * configuration handler is declared as the default logging configuration
for
+ * suprocesses launched by the DPML Station.
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class DepotLoggingConfiguration
+{
+ /**
+ * Creation of the logging controller.
+ */
+ public DepotLoggingConfiguration()
+ {
+ String group = System.getProperty( "dpml.system.group", "root" );
+ String level = System.getProperty( "dpml.logging.level", "INFO"
).toUpperCase();
+
+ Properties properties = new Properties();
+
+ properties.setProperty(
+ "handlers",
+ System.getProperty(
+ "handlers",
+ "net.dpml.depot.DepotHandler" ) );
+
+ //
+ // set the default level by setting the root logger level
+ //
+
+ properties.setProperty( ".level", level );
+
+ try
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ properties.store( out, "DPML Logging properties" );
+ byte[] bytes = out.toByteArray();
+ ByteArrayInputStream input = new ByteArrayInputStream( bytes );
+ LogManager manager = LogManager.getLogManager();
+ manager.readConfiguration( input );
+ }
+ catch( Throwable e )
+ {
+ e.printStackTrace();
+ }
+ }
+}
+

Added:
trunk/main/depot/core/src/main/net/dpml/depot/DepotRMIClassLoaderSpi.java
===================================================================
--- trunk/main/depot/core/src/main/net/dpml/depot/DepotRMIClassLoaderSpi.java
2006-03-14 19:40:35 UTC (rev 1183)
+++ trunk/main/depot/core/src/main/net/dpml/depot/DepotRMIClassLoaderSpi.java
2006-03-14 20:09:36 UTC (rev 1184)
@@ -0,0 +1,330 @@
+/*
+ * Copyright 2005 Stephen J. McConnell.
+ *
+ * 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 net.dpml.depot;
+
+import java.io.IOException;
+import java.rmi.server.RMIClassLoader;
+import java.rmi.server.RMIClassLoaderSpi;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.Permission;
+import java.util.Collections;
+import java.util.IdentityHashMap;
+import java.util.Map;
+
+import net.dpml.transit.StandardClassLoader;
+
+/**
+ * The DepotRMIClassLoaderSpi handles the loading of classes that are based
on
+ * plugin artifact types.
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class DepotRMIClassLoaderSpi extends RMIClassLoaderSpi
+{
+ private static final Map LOADERS = Collections.synchronizedMap( new
IdentityHashMap( 5 ) );
+
+ private RMIClassLoaderSpi m_delegate =
RMIClassLoader.getDefaultProviderInstance();
+
+ static
+ {
+ for( ClassLoader classloader = ClassLoader.getSystemClassLoader();
+ classloader != null; classloader = classloader.getParent() )
+ {
+ LOADERS.put( classloader, null );
+ }
+ }
+
+ /**
+ * Default constructor.
+ */
+ public DepotRMIClassLoaderSpi()
+ {
+ super();
+ }
+
+ /**
+ * Provides the implementation for
+ * {@link RMIClassLoader#loadClass(URL,String)},
+ * {@link RMIClassLoader#loadClass(String,String)}, and
+ * {@link RMIClassLoader#loadClass(String,String,ClassLoader)}.
+ *
+ * Loads a class from a codebase URL path, optionally using the
+ * supplied loader.
+ *
+ * @param codebase the list of URLs (separated by spaces) to load
+ * the class from, or <code>null</code>
+ * @param name the name of the class to load
+ * @param defaultLoader additional contextual class loader
+ * to use, or <code>null</code>
+ * @return the <code>Class</code> object representing the loaded class
+ * @exception MalformedURLException if <code>codebase</code> is
+ * non-<code>null</code> and contains an invalid URL, or
+ * if <code>codebase</code> is <code>null</code> and the system
+ * property <code>java.rmi.server.codebase</code> contains an
+ * invalid URL
+ * @exception ClassNotFoundException if a definition for the class
+ * could not be found at the specified location
+ */
+ public Class loadClass(
+ String codebase, String name, ClassLoader defaultLoader )
+ throws MalformedURLException, ClassNotFoundException
+ {
+ //if( null != codebase )
+ //{
+ // final String message =
+ // "Loading class: "
+ // + name
+ // + "\nCodebase: "
+ // + codebase;
+ // getLogger().debug( message );
+ //}
+ return m_delegate.loadClass( codebase, name, defaultLoader );
+ }
+
+ /**
+ * Provides the implementation for
+ * {@link RMIClassLoader#loadProxyClass(String,String[],ClassLoader)}.
+ *
+ * Loads a dynamic proxy class (see {@link java.lang.reflect.Proxy}
+ * that implements a set of interfaces with the given names
+ * from a codebase URL path, optionally using the supplied loader.
+ *
+ * <p>An implementation of this method must either return a proxy
+ * class that implements the named interfaces or throw an exception.
+ *
+ * @param codebase the list of URLs (space-separated) to load
+ * classes from, or <code>null</code>
+ * @param interfaces the names of the interfaces for the proxy class
+ * to implement
+ * @param defaultLoader additional contextual class loader
+ * to use, or <code>null</code>
+ * @return a dynamic proxy class that implements the named interfaces
+ * @exception MalformedURLException if <code>codebase</code> is
+ * non-<code>null</code> and contains an invalid URL, or
+ * if <code>codebase</code> is <code>null</code> and the system
+ * property <code>java.rmi.server.codebase</code> contains an
+ * invalid URL
+ * @exception ClassNotFoundException if a definition for one of
+ * the named interfaces could not be found at the specified location,
+ * or if creation of the dynamic proxy class failed (such as if
+ * {@link java.lang.reflect.Proxy#getProxyClass(ClassLoader,Class[])}
+ * would throw an <code>IllegalArgumentException</code> for the given
+ * interface list)
+ */
+ public Class loadProxyClass(
+ String codebase, String[] interfaces, ClassLoader defaultLoader )
+ throws MalformedURLException, ClassNotFoundException
+ {
+ //if( null != codebase )
+ //{
+ // getLogger().debug( "Loading proxy: " + codebase );
+ //}
+ return m_delegate.loadProxyClass( codebase, interfaces,
defaultLoader );
+ }
+
+ /**
+ * Provides the implementation for
+ * {@link RMIClassLoader#getClassLoader(String)}.
+ *
+ * Returns a class loader that loads classes from the given codebase
+ * URL path.
+ *
+ * <p>If there is a security manger, its <code>checkPermission</code>
+ * method will be invoked with a
+ * <code>RuntimePermission("getClassLoader")</code> permission;
+ * this could result in a <code>SecurityException</code>.
+ * The implementation of this method may also perform further security
+ * checks to verify that the calling context has permission to connect
+ * to all of the URLs in the codebase URL path.
+ *
+ * @param codebase the list of URLs (space-separated) from which
+ * the returned class loader will load classes from, or <code>null</code>
+ * @return a class loader that loads classes from the given codebase URL
+ * path
+ * @exception MalformedURLException if <code>codebase</code> is
+ * non-<code>null</code> and contains an invalid URL, or
+ * if <code>codebase</code> is <code>null</code> and the system
+ * property <code>java.rmi.server.codebase</code> contains an
+ * invalid URL
+ * @exception SecurityException if there is a security manager and the
+ * invocation of its <code>checkPermission</code> method fails, or
+ * if the caller does not have permission to connect to all of the
+ * URLs in the codebase URL path
+ */
+ public ClassLoader getClassLoader( String codebase )
+ throws MalformedURLException, SecurityException
+ {
+ return m_delegate.getClassLoader( codebase );
+ }
+
+ /**
+ * Provides the implementation for
+ * {@link RMIClassLoader#getClassAnnotation(Class)}.
+ *
+ * Returns the annotation string (representing a location for
+ * the class definition) that RMI will use to annotate the class
+ * descriptor when marshalling objects of the given class.
+ *
+ * @param cl the class to obtain the annotation for
+ * @return a string to be used to annotate the given class when
+ * it gets marshalled, or <code>null</code>
+ * @exception NullPointerException if <code>cl</code> is <code>null</code>
+ */
+ public String getClassAnnotation( Class cl ) throws NullPointerException
+ {
+ final String annotations = getAnnotation( cl );
+ //if( null != annotations )
+ //{
+ // System.out.println( "# " + cl.getName() + ", " + annotations );
+ //}
+ return annotations;
+ }
+
+ private String getAnnotation( Class cl ) throws NullPointerException
+ {
+ String classname = cl.getName();
+ int i = classname.length();
+ if( ( i > 0 ) && classname.charAt( 0 ) == '[' )
+ {
+ int j;
+ for( j=1; i > j && classname.charAt( j ) == '['; j++ )
+ {
+ if( ( i > j ) && classname.charAt( j ) != 'L' )
+ {
+ return null;
+ }
+ }
+ }
+
+ ClassLoader classloader = cl.getClassLoader();
+ if( classloader == null || LOADERS.containsKey( classloader ) )
+ {
+ return System.getProperty( "java.rmi.server.codebase" );
+ }
+
+ String annotations = null;
+ if( classloader instanceof StandardClassLoader )
+ {
+ annotations = ( (StandardClassLoader) classloader
).getAnnotations();
+ }
+ else if( classloader instanceof URLClassLoader )
+ {
+ annotations = getAnnotations( (URLClassLoader) classloader );
+ }
+
+ if( annotations != null )
+ {
+ return annotations;
+ }
+ else
+ {
+ return System.getProperty( "java.rmi.server.codebase" );
+ }
+ }
+
+ private String getAnnotations( URLClassLoader classloader )
+ {
+ StringBuffer buffer = new StringBuffer();
+ return getAnnotations( buffer, classloader );
+ }
+
+ private String getAnnotations( StringBuffer buffer, URLClassLoader
classloader )
+ {
+ packAnnotations( buffer, classloader );
+ String result = buffer.toString();
+ return result.trim();
+ }
+
+ private void packAnnotations( StringBuffer buffer, URLClassLoader
classloader )
+ {
+ if( ClassLoader.getSystemClassLoader() == classloader )
+ {
+ return;
+ }
+
+ ClassLoader parent = classloader.getParent();
+ if( ( null != parent ) && ( parent instanceof URLClassLoader ) )
+ {
+ packAnnotations( buffer, (URLClassLoader) parent );
+ }
+
+ try
+ {
+ URL[] urls = classloader.getURLs();
+ if( null != urls )
+ {
+ SecurityManager manager = System.getSecurityManager();
+ if( manager != null )
+ {
+ for( int k = 0; k < urls.length; k++ )
+ {
+ Permission permission =
urls[k].openConnection().getPermission();
+ if( permission != null )
+ {
+ manager.checkPermission( permission );
+ }
+ }
+ }
+ buffer.append( urlsToPath( urls ) + " " );
+ }
+ }
+ catch( SecurityException e )
+ {
+ boolean ignore = true; // ignore
+ }
+ catch( IOException e )
+ {
+ boolean ignore = true; // ignore
+ }
+ }
+
+ private static String urlsToPath( URL[] urls )
+ {
+ if( urls.length == 0 )
+ {
+ return null;
+ }
+ else if( urls.length == 1 )
+ {
+ final String path = urls[0].toExternalForm();
+ if( !path.startsWith( "file:" ) )
+ {
+ return path;
+ }
+ else
+ {
+ return "";
+ }
+ }
+ StringBuffer buffer = new StringBuffer( urls[0].toExternalForm() );
+ for( int i=1; i < urls.length; i++ )
+ {
+ final String path = urls[i].toExternalForm();
+ if( !path.startsWith( "file:" ) )
+ {
+ buffer.append( ' ' );
+ buffer.append( path );
+ }
+
+ }
+ return buffer.toString();
+ }
+}

Added: trunk/main/depot/core/src/main/net/dpml/depot/GeneralException.java
===================================================================
--- trunk/main/depot/core/src/main/net/dpml/depot/GeneralException.java
2006-03-14 19:40:35 UTC (rev 1183)
+++ trunk/main/depot/core/src/main/net/dpml/depot/GeneralException.java
2006-03-14 20:09:36 UTC (rev 1184)
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2005 Stephen McConnell
+ *
+ * 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 net.dpml.depot;
+
+import java.rmi.ServerException;
+
+/**
+ * A general exception that is typically used for scenarios in which a stack
dump
+ * is not relevant.
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class GeneralException extends ServerException
+{
+ /**
+ * Creation of a new general exception instance.
+ * @param message the exception message.
+ */
+ public GeneralException( final String message )
+ {
+ super( message );
+ }
+}

Added: trunk/main/depot/core/src/main/net/dpml/depot/Main.java
===================================================================
--- trunk/main/depot/core/src/main/net/dpml/depot/Main.java 2006-03-14
19:40:35 UTC (rev 1183)
+++ trunk/main/depot/core/src/main/net/dpml/depot/Main.java 2006-03-14
20:09:36 UTC (rev 1184)
@@ -0,0 +1,541 @@
+/*
+ * Copyright 2005 Stephen J. McConnell.
+ *
+ * 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 net.dpml.depot;
+
+import java.net.URL;
+import java.net.URI;
+import java.rmi.RMISecurityManager;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Enumeration;
+
+import net.dpml.transit.Disposable;
+import net.dpml.transit.Transit;
+import net.dpml.transit.TransitError;
+import net.dpml.transit.Repository;
+import net.dpml.transit.RepositoryException;
+import net.dpml.transit.Logger;
+import net.dpml.transit.DefaultTransitModel;
+import net.dpml.transit.model.TransitModel;
+import net.dpml.transit.monitor.Adapter;
+import net.dpml.transit.monitor.LoggingAdapter;
+import net.dpml.transit.monitor.RepositoryMonitorAdapter;
+import net.dpml.transit.monitor.CacheMonitorAdapter;
+import net.dpml.transit.monitor.NetworkMonitorAdapter;
+import net.dpml.lang.Enum;
+import net.dpml.transit.PID;
+
+/**
+ * CLI hander for the depot package.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public final class Main //implements ShutdownHandler
+{
+ private static Main m_MAIN;
+ private static final PID PROCESS_ID = new PID();
+
+ private Object m_plugin;
+ private boolean m_debug = false;
+
+ /**
+ * Processes command line options to establish the command handler plugin
to deploy.
+ * Command parameters recognixed by the console include the following:
+ * <ul>
+ * <li>-Ddpml.depot.addplication=transit|station|metro|build</li>
+ * <li>-debug</li>
+ * </ul>
+ * @param args the command line argument array
+ * @exception Exception if a error occurs
+ */
+ public static void main( String[] args )
+ throws Exception
+ {
+ if( null != m_MAIN )
+ {
+ final String error =
+ "Console already established.";
+ throw new IllegalArgumentException( error );
+ }
+ else
+ {
+ m_MAIN = new Main( args );
+ }
+ }
+
+ private Main( String[] arguments )
+ {
+ String[] args = arguments;
+
+ //
+ // check for debug mode
+ //
+
+ if( CLIHelper.isOptionPresent( args, "-debug" ) )
+ {
+ System.setProperty( "dpml.logging.config",
"local:properties:dpml/transit/debug" );
+ args = CLIHelper.consolidate( args, "-debug" );
+ System.setProperty( "dpml.debug", "true" );
+ m_debug = true;
+ for( int i=0; i<arguments.length; i++ )
+ {
+ System.out.println( " arg[" + i + "] " + arguments[i] );
+ }
+ }
+
+ //
+ // handle cli sub-system establishment
+ //
+
+ Command command = getCommand( args );
+ if( Command.BUILD.equals( command ) )
+ {
+ handleBuild( args );
+ }
+ else if( Command.TRANSIT.equals( command ) )
+ {
+ handleTransit( args );
+ }
+ else if( Command.METRO.equals( command ) )
+ {
+ handleMetro( args );
+ }
+ else if( Command.STATION.equals( command ) )
+ {
+ handleStation( args );
+ }
+ else
+ {
+ final String error =
+ "Missing application key '" + APPLICATION_KEY + "'.";
+ System.err.println( error );
+ System.exit( 1 );
+ }
+ }
+
+ private void handleBuild( String[] arguments )
+ {
+ String[] args = processSystemProperties( arguments );
+ String name = "build";
+ String spec = "@DEPOT-BUILDER-URI@";
+ handlePlugin( name, spec, args, false );
+ }
+
+ private void handleMetro( String[] arguments )
+ {
+ String[] args = processSystemProperties( arguments );
+ String name = "metro";
+ String spec = "@DEPOT-EXEC-URI@";
+ handlePlugin( name, spec, args, true );
+ }
+
+ private void handleTransit( String[] arguments )
+ {
+ String[] args = processSystemProperties( arguments );
+ String name = "transit";
+ String spec = "@TRANSIT-CONSOLE-URI@";
+ handlePlugin( name, spec, args, false );
+ }
+
+ private void handleStation( String[] arguments )
+ {
+ String name = "station";
+ new File( Transit.DPML_DATA, "logs/station" ).mkdirs();
+ if( CLIHelper.isOptionPresent( arguments, "-server" ) )
+ {
+ String[] args = CLIHelper.consolidate( arguments, "-server" );
+ args = processSystemProperties( args );
+ String spec = "@DEPOT-STATION-SERVER-URI@";
+ handlePlugin( name, spec, args, true );
+ }
+ else
+ {
+ String spec = "@DEPOT-STATION-URI@";
+ handlePlugin( name, spec, arguments, false );
+ }
+ }
+
+ private void handlePlugin( String name, String spec, String[] args,
boolean wait )
+ {
+ System.setSecurityManager( new RMISecurityManager() );
+ TransitModel model = getTransitModel( args );
+ boolean waitForCompletion = deployHandler( model, name, spec, args,
wait );
+ if( !waitForCompletion )
+ {
+ if( m_plugin instanceof Disposable )
+ {
+ Disposable disposable = (Disposable) m_plugin;
+ disposable.dispose();
+ }
+ if( model instanceof DefaultTransitModel )
+ {
+ DefaultTransitModel disposable = (DefaultTransitModel) model;
+ disposable.dispose();
+ }
+ System.exit( 0 );
+ }
+ }
+
+ private boolean deployHandler(
+ TransitModel model, String command, String path, String[] args,
boolean waitFor )
+ {
+
+ Logger logger = getLogger().getChildLogger( command );
+ if( m_debug )
+ {
+ Enumeration names = System.getProperties().propertyNames();
+ StringBuffer buffer = new StringBuffer( "System property
listing:" );
+ while( names.hasMoreElements() )
+ {
+ String name = (String) names.nextElement();
+ buffer.append( name + "=" + System.getProperty( name ) );
+ }
+ }
+ try
+ {
+ URI uri = new URI( path );
+ Transit transit = Transit.getInstance( model );
+ setupMonitors( transit, (Adapter) getLogger() );
+ Repository repository = transit.getRepository();
+ m_plugin =
+ repository.getPlugin(
+ ClassLoader.getSystemClassLoader(),
+ uri, new Object[]{model, args, logger} );
+ }
+ catch( RepositoryException e )
+ {
+ Throwable cause = e.getCause();
+ if( ( null != cause ) && ( cause instanceof GeneralException ) )
+ {
+ getLogger().error( cause.getMessage() );
+ System.exit( 1 );
+ }
+ else
+ {
+ getLogger().error( e.getMessage(), e.getCause() );
+ System.exit( 1 );
+ }
+ }
+ catch( GeneralException e )
+ {
+ getLogger().error( e.getMessage() );
+ System.exit( 1 );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unable to deploy the ["
+ + command
+ + "] handler due to deployment failure.";
+ getLogger().error( error, e );
+ System.exit( 1 );
+ }
+
+ if( m_plugin instanceof Runnable )
+ {
+ getLogger().debug( "starting " + m_plugin.getClass().getName() );
+ Thread thread = new Thread( (Runnable) m_plugin );
+ thread.start();
+ setShutdownHook( thread );
+ return true;
+ }
+ else
+ {
+ getLogger().debug( "deployed " + m_plugin.getClass().getName() );
+ return waitFor;
+ }
+ }
+
+ private TransitModel getTransitModel( String[] args )
+ {
+ final String key = "dpml.transit.model";
+ String property = null;
+ for( int i=0; i<args.length; i++ )
+ {
+ String arg = args[i];
+ if( arg.startsWith( "-D" + key + "=" ) )
+ {
+ property = arg.substring( 21 );
+ break;
+ }
+ }
+
+ if( null != property )
+ {
+ if( property.startsWith( "registry:" ) )
+ {
+ try
+ {
+ return (TransitModel) new URL( property ).getContent(
+ new Class[]{TransitModel.class} );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Unable to resolve registry reference: " + property;
+ throw new TransitError( error, e );
+ }
+ }
+ else
+ {
+ final String error =
+ "System property value for the key ': "
+ + key
+ + "' contains an unrecognized value: "
+ + property;
+ throw new TransitError( error );
+ }
+ }
+
+ //
+ // otherwise let Transit handle model creation
+ //
+
+ try
+ {
+ Logger logger = getLogger();
+ return DefaultTransitModel.getDefaultModel( logger );
+ }
+ catch( Exception e )
+ {
+ final String error =
+ "Transit model establishment failure.";
+ throw new TransitError( error, e );
+ }
+ }
+
+ private static Logger getLogger()
+ {
+ if( null == m_LOGGER )
+ {
+ String category = System.getProperty( "dpml.logging.category",
"depot" );
+ m_LOGGER = new LoggingAdapter(
java.util.logging.Logger.getLogger( category ) );
+ }
+ return m_LOGGER;
+ }
+
+
//--------------------------------------------------------------------------
+ // static utilities for setup of logging manager and root prefs
+
//--------------------------------------------------------------------------
+
+ private String[] processSystemProperties( String[] args )
+ {
+ ArrayList result = new ArrayList();
+ for( int i=0; i < args.length; i++ )
+ {
+ String arg = args[i];
+ int index = arg.indexOf( "=" );
+ if( index > -1 && arg.startsWith( "-D" ) )
+ {
+ String name = arg.substring( 2, index );
+ String value = arg.substring( index + 1 );
+ System.setProperty( name, value );
+ }
+ else
+ {
+ result.add( arg );
+ }
+ }
+ return (String[]) result.toArray( new String[0] );
+ }
+
+ /**
+ * Setup the monitors.
+ */
+ private static void setupMonitors( Transit instance, Adapter adapter )
throws Exception
+ {
+ instance.getRepositoryMonitorRouter().addMonitor(
+ new RepositoryMonitorAdapter( adapter ) );
+ instance.getCacheMonitorRouter().addMonitor(
+ new CacheMonitorAdapter( adapter ) );
+ instance.getNetworkMonitorRouter().addMonitor(
+ new NetworkMonitorAdapter( adapter ) );
+ }
+
+ /**
+ * Create a shutdown hook that will trigger shutdown of the supplied
plugin.
+ * @param thread the application thread
+ */
+ public static void setShutdownHook( final Thread thread )
+ {
+ //
+ // Create a shutdown hook to trigger clean disposal of the
+ // controller
+ //
+
+ Runtime.getRuntime().addShutdownHook(
+ new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ thread.interrupt();
+ }
+ catch( Throwable e )
+ {
+ boolean ignorable = true;
+ }
+ System.runFinalization();
+ }
+ }
+ );
+ }
+
+ /**
+ * DPML build key.
+ */
+ private static final String BUILD_KEY = "dpml.build";
+
+ /**
+ * The Depot system version.
+ */
+ private static final String BUILD_ID = "@BUILD-ID@";
+
+ static
+ {
+ setSystemProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
+ setSystemProperty( "java.util.logging.config.class",
"net.dpml.transit.util.ConfigurationHandler" );
+ setSystemProperty( "java.rmi.server.RMIClassLoaderSpi",
"net.dpml.depot.DepotRMIClassLoaderSpi" );
+ setSystemProperty( Transit.SYSTEM_KEY,
Transit.DPML_SYSTEM.getAbsolutePath() );
+ setSystemProperty( Transit.HOME_KEY,
Transit.DPML_HOME.getAbsolutePath() );
+ setSystemProperty( Transit.DATA_KEY,
Transit.DPML_DATA.getAbsolutePath() );
+ setSystemProperty( Transit.PREFS_KEY,
Transit.DPML_PREFS.getAbsolutePath() );
+ setSystemProperty( BUILD_KEY, BUILD_ID );
+ }
+
+ private static void setSystemProperty( String key, String value )
+ {
+ if( null == System.getProperty( key ) )
+ {
+ System.setProperty( key, value );
+ }
+ }
+
+ private static Logger m_LOGGER = null;
+
+ private Command getCommand( String[] args )
+ {
+ String ref = getApplicationReference( args );
+ String app = System.getProperty( APPLICATION_KEY, ref );
+ return Command.parse( app );
+ }
+
+ private String getApplicationReference( String[] args )
+ {
+ String key = "-D" + APPLICATION_KEY + "=";
+ for( int i=0; i<args.length; i++ )
+ {
+ String arg = args[i];
+ if( arg.startsWith( key ) )
+ {
+ return arg.substring( 25 );
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Application selection key.
+ */
+ public static final String APPLICATION_KEY = "dpml.depot.application";
+
+ /**
+ * Application identifier enumeration.
+ */
+ private static final class Command extends Enum
+ {
+ static final long serialVersionUID = 1L;
+
+ /**
+ * Transit command id.
+ */
+ public static final Command TRANSIT = new Command( "dpml.transit" );
+
+ /**
+ * Metro command id.
+ */
+ public static final Command METRO = new Command( "dpml.metro" );
+
+ /**
+ * Station command id.
+ */
+ public static final Command STATION = new Command( "dpml.station" );
+
+ /**
+ * Builder command id.
+ */
+ public static final Command BUILD = new Command( "dpml.builder" );
+
+ /**
+ * Internal constructor.
+ * @param label the enumeration label.
+ * @param index the enumeration index.
+ * @param map the set of constructed enumerations.
+ */
+ private Command( String label )
+ {
+ super( label );
+ }
+
+ /**
+ * Create a now mode using a supplied mode name.
+ * @param value the mode name
+ * @return the mode
+ * @exception NullPointerException if the supplied value is null
+ * @exception IllegalArgumentException if the supplied value is not
recognized
+ */
+ public static Command parse( String value ) throws
NullPointerException, IllegalArgumentException
+ {
+ if( null == value )
+ {
+ final String error =
+ "Undefined sub-system identifier."
+ + "\nThe depot cli handler must be supplied with an -D"
+ + APPLICATION_KEY + "=[id] where id is one of the value
'dpml.metro', "
+ + "'dpml.transit', 'dpml.station' or 'dpml.build'.";
+ throw new NullPointerException( error );
+ }
+ if( value.equalsIgnoreCase( "dpml.metro" ) )
+ {
+ return METRO;
+ }
+ else if( value.equalsIgnoreCase( "dpml.transit" ) )
+ {
+ return TRANSIT;
+ }
+ else if( value.equalsIgnoreCase( "dpml.station" ) )
+ {
+ return STATION;
+ }
+ else if( value.equalsIgnoreCase( "dpml.builder" ) )
+ {
+ return BUILD;
+ }
+ else
+ {
+ final String error =
+ "Unrecognized application id [" + value + "]";
+ throw new IllegalArgumentException( error );
+ }
+ }
+ }
+}
+

Added: trunk/main/depot/core/src/main/net/dpml/depot/package.html
===================================================================
--- trunk/main/depot/core/src/main/net/dpml/depot/package.html 2006-03-14
19:40:35 UTC (rev 1183)
+++ trunk/main/depot/core/src/main/net/dpml/depot/package.html 2006-03-14
20:09:36 UTC (rev 1184)
@@ -0,0 +1,7 @@
+
+<body>
+<p>
+Depot bootstrap application launcher.
+</p>
+</body>
+

Added: trunk/main/depot/core/src/test/net/dpml/depot/CLIHelperTestCase.java
===================================================================
--- trunk/main/depot/core/src/test/net/dpml/depot/CLIHelperTestCase.java
2006-03-14 19:40:35 UTC (rev 1183)
+++ trunk/main/depot/core/src/test/net/dpml/depot/CLIHelperTestCase.java
2006-03-14 20:09:36 UTC (rev 1184)
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2005 Stephen McConnell
+ *
+ * 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 net.dpml.depot;
+
+import junit.framework.TestCase;
+
+/**
+ * Test utility functions in the CLIHelper class.
+ *
+ * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
+ */
+public class CLIHelperTestCase extends TestCase
+{
+ /**
+ * Test the conslidation of a single argument value whereby
+ * a supplied argument is removed from an args sequence.
+ * @exception Exception if the test fails
+ */
+ public void testConsolidation() throws Exception
+ {
+ String[] args = new String[]{"aaa", "bbb", "ccc"};
+ String[] result = CLIHelper.consolidate( args, "aaa" );
+ assertEquals( "first", result[0], "bbb" );
+ assertEquals( "second", result[1], "ccc" );
+ assertEquals( "length", result.length, 2 );
+ }
+
+ /**
+ * Test the conslidation of a single argument and parameter.
+ * The int parameter dictates the number of additional arguments to
+ * remove from the array following the parameter value.
+ * @exception Exception if the test fails
+ */
+ public void testConsolidationWithOffset() throws Exception
+ {
+ String[] args = new String[]{"aaa", "bbb", "ccc"};
+ String[] result = CLIHelper.consolidate( args, "aaa", 1 );
+ assertEquals( "first", result[0], "ccc" );
+ assertEquals( "length", result.length, 1 );
+ }
+
+ /**
+ * Test the conslidation of a single argument and two parameters.
+ * @exception Exception if the test fails
+ */
+ public void testConsolidationWithNoRemainder() throws Exception
+ {
+ String[] args = new String[]{"aaa", "bbb", "ccc"};
+ String[] result = CLIHelper.consolidate( args, "aaa", 2 );
+ assertEquals( "length", result.length, 0 );
+ }
+
+ /**
+ * Test the conslidation of a single that is not the inital argument and
one parameters.
+ * @exception Exception if the test fails
+ */
+ public void testConsolidationInterim() throws Exception
+ {
+ String[] args = new String[]{"aaa", "bbb", "ccc"};
+ String[] result = CLIHelper.consolidate( args, "bbb", 1 );
+ assertEquals( "length", result.length, 1 );
+ assertEquals( "value", result[0], "aaa" );
+ }
+
+ /**
+ * Test the conslidation of a single that is not the inital argument and
one parameters.
+ * @exception Exception if the test fails
+ */
+ public void testIsOptionPresent() throws Exception
+ {
+ String[] args = new String[]{"aaa", "bbb", "ccc"};
+ assertTrue( "option aaa", CLIHelper.isOptionPresent( args, "aaa" ) );
+ assertTrue( "option bbb", CLIHelper.isOptionPresent( args, "bbb" ) );
+ assertTrue( "option ccc", CLIHelper.isOptionPresent( args, "ccc" ) );
+ }
+
+ /**
+ * Test the conslidation of a single that is not the inital argument and
one parameters.
+ * @exception Exception if the test fails
+ */
+ public void testGetOption() throws Exception
+ {
+ String[] args = new String[]{"aaa", "bbb", "ccc"};
+ assertEquals( "get option", CLIHelper.getOption( args, "aaa" ),
"bbb" );
+ }
+
+}

Modified:
trunk/main/depot/library/src/main/net/dpml/library/impl/LibraryBuilder.java
===================================================================
---
trunk/main/depot/library/src/main/net/dpml/library/impl/LibraryBuilder.java
2006-03-14 19:40:35 UTC (rev 1183)
+++
trunk/main/depot/library/src/main/net/dpml/library/impl/LibraryBuilder.java
2006-03-14 20:09:36 UTC (rev 1184)
@@ -375,14 +375,10 @@
final String basedir = path;
final Element root = getRootElement( source );
final String tag = root.getTagName();
- if( "module".equals( tag ) )
+ if( "module".equals( tag ) || "project".equals( tag ) ||
"resource".equals( tag ))
{
return buildResourceDirectiveFromElement( parent, root,
basedir );
}
- else if( "project".equals( tag ) )
- {
- throw new IllegalArgumentException( "project" );
- }
else
{
throw new IllegalArgumentException( tag );




  • r1184 - in trunk/main: . depot/core depot/core/src depot/core/src/main depot/core/src/main/net depot/core/src/main/net/dpml depot/core/src/main/net/dpml/depot depot/core/src/test depot/core/src/test/net depot/core/src/test/net/dpml depot/core/src/test/net/dpml/depot depot/library/src/main/net/dpml/library/impl, mcconnell at BerliOS, 03/14/2006

Archive powered by MHonArc 2.6.24.

Top of Page