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.

AjdocTestCase.java 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /********************************************************************
  2. * Copyright (c) 2005 Contributors. All rights reserved.
  3. * This program and the accompanying materials are made available
  4. * under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution and is available at
  6. * http://eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: IBM Corporation - initial API and implementation
  9. * Helen Hawkins - iniital version
  10. *******************************************************************/
  11. package org.aspectj.tools.ajdoc;
  12. import java.io.File;
  13. import java.io.IOException;
  14. import java.util.Iterator;
  15. import java.util.List;
  16. import junit.framework.AssertionFailedError;
  17. import junit.framework.TestCase;
  18. import org.aspectj.tools.ajc.Ajc;
  19. /**
  20. * This class is the super class of all Ajdoc tests. It creates
  21. * a sandbox directory and provides utility methods for
  22. * copying over the test projects and running the ajdoc command
  23. */
  24. public class AjdocTestCase extends TestCase{
  25. public final static String testdataSrcDir = "../ajdoc/testdata";
  26. protected static File sandboxDir;
  27. private String docOutdir, projectDir;
  28. protected void setUp() throws Exception {
  29. super.setUp();
  30. docOutdir = null;
  31. projectDir = null;
  32. // Create a sandbox in which to work
  33. sandboxDir = Ajc.createEmptySandbox();
  34. // create the ajdocworkdingdir in the sandbox
  35. Main.setOutputWorkingDir(getWorkingDir().getAbsolutePath());
  36. }
  37. protected void tearDown() throws Exception {
  38. super.tearDown();
  39. // reset where ajdocworkingdir is created
  40. Main.resetOutputWorkingDir();
  41. }
  42. /**
  43. * Fill in the working directory with the project files and
  44. * create a doc top level directory in which to generate
  45. * the ajdoc output.
  46. */
  47. public void initialiseProject(String projectName) {
  48. File projectSrc=new File(testdataSrcDir + File.separatorChar + projectName);
  49. File destination=new File(getWorkingDir(),projectName);
  50. if (!destination.exists()) {destination.mkdir();}
  51. copy(projectSrc,destination);
  52. projectDir = destination.getAbsolutePath();
  53. File docDestination = new File(getWorkingDir().toString() + File.separatorChar + projectName,"doc");
  54. if (!docDestination.exists()) {docDestination.mkdir();}
  55. docOutdir = docDestination.getAbsolutePath();
  56. }
  57. /**
  58. * @return the working directory
  59. */
  60. protected File getWorkingDir() {
  61. return sandboxDir;
  62. }
  63. /**
  64. * @return the absolute path of the project directory
  65. * for example c:\temp\ajcSandbox\ajcTest15200.tmp\myProject
  66. */
  67. protected String getAbsoluteProjectDir() {
  68. return projectDir;
  69. }
  70. /**
  71. * @return the absolute path of the doc output directory
  72. * for example c:\temp\ajcSandbox\ajcTest15200.tmp\myProject\doc
  73. */
  74. protected String getAbsolutePathOutdir() {
  75. return docOutdir;
  76. }
  77. /**
  78. * Copy the contents of some directory to another location - the
  79. * copy is recursive.
  80. */
  81. private void copy(File from, File to) {
  82. String contents[] = from.list();
  83. if (contents==null) return;
  84. for (int i = 0; i < contents.length; i++) {
  85. String string = contents[i];
  86. File f = new File(from,string);
  87. File t = new File(to,string);
  88. if (f.isDirectory()) {
  89. t.mkdir();
  90. copy(f,t);
  91. } else if (f.isFile()) {
  92. try {
  93. org.aspectj.util.FileUtil.copyFile(f,t);
  94. } catch (IOException e) {
  95. throw new AssertionFailedError("Unable to copy " + f + " to " + t);
  96. }
  97. }
  98. }
  99. }
  100. /**
  101. * Run the ajdoc command with the given visibility argument,
  102. * the default source level and the given input files.
  103. */
  104. public void runAjdoc(String visibility, File[] inputFiles) {
  105. if (!visibility.equals("public")
  106. && !visibility.equals("protected")
  107. && !visibility.equals("private")) {
  108. fail("need to pass 'public','protected' or 'private' visibility to ajdoc");
  109. }
  110. if (inputFiles.length == 0) {
  111. fail("need to pass some files into ajdoc");
  112. }
  113. String[] args = new String[5 + inputFiles.length];
  114. args[0] = "-" + visibility;
  115. args[1] = "-classpath";
  116. args[2] = AjdocTests.ASPECTJRT_PATH.getPath();
  117. args[3] = "-d";
  118. args[4] = getAbsolutePathOutdir();
  119. for (int i = 0; i < inputFiles.length; i++) {
  120. args[5+i] = inputFiles[i].getAbsolutePath();
  121. }
  122. org.aspectj.tools.ajdoc.Main.main(args);
  123. }
  124. /**
  125. * Run the ajdoc command with the default visibility
  126. * and source level and the given input files.
  127. */
  128. public void runAjdoc(File[] inputFiles) {
  129. if (inputFiles.length == 0) {
  130. fail("need to pass some files into ajdoc");
  131. }
  132. String[] args = new String[4 + inputFiles.length];
  133. args[0] = "-classpath";
  134. args[1] = AjdocTests.ASPECTJRT_PATH.getPath();
  135. args[2] = "-d";
  136. args[3] = getAbsolutePathOutdir();
  137. for (int i = 0; i < inputFiles.length; i++) {
  138. args[4+i] = inputFiles[i].getAbsolutePath();
  139. }
  140. org.aspectj.tools.ajdoc.Main.main(args);
  141. }
  142. /**
  143. * Run the ajdoc command with the default visibility
  144. * and source level, the given input files and the given
  145. * aspectj options
  146. */
  147. public void runAjdoc(File[] inputFiles, String sourceLevel, String[] ajOptions) {
  148. if (inputFiles.length == 0) {
  149. fail("need to pass some files into ajdoc");
  150. }
  151. if (!sourceLevel.equals("1.3")
  152. && !sourceLevel.equals("1.4")
  153. && !sourceLevel.equals("1.5")) {
  154. fail("need to pass ajdoc '1.3', '1.4', or '1.5' as the source level");
  155. }
  156. String[] args = new String[6 + inputFiles.length + ajOptions.length];
  157. args[0] = "-source";
  158. args[1] = sourceLevel;
  159. args[2] = "-classpath";
  160. args[3] = AjdocTests.ASPECTJRT_PATH.getPath();
  161. args[4] = "-d";
  162. args[5] = getAbsolutePathOutdir();
  163. for (int i = 0; i < ajOptions.length; i++) {
  164. args[6 + i] = ajOptions[i];
  165. }
  166. for (int i = 0; i < inputFiles.length; i++) {
  167. args[6 + i +ajOptions.length] = inputFiles[i].getAbsolutePath();
  168. }
  169. org.aspectj.tools.ajdoc.Main.main(args);
  170. }
  171. /**
  172. * Run the ajdoc command with the given visibility argument,
  173. * the given source level argument and the given input files.
  174. */
  175. public void runAjdoc(String visibility, String sourceLevel, File[] inputFiles) {
  176. if (!visibility.equals("public")
  177. && !visibility.equals("protected")
  178. && !visibility.equals("private")) {
  179. fail("need to pass 'public','protected' or 'private' visibility to ajdoc");
  180. }
  181. if (!sourceLevel.equals("1.3")
  182. && !sourceLevel.equals("1.4")
  183. && !sourceLevel.equals("1.5")) {
  184. fail("need to pass ajdoc '1.3', '1.4', or '1.5' as the source level");
  185. }
  186. if (inputFiles.length == 0) {
  187. fail("need to pass some files into ajdoc");
  188. }
  189. for (int i = 0; i < inputFiles.length; i++) {
  190. if (!inputFiles[i].exists()) {
  191. fail(inputFiles[i].getAbsolutePath() + " does not exist");
  192. }
  193. }
  194. String[] args = new String[7 + inputFiles.length];
  195. args[0] = "-" + visibility;
  196. args[1] = "-source";
  197. args[2] = sourceLevel;
  198. args[3] = "-classpath";
  199. args[4] = AjdocTests.ASPECTJRT_PATH.getPath();
  200. args[5] = "-d";
  201. args[6] = getAbsolutePathOutdir();
  202. for (int i = 0; i < inputFiles.length; i++) {
  203. args[7+i] = inputFiles[i].getAbsolutePath();
  204. }
  205. org.aspectj.tools.ajdoc.Main.main(args);
  206. }
  207. /**
  208. * Run the ajdoc command with the given visibility argument,
  209. * the default source level and the given input directories.
  210. */
  211. public void runAjdoc(String visibility, String[] directoryNames) {
  212. if (!visibility.equals("public")
  213. && !visibility.equals("protected")
  214. && !visibility.equals("private")) {
  215. fail("need to pass 'public','protected' or 'private' visibility to ajdoc");
  216. }
  217. if (directoryNames.length == 0) {
  218. fail("need to pass some directories into ajdoc");
  219. }
  220. String[] args = new String[7 + directoryNames.length];
  221. args[0] = "-" + visibility;
  222. args[1] = "-classpath";
  223. args[2] = AjdocTests.ASPECTJRT_PATH.getPath();
  224. args[3] = "-d";
  225. args[4] = getAbsolutePathOutdir();
  226. args[5] = "-sourcepath";
  227. args[6] = getAbsoluteProjectDir();
  228. for (int i = 0; i < directoryNames.length; i++) {
  229. args[7+i] = directoryNames[i];
  230. }
  231. org.aspectj.tools.ajdoc.Main.main(args);
  232. }
  233. /**
  234. * Run the ajdoc command with the default visibility and
  235. * source level and the given input directories.
  236. */
  237. public void runAjdoc(String[] directoryNames) {
  238. if (directoryNames.length == 0) {
  239. fail("need to pass some directories into ajdoc");
  240. }
  241. String[] args = new String[6 + directoryNames.length];
  242. args[0] = "-classpath";
  243. args[1] = AjdocTests.ASPECTJRT_PATH.getPath();
  244. args[2] = "-d";
  245. args[3] = getAbsolutePathOutdir();
  246. args[4] = "-sourcepath";
  247. args[5] = getAbsoluteProjectDir();
  248. for (int i = 0; i < directoryNames.length; i++) {
  249. args[6+i] = directoryNames[i];
  250. }
  251. org.aspectj.tools.ajdoc.Main.main(args);
  252. }
  253. /**
  254. * Run the ajdoc command with the given visibility argument,
  255. * the default source level and the given input directories.
  256. */
  257. public void runAjdoc(String visibility, String lstFile) {
  258. if (!visibility.equals("public")
  259. && !visibility.equals("protected")
  260. && !visibility.equals("private")) {
  261. fail("need to pass 'public','protected' or 'private' visibility to ajdoc");
  262. }
  263. String[] args = new String[8];
  264. args[0] = "-" + visibility;
  265. args[1] = "-classpath";
  266. args[2] = AjdocTests.ASPECTJRT_PATH.getPath();
  267. args[3] = "-d";
  268. args[4] = getAbsolutePathOutdir();
  269. args[5] = "-sourcepath";
  270. args[6] = getAbsoluteProjectDir();
  271. args[7] = "@" + getAbsoluteProjectDir() + File.separatorChar + lstFile;
  272. org.aspectj.tools.ajdoc.Main.main(args);
  273. }
  274. /**
  275. * Run the ajdoc command with the given options
  276. */
  277. public void runAjdoc(List options) {
  278. String[] args = new String[options.size()];
  279. int i = 0;
  280. for (Iterator iter = options.iterator(); iter.hasNext();) {
  281. String element = (String) iter.next();
  282. args[i] = element;
  283. i++;
  284. }
  285. org.aspectj.tools.ajdoc.Main.main(args);
  286. }
  287. }