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.

TestCompilerConfiguration.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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.ajde.ui.utils;
  12. import java.io.File;
  13. import java.io.FileFilter;
  14. import java.util.ArrayList;
  15. import java.util.Collections;
  16. import java.util.HashMap;
  17. import java.util.Hashtable;
  18. import java.util.List;
  19. import java.util.Map;
  20. import java.util.Set;
  21. import org.aspectj.ajde.core.ICompilerConfiguration;
  22. import org.aspectj.ajde.core.IOutputLocationManager;
  23. import org.aspectj.ajde.core.JavaOptions;
  24. import org.aspectj.tools.ajc.AjcTests;
  25. import org.aspectj.util.FileUtil;
  26. import org.aspectj.util.LangUtil;
  27. /**
  28. * Test implementation of ICompilerConfiguration. Allows users to configure the settings via setter methods. By default returns null
  29. * for all options except getClasspath(), getJavaOptionsMap() (by default returns that it's 1.3 compliant),
  30. * getOutputLocationManager(), getSourcePathResources() (it recursively looks for them) and getProjectSourceFiles(). If no source
  31. * files are specified by the user, then getProjectSourceFiles() returns an empty list.
  32. */
  33. public class TestCompilerConfiguration implements ICompilerConfiguration {
  34. private String projectPath;
  35. private Set aspectpath;
  36. private Set inpath;
  37. private String outjar;
  38. private Map<String,String> javaOptions;
  39. private String nonStandardOptions;
  40. private List projectSourceFiles = new ArrayList();
  41. private Map sourcePathResources;
  42. private String srcDirName = "src";
  43. private IOutputLocationManager outputLoc;
  44. public TestCompilerConfiguration(String projectPath) {
  45. this.projectPath = projectPath;
  46. }
  47. public void configurationRead() {
  48. }
  49. public List getProjectXmlConfigFiles() {
  50. return Collections.EMPTY_LIST;
  51. }
  52. public Set getAspectPath() {
  53. return aspectpath;
  54. }
  55. public String getClasspath() {
  56. String cp = projectPath + File.pathSeparator + System.getProperty("sun.boot.class.path") + File.pathSeparator
  57. + AjcTests.aspectjrtClasspath();
  58. if (LangUtil.is19VMOrGreater()) {
  59. cp = LangUtil.getJrtFsFilePath()+File.pathSeparator+cp;
  60. }
  61. return cp;
  62. }
  63. public Set getInpath() {
  64. return inpath;
  65. }
  66. public Map<String,String> getJavaOptionsMap() {
  67. if (javaOptions == null) {
  68. javaOptions = new Hashtable<>();
  69. javaOptions.put(JavaOptions.COMPLIANCE_LEVEL, JavaOptions.VERSION_13);
  70. javaOptions.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL, JavaOptions.VERSION_13);
  71. }
  72. return javaOptions;
  73. }
  74. public String getNonStandardOptions() {
  75. return nonStandardOptions;
  76. }
  77. public String getOutJar() {
  78. return outjar;
  79. }
  80. public IOutputLocationManager getOutputLocationManager() {
  81. if (outputLoc == null) {
  82. outputLoc = new TestOutputLocationManager(projectPath);
  83. }
  84. return outputLoc;
  85. }
  86. public List getProjectSourceFiles() {
  87. return projectSourceFiles;
  88. }
  89. public List getProjectSourceFilesChanged() {
  90. return null;
  91. }
  92. public Map getSourcePathResources() {
  93. if (sourcePathResources == null) {
  94. sourcePathResources = new HashMap();
  95. /* Allow the user to override the testProjectPath by using sourceRoots */
  96. File[] srcBase = new File[] { new File(projectPath + File.separator + srcDirName) };
  97. for (int j = 0; j < srcBase.length; j++) {
  98. File[] fromResources = FileUtil.listFiles(srcBase[j], new FileFilter() {
  99. public boolean accept(File pathname) {
  100. String name = pathname.getName().toLowerCase();
  101. return !name.endsWith(".class") && !name.endsWith(".java") && !name.endsWith(".aj")
  102. && !name.endsWith(".lst") && !name.endsWith(".jar");
  103. }
  104. });
  105. for (int i = 0; i < fromResources.length; i++) {
  106. String normPath = FileUtil.normalizedPath(fromResources[i], srcBase[j]);
  107. sourcePathResources.put(normPath, fromResources[i]);
  108. }
  109. }
  110. }
  111. return sourcePathResources;
  112. }
  113. // -------------------- setter methods useful for testing ---------------
  114. public void setAspectPath(Set aspectPath) {
  115. this.aspectpath = aspectPath;
  116. }
  117. public void setInpath(Set inpath) {
  118. this.inpath = inpath;
  119. }
  120. public void setOutjar(String outjar) {
  121. this.outjar = outjar;
  122. }
  123. public void setJavaOptions(Map javaOptions) {
  124. this.javaOptions = javaOptions;
  125. }
  126. public void setNonStandardOptions(String options) {
  127. this.nonStandardOptions = options;
  128. }
  129. public void setProjectSourceFiles(List projectSourceFiles) {
  130. this.projectSourceFiles = projectSourceFiles;
  131. }
  132. public void setSourcePathResources(Map sourcePathResources) {
  133. this.sourcePathResources = sourcePathResources;
  134. }
  135. public void setSourceDir(String srcDirName) {
  136. this.srcDirName = srcDirName;
  137. }
  138. public int getConfigurationChanges() {
  139. return ICompilerConfiguration.EVERYTHING;
  140. }
  141. public List getClasspathElementsWithModifiedContents() {
  142. return null;
  143. }
  144. public String getProjectEncoding() {
  145. return null;
  146. }
  147. public String getProcessor() {
  148. return null;
  149. }
  150. public String getProcessorPath() {
  151. return null;
  152. }
  153. @Override
  154. public String getModulepath() {
  155. return null;
  156. }
  157. @Override
  158. public String getModuleSourcepath() {
  159. return null;
  160. }
  161. }