Blame | Last modification | View Log | RSS feed
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 <jbossnet> tag** This task will search for "@jboss-net.xml-schema" token and replace it with* @jboss-net.xml-schema urn="webDeploymentName:ClassName"** <wsdetails dir="" webDeploymentName="">* <wsinclude name="filePattern" />* ....* </wsdetails>** <wsdetails dir="" includes="pattern1,pattern2" webDeploymentName="" />**/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 <wsinlcude>");}// returns a list of all include file NamesFileSet fileSet = new FileSet();fileSet.setDir(this.dir);//if <wsinclude> is usedif (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 tokenfor (int i=0; i<files.length; i++){Replace replace = new Replace();replace.setProject(getProject());replace.setToken(this.token);replace.setDir(this.dir);String fileName = files[i];replace.setIncludes(files[i]);fileName = fileName.substring(fileName.lastIndexOf("\\")+1, fileName.length() );fileName = fileName.substring(0, fileName.lastIndexOf(".java") );String replaceValue = "@jboss-net.xml-schema urn=\"" + this.webDeploymentName + ":" + fileName + "\"";replace.setValue(replaceValue);replace.execute();}}public WSInclude createWsinclude(){WSInclude element = new WSInclude();includeElements.add(element);return element;}public void setWebDeploymentName(String webDeploymentName){this.webDeploymentName = webDeploymentName;}public void setIncludes(String includes){this.includes = includes;}public void setDir(File dir){this.dir = dir;}}