1 package org.codehaus.nanning.attribute;
2
3 import java.io.File;
4 import java.net.MalformedURLException;
5
6 import junit.framework.TestCase;
7
8 /***
9 * For internal use only, test-cases in the frameworks extend this to compile their
10 * attributes properly under IntelliJ. It should be placed in the test-directory but
11 * unfortunately those classes are not included in the produced jar-file so the
12 * frameworks can't use them.
13 */
14 public abstract class AbstractAttributesTest extends TestCase {
15 private static boolean attributesCompiled = false;
16 private static File attributesDir;
17
18 protected void setUp() throws Exception {
19 super.setUp();
20 compileAttributes();
21 }
22
23 private static void compileAttributes() {
24 if (!attributesCompiled) {
25 attributesCompiled = true;
26 attributesDir = new File("target" + File.separator + "attributes");
27
28 compileFromBaseDir(new File("."));
29 compileFromBaseDir(new File(".." + File.separator + "nanning"));
30
31 try {
32 Attributes.addSearchPath(attributesDir.toURL());
33 } catch (MalformedURLException e) {
34 fail(e.getMessage());
35 }
36 }
37 }
38
39 private static void compileFromBaseDir(File baseDir) {
40 compileAttributes(new File(baseDir, "src" + File.separator + "test"));
41 compileAttributes(new File(baseDir, "src" + File.separator + "main"));
42 File[] frameworks = new File(baseDir, "src" + File.separator + "frameworks").listFiles();
43 if (frameworks != null) {
44 for (int i = 0; i < frameworks.length; i++) {
45 File framework = frameworks[i];
46 compileAttributes(new File(framework, "src" + File.separator + "test"));
47 compileAttributes(new File(framework, "src" + File.separator + "main"));
48 }
49 }
50 }
51
52 private static void compileAttributes(File source) {
53 if (source.isDirectory()) {
54 AttributesCompiler attributesCompiler = new AttributesCompiler();
55 attributesCompiler.setSrc(source);
56 attributesCompiler.setDest(attributesDir);
57 attributesCompiler.execute();
58 }
59 }
60
61 public static File findNanningFile(String path) {
62 File file = new File(path);
63 if (file.exists()) {
64 return file;
65 }
66 file = new File(".." + File.separator + "nanning", path);
67 return file;
68 }
69 }
This page was automatically generated by Maven