1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
package net.sf.infrared.tools.ant; |
23 |
|
|
24 |
|
import java.io.File; |
25 |
|
import java.util.ArrayList; |
26 |
|
import java.util.HashSet; |
27 |
|
import java.util.Iterator; |
28 |
|
import java.util.List; |
29 |
|
import java.util.Set; |
30 |
|
|
31 |
|
import org.apache.commons.io.FileUtils; |
32 |
|
import org.apache.tools.ant.BuildException; |
33 |
|
import org.apache.tools.ant.Project; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
public class EarType extends ApplicationType { |
40 |
0 |
public static String APP_INF_CLASSES = "APP-INF" + File.separator + "classes"; |
41 |
|
|
42 |
0 |
public static String APP_INF_LIB = "APP-INF" + File.separator + "lib"; |
43 |
|
|
44 |
0 |
private Set modules = new HashSet(); |
45 |
|
|
46 |
0 |
private List jarsToInstrument = new ArrayList(); |
47 |
|
|
48 |
0 |
private List classesToInstrument = new ArrayList(); |
49 |
|
|
50 |
0 |
private List packagesToInstrument = new ArrayList(); |
51 |
|
|
52 |
|
public EarType(Project project) { |
53 |
0 |
super(project); |
54 |
0 |
} |
55 |
|
|
56 |
|
public void addConfiguredModule(ModuleType module) { |
57 |
0 |
modules.add(module); |
58 |
0 |
} |
59 |
|
|
60 |
|
public File[] getJarsToInstrument() { |
61 |
0 |
return (File[]) jarsToInstrument.toArray(new File[jarsToInstrument.size()]); |
62 |
|
} |
63 |
|
|
64 |
|
public File[] getClassesToInstrument() { |
65 |
0 |
return (File[]) classesToInstrument.toArray(new File[classesToInstrument.size()]); |
66 |
|
} |
67 |
|
|
68 |
|
public String[] getPackagesToInstrument() { |
69 |
0 |
return (String[]) packagesToInstrument.toArray(new String[packagesToInstrument.size()]); |
70 |
|
} |
71 |
|
|
72 |
|
public void setup() { |
73 |
0 |
verifyInputs(); |
74 |
0 |
backupSrcToWorkDir(); |
75 |
0 |
getLogger().verbose("[EAR:"+ getSrc().getName() + "] Backed up " + getSrc().getAbsolutePath() + |
76 |
|
" to " + getBackupDir().getAbsolutePath()); |
77 |
0 |
for (Iterator it = modules.iterator(); it.hasNext(); ) { |
78 |
0 |
ModuleType module = (ModuleType) it.next(); |
79 |
0 |
module.setLogger(getLogger()); |
80 |
0 |
module.setup(this.getBackupDir()); |
81 |
|
} |
82 |
0 |
findJarsAndClassesToInstrument(); |
83 |
0 |
} |
84 |
|
|
85 |
|
public void cleanup() { |
86 |
0 |
for (Iterator it = modules.iterator(); it.hasNext(); ) { |
87 |
0 |
ModuleType module = (ModuleType) it.next(); |
88 |
0 |
module.cleanup(); |
89 |
|
} |
90 |
0 |
copyBackupToDest(); |
91 |
0 |
getLogger().verbose("[EAR:"+ getSrc().getName() + "] Copied backup " + |
92 |
|
getBackupDir().getAbsolutePath() + " to destination " + getDest().getAbsolutePath()); |
93 |
0 |
} |
94 |
|
|
95 |
|
public void appendToManifestClassPath(String cp) { |
96 |
0 |
if ((cp == null) || (cp.trim().length() == 0)) { |
97 |
0 |
return; |
98 |
|
} |
99 |
0 |
for (Iterator it = modules.iterator(); it.hasNext(); ) { |
100 |
0 |
ModuleType module = (ModuleType) it.next(); |
101 |
0 |
module.appendToManifestClassPath(cp); |
102 |
|
} |
103 |
0 |
getLogger().verbose("[EAR:"+ getSrc().getName() + "] Added " + cp + " to MANIFEST classpath"); |
104 |
0 |
} |
105 |
|
|
106 |
|
public File[] getApplicationClassPath() { |
107 |
0 |
Set appClassPath = new HashSet(); |
108 |
|
|
109 |
0 |
for (Iterator it = modules.iterator(); it.hasNext(); ) { |
110 |
0 |
ModuleType module = (ModuleType) it.next(); |
111 |
0 |
appClassPath.addAll(module.getApplicationClasspath()); |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
0 |
File app_inf_classes = new File(getBackupDir(), APP_INF_CLASSES); |
117 |
0 |
File app_inf_lib = new File(getBackupDir(), APP_INF_LIB); |
118 |
0 |
if(app_inf_lib.exists()){ |
119 |
0 |
appClassPath.addAll(FileUtils.listFiles(app_inf_lib, new String[] {"jar", "zip"}, false)); |
120 |
|
} |
121 |
0 |
if(app_inf_classes.exists()){ |
122 |
0 |
appClassPath.add(app_inf_classes); |
123 |
|
} |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
0 |
getLogger().verbose("[EAR:"+ getSrc().getName() + "] Application ClassPath is " + appClassPath); |
128 |
0 |
return (File[]) appClassPath.toArray(new File[appClassPath.size()]); |
129 |
|
} |
130 |
|
|
131 |
|
void verifyInputs() { |
132 |
0 |
if (getSrc() == null) { |
133 |
0 |
throw new BuildException("'src' attribute is not specified"); |
134 |
|
} |
135 |
0 |
if (getDest() == null) { |
136 |
0 |
throw new BuildException("'dest' attribute is not specified"); |
137 |
|
} |
138 |
0 |
if (getDest().exists()) { |
139 |
0 |
throw new BuildException(getDest().getAbsolutePath() + " exists already"); |
140 |
|
} |
141 |
0 |
getLogger().verbose("[EAR:"+ getSrc().getName() + "] Verified all inputs"); |
142 |
0 |
} |
143 |
|
|
144 |
|
void findJarsAndClassesToInstrument() { |
145 |
0 |
for (Iterator it = modules.iterator(); it.hasNext(); ) { |
146 |
0 |
ModuleType module = (ModuleType) it.next(); |
147 |
0 |
jarsToInstrument.addAll(module.getJarsToInstrument()); |
148 |
0 |
classesToInstrument.addAll(module.getClassesToInstrument()); |
149 |
0 |
packagesToInstrument.addAll(module.getPackagesToInstrument()); |
150 |
|
} |
151 |
0 |
getLogger().verbose("[EAR:"+ getSrc().getName() + "] Collected all jars and classes to instrument: " + |
152 |
|
"\n\tJars = " + jarsToInstrument + |
153 |
|
"\n\tClasses = " + classesToInstrument + |
154 |
|
"\n\tPackages = " + packagesToInstrument); |
155 |
0 |
} |
156 |
|
} |