mcconnell 2003/12/06 19:17:18
Modified: kernel/cli maven.xml project.properties
kernel/cli/src/java/org/apache/avalon/merlin/cli Main.java
kernel/cli/src/test/org/apache/avalon/merlin/cli/test
MerlinCLITest.java
kernel/impl/src/java/org/apache/avalon/merlin/impl
DefaultFactory.java
kernel/unit/src/java/org/apache/avalon/merlin/unit
AbstractMerlinTestCase.java
Log:
Sync. with repo and improve -info handling.
Revision Changes Path
1.3 +27 -0 avalon-sandbox/kernel/cli/maven.xml
Index: maven.xml
===================================================================
RCS file: /home/cvs/avalon-sandbox/kernel/cli/maven.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- maven.xml 6 Dec 2003 06:37:43 -0000 1.2
+++ maven.xml 7 Dec 2003 03:17:18 -0000 1.3
@@ -17,4 +17,31 @@
</j:forEach>
</preGoal>
+ <!--
+ ###################################################################
+ # Create the merlin.implementation property file. #
+ # This contains the information used to identify the #
+ # the implementation artifact classpath, factory, etc. #
+ ###################################################################
+ -->
+
+ <postGoal name="java:compile">
+ <ant:echo file="${maven.build.dir}/classes/merlin.implementation">
+#===================================================================#
+# Default merlin implementation artifact identifier. #
+#===================================================================#
+
+meta.domain = avalon
+meta.version = 1.0
+avalon.artifact.group = ${merlin.implementation.group}
+avalon.artifact.name = ${merlin.implementation.name}
+avalon.artifact.version = ${merlin.implementation.version}
+
+#
+# EOF
+#
+</ant:echo>
+ </postGoal>
+
+
</project>
1.3 +4 -2 avalon-sandbox/kernel/cli/project.properties
Index: project.properties
===================================================================
RCS file: /home/cvs/avalon-sandbox/kernel/cli/project.properties,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- project.properties 6 Dec 2003 06:37:43 -0000 1.2
+++ project.properties 7 Dec 2003 03:17:18 -0000 1.3
@@ -1,7 +1,9 @@
#
-# factory class
+# default implementation
#
-avalon.artifact.factory = org.apache.avalon.merlin.cli.DefaultFactory
+merlin.implementation.group = merlin
+merlin.implementation.name = merlin-impl
+merlin.implementation.version = 3.2-dev
#
# main class
1.4 +103 -94
avalon-sandbox/kernel/cli/src/java/org/apache/avalon/merlin/cli/Main.java
Index: Main.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/kernel/cli/src/java/org/apache/avalon/merlin/cli/Main.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Main.java 6 Dec 2003 23:58:59 -0000 1.3
+++ Main.java 7 Dec 2003 03:17:18 -0000 1.4
@@ -53,6 +53,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.Map;
import java.util.Hashtable;
import java.util.Properties;
@@ -193,7 +194,6 @@
//----------------------------------------------------------
private final InitialContext m_context;
- private final String[] m_args;
//----------------------------------------------------------
// constructor
@@ -203,85 +203,26 @@
* Creation of a new kernel cli factory.
* @param factory the repository inital factory
*/
- public Main( InitialContext context, String[] args )
+ public Main( InitialContext context, Artifact artifact, CommandLine line )
throws Exception
{
m_context = context;
- m_args = args;
- Artifact artifact =
- Artifact.createArtifact(
- "merlin", "merlin-impl", "3.2-dev" );
+ Builder builder = new DefaultBuilder( m_context, artifact );
+ ClassLoader classloader = builder.getClassLoader();
+ Factory factory = builder.getFactory();
+ Map criteria = factory.createDefaultCriteria();
+
+ //
+ // update the criteria using the command line information
+ //
+
+ handleCommandLine( criteria, line );
+
+ //
+ // instantiate the kernel
+ //
- try
- {
- Builder builder = new DefaultBuilder( m_context, artifact );
- ClassLoader classloader = builder.getClassLoader();
- Factory factory = builder.getFactory();
- Map criteria = factory.createDefaultCriteria();
-
- //
- // parse the commandline
- //
-
- CommandLineParser parser = new BasicParser();
- CommandLine line = parser.parse( CL_OPTIONS, args );
-
- if( line.hasOption( "version" ) )
- {
- printVersionInfo( artifact );
- return;
- }
-
- if( line.hasOption( "help" ) )
- {
- if( line.hasOption( "lang" ) )
- {
- ResourceManager.clearResourceCache();
- String language = line.getOptionValue( "lang" );
- Locale locale = new Locale( language, "" );
- Locale.setDefault( locale );
- REZ = ResourceManager.getPackageResources( Main.class );
- }
- printHelpInfo();
- return;
- }
-
- //
- // otherwise we are into an install or deployment scenario
- //
-
- handleCommandLine( criteria, line );
-
- //
- // read in any properties declared under the path
- // ${basedir}/merlin.properties
- //
-
- Object kernel = factory.create( criteria );
-
- }
- catch( Throwable e )
- {
- final String error =
- "Internal error while attempting to create the intitial context.";
- String msg =
- ExceptionHelper.packException( error, e, true );
- System.err.println( msg );
- System.exit( -1 );
- }
- }
-
- private void printVersionInfo( Artifact artifact )
- {
- System.out.println( "Group: " + artifact.getGroup() );
- System.out.println( "Product: " + artifact.getName() );
- System.out.println( "Version: " + artifact.getVersion() );
- }
-
- private void printHelpInfo()
- {
- HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp( "merlin [block]", " ", CL_OPTIONS, "", true );
+ Object kernel = factory.create( criteria );
}
private void handleCommandLine( Map criteria, CommandLine line )
@@ -380,34 +321,109 @@
{
try
{
-
+ Artifact artifact = getDefaultImplementation();
+
//
// parse the commandline
//
CommandLineParser parser = new BasicParser();
CommandLine line = parser.parse( CL_OPTIONS, args );
- File system = getMerlinSystemRepository( line );
- InitialContext context =
- new DefaultInitialContext(
- system,
- getDefaultHosts() );
+ if( line.hasOption( "version" ) )
+ {
+ Main.printVersionInfo( artifact );
+ return;
+ }
+
+ if( line.hasOption( "help" ) )
+ {
+ if( line.hasOption( "lang" ) )
+ {
+ ResourceManager.clearResourceCache();
+ String language = line.getOptionValue( "lang" );
+ Locale locale = new Locale( language, "" );
+ Locale.setDefault( locale );
+ REZ = ResourceManager.getPackageResources( Main.class );
+ }
+ Main.printHelpInfo();
+ return;
+ }
+
+ //
+ // the real stuff
+ //
- Main main = new Main( context, args );
+ File system = getMerlinSystemRepository( line );
+ InitialContext context =
+ new DefaultInitialContext( system );
+ Main main = new Main( context, artifact, line );
}
catch( Throwable e )
{
- final String error =
- "Internal error while attempting to create the intitial context.";
String msg =
- ExceptionHelper.packException( error, e, true );
+ ExceptionHelper.packException( e, true );
System.err.println( msg );
System.exit( -1 );
}
}
+ private static Artifact getDefaultImplementation() throws Exception
+ {
+ Properties properties = createDefaultProperties();
+
+ final String group =
+ properties.getProperty( Artifact.GROUP_KEY );
+ final String name =
+ properties.getProperty( Artifact.NAME_KEY );
+ final String version =
+ properties.getProperty( Artifact.VERSION_KEY );
+
+ return Artifact.createArtifact( group, name, version );
+ }
+
+ private static Properties createDefaultProperties()
+ {
+ final String path = "merlin.implementation";
+
+ try
+ {
+ Properties properties = new Properties();
+ ClassLoader classloader = Main.class.getClassLoader();
+ InputStream input = classloader.getResourceAsStream( path );
+ if( input == null )
+ {
+ final String error =
+ "Missing resource: [" + path + "]";
+ throw new Error( error );
+ }
+ properties.load( input );
+ return properties;
+ }
+ catch ( Throwable e )
+ {
+ final String error =
+ "Internal error. "
+ + "Unable to locate the resource: merlin.implementation.";
+ throw new IllegalStateException( error );
+ }
+ }
+
+
+ private static void printVersionInfo( Artifact artifact )
+ {
+ System.out.println( "Group: " + artifact.getGroup() );
+ System.out.println( "Product: " + artifact.getName() );
+ System.out.println( "Version: " + artifact.getVersion() );
+ }
+
+ private static void printHelpInfo()
+ {
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp( "merlin [block]", " ", CL_OPTIONS, "", true );
+ }
+
private static File getMerlinSystemRepository( CommandLine line )
{
if( line.hasOption( "system" ) )
@@ -494,13 +510,6 @@
return new File( base );
}
return new File( System.getProperty( "user.dir" ) );
- }
-
- private static String[] getDefaultHosts()
- {
- return new String[]{
- "http://dpml.net/"
- };
}
private static String getArgument( String key, String[] args )
1.3 +8 -36
avalon-sandbox/kernel/cli/src/test/org/apache/avalon/merlin/cli/test/MerlinCLITest.java
Index: MerlinCLITest.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/kernel/cli/src/test/org/apache/avalon/merlin/cli/test/MerlinCLITest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MerlinCLITest.java 6 Dec 2003 23:58:59 -0000 1.2
+++ MerlinCLITest.java 7 Dec 2003 03:17:18 -0000 1.3
@@ -61,13 +61,6 @@
import junit.framework.TestCase;
-import org.apache.avalon.repository.Artifact;
-import org.apache.avalon.repository.provider.Builder;
-import org.apache.avalon.repository.provider.InitialContext;
-import org.apache.avalon.repository.provider.Factory;
-import org.apache.avalon.repository.RepositoryException;
-import org.apache.avalon.repository.main.DefaultInitialContext;
-import org.apache.avalon.repository.main.DefaultBuilder;
import org.apache.avalon.util.env.Env;
import org.apache.avalon.util.exception.ExceptionHelper;
@@ -100,24 +93,21 @@
public void testMain() throws Exception
{
+ String system =
+ getMavenRepositoryDirectory().toString();
+
try
{
- InitialContext context =
- new DefaultInitialContext(
- getMavenRepositoryDirectory(),
- getDefaultHosts() );
-
String[] args =
new String[]
{
"-info",
"-execute",
- "conf/hello.block"
+ "conf/hello.block",
+ "-system",
+ system
};
-
- Main main = new Main( context, args );
-
- assertNotNull( main );
+ Main.main( args );
}
catch( Throwable e )
{
@@ -164,23 +154,5 @@
ExceptionHelper.packException( error, e, true );
throw new RuntimeException( message );
}
- }
-
- private File getBaseDirectory()
- {
- final String base = System.getProperty( "basedir" );
- if( null != base )
- {
- return new File( base );
- }
- return new File( System.getProperty( "user.dir" ) );
- }
-
- private static String[] getDefaultHosts()
- {
- return new String[]{
- "http://dpml.net/",
- "http://www.ibiblio.org/maven/"
- };
}
}
1.11 +24 -7
avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultFactory.java
Index: DefaultFactory.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultFactory.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- DefaultFactory.java 6 Dec 2003 23:58:59 -0000 1.10
+++ DefaultFactory.java 7 Dec 2003 03:17:18 -0000 1.11
@@ -58,6 +58,7 @@
import org.apache.avalon.merlin.KernelCriteria;
import org.apache.avalon.repository.Repository;
+import org.apache.avalon.repository.provider.CacheManager;
import org.apache.avalon.repository.provider.InitialContext;
import org.apache.avalon.repository.provider.Factory;
@@ -216,9 +217,24 @@
new StringBuffer( REZ.getString( "info.listing" ) );
buffer.append( "\n" );
- buffer.append( "\n ${user.dir} == " + System.getProperty( "user.dir" )
);
- buffer.append( "\n ${user.home} == " + System.getProperty( "user.home"
) );
-
+ buffer.append(
+ "\n ${user.dir} == "
+ + System.getProperty( "user.dir" ) );
+ buffer.append(
+ "\n ${user.home} == "
+ + System.getProperty( "user.home" ) );
+
+ buffer.append( "\n" );
+ buffer.append( "\n ${avalon.repository.cache} == "
+ + m_context.getInitialCacheDirectory() );
+ buffer.append( "\n ${avalon.repository.hosts} == " );
+ String[] hosts = m_context.getInitialHosts();
+ for( int i=0; i<hosts.length; i++ )
+ {
+ if( i>0 ) buffer.append( "," );
+ buffer.append( hosts[i] );
+ }
+
buffer.append( "\n" );
Iterator keys = criteria.keySet().iterator();
while( keys.hasNext() )
@@ -248,8 +264,9 @@
Configuration repositoryConfig =
kernelConfig.getChild( "repository" );
File cache = criteria.getRepositoryDirectory();
- Repository repository =
- createRepository( m_context, cache, repositoryConfig );
+ CacheManager manager =
+ createCacheManager( m_context, cache, repositoryConfig );
+ Repository repository = manager.createRepository();
getLogger().debug(
"repository established: " + repository );
@@ -525,7 +542,7 @@
}
}
- private Repository createRepository(
+ private CacheManager createCacheManager(
InitialContext context, File root, Configuration config )
throws KernelException
{
@@ -592,7 +609,7 @@
}
}
- return (Repository) factory.create( criteria );
+ return (CacheManager) factory.create( criteria );
}
catch ( Throwable e )
{
1.6 +2 -11
avalon-sandbox/kernel/unit/src/java/org/apache/avalon/merlin/unit/AbstractMerlinTestCase.java
Index: AbstractMerlinTestCase.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/kernel/unit/src/java/org/apache/avalon/merlin/unit/AbstractMerlinTestCase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractMerlinTestCase.java 6 Dec 2003 23:58:59 -0000 1.5
+++ AbstractMerlinTestCase.java 7 Dec 2003 03:17:18 -0000 1.6
@@ -126,8 +126,7 @@
InitialContext context =
new DefaultInitialContext(
- getMavenRepositoryDirectory(),
- getDefaultHosts() );
+ getMavenRepositoryDirectory() );
Builder builder = new DefaultBuilder( context, artifact );
m_classloader = builder.getClassLoader();
@@ -293,13 +292,5 @@
return new File( base );
}
return new File( System.getProperty( "user.dir" ) );
- }
-
- private static String[] getDefaultHosts()
- {
- return new String[]{
- "http://dpml.net/",
- "http://www.ibiblio.org/maven/"
- };
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]