Browse Source

Removed ServiceDiscoveryTask ( for now ).

Added an experimental TaskDiscovery that will use commons-discovery
to find tasks using the ProjectComponentFactory hook.
This is just to play with different antlib mechanisms.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273439 13f79535-47bb-0310-9956-ffa450edef68
master
Costin Manolache 22 years ago
parent
commit
51f00807c2
1 changed files with 54 additions and 26 deletions
  1. +54
    -26
      proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional/TaskDiscovery.java

proposal/embed/src/java/org/apache/tools/ant/taskdefs/ServiceDiscoveryTask.java → proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional/TaskDiscovery.java View File

@@ -55,9 +55,10 @@
*
*/

package org.apache.tools.ant.taskdefs;
package org.apache.tools.ant.taskdefs.optional;
import org.apache.tools.ant.*;

import java.util.Vector;
import java.util.*;

import org.apache.commons.discovery.ResourceName;
import org.apache.commons.discovery.ResourceNameIterator;
@@ -66,51 +67,78 @@ import org.apache.commons.discovery.resource.DiscoverResources;


/**
* Small ant task that will use discovery to locate a particular impl.
* and display all values.
* Default implementation for discovery and (lazy) creation of tasks.
*
* You can execute this and save it with an id, then other classes can use it.
* Several mechanisms will be used:
* - properties files found in the classpath ( META-INF/ant.tasks ).
* - resources named after the task name: META-INF/ant/[TASK_NAME].task
*
* @author Costin Manolache
*/
public class ServiceDiscoveryTask
public class TaskDiscovery extends Task implements ProjectComponentFactory
{
String name;
int debug=0;
ResourceName[] drivers = null;
public void setServiceName(String name ) {
this.name=name;
}
String RESOURCE_NAME="META-INF/ant.tasks";

// Also discovery the 'legacy' names - in ant1.6 the initial preloaded tasks
// should be deprecated.
ResourceName[] discoveredTasks = null;

public void setDebug(int i) {
this.debug=debug;
Hashtable taskDefs=new Hashtable();

public Object createProjectComponent( Project project,
String ns,
String taskName )
throws BuildException
{
// System.out.println("Try create " + taskName);
//
return null;
}

public ResourceName[] getServiceInfo() {
return drivers;
public String toString() {
StringBuffer sb=new StringBuffer();
sb.append( "DiscoveredTasks[" );
if( discoveredTasks != null ) {
for( int i=0; i<discoveredTasks.length; i++ ) {
if( i>0) sb.append( ", ");
sb.append( discoveredTasks[i] );
}
sb.append( "]");
}
return sb.toString();
}

public void execute() throws Exception {
System.out.println("XXX ");

Properties taskClassNames=new Properties();

/** @TODO: Register itself as ProjectComponentHelper.
*/
public void execute() throws BuildException
{
ProjectComponentHelper pcHelper=ProjectComponentHelper.getProjectComponentHelper();
pcHelper.addComponentFactory( this );
// We'll read all 'ant.tasks' at startup, and every time an unknown task
// is found ( the classloader may be different from last time ). Not the best
// solution, just a start.
DiscoverResources disc = new DiscoverResources();
disc.addClassLoader( JDKHooks.getJDKHooks().getThreadContextClassLoader() );
disc.addClassLoader( this.getClass().getClassLoader() );
ResourceNameIterator enum = disc.findResources(name);

ResourceNameIterator enum = disc.findResources(RESOURCE_NAME);
Vector vector = new Vector();
while (enum.hasNext()) {
ResourceName resourceInfo = enum.nextResourceName();
vector.add(resourceInfo);
if( debug > 0 ) {
System.out.println("Found " + resourceInfo);
}
System.out.println("Found " + resourceInfo);
}
drivers = new ResourceName[vector.size()];
vector.copyInto(drivers);
discoveredTasks = new ResourceName[vector.size()];
vector.copyInto(discoveredTasks);
}
}

Loading…
Cancel
Save