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