git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270238 13f79535-47bb-0310-9956-ffa450edef68master
@@ -1,138 +0,0 @@ | |||||
/* | |||||
* Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
* | |||||
* This software is published under the terms of the Apache Software License | |||||
* version 1.1, a copy of which has been included with this distribution in | |||||
* the LICENSE file. | |||||
*/ | |||||
package org.apache.myrmidon.libs.ant1; | |||||
import java.io.File; | |||||
import org.apache.avalon.framework.context.Context; | |||||
import org.apache.avalon.framework.context.Contextualizable; | |||||
import org.apache.avalon.framework.logger.LogEnabled; | |||||
import org.apache.avalon.framework.logger.Logger; | |||||
import org.apache.myrmidon.api.TaskContext; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.tools.ant.Project; | |||||
import org.apache.tools.ant.Task; | |||||
public class Ant1Project | |||||
extends Project | |||||
implements LogEnabled, Contextualizable | |||||
{ | |||||
private Logger m_logger; | |||||
///Variable to hold context for use by sub-classes | |||||
private TaskContext m_context; | |||||
public void enableLogging( final Logger logger ) | |||||
{ | |||||
m_logger = logger; | |||||
} | |||||
protected final Logger getLogger() | |||||
{ | |||||
return m_logger; | |||||
} | |||||
/** | |||||
* Retrieve context from container. | |||||
* | |||||
* @param context the context | |||||
*/ | |||||
public void contextualize( final Context context ) | |||||
{ | |||||
m_context = (TaskContext)context; | |||||
} | |||||
protected final TaskContext getContext() | |||||
{ | |||||
return m_context; | |||||
} | |||||
/** | |||||
* Initialise the project. | |||||
*/ | |||||
public void init() | |||||
throws TaskException | |||||
{ | |||||
setJavaVersionProperty(); | |||||
} | |||||
public void setProperty( final String name, final String value ) | |||||
{ | |||||
try | |||||
{ | |||||
getContext().setProperty( name, value ); | |||||
} | |||||
catch( final Exception e ) | |||||
{ | |||||
getLogger().warn( "Failed to set property " + name + " to " + value, e ); | |||||
} | |||||
} | |||||
public String getProperty( final String name ) | |||||
{ | |||||
return "" + getContext().getProperty( name ); | |||||
} | |||||
public String getUserProperty( final String name ) | |||||
{ | |||||
return getProperty( name ); | |||||
} | |||||
public String getName() | |||||
{ | |||||
return "Ant1 Project"; | |||||
} | |||||
public Task createTask( final String taskType ) | |||||
throws TaskException | |||||
{ | |||||
throw new UnsupportedOperationException(); | |||||
} | |||||
public Object createDataType( final String typeName ) | |||||
throws TaskException | |||||
{ | |||||
throw new UnsupportedOperationException(); | |||||
} | |||||
public File resolveFile( final String fileName ) | |||||
{ | |||||
try | |||||
{ | |||||
return getContext().resolveFile( fileName ); | |||||
} | |||||
catch( final Exception e ) | |||||
{ | |||||
return null; | |||||
} | |||||
} | |||||
private void messageLogged( String message, int priority ) | |||||
{ | |||||
switch( priority ) | |||||
{ | |||||
case MSG_ERR: | |||||
getLogger().error( message ); | |||||
break; | |||||
case MSG_WARN: | |||||
getLogger().warn( message ); | |||||
break; | |||||
case MSG_INFO: | |||||
getLogger().info( message ); | |||||
break; | |||||
case MSG_VERBOSE: | |||||
getLogger().debug( message ); | |||||
break; | |||||
case MSG_DEBUG: | |||||
getLogger().debug( message ); | |||||
break; | |||||
default: | |||||
getLogger().debug( message ); | |||||
} | |||||
} | |||||
} |
@@ -1,92 +0,0 @@ | |||||
/* | |||||
* Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
* | |||||
* This software is published under the terms of the Apache Software License | |||||
* version 1.1, a copy of which has been included with this distribution in | |||||
* the LICENSE file. | |||||
*/ | |||||
package org.apache.myrmidon.libs.ant1; | |||||
import java.io.File; | |||||
import java.io.InputStream; | |||||
import java.io.IOException; | |||||
import java.net.URL; | |||||
import java.util.Enumeration; | |||||
import java.util.Properties; | |||||
import org.apache.myrmidon.api.AbstractTask; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.api.Task; | |||||
import org.apache.avalon.framework.component.ComponentException; | |||||
import org.apache.avalon.framework.component.ComponentManager; | |||||
import org.apache.avalon.framework.component.Composable; | |||||
import org.apache.myrmidon.interfaces.type.TypeManager; | |||||
/** | |||||
* Method to register a tasklib. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
*/ | |||||
public class Ant1Tasklib | |||||
extends AbstractTask | |||||
implements Composable | |||||
{ | |||||
private String m_prefix = ""; | |||||
private File m_lib; | |||||
private TypeManager m_typeManager; | |||||
public void compose( final ComponentManager componentManager ) | |||||
throws ComponentException | |||||
{ | |||||
m_typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE ); | |||||
} | |||||
public void setLib( final File lib ) | |||||
{ | |||||
m_lib = lib; | |||||
} | |||||
public void setPrefix( final String prefix ) | |||||
{ | |||||
m_prefix = prefix; | |||||
} | |||||
public void execute() | |||||
throws TaskException | |||||
{ | |||||
if( null == m_lib ) | |||||
{ | |||||
throw new TaskException( "Must specify lib parameter" ); | |||||
} | |||||
try | |||||
{ | |||||
final String location = "jar:" + m_lib.toURL() + | |||||
"!/org/apache/tools/ant/taskdefs/defaults.properties"; | |||||
final URL url = new URL( location ); | |||||
final InputStream input = url.openStream(); | |||||
final Properties tasks = new Properties(); | |||||
tasks.load( input ); | |||||
input.close(); | |||||
final Ant1TypeFactory factory = new Ant1TypeFactory( m_lib.toURL() ); | |||||
final Enumeration enum = tasks.propertyNames(); | |||||
while( enum.hasMoreElements() ) | |||||
{ | |||||
final String rawName = (String)enum.nextElement(); | |||||
final String className = tasks.getProperty( rawName ); | |||||
final String name = m_prefix + rawName; | |||||
factory.addNameClassMapping( name, className ); | |||||
m_typeManager.registerType( Task.ROLE, name, factory ); | |||||
} | |||||
} | |||||
catch( final Exception e ) | |||||
{ | |||||
throw new TaskException( "Failed to load task definitions", e ); | |||||
} | |||||
} | |||||
} |
@@ -1,57 +0,0 @@ | |||||
/* | |||||
* Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
* | |||||
* This software is published under the terms of the Apache Software License | |||||
* version 1.1, a copy of which has been included with this distribution in | |||||
* the LICENSE file. | |||||
*/ | |||||
package org.apache.myrmidon.libs.ant1; | |||||
import java.net.URL; | |||||
import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | |||||
import org.apache.myrmidon.interfaces.type.TypeException; | |||||
import org.apache.tools.ant.Task; | |||||
/** | |||||
* Factory used to create adaptors for Ant1 tasks. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
*/ | |||||
public class Ant1TypeFactory | |||||
extends DefaultTypeFactory | |||||
{ | |||||
public Ant1TypeFactory( final URL url ) | |||||
{ | |||||
super( url ); | |||||
} | |||||
public Ant1TypeFactory( final URL[] urls ) | |||||
{ | |||||
super( urls ); | |||||
} | |||||
public Ant1TypeFactory( final URL[] urls, final ClassLoader parent ) | |||||
{ | |||||
super( urls, parent ); | |||||
} | |||||
public Ant1TypeFactory( final ClassLoader classLoader ) | |||||
{ | |||||
super( classLoader ); | |||||
} | |||||
public Object create( final String name ) | |||||
throws TypeException | |||||
{ | |||||
final Object object = super.create( name ); | |||||
if( !(object instanceof Task) ) | |||||
{ | |||||
throw new TypeException( "Expected an Ant1 task but received an " + | |||||
"object of type : " + object.getClass().getName() ); | |||||
} | |||||
return new TaskAdapter( (Task)object ); | |||||
} | |||||
} | |||||
@@ -1,74 +0,0 @@ | |||||
/* | |||||
* Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
* | |||||
* This software is published under the terms of the Apache Software License | |||||
* version 1.1, a copy of which has been included with this distribution in | |||||
* the LICENSE file. | |||||
*/ | |||||
package org.apache.myrmidon.libs.ant1; | |||||
import org.apache.avalon.framework.configuration.Configurable; | |||||
import org.apache.avalon.framework.configuration.Configuration; | |||||
import org.apache.avalon.framework.configuration.ConfigurationException; | |||||
import org.apache.myrmidon.api.TaskContext; | |||||
import org.apache.myrmidon.api.TaskException; | |||||
import org.apache.myrmidon.interfaces.type.TypeException; | |||||
import org.apache.myrmidon.interfaces.type.TypeFactory; | |||||
import org.apache.myrmidon.interfaces.type.TypeManager; | |||||
import org.apache.myrmidon.framework.AbstractContainerTask; | |||||
import org.apache.tools.ant.Task; | |||||
/** | |||||
* Adapter of Ant1 tasks to myrmidon. | |||||
* | |||||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||||
*/ | |||||
public class TaskAdapter | |||||
extends AbstractContainerTask | |||||
implements Configurable | |||||
{ | |||||
private Task m_task; | |||||
private Ant1Project m_project = new Ant1Project(); | |||||
public TaskAdapter( final Task task ) | |||||
{ | |||||
m_task = task; | |||||
} | |||||
protected final Task getTask() | |||||
{ | |||||
return m_task; | |||||
} | |||||
protected final Ant1Project getProject() | |||||
{ | |||||
return m_project; | |||||
} | |||||
public void configure( final Configuration configuration ) | |||||
throws ConfigurationException | |||||
{ | |||||
//getTask().setTaskName( configuration.getName() ); | |||||
//do configuration | |||||
configure( getTask(), configuration ); | |||||
} | |||||
public void execute() | |||||
throws TaskException | |||||
{ | |||||
try | |||||
{ | |||||
getProject().enableLogging( getLogger() ); | |||||
getProject().contextualize( getContext() ); | |||||
getProject().init(); | |||||
getTask().setProject( getProject() ); | |||||
getTask().execute(); | |||||
} | |||||
catch( final Exception e ) | |||||
{ | |||||
throw new TaskException( e.getMessage(), e ); | |||||
} | |||||
} | |||||
} |