package com.erggroup.mass.ant; import java.io.File; import org.apache.tools.ant.*; import org.apache.tools.ant.types.*; import org.apache.tools.ant.taskdefs.*; import java.util.ArrayList; import java.util.Iterator; /** * Custom ANT task that will take * @param dir = as a base directory * @param includes = as a fileNamePattern that should be found in the base dir * @param webDeploymentName = defined inside tag * * This task will search for "@jboss-net.xml-schema" token and replace it with * @jboss-net.xml-schema urn="webDeploymentName:ClassName" * * * * .... * * * * */ public class WSReplaceElement extends Task { private String token = "@jboss-net.xml-schema"; private String webDeploymentName; private File dir; private String includes; private ArrayList includeElements = new ArrayList(); public void execute() { if ( includeElements.size() == 0) { if ( dir == null || includes == null || webDeploymentName == null) { throw new BuildException(" \'dir\' and \'includes\' and \'webDeploymentName\' attribute must be provided"); } } else if ( includeElements.size() > 0 && dir == null || webDeploymentName == null ) { throw new BuildException(" \'dir\' and \'webDeploymentName\' attribute must be provided and at least one "); } // returns a list of all include file Names FileSet fileSet = new FileSet(); fileSet.setDir(this.dir); //if is used if (includeElements.size() > 0) { this.includes = ""; Iterator i = includeElements.iterator(); int index = 0; while(i.hasNext()) { this.includes += ((WSInclude)i.next()).getName(); if (index < includeElements.size()-1 ) { this.includes += ","; } index ++; } } fileSet.setIncludes(this.includes); DirectoryScanner scanner = fileSet.getDirectoryScanner(getProject()); String[] files = scanner.getIncludedFiles();; // for each file name create replaceValue and replace specified token for (int i=0; i