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;
29 configureBuildStructureModel(false);
32 public void build(String projectName) {
33 constructUpToDateLstFile(projectName,"build.lst");
34 build(projectName,"build.lst");
35 if (AjdeInteractionTestbed.VERBOSE) printBuildReport();
38 public void fullBuild(String projectName) {
39 constructUpToDateLstFile(projectName,"build.lst");
40 fullBuild(projectName,"build.lst");
41 if (AjdeInteractionTestbed.VERBOSE) printBuildReport();
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);
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");
58 } catch (IOException ioe) {
59 ioe.printStackTrace();
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;
69 fail("Didn't find the error message:\n'"+anError+"'.\nErrors that occurred:\n"+MyTaskListManager.getErrorMessages());
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"))) {
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) {
95 * Fill in the working directory with the project base files,
96 * from the 'base' folder.
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);
106 * Copy the contents of some directory to another location - the
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);
117 if (f.isDirectory() && !f.getName().startsWith("inc")) {
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());}