You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2003/12/09 10:18:44 UTC
cvs commit: avalon/merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl DefaultCriteria.java DefaultFactory.java
mcconnell 2003/12/09 01:18:44
Modified: merlin/kernel/cli/src/java/org/apache/avalon/merlin/cli
Main.java
merlin/kernel/impl/conf merlin.properties
merlin/kernel/impl/src/java/org/apache/avalon/merlin/impl
DefaultCriteria.java DefaultFactory.java
Added: merlin/kernel/cli/src/java/org/apache/avalon/merlin/cli
Resources_de.properties Resources_fr.properties
Log:
Improve handling of working base directory by moving abstraction to the repository inital context.
Revision Changes Path
1.2 +57 -22 avalon/merlin/kernel/cli/src/java/org/apache/avalon/merlin/cli/Main.java
Index: Main.java
===================================================================
RCS file: /home/cvs/avalon/merlin/kernel/cli/src/java/org/apache/avalon/merlin/cli/Main.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Main.java 8 Dec 2003 15:37:12 -0000 1.1
+++ Main.java 9 Dec 2003 09:18:44 -0000 1.2
@@ -208,11 +208,13 @@
return options;
}
+ private static Main MAIN = null;
+
//----------------------------------------------------------
// immutable state
//----------------------------------------------------------
- private final InitialContext m_context;
+ private final Object m_kernel;
//----------------------------------------------------------
// constructor
@@ -223,13 +225,13 @@
* @param context the repository inital context
* @param artifact the merlin implementation artifact
* @param line the command line construct
+ * @param base the base working directory
* @exception Exception if an error occurs
*/
- public Main( InitialContext context, Artifact artifact, CommandLine line ) throws Exception
+ public Main(
+ InitialContext context, Artifact artifact, CommandLine line ) throws Exception
{
- m_context = context;
-
- Builder builder = new DefaultBuilder( m_context, artifact );
+ Builder builder = new DefaultBuilder( context, artifact );
ClassLoader classloader = builder.getClassLoader();
Factory factory = builder.getFactory();
Map criteria = factory.createDefaultCriteria();
@@ -244,7 +246,7 @@
// instantiate the kernel
//
- Object kernel = factory.create( criteria );
+ m_kernel = factory.create( criteria );
}
private void handleCommandLine( Map criteria, CommandLine line )
@@ -253,7 +255,6 @@
setInfoPolicy( criteria, line );
setDebugPolicy( criteria, line );
setServerPolicy( criteria, line );
- setWorkingDirectory( criteria, line );
setAnchorDirectory( criteria, line );
setRepositoryDirectory( criteria, line );
setKernelURL( criteria, line );
@@ -293,7 +294,7 @@
if( line.hasOption( "home" ) )
{
String home = line.getOptionValue( "home" );
- criteria.put( "merlin.work", home );
+ criteria.put( "merlin.dir", home );
}
}
@@ -336,7 +337,10 @@
private void setDeploymentPath( Map criteria, CommandLine line )
{
String[] arguments = line.getArgs();
- criteria.put( "merlin.deployment", arguments );
+ if( arguments.length > 0 )
+ {
+ criteria.put( "merlin.deployment", arguments );
+ }
}
/**
@@ -354,7 +358,8 @@
CommandLineParser parser = new BasicParser();
CommandLine line = parser.parse( CL_OPTIONS, args );
- Artifact artifact = getDefaultImplementation( line );
+ File dir = getWorkingDirectory( line );
+ Artifact artifact = getDefaultImplementation( dir, line );
File system = getMerlinSystemRepository( line );
if( line.hasOption( "version" ) )
@@ -362,8 +367,7 @@
Main.printVersionInfo( system, artifact );
return;
}
-
- if( line.hasOption( "help" ) )
+ else if( line.hasOption( "help" ) )
{
if( line.hasOption( "lang" ) )
{
@@ -376,15 +380,27 @@
Main.printHelpInfo();
return;
}
+ else
+ {
+ //
+ // setup the initial context
+ //
+
+ ClassLoader parent = Main.class.getClassLoader();
+ Artifact impl = null; // default
+ String[] bootstrap = null; // default
+
+ InitialContext context =
+ new DefaultInitialContext(
+ dir, parent, impl, system, bootstrap );
+
+ //
+ // process the commandline and do the real work
+ //
- //
- // the real stuff
- //
-
- InitialContext context =
- new DefaultInitialContext( system );
- Main main = new Main( context, artifact, line );
+ MAIN = new Main( context, artifact, line );
+ }
}
catch( Throwable e )
{
@@ -396,13 +412,32 @@
}
/**
+ * Resolve the merlin.dir value.
+ * @param line the command line construct
+ * @return the working directory
+ */
+ private static File getWorkingDirectory( CommandLine line ) throws Exception
+ {
+ if( line.hasOption( "home" ) )
+ {
+ String dir = line.getOptionValue( "home" );
+ return new File( dir );
+ }
+ else
+ {
+ return getBaseDirectory();
+ }
+ }
+
+ /**
* Resolve the default implementation taking into account
* command line arguments, local and hom properties, and
* application defaults.
* @param line the command line construct
* @return the artifact reference
*/
- private static Artifact getDefaultImplementation( CommandLine line ) throws Exception
+ private static Artifact getDefaultImplementation(
+ File base, CommandLine line ) throws Exception
{
if( line.hasOption( "impl" ) )
{
@@ -417,7 +452,7 @@
final String key = "merlin.implementation";
String home = getLocalProperties( USER_HOME, MERLIN ).getProperty( key );
- String work = getLocalProperties( USER_DIR, MERLIN ).getProperty( key, home);
+ String work = getLocalProperties( base, MERLIN ).getProperty( key, home);
if( null != work )
{
return Artifact.createArtifact( work );
1.1 avalon/merlin/kernel/cli/src/java/org/apache/avalon/merlin/cli/Resources_de.properties
Index: Resources_de.properties
===================================================================
directory=Verzeichnis
file=Datei
url=url?
artifact=artifact?
cli-help-description=Gibt diese Meldung aus.
cli-language-description=Ein Sprachcode aus zwei Buchstaben (ISO-639).
cli-execute-description=???
cli-version-description=Gibt die Systemversionsnummer von Merlin aus.
cli-info-description=???
cli-install-description=???
cli-debug-description=Aktiviere Debug-Meldungen w\u00e4hrend der Bootstrap-Phase.
cli-implementation-description=???
cli-home-description=Ein relativer oder absoluter Pfad zu einem Arbeitswurzelverzeichnis. Wenn der Pfad nicht existiert, wird er angelegt.
cli-kernel-description=???
cli-block-description=???
cli-config-description=???
cli-system-description=???
cli-repository-description=???
cli-library-description=???
cli-description=???
1.1 avalon/merlin/kernel/cli/src/java/org/apache/avalon/merlin/cli/Resources_fr.properties
Index: Resources_fr.properties
===================================================================
url=url
directory=annuaire
file=dossier
artifact=artifact?
cli-help-description=Imprime ce message.
cli-language-description=Un code de pays de deux lettres.
cli-execute-description=???
cli-version-description=Imprime le version de systeme de Merlin.
cli-info-description=???
cli-install-description=???
cli-debug-description=Presentation des messages debug pendant la phase d'initialisation.
cli-implementation-description=???
cli-home-description=Un chemin relatif ou absolu a un repertoire local de fonctionnement. Si non fourni la valeur par defaut correspondra au repertoire local. Un nom releative de chemin sera parent resolu par le repertoire local.
cli-kernel-description=???
cli-block-description=???
cli-config-description=???
cli-system-description=???
cli-repository-description=???
cli-description=???
1.2 +3 -13 avalon/merlin/kernel/impl/conf/merlin.properties
Index: merlin.properties
===================================================================
RCS file: /home/cvs/avalon/merlin/kernel/impl/conf/merlin.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- merlin.properties 8 Dec 2003 15:37:13 -0000 1.1
+++ merlin.properties 9 Dec 2003 09:18:44 -0000 1.2
@@ -25,20 +25,10 @@
#
# A url to the default location of the merlin kernel
-# configuration file.
+# configuration file. This value is commented out as it assumes
+# a merlin install is in place (which is not always the case).
#
-merlin.kernel = file:///${merlin.config}/kernel.xml
-
-#----------------------------------------------------------------------
-# merlin runtime properties
-#----------------------------------------------------------------------
-
-#
-# The working directory.
-# If the system property ${basedir} is defined it will take priority
-# over the value defined here.
-#
-merlin.dir = ${user.dir}
+# merlin.kernel = file:///${merlin.config}/kernel.xml
#
# The partition root directory. The partition root directory serves as
1.2 +72 -29 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultCriteria.java 8 Dec 2003 15:37:13 -0000 1.1
+++ DefaultCriteria.java 9 Dec 2003 09:18:44 -0000 1.2
@@ -65,6 +65,8 @@
import org.apache.avalon.merlin.KernelCriteria;
import org.apache.avalon.merlin.KernelRuntimeException;
+import org.apache.avalon.repository.provider.InitialContext;
+
import org.apache.avalon.util.defaults.Defaults;
import org.apache.avalon.util.defaults.DefaultsFinder;
import org.apache.avalon.util.defaults.SimpleDefaultsFinder;
@@ -158,25 +160,59 @@
new String[0];
//--------------------------------------------------------------
+ // immutable state
+ //--------------------------------------------------------------
+
+ private final InitialContext m_context;
+
+ //--------------------------------------------------------------
// constructor
//--------------------------------------------------------------
/**
* Creation of a new default kernel criteria.
*/
- public DefaultCriteria()
+ public DefaultCriteria( InitialContext context )
{
super( PARAMS );
+ m_context = context;
+
+ //
+ // static defaults are the most primative
+ //
+
Properties avalonStatic = getStaticProperties( AVALON );
Properties merlinStatic = getStaticProperties( MERLIN );
+ //
+ // then comes environment variables
+ //
+
Properties env = getEnvinronment();
+
+ //
+ // then the system properites
+ //
+
Properties system = System.getProperties();
+
+ //
+ // ${user.home} overrides environment
+ //
+
Properties avalonHome = getLocalProperties( USER_HOME, AVALON );
Properties merlinHome = getLocalProperties( USER_HOME, MERLIN );
- Properties avalonWork = getLocalProperties( USER_DIR, AVALON );
- Properties merlinWork = getLocalProperties( USER_DIR, MERLIN );
+
+ //
+ // and ${merlin.dir} overrides ${user.home}
+ //
+
+ File work = getWorkingDirectory();
+ Properties avalonWork =
+ getLocalProperties( work, AVALON );
+ Properties merlinWork =
+ getLocalProperties( work, MERLIN );
//
// Create the finder (discovery policy), construct the defaults, and
@@ -203,6 +239,12 @@
Defaults defaults = new Defaults( SINGLE_KEYS, MULTI_VALUE_KEYS, finders );
+ //
+ // add ${merlin.dir} to assist in synbol expansion then expand
+ // symbols (done twice to handle nested defintions)
+ //
+
+ defaults.setProperty( "merlin.dir", work.toString() );
Defaults.macroExpand( defaults, new Properties[]{ system, avalonStatic, env } );
Defaults.macroExpand( defaults, new Properties[]{ system, avalonStatic, env } );
@@ -212,34 +254,26 @@
// client
//
+ put( "merlin.dir", work.toString() );
ArrayList errors = new ArrayList();
for( int i=0; i<PARAMS.length; i++ )
{
Parameter param = PARAMS[i];
final String key = param.getKey();
- try
+ if( !key.equals( "merlin.dir" ) )
{
- put( key, defaults.getProperty( key ) );
- }
- catch( Exception re )
- {
- errors.add( re );
+ try
+ {
+ put( key, defaults.getProperty( key ) );
+ }
+ catch( Exception re )
+ {
+ errors.add( re );
+ }
}
}
//
- // deal with the special case of a ${basedir} declaration
- // which is equivalent to the overriding of the merlin.dir
- // property
- //
-
- //String basedir = System.getProperty( "basedir" );
- //if( null != basedir )
- //{
- // put( "merlin.dir", basedir );
- //}
-
- //
// check for any errors created in the process and dump a
// notice to System.err
//
@@ -248,6 +282,7 @@
{
Throwable[] throwables =
(Throwable[]) errors.toArray( new Throwable[0] );
+
final String report =
"One or more errors occured while attempting to resolve defaults.";
String message =
@@ -317,6 +352,7 @@
public URL[] getDeploymentURLs()
{
String[] blocks = (String[]) get( MERLIN_DEPLOYMENT );
+
ArrayList list = new ArrayList();
File base = getWorkingDirectory();
for( int i=0; i<blocks.length; i++ )
@@ -354,7 +390,19 @@
*/
public URL getKernelURL()
{
- return (URL) get( MERLIN_KERNEL );
+ URL url = (URL) get( MERLIN_KERNEL );
+ if( null != url ) return url;
+ File conf = getConfigDirectory();
+ if( null == conf ) return null;
+ File kernel = new File( conf, "kernel.xml" );
+ if( kernel.exists() )
+ {
+ return toURL( kernel );
+ }
+ else
+ {
+ return null;
+ }
}
/**
@@ -372,12 +420,7 @@
*/
public File getWorkingDirectory()
{
- String basedir = System.getProperty( "basedir" );
- if( null != basedir )
- {
- return new File( basedir );
- }
- return (File) get( MERLIN_DIR );
+ return m_context.getInitialWorkingDirectory();
}
/**
1.2 +53 -4 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultFactory.java 8 Dec 2003 15:37:13 -0000 1.1
+++ DefaultFactory.java 9 Dec 2003 09:18:44 -0000 1.2
@@ -1,3 +1,52 @@
+/*
+
+ ============================================================================
+ 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 apache@apache.org.
+
+ 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;
@@ -112,7 +161,7 @@
/**
* Creation of a new default factory.
* @param context the repository inital context
- * @param the factory classloader
+ * @param classloader the factory classloader
*/
public DefaultFactory( InitialContext context, ClassLoader classloader )
{
@@ -131,7 +180,7 @@
*/
public Map createDefaultCriteria()
{
- return new DefaultCriteria();
+ return new DefaultCriteria( m_context );
}
/**
@@ -563,7 +612,7 @@
{
Factory factory = context.getInitialFactory();
Map criteria = factory.createDefaultCriteria();
-
+ criteria.put( "avalon.repository.cache", cache );
criteria.put( "avalon.repository.hosts", hosts );
Configuration proxyConfig = config.getChild( "proxy", false );
@@ -728,6 +777,7 @@
{
if( null != url )
{
+
try
{
DefaultConfigurationBuilder builder =
@@ -743,7 +793,6 @@
}
else
{
-
try
{
final InputStream stream =
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org