Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AjConfigTest.java 8.6KB

17 лет назад
17 лет назад
17 лет назад
12 лет назад
17 лет назад
5 лет назад
17 лет назад
5 лет назад
17 лет назад
5 лет назад
17 лет назад
12 лет назад
17 лет назад
9 лет назад
17 лет назад
5 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
12 лет назад
5 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
5 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
5 лет назад
17 лет назад
5 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
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.tests;
  12. import java.io.File;
  13. import java.io.IOException;
  14. import java.util.ArrayList;
  15. import java.util.HashMap;
  16. import java.util.HashSet;
  17. import java.util.Iterator;
  18. import java.util.List;
  19. import java.util.Map;
  20. import java.util.Set;
  21. import org.aspectj.ajde.core.AjdeCoreTestCase;
  22. import org.aspectj.ajde.core.IOutputLocationManager;
  23. import org.aspectj.ajde.core.JavaOptions;
  24. import org.aspectj.ajde.core.TestCompilerConfiguration;
  25. import org.aspectj.ajde.core.internal.AjdeCoreBuildManager;
  26. import org.aspectj.ajdt.internal.core.builder.AjBuildConfig;
  27. /**
  28. * Tests that the AjBuildConfig is populated correctly from the ICompilerConfiguration
  29. */
  30. public class AjConfigTest extends AjdeCoreTestCase {
  31. private TestCompilerConfiguration compilerConfig;
  32. private AjdeCoreBuildManager ajdeBuildManager;
  33. @Override
  34. protected void setUp() throws Exception {
  35. super.setUp();
  36. initialiseProject("SimpleProject");
  37. ajdeBuildManager = new AjdeCoreBuildManager(getCompiler());
  38. compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration();
  39. }
  40. @Override
  41. protected void tearDown() throws Exception {
  42. super.tearDown();
  43. ajdeBuildManager = null;
  44. compilerConfig = null;
  45. }
  46. public void testJavaOptionsMap() {
  47. Map<String,String> options = JavaOptions.getDefaultJavaOptions();
  48. options.put(JavaOptions.WARN_DEPRECATION, JavaOptions.WARNING);
  49. compilerConfig.setJavaOptions(options);
  50. Map<String,String> found = genAjBuildConfig().getOptions().getMap();
  51. String warning = found.get(JavaOptions.WARN_DEPRECATION);
  52. assertEquals("expected to be warning on deprecation but found setting " + " was " + warning, JavaOptions.WARNING, warning);
  53. }
  54. public void testAspectPath() {
  55. Set<File> aspects = new HashSet<>();
  56. compilerConfig.setAspectPath(aspects);
  57. AjBuildConfig buildConfig = genAjBuildConfig();
  58. List<File> aPath = buildConfig.getAspectpath();
  59. assertTrue("no aspect path", aPath.isEmpty());
  60. File f = new File("jarone.jar");
  61. aspects.add(f);
  62. buildConfig = genAjBuildConfig();
  63. List<File> aPath2 = buildConfig.getAspectpath();
  64. assertEquals("expected one entry on the aspectpath but found " + aPath2.size(), 1, aPath2.size());
  65. assertTrue("expected to find file " + f.getName() + " on the aspectpath" + " but didn't", aPath2.contains(f));
  66. File f2 = new File("jartwo.jar");
  67. aspects.add(f2);
  68. buildConfig = genAjBuildConfig();
  69. List<File> aPath3 = buildConfig.getAspectpath();
  70. assertEquals("expected two entries on the aspectpath but found " + aPath3.size(), 2, aPath3.size());
  71. assertTrue("expected to find file " + f.getName() + " on the aspectpath" + " but didn't", aPath3.contains(f));
  72. assertTrue("expected to find file " + f2.getName() + " on the aspectpath" + " but didn't", aPath3.contains(f2));
  73. }
  74. public void testInpath() {
  75. Set<File> jars = new HashSet<>();
  76. compilerConfig.setInpath(jars);
  77. AjBuildConfig buildConfig = genAjBuildConfig();
  78. List<File> inJars = buildConfig.getInpath();
  79. assertTrue("expected to find nothing on the inpath but found " + inJars, inJars.isEmpty());
  80. File f = new File("jarone.jar");
  81. jars.add(f);
  82. buildConfig = genAjBuildConfig();
  83. List<File> inJars2 = buildConfig.getInpath();
  84. assertTrue("expected to find one file on the inpath but found " + inJars2.size() + ": " + inJars2, inJars2.size() == 1);
  85. assertTrue("expected to find file " + f.getName() + " on the inpath" + " but didn't", inJars2.contains(f));
  86. File f2 = new File("jartwo.jar");
  87. jars.add(f2);
  88. buildConfig = genAjBuildConfig();
  89. List<File> inJars3 = buildConfig.getInpath();
  90. assertEquals("expected two entries on the inpath but found " + inJars3.size(), 2, inJars3.size());
  91. assertTrue("expected to find file " + f.getName() + " on the inpath" + " but didn't", inJars3.contains(f));
  92. assertTrue("expected to find file " + f2.getName() + " on the inpath" + " but didn't", inJars3.contains(f2));
  93. }
  94. public void testOutJar() {
  95. String outJar = "mybuild.jar";
  96. compilerConfig.setOutjar(outJar);
  97. AjBuildConfig buildConfig = genAjBuildConfig();
  98. assertNotNull("expected to find a non null output jar but " + "didn't", buildConfig.getOutputJar());
  99. assertEquals("expected to find outjar 'mybuild.jar' but instead " + "found " + buildConfig.getOutputJar().toString(),
  100. outJar, buildConfig.getOutputJar().toString());
  101. }
  102. public void testXHasMember() {
  103. compilerConfig.setNonStandardOptions("-XhasMember");
  104. AjBuildConfig buildConfig = genAjBuildConfig();
  105. assertTrue("expected XhasMember to be enabled but wasn't ", buildConfig.isXHasMemberEnabled());
  106. }
  107. public void testOutputLocationManager() {
  108. IOutputLocationManager mgr = compilerConfig.getOutputLocationManager();
  109. String expectedDefaultOutputDir = mgr.getDefaultOutputLocation().getAbsolutePath();
  110. AjBuildConfig buildConfig = genAjBuildConfig();
  111. String found = buildConfig.getCompilationResultDestinationManager().getDefaultOutputLocation().getAbsolutePath();
  112. assertEquals("expected to find default output location " + expectedDefaultOutputDir + " but found " + found,
  113. expectedDefaultOutputDir, found);
  114. }
  115. public void testSourcePathResources() {
  116. Map<String, File> m = new HashMap<>();
  117. m.put("newFile.txt", getWorkingDir());
  118. compilerConfig.setSourcePathResources(m);
  119. AjBuildConfig buildConfig = genAjBuildConfig();
  120. Map<String, File> found = buildConfig.getSourcePathResources();
  121. for (String resource : found.keySet()) {
  122. assertEquals("expected to find resource with name newFile.txt but " + "found " + resource, "newFile.txt", resource);
  123. File from = buildConfig.getSourcePathResources().get(resource);
  124. assertEquals("expected to find resource with file " + getWorkingDir() + "but found " + from, getWorkingDir(), from);
  125. }
  126. }
  127. public void testClasspath() {
  128. String classpath = compilerConfig.getClasspath();
  129. List<String> found = genAjBuildConfig().getClasspath();
  130. StringBuffer sb = new StringBuffer();
  131. for (Iterator<String> iterator = found.iterator(); iterator.hasNext();) {
  132. String name = iterator.next();
  133. sb.append(name);
  134. if (iterator.hasNext()) {
  135. sb.append(File.pathSeparator);
  136. }
  137. }
  138. assertEquals("expected to find classpath " + classpath + " but found " + sb.toString(), classpath, sb.toString());
  139. }
  140. public void testNonStandardOptions() {
  141. compilerConfig.setNonStandardOptions("-XterminateAfterCompilation");
  142. AjBuildConfig buildConfig = genAjBuildConfig();
  143. assertTrue("XterminateAfterCompilation", buildConfig.isTerminateAfterCompilation());
  144. compilerConfig.setNonStandardOptions("-XserializableAspects");
  145. buildConfig = genAjBuildConfig();
  146. assertTrue("XserializableAspects", buildConfig.isXserializableAspects());
  147. compilerConfig.setNonStandardOptions("-XnoInline");
  148. buildConfig = genAjBuildConfig();
  149. assertTrue("XnoInline", buildConfig.isXnoInline());
  150. compilerConfig.setNonStandardOptions("-Xlint");
  151. buildConfig = genAjBuildConfig();
  152. assertEquals("Xlint", AjBuildConfig.AJLINT_DEFAULT, buildConfig.getLintMode());
  153. compilerConfig.setNonStandardOptions("-Xlint:error");
  154. buildConfig = genAjBuildConfig();
  155. assertEquals("Xlint", AjBuildConfig.AJLINT_ERROR, buildConfig.getLintMode());
  156. // and a few options thrown in at once
  157. compilerConfig.setNonStandardOptions("-Xlint -XnoInline -XserializableAspects");
  158. buildConfig = genAjBuildConfig();
  159. assertEquals("Xlint", AjBuildConfig.AJLINT_DEFAULT, buildConfig.getLintMode());
  160. assertTrue("XnoInline", buildConfig.isXnoInline());
  161. assertTrue("XserializableAspects", buildConfig.isXserializableAspects());
  162. }
  163. public void testProjectSourceFiles() throws IOException {
  164. String f = getAbsoluteProjectDir() + File.separator + "C.java";
  165. List<String> files = new ArrayList<>();
  166. files.add(f);
  167. compilerConfig.setProjectSourceFiles(files);
  168. AjBuildConfig buildConfig = genAjBuildConfig();
  169. String found = buildConfig.getFiles().get(0).getCanonicalPath();// AbsolutePath();
  170. assertEquals("expected source file " + f + ", but found " + found, f, found);
  171. }
  172. private AjBuildConfig genAjBuildConfig() {
  173. AjBuildConfig buildConfig = ajdeBuildManager.generateAjBuildConfig();
  174. assertNotNull("exepected to generate a non null AjBuildConfig but " + "didn't", buildConfig);
  175. return buildConfig;
  176. }
  177. }