Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

AjdeCoreTestCase.java 4.1KB

pirms 17 gadiem
pirms 17 gadiem
pirms 9 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 9 gadiem
pirms 17 gadiem
pirms 17 gadiem
pirms 9 gadiem
pirms 17 gadiem
pirms 12 gadiem
pirms 17 gadiem
pirms 17 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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.IOException;
  14. import java.util.ArrayList;
  15. import java.util.List;
  16. import junit.framework.AssertionFailedError;
  17. import junit.framework.TestCase;
  18. import org.aspectj.ajde.core.TestMessageHandler.TestMessage;
  19. import org.aspectj.testing.util.TestUtil;
  20. /**
  21. * Testcase class to be used by all ajde.core tests. Provides helper methods to set up the environment in a sandbox as well as to
  22. * drive a build.
  23. */
  24. public abstract class AjdeCoreTestCase extends TestCase {
  25. public final static String testdataSrcDir = "../ajde.core/testdata";
  26. protected static File sandboxDir;
  27. private String projectDir;
  28. private AjCompiler compiler;
  29. protected void setUp() throws Exception {
  30. super.setUp();
  31. // Create a sandbox in which to work
  32. sandboxDir = TestUtil.createEmptySandbox();
  33. // AMC - added this next line as a temporary workaround for
  34. // listener leakage in AsmManager induced by the Ajde test suite.
  35. // AsmManager.getDefault().removeAllListeners();
  36. }
  37. protected void tearDown() throws Exception {
  38. super.tearDown();
  39. compiler.clearLastState();
  40. compiler = null;
  41. }
  42. /**
  43. * Fill in the working directory with the project files and creates a compiler instance for this project
  44. */
  45. public void initialiseProject(String projectName) throws IOException {
  46. File projectSrc = new File(testdataSrcDir + File.separatorChar + projectName);
  47. File destination = new File(getWorkingDir(), projectName);
  48. if (!destination.exists()) {
  49. destination.mkdir();
  50. }
  51. copy(projectSrc, destination);
  52. projectDir = destination.getCanonicalPath();// getAbsolutePath();
  53. compiler = new AjCompiler(projectDir, new TestCompilerConfiguration(projectDir), new TestBuildProgressMonitor(),
  54. new TestMessageHandler());
  55. }
  56. /**
  57. * @return the working directory
  58. */
  59. protected File getWorkingDir() {
  60. return sandboxDir;
  61. }
  62. /**
  63. * @return the absolute path of the project directory for example c:\temp\ajcSandbox\ajcTest15200.tmp\myProject
  64. */
  65. protected String getAbsoluteProjectDir() {
  66. return projectDir;
  67. }
  68. /**
  69. * Copy the contents of some directory to another location - the copy is recursive.
  70. */
  71. private void copy(File from, File to) {
  72. String contents[] = from.list();
  73. if (contents == null)
  74. return;
  75. for (String string : contents) {
  76. File f = new File(from, string);
  77. File t = new File(to, string);
  78. if (f.isDirectory()) {
  79. t.mkdir();
  80. copy(f, t);
  81. } else if (f.isFile()) {
  82. try {
  83. org.aspectj.util.FileUtil.copyFile(f, t);
  84. } catch (IOException e) {
  85. throw new AssertionFailedError("Unable to copy " + f + " to " + t);
  86. }
  87. }
  88. }
  89. }
  90. protected File openFile(String path) {
  91. return new File(projectDir + File.separatorChar + path);
  92. }
  93. public void doBuild() {
  94. doBuild(true);
  95. }
  96. public void doBuild(boolean buildFresh) {
  97. if (buildFresh) {
  98. compiler.buildFresh();
  99. } else {
  100. compiler.build();
  101. }
  102. }
  103. public AjCompiler getCompiler() {
  104. return compiler;
  105. }
  106. public boolean checkFor(String what) {
  107. List<TestMessage> ll = ((TestMessageHandler) compiler.getMessageHandler()).getMessages();
  108. for (TestMessage element: ll) {
  109. if (element.toString().contains(what))
  110. return true;
  111. }
  112. return false;
  113. }
  114. public void dumpTaskData() {
  115. List<TestMessage> ll = ((TestMessageHandler) compiler.getMessageHandler()).getMessages();
  116. for (TestMessage element: ll) {
  117. System.out.println("RecordedMessage>" + element);
  118. }
  119. }
  120. public List<String> getSourceFileList(String[] files) {
  121. List<String> sourceFiles = new ArrayList<>();
  122. for (String file : files) {
  123. sourceFiles.add(getAbsoluteProjectDir() + File.separator + file);
  124. }
  125. return sourceFiles;
  126. }
  127. }