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