You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Ajctest.java 70KB

21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
21 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.internal.tools.ant.taskdefs;
  14. import java.awt.BorderLayout;
  15. import java.awt.Color;
  16. import java.awt.Component;
  17. import java.awt.Dimension;
  18. import java.awt.FlowLayout;
  19. import java.awt.Font;
  20. import java.awt.GridBagConstraints;
  21. import java.awt.GridBagLayout;
  22. import java.awt.Insets;
  23. import java.awt.LayoutManager;
  24. import java.beans.PropertyChangeEvent;
  25. import java.beans.PropertyChangeListener;
  26. import java.beans.PropertyChangeSupport;
  27. import java.io.File;
  28. import java.io.FileWriter;
  29. import java.io.IOException;
  30. import java.io.OutputStream;
  31. import java.io.PrintStream;
  32. import java.io.PrintWriter;
  33. import java.io.StringWriter;
  34. import java.text.DateFormat;
  35. //import java.util.Collection;
  36. import java.util.Date;
  37. import java.util.HashMap;
  38. import java.util.Iterator;
  39. import java.util.List;
  40. import java.util.Map;
  41. import java.util.StringTokenizer;
  42. import java.util.Vector;
  43. import javax.swing.BorderFactory;
  44. import javax.swing.BoxLayout;
  45. import javax.swing.JFrame;
  46. import javax.swing.JLabel;
  47. import javax.swing.JPanel;
  48. import javax.swing.JScrollPane;
  49. import javax.swing.JSplitPane;
  50. import javax.swing.JTable;
  51. import javax.swing.JTextArea;
  52. import javax.swing.JTextField;
  53. import javax.swing.ListSelectionModel;
  54. import javax.swing.border.BevelBorder;
  55. import javax.swing.event.ListSelectionEvent;
  56. import javax.swing.table.DefaultTableModel;
  57. import javax.swing.table.TableModel;
  58. import javax.swing.text.StyleContext;
  59. import org.apache.tools.ant.BuildException;
  60. import org.apache.tools.ant.Location;
  61. import org.apache.tools.ant.Project;
  62. import org.apache.tools.ant.Target;
  63. import org.apache.tools.ant.Task;
  64. import org.apache.tools.ant.taskdefs.Delete;
  65. //import org.apache.tools.ant.taskdefs.ExecTask;
  66. import org.apache.tools.ant.taskdefs.Java;
  67. import org.apache.tools.ant.taskdefs.LogOutputStream;
  68. import org.apache.tools.ant.taskdefs.Mkdir;
  69. import org.apache.tools.ant.taskdefs.StreamPumper;
  70. import org.apache.tools.ant.types.Commandline;
  71. import org.apache.tools.ant.types.FileSet;
  72. import org.apache.tools.ant.types.Path;
  73. import org.apache.tools.ant.types.Reference;
  74. import org.aspectj.util.LangUtil;
  75. public class Ajctest extends Task implements PropertyChangeListener {
  76. private static Ajctest CURRENT_AJCTEST;
  77. // todo shutdown hook assumes one task per VM
  78. public Ajctest() {
  79. super();
  80. CURRENT_AJCTEST = this;
  81. }
  82. private static boolean firstTime = true;
  83. public final PropertyChangeSupport bean = new PropertyChangeSupport(this);
  84. {
  85. bean.addPropertyChangeListener(this);
  86. }
  87. public void propertyChange(PropertyChangeEvent evt) {
  88. String name = evt.getPropertyName();
  89. if ("ajdoc.good".equals(name)) ajdocStats.goods++;
  90. else if ("ajc.good".equals(name)) ajcStats.goods++;
  91. else if ("run.good".equals(name)) runStats.goods++;
  92. if ("ajdoc.fail".equals(name)) ajdocStats.fails++;
  93. else if ("ajc.fail".equals(name)) ajcStats.fails++;
  94. else if ("run.fail".equals(name)) runStats.fails++;
  95. }
  96. private void fire(String prop, Object oldval, Object newval) {
  97. bean.firePropertyChange(prop, oldval, newval);
  98. }
  99. private void fire(String prop) {
  100. fire(prop, "dummy-old", "dummy-new");
  101. }
  102. private static boolean dumpresults = false;
  103. private Stats ajdocStats = new Stats();
  104. private Stats ajcStats = new Stats();
  105. private Stats runStats = new Stats();
  106. // private Stats errorStats = new Stats();
  107. private static final String NO_TESTID = "NONE";
  108. private File workingdir = new File("ajworkingdir"); //XXX
  109. //fields
  110. private String testId = NO_TESTID;
  111. private List<Argument> args = new Vector<>();
  112. private List<Testset> testsets = new Vector<>();
  113. private Path classpath;
  114. private Path internalclasspath;
  115. private File destdir;
  116. private File dir;
  117. private File errorfile;
  118. private List<Run> testclasses = new Vector<>();
  119. private boolean nocompile;
  120. private Ajdoc ajdoc = null;
  121. private boolean noclean;
  122. private boolean noverify;
  123. private List<String> depends = new Vector<>();
  124. //end-fields
  125. public Argfile createArgfile() {
  126. return createTestset().createArgfile();
  127. }
  128. public void setNoverify(boolean input) {
  129. if (input != noverify) noverify = input;
  130. }
  131. public void setOwningTarget(Target target) {
  132. super.setOwningTarget(target);
  133. if (null != target) {
  134. //setTestId(target.getName());
  135. }
  136. }
  137. public void setTestId(String str) {
  138. if ((null != str) && (0 < str.trim().length())) {
  139. testId = str;
  140. }
  141. }
  142. public void setArgs(String str) {
  143. if (str == null || str.length() < 1) return;
  144. StringTokenizer tok = new StringTokenizer(str, ",", false);
  145. while (tok.hasMoreTokens()) {
  146. String name = tok.nextToken().trim();
  147. if (0 < name.length()) {
  148. parse(name.startsWith("J") ? createJarg() : createArg(), name);
  149. }
  150. }
  151. }
  152. private void parse(Argument arg, String name) {
  153. int itilde = name.lastIndexOf("~");
  154. if (itilde != -1) {
  155. name = name.substring(0, itilde) + name.substring(itilde+1);
  156. }
  157. int ieq = name.lastIndexOf("=");
  158. int icolon = name.lastIndexOf(":");
  159. int ileft = name.lastIndexOf("[");
  160. int iright = name.lastIndexOf("]");
  161. boolean always = true;
  162. String rest = "";
  163. String newName = name;
  164. if (ieq != -1) {
  165. rest = name.substring(ieq+1);
  166. newName = name.substring(0, ieq);
  167. always = true;
  168. } else if (icolon != -1) {
  169. rest = name.substring(icolon+1);
  170. newName = name.substring(0, icolon);
  171. always = false;
  172. } else if (ileft != -1) {
  173. newName = name.substring(0, ileft);
  174. always = true;
  175. }
  176. String values = ileft == -1 ? rest :
  177. name.substring(ileft+1, iright > ileft ? iright : rest.length()-1);
  178. String value = null;
  179. if (itilde != -1) {
  180. String prop = project.getUserProperty(values);
  181. if (prop == null) {
  182. prop = project.getProperty(values);
  183. }
  184. if (prop != null) {
  185. value = prop;
  186. }
  187. }
  188. if (value != null) {
  189. arg.setValue(value);
  190. } else {
  191. arg.setValues(values);
  192. }
  193. arg.setName(newName);
  194. arg.setAlways(always);
  195. }
  196. public Argument createJarg() {
  197. Argument arg = new Argument(true);
  198. args.add(arg);
  199. return arg;
  200. }
  201. public Argument createArg() {
  202. Argument arg = new Argument(false);
  203. args.add(arg);
  204. return arg;
  205. }
  206. public void setClasspath(Path path) {
  207. if (classpath == null) {
  208. classpath = path;
  209. } else {
  210. classpath.append(path);
  211. }
  212. }
  213. public Path createClasspath() {
  214. if (classpath == null) {
  215. classpath = new Path(project);
  216. }
  217. return classpath.createPath();
  218. }
  219. public void setClasspathRef(Reference r) {
  220. createClasspath().setRefid(r);
  221. }
  222. public void setInternalclasspath(Path path) {
  223. if (internalclasspath == null) {
  224. internalclasspath = path;
  225. } else {
  226. internalclasspath.append(path);
  227. }
  228. }
  229. public Path createInternalclasspath() {
  230. if (internalclasspath == null) {
  231. internalclasspath = new Path(project);
  232. }
  233. return internalclasspath.createPath();
  234. }
  235. public void setInternalclasspathRef(Reference r) {
  236. createInternalclasspath().setRefid(r);
  237. }
  238. public void setDestdir(String destdir) {
  239. this.destdir = project.resolveFile(destdir);
  240. }
  241. public void setDir(File dir) {
  242. this.dir = dir;
  243. }
  244. public void setErrorfile(File errorfile) {
  245. this.errorfile = errorfile;
  246. }
  247. public Run createJava() {
  248. Run testclass = new Run(project);
  249. testclasses.add(testclass);
  250. return testclass;
  251. }
  252. public void setClasses(String str) {
  253. for (StringTokenizer t = new StringTokenizer(str, ", ", false);
  254. t.hasMoreTokens();) {
  255. createJava().setClassname(t.nextToken().trim());
  256. }
  257. }
  258. public void setTestclass(String testclass) {
  259. createJava().setClassname(testclass);
  260. }
  261. public void setAjdoc(boolean b) {
  262. if (b && ajdoc == null) {
  263. createAjdoc();
  264. } else if (!b) {
  265. ajdoc = null;
  266. }
  267. }
  268. public void setAjdocargs(String str) {
  269. createAjdoc();
  270. for (StringTokenizer t = new StringTokenizer(str, ", ", false);
  271. t.hasMoreTokens();) {
  272. ajdoc.createArg().setValue(t.nextToken().trim());
  273. }
  274. }
  275. public void addAjdoc(Ajdoc ajdoc) {
  276. this.ajdoc = ajdoc;
  277. }
  278. public Ajdoc createAjdoc() {
  279. return ajdoc = new Ajdoc();
  280. }
  281. public static class Argument {
  282. private String name;
  283. private List<String> values = new Vector<>();
  284. private boolean always = true;
  285. final boolean isj;
  286. public Argument(boolean isj) {
  287. this.isj = isj;
  288. }
  289. public void setName(String str) {
  290. this.name = str.startsWith("-") ? str :
  291. ("-" + (str.startsWith("J") ? str.substring(1) : str));
  292. }
  293. public void setValues(String str) {
  294. values = new Vector<>();
  295. StringTokenizer tok = new StringTokenizer(str, ", ", false);
  296. while (tok.hasMoreTokens()) {
  297. values.add(tok.nextToken().trim());
  298. }
  299. }
  300. public void setValue(String value) {
  301. (values = new Vector<>()).add(value);
  302. }
  303. public void setAlways(boolean always) {
  304. this.always = always;
  305. }
  306. public String toString() { return name + ":" + values; }
  307. }
  308. public void setNocompile(boolean nocompile) {
  309. this.nocompile = nocompile;
  310. }
  311. private static class Stats {
  312. int goods = 0;
  313. int fails = 0;
  314. }
  315. private static class Arg {
  316. final String name;
  317. final String value;
  318. final boolean isj;
  319. Arg(String name, String value, boolean isj) {
  320. this.name = name;
  321. this.value = value;
  322. this.isj = isj;
  323. }
  324. public String toString() {
  325. return name + (!"".equals(value) ? " " + value : "");
  326. }
  327. }
  328. public Testset createTestset() {
  329. Testset testset = new Testset();
  330. testsets.add(testset);
  331. return testset;
  332. }
  333. public void setNoclean(boolean noclean) {
  334. this.noclean = noclean;
  335. }
  336. public void setDepends(String depends) {
  337. for (StringTokenizer t = new StringTokenizer(depends, ", ", false);
  338. t.hasMoreTokens();) {
  339. this.depends.add(t.nextToken().trim());
  340. }
  341. }
  342. //end-methods
  343. public static class Argfile {
  344. private String name;
  345. public void setName(String name) { this.name = name; }
  346. }
  347. public class Ajdoc {
  348. private Commandline cmd = new Commandline();
  349. public Commandline.Argument createArg() { return cmd.createArgument(); }
  350. public Commandline getCommandline() { return cmd; }
  351. public String toString() { return cmd + ""; }
  352. }
  353. public class Testset extends FileSet {
  354. private List<Argfile> argfileNames = new Vector<>();
  355. public List<File> argfiles;
  356. public List<File> files;
  357. public List<Argument> args = new Vector<>();
  358. public String classname;
  359. private boolean havecludes = false;
  360. private List<Run> testclasses = new Vector<>();
  361. private Path classpath;
  362. private Path internalclasspath;
  363. private Ajdoc ajdoc = null;
  364. private boolean fork = false;
  365. private boolean noclean;
  366. private List<String> depends = new Vector<>();
  367. public String toString() {
  368. String str = "";
  369. if (files.size() > 0) {
  370. str += "files:" + "\n";
  371. for (Iterator<File> i = files.iterator(); i.hasNext();) {
  372. str += "\t" + i.next() + "\n";
  373. }
  374. }
  375. if (argfiles.size() > 0) {
  376. str += "argfiles:" + "\n";
  377. for (Iterator<File> i = argfiles.iterator(); i.hasNext();) {
  378. str += "\t" + i.next() + "\n";
  379. }
  380. }
  381. if (args.size() > 0) {
  382. str += "args:" + "\n";
  383. for (Iterator i = args.iterator(); i.hasNext();) {
  384. str += "\t" + i.next() + "\n";
  385. }
  386. }
  387. if (testclasses.size() > 0) {
  388. str += "classes:" + "\n";
  389. for (Iterator i = testclasses.iterator(); i.hasNext();) {
  390. str += "\t" + i.next() + "\n";
  391. }
  392. }
  393. return str;
  394. }
  395. public void setIncludes(String includes) {
  396. super.setIncludes(includes);
  397. havecludes = true;
  398. }
  399. public void setExcludes(String excludes) {
  400. super.setExcludes(excludes);
  401. havecludes = true;
  402. }
  403. public void setIncludesfile(File includesfile) {
  404. super.setIncludesfile(includesfile);
  405. havecludes = true;
  406. }
  407. public void setExcludesfile(File excludesfile) {
  408. super.setExcludesfile(excludesfile);
  409. havecludes = true;
  410. }
  411. public void setArgfile(String name) {
  412. createArgfile().setName(name);
  413. }
  414. public void setArgfiles(String str) {
  415. StringTokenizer tok = new StringTokenizer(str, ", ", false);
  416. while (tok.hasMoreTokens()) {
  417. createArgfile().setName(tok.nextToken().trim());
  418. }
  419. }
  420. public Argfile createArgfile() {
  421. Argfile argfile = new Argfile();
  422. argfileNames.add(argfile);
  423. return argfile;
  424. }
  425. public Run createJava() {
  426. // See crashing note
  427. //Run testclass = new Run();
  428. Run testclass = new Run(project);
  429. this.testclasses.add(testclass);
  430. return testclass;
  431. }
  432. public void addJava(Run run) {
  433. this.testclasses.add(run);
  434. }
  435. public void setJava(String str) {
  436. StringTokenizer t = new StringTokenizer(str, " ");
  437. Run run = createJava();
  438. run.setClassname(t.nextToken().trim());
  439. while (t.hasMoreTokens()) {
  440. run.createArg().setValue(t.nextToken().trim());
  441. }
  442. }
  443. public void setTestclass(String testclass) {
  444. createJava().setClassname(testclass);
  445. }
  446. public void setClasses(String str) {
  447. for (StringTokenizer t = new StringTokenizer(str, ", ", false);
  448. t.hasMoreTokens();) {
  449. createJava().setClassname(t.nextToken().trim());
  450. }
  451. }
  452. public void setClasspath(Path path) {
  453. if (classpath == null) {
  454. classpath = path;
  455. } else {
  456. classpath.append(path);
  457. }
  458. }
  459. public Path createClasspath() {
  460. if (classpath == null) {
  461. classpath = new Path(project);
  462. }
  463. return classpath.createPath();
  464. }
  465. public void setClasspathRef(Reference r) {
  466. createClasspath().setRefid(r);
  467. }
  468. public void setInternalclasspath(Path path) {
  469. if (internalclasspath == null) {
  470. internalclasspath = path;
  471. } else {
  472. internalclasspath.append(path);
  473. }
  474. }
  475. public Path createInternalclasspath() {
  476. if (internalclasspath == null) {
  477. internalclasspath = new Path(project);
  478. }
  479. return internalclasspath.createPath();
  480. }
  481. public void setInternalclasspathRef(Reference r) {
  482. createInternalclasspath().setRefid(r);
  483. }
  484. public void setAjdoc(boolean b) {
  485. if (b && ajdoc == null) {
  486. createAjdoc();
  487. } else if (!b) {
  488. this.ajdoc = null;
  489. }
  490. }
  491. public Ajdoc getAjdoc() { return this.ajdoc; }
  492. public void setAjdocargs(String str) {
  493. createAjdoc();
  494. for (StringTokenizer t = new StringTokenizer(str, ", ", false);
  495. t.hasMoreTokens();) {
  496. this.ajdoc.createArg().setValue(t.nextToken().trim());
  497. }
  498. }
  499. public void addAjdoc(Ajdoc ajdoc) {
  500. this.ajdoc = ajdoc;
  501. }
  502. public Ajdoc createAjdoc() {
  503. return this.ajdoc = new Ajdoc();
  504. }
  505. public void setFork(boolean fork) {
  506. this.fork = fork;
  507. }
  508. public void setNoclean(boolean noclean) {
  509. this.noclean = noclean;
  510. }
  511. public void setDepends(String depends) {
  512. for (StringTokenizer t = new StringTokenizer(depends, ", ", false);
  513. t.hasMoreTokens();) {
  514. this.depends.add(t.nextToken().trim());
  515. }
  516. }
  517. //end-testset-methods
  518. public void resolve() throws BuildException {
  519. if (dir != null) this.setDir(dir);
  520. File src = getDir(project);
  521. argfiles = new Vector<>();
  522. files = new Vector<>();
  523. for(Iterator<Argfile> iter = argfileNames.iterator(); iter.hasNext();) {
  524. String name = iter.next().name;
  525. File argfile = new File(src, name);
  526. if (check(argfile, name, location)) argfiles.add(argfile);
  527. }
  528. if (havecludes || argfiles.size() <= 0) {
  529. String[] filenames =
  530. getDirectoryScanner(project).getIncludedFiles();
  531. for (int j = 0; j < filenames.length; j++) {
  532. String name = filenames[j];
  533. if (name.endsWith(".java")) {
  534. File file = new File(src, name);
  535. if (check(file, name, location)) files.add(file);
  536. }
  537. }
  538. }
  539. for (Iterator i = Ajctest.this.testclasses.iterator();
  540. i.hasNext();) {
  541. this.testclasses.add((Run)i.next());
  542. }
  543. if (this.classpath == null) {
  544. setClasspath(Ajctest.this.classpath);
  545. }
  546. if (this.internalclasspath == null) {
  547. setInternalclasspath(Ajctest.this.internalclasspath);
  548. }
  549. if (this.ajdoc == null) {
  550. this.ajdoc = Ajctest.this.ajdoc;
  551. }
  552. if (this.fork) {
  553. for (Iterator<Run> i = this.testclasses.iterator(); i.hasNext();) {
  554. i.next().setFork(fork);
  555. }
  556. }
  557. if (!this.noclean) {
  558. this.noclean = Ajctest.this.noclean;
  559. }
  560. this.depends.addAll(Ajctest.this.depends);
  561. }
  562. private boolean check(File file, String name, Location loc)
  563. throws BuildException {
  564. loc = loc != null ? loc : location;
  565. if (file == null) {
  566. throw new BuildException
  567. ("file " + name + " is null!", loc);
  568. }
  569. if (!file.exists()) {
  570. throw new BuildException
  571. ("file " + file + " with name " + name +
  572. " doesn't exist!", loc);
  573. }
  574. return true;
  575. }
  576. public void setArgs(String str) {
  577. if (str == null || str.length() < 1) return;
  578. StringTokenizer tok = new StringTokenizer(str, ",", false);
  579. while (tok.hasMoreTokens()) {
  580. String name = tok.nextToken().trim();
  581. parse(name.startsWith("J") ? createJarg() : createArg(), name);
  582. }
  583. }
  584. public Argument createJarg() {
  585. Argument arg = new Argument(true);
  586. args.add(arg);
  587. return arg;
  588. }
  589. public Argument createArg() {
  590. Argument arg = new Argument(false);
  591. args.add(arg);
  592. return arg;
  593. }
  594. }
  595. private void prepare() throws BuildException {
  596. }
  597. private void finish() throws BuildException {
  598. if (errors.size() > 0) {
  599. log("");
  600. log("There " + w(errors) + " " + errors.size() + " errors:");
  601. for (int i = 0; i < errors.size(); i++) {
  602. log(" ", (Failure)errors.get(i), i);
  603. }
  604. }
  605. allErrors.addAll(errors);
  606. }
  607. private void log(String space, Failure failure, int num) {
  608. String number = "[" + num + "] ";
  609. log(enough(number, 60, '-'));
  610. for (int i = number.length()-1; i > 0; i--) space += " ";
  611. log(space, failure.testset.files, "files:");
  612. log(space, failure.testset.argfiles, "argfiles:");
  613. log(space, failure.args, "args:");
  614. log(space + "msgs:" + failure.msgs);
  615. }
  616. private String enough(String str, int size, char filler) {
  617. while (str.length() < size) str += filler;
  618. return str;
  619. }
  620. private void log(String space, List<?> list, String title) {
  621. if (list == null || list.size() < 1) return;
  622. log(space + title);
  623. for (Iterator<?> i = list.iterator(); i.hasNext();) {
  624. log(space + " " + i.next());
  625. }
  626. }
  627. private void execute(Testset testset, List<Arg> args) throws BuildException {
  628. if (testset.files.size() > 0) {
  629. log("\tfiles:");
  630. for (Iterator<File> i = testset.files.iterator(); i.hasNext();) {
  631. log("\t " + i.next());
  632. }
  633. }
  634. if (testset.argfiles.size() > 0) {
  635. log("\targfiles:");
  636. for (Iterator<File> i = testset.argfiles.iterator(); i.hasNext();) {
  637. log("\t " + i.next());
  638. }
  639. }
  640. if (args.size() > 0) {
  641. log("\targs:");
  642. for (Iterator<Arg> i = args.iterator(); i.hasNext();) {
  643. log("\t " + i.next());
  644. }
  645. }
  646. if (testset.testclasses.size() > 0) {
  647. log("\tclasses:");
  648. for (Iterator<Run> i = testset.testclasses.iterator(); i.hasNext();) {
  649. log("\t " + i.next());
  650. }
  651. }
  652. if (!testset.noclean &&
  653. (!isSet("noclean") && !isSet("nocompile"))) {
  654. delete(destdir);
  655. make(destdir);
  656. }
  657. delete(workingdir);
  658. make(workingdir);
  659. for (Iterator<String> i = testset.depends.iterator(); i.hasNext();) {
  660. String target = i.next()+"";
  661. // todo: capture failures here?
  662. project.executeTarget(target);
  663. }
  664. int exit;
  665. if (!isSet("nodoc") && testset.ajdoc != null) {
  666. log("\tdoc... " + testset.ajdoc);
  667. AjdocWrapper ajdoc = new AjdocWrapper(testset, args);
  668. if ((exit = ajdoc.run()) != 0) {
  669. post(testset, args, ajdoc.msgs, exit, "ajdoc");
  670. } else {
  671. fire("ajdoc.good");
  672. }
  673. fire("ajdoc.done");
  674. log("\tdone with ajdoc.");
  675. }
  676. boolean goodCompile = true;
  677. if (!isSet("nocompile") && !nocompile) {
  678. log("\tcompile" +
  679. (testset.noclean ? "(boostrapped)" : "") + "...");
  680. //AjcWrapper ajc = new AjcWrapper(testset, args);
  681. JavaCommandWrapper ajc;
  682. // XXX dependency on Ant property ajctest.compiler
  683. final String compiler = getAntProperty("ajctest.compiler");
  684. if ("eclipse".equals(compiler) || "eajc".equals(compiler)) {
  685. ajc = new EAjcWrapper(testset, args);
  686. } else if ((null == compiler) || "ajc".equals(compiler)) {
  687. ajc = new AjcWrapper(testset, args);
  688. } else if ("javac".equals(compiler)) {
  689. throw new Error("javac not supported");
  690. //ajc = new JavacWrapper(testset, args);
  691. } else {
  692. throw new Error("unknown compiler: " + compiler);
  693. }
  694. System.out.println("using compiler: " + ajc);
  695. try {
  696. if ((exit = ajc.run()) != 0) {
  697. post(testset, args, ajc.msgs, exit, "ajc");
  698. goodCompile = false;
  699. } else {
  700. fire("ajc.good");
  701. }
  702. fire("ajc.done");
  703. } catch (Throwable ___) {
  704. post(testset, args, ___+"", -1, "ajc");
  705. goodCompile = false;
  706. }
  707. }
  708. if (!goodCompile) {
  709. post(testset, new Vector(),
  710. "couldn't run classes " + testset.testclasses +
  711. "due to failed compile",
  712. -1, "run");
  713. } else if (!isSet("norun")) {
  714. for (Iterator<Run> i = testset.testclasses.iterator(); i.hasNext();) {
  715. Run testclass = i.next();
  716. log("\ttest..." + testclass.classname());
  717. if (null != destdir) {
  718. testclass.setClassesDir(destdir.getAbsolutePath());
  719. }
  720. if ((exit = testclass.executeJava()) != 0) {
  721. post(testset, new Vector(), testclass.msgs, exit, "run");
  722. } else {
  723. fire("run.good");
  724. }
  725. fire("run.done");
  726. }
  727. }
  728. log("");
  729. }
  730. public void execute() throws BuildException {
  731. gui(this);
  732. dumpresults = isSet("dumpresults");
  733. prepare();
  734. log(testsets.size() + " testset" + s(testsets),
  735. Project.MSG_VERBOSE);
  736. Map<Testset,List<List<Arg>>> testsetToArgcombo = new HashMap<>();
  737. List<Integer> argcombos = new Vector<>();
  738. for (Testset testset: testsets) {
  739. testset.resolve();
  740. List<Argument> bothargs = new Vector<>(args);
  741. bothargs.addAll(testset.args);
  742. List<List<Arg>> argcombo = argcombo(bothargs);
  743. argcombos.add(new Integer(argcombo.size()));
  744. testsetToArgcombo.put(testset, argcombo);
  745. }
  746. while (!testsetToArgcombo.isEmpty()) {
  747. int _ = 1;
  748. for (Iterator<Testset> iter = testsets.iterator(); iter.hasNext(); _++) {
  749. Testset testset = iter.next();
  750. List<List<Arg>> argcombo = testsetToArgcombo.get(testset);
  751. if (argcombo.size() == 0) {
  752. testsetToArgcombo.remove(testset);
  753. continue;
  754. }
  755. List<Arg> args = argcombo.remove(0);
  756. final String startStr = "Testset " + _ + " of " + testsets.size();
  757. String str = startStr + " / Combo " + _ + " of " + argcombos.size();
  758. log("---------- " + str + " ----------");
  759. execute(testset, args);
  760. }
  761. }
  762. // for (Iterator iter = testsets.iterator(); iter.hasNext(); _++) {
  763. // Testset testset = (Testset)iter.next();
  764. // testset.resolve();
  765. // List bothargs = new Vector(args);
  766. // bothargs.addAll(testset.args);
  767. // int __ = 1;
  768. // List argcombo = argcombo(bothargs);
  769. // log(argcombo.size() + " combination" + s(argcombo),
  770. // Project.MSG_VERBOSE);
  771. // final String startStr = "Testset " + _ + " of " + testsets.size();
  772. // for (Iterator comboiter = argcombo.iterator();
  773. // comboiter.hasNext(); __++) {
  774. // List args = (List)comboiter.next();
  775. // execute(testset, args);
  776. // log("");
  777. // }
  778. // }
  779. finish();
  780. }
  781. private void delete(File dir) throws BuildException {
  782. Delete delete = (Delete)project.createTask("delete");
  783. delete.setDir(dir);
  784. delete.execute();
  785. }
  786. private void make(File dir) throws BuildException {
  787. Mkdir mkdir = (Mkdir)project.createTask("mkdir");
  788. mkdir.setDir(dir);
  789. mkdir.execute();
  790. }
  791. private String getAntProperty(String name) {
  792. String uprop = project.getUserProperty(name);
  793. if (null == uprop) {
  794. uprop = project.getProperty(name);
  795. }
  796. return uprop;
  797. }
  798. private boolean isSet(String name) {
  799. String uprop = project.getUserProperty(name);
  800. if (uprop == null ||
  801. "no".equals(uprop) ||
  802. "false".equals(uprop)) return false;
  803. String prop = project.getProperty(name);
  804. if (prop == null ||
  805. "no".equals(prop) ||
  806. "false".equals(prop)) return false;
  807. return true;
  808. }
  809. /**
  810. * Interpose Wrapper class to catch and report exceptions
  811. * by setting a positive value for System.exit().
  812. * (In some cases it seems that Exceptions are not being reported
  813. * as errors in the tests.)
  814. * This forces the VM to fork. A forked VM is required for
  815. * two reasons:
  816. * (1) The wrapper class may have been defined by a different
  817. * class loader than the target class, so it would not be able
  818. * to load the target class;
  819. * <p>
  820. * (2) Since the wrapper class is generic, we have to pass in
  821. * the name of the target class. I choose to do this using
  822. * VM properties rather than hacking up the arguments.
  823. * <p>todo: relies on name/value of property "taskdef.jar"
  824. * to add jar with wrapper to invoking classpath.
  825. * <p>
  826. * It is beneficial for another reason:
  827. * (3) The wrapper class can be asked to test-load all classes
  828. * in a classes dir, by setting a VM property. This class
  829. * sets up the property if the value is defined using
  830. * <code>setClassesDir(String)</code>
  831. * <p>todo: if more tunnelling, generalize and parse.
  832. */
  833. public class RunWrapper extends Java {
  834. public final Class LINK_WRAPPER_CLASS = MainWrapper.class;
  835. /** tracked in MainWrapper.PROP_NAME */ // todo: since reflective, avoid direct
  836. public final String PROP_NAME = "MainWrapper.classname";
  837. /** tracked in MainWrapper.CLASSDIR_NAME */
  838. public final String CLASSDIR_NAME = "MainWrapper.classdir";
  839. public final String WRAPPER_CLASS
  840. = "org.aspectj.internal.tools.ant.taskdefs.MainWrapper";
  841. private String classname;
  842. protected String classesDir;
  843. /** capture classname here, replace with WRAPPER_CLASS */
  844. public void setClassname(String classname) {
  845. super.setClassname(WRAPPER_CLASS);
  846. this.classname = classname;
  847. }
  848. /**
  849. * Setup the requirements for the wrapper class:
  850. * <li>fork to get classpath and VM properties right</li>
  851. * <li>set VM property</li>
  852. * <li>add ${ajctest.wrapper.jar} (with wrapper class) to the classpath</li>
  853. */
  854. private void setup() {
  855. setFork(true);
  856. Commandline.Argument cname = createJvmarg();
  857. cname.setValue("-D"+PROP_NAME+"="+classname);
  858. if (!noverify) {
  859. cname = createJvmarg();
  860. cname.setValue("-Xfuture"); // todo: 1.2 or later..
  861. }
  862. if (null != classesDir) {
  863. cname = createJvmarg();
  864. cname.setValue("-D"+CLASSDIR_NAME+"="+classesDir);
  865. }
  866. // todo dependence on name/setting of ajctest.wrapper.jar
  867. String value = project.getProperty("ajctest.wrapper.jar");
  868. if (null != value) {
  869. Path wrapperPath = new Path(project, value);
  870. RunWrapper.this.createClasspath().append(wrapperPath);
  871. }
  872. }
  873. /** do setup, then super.execute() */
  874. public int executeJava() {
  875. setup();
  876. int result = super.executeJava();
  877. // snarf - also load all classes?
  878. return result;
  879. }
  880. /** set directory to scan for classes */
  881. public void setClassesDir(String dir) {
  882. classesDir = dir;
  883. }
  884. }
  885. public class Run extends RunWrapper {
  886. //public class Run extends Java
  887. private Path bootclasspath;
  888. public void setBootbootclasspath(Path path) {
  889. if (bootclasspath == null) {
  890. bootclasspath = path;
  891. } else {
  892. bootclasspath.append(path);
  893. }
  894. }
  895. public Path createBootbootclasspath() {
  896. if (bootclasspath == null) bootclasspath = new Path(this.project);
  897. return bootclasspath.createPath();
  898. }
  899. public void setBootbootclasspathRef(Reference r) {
  900. createBootbootclasspath().setRefid(r);
  901. }
  902. private Path bootclasspatha;
  903. public void setBootbootclasspatha(Path path) {
  904. if (bootclasspatha == null) {
  905. bootclasspatha = path;
  906. } else {
  907. bootclasspatha.append(path);
  908. }
  909. }
  910. public Path createBootbootclasspatha() {
  911. if (bootclasspatha == null) bootclasspatha = new Path(this.project);
  912. return bootclasspatha.createPath();
  913. }
  914. public void setBootbootclasspathaRef(Reference r) {
  915. createBootbootclasspatha().setRefid(r);
  916. }
  917. private Path bootclasspathp;
  918. public void setBootbootclasspathp(Path path) {
  919. if (bootclasspathp == null) {
  920. bootclasspathp = path;
  921. } else {
  922. bootclasspathp.append(path);
  923. }
  924. }
  925. public Path createBootbootclasspathp() {
  926. if (bootclasspathp == null) bootclasspathp = new Path(this.project);
  927. return bootclasspathp.createPath();
  928. }
  929. public void setBootbootclasspathpRef(Reference r) {
  930. createBootbootclasspathp().setRefid(r);
  931. }
  932. public Run(Project project) {
  933. super();
  934. //this.project = Ajctest.this.project;
  935. this.setTaskName("ajcjava");
  936. this.project = project;
  937. }
  938. public String msgs = "";
  939. public int executeJava() {
  940. Path cp = Ajctest.this.classpath != null ? Ajctest.this.classpath :
  941. new Path(this.project, destdir.getAbsolutePath());
  942. cp.append(Path.systemClasspath);
  943. this.setClasspath(cp);
  944. if (bootclasspath != null) {
  945. setFork(true);
  946. createJvmarg().setValue("-Xbootclasspath:" + bootclasspath);
  947. }
  948. if (bootclasspatha != null) {
  949. setFork(true);
  950. createJvmarg().setValue("-Xbootclasspath/a:" + bootclasspatha);
  951. }
  952. if (bootclasspathp != null) {
  953. setFork(true);
  954. createJvmarg().setValue("-Xbootclasspath/p:" + bootclasspathp);
  955. }
  956. int exit = -1;
  957. // todo: add timeout feature todo: this or below?
  958. try {
  959. exit = super.executeJava();
  960. } catch (Throwable t) {
  961. StringWriter sw = new StringWriter();
  962. PrintWriter out = new PrintWriter(sw);
  963. t.printStackTrace(out);
  964. msgs = sw.toString();
  965. out.close();
  966. // todo: return exit code
  967. }
  968. return exit;
  969. }
  970. public String _classname;
  971. public String classname() { return _classname; }
  972. public void setClassname(String classname) {
  973. super.setClassname(_classname = classname);
  974. }
  975. public String toString() { return _classname; }
  976. }
  977. // class Run
  978. // todo: need to run in a wrapper which report non-zero int on exception
  979. // todo: unused method? see executeJava above.
  980. // private int java(String classname, Collection args) throws BuildException {
  981. // Java java = (Java)project.createTask("java");
  982. // java.setClassname(classname);
  983. // for (Iterator i = args.iterator(); i.hasNext();) {
  984. // Object o = i.next();
  985. // Commandline.Argument arg = java.createArg();
  986. // if (o instanceof File) {
  987. // arg.setFile((File)o);
  988. // } else if (o instanceof Path) {
  989. // arg.setPath((Path)o);
  990. // } else {
  991. // arg.setValue(o+"");
  992. // }
  993. // }
  994. // return java.executeJava();
  995. // }
  996. private static List allErrors = new Vector();
  997. private List<Failure> errors = new Vector<>();
  998. private void post(Testset testset, List args,
  999. String msgs, int exit, String type) {
  1000. errors.add(new Failure(testset, args, msgs, exit, type, testId));
  1001. fire(type + ".fail");
  1002. }
  1003. private static long startTime;
  1004. private static long stopTime;
  1005. private static String date(long time) {
  1006. return DateFormat.getDateTimeInstance
  1007. (DateFormat.FULL, DateFormat.FULL).
  1008. format(new Date(time));
  1009. }
  1010. static {
  1011. final PrintStream err = System.err;
  1012. startTime = System.currentTimeMillis();
  1013. Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
  1014. private String ms(long start, long stop) {
  1015. long rest = Math.abs(stop-start) / 1000;
  1016. long days = rest / 86400;
  1017. long hours = (rest -= days*86400) / 3600;
  1018. long mins = (rest -= hours*3600) / 60;
  1019. long secs = (rest -= mins*60);
  1020. boolean req = false;
  1021. String str = "";
  1022. if (req || days > 0) {
  1023. req = true;
  1024. str += days + " day" + (days != 1 ? "s" : "") + " ";
  1025. }
  1026. if (req || hours > 0) {
  1027. req = true;
  1028. str += hours + " hour" + (hours != 1 ? "s" : "") + " ";
  1029. }
  1030. if (req || mins > 0) {
  1031. req = true;
  1032. str += mins + " minute" + (mins != 1 ? "s" : "") + " ";
  1033. }
  1034. str += secs + " second" + (secs != 1 ? "s" : "") + " ";
  1035. return str;
  1036. }
  1037. public void run() {
  1038. Ajctest current = CURRENT_AJCTEST;
  1039. String oneLine = "warning: oneLine not set.";
  1040. String multiLine = "warning: multiLine not set.";
  1041. // setup oneLine
  1042. if (null == current) {
  1043. oneLine = "\nRESULT=\"ERROR\" null ACJTEST";
  1044. } else {
  1045. StringBuffer sb = new StringBuffer("\n");
  1046. int errs = Ajctest.allErrors.size();
  1047. int allFails = errs
  1048. + current.ajdocStats.fails
  1049. + current.ajcStats.fails
  1050. + current.runStats.fails;
  1051. if (1 > allFails) {
  1052. sb.append("RESULT=\"PASS\"\terrors=\"");
  1053. } else {
  1054. sb.append("RESULT=\"FAIL\"\terrors=\"");
  1055. }
  1056. sb.append(""+errs);
  1057. sb.append("\"\tajdoc.pass=\"");
  1058. sb.append(""+current.ajdocStats.goods);
  1059. sb.append("\"\tajdoc.fail=\"");
  1060. sb.append(""+current.ajdocStats.fails);
  1061. sb.append("\"\tajc.pass=\"");
  1062. sb.append(""+current.ajcStats.goods);
  1063. sb.append("\"\tajc.fail=\"");
  1064. sb.append(""+current.ajcStats.fails);
  1065. sb.append("\"\trun.pass=\"");
  1066. sb.append(""+current.runStats.goods);
  1067. sb.append("\"\trun.fail=\"");
  1068. sb.append(""+current.runStats.fails);
  1069. sb.append("\"\ttestId=\"");
  1070. sb.append(current.testId);
  1071. sb.append("\"\tproject=\"");
  1072. Project p = current.getProject();
  1073. if (null != p) sb.append(p.getName());
  1074. sb.append("\"\tfile=\"");
  1075. sb.append(""+current.getLocation());
  1076. sb.append("\"");
  1077. oneLine = sb.toString();
  1078. }
  1079. // setup multiLine
  1080. {
  1081. stopTime = System.currentTimeMillis();
  1082. String str = "";
  1083. str += "\n";
  1084. str +=
  1085. "===================================" +
  1086. "===================================" + "\n";
  1087. str += "Test started : " + date(startTime) + "\n";
  1088. str += "Test ended : " + date(stopTime) + "\n";
  1089. str += "Total time : " + ms(startTime, stopTime) + "\n";
  1090. str +=
  1091. "------------------------------" +
  1092. " Summary " +
  1093. "------------------------------" + "\n";
  1094. str += "Task\tPassed\tFailed" + "\n";
  1095. Object[] os = new Object[] {
  1096. "ajdoc", current.ajdocStats.goods+"", current.ajdocStats.fails+"",
  1097. "ajc", current.ajcStats.goods +"", current.ajcStats.fails +"",
  1098. "run", current.runStats.goods +"", current.runStats.fails +"",
  1099. };
  1100. for (int i = 0; i < os.length; i += 3) {
  1101. str += os[i] + "\t" + os[i+1] + "\t" + os[i+2] + "\n";
  1102. }
  1103. if (allErrors.size() > 0) {
  1104. str += "" + "\n";
  1105. str +=
  1106. "There " + w(allErrors) + " " +
  1107. allErrors.size() + " error" +
  1108. s(allErrors) + ":" + "\n";
  1109. for (int i = 0; i < allErrors.size(); i++) {
  1110. Failure failure = (Failure)allErrors.get(i);
  1111. str +=
  1112. "---------- Error " + i + " [" +
  1113. failure.testId + "]" +
  1114. " ------------------------------" + "\n";
  1115. str += " " + failure + "\n\n";
  1116. }
  1117. } else {
  1118. str += "No errors." + "\n";
  1119. }
  1120. str += "--------------------------" +
  1121. " End of Summary " +
  1122. "---------------------------" + "\n";
  1123. multiLine = str;
  1124. }
  1125. // print both multiLine and oneLine
  1126. err.println(multiLine);
  1127. err.println(oneLine);
  1128. if (dumpresults && (allErrors.size() +
  1129. current.ajdocStats.fails +
  1130. current.ajcStats.fails +
  1131. current.runStats.fails) > 0) {
  1132. String date = date(System.currentTimeMillis());
  1133. String filename = "ajc-errors";
  1134. for (StringTokenizer t = new StringTokenizer(date, ",: ");
  1135. t.hasMoreTokens();) {
  1136. filename += "-" + t.nextToken().trim();
  1137. }
  1138. filename += ".txt";
  1139. PrintWriter out = null;
  1140. File file = new File(filename);
  1141. System.err.println("dumping results to " + file);
  1142. try {
  1143. out = new PrintWriter(new FileWriter(file));
  1144. out.println(multiLine);
  1145. out.println(oneLine);
  1146. System.err.println("dumped results to " + file);
  1147. } catch (IOException ioe) {
  1148. if (out != null) out.close();
  1149. }
  1150. }
  1151. }
  1152. }));
  1153. }
  1154. private static String w(List list) { return a(list, "were", "was"); }
  1155. private static String s(List list) { return a(list, "s", ""); }
  1156. private static String a(List list, String some, String one) {
  1157. return list == null || list.size() != 1 ? some : one;
  1158. }
  1159. static class Failure {
  1160. public final Testset testset;
  1161. public final List args;
  1162. public final String msgs;
  1163. public final int exit;
  1164. public final String type;
  1165. public final long time;
  1166. public final String testId;
  1167. public Failure(Testset testset, List args,
  1168. String msgs, int exit, String type,
  1169. String testId) {
  1170. this.testset = testset;
  1171. this.args = args;
  1172. this.msgs = msgs;
  1173. this.exit = exit;
  1174. this.type = type;
  1175. this.time = System.currentTimeMillis();
  1176. this.testId = testId;
  1177. }
  1178. public String toString() {
  1179. String str = "testId:" + testId+ "\n";
  1180. str += "type:" + type + "\n";
  1181. str += testset + "\n";
  1182. if (args.size() > 0) {
  1183. str += " args: " + args + "\n";;
  1184. }
  1185. str += " msgs:" + msgs + "\n";
  1186. str += " exit:" + exit;
  1187. return str;
  1188. }
  1189. }
  1190. private List<List<Arg>> argcombo(List<Argument> arguments) {
  1191. List<Argument> combos = new Vector<>();
  1192. List<Arg> always = new Vector<>();
  1193. for (Iterator<Argument> iter = arguments.iterator(); iter.hasNext();) {
  1194. Argument arg = iter.next();
  1195. if (arg.values.size() == 0) arg.values.add("");
  1196. if (!arg.always && !arg.values.contains(null)) arg.values.add(null);
  1197. if (arg.values.size() > 0) {
  1198. combos.add(arg);
  1199. } else if (arg.always) {
  1200. always.add(new Arg(arg.name, arg.values.get(0)+"", arg.isj));
  1201. }
  1202. }
  1203. List<List<Arg>> argcombo = combinations(combos);
  1204. for (Iterator<Arg> iter = always.iterator(); iter.hasNext();) {
  1205. Arg arg = iter.next();
  1206. for (Iterator<List<Arg>> comboiter = argcombo.iterator(); comboiter.hasNext();) {
  1207. comboiter.next().add(arg);
  1208. }
  1209. }
  1210. return argcombo;
  1211. }
  1212. private abstract class ExecWrapper {
  1213. public String msgs;
  1214. public int run() {
  1215. return run(createCommandline());
  1216. }
  1217. protected abstract Commandline createCommandline();
  1218. protected final int run(Commandline cmd) {
  1219. Process process = null;
  1220. int exit = Integer.MIN_VALUE;
  1221. final StringBuffer buf = new StringBuffer();
  1222. Thread errPumper = null;
  1223. Thread outPumper = null;
  1224. try {
  1225. log("\tcalling " + cmd, Project.MSG_VERBOSE);
  1226. process = Runtime.getRuntime().exec(cmd.getCommandline());
  1227. OutputStream os = new OutputStream() {
  1228. StringBuffer sb = new StringBuffer();
  1229. public void write(int b) throws IOException {
  1230. final char c = (char)b;
  1231. buf.append(c);
  1232. if (c != '\n') {
  1233. sb.append(c);
  1234. } else {
  1235. System.err.println(sb.toString());
  1236. sb = new StringBuffer();
  1237. }
  1238. }
  1239. };
  1240. OutputStream los = new LogOutputStream(Ajctest.this,
  1241. Project.MSG_INFO);
  1242. outPumper = new Thread(new StreamPumper(process.getInputStream(),
  1243. los));
  1244. errPumper = new Thread(new StreamPumper(process.getErrorStream(),
  1245. os));
  1246. outPumper.setDaemon(true);
  1247. errPumper.setDaemon(true);
  1248. outPumper.start();
  1249. errPumper.start();
  1250. process.waitFor();
  1251. } catch (Exception e) {
  1252. e.printStackTrace();
  1253. //throw e;
  1254. } finally {
  1255. try {
  1256. if (outPumper != null) outPumper.join();
  1257. if (errPumper != null) errPumper.join();
  1258. } catch (InterruptedException ie) {
  1259. } finally {
  1260. outPumper = null;
  1261. errPumper = null;
  1262. }
  1263. exit = process.exitValue();
  1264. msgs = buf.toString();
  1265. if (exit != 0) {
  1266. log("Test failed with exit value: " + exit);
  1267. } else {
  1268. log("Success!", Project.MSG_VERBOSE);
  1269. }
  1270. if (process != null) process.destroy();
  1271. process = null;
  1272. System.err.flush();
  1273. System.out.flush();
  1274. }
  1275. return exit;
  1276. }
  1277. }
  1278. private class AjcWrapper extends JavaCommandWrapper {
  1279. public AjcWrapper(Testset testset, List args) {
  1280. super(testset, args, false);
  1281. if (testset.noclean) {
  1282. setExtraclasspath(new Path(project,
  1283. destdir.getAbsolutePath()));
  1284. }
  1285. }
  1286. String getMainClassName() {
  1287. return "org.aspectj.tools.ajc.Main";
  1288. }
  1289. }
  1290. private class EAjcWrapper extends JavaCommandWrapper {
  1291. public EAjcWrapper(Testset testset, List args) {
  1292. super(testset, args, false);
  1293. if (testset.noclean) {
  1294. setExtraclasspath(new Path(project,
  1295. destdir.getAbsolutePath()));
  1296. }
  1297. }
  1298. String getMainClassName() {
  1299. return "org.aspectj.ajdt.ajc.Main";
  1300. }
  1301. }
  1302. static List ajdocArgs(List args) {
  1303. List newargs = new Vector();
  1304. for (Iterator i = args.iterator(); i.hasNext();) {
  1305. String arg = i.next() + "";
  1306. if (arg.startsWith("-X")) {
  1307. newargs.add(arg);
  1308. } else if (arg.equals("-public") ||
  1309. arg.equals("-package") ||
  1310. arg.equals("-protected") ||
  1311. arg.equals("-private")) {
  1312. newargs.add(arg);
  1313. } else if (arg.equals("-d") ||
  1314. arg.equals("-classpath") ||
  1315. arg.equals("-cp") ||
  1316. arg.equals("-sourcepath") ||
  1317. arg.equals("-bootclasspath") ||
  1318. arg.equals("-argfile")) {
  1319. newargs.add(arg);
  1320. newargs.add(i.next()+"");
  1321. } else if (arg.startsWith("@")) {
  1322. newargs.add(arg);
  1323. }
  1324. }
  1325. return newargs;
  1326. }
  1327. private class AjdocWrapper extends JavaCommandWrapper {
  1328. public AjdocWrapper(Testset testset, List args) {
  1329. super(testset, ajdocArgs(args), true);
  1330. String[] cmds = testset.getAjdoc().getCommandline().getCommandline();
  1331. for (int i = 0; i < cmds.length; i++) {
  1332. this.args.add(cmds[i]);
  1333. }
  1334. }
  1335. String getMainClassName() {
  1336. return "org.aspectj.tools.ajdoc.Main";
  1337. }
  1338. }
  1339. private abstract class JavaCommandWrapper extends ExecWrapper {
  1340. abstract String getMainClassName();
  1341. protected Testset testset;
  1342. protected List args;
  1343. protected boolean needsClasspath;
  1344. protected Path extraClasspath;
  1345. public JavaCommandWrapper(Testset testset, List args,
  1346. boolean needsClasspath) {
  1347. this.testset = testset;
  1348. this.args = args;
  1349. this.needsClasspath = needsClasspath;
  1350. this.extraClasspath = testset.internalclasspath;
  1351. }
  1352. public void setExtraclasspath(Path extraClasspath) {
  1353. this.extraClasspath = extraClasspath;
  1354. }
  1355. public String toString() {
  1356. return LangUtil.unqualifiedClassName(getClass())
  1357. + "(" + getMainClassName() + ")";
  1358. }
  1359. protected Commandline createCommandline() {
  1360. Commandline cmd = new Commandline();
  1361. cmd.setExecutable("java");
  1362. cmd.createArgument().setValue("-classpath");
  1363. Path cp = null;
  1364. if (extraClasspath != null) {
  1365. cp = extraClasspath;
  1366. }
  1367. if (extraClasspath == null) {
  1368. Path aspectjBuildDir =
  1369. new Path(project,
  1370. project.getProperty("ajctest.pathelement"));
  1371. // todo: dependency on ant script variable name ajctest.pathelement
  1372. if (cp == null) cp = aspectjBuildDir;
  1373. else cp.append(aspectjBuildDir);
  1374. }
  1375. if (cp == null) {
  1376. cp = Path.systemClasspath;
  1377. } else {
  1378. cp.append(Path.systemClasspath);
  1379. }
  1380. cmd.createArgument().setPath(cp);
  1381. for (Iterator iter = args.iterator(); iter.hasNext();) {
  1382. Arg arg = (Arg)iter.next();
  1383. if (arg.isj) {
  1384. cmd.createArgument().setValue(arg.name);
  1385. if (!arg.value.equals("")) {
  1386. cmd.createArgument().setValue(arg.value);
  1387. }
  1388. }
  1389. }
  1390. cmd.createArgument().setValue(getMainClassName());
  1391. boolean alreadySetDestDir = false;
  1392. boolean alreadySetClasspath = false;
  1393. for (Iterator iter = args.iterator(); iter.hasNext();) {
  1394. Arg arg = (Arg)iter.next();
  1395. if (!arg.isj) {
  1396. cmd.createArgument().setValue(arg.name);
  1397. if (arg.name.equals("-d")) {
  1398. setDestdir(arg.value+"");
  1399. alreadySetDestDir = true;
  1400. }
  1401. if (arg.name.equals("-classpath")) {
  1402. alreadySetClasspath = true;
  1403. }
  1404. if (!arg.value.equals("")) {
  1405. cmd.createArgument().setValue(arg.value);
  1406. }
  1407. }
  1408. }
  1409. if (destdir == null) {
  1410. setDestdir(".");
  1411. }
  1412. if (!alreadySetDestDir) {
  1413. cmd.createArgument().setValue("-d");
  1414. cmd.createArgument().setFile(destdir);
  1415. }
  1416. if (!alreadySetClasspath && testset.classpath != null) {
  1417. cmd.createArgument().setValue("-classpath");
  1418. cmd.createArgument().setPath(testset.classpath);
  1419. } else if (needsClasspath) {
  1420. Path _cp = Ajctest.this.classpath != null ? Ajctest.this.classpath :
  1421. new Path(project, destdir.getAbsolutePath());
  1422. _cp.append(Path.systemClasspath);
  1423. cmd.createArgument().setValue("-classpath");
  1424. cmd.createArgument().setPath(_cp);
  1425. }
  1426. for (Iterator iter = testset.files.iterator(); iter.hasNext();) {
  1427. cmd.createArgument().setFile((File)iter.next());
  1428. }
  1429. for (Iterator iter = testset.argfiles.iterator(); iter.hasNext();) {
  1430. cmd.createArgument().setValue("-argfile");
  1431. cmd.createArgument().setFile((File)iter.next());
  1432. }
  1433. return cmd;
  1434. }
  1435. }
  1436. /** implement invocation of ajc */
  1437. // private void java(Testset testset, List args) throws BuildException {
  1438. // Java java = (Java)project.createTask("java");
  1439. // java.setClassname("org.aspectj.tools.ajc.Main");
  1440. // if (classpath != null) {
  1441. // java.setClasspath(classpath);
  1442. // }
  1443. // for (Iterator iter = args.iterator(); iter.hasNext();) {
  1444. // Arg arg = (Arg)iter.next();
  1445. // if (arg.isj) {
  1446. // java.createJvmarg().setValue(arg.name);
  1447. // if (!arg.value.equals("")) {
  1448. // java.createJvmarg().setValue(arg.value);
  1449. // }
  1450. // }
  1451. // }
  1452. // for (Iterator iter = args.iterator(); iter.hasNext();) {
  1453. // Arg arg = (Arg)iter.next();
  1454. // if (!arg.isj) {
  1455. // java.createArg().setValue(arg.name);
  1456. // if (!arg.value.equals("")) {
  1457. // java.createArg().setValue(arg.value);
  1458. // }
  1459. // }
  1460. // }
  1461. // for (Iterator iter = testset.files.iterator(); iter.hasNext();) {
  1462. // java.createArg().setFile((File)iter.next());
  1463. // }
  1464. // for (Iterator iter = testset.argfiles.iterator(); iter.hasNext();) {
  1465. // java.createArg().setValue("-argfile");
  1466. // java.createArg().setFile((File)iter.next());
  1467. // }
  1468. // java.setFork(true);
  1469. // java.execute();
  1470. // }
  1471. //
  1472. // private void exec(Testset testset, List args) throws BuildException {
  1473. // ExecTask exec = (ExecTask)project.createTask("exec");
  1474. // exec.setExecutable("java");
  1475. // if (classpath != null) {
  1476. // exec.createArg().setValue("-classpath");
  1477. // exec.createArg().setPath(classpath);
  1478. // }
  1479. // for (Iterator iter = args.iterator(); iter.hasNext();) {
  1480. // Arg arg = (Arg)iter.next();
  1481. // if (arg.isj) {
  1482. // exec.createArg().setValue(arg.name);
  1483. // if (!arg.value.equals("")) {
  1484. // exec.createArg().setValue(arg.value);
  1485. // }
  1486. // }
  1487. // }
  1488. // exec.createArg().setValue("org.aspectj.tools.ajc.Main");
  1489. // for (Iterator iter = args.iterator(); iter.hasNext();) {
  1490. // Arg arg = (Arg)iter.next();
  1491. // if (!arg.isj) {
  1492. // exec.createArg().setValue(arg.name);
  1493. // if (!arg.value.equals("")) {
  1494. // exec.createArg().setValue(arg.value);
  1495. // }
  1496. // }
  1497. // }
  1498. // for (Iterator iter = testset.files.iterator(); iter.hasNext();) {
  1499. // exec.createArg().setFile((File)iter.next());
  1500. // }
  1501. // for (Iterator iter = testset.argfiles.iterator(); iter.hasNext();) {
  1502. // exec.createArg().setValue("-argfile");
  1503. // exec.createArg().setFile((File)iter.next());
  1504. // }
  1505. // exec.execute();
  1506. // }
  1507. //
  1508. public void handle(Throwable t) {
  1509. log("handling " + t);
  1510. if (t != null) t.printStackTrace();
  1511. log("done handling " + t);
  1512. }
  1513. private List<List<Arg>> combinations(List<Argument> arglist) {
  1514. List<List<Arg>> result = new Vector<>();
  1515. result.add(new Vector<Arg>());
  1516. for (Iterator<Argument> iter = arglist.iterator(); iter.hasNext();) {
  1517. Argument arg = iter.next();
  1518. int N = result.size();
  1519. for (int i = 0; i < N; i++) {
  1520. List<Arg> to = result.remove(0);
  1521. for (Iterator<String> valiter = arg.values.iterator(); valiter.hasNext();) {
  1522. List<Arg> newlist = new Vector<>(to);
  1523. Object val = valiter.next();
  1524. if (val != null) newlist.add(new Arg(arg.name, val+"", arg.isj));
  1525. result.add(newlist);
  1526. }
  1527. }
  1528. }
  1529. return result;
  1530. }
  1531. /////////////////////// GUI support //////////////////////////////
  1532. private static Gui gui;
  1533. private static void gui(Ajctest ajc) {
  1534. if (firstTime && ajc.isSet("gui")) {
  1535. JFrame f = new JFrame("AspectJ Test Suite");
  1536. f.getContentPane().add(BorderLayout.CENTER, gui = new Gui());
  1537. f.pack();
  1538. f.setVisible(true);
  1539. }
  1540. if (gui != null) {
  1541. ajc.bean.addPropertyChangeListener(gui);
  1542. }
  1543. firstTime = false;
  1544. }
  1545. private static class Gui extends JPanel implements PropertyChangeListener {
  1546. private FailurePanel fail = new FailurePanel();
  1547. private TablePanel table = new TablePanel();
  1548. private StatusPanel status = new StatusPanel();
  1549. public Gui() {
  1550. super(new BorderLayout());
  1551. JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
  1552. split.setPreferredSize(new Dimension(500, 300));
  1553. split.add(JSplitPane.BOTTOM, fail);
  1554. split.add(JSplitPane.TOP, table);
  1555. split.setDividerLocation(200);
  1556. add(BorderLayout.CENTER, split);
  1557. add(BorderLayout.SOUTH, status);
  1558. setPreferredSize(new Dimension(640, 680));
  1559. }
  1560. public void propertyChange(PropertyChangeEvent evt) {
  1561. String name = evt.getPropertyName();
  1562. if ("ajdoc.good".equals(name)) {
  1563. status.ajc.goods.inc();
  1564. } else if ("ajc.good".equals(name)) {
  1565. status.ajc.goods.inc();
  1566. } else if ("run.good".equals(name)) {
  1567. status.runs.goods.inc();
  1568. }
  1569. if ("ajdoc.done".equals(name)) {
  1570. status.ajc.total.inc();
  1571. } else if ("ajc.done".equals(name)) {
  1572. status.ajc.total.inc();
  1573. } else if ("run.done".equals(name)) {
  1574. status.runs.total.inc();
  1575. }
  1576. if ("ajdoc.fail".equals(name)) {
  1577. status.ajc.fails.inc();
  1578. } else if ("ajc.fail".equals(name)) {
  1579. status.ajc.fails.inc();
  1580. } else if ("run.fail".equals(name)) {
  1581. status.runs.fails.inc();
  1582. }
  1583. }
  1584. private abstract static class TitledPanel extends JPanel {
  1585. public TitledPanel(LayoutManager layout, String title) {
  1586. super(layout);
  1587. setBorder(BorderFactory.createTitledBorder(title));
  1588. }
  1589. }
  1590. private static class StatusPanel extends TitledPanel {
  1591. StatusInnerPanel ajdoc = new StatusInnerPanel("Ajdoc");
  1592. StatusInnerPanel runs = new StatusInnerPanel("Runs");
  1593. StatusInnerPanel ajc = new StatusInnerPanel("Ajc");
  1594. public StatusPanel() {
  1595. super(new FlowLayout(), "Status");
  1596. add(ajdoc);
  1597. add(runs);
  1598. add(ajc);
  1599. }
  1600. private static class StatusInnerPanel extends TitledPanel {
  1601. IntField goods = new IntField(5, Color.green.darker());
  1602. IntField fails = new IntField(5, Color.red.darker());
  1603. IntField total = new IntField(5, Color.blue.darker());
  1604. public StatusInnerPanel(String str) {
  1605. super(null, str);
  1606. this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
  1607. Object[] os = new Object[] {
  1608. "Passed", goods,
  1609. "Failed", fails,
  1610. "Totals", total,
  1611. };
  1612. for (int i = 0; i < os.length; i += 2) {
  1613. JPanel p = p();
  1614. p.add(new JLabel(os[i]+":"));
  1615. p.add((Component)os[i+1]);
  1616. this.add(p);
  1617. }
  1618. }
  1619. private JPanel p() {
  1620. JPanel p = new JPanel();
  1621. p.setLayout(new FlowLayout(FlowLayout.LEFT));
  1622. return p;
  1623. }
  1624. private class IntField extends JTextField {
  1625. public IntField(int i, Color fg) {
  1626. super("0", i);
  1627. this.setBackground(StatusInnerPanel.this.getBackground());
  1628. this.setForeground(fg);
  1629. this.setEditable(false);
  1630. this.setBorder(BorderFactory.createEmptyBorder());
  1631. }
  1632. public void add(int i) {
  1633. setText((Integer.parseInt(getText().trim())+i)+"");
  1634. }
  1635. public void inc() { add(1); }
  1636. }
  1637. }
  1638. }
  1639. private class TablePanel extends TitledPanel {
  1640. private DefaultTableModel model = new DefaultTableModel();
  1641. private TJable table;
  1642. private List failures = new Vector();
  1643. public TablePanel() {
  1644. super(new BorderLayout(), "Failures");
  1645. Object[] names = new String[] {
  1646. "Task", "Type", "Number", "Time"
  1647. };
  1648. for (int i = 0; i < names.length; i++) {
  1649. model.addColumn(names[i]);
  1650. }
  1651. table = new TJable(model, failures);
  1652. this.add(new JScrollPane(table), BorderLayout.CENTER);
  1653. }
  1654. private class TJable extends JTable {
  1655. private List list;
  1656. public TJable(TableModel model, List list) {
  1657. super(model);
  1658. this.list = list;
  1659. setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  1660. }
  1661. public void valueChanged(ListSelectionEvent e) {
  1662. super.valueChanged(e);
  1663. if (list == null) return;
  1664. int i = (e.getFirstIndex()-e.getLastIndex())/2;
  1665. if (list.size() > 0) {
  1666. Failure f = (Failure)list.get(i);
  1667. fail.setFailure(f);
  1668. }
  1669. }
  1670. }
  1671. public void add(Failure f, String taskname, String type,
  1672. int num, long time) {
  1673. model.addRow(new Object[]{taskname, type,
  1674. new Integer(num), date(time)});
  1675. failures.add(f);
  1676. }
  1677. }
  1678. private static class FailurePanel extends TitledPanel {
  1679. private JTextArea msgs = new JTextArea(10,50);
  1680. private InfoPanel info = new InfoPanel();
  1681. public FailurePanel() {
  1682. super(new BorderLayout(), "Failure");
  1683. msgs.setFont(StyleContext.getDefaultStyleContext().
  1684. getFont("SansSerif", Font.PLAIN, 10));
  1685. add(BorderLayout.NORTH, info);
  1686. JScrollPane sc = new JScrollPane(msgs);
  1687. sc.setBorder(BorderFactory.createTitledBorder("Messages"));
  1688. add(BorderLayout.CENTER, sc);
  1689. }
  1690. public void setText(String str) {
  1691. msgs.setText(str);
  1692. }
  1693. public void setFailure(Failure f) {
  1694. msgs.setText(f.msgs);
  1695. info.setText("Type" , f.type);
  1696. info.setText("Args" , f.args);
  1697. info.setText("Exit" , f.exit+"");
  1698. info.setText("Time" , date(f.time));
  1699. info.setText("Files" , f.testset.files);
  1700. info.setText("Classnames" , f.testset.testclasses);
  1701. }
  1702. private static class InfoPanel extends JPanel {
  1703. Map fields = new HashMap();
  1704. public void setText(String key, Object str) {
  1705. ((JTextField)fields.get(key)).setText(str+"");
  1706. }
  1707. public InfoPanel() {
  1708. super(new GridBagLayout());
  1709. LabelFieldGBC gbc = new LabelFieldGBC();
  1710. Object[] os = new Object[] {
  1711. "Type",
  1712. "Args",
  1713. "Exit",
  1714. "Time",
  1715. "Files",
  1716. "Classnames",
  1717. };
  1718. for (int i = 0; i < os.length; i++) {
  1719. String name = os[i]+"";
  1720. JLabel label = new JLabel(name+":");
  1721. JTextField comp = new JTextField(25);
  1722. comp.setEditable(false);
  1723. comp.setBackground(Color.white);
  1724. comp.setBorder(BorderFactory.
  1725. createBevelBorder(BevelBorder.LOWERED));
  1726. label.setLabelFor(comp);
  1727. fields.put(name, comp);
  1728. add(label, gbc.forLabel());
  1729. add(comp, gbc.forField());
  1730. }
  1731. add(new JLabel(), gbc.forLastLabel());
  1732. }
  1733. }
  1734. private static class LabelFieldGBC extends GridBagConstraints {
  1735. public LabelFieldGBC() {
  1736. insets = new Insets(1,3,1,3);
  1737. gridy = RELATIVE;
  1738. gridheight = 1;
  1739. gridwidth = 1;
  1740. }
  1741. public LabelFieldGBC forLabel() {
  1742. fill = NONE;
  1743. gridx = 0;
  1744. anchor = NORTHEAST;
  1745. weightx = 0.0;
  1746. return this;
  1747. }
  1748. public LabelFieldGBC forLastLabel() {
  1749. forLabel();
  1750. fill = VERTICAL;
  1751. weighty = 1.0;
  1752. return this;
  1753. }
  1754. public LabelFieldGBC forField() {
  1755. fill = HORIZONTAL;
  1756. gridx = 1;
  1757. anchor = CENTER;
  1758. weightx = 1.0;
  1759. return this;
  1760. }
  1761. public LabelFieldGBC forLastField() {
  1762. forField();
  1763. fill = BOTH;
  1764. weighty = 1.0;
  1765. return this;
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }