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