aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/org/aspectj/systemtest/incremental/tools/MultiProjTestCompilerConfiguration.java
blob: 86302bfbaf0a8676002fbb00a59f1692bb62a2c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/********************************************************************
 * Copyright (c) 2007 Contributors. All rights reserved. 
 * This program and the accompanying materials are made available 
 * under the terms of the Eclipse Public License v1.0 
 * which accompanies this distribution and is available at 
 * http://eclipse.org/legal/epl-v10.html 
 *  
 * Contributors: IBM Corporation - initial API and implementation 
 * 				 Helen Hawkins   - initial version (bug 148190)
 *******************************************************************/
package org.aspectj.systemtest.incremental.tools;

import java.io.File;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.aspectj.ajde.core.ICompilerConfiguration;
import org.aspectj.ajde.core.IOutputLocationManager;

/**
 * ICompilerConfiguration which mirrors the way AJDT behaves. Always returns that its 1.5 compliant and enables the setting of all
 * options except output jar.
 */
public class MultiProjTestCompilerConfiguration implements ICompilerConfiguration {

	private boolean verbose = false;

	private String classPath = "";
	private Set<File> aspectPath = null;
	private Map<String,File> sourcePathResources = null;
	private IOutputLocationManager outputLocationManager = null;
	private List<String> dependants;
	private Map<String,String> javaOptionsMap;
	private Set<File> inpath;
	private String encoding = null;
	private String outjar;
	private String processor;
	private String processorPath;
	private String nonstandardoptions;
	private List<File> modifiedFiles;
	private List<String> modifiedDirs;
	private List<String> projectSourceFiles = new ArrayList<>();
	private List<String> xmlConfigFiles = new ArrayList<>();
	private String projectPath;

	int changed;

	public MultiProjTestCompilerConfiguration(String projectPath) {
		this.projectPath = projectPath;
	}

	public Set<File> getAspectPath() {
		log("ICompilerConfiguration.getAspectPath(" + aspectPath + ")");
		return aspectPath;
	}

	public String getClasspath() {
		log("ICompilerConfiguration.getClasspath()");
		// AJDT has all the output directories on it's classpath
		StringBuffer sb = new StringBuffer();
		List<File> allOutputPaths = getOutputLocationManager().getAllOutputLocations();
		for (File dir: allOutputPaths) {
			sb.append(File.pathSeparator + dir.getAbsolutePath());
		}
		String cp = sb.toString() + File.pathSeparator + new File(AjdeInteractionTestbed.testdataSrcDir) + File.pathSeparator
				+ System.getProperty("sun.boot.class.path") + File.pathSeparator + "../runtime/bin" + File.pathSeparator
				+ this.classPath + File.pathSeparator + System.getProperty("aspectjrt.path") + File.pathSeparator
				+ "../lib/junit/junit.jar" + "c:/batik/batik-1.6/lib/batik-util.jar;"
				+ "c:/batik/batik-1.6/lib/batik-awt-util.jar;" + "c:/batik/batik-1.6/lib/batik-dom.jar;"
				+ "c:/batik/batik-1.6/lib/batik-svggen.jar;" + File.pathSeparator + ".." + File.separator + "lib" + File.separator
				+ "test" + File.separator + "aspectjrt.jar";

		// look at dependant projects
		if (dependants != null) {
			for (String dependant: dependants) {
				cp = AjdeInteractionTestbed.getFile(dependant, "bin") + File.pathSeparator + cp;
			}
		}
		// System.err.println("For project "+projectPath+" getClasspath() returning "+cp);
		return cp;
	}

	public Set<File> getInpath() {
		log("ICompilerConfiguration.getInPath()");
		return inpath;
	}

	public Map<String, String> getJavaOptionsMap() {
		log("ICompilerConfiguration.getJavaOptionsMap()");
		if (javaOptionsMap != null && !javaOptionsMap.isEmpty())
			return javaOptionsMap;

		Hashtable<String, String> ht = new Hashtable<String, String>();
		ht.put("org.eclipse.jdt.core.compiler.compliance", "1.5");
		ht.put("org.eclipse.jdt.core.compiler.codegen.targetPlatform", "1.5");
		ht.put("org.eclipse.jdt.core.compiler.source", "1.5");
		return ht;
	}

	public String getNonStandardOptions() {
		log("ICompilerConfiguration.getNonStandardOptions( " + nonstandardoptions + ")");
		return nonstandardoptions;
	}

	public String getOutJar() {
		log("ICompilerConfiguration.getOutJar()");
		return null;
	}

	public IOutputLocationManager getOutputLocationManager() {
		log("ICompilerConfiguration.getOutputLocationManager()");
		if (outputLocationManager == null) {
			outputLocationManager = new MultiProjTestOutputLocationManager(projectPath);
		}
		return outputLocationManager;
	}

	public List<String> getProjectSourceFiles() {
		log("ICompilerConfiguration.getProjectSourceFiles()");
		return projectSourceFiles;
	}

	public List<String> getProjectXmlConfigFiles() {
		return xmlConfigFiles;
	}

	public List<File> getProjectSourceFilesChanged() {
		log("ICompilerConfiguration.getProjectSourceFilesChanged()");
		return modifiedFiles;
	}

	public Map<String,File> getSourcePathResources() {
		log("ICompilerConfiguration.getSourcePathResources()");
		return sourcePathResources;
	}

	public void log(String s) {
		if (verbose)
			System.out.println(s);
	}

	public void addDependancy(String projectItDependsOn) {
		if (dependants == null) {
			dependants = new ArrayList<String>();
		}
		dependants.add(projectItDependsOn);
	}

	// -------------------- setter methods useful for testing ---------------
	public void setAspectPath(Set<File> aspectPath) {
		this.aspectPath = aspectPath;
		this.changed |= ICompilerConfiguration.ASPECTPATH_CHANGED;
	}

	public void setInpath(Set<File> inpath) {
		this.inpath = inpath;
		this.changed |= ICompilerConfiguration.INPATH_CHANGED;
	}

	public void setOutjar(String outjar) {
		this.outjar = outjar;
		this.changed |= ICompilerConfiguration.OUTJAR_CHANGED;
	}
	
	public void setProcessor(String processor) {
		this.processor = processor;
		this.changed |= ICompilerConfiguration.PROCESSOR_CHANGED;
	}

	public void setProcessorPath(String processorPath) {
		this.processorPath = processorPath;
		this.changed |= ICompilerConfiguration.PROCESSOR_CHANGED;
	}

	public void setJavaOptions(Map<String,String> javaOptions) {
		this.javaOptionsMap = javaOptions;
		this.changed |= ICompilerConfiguration.JAVAOPTIONS_CHANGED;
	}

	public void setNonStandardOptions(String options) {
		this.nonstandardoptions = options;
		this.changed |= ICompilerConfiguration.NONSTANDARDOPTIONS_CHANGED;
	}

	public void setProjectSourceFiles(List<String> projectSourceFiles) {
		this.projectSourceFiles = projectSourceFiles;
		this.changed |= ICompilerConfiguration.PROJECTSOURCEFILES_CHANGED;
	}

	public void setProjectXmlConfigFiles(List<String> xmlConfigFiles) {
		this.xmlConfigFiles = xmlConfigFiles;
		this.changed |= ICompilerConfiguration.XMLCONFIG_CHANGED;
	}

	public void addProjectSourceFileChanged(File f) {
		if (this.modifiedFiles == null) {
			this.modifiedFiles = new ArrayList<File>();
		}
		if (f != null) {
			modifiedFiles.add(f);
		}
	}

	public void addClasspathEntryChanged(String f) {
		if (this.modifiedDirs == null) {
			this.modifiedDirs = new ArrayList<String>();
		}
		if (f != null) {
			modifiedDirs.add(f);
		}
	}

	public void setSourcePathResources(Map<String,File> sourcePathResources) {
		this.sourcePathResources = sourcePathResources;
		this.changed |= ICompilerConfiguration.PROJECTSOURCERESOURCES_CHANGED;
	}

	public void setOutputLocationManager(IOutputLocationManager manager) {
		this.outputLocationManager = manager;
	}

	public void setClasspath(String path) {
		this.classPath = path;
		this.changed |= ICompilerConfiguration.CLASSPATH_CHANGED;
	}

	public int getConfigurationChanges() {
		return changed;
		// return EVERYTHING;
	}

	public void configurationRead() {
		changed = NO_CHANGES;
		modifiedFiles = null;
		modifiedDirs = null;
	}

	public List<String> getClasspathElementsWithModifiedContents() {
		return modifiedDirs;
	}

	public void setProjectEncoding(String encoding) {
		this.encoding = encoding;
	}

	public String getProjectEncoding() {
		return this.encoding;
	}

	public String getProcessor() {
		return this.processor;
	}

	public String getProcessorPath() {
		return this.processorPath;
	}

}