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 4.9KB

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