mcconnell 2003/10/27 15:50:47
Modified: merlin/kernel/loader project.xml
merlin/kernel/loader/src/java/org/apache/avalon/merlin
KernelDefaults.java
Added: merlin/kernel/loader/src/java/org/apache/avalon/merlin
KernelConfig.java merlin.properties
merlin/kernel/loader/src/test/org/apache/avalon/merlin/env
EnvTest.java KernelDefaultsTest.java
Log:
Kernel loader updates from Alex.
Revision Changes Path
1.2 +8 -2 avalon/merlin/kernel/loader/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/avalon/merlin/kernel/loader/project.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- project.xml 24 Oct 2003 06:57:49 -0000 1.1
+++ project.xml 27 Oct 2003 23:50:47 -0000 1.2
@@ -18,6 +18,12 @@
<dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ </dependency>
+
</dependencies>
<build>
@@ -45,9 +51,9 @@
<resources>
<resource>
- <directory>${basedir}/src/etc</directory>
+ <directory>${basedir}/src/java</directory>
<includes>
- <include>merlin.properties</include>
+ <include>**/merlin.properties</include>
</includes>
</resource>
<resource>
1.2 +254 -54
avalon/merlin/kernel/loader/src/java/org/apache/avalon/merlin/KernelDefaults.java
Index: KernelDefaults.java
===================================================================
RCS file:
/home/cvs/avalon/merlin/kernel/loader/src/java/org/apache/avalon/merlin/KernelDefaults.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- KernelDefaults.java 24 Oct 2003 06:57:51 -0000 1.1
+++ KernelDefaults.java 27 Oct 2003 23:50:47 -0000 1.2
@@ -48,7 +48,20 @@
*/
-package org.apache.avalon.merlin;
+package org.apache.avalon.merlin ;
+
+
+import java.io.File ;
+import java.io.IOException ;
+import java.io.InputStream ;
+import java.io.FileInputStream ;
+
+import java.util.ArrayList ;
+import java.util.Properties ;
+import java.util.Enumeration ;
+
+import org.apache.avalon.merlin.env.Env ;
+import org.apache.avalon.merlin.env.EnvAccessException ;
/**
@@ -58,168 +71,355 @@
* system properties. Basically the policy of finding the values to these
* kernel parameters are maintained here.
*
+ * @todo document the property keys and make sure they reflect those defined by
+ * Steve in his emails
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
* @author $Author$
* @version $Revision$
*/
public class KernelDefaults
{
+ private static final String [] s_keys =
+ {
+ "merlin.kernel.isserver",
+ "merlin.kernel.isinfo",
+ "merlin.kernel.isdebug",
+ "merlin.kernel.remoterepo",
+ "merlin.kernel.userrepo",
+ "merlin.kernel.systemrepo",
+ "merlin.kernel.homepath",
+ "merlin.kernel.configurl",
+ "merlin.kernel.kernelurl",
+ "java.io.tmpdir",
+ "merlin.kernel.librarypath"
+ } ;
+
+
public static final String IS_SERVER_KEY =
- "merlin.kernel.isserver" ;
+ s_keys[0] ;
public static final String IS_INFO_KEY =
- "merlin.kernel.isinfo" ;
+ s_keys[1] ;
public static final String IS_DEBUG_KEY =
- "merlin.kernel.isdebug" ;
+ s_keys[2] ;
public static final String REMOTE_REPO_KEY =
- "merlin.kernel.remoterepo" ;
+ s_keys[3] ;
public static final String USER_REPO_KEY =
- "merlin.kernel.userrepo" ;
+ s_keys[4] ;
public static final String SYSTEM_REPO_KEY =
- "merlin.kernel.systemrepo" ;
+ s_keys[5] ;
public static final String HOME_PATH_KEY =
- "merlin.kernel.homepath" ;
+ s_keys[6] ;
public static final String CONFIG_URL_KEY =
- "merlin.kernel.configurl" ;
+ s_keys[7] ;
public static final String KERNEL_URL_KEY =
- "merlin.kernel.kernelurl" ;
- public static final String TARGET_URLS_KEY =
- "merlin.kernel.targeturls" ;
+ s_keys[8] ;
public static final String TEMP_PATH_KEY =
- "merlin.kernel.temppath" ;
+ s_keys[9] ;
public static final String LIBRARY_PATH_KEY =
- "merlin.kernel.librarypath" ;
+ s_keys[10] ;
+
+ public static final String TARGET_URLS_BASE =
+ "merlin.kernel.targeturls" ;
+ public static final String MERLIN_FILE_BASE =
+ "merlin.properties" ;
+
+ /** Overlay of default properties discovered */
+ private static final Properties s_defaults = new Properties() ;
+
+
+ static
+ {
+ loadDefaults() ;
+ }
+
+ /**
+ * Loads the defaults for the kernel configuration. Not fail fast meaning
+ * if it fails at one stage it continues to gather defaults rather than
+ * bombing out.
+ */
+ private static void loadDefaults()
+ {
+ /*
+ * Stage I - load the default properties bundled with this jar
+ */
+
+ InputStream l_in =
+ KernelDefaults.class.getResourceAsStream( MERLIN_FILE_BASE ) ;
+
+ try
+ {
+ s_defaults.load( l_in ) ;
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace( System.err ) ;
+ }
+
+ /*
+ * Stage II - get some properties from the shell environment
+ */
+ File l_merlinHome = null ;
+ try
+ {
+ l_merlinHome = new File( Env.getVariable( "MERLIN_HOME" ) ) ;
+ }
+ catch( EnvAccessException e )
+ {
+ e.printStackTrace( System.err ) ;
+ }
+
+ if ( null != l_merlinHome && l_merlinHome.exists() )
+ {
+ File l_sysRepo = new File( l_merlinHome, "system" ) ;
+ if ( l_sysRepo.exists() )
+ {
+ s_defaults.setProperty( SYSTEM_REPO_KEY,
+ l_sysRepo.getAbsolutePath() ) ;
+ }
+
+ File l_userRepo = new File( l_merlinHome, "repository" ) ;
+ if ( l_userRepo.exists() )
+ {
+ s_defaults.setProperty( USER_REPO_KEY,
+ l_userRepo.getAbsolutePath() ) ;
+ }
+ }
+
+ /*
+ * Stage III - check for overriding values of .merlin.properties within
+ * the user's home directory.
+ */
+ String l_userHome = System.getProperty( "user.home" ) ;
+ File l_userProps = new File( l_userHome, "." + MERLIN_FILE_BASE ) ;
+ if ( l_userProps.exists() )
+ {
+ try
+ {
+ s_defaults.load( new FileInputStream( l_userProps ) ) ;
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace( System.err ) ;
+ }
+ }
+
+ /*
+ * Stage IV - Check for overriding values within the System properties
+ */
+ for( int ii = 0; ii < s_keys.length; ii++ )
+ {
+ /*
+ * If s_defaults has the property use it as default in case property
+ * does not exist in the system properties.
+ */
+ String l_default = System.getProperty( s_keys[ii],
+ s_defaults.getProperty( s_keys[ii] ) ) ;
+ if ( null != l_default )
+ {
+ s_defaults.setProperty( s_keys[ii], l_default ) ;
+ }
+ }
+
+ // Now we overlay all the targets properties defined
+ Enumeration l_list = System.getProperties().keys() ;
+ while ( l_list.hasMoreElements() )
+ {
+ String l_key = ( String ) l_list.nextElement() ;
+ if ( l_key.startsWith( TARGET_URLS_BASE ) )
+ {
+ String l_default = System.getProperty( l_key,
+ s_defaults.getProperty( l_key ) ) ;
+
+ if ( null != l_default )
+ {
+ s_defaults.setProperty( l_key, l_default ) ;
+ }
+ }
+ }
+ }
+
/**
- * Gets a default value for the server flag.
+ * Gets a default value for the server flag property for the KernelConfig.
*
- * @see org.apache.avalon.merlin.kernel.KernelParameters#isServer()
+ * @return true if the IS_SERVER_KEY property value is set to 1, true, yes
+ * or on, and false otherwise.
+ * @see org.apache.avalon.merlin.kernel.KernelConfig#isServer()
*/
public static boolean isServer()
{
- throw new UnsupportedOperationException(
- "N O T I M P L E M E N T E D Y E T !" ) ;
+ return getBoolean( IS_SERVER_KEY ) ;
}
/**
* Gets a default value for the debug flag.
*
- * @see org.apache.avalon.merlin.kernel.KernelParameters#isDebugEnabled()
+ * @see org.apache.avalon.merlin.kernel.KernelConfig#isDebugEnabled()
*/
public static boolean isDebugEnabled()
{
- throw new UnsupportedOperationException(
- "N O T I M P L E M E N T E D Y E T !" ) ;
+ return getBoolean( IS_DEBUG_KEY ) ;
}
/**
* Gets a default value for the info flag.
*
- * @see org.apache.avalon.merlin.kernel.KernelParameters#isInfoEnabled()
+ * @see org.apache.avalon.merlin.kernel.KernelConfig#isInfoEnabled()
*/
public static boolean isInfoEnabled()
{
- throw new UnsupportedOperationException(
- "N O T I M P L E M E N T E D Y E T !" ) ;
+ return getBoolean( IS_INFO_KEY ) ;
}
/**
* Gets a default value for the remote repo.
*
- * @see org.apache.avalon.merlin.kernel.KernelParameters#
+ * @see org.apache.avalon.merlin.kernel.KernelConfig#
* getRemoteRepositoryUrl()
*/
public static String getRemoteRepositoryUrl()
{
- throw new UnsupportedOperationException(
- "N O T I M P L E M E N T E D Y E T !" ) ;
+ return s_defaults.getProperty( REMOTE_REPO_KEY ) ;
}
/**
- *
- * @see org.apache.avalon.merlin.kernel.KernelParameters#
+ * Gets the default value for the user repository path.
+ *
+ * @see org.apache.avalon.merlin.kernel.KernelConfig#
* getUserRepositoryPath()
*/
public static String getUserRepositoryPath()
{
- throw new UnsupportedOperationException(
- "N O T I M P L E M E N T E D Y E T !" ) ;
+ return s_defaults.getProperty( USER_REPO_KEY ) ;
}
/**
- * @see org.apache.avalon.merlin.kernel.KernelParameters#
+ * Gets the default value for the system repository path.
+ *
+ * @see org.apache.avalon.merlin.kernel.KernelConfig#
* getSystemRepositoryPath()
*/
public static String getSystemRepositoryPath()
{
- throw new UnsupportedOperationException(
- "N O T I M P L E M E N T E D Y E T !" ) ;
+ return s_defaults.getProperty( SYSTEM_REPO_KEY ) ;
}
/**
- * @see org.apache.avalon.merlin.kernel.KernelParameters#getLibraryPath()
+ * Gets the default path to optional extention librarys.
+ *
+ * @see org.apache.avalon.merlin.kernel.KernelConfig#getLibraryPath()
*/
public static String getLibraryPath()
{
- throw new UnsupportedOperationException(
- "N O T I M P L E M E N T E D Y E T !" ) ;
+ return s_defaults.getProperty( LIBRARY_PATH_KEY ) ;
}
/**
- * @see org.apache.avalon.merlin.kernel.KernelParameters#getHomePath()
+ * Gets the path to the instance home or working directory.
+ *
+ * @see org.apache.avalon.merlin.kernel.KernelConfig#getHomePath()
*/
public static String getHomePath()
{
- throw new UnsupportedOperationException(
- "N O T I M P L E M E N T E D Y E T !" ) ;
+ return s_defaults.getProperty( HOME_PATH_KEY ) ;
}
/**
- * @see org.apache.avalon.merlin.kernel.KernelParameters#getTempPath()
+ * Gets the path to a temporary directory.
+ *
+ * @see org.apache.avalon.merlin.kernel.KernelConfig#getTempPath()
*/
public static String getTempPath()
{
- throw new UnsupportedOperationException(
- "N O T I M P L E M E N T E D Y E T !" ) ;
+ return s_defaults.getProperty( TEMP_PATH_KEY ) ;
}
/**
- * @see org.apache.avalon.merlin.kernel.KernelParameters#getConfigUrl()
+ * Gets the path to the server configuration file or config.xml.
+ *
+ * @see org.apache.avalon.merlin.kernel.KernelConfig#getConfigUrl()
*/
public static String getConfigUrl()
{
- throw new UnsupportedOperationException(
- "N O T I M P L E M E N T E D Y E T !" ) ;
+ return s_defaults.getProperty( CONFIG_URL_KEY ) ;
}
/**
- * @see org.apache.avalon.merlin.kernel.KernelParameters#getTargetUrls()
+ * Gets the set of block.xml file urls for components that are setup by the
+ * kernel. Note that properties are enumerated off of the base key using
+ * dot number notation like base.1, base.2, ... , base.n.
+ *
+ * @see org.apache.avalon.merlin.kernel.KernelConfig#getTargetUrls()
*/
public static String[] getTargetUrls()
{
- throw new UnsupportedOperationException(
- "N O T I M P L E M E N T E D Y E T !" ) ;
+ String [] l_urls = null ;
+ ArrayList l_urlArray = new ArrayList() ;
+ Enumeration l_list = s_defaults.keys() ;
+
+ while ( l_list.hasMoreElements() )
+ {
+ String l_key = ( String ) l_list.nextElement() ;
+ if ( l_key.startsWith( TARGET_URLS_BASE ) )
+ {
+ l_urlArray.add( s_defaults.getProperty( l_key ) ) ;
+ }
+ }
+
+ return ( String [] ) l_urlArray.toArray( new String [0] ) ;
}
/**
- * @see org.apache.avalon.merlin.kernel.KernelParameters#getKernelUrl()
+ * Gets the url to the kernel configuration xml file.
+ *
+ * @see org.apache.avalon.merlin.kernel.KernelConfig#getKernelUrl()
*/
public static String getKernelUrl()
{
- throw new UnsupportedOperationException(
- "N O T I M P L E M E N T E D Y E T !" ) ;
+ return s_defaults.getProperty( KERNEL_URL_KEY ) ;
+ }
+
+
+ // ------------------------------------------------------------------------
+ // Private Utility Methods
+ // ------------------------------------------------------------------------
+
+
+ /**
+ * Utility method that gets a key's value and returns a boolean value to
+ * represent it.
+ *
+ * @param a_key the boolean property key
+ * @return true if the property is 1, true, yes or on, and false otherwise
+ */
+ private static boolean getBoolean( String a_key )
+ {
+ String l_value = s_defaults.getProperty( a_key ) ;
+ l_value = l_value.trim().toLowerCase() ;
+
+ if ( l_value.equals( "1" ) ||
+ l_value.equals( "on" ) ||
+ l_value.equals( "yes" ) ||
+ l_value.equals( "true" ) )
+ {
+ return true ;
+ }
+
+ return false ;
}
}
1.1
avalon/merlin/kernel/loader/src/java/org/apache/avalon/merlin/KernelConfig.java
Index: KernelConfig.java
===================================================================
package org.apache.avalon.merlin ;
/**
* Kernel configuration parameters.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
* @author $Author: mcconnell $
* @version $Revision: 1.1 $
*/
public class KernelConfig
{
/** @todo confirm default value */
private boolean m_isServer = KernelDefaults.isServer() ;
/** @todo confirm default value */
private boolean m_isDebug = KernelDefaults.isDebugEnabled() ;
/** @todo confirm default value */
private boolean m_isInfo = KernelDefaults.isInfoEnabled() ;
/** @todo confirm default value */
private String m_remoteRepositoryUrl =
KernelDefaults.getRemoteRepositoryUrl() ;
/** @todo confirm default value */
private String m_systemRepositoryPath =
KernelDefaults.getSystemRepositoryPath() ;
/** @todo confirm default value */
private String m_userRepositoryPath =
KernelDefaults.getUserRepositoryPath() ;
/** @todo confirm default value */
private String m_configUrl = KernelDefaults.getConfigUrl() ;
/** @todo confirm default value */
private String m_homePath = KernelDefaults.getHomePath() ;
/** @todo confirm default value */
private String m_kernelUrl = KernelDefaults.getKernelUrl() ;
/** @todo confirm default value */
private String m_libraryPath = KernelDefaults.getLibraryPath() ;
/** @todo confirm default value */
private String m_tempPath = KernelDefaults.getTempPath() ;
/** @todo confirm default value */
private String [] m_targetUrls = KernelDefaults.getTargetUrls() ;
public boolean isServer()
{
return m_isServer ;
}
public boolean isDebugEnabled()
{
return m_isDebug ;
}
public boolean isInfoEnabled()
{
return m_isInfo ;
}
public String getRemoteRepositoryUrl()
{
return m_remoteRepositoryUrl ;
}
public String getUserRepositoryPath()
{
return m_userRepositoryPath ;
}
public String getSystemRepositoryPath()
{
return m_systemRepositoryPath ;
}
public String getLibraryPath()
{
return m_libraryPath ;
}
public String getHomePath()
{
return m_homePath ;
}
public String getTempPath()
{
return m_tempPath ;
}
public String getConfigUrl()
{
return m_configUrl ;
}
public String[] getTargetUrls()
{
return m_targetUrls ;
}
public String getKernelUrl()
{
return m_kernelUrl ;
}
/**
* @param a_configUrl The configUrl to set.
*/
public void setConfigUrl( String a_configUrl )
{
m_configUrl = a_configUrl ;
}
/**
* @param a_homePath The homePath to set.
*/
public void setHomePath( String a_homePath )
{
m_homePath = a_homePath ;
}
/**
* @param a_isDebug The isDebug to set.
*/
public void setDebug( boolean a_isDebug )
{
m_isDebug = a_isDebug ;
}
/**
* @param a_isInfo The isInfo to set.
*/
public void setInfo( boolean a_isInfo )
{
m_isInfo = a_isInfo ;
}
/**
* @param a_isServer The isServer to set.
*/
public void setServer( boolean a_isServer )
{
m_isServer = a_isServer ;
}
/**
* @param a_kernelUrl The kernelUrl to set.
*/
public void setKernelUrl( String a_kernelUrl )
{
m_kernelUrl = a_kernelUrl ;
}
/**
* @param a_libraryPath The libraryPath to set.
*/
public void setLibraryPath( String a_libraryPath )
{
m_libraryPath = a_libraryPath ;
}
/**
* @param a_remoteRepositoryUrl The remoteRepositoryUrl to set.
*/
public void setRemoteRepositoryUrl( String a_remoteRepositoryUrl )
{
m_remoteRepositoryUrl = a_remoteRepositoryUrl ;
}
/**
* @param a_systemRepositoryPath The systemRepositoryPath to set.
*/
public void setSystemRepositoryPath( String a_systemRepositoryPath )
{
m_systemRepositoryPath = a_systemRepositoryPath ;
}
/**
* @param a_targetUrls The targetUrls to set.
*/
public void setTargetUrls( String [] a_targetUrls )
{
m_targetUrls = a_targetUrls ;
}
/**
* @param a_tempPath The tempPath to set.
*/
public void setTempPath( String a_tempPath )
{
m_tempPath = a_tempPath ;
}
/**
* @param a_userRepositoryPath The userRepositoryPath to set.
*/
public void setUserRepositoryPath( String a_userRepositoryPath )
{
m_userRepositoryPath = a_userRepositoryPath ;
}
}
1.1
avalon/merlin/kernel/loader/src/java/org/apache/avalon/merlin/merlin.properties
Index: merlin.properties
===================================================================
#start
#foo=bar
1.1
avalon/merlin/kernel/loader/src/test/org/apache/avalon/merlin/env/EnvTest.java
Index: EnvTest.java
===================================================================
package org.apache.avalon.merlin.env;
import junit.framework.TestCase ;
/**
* Env tests.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
* @author $Author: mcconnell $
* @version $Revision: 1.1 $
*/
public class EnvTest extends TestCase
{
public static void main(String[] args)
{
junit.textui.TestRunner.run(EnvTest.class);
}
/*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception
{
super.setUp();
}
/*
* @see TestCase#tearDown()
*/
protected void tearDown() throws Exception
{
super.tearDown();
}
/**
* Constructor for EnvTest.
* @param arg0
*/
public EnvTest(String arg0)
{
super(arg0);
}
final public void testGetProperty()
throws Exception
{
assertNull( Env.getVariable( "PAT" ) ) ;
assertNotNull( Env.getVariable( "PATH" ) ) ;
EnvAccessException l_error = null ;
try
{
Env.getVariable( "--*&^%^%$" ) ;
}
catch( EnvAccessException e )
{
l_error = e ;
}
assertNotNull( l_error ) ;
}
}
1.1
avalon/merlin/kernel/loader/src/test/org/apache/avalon/merlin/env/KernelDefaultsTest.java
Index: KernelDefaultsTest.java
===================================================================
/*
* $Id: KernelDefaultsTest.java,v 1.1 2003/10/27 23:50:47 mcconnell Exp $
*
* -- (c) LDAPd Group --
* -- Please refer to the LICENSE.txt file in the root directory of --
* -- any LDAPd project for copyright and distribution information. --
*
* Created on Oct 27, 2003
*/
package org.apache.avalon.merlin.env;
import org.apache.avalon.merlin.KernelDefaults;
import junit.framework.TestCase;
/**
* @todo
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
* @author $Author: mcconnell $
* @version $Revision: 1.1 $
*/
public class KernelDefaultsTest extends TestCase
{
public static void main(String[] args)
{
junit.textui.TestRunner.run(KernelDefaultsTest.class);
}
/*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception
{
super.setUp();
}
/*
* @see TestCase#tearDown()
*/
protected void tearDown() throws Exception
{
super.tearDown();
}
/**
* Constructor for KernelDefaultsTest.
* @param arg0
*/
public KernelDefaultsTest(String arg0)
{
super(arg0);
}
final public void testGetTempPath()
{
assertEquals( KernelDefaults.getTempPath(),
System.getProperty( "java.io.tmpdir" ) ) ;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]