Lines 28-37
Link Here
|
28 |
import java.io.OutputStream; |
28 |
import java.io.OutputStream; |
29 |
import java.util.ArrayList; |
29 |
import java.util.ArrayList; |
30 |
import java.util.Arrays; |
30 |
import java.util.Arrays; |
|
|
31 |
import java.util.HashMap; |
31 |
import java.util.HashSet; |
32 |
import java.util.HashSet; |
32 |
import java.util.Hashtable; |
33 |
import java.util.Hashtable; |
33 |
import java.util.Iterator; |
34 |
import java.util.Iterator; |
|
|
35 |
import java.util.LinkedList; |
34 |
import java.util.List; |
36 |
import java.util.List; |
|
|
37 |
import java.util.Map; |
35 |
import java.util.Set; |
38 |
import java.util.Set; |
36 |
import java.util.StringTokenizer; |
39 |
import java.util.StringTokenizer; |
37 |
import java.util.jar.Attributes; |
40 |
import java.util.jar.Attributes; |
Lines 189-194
Link Here
|
189 |
classPathExtensionsProperty = s; |
192 |
classPathExtensionsProperty = s; |
190 |
} |
193 |
} |
191 |
|
194 |
|
|
|
195 |
// test distribution path |
196 |
public static String testDistLocation; |
197 |
|
198 |
public static class TestType { |
199 |
private String name; |
200 |
private String folder; |
201 |
private String runtimeCP; |
202 |
private String compileCP; |
203 |
|
204 |
public TestType() {} |
205 |
public String getName() { |
206 |
return name; |
207 |
} |
208 |
|
209 |
public void setName(String name) { |
210 |
this.name = name; |
211 |
} |
212 |
|
213 |
public String getFolder() { |
214 |
return folder; |
215 |
} |
216 |
|
217 |
public void setFolder(String folder) { |
218 |
this.folder = folder; |
219 |
} |
220 |
|
221 |
public String getRuntimeCP() { |
222 |
return runtimeCP; |
223 |
} |
224 |
|
225 |
public void setRuntimeCP(String runtimeCP) { |
226 |
this.runtimeCP = runtimeCP; |
227 |
} |
228 |
|
229 |
public String getCompileCP() { |
230 |
return compileCP; |
231 |
} |
232 |
|
233 |
public void setCompileCP(String compileCP) { |
234 |
this.compileCP = compileCP; |
235 |
} |
236 |
|
237 |
} |
238 |
List /*<TestType>*/ testTypes = new LinkedList(); |
239 |
|
240 |
public void addTestType(TestType testType) { |
241 |
testTypes.add(testType); |
242 |
} |
243 |
public void add(TestType testType) { |
244 |
testTypes.add(testType); |
245 |
} |
246 |
|
247 |
|
248 |
private TestType getTestType(String name) { |
249 |
for (int i = 0 ; i < testTypes.size() ; i++) { |
250 |
TestType testType = (TestType) testTypes.get(i); |
251 |
if (testType.getName().equals(name)) { |
252 |
return testType; |
253 |
} |
254 |
} |
255 |
return null; |
256 |
} |
257 |
|
258 |
|
192 |
private void define(String prop, String val) { |
259 |
private void define(String prop, String val) { |
193 |
log("Setting " + prop + "=" + val, Project.MSG_VERBOSE); |
260 |
log("Setting " + prop + "=" + val, Project.MSG_VERBOSE); |
194 |
String old = getProject().getProperty(prop); |
261 |
String old = getProject().getProperty(prop); |
Lines 198-203
Link Here
|
198 |
getProject().setNewProperty(prop, val); |
265 |
getProject().setNewProperty(prop, val); |
199 |
} |
266 |
} |
200 |
|
267 |
|
|
|
268 |
|
201 |
public void execute() throws BuildException { |
269 |
public void execute() throws BuildException { |
202 |
try { |
270 |
try { |
203 |
if (getProjectFile() == null) { |
271 |
if (getProjectFile() == null) { |
Lines 276-282
Link Here
|
276 |
} |
344 |
} |
277 |
ModuleListParser modules = null; |
345 |
ModuleListParser modules = null; |
278 |
Dep[] deps = null; |
346 |
Dep[] deps = null; |
279 |
if (moduleDependenciesProperty != null || moduleClassPathProperty != null || moduleRunClassPathProperty != null) { |
347 |
if (moduleDependenciesProperty != null || |
|
|
348 |
moduleClassPathProperty != null || |
349 |
moduleRunClassPathProperty != null || |
350 |
testTypes.size() > 0) { |
280 |
String nball = getProject().getProperty("nb_all"); |
351 |
String nball = getProject().getProperty("nb_all"); |
281 |
Hashtable properties = getProject().getProperties(); |
352 |
Hashtable properties = getProject().getProperties(); |
282 |
properties.put("project", project.getAbsolutePath()); |
353 |
properties.put("project", project.getAbsolutePath()); |
Lines 348-353
Link Here
|
348 |
define(classPathExtensionsProperty, val); |
419 |
define(classPathExtensionsProperty, val); |
349 |
} |
420 |
} |
350 |
} |
421 |
} |
|
|
422 |
|
423 |
// Test dependecies |
424 |
// |
425 |
if (modules != null) { |
426 |
String testDistLocation = getProject().getProperty(TestDeps.TEST_DIST_VAR); |
427 |
if (testDistLocation == null) { |
428 |
testDistLocation = "${" + TestDeps.TEST_DIST_VAR + "}"; |
429 |
} |
430 |
ParseProjectXml.testDistLocation = testDistLocation; |
431 |
|
432 |
TestDeps testDepss[] = getTestDeps(pDoc,modules,getCodeNameBase(pDoc)); |
433 |
for (int tdIt = 0 ; tdIt < testDepss.length ; tdIt++) { |
434 |
TestDeps td = testDepss[tdIt]; |
435 |
// unit tests |
436 |
TestType testType = getTestType(td.testtype); |
437 |
if (testType!= null ) { |
438 |
if (testType.getFolder() != null) { |
439 |
define (testType.getFolder(),td.getTestFolder()); |
440 |
} |
441 |
if (testType.getCompileCP() != null) { |
442 |
|
443 |
define(testType.getCompileCP(),td.getCompileClassPath()); |
444 |
} |
445 |
if (testType.getRuntimeCP() != null) { |
446 |
define(testType.getRuntimeCP(),td.getRuntimeClassPath()); |
447 |
} |
448 |
|
449 |
} |
450 |
} |
451 |
} |
351 |
} catch (BuildException e) { |
452 |
} catch (BuildException e) { |
352 |
throw e; |
453 |
throw e; |
353 |
} catch (Exception e) { |
454 |
} catch (Exception e) { |
Lines 737-743
Link Here
|
737 |
} |
838 |
} |
738 |
return module.getJar(); |
839 |
return module.getJar(); |
739 |
} |
840 |
} |
740 |
|
841 |
|
|
|
842 |
final class TestDeps { |
843 |
public static final String UNIT = "unit"; |
844 |
public static final String QA_FUNCTIONAL = "qa-functional"; |
845 |
// unit, qa-functional, performance |
846 |
final String testtype; |
847 |
// all dependecies for the testtype |
848 |
final List /*<TestDep>*/ dependencies = new ArrayList(); |
849 |
// code name base of tested module |
850 |
final String cnb; |
851 |
final ModuleListParser modulesParser; |
852 |
|
853 |
public static final String TEST_DIST_VAR = "test.dist.dir"; |
854 |
public TestDeps(String testtype,String cnb,ModuleListParser modulesParser) { |
855 |
assert modulesParser != null; |
856 |
this.testtype = testtype; |
857 |
this.cnb = cnb; |
858 |
this.modulesParser = modulesParser; |
859 |
} |
860 |
|
861 |
public List/*<String>*/ getFiles(boolean compile) { |
862 |
List/*<String>*/ files = new ArrayList(); |
863 |
for (int dIt = 0 ; dIt < dependencies.size() ; dIt++) { |
864 |
files.addAll(((TestDep)dependencies.get(dIt)).getFiles(compile)); |
865 |
} |
866 |
return files; |
867 |
} |
868 |
public void addDepenency(TestDep dep) { |
869 |
dependencies.add(dep); |
870 |
} |
871 |
|
872 |
private String getTestFolder() { |
873 |
ModuleListParser.Entry entry = modulesParser.findByCodeNameBase(cnb); |
874 |
String sep = File.separator; |
875 |
|
876 |
String cluster = entry.getClusterName(); |
877 |
if (cluster == null) { |
878 |
// no cluster name is specified for standalone or module in module suite |
879 |
cluster = "cluster"; |
880 |
} |
881 |
return ParseProjectXml.testDistLocation + sep + testtype + sep + entry.getClusterName() + sep + cnb.replace('.','-'); |
882 |
} |
883 |
|
884 |
String getCompileClassPath() { |
885 |
return getPath(getFiles(true)); |
886 |
} |
887 |
private String getPath(List/*<String>*/ files) { |
888 |
StringBuffer path = new StringBuffer(); |
889 |
Set/*<String>*/ filesSet = new HashSet(); |
890 |
for (int fIt = 0 ; fIt < files.size() ; fIt++) { |
891 |
String filePath = (String)files.get(fIt); |
892 |
if (!filesSet.contains(filePath)) { |
893 |
if (path.length() > 0) { |
894 |
path.append(File.pathSeparatorChar); |
895 |
} |
896 |
filesSet.add(filePath); |
897 |
path.append(filePath); |
898 |
} |
899 |
} |
900 |
return path.toString(); |
901 |
} |
902 |
|
903 |
String getRuntimeClassPath() { |
904 |
return getPath(getFiles(false)); |
905 |
} |
906 |
|
907 |
|
908 |
} |
909 |
/** Test dependency for module and type |
910 |
*/ |
911 |
final class TestDep { |
912 |
final ModuleListParser modulesParser; |
913 |
// code name base |
914 |
final String cnb; |
915 |
// dependencies on tests of modules |
916 |
final boolean recursive; |
917 |
final boolean test; |
918 |
// runtime classpath |
919 |
final boolean compile; |
920 |
TestDeps testDeps; |
921 |
|
922 |
TestDep (String cnb,ModuleListParser modules, boolean recursive,boolean test, boolean compile,TestDeps testDeps) { |
923 |
this.modulesParser = modules; |
924 |
this.cnb = cnb; |
925 |
this.recursive = recursive; |
926 |
this.test = test; |
927 |
this.testDeps = testDeps; |
928 |
this.compile = compile; |
929 |
} |
930 |
/* get modules dependecies |
931 |
*/ |
932 |
List/*<ModuleListParser.Entry>*/ getModules() { |
933 |
List /*<ModuleListParser.Entry>*/ entries = new ArrayList(); |
934 |
if (!test) { |
935 |
if (recursive ) { |
936 |
Map/*<String,ModuleListParser.Entry>*/ entriesMap = new HashMap(); |
937 |
addRecursiveModules(cnb,entriesMap); |
938 |
entries.addAll(entriesMap.values()); |
939 |
} else { |
940 |
entries.add(modulesParser.findByCodeNameBase(cnb)); |
941 |
} |
942 |
} |
943 |
return entries; |
944 |
|
945 |
} |
946 |
|
947 |
private void addRecursiveModules(String cnd, Map entriesMap) { |
948 |
if (!entriesMap.containsKey(cnd)) { |
949 |
ModuleListParser.Entry entry = modulesParser.findByCodeNameBase(cnd); |
950 |
entriesMap.put(cnd,entry); |
951 |
String cnds[] = entry.getBuildPrerequisites(); |
952 |
// cnds can be null |
953 |
if (cnds != null) { |
954 |
for (int i = 0 ; i < cnds.length ; i++) { |
955 |
addRecursiveModules(cnds[i],entriesMap); |
956 |
} |
957 |
} |
958 |
} |
959 |
} |
960 |
List/*<String>*/ getFiles(boolean compile) { |
961 |
List/*<String>*/ files = new ArrayList(); |
962 |
if (!compile || ( compile && this.compile)) { |
963 |
List /*<ModuleListParser.Entry>*/ modules = getModules(); |
964 |
for (int mIt = 0 ; mIt <modules.size() ; mIt++) { |
965 |
ModuleListParser.Entry entry = (ModuleListParser.Entry)modules.get(mIt); |
966 |
if (entry != null) { |
967 |
files.add(entry.getJar().getAbsolutePath()); |
968 |
} else { |
969 |
log("Entry doesn't exist."); |
970 |
} |
971 |
} |
972 |
// get tests files |
973 |
if (test) { |
974 |
// get test folder |
975 |
ModuleListParser.Entry entry = (ModuleListParser.Entry) modulesParser.findByCodeNameBase(cnb); |
976 |
String sep = File.separator; |
977 |
String jarPath = ParseProjectXml.testDistLocation + sep + testDeps.testtype + sep + entry.getClusterName() + sep + cnb.replace('.','-') + sep + "tests.jar"; |
978 |
files.add(jarPath); |
979 |
} |
980 |
} |
981 |
return files; |
982 |
} |
983 |
} |
741 |
private String computeClassPathExtensions(Document pDoc) { |
984 |
private String computeClassPathExtensions(Document pDoc) { |
742 |
Element data = getConfig(pDoc); |
985 |
Element data = getConfig(pDoc); |
743 |
StringBuffer list = null; |
986 |
StringBuffer list = null; |
Lines 847-850
Link Here
|
847 |
return ppjar; |
1090 |
return ppjar; |
848 |
} |
1091 |
} |
849 |
|
1092 |
|
|
|
1093 |
private TestDeps[] getTestDeps(Document pDoc,ModuleListParser modules,String testCnb) { |
1094 |
assert modules != null; |
1095 |
Element cfg = getConfig(pDoc); |
1096 |
List testDepsList = new ArrayList(); |
1097 |
Element pp = XMLUtil.findElement(cfg, "test-dependencies", NBM_NS); |
1098 |
if (pp != null) { |
1099 |
for (Iterator depssIt = XMLUtil.findSubElements(pp).iterator(); depssIt.hasNext();) { |
1100 |
Element depssEl = (Element) depssIt.next(); |
1101 |
String testType = findTextOrNull(depssEl,"name"); |
1102 |
if (testType == null) { |
1103 |
testType = TestDeps.UNIT; // default variant |
1104 |
} |
1105 |
TestDeps testDeps = new TestDeps(testType,testCnb,modules); |
1106 |
testDepsList.add(testDeps); |
1107 |
for (Iterator depsIt = XMLUtil.findSubElements(depssEl).iterator() ; depsIt.hasNext();) { |
1108 |
Element el = (Element) depsIt.next(); |
1109 |
if (el.getTagName().equals("test-dependency")) { |
1110 |
// parse test dep |
1111 |
boolean test = (XMLUtil.findElement(el,"test",NBM_NS) != null);; |
1112 |
String cnb = findTextOrNull(el,"code-name-base"); |
1113 |
boolean recursive = (XMLUtil.findElement(el,"recursive",NBM_NS) != null); |
1114 |
boolean compile = (XMLUtil.findElement(el,"compile-dependency",NBM_NS) != null); |
1115 |
testDeps.addDepenency(new TestDep(cnb, |
1116 |
modules, |
1117 |
recursive, |
1118 |
test, |
1119 |
compile, |
1120 |
testDeps)); |
1121 |
} |
1122 |
|
1123 |
} |
1124 |
} |
1125 |
} |
1126 |
TestDeps testDepss[] = new TestDeps[testDepsList.size()]; |
1127 |
testDepsList.toArray(testDepss); |
1128 |
return testDepss; |
1129 |
} |
1130 |
private static String findTextOrNull(Element parentElement,String elementName) { |
1131 |
Element el = XMLUtil.findElement(parentElement,elementName,NBM_NS); |
1132 |
return (el == null) ? null : |
1133 |
XMLUtil.findText(el); |
1134 |
|
1135 |
} |
1136 |
|
850 |
} |
1137 |
} |