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

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