1 /********************************************************************
2 * Copyright (c) 2007 Contributors. All rights reserved.
3 * This program and the accompanying materials are made available
4 * under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution and is available at
6 * http://eclipse.org/legal/epl-v10.html
8 * Contributors: IBM Corporation - initial API and implementation
9 * Helen Hawkins - initial version (bug 148190)
10 *******************************************************************/
11 package org.aspectj.systemtest.incremental.tools;
14 import java.util.ArrayList;
15 import java.util.Hashtable;
16 import java.util.List;
19 import java.util.StringTokenizer;
21 import org.aspectj.ajde.core.ICompilerConfiguration;
22 import org.aspectj.ajde.core.IOutputLocationManager;
23 import org.aspectj.util.LangUtil;
26 * ICompilerConfiguration which mirrors the way AJDT behaves. Always returns that its 1.5 compliant and enables the setting of all
27 * options except output jar.
29 public class MultiProjTestCompilerConfiguration implements ICompilerConfiguration {
31 private boolean verbose = false;
33 private String classPath = "";
34 private Set<File> aspectPath = null;
35 private Map<String,File> sourcePathResources = null;
36 private IOutputLocationManager outputLocationManager = null;
37 private List<String> dependants;
38 private Map<String,String> javaOptionsMap;
39 private Set<File> inpath;
40 private String encoding = null;
41 private String outjar;
42 private String processor;
43 private String processorPath;
44 private String nonstandardoptions;
45 private List<File> modifiedFiles;
46 private List<String> modifiedDirs;
47 private List<String> projectSourceFiles = new ArrayList<>();
48 private List<String> xmlConfigFiles = new ArrayList<>();
49 private String projectPath;
53 public MultiProjTestCompilerConfiguration(String projectPath) {
54 this.projectPath = projectPath;
57 public Set<File> getAspectPath() {
58 log("ICompilerConfiguration.getAspectPath(" + aspectPath + ")");
62 public String getClasspath() {
63 log("ICompilerConfiguration.getClasspath()");
64 // AJDT has all the output directories on it's classpath
65 StringBuffer sb = new StringBuffer();
66 List<File> allOutputPaths = getOutputLocationManager().getAllOutputLocations();
67 for (File dir: allOutputPaths) {
68 sb.append(File.pathSeparator + dir.getAbsolutePath());
70 String cp = sb.toString() + File.pathSeparator + new File(AjdeInteractionTestbed.testdataSrcDir) + File.pathSeparator
71 + System.getProperty("sun.boot.class.path") + File.pathSeparator + "../runtime/target/classes" + File.pathSeparator
72 + this.classPath + File.pathSeparator + System.getProperty("aspectjrt.path") + File.pathSeparator
73 + "../lib/junit/junit.jar" + "c:/batik/batik-1.6/lib/batik-util.jar;"
74 + "c:/batik/batik-1.6/lib/batik-awt-util.jar;" + "c:/batik/batik-1.6/lib/batik-dom.jar;"
75 + "c:/batik/batik-1.6/lib/batik-svggen.jar;" + File.pathSeparator + ".." + File.separator + "lib" + File.separator
76 + "test" + File.separator + "aspectjrt.jar";
78 if (LangUtil.is19VMOrGreater()) {
79 cp = LangUtil.getJrtFsFilePath() + File.pathSeparator + cp;
82 // look at dependant projects
83 if (dependants != null) {
84 for (String dependant: dependants) {
85 cp = AjdeInteractionTestbed.getFile(dependant, "bin") + File.pathSeparator + cp;
88 // System.err.println("For project "+projectPath+" getClasspath() returning "+cp);
92 public static void verifyClasspath(String cp) {
93 StringTokenizer st = new StringTokenizer(cp,File.pathSeparator);
94 while (st.hasMoreElements()) {
95 String cpElement = st.nextToken();
96 System.out.println("Checking: "+cpElement+" exists? "+new File(cpElement).exists());
100 public Set<File> getInpath() {
101 log("ICompilerConfiguration.getInPath()");
105 public Map<String, String> getJavaOptionsMap() {
106 log("ICompilerConfiguration.getJavaOptionsMap()");
107 if (javaOptionsMap != null && !javaOptionsMap.isEmpty())
108 return javaOptionsMap;
110 Hashtable<String, String> ht = new Hashtable<String, String>();
111 ht.put("org.eclipse.jdt.core.compiler.compliance", "1.5");
112 ht.put("org.eclipse.jdt.core.compiler.codegen.targetPlatform", "1.5");
113 ht.put("org.eclipse.jdt.core.compiler.source", "1.5");
117 public String getNonStandardOptions() {
118 log("ICompilerConfiguration.getNonStandardOptions( " + nonstandardoptions + ")");
119 return nonstandardoptions;
122 public String getOutJar() {
123 log("ICompilerConfiguration.getOutJar()");
127 public IOutputLocationManager getOutputLocationManager() {
128 log("ICompilerConfiguration.getOutputLocationManager()");
129 if (outputLocationManager == null) {
130 outputLocationManager = new MultiProjTestOutputLocationManager(projectPath);
132 return outputLocationManager;
135 public List<String> getProjectSourceFiles() {
136 log("ICompilerConfiguration.getProjectSourceFiles()");
137 return projectSourceFiles;
140 public List<String> getProjectXmlConfigFiles() {
141 return xmlConfigFiles;
144 public List<File> getProjectSourceFilesChanged() {
145 log("ICompilerConfiguration.getProjectSourceFilesChanged()");
146 return modifiedFiles;
149 public Map<String,File> getSourcePathResources() {
150 log("ICompilerConfiguration.getSourcePathResources()");
151 return sourcePathResources;
154 public void log(String s) {
156 System.out.println(s);
159 public void addDependancy(String projectItDependsOn) {
160 if (dependants == null) {
161 dependants = new ArrayList<String>();
163 dependants.add(projectItDependsOn);
166 // -------------------- setter methods useful for testing ---------------
167 public void setAspectPath(Set<File> aspectPath) {
168 this.aspectPath = aspectPath;
169 this.changed |= ICompilerConfiguration.ASPECTPATH_CHANGED;
172 public void setInpath(Set<File> inpath) {
173 this.inpath = inpath;
174 this.changed |= ICompilerConfiguration.INPATH_CHANGED;
177 public void setOutjar(String outjar) {
178 this.outjar = outjar;
179 this.changed |= ICompilerConfiguration.OUTJAR_CHANGED;
182 public void setProcessor(String processor) {
183 this.processor = processor;
184 this.changed |= ICompilerConfiguration.PROCESSOR_CHANGED;
187 public void setProcessorPath(String processorPath) {
188 this.processorPath = processorPath;
189 this.changed |= ICompilerConfiguration.PROCESSOR_CHANGED;
192 public void setJavaOptions(Map<String,String> javaOptions) {
193 this.javaOptionsMap = javaOptions;
194 this.changed |= ICompilerConfiguration.JAVAOPTIONS_CHANGED;
197 public void setNonStandardOptions(String options) {
198 this.nonstandardoptions = options;
199 this.changed |= ICompilerConfiguration.NONSTANDARDOPTIONS_CHANGED;
202 public void setProjectSourceFiles(List<String> projectSourceFiles) {
203 this.projectSourceFiles = projectSourceFiles;
204 this.changed |= ICompilerConfiguration.PROJECTSOURCEFILES_CHANGED;
207 public void setProjectXmlConfigFiles(List<String> xmlConfigFiles) {
208 this.xmlConfigFiles = xmlConfigFiles;
209 this.changed |= ICompilerConfiguration.XMLCONFIG_CHANGED;
212 public void addProjectSourceFileChanged(File f) {
213 if (this.modifiedFiles == null) {
214 this.modifiedFiles = new ArrayList<File>();
217 modifiedFiles.add(f);
221 public void addClasspathEntryChanged(String f) {
222 if (this.modifiedDirs == null) {
223 this.modifiedDirs = new ArrayList<String>();
230 public void setSourcePathResources(Map<String,File> sourcePathResources) {
231 this.sourcePathResources = sourcePathResources;
232 this.changed |= ICompilerConfiguration.PROJECTSOURCERESOURCES_CHANGED;
235 public void setOutputLocationManager(IOutputLocationManager manager) {
236 this.outputLocationManager = manager;
239 public void setClasspath(String path) {
240 this.classPath = path;
241 this.changed |= ICompilerConfiguration.CLASSPATH_CHANGED;
244 public int getConfigurationChanges() {
246 // return EVERYTHING;
249 public void configurationRead() {
250 changed = NO_CHANGES;
251 modifiedFiles = null;
255 public List<String> getClasspathElementsWithModifiedContents() {
259 public void setProjectEncoding(String encoding) {
260 this.encoding = encoding;
263 public String getProjectEncoding() {
264 return this.encoding;
267 public String getProcessor() {
268 return this.processor;
271 public String getProcessorPath() {
272 return this.processorPath;
276 public String getModulepath() {
281 public String getModuleSourcepath() {