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.5KB

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 v 2.0
  5. * which accompanies this distribution and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  7. *
  8. * Contributors: IBM Corporation - initial API and implementation
  9. * Helen Hawkins - initial version
  10. *******************************************************************/
  11. package org.aspectj.ajde.core;
  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.testing.util.TestUtil;
  22. import org.aspectj.util.FileUtil;
  23. import org.aspectj.util.LangUtil;
  24. /**
  25. * Test implementation of ICompilerConfiguration. Allows users to configure the settings via setter methods. By default returns null
  26. * for all options except getClasspath(), getJavaOptionsMap() (by default returns that it's 1.3 compliant),
  27. * getOutputLocationManager(), getSourcePathResources() (it recursively looks for them) and getProjectSourceFiles(). If no source
  28. * files are specified by the user, then getProjectSourceFiles() returns an empty list.
  29. */
  30. public class TestCompilerConfiguration implements ICompilerConfiguration {
  31. private String projectPath;
  32. private Set<File> aspectpath;
  33. private Set<File> inpath;
  34. private String outjar;
  35. private Map<String, String> javaOptions;
  36. private String nonStandardOptions;
  37. private List<String> projectSourceFiles = new ArrayList<>();
  38. private Map<String, File> sourcePathResources;
  39. private String srcDirName = "src";
  40. private IOutputLocationManager outputLoc;
  41. public TestCompilerConfiguration(String projectPath) {
  42. this.projectPath = projectPath;
  43. }
  44. public Set<File> getAspectPath() {
  45. return aspectpath;
  46. }
  47. public List<String> getProjectXmlConfigFiles() {
  48. return Collections.emptyList();
  49. }
  50. public String getClasspath() {
  51. StringBuilder classpath = new StringBuilder();
  52. classpath.append(projectPath);
  53. if (LangUtil.is9VMOrGreater()) {
  54. classpath.append(File.pathSeparator).append(LangUtil.getJrtFsFilePath());
  55. } else {
  56. classpath.append(File.pathSeparator).append(System.getProperty("sun.boot.class.path"));
  57. }
  58. classpath.append(File.pathSeparator).append(TestUtil.aspectjrtClasspath());
  59. return classpath.toString();
  60. }
  61. public Set<File> getInpath() {
  62. return inpath;
  63. }
  64. public Map<String, String> getJavaOptionsMap() {
  65. if (javaOptions == null) {
  66. javaOptions = new Hashtable<>();
  67. javaOptions.put(JavaOptions.COMPLIANCE_LEVEL, JavaOptions.VERSION_13);
  68. javaOptions.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL, JavaOptions.VERSION_13);
  69. }
  70. return javaOptions;
  71. }
  72. public String getNonStandardOptions() {
  73. return nonStandardOptions;
  74. }
  75. public String getOutJar() {
  76. return outjar;
  77. }
  78. public IOutputLocationManager getOutputLocationManager() {
  79. if (outputLoc == null) {
  80. outputLoc = new TestOutputLocationManager(projectPath);
  81. }
  82. return outputLoc;
  83. }
  84. public List<String> getProjectSourceFiles() {
  85. return projectSourceFiles;
  86. }
  87. public List<File> getProjectSourceFilesChanged() {
  88. return null;
  89. }
  90. public void configurationRead() {
  91. }
  92. public Map<String, File> 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 (File file : srcBase) {
  98. File[] fromResources = FileUtil.listFiles(file, 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 (File fromResource : fromResources) {
  106. String normPath = FileUtil.normalizedPath(fromResource, file);
  107. sourcePathResources.put(normPath, fromResource);
  108. }
  109. }
  110. }
  111. return sourcePathResources;
  112. }
  113. // -------------------- setter methods useful for testing ---------------
  114. public void setAspectPath(Set<File> aspectPath) {
  115. this.aspectpath = aspectPath;
  116. }
  117. public void setInpath(Set<File> inpath) {
  118. this.inpath = inpath;
  119. }
  120. public void setOutjar(String outjar) {
  121. this.outjar = outjar;
  122. }
  123. public void setJavaOptions(Map<String,String> javaOptions) {
  124. this.javaOptions = javaOptions;
  125. }
  126. public void setNonStandardOptions(String options) {
  127. this.nonStandardOptions = options;
  128. }
  129. public void setProjectSourceFiles(List<String> projectSourceFiles) {
  130. this.projectSourceFiles = projectSourceFiles;
  131. }
  132. public void setSourcePathResources(Map<String, File> 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<String> 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. }