1 package org.aspectj.systemtest.incremental.tools;
3 import java.io.DataOutputStream;
5 import java.io.FileOutputStream;
6 import java.io.IOException;
7 import java.util.ArrayList;
8 import java.util.Iterator;
11 import org.aspectj.ajdt.internal.core.builder.AjState;
12 import org.aspectj.bridge.IMessage;
13 import org.aspectj.testing.util.FileUtil;
15 public class AbstractMultiProjectIncrementalAjdeInteractionTestbed extends
16 AjdeInteractionTestbed {
18 public static boolean VERBOSE = false;
20 protected void setUp() throws Exception {
22 AjdeInteractionTestbed.VERBOSE = VERBOSE;
23 AjState.FORCE_INCREMENTAL_DURING_TESTING = true;
26 protected void tearDown() throws Exception {
28 AjState.FORCE_INCREMENTAL_DURING_TESTING = false;
31 public void build(String projectName) {
32 constructUpToDateLstFile(projectName,"build.lst");
33 build(projectName,"build.lst");
34 if (AjdeInteractionTestbed.VERBOSE) printBuildReport();
37 public void fullBuild(String projectName) {
38 constructUpToDateLstFile(projectName,"build.lst");
39 fullBuild(projectName,"build.lst");
40 if (AjdeInteractionTestbed.VERBOSE) printBuildReport();
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);
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");
57 } catch (IOException ioe) {
58 ioe.printStackTrace();
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;
68 fail("Didn't find the error message:\n'"+anError+"'.\nErrors that occurred:\n"+MyTaskListManager.getErrorMessages());
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"))) {
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) {
94 * Fill in the working directory with the project base files,
95 * from the 'base' folder.
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);
105 * Copy the contents of some directory to another location - the
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);
116 if (f.isDirectory() && !f.getName().startsWith("inc")) {
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());}