You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MultiProjTestCompilerConfiguration.java 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. import java.io.File;
  13. import java.util.ArrayList;
  14. import java.util.Hashtable;
  15. import java.util.List;
  16. import java.util.Map;
  17. import java.util.Set;
  18. import java.util.StringTokenizer;
  19. import org.aspectj.ajde.core.ICompilerConfiguration;
  20. import org.aspectj.ajde.core.IOutputLocationManager;
  21. import org.aspectj.util.LangUtil;
  22. /**
  23. * ICompilerConfiguration which mirrors the way AJDT behaves. Always returns that its 1.5 compliant and enables the setting of all
  24. * options except output jar.
  25. */
  26. public class MultiProjTestCompilerConfiguration implements ICompilerConfiguration {
  27. private boolean verbose = false;
  28. private String classPath = "";
  29. private Set<File> aspectPath = null;
  30. private Map<String,File> sourcePathResources = null;
  31. private IOutputLocationManager outputLocationManager = null;
  32. private List<String> dependants;
  33. private Map<String,String> javaOptionsMap;
  34. private Set<File> inpath;
  35. private String encoding = null;
  36. private String outjar;
  37. private String processor;
  38. private String processorPath;
  39. private String nonstandardoptions;
  40. private List<File> modifiedFiles;
  41. private List<String> modifiedDirs;
  42. private List<String> projectSourceFiles = new ArrayList<>();
  43. private List<String> xmlConfigFiles = new ArrayList<>();
  44. private String projectPath;
  45. int changed;
  46. public MultiProjTestCompilerConfiguration(String projectPath) {
  47. this.projectPath = projectPath;
  48. }
  49. public Set<File> getAspectPath() {
  50. log("ICompilerConfiguration.getAspectPath(" + aspectPath + ")");
  51. return aspectPath;
  52. }
  53. public String getClasspath() {
  54. log("ICompilerConfiguration.getClasspath()");
  55. // AJDT has all the output directories on it's classpath
  56. StringBuffer sb = new StringBuffer();
  57. List<File> allOutputPaths = getOutputLocationManager().getAllOutputLocations();
  58. for (File dir: allOutputPaths) {
  59. sb.append(File.pathSeparator + dir.getAbsolutePath());
  60. }
  61. String cp = sb.toString() + File.pathSeparator + new File(AjdeInteractionTestbed.testdataSrcDir) + File.pathSeparator
  62. + System.getProperty("sun.boot.class.path") + File.pathSeparator + "../runtime/target/classes" + File.pathSeparator
  63. + this.classPath + File.pathSeparator + System.getProperty("aspectjrt.path") + File.pathSeparator
  64. + "../lib/junit/junit.jar" + "c:/batik/batik-1.6/lib/batik-util.jar;"
  65. + "c:/batik/batik-1.6/lib/batik-awt-util.jar;" + "c:/batik/batik-1.6/lib/batik-dom.jar;"
  66. + "c:/batik/batik-1.6/lib/batik-svggen.jar;" + File.pathSeparator + ".." + File.separator + "lib" + File.separator
  67. + "test" + File.separator + "aspectjrt.jar";
  68. verifyClasspath(cp);
  69. if (LangUtil.is9VMOrGreater()) {
  70. cp = LangUtil.getJrtFsFilePath() + File.pathSeparator + cp;
  71. }
  72. // look at dependant projects
  73. if (dependants != null) {
  74. for (String dependant: dependants) {
  75. cp = AjdeInteractionTestbed.getFile(dependant, "bin") + File.pathSeparator + cp;
  76. }
  77. }
  78. // System.err.println("For project "+projectPath+" getClasspath() returning "+cp);
  79. return cp;
  80. }
  81. public static void verifyClasspath(String cp) {
  82. StringTokenizer st = new StringTokenizer(cp,File.pathSeparator);
  83. while (st.hasMoreElements()) {
  84. String cpElement = st.nextToken();
  85. // System.out.println("Checking: "+cpElement+" exists? "+new File(cpElement).exists());
  86. }
  87. }
  88. public Set<File> getInpath() {
  89. log("ICompilerConfiguration.getInPath()");
  90. return inpath;
  91. }
  92. public Map<String, String> getJavaOptionsMap() {
  93. log("ICompilerConfiguration.getJavaOptionsMap()");
  94. if (javaOptionsMap != null && !javaOptionsMap.isEmpty())
  95. return javaOptionsMap;
  96. Map<String, String> ht = new Hashtable<>();
  97. ht.put("org.eclipse.jdt.core.compiler.compliance", "1.5");
  98. ht.put("org.eclipse.jdt.core.compiler.codegen.targetPlatform", "1.5");
  99. ht.put("org.eclipse.jdt.core.compiler.source", "1.5");
  100. return ht;
  101. }
  102. public String getNonStandardOptions() {
  103. log("ICompilerConfiguration.getNonStandardOptions( " + nonstandardoptions + ")");
  104. return nonstandardoptions;
  105. }
  106. public String getOutJar() {
  107. log("ICompilerConfiguration.getOutJar()");
  108. return null;
  109. }
  110. public IOutputLocationManager getOutputLocationManager() {
  111. log("ICompilerConfiguration.getOutputLocationManager()");
  112. if (outputLocationManager == null) {
  113. outputLocationManager = new MultiProjTestOutputLocationManager(projectPath);
  114. }
  115. return outputLocationManager;
  116. }
  117. public List<String> getProjectSourceFiles() {
  118. log("ICompilerConfiguration.getProjectSourceFiles()");
  119. return projectSourceFiles;
  120. }
  121. public List<String> getProjectXmlConfigFiles() {
  122. return xmlConfigFiles;
  123. }
  124. public List<File> getProjectSourceFilesChanged() {
  125. log("ICompilerConfiguration.getProjectSourceFilesChanged()");
  126. return modifiedFiles;
  127. }
  128. public Map<String,File> getSourcePathResources() {
  129. log("ICompilerConfiguration.getSourcePathResources()");
  130. return sourcePathResources;
  131. }
  132. public void log(String s) {
  133. if (verbose)
  134. System.out.println(s);
  135. }
  136. public void addDependancy(String projectItDependsOn) {
  137. if (dependants == null) {
  138. dependants = new ArrayList<>();
  139. }
  140. dependants.add(projectItDependsOn);
  141. }
  142. // -------------------- setter methods useful for testing ---------------
  143. public void setAspectPath(Set<File> aspectPath) {
  144. this.aspectPath = aspectPath;
  145. this.changed |= ICompilerConfiguration.ASPECTPATH_CHANGED;
  146. }
  147. public void setInpath(Set<File> inpath) {
  148. this.inpath = inpath;
  149. this.changed |= ICompilerConfiguration.INPATH_CHANGED;
  150. }
  151. public void setOutjar(String outjar) {
  152. this.outjar = outjar;
  153. this.changed |= ICompilerConfiguration.OUTJAR_CHANGED;
  154. }
  155. public void setProcessor(String processor) {
  156. this.processor = processor;
  157. this.changed |= ICompilerConfiguration.PROCESSOR_CHANGED;
  158. }
  159. public void setProcessorPath(String processorPath) {
  160. this.processorPath = processorPath;
  161. this.changed |= ICompilerConfiguration.PROCESSOR_CHANGED;
  162. }
  163. public void setJavaOptions(Map<String,String> javaOptions) {
  164. this.javaOptionsMap = javaOptions;
  165. this.changed |= ICompilerConfiguration.JAVAOPTIONS_CHANGED;
  166. }
  167. public void setNonStandardOptions(String options) {
  168. this.nonstandardoptions = options;
  169. this.changed |= ICompilerConfiguration.NONSTANDARDOPTIONS_CHANGED;
  170. }
  171. public void setProjectSourceFiles(List<String> projectSourceFiles) {
  172. this.projectSourceFiles = projectSourceFiles;
  173. this.changed |= ICompilerConfiguration.PROJECTSOURCEFILES_CHANGED;
  174. }
  175. public void setProjectXmlConfigFiles(List<String> xmlConfigFiles) {
  176. this.xmlConfigFiles = xmlConfigFiles;
  177. this.changed |= ICompilerConfiguration.XMLCONFIG_CHANGED;
  178. }
  179. public void addProjectSourceFileChanged(File f) {
  180. if (this.modifiedFiles == null) {
  181. this.modifiedFiles = new ArrayList<>();
  182. }
  183. if (f != null) {
  184. modifiedFiles.add(f);
  185. }
  186. }
  187. public void addClasspathEntryChanged(String f) {
  188. if (this.modifiedDirs == null) {
  189. this.modifiedDirs = new ArrayList<>();
  190. }
  191. if (f != null) {
  192. modifiedDirs.add(f);
  193. }
  194. }
  195. public void setSourcePathResources(Map<String,File> sourcePathResources) {
  196. this.sourcePathResources = sourcePathResources;
  197. this.changed |= ICompilerConfiguration.PROJECTSOURCERESOURCES_CHANGED;
  198. }
  199. public void setOutputLocationManager(IOutputLocationManager manager) {
  200. this.outputLocationManager = manager;
  201. }
  202. public void setClasspath(String path) {
  203. this.classPath = path;
  204. this.changed |= ICompilerConfiguration.CLASSPATH_CHANGED;
  205. }
  206. public int getConfigurationChanges() {
  207. return changed;
  208. // return EVERYTHING;
  209. }
  210. public void configurationRead() {
  211. changed = NO_CHANGES;
  212. modifiedFiles = null;
  213. modifiedDirs = null;
  214. }
  215. public List<String> getClasspathElementsWithModifiedContents() {
  216. return modifiedDirs;
  217. }
  218. public void setProjectEncoding(String encoding) {
  219. this.encoding = encoding;
  220. }
  221. public String getProjectEncoding() {
  222. return this.encoding;
  223. }
  224. public String getProcessor() {
  225. return this.processor;
  226. }
  227. public String getProcessorPath() {
  228. return this.processorPath;
  229. }
  230. @Override
  231. public String getModulepath() {
  232. return null;
  233. }
  234. @Override
  235. public String getModuleSourcepath() {
  236. return null;
  237. }
  238. }