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 2002/05/03 05:51:07 UTC
cvs commit: jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/service/ant Load.java
mcconnell 02/05/02 20:51:07
Added: all/src/scratchpad/org/apache/avalon/excalibur/service/ant
Load.java
Log:
ant load task
Revision Changes Path
1.1 jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/service/ant/Load.java
Index: Load.java
===================================================================
/*
* File: Load.java
* License: etc/LICENSE.TXT
* Copyright: Copyright (C) The Apache Software Foundation. All rights reserved.
* Copyright: OSM SARL 2002, All Rights Reserved.
*/
package org.apache.avalon.excalibur.service.ant;
import java.io.*;
import java.io.File;
import java.util.*;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.MalformedURLException;
import java.util.jar.JarFile;
import java.util.jar.Attributes;
import java.util.jar.Attributes.Name;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.Exec;
import org.apache.tools.ant.taskdefs.Execute;
import org.apache.tools.ant.taskdefs.PumpStreamHandler;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.CommandlineJava;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Environment;
import org.apache.log.Hierarchy;
import org.apache.log.Priority;
import org.apache.log.output.io.StreamTarget;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.CascadingRuntimeException;
import org.apache.avalon.framework.CascadingException;
import org.apache.avalon.framework.logger.LogKitLogger;
import org.apache.avalon.framework.logger.AvalonFormatter;
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.DefaultComponentManager;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.activity.Startable;
import org.apache.avalon.framework.activity.Disposable;
/**
* A service loader task. Loads a series a blocks as supporting services,
* supporting libraries, and runs a target component.</p>
*/
public class Load extends Task
{
private String[] m_args;
private Vector m_filesets = new Vector();
private Vector m_sys_properties = new Vector();
private String m_target;
private String m_priority;
private String m_policy = "true";
private String m_verbose = "false";
private String m_config;
private Commandline m_cmd = new Commandline();
private Execute m_exe = new Execute(new PumpStreamHandler(System.out, System.err));
private Path m_classpath;
/**
* Adds a set of files (nested fileset attribute).
*/
public void addFileset(FileSet set)
{
m_filesets.addElement(set);
}
/**
* Creates a nested arg element.
*/
public Commandline.Argument createArg() {
return m_cmd.createArgument();
}
public void setClasspath(Path path)
{
if (m_classpath == null)
{
m_classpath = path;
}
else
{
m_classpath.append(path);
}
}
public Path createClasspath()
{
if (m_classpath == null) m_classpath = new Path(project);
return m_classpath.createPath();
}
/**
* Sets the target class.
*/
public void setTarget( String target )
{
m_target = target;
}
/**
* Set the log priority.
*/
public void setPriority( String level )
{
m_priority = level;
}
/**
* Set the disposal policy.
* @param String boolean equivalent
*/
public void setDisposal( String policy )
{
m_policy = policy;
}
/**
* Set the disposal policy.
* @param String boolean equivalent
*/
public void setVerbose( String value )
{
m_verbose = value;
}
/**
* Set the configuration file.
* @param String boolean equivalent
*/
public void setConfiguration( String value )
{
m_config = value;
}
/**
* Performs execution as an Ant target.
*/
public void execute() throws BuildException
{
//
// add the classpath
//
if (m_classpath == null)
{
m_classpath = Path.systemClasspath;
}
else
{
m_classpath = m_classpath.concatSystemClasspath("ignore");
}
m_cmd.createArgument().setValue("-classpath");
m_cmd.createArgument().setPath(m_classpath);
Commandline toExecute = (Commandline)m_cmd.clone();
toExecute.setExecutable("java");
//
// declare the service loader class
//
toExecute.createArgument().setValue("org.apache.avalon.excalibur.service.ServiceLoader");
//
// preprocess the fileset into a vector of file arguments
//
for (int i=0; i<m_filesets.size(); i++)
{
final FileSet fs = (FileSet) m_filesets.elementAt(i);
final File base = fs.getDir( project );
final DirectoryScanner ds = fs.getDirectoryScanner(project);
final String[] files = ds.getIncludedFiles();
for( int j=0; j<files.length; j++ )
{
File target = new File( base, files[j] );
toExecute.createArgument().setValue( target.toString() );
}
}
// add the target parameter
toExecute.createArgument().setValue( "-target" );
toExecute.createArgument().setValue( m_target );
// add the priority parameter
toExecute.createArgument().setValue( "-priority");
toExecute.createArgument().setValue( m_priority );
// add the policy parameter
toExecute.createArgument().setValue( "-disposal");
toExecute.createArgument().setValue( m_policy );
// add the verbose parameter
toExecute.createArgument().setValue( "-verbose");
toExecute.createArgument().setValue( m_verbose );
// add the config parameter
if( m_config != null )
{
toExecute.createArgument().setValue( "-configuration");
toExecute.createArgument().setValue( m_config );
}
try
{
m_exe.setAntRun(project);
m_exe.setWorkingDirectory( new File(System.getProperty("user.dir")));
m_exe.setCommandline(toExecute.getCommandline());
int ret = m_exe.execute();
}
catch( Throwable e )
{
e.printStackTrace();
throw new BuildException( e.getMessage() );
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>