KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tirsen > nanning > attribute > AbstractAttributesTest


1 package com.tirsen.nanning.attribute;
2
3 import java.io.File JavaDoc;
4 import java.net.MalformedURLException JavaDoc;
5
6 import junit.framework.TestCase;
7
8 public abstract class AbstractAttributesTest extends TestCase {
9     private static boolean attributesCompiled = false;
10     private static File JavaDoc attributesDir;
11
12     protected void setUp() throws Exception JavaDoc {
13         super.setUp();
14         compileAttributes();
15     }
16
17     private static void compileAttributes() {
18         if (!attributesCompiled) {
19             attributesCompiled = true;
20             attributesDir = new File JavaDoc("target" + File.separator + "attributes");
21
22             compileFromBaseDir(new File JavaDoc("."));
23             compileFromBaseDir(new File JavaDoc(".." + File.separator + "nanning"));
24
25             try {
26                 Attributes.addSearchPath(attributesDir.toURL());
27             } catch (MalformedURLException JavaDoc e) {
28                 fail(e.getMessage());
29             }
30         }
31     }
32
33     private static void compileFromBaseDir(File JavaDoc baseDir) {
34         compileAttributes(new File JavaDoc(baseDir, "src" + File.separator + "test"));
35         compileAttributes(new File JavaDoc(baseDir, "src" + File.separator + "main"));
36         File JavaDoc[] frameworks = new File JavaDoc(baseDir, "src" + File.separator + "frameworks").listFiles();
37         if (frameworks != null) {
38             for (int i = 0; i < frameworks.length; i++) {
39                 File JavaDoc framework = frameworks[i];
40                 compileAttributes(new File JavaDoc(framework, "src" + File.separator + "test"));
41                 compileAttributes(new File JavaDoc(framework, "src" + File.separator + "main"));
42             }
43         }
44     }
45
46     private static void compileAttributes(File JavaDoc source) {
47         if (source.isDirectory()) {
48             AttributesCompiler attributesCompiler = new AttributesCompiler();
49             attributesCompiler.setSrc(source);
50             attributesCompiler.setDest(attributesDir);
51             attributesCompiler.execute();
52         }
53     }
54
55     public static File JavaDoc findNanningFile(String JavaDoc path) {
56         File JavaDoc file = new File JavaDoc(path);
57         if (file.exists()) {
58             return file;
59         }
60         file = new File JavaDoc(".." + File.separator + "nanning", path);
61         return file;
62     }
63 }
64
Popular Tags