mcconnell 2003/11/24 13:26:36
Modified: kernel maven.xml project.xml
kernel/impl maven.xml project.xml
kernel/impl/src/java/org/apache/avalon/merlin/kernel
KernelCriteria.java
kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl
DefaultCriteria.java DefaultFactory.java
kernel/test/src/test/org/apache/avalon/merlin
MerlinEmbeddedTest.java
Log:
General progress on getting defaults management in place on the kernel context.
Revision Changes Path
1.5 +2 -2 avalon-sandbox/kernel/maven.xml
Index: maven.xml
===================================================================
RCS file: /home/cvs/avalon-sandbox/kernel/maven.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- maven.xml 24 Nov 2003 14:57:27 -0000 1.4
+++ maven.xml 24 Nov 2003 21:26:36 -0000 1.5
@@ -14,13 +14,13 @@
ignoreFailures="false" />
</goal>
- <goal name="merlin:clean" prereqs="clean">
+ <goal name="avalon:clean" prereqs="clean">
<maven:reactor
basedir="${basedir}"
includes="**/project.xml"
excludes="project.xml"
goals="clean:clean"
- banner="Cleaning subproject:"
+ banner="Cleaning:"
ignoreFailures="true"/>
</goal>
1.3 +1 -7 avalon-sandbox/kernel/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/avalon-sandbox/kernel/project.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- project.xml 13 Nov 2003 14:24:41 -0000 1.2
+++ project.xml 24 Nov 2003 21:26:36 -0000 1.3
@@ -282,15 +282,9 @@
</resource>
<resource>
<directory>${basedir}/conf</directory>
- <includes>
+ <includes>
<include>**/*.properties</include>
<include>kernel.xml</include>
- </includes>
- </resource>
- <resource>
- <directory>${basedir}</directory>
- <includes>
- <include>snapshot.properties</include>
</includes>
</resource>
</resources>
1.2 +2 -3 avalon-sandbox/kernel/impl/maven.xml
Index: maven.xml
===================================================================
RCS file: /home/cvs/avalon-sandbox/kernel/impl/maven.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- maven.xml 24 Nov 2003 15:14:18 -0000 1.1
+++ maven.xml 24 Nov 2003 21:26:36 -0000 1.2
@@ -15,8 +15,7 @@
<postGoal name="java:compile">
- <ant:mkdir dir="${maven.build.dir}/classes/${pom.groupId}"/>
- <ant:echo
file="${maven.build.dir}/classes/${pom.groupId}/${pom.artifactId}.meta">
+ <ant:echo file="${maven.build.dir}/${pom.artifactId}.meta">
#
# Metadata identification.
# This file if generated under the Avalon Repository Main build process.
@@ -43,7 +42,7 @@
</ant:echo>
<ant:mkdir dir="${maven.repo.local}/${pom.groupId}"/>
<ant:copy toDir="${maven.repo.local}/${pom.groupId}"
- file="${maven.build.dir}/classes/${pom.groupId}/${pom.artifactId}.meta"/>
+ file="${maven.build.dir}/${pom.artifactId}.meta" verbose="yes"/>
</postGoal>
</project>
1.6 +12 -2 avalon-sandbox/kernel/impl/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/avalon-sandbox/kernel/impl/project.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- project.xml 24 Nov 2003 14:57:27 -0000 1.5
+++ project.xml 24 Nov 2003 21:26:36 -0000 1.6
@@ -5,8 +5,8 @@
<extend>${basedir}/../project.xml</extend>
<groupId>merlin</groupId>
- <id>merlin-kernel-test</id>
- <name>Merlin Kernel TestCase</name>
+ <id>merlin-kernel-impl</id>
+ <name>Merlin Kernel Implementation</name>
<package>org.apache.avalon.merlin</package>
<currentVersion>3.2.2-dev</currentVersion>
@@ -159,6 +159,16 @@
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework-impl</artifactId>
<version>4.1.5</version>
+ </dependency>
+ <dependency>
+ <groupId>avalon-util</groupId>
+ <artifactId>avalon-util-defaults</artifactId>
+ <version>1.0-dev</version>
+ </dependency>
+ <dependency>
+ <groupId>avalon-util</groupId>
+ <artifactId>avalon-util-env</artifactId>
+ <version>1.0-dev</version>
</dependency>
<!-- logkit dependecies -->
1.2 +56 -27
avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/KernelCriteria.java
Index: KernelCriteria.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/KernelCriteria.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- KernelCriteria.java 24 Nov 2003 08:10:36 -0000 1.1
+++ KernelCriteria.java 24 Nov 2003 21:26:36 -0000 1.2
@@ -65,74 +65,101 @@
public interface KernelCriteria extends Criteria
{
/**
+ * Shared application repository root directory.
+ */
+ public static final Parameter AVALON_HOME =
+ new Parameter(
+ "avalon.home",
+ File.class.getName(),
+ false );
+
+ /**
* Repository parameter descriptor.
*/
- public static final Parameter MERLIN_REPOSITORY_DIR =
+ public static final Parameter MERLIN_HOME =
new Parameter(
- "urn:merlin:repository.dir",
+ "merlin.home",
File.class.getName(),
false );
/**
- * Library path parameter descriptor.
+ * Repository parameter descriptor.
+ */
+ public static final Parameter MERLIN_SYSTEM =
+ new Parameter(
+ "merlin.system",
+ File.class.getName(),
+ false );
+
+ /**
+ * Repository parameter descriptor.
*/
- public static final Parameter MERLIN_LIBRARY_DIR =
+ public static final Parameter MERLIN_CONFIG =
new Parameter(
- "urn:merlin:library.dir",
+ "merlin.config",
File.class.getName(),
false );
/**
+ * Library path parameter descriptor.
+ */
+ public static final Parameter MERLIN_KERNEL =
+ new Parameter(
+ "merlin.kernel",
+ URL.class.getName(),
+ false );
+
+ /**
* Home directory parameter descriptor.
*/
- public static final Parameter MERLIN_HOME_DIR =
+ public static final Parameter MERLIN_DIR =
new Parameter(
- "urn:merlin:home.dir",
+ "merlin.dir",
File.class.getName(),
false );
/**
* Base directory parameter descriptor.
*/
- public static final Parameter MERLIN_BASE_DIR =
+ public static final Parameter MERLIN_CONTEXT =
new Parameter(
- "urn:merlin:base.dir",
+ "merlin.context",
File.class.getName(),
false );
/**
* Kernel url parameter descriptor.
*/
- public static final Parameter MERLIN_KERNEL_URL =
+ public static final Parameter MERLIN_EXT =
new Parameter(
- "urn:merlin:kernel.url",
- URL.class.getName(),
+ "merlin.ext",
+ File.class.getName(),
false );
/**
* Info policy parameter descriptor.
*/
- public static final Parameter MERLIN_POLICY_INFO =
+ public static final Parameter MERLIN_INFO =
new Parameter(
- "urn:merlin:policy.info",
+ "merlin.info",
Boolean.class.getName(),
false );
/**
* Debug policy parameter descriptor.
*/
- public static final Parameter MERLIN_POLICY_DEBUG =
+ public static final Parameter MERLIN_DEBUG =
new Parameter(
- "urn:merlin:policy.debug",
+ "merlin.debug",
Boolean.class.getName(),
false );
/**
* Server model parameter descriptor.
*/
- public static final Parameter MERLIN_POLICY_SERVER =
+ public static final Parameter MERLIN_SERVER =
new Parameter(
- "urn:merlin:policy.server",
+ "merlin.server",
Boolean.class.getName(),
false );
@@ -141,13 +168,15 @@
*/
public static final Parameter[] PARAMS =
new Parameter[]{
- MERLIN_REPOSITORY_DIR,
- MERLIN_LIBRARY_DIR,
- MERLIN_HOME_DIR,
- MERLIN_BASE_DIR,
- MERLIN_KERNEL_URL,
- MERLIN_POLICY_INFO,
- MERLIN_POLICY_DEBUG,
- MERLIN_POLICY_SERVER };
+ MERLIN_HOME,
+ MERLIN_SYSTEM,
+ MERLIN_CONFIG,
+ MERLIN_KERNEL,
+ MERLIN_DIR,
+ MERLIN_CONTEXT,
+ MERLIN_EXT,
+ MERLIN_INFO,
+ MERLIN_DEBUG,
+ MERLIN_SERVER };
}
1.4 +153 -3
avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultCriteria.java
Index: DefaultCriteria.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultCriteria.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefaultCriteria.java 24 Nov 2003 14:57:27 -0000 1.3
+++ DefaultCriteria.java 24 Nov 2003 21:26:36 -0000 1.4
@@ -50,13 +50,28 @@
package org.apache.avalon.merlin.kernel.impl;
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Properties;
+import java.util.Map;
+
import org.apache.avalon.merlin.kernel.KernelCriteria;
+import org.apache.avalon.merlin.kernel.KernelRuntimeException;
+
+import org.apache.avalon.repository.RepositoryException;
import org.apache.avalon.repository.criteria.Criteria;
import org.apache.avalon.repository.criteria.ValidationException;
import org.apache.avalon.repository.criteria.Parameter;
-import java.util.Hashtable;
-import java.util.Map;
+import org.apache.avalon.defaults.Defaults;
+import org.apache.avalon.defaults.DefaultsFinder;
+import org.apache.avalon.defaults.SimpleDefaultsFinder;
+import org.apache.avalon.defaults.SystemDefaultsFinder;
+
+import org.apache.avalon.util.env.Env;
+import org.apache.avalon.util.env.EnvAccessException;
/**
* A Criteria is a class holding the values supplied by a user
@@ -68,12 +83,111 @@
public class DefaultCriteria implements KernelCriteria
{
//--------------------------------------------------------------
+ // static
+ //--------------------------------------------------------------
+
+ private static final String AVALON = "/avalon.properties";
+ private static final String MERLIN = "/merlin.properties";
+
+ private static final String [] SINGLE_KEYS = {
+ AVALON_HOME.getKey(),
+ MERLIN_HOME.getKey(),
+ MERLIN_SYSTEM.getKey(),
+ MERLIN_CONFIG.getKey(),
+ MERLIN_KERNEL.getKey(),
+ MERLIN_DIR.getKey(),
+ MERLIN_CONTEXT.getKey(),
+ MERLIN_EXT.getKey(),
+ MERLIN_INFO.getKey(),
+ MERLIN_DEBUG.getKey(),
+ MERLIN_SERVER.getKey() };
+
+ private static final String[] MULTI_VALUE_KEYS = new String[0];
+
+ //--------------------------------------------------------------
// state
//--------------------------------------------------------------
private final Hashtable m_bindings = new Hashtable();
//--------------------------------------------------------------
+ // constructor
+ //--------------------------------------------------------------
+
+ /**
+ * Creation of a new default kernel criteria.
+ */
+ public DefaultCriteria()
+ {
+ Properties avalon = getStaticProperties( AVALON );
+ Properties merlin = getStaticProperties( MERLIN );
+ Properties env = getEnvinronment();
+ Properties system = System.getProperties();
+
+ printProperties( avalon, "avalon" );
+ printProperties( merlin, "merin" );
+ printProperties( env, "environment" );
+
+ //
+ // Create the finder (discovery policy), construct the defaults, and
+ // macro expand the values.
+ //
+
+ final DefaultsFinder[] finders =
+ new DefaultsFinder[]{
+ new SimpleDefaultsFinder(
+ new Properties[] { avalon, merlin },
+ false ),
+ new SystemDefaultsFinder()
+ };
+
+ Defaults defaults = new Defaults( SINGLE_KEYS, MULTI_VALUE_KEYS, finders );
+ printProperties( defaults, "defaults (unresolved)" );
+ Defaults.macroExpand( defaults, new Properties[]{ system, env } );
+ Defaults.macroExpand( defaults, new Properties[]{ system, env } );
+ printProperties( defaults, "defaults (resolved)" );
+ System.out.print( "" );
+
+ }
+
+ private void printProperties( Properties properties, String label )
+ {
+ System.out.print( "\n------------ " + label.toUpperCase()
+ + "--------------------------------".substring( label.length() ) + "\n\n"
);
+ if( null == properties ) return;
+ Enumeration names = properties.propertyNames();
+ while( names.hasMoreElements() )
+ {
+ String name = (String) names.nextElement();
+ System.out.println( " ${" + name + "} == " + properties.getProperty(
name ) );
+ }
+ }
+
+ private Properties getEnvinronment()
+ {
+ try
+ {
+ Properties properties = new Properties();
+ setProperty( properties, "avalon.home", Env.getEnvVariable(
"AVALON_HOME" ) );
+ setProperty( properties, "maven.home", Env.getEnvVariable( "MAVEN_HOME"
) );
+ setProperty( properties, "maven.home.local", Env.getEnvVariable(
"MAVEN_HOME_LOCAL" ) );
+ setProperty( properties, "merlin.home", Env.getEnvVariable(
"MERLIN_HOME" ) );
+ return properties;
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Internal error occured while attempting to access system
environment.";
+ throw new KernelRuntimeException( error, e );
+ }
+ }
+
+ private void setProperty( Properties properties, String key, String value )
+ {
+ if( null != value ) properties.setProperty( key, value );
+ }
+
+ //--------------------------------------------------------------
// Criteria
//--------------------------------------------------------------
@@ -185,6 +299,42 @@
}
final String error = "Unknown key: [" + key + "].";
throw new IllegalArgumentException( error );
+ }
+
+ /**
+ * Read in the static defined properties that contribute to
+ * the default context value establishment.
+ *
+ * @return the static default properties
+ * @exception RepositoryException if a error occurs while attempt to
+ * load the property resource
+ */
+ private Properties getStaticProperties( String path ) throws
KernelRuntimeException
+ {
+ Properties bootstrap = new Properties();
+ try
+ {
+ InputStream input =
+ DefaultCriteria.class.getResourceAsStream( path );
+ if( input == null )
+ {
+ final String error =
+ "Internal error, unable to locate enbedded resource: "
+ + path
+ + " from the resource: "
+ + DefaultCriteria.class.getProtectionDomain()
+ .getCodeSource().getLocation();
+ throw new IllegalStateException( error );
+ }
+ bootstrap.load( input );
+ return bootstrap;
+ }
+ catch ( IOException e )
+ {
+ throw new KernelRuntimeException(
+ "Failed to load implementation defaults resource: "
+ + path, e );
+ }
}
}
1.5 +1 -9
avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultFactory.java
Index: DefaultFactory.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultFactory.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultFactory.java 24 Nov 2003 14:57:27 -0000 1.4
+++ DefaultFactory.java 24 Nov 2003 21:26:36 -0000 1.5
@@ -48,17 +48,9 @@
public Object create( Map map )
{
//
- // Alex - over to you. The supplied map
- // has a set of values bound to keys defined in
- // the DefaultFactory (see kernel/impl package
- // in sandbox. All we need to do now is to
- // combine this top-level directives with
- // static defaults, environment variables and
- // synbol parsing and we are home free.
+ // create the kernel with the supplied values
//
-
- System.out.println( "CRITERIA: " + map );
return null;
}
}
1.2 +9 -8
avalon-sandbox/kernel/test/src/test/org/apache/avalon/merlin/MerlinEmbeddedTest.java
Index: MerlinEmbeddedTest.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/kernel/test/src/test/org/apache/avalon/merlin/MerlinEmbeddedTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MerlinEmbeddedTest.java 24 Nov 2003 14:57:27 -0000 1.1
+++ MerlinEmbeddedTest.java 24 Nov 2003 21:26:36 -0000 1.2
@@ -124,28 +124,29 @@
// populate the criteria with stuff
//
+ /*
criteria.setValue(
- "urn:merlin:base.dir",
+ "merlin.base.dir",
new File( getBaseDirectory(), "home" ) );
criteria.setValue(
- "urn:merlin:policy.info",
+ "merlin.policy.info",
new Boolean( true ) );
criteria.setValue(
- "urn:merlin:policy.debug",
+ "merlin.policy.debug",
new Boolean( true ) );
criteria.setValue(
- "urn:merlin:policy.server",
+ "merlin.policy.server",
new Boolean( false ) );
+ */
//
// instantiate the application
//
Object app = factory.create( criteria );
- System.out.println( "APP: " + app );
}
//----------------------------------------------------------------------
@@ -155,14 +156,14 @@
private static String[] getBootstrapRepositorySet()
{
return new String[]{
- "file:///" + System.getProperty( "basedir" ) + "/target/repository",
+ "file:///" + System.getProperty( "basedir" ) + "/target/repository/",
};
}
private static String[] getWorkingRepositorySet()
{
return new String[]{
- "file:///" + System.getProperty( "basedir" ) + "/target/repository",
+ "file:///" + System.getProperty( "basedir" ) + "/target/repository/",
"http://dpml.net/",
"http://www.ibiblio.org/maven/"
};
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]