| 1974 |
jgill |
1 |
package com.erggroup.mass.ant;
|
|
|
2 |
|
|
|
3 |
import java.io.File;
|
|
|
4 |
import org.apache.tools.ant.*;
|
|
|
5 |
import org.apache.tools.ant.types.*;
|
|
|
6 |
import org.apache.tools.ant.taskdefs.*;
|
|
|
7 |
import java.util.ArrayList;
|
|
|
8 |
import java.util.Iterator;
|
|
|
9 |
|
|
|
10 |
/**
|
|
|
11 |
* Custom ANT task that will take
|
|
|
12 |
* @param dir = as a base directory
|
|
|
13 |
* @param includes = as a fileNamePattern that should be found in the base dir
|
|
|
14 |
* @param webDeploymentName = defined inside <jbossnet> tag
|
|
|
15 |
*
|
|
|
16 |
* This task will search for "@jboss-net.xml-schema" token and replace it with
|
|
|
17 |
* @jboss-net.xml-schema urn="webDeploymentName:ClassName"
|
|
|
18 |
*
|
|
|
19 |
* <wsdetails dir="" webDeploymentName="">
|
|
|
20 |
* <wsinclude name="filePattern" />
|
|
|
21 |
* ....
|
|
|
22 |
* </wsdetails>
|
|
|
23 |
*
|
|
|
24 |
* <wsdetails dir="" includes="pattern1,pattern2" webDeploymentName="" />
|
|
|
25 |
*
|
|
|
26 |
*/
|
|
|
27 |
public class WSReplaceElement extends Task
|
|
|
28 |
{
|
|
|
29 |
private String token = "@jboss-net.xml-schema";
|
|
|
30 |
|
|
|
31 |
private String webDeploymentName;
|
|
|
32 |
private File dir;
|
|
|
33 |
private String includes;
|
|
|
34 |
private ArrayList includeElements = new ArrayList();
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
public void execute()
|
|
|
38 |
{
|
|
|
39 |
|
|
|
40 |
if ( includeElements.size() == 0)
|
|
|
41 |
{
|
|
|
42 |
if ( dir == null || includes == null || webDeploymentName == null)
|
|
|
43 |
{
|
|
|
44 |
throw new BuildException(" \'dir\' and \'includes\' and \'webDeploymentName\' attribute must be provided");
|
|
|
45 |
}
|
|
|
46 |
}
|
|
|
47 |
else if ( includeElements.size() > 0 && dir == null || webDeploymentName == null )
|
|
|
48 |
{
|
|
|
49 |
throw new BuildException(" \'dir\' and \'webDeploymentName\' attribute must be provided and at least one <wsinlcude>");
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
// returns a list of all include file Names
|
|
|
53 |
FileSet fileSet = new FileSet();
|
|
|
54 |
fileSet.setDir(this.dir);
|
|
|
55 |
//if <wsinclude> is used
|
|
|
56 |
if (includeElements.size() > 0)
|
|
|
57 |
{
|
|
|
58 |
this.includes = "";
|
|
|
59 |
Iterator i = includeElements.iterator();
|
|
|
60 |
int index = 0;
|
|
|
61 |
while(i.hasNext())
|
|
|
62 |
{
|
|
|
63 |
this.includes += ((WSInclude)i.next()).getName();
|
|
|
64 |
if (index < includeElements.size()-1 )
|
|
|
65 |
{
|
|
|
66 |
this.includes += ",";
|
|
|
67 |
}
|
|
|
68 |
index ++;
|
|
|
69 |
}
|
|
|
70 |
}
|
|
|
71 |
fileSet.setIncludes(this.includes);
|
|
|
72 |
DirectoryScanner scanner = fileSet.getDirectoryScanner(getProject());
|
|
|
73 |
String[] files = scanner.getIncludedFiles();;
|
|
|
74 |
|
|
|
75 |
// for each file name create replaceValue and replace specified token
|
|
|
76 |
for (int i=0; i<files.length; i++)
|
|
|
77 |
{
|
|
|
78 |
Replace replace = new Replace();
|
|
|
79 |
replace.setProject(getProject());
|
|
|
80 |
replace.setToken(this.token);
|
|
|
81 |
replace.setDir(this.dir);
|
|
|
82 |
|
|
|
83 |
String fileName = files[i];
|
|
|
84 |
replace.setIncludes(files[i]);
|
|
|
85 |
fileName = fileName.substring(fileName.lastIndexOf("\\")+1, fileName.length() );
|
|
|
86 |
fileName = fileName.substring(0, fileName.lastIndexOf(".java") );
|
|
|
87 |
String replaceValue = "@jboss-net.xml-schema urn=\"" + this.webDeploymentName + ":" + fileName + "\"";
|
|
|
88 |
replace.setValue(replaceValue);
|
|
|
89 |
replace.execute();
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
public WSInclude createWsinclude()
|
|
|
94 |
{
|
|
|
95 |
WSInclude element = new WSInclude();
|
|
|
96 |
includeElements.add(element);
|
|
|
97 |
return element;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
public void setWebDeploymentName(String webDeploymentName)
|
|
|
103 |
{
|
|
|
104 |
this.webDeploymentName = webDeploymentName;
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
public void setIncludes(String includes)
|
|
|
108 |
{
|
|
|
109 |
this.includes = includes;
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
public void setDir(File dir)
|
|
|
113 |
{
|
|
|
114 |
this.dir = dir;
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
}
|