mcconnell 2004/02/19 04:25:29
Modified: logging/logkit/impl maven.xml
logging/logkit/impl/src/java/org/apache/avalon/logging/logkit
DefaultLoggingCriteria.java
repository/impl/src/java/org/apache/avalon/repository/impl
DefaultRepositoryCriteria.java
repository/main/src/java/org/apache/avalon/repository/main
DefaultInitialContextFactory.java
Log:
CLeaning up of the repository and logging context implementations based on the
enhancements to the intial context object model.
Revision Changes Path
1.2 +17 -0 avalon/logging/logkit/impl/maven.xml
Index: maven.xml
===================================================================
RCS file: /home/cvs/avalon/logging/logkit/impl/maven.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- maven.xml 4 Feb 2004 20:48:57 -0000 1.1
+++ maven.xml 19 Feb 2004 12:25:28 -0000 1.2
@@ -4,10 +4,27 @@
<attainGoal name="avalon:artifact"/>
</postGoal>
+ <postGoal name="java:compile">
+ <ant:echo file="${maven.build.dir}/classes/avalon.logging.properties">
+#===================================================================#
+# Default logging implementation properties #
+#===================================================================#
+
+#
+# No properties are defined at this time.
+#
+#
+# EOF
+#
+</ant:echo>
+ </postGoal>
+
<postGoal name="jar:install">
<ant:copy verbose="yes"
toDir="${maven.repo.local}/${pom.groupId}/jars"
file="${maven.build.dir}/${pom.artifactId}-${pom.currentVersion}.jar.meta" />
</postGoal>
+
+
</project>
1.4 +48 -38
avalon/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultLoggingCriteria.java
Index: DefaultLoggingCriteria.java
===================================================================
RCS file:
/home/cvs/avalon/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultLoggingCriteria.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefaultLoggingCriteria.java 14 Feb 2004 03:50:12 -0000 1.3
+++ DefaultLoggingCriteria.java 19 Feb 2004 12:25:29 -0000 1.4
@@ -20,6 +20,7 @@
import java.io.File;
import java.net.URL;
import java.io.IOException;
+import java.util.Properties;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
@@ -38,6 +39,8 @@
import org.apache.avalon.util.criteria.CriteriaException;
import org.apache.avalon.util.criteria.Criteria;
import org.apache.avalon.util.criteria.Parameter;
+import org.apache.avalon.util.defaults.Defaults;
+import org.apache.avalon.util.defaults.DefaultsBuilder;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
@@ -59,11 +62,14 @@
// static
//--------------------------------------------------------------
- private static final File BASEDIR = getDefaultBaseDirectory();
+ private static final String[] KEYS =
+ new String[]{
+ LOGGING_CONFIGURATION_KEY,
+ LOGGING_BASEDIR_KEY,
+ LOGGING_DEBUG_KEY,
+ LOGGING_BOOTSTRAP_KEY };
- private static final String IMPLEMENTATION_KEY =
"avalon.logging.implementation";
-
- private static final String LOGGING_PROPERTIES = "avalon.properties";
+ private static final String DEFAULTS = "/avalon.logging.properties";
private static final Resources REZ =
ResourceManager.getPackageResources( DefaultLoggingCriteria.class );
@@ -81,7 +87,7 @@
new Parameter(
LOGGING_BASEDIR_KEY,
File.class,
- BASEDIR ),
+ context.getInitialWorkingDirectory() ),
new Parameter(
LOGGING_DEBUG_KEY,
Boolean.class,
@@ -92,17 +98,6 @@
};
}
- private static File getDefaultBaseDirectory()
- {
- String base = System.getProperty( "basedir" );
- if( null != base )
- {
- return getCanonicalForm( new File( base ) );
- }
- return getCanonicalForm(
- new File( System.getProperty( "user.dir" ) ) );
- }
-
//--------------------------------------------------------------
// immutable state
//--------------------------------------------------------------
@@ -121,6 +116,42 @@
{
super( buildParameters( context ) );
m_context = context;
+
+ try
+ {
+ //
+ // get the properties declared relative to the application
+ //
+
+ final String key = context.getApplicationKey();
+ final File work = context.getInitialWorkingDirectory();
+ DefaultsBuilder builder = new DefaultsBuilder( key, work );
+ Properties bootstrap =
+ Defaults.getStaticProperties(
+ DefaultLoggingCriteria.class, DEFAULTS );
+ Properties properties =
+ builder.getConsolidatedProperties( bootstrap, KEYS );
+
+ //
+ // apply any non-null properties to the criteria
+ //
+
+ for( int i=0; i<KEYS.length; i++ )
+ {
+ final String propertyKey = KEYS[i];
+ final String value = properties.getProperty( propertyKey );
+ if( null != value )
+ {
+ put( propertyKey, value );
+ }
+ }
+ }
+ catch ( IOException e )
+ {
+ throw new LoggingRuntimeException(
+ "Failed to load implementation defaults resource: "
+ + DEFAULTS, e );
+ }
}
//--------------------------------------------------------------
@@ -191,26 +222,6 @@
}
/**
- * Return the artifact reference to the logging implementation factory .
- * @return the logging implementation factory classname
- * @exception IllegalStateException if the url is not an artifact url
- */
- /*
- public Artifact getFactoryArtifact() throws IOException
- {
- String value = (String) get( FACTORY_ARTIFACT_KEY );
- if( null == value )
- {
- return getDefaultImplementationArtifact( m_context );
- }
- else
- {
- return Artifact.createArtifact( value );
- }
- }
- */
-
- /**
* Return debug policy. If TRUE all logging channels will be
* set to debug level.
*
@@ -238,5 +249,4 @@
throw new LoggingRuntimeException( error, e );
}
}
-
}
1.5 +8 -116
avalon/repository/impl/src/java/org/apache/avalon/repository/impl/DefaultRepositoryCriteria.java
Index: DefaultRepositoryCriteria.java
===================================================================
RCS file:
/home/cvs/avalon/repository/impl/src/java/org/apache/avalon/repository/impl/DefaultRepositoryCriteria.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultRepositoryCriteria.java 19 Feb 2004 07:37:46 -0000 1.4
+++ DefaultRepositoryCriteria.java 19 Feb 2004 12:25:29 -0000 1.5
@@ -73,47 +73,6 @@
",",
null );
-
- /**
- * Repository proxy host parameter descriptor.
- */
- //public static final String REPOSITORY_PROXY_HOST =
"avalon.repository.proxy.host";
- //private static final Parameter REPOSITORY_PROXY_HOST_PARAM =
- // new Parameter(
- // REPOSITORY_PROXY_HOST,
- // String.class,
- // null );
-
- /**
- * Repository proxy port parameter descriptor.
- */
- //public static final String REPOSITORY_PROXY_PORT =
"avalon.repository.proxy.port";
- //private static final Parameter REPOSITORY_PROXY_PORT_PARAM =
- // new Parameter(
- // REPOSITORY_PROXY_PORT,
- // Integer.class,
- // null );
-
- /**
- * Repository proxy username parameter descriptor.
- */
- //public static final String REPOSITORY_PROXY_USERNAME =
"avalon.repository.proxy.username";
- //private static final Parameter REPOSITORY_PROXY_USERNAME_PARAM =
- // new Parameter(
- // REPOSITORY_PROXY_USERNAME,
- // String.class,
- // null );
-
- /**
- * Repository proxy password parameter descriptor.
- */
- //public static final String REPOSITORY_PROXY_PASSWORD =
"avalon.repository.proxy.password";
- //private static final Parameter REPOSITORY_PROXY_PASSWORD_PARAM =
- // new Parameter(
- // REPOSITORY_PROXY_PASSWORD,
- // String.class,
- // null );
-
/**
* The factory parameters template.
*/
@@ -164,86 +123,19 @@
builder.getConsolidatedProperties( bootstrap, SINGLE_KEYS );
//
- // override values aquired from the initial context
- //
-
- put(
- REPOSITORY_CACHE_DIR,
- context.getInitialCacheDirectory() );
- put(
- REPOSITORY_REMOTE_HOSTS,
- context.getInitialHosts() );
-
- //
- // Create the finder (discovery policy), construct the defaults, and
- // macro expand the values.
- //
- //
- //final DefaultsFinder[] finders = {
- // new SimpleDefaultsFinder( new Properties[] { bootstrap }, false
),
- // new SystemDefaultsFinder() };
- //
- //Defaults defaults = new Defaults( SINGLE_KEYS, MULTI_VALUE_KEYS,
finders );
- //Defaults.macroExpand( defaults, new Properties[]{
System.getProperties() } );
- //
-
- //
- // Here we start to populate the empty repository criteria using
- // the values from the consilidated defaults
+ // Populate the empty repository criteria using
+ // the values from the consilidated defaults.
//
- String cache =
- properties.getProperty( REPOSITORY_CACHE_DIR );
- if( null != cache )
- {
- put(
- REPOSITORY_CACHE_DIR,
- new File( cache ) );
- }
-
- try
+ for( int i=0; i<SINGLE_KEYS.length; i++ )
{
- String hosts =
- properties.getProperty( REPOSITORY_REMOTE_HOSTS );
- if( null != hosts )
+ final String propertyKey = SINGLE_KEYS[i];
+ final String value = properties.getProperty( propertyKey );
+ if( null != value )
{
- put( REPOSITORY_REMOTE_HOSTS, hosts );
+ put( propertyKey, value );
}
}
- catch ( Throwable e )
- {
- final String error =
- "Failed to set remote repositories.";
- throw new RepositoryException( error, e );
- }
-
- //if( properties.containsKey( REPOSITORY_PROXY_HOST ) )
- //{
- // put(
- // REPOSITORY_PROXY_HOST,
- // new Integer( properties.getProperty( REPOSITORY_PROXY_HOST ) )
);
-
- // if( properties.containsKey( REPOSITORY_PROXY_PORT ) )
- // {
- // put(
- // REPOSITORY_PROXY_PORT,
- // new Integer( properties.getProperty( REPOSITORY_PROXY_PORT
) ) );
- // }
-
- // if( properties.containsKey( REPOSITORY_PROXY_USERNAME ) )
- // {
- // put(
- // REPOSITORY_PROXY_USERNAME,
- // properties.getProperty( REPOSITORY_PROXY_USERNAME ) );
- // }
-
- // if( properties.containsKey( REPOSITORY_PROXY_PASSWORD ) )
- // {
- // put(
- // REPOSITORY_PROXY_PASSWORD,
- // properties.getProperty( REPOSITORY_PROXY_PASSWORD ) );
- // }
- //}
}
catch( IOException ioe )
{
1.5 +35 -3
avalon/repository/main/src/java/org/apache/avalon/repository/main/DefaultInitialContextFactory.java
Index: DefaultInitialContextFactory.java
===================================================================
RCS file:
/home/cvs/avalon/repository/main/src/java/org/apache/avalon/repository/main/DefaultInitialContextFactory.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultInitialContextFactory.java 19 Feb 2004 07:37:46 -0000 1.4
+++ DefaultInitialContextFactory.java 19 Feb 2004 12:25:29 -0000 1.5
@@ -131,6 +131,27 @@
// ------------------------------------------------------------------------
/**
+ * <p>Creates an initial repository context factory relative to
+ * the current working directory. This is equivalent to the following
+ * invocation:</p>
+ * <pre>
+ * final String key = "demo";
+ * final File work = new File( System.getProperty( "user.dir" );
+ * InitialContextFactory factory =
+ * new DefaultInitialContextFactory( key, work );
+ * </pre>
+ *
+ * @param key the application key
+ * @throws IOException if an error occurs during establishment
+ * @exception NullPointerException if tyhe supplied key is null
+ */
+ public DefaultInitialContextFactory( String key )
+ throws IOException
+ {
+ this( key, new File( System.getProperty( "user.dir" ) ) );
+ }
+
+ /**
* <p>Creates an initial repository context factory. The supplied
* key is used to establish the application root directory and
* property files at application, user and working directory
@@ -171,15 +192,26 @@
m_key = key;
m_work = work;
+
m_defaults = new DefaultsBuilder( key, work );
- Properties defaults = getDefaultProperties();
+
+ //
+ // pull in the set of properties we need for the construction of
+ // the initial context
+ //
+
m_properties =
m_defaults.getConsolidatedProperties(
- defaults,
+ getDefaultProperties(),
KEYS );
Defaults.macroExpand(
m_properties,
new Properties[]{ m_properties } );
+
+ //
+ // retrieve the property defining the implementation
+ // artifact for the initial repository
+ //
String spec = m_properties.getProperty(
InitialContext.IMPLEMENTATION_KEY );
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]