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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.HashMap;
  16. import java.util.Hashtable;
  17. import java.util.List;
  18. import java.util.Map;
  19. import java.util.Set;
  20. import org.aspectj.tools.ajc.AjcTests;
  21. import org.aspectj.util.FileUtil;
  22. /**
  23. * Test implementation of ICompilerConfiguration. Allows users to configure
  24. * the settings via setter methods. By default returns null for all options
  25. * except getClasspath(), getJavaOptionsMap() (by default returns that it's
  26. * 1.3 compliant), getOutputLocationManager(), getSourcePathResources() (it
  27. * recursively looks for them) and getProjectSourceFiles(). If no source
  28. * files are specified by the user, then getProjectSourceFiles() returns
  29. * an empty list.
  30. */
  31. public class TestCompilerConfiguration implements ICompilerConfiguration {
  32. private String projectPath;
  33. private Set aspectpath;
  34. private Set inpath;
  35. private String outjar;
  36. private Map javaOptions;
  37. private String nonStandardOptions;
  38. private List projectSourceFiles = new ArrayList();
  39. private Map sourcePathResources;
  40. private String srcDirName = "src";
  41. private IOutputLocationManager outputLoc;
  42. public TestCompilerConfiguration(String projectPath) {
  43. this.projectPath = projectPath;
  44. }
  45. public Set getAspectPath() {
  46. return aspectpath;
  47. }
  48. public String getClasspath() {
  49. return projectPath
  50. + File.pathSeparator
  51. + System.getProperty("sun.boot.class.path")
  52. + File.pathSeparator
  53. + AjcTests.aspectjrtClasspath();
  54. }
  55. public Set getInpath() {
  56. return inpath;
  57. }
  58. public Map getJavaOptionsMap() {
  59. if (javaOptions == null) {
  60. javaOptions = new Hashtable();
  61. javaOptions.put(JavaOptions.COMPLIANCE_LEVEL,JavaOptions.VERSION_13);
  62. javaOptions.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL,JavaOptions.VERSION_13);
  63. }
  64. return javaOptions;
  65. }
  66. public String getNonStandardOptions() {
  67. return nonStandardOptions;
  68. }
  69. public String getOutJar() {
  70. return outjar;
  71. }
  72. public IOutputLocationManager getOutputLocationManager() {
  73. if (outputLoc == null) {
  74. outputLoc = new TestOutputLocationManager(projectPath);
  75. }
  76. return outputLoc;
  77. }
  78. public List getProjectSourceFiles() {
  79. return projectSourceFiles;
  80. }
  81. public Map getSourcePathResources() {
  82. if (sourcePathResources == null) {
  83. sourcePathResources = new HashMap();
  84. /* Allow the user to override the testProjectPath by using sourceRoots */
  85. File[] srcBase = new File[] { new File(projectPath + File.separator + srcDirName) };
  86. for (int j = 0; j < srcBase.length; j++) {
  87. File[] fromResources = FileUtil.listFiles(srcBase[j], new FileFilter() {
  88. public boolean accept(File pathname) {
  89. String name = pathname.getName().toLowerCase();
  90. return !name.endsWith(".class")
  91. && !name.endsWith(".java")
  92. && !name.endsWith(".aj")
  93. && !name.endsWith(".lst")
  94. && !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 aspectPath) {
  107. this.aspectpath = aspectPath;
  108. }
  109. public void setInpath(Set 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 projectSourceFiles) {
  122. this.projectSourceFiles = projectSourceFiles;
  123. }
  124. public void setSourcePathResources(Map sourcePathResources) {
  125. this.sourcePathResources = sourcePathResources;
  126. }
  127. public void setSourceDir(String srcDirName) {
  128. this.srcDirName = srcDirName;
  129. }
  130. }