]> source.dussan.org Git - aspectj.git/blob
b3ae1b6c100f8160baafd9a2e937ff26e05e5249
[aspectj.git] /
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 
7  *  
8  * Contributors: IBM Corporation - initial API and implementation 
9  *                               Helen Hawkins   - initial version (bug 148190)
10  *******************************************************************/
11 package org.aspectj.systemtest.incremental.tools;
12
13 import java.io.File;
14 import java.util.ArrayList;
15 import java.util.Hashtable;
16 import java.util.List;
17 import java.util.Map;
18 import java.util.Set;
19 import java.util.StringTokenizer;
20
21 import org.aspectj.ajde.core.ICompilerConfiguration;
22 import org.aspectj.ajde.core.IOutputLocationManager;
23 import org.aspectj.util.LangUtil;
24
25 /**
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.
28  */
29 public class MultiProjTestCompilerConfiguration implements ICompilerConfiguration {
30
31         private boolean verbose = false;
32
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;
50
51         int changed;
52
53         public MultiProjTestCompilerConfiguration(String projectPath) {
54                 this.projectPath = projectPath;
55         }
56
57         public Set<File> getAspectPath() {
58                 log("ICompilerConfiguration.getAspectPath(" + aspectPath + ")");
59                 return aspectPath;
60         }
61
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());
69                 }
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";
77                 verifyClasspath(cp);
78                 if (LangUtil.is19VMOrGreater()) {
79                         cp = LangUtil.getJrtFsFilePath() + File.pathSeparator + cp;
80                 }
81
82                 // look at dependant projects
83                 if (dependants != null) {
84                         for (String dependant: dependants) {
85                                 cp = AjdeInteractionTestbed.getFile(dependant, "bin") + File.pathSeparator + cp;
86                         }
87                 }
88                 // System.err.println("For project "+projectPath+" getClasspath() returning "+cp);
89                 return cp;
90         }
91
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());
97                 }
98         }
99
100         public Set<File> getInpath() {
101                 log("ICompilerConfiguration.getInPath()");
102                 return inpath;
103         }
104
105         public Map<String, String> getJavaOptionsMap() {
106                 log("ICompilerConfiguration.getJavaOptionsMap()");
107                 if (javaOptionsMap != null && !javaOptionsMap.isEmpty())
108                         return javaOptionsMap;
109
110                 Map<String, String> ht = new Hashtable<>();
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");
114                 return ht;
115         }
116
117         public String getNonStandardOptions() {
118                 log("ICompilerConfiguration.getNonStandardOptions( " + nonstandardoptions + ")");
119                 return nonstandardoptions;
120         }
121
122         public String getOutJar() {
123                 log("ICompilerConfiguration.getOutJar()");
124                 return null;
125         }
126
127         public IOutputLocationManager getOutputLocationManager() {
128                 log("ICompilerConfiguration.getOutputLocationManager()");
129                 if (outputLocationManager == null) {
130                         outputLocationManager = new MultiProjTestOutputLocationManager(projectPath);
131                 }
132                 return outputLocationManager;
133         }
134
135         public List<String> getProjectSourceFiles() {
136                 log("ICompilerConfiguration.getProjectSourceFiles()");
137                 return projectSourceFiles;
138         }
139
140         public List<String> getProjectXmlConfigFiles() {
141                 return xmlConfigFiles;
142         }
143
144         public List<File> getProjectSourceFilesChanged() {
145                 log("ICompilerConfiguration.getProjectSourceFilesChanged()");
146                 return modifiedFiles;
147         }
148
149         public Map<String,File> getSourcePathResources() {
150                 log("ICompilerConfiguration.getSourcePathResources()");
151                 return sourcePathResources;
152         }
153
154         public void log(String s) {
155                 if (verbose)
156                         System.out.println(s);
157         }
158
159         public void addDependancy(String projectItDependsOn) {
160                 if (dependants == null) {
161                         dependants = new ArrayList<>();
162                 }
163                 dependants.add(projectItDependsOn);
164         }
165
166         // -------------------- setter methods useful for testing ---------------
167         public void setAspectPath(Set<File> aspectPath) {
168                 this.aspectPath = aspectPath;
169                 this.changed |= ICompilerConfiguration.ASPECTPATH_CHANGED;
170         }
171
172         public void setInpath(Set<File> inpath) {
173                 this.inpath = inpath;
174                 this.changed |= ICompilerConfiguration.INPATH_CHANGED;
175         }
176
177         public void setOutjar(String outjar) {
178                 this.outjar = outjar;
179                 this.changed |= ICompilerConfiguration.OUTJAR_CHANGED;
180         }
181         
182         public void setProcessor(String processor) {
183                 this.processor = processor;
184                 this.changed |= ICompilerConfiguration.PROCESSOR_CHANGED;
185         }
186
187         public void setProcessorPath(String processorPath) {
188                 this.processorPath = processorPath;
189                 this.changed |= ICompilerConfiguration.PROCESSOR_CHANGED;
190         }
191
192         public void setJavaOptions(Map<String,String> javaOptions) {
193                 this.javaOptionsMap = javaOptions;
194                 this.changed |= ICompilerConfiguration.JAVAOPTIONS_CHANGED;
195         }
196
197         public void setNonStandardOptions(String options) {
198                 this.nonstandardoptions = options;
199                 this.changed |= ICompilerConfiguration.NONSTANDARDOPTIONS_CHANGED;
200         }
201
202         public void setProjectSourceFiles(List<String> projectSourceFiles) {
203                 this.projectSourceFiles = projectSourceFiles;
204                 this.changed |= ICompilerConfiguration.PROJECTSOURCEFILES_CHANGED;
205         }
206
207         public void setProjectXmlConfigFiles(List<String> xmlConfigFiles) {
208                 this.xmlConfigFiles = xmlConfigFiles;
209                 this.changed |= ICompilerConfiguration.XMLCONFIG_CHANGED;
210         }
211
212         public void addProjectSourceFileChanged(File f) {
213                 if (this.modifiedFiles == null) {
214                         this.modifiedFiles = new ArrayList<>();
215                 }
216                 if (f != null) {
217                         modifiedFiles.add(f);
218                 }
219         }
220
221         public void addClasspathEntryChanged(String f) {
222                 if (this.modifiedDirs == null) {
223                         this.modifiedDirs = new ArrayList<>();
224                 }
225                 if (f != null) {
226                         modifiedDirs.add(f);
227                 }
228         }
229
230         public void setSourcePathResources(Map<String,File> sourcePathResources) {
231                 this.sourcePathResources = sourcePathResources;
232                 this.changed |= ICompilerConfiguration.PROJECTSOURCERESOURCES_CHANGED;
233         }
234
235         public void setOutputLocationManager(IOutputLocationManager manager) {
236                 this.outputLocationManager = manager;
237         }
238
239         public void setClasspath(String path) {
240                 this.classPath = path;
241                 this.changed |= ICompilerConfiguration.CLASSPATH_CHANGED;
242         }
243
244         public int getConfigurationChanges() {
245                 return changed;
246                 // return EVERYTHING;
247         }
248
249         public void configurationRead() {
250                 changed = NO_CHANGES;
251                 modifiedFiles = null;
252                 modifiedDirs = null;
253         }
254
255         public List<String> getClasspathElementsWithModifiedContents() {
256                 return modifiedDirs;
257         }
258
259         public void setProjectEncoding(String encoding) {
260                 this.encoding = encoding;
261         }
262
263         public String getProjectEncoding() {
264                 return this.encoding;
265         }
266
267         public String getProcessor() {
268                 return this.processor;
269         }
270
271         public String getProcessorPath() {
272                 return this.processorPath;
273         }
274
275         @Override
276         public String getModulepath() {
277                 return null;
278         }
279
280         @Override
281         public String getModuleSourcepath() {
282                 return null;
283         }
284
285 }