]> source.dussan.org Git - aspectj.git/blob
57ac60c9e630e49cff5a5ac3ba0f1d52a87e9384
[aspectj.git] /
1 package org.aspectj.systemtest.incremental.tools;
2
3 import java.io.DataOutputStream;
4 import java.io.File;
5 import java.io.FileOutputStream;
6 import java.io.IOException;
7 import java.util.ArrayList;
8 import java.util.Iterator;
9 import java.util.List;
10
11 import org.aspectj.ajdt.internal.core.builder.AjState;
12 import org.aspectj.bridge.IMessage;
13 import org.aspectj.testing.util.FileUtil;
14
15 public class AbstractMultiProjectIncrementalAjdeInteractionTestbed extends
16                 AjdeInteractionTestbed {
17
18         public static boolean VERBOSE = false;
19
20         protected void setUp() throws Exception {
21                 super.setUp();
22                 AjdeInteractionTestbed.VERBOSE = VERBOSE;
23                 AjState.FORCE_INCREMENTAL_DURING_TESTING = true;
24         }
25
26         protected void tearDown() throws Exception {
27                 super.tearDown();
28                 AjState.FORCE_INCREMENTAL_DURING_TESTING = false;
29         }
30
31         public void build(String projectName) {
32                 constructUpToDateLstFile(projectName,"build.lst");
33                 build(projectName,"build.lst");
34                 if (AjdeInteractionTestbed.VERBOSE) printBuildReport();
35         }
36
37         public void fullBuild(String projectName) {
38                 constructUpToDateLstFile(projectName,"build.lst");
39                 fullBuild(projectName,"build.lst");
40                 if (AjdeInteractionTestbed.VERBOSE) printBuildReport();
41         }
42
43         private void constructUpToDateLstFile(String pname, String configname) {
44                 File projectBase = new File(sandboxDir,pname);
45                 File toConstruct = new File(projectBase,configname);
46                 List filesForCompilation = new ArrayList();
47                 collectUpFiles(projectBase,projectBase,filesForCompilation);
48         
49                 try {
50                         FileOutputStream fos = new FileOutputStream(toConstruct);
51                         DataOutputStream dos = new DataOutputStream(fos);
52                         for (Iterator iter = filesForCompilation.iterator(); iter.hasNext();) {
53                                 String file = (String) iter.next();
54                                 dos.writeBytes(file+"\n");
55                         }
56                         dos.close();
57                 } catch (IOException ioe) {
58                         ioe.printStackTrace();
59                 }
60         }
61
62         public void checkForError(String anError) {
63                 List messages = MyTaskListManager.getErrorMessages();
64                 for (Iterator iter = messages.iterator(); iter.hasNext();) {
65                         IMessage element = (IMessage) iter.next();
66                         if (element.getMessage().indexOf(anError)!=-1) return;
67                 }
68                 fail("Didn't find the error message:\n'"+anError+"'.\nErrors that occurred:\n"+MyTaskListManager.getErrorMessages());
69         }
70
71         private void collectUpFiles(File location, File base, List collectionPoint) {
72                 String contents[] = location.list();
73                 if (contents==null) return;
74                 for (int i = 0; i < contents.length; i++) {
75                         String string = contents[i];
76                         File f = new File(location,string);
77                         if (f.isDirectory()) {
78                                 collectUpFiles(f,base,collectionPoint);
79                         } else if (f.isFile() && (f.getName().endsWith(".aj") || f.getName().endsWith(".java"))) {
80                                 String fileFound;
81                                 try {
82                                         fileFound = f.getCanonicalPath();
83                                         String toRemove  = base.getCanonicalPath();
84                                         if (!fileFound.startsWith(toRemove)) throw new RuntimeException("eh? "+fileFound+"   "+toRemove);
85                                         collectionPoint.add(fileFound.substring(toRemove.length()+1));//+1 captures extra separator
86                                 } catch (IOException e) {
87                                         e.printStackTrace();
88                                 }
89                         }
90                 }
91         }
92
93         /**
94          * Fill in the working directory with the project base files,
95          * from the 'base' folder.
96          */
97         protected void initialiseProject(String p) {
98                 File projectSrc=new File(testdataSrcDir+File.separatorChar+p+File.separatorChar+"base");
99                 File destination=new File(getWorkingDir(),p);
100                 if (!destination.exists()) {destination.mkdir();}
101                 copy(projectSrc,destination);//,false);
102         }
103
104         /**
105          * Copy the contents of some directory to another location - the
106          * copy is recursive.
107          */
108         protected void copy(File from, File to) {
109                 String contents[] = from.list();
110                 if (contents==null) return;
111                 for (int i = 0; i < contents.length; i++) {
112                         String string = contents[i];
113                         File f = new File(from,string);
114                         File t = new File(to,string);
115                         
116                         if (f.isDirectory() && !f.getName().startsWith("inc")) {
117                                 t.mkdir();
118                                 copy(f,t);
119                         } else if (f.isFile()) {
120                                 StringBuffer sb = new StringBuffer();
121                                 //if (VERBOSE) System.err.println("Copying "+f+" to "+t);
122                                 FileUtil.copyFile(f,t,sb);
123                                 if (sb.length()!=0) { System.err.println(sb.toString());}
124                         } 
125                 }
126         }
127
128 }