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.

AjdeTestCase.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /********************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Xerox/PARC initial implementation
  11. * Helen Hawkins Converted to new interface (bug 148190) and
  12. * to use a sandbox directory
  13. *******************************************************************/
  14. package org.aspectj.ajde;
  15. import java.io.File;
  16. import java.io.IOException;
  17. import java.util.List;
  18. import org.aspectj.ajde.core.AjCompiler;
  19. import org.aspectj.ajde.ui.utils.TestBuildProgressMonitor;
  20. import org.aspectj.ajde.ui.utils.TestCompilerConfiguration;
  21. import org.aspectj.ajde.ui.utils.TestEditorAdapter;
  22. import org.aspectj.ajde.ui.utils.TestIdeUIAdapter;
  23. import org.aspectj.ajde.ui.utils.TestMessageHandler;
  24. import org.aspectj.ajde.ui.utils.TestRuntimeProperties;
  25. import org.aspectj.testing.util.TestUtil;
  26. import junit.framework.AssertionFailedError;
  27. import junit.framework.TestCase;
  28. public abstract class AjdeTestCase extends TestCase {
  29. public final static String testdataSrcDir = "../ajde/testdata";
  30. protected static File sandboxDir;
  31. private String projectDir;
  32. protected void setUp() throws Exception {
  33. super.setUp();
  34. // Create a sandbox in which to work
  35. sandboxDir = TestUtil.createEmptySandbox();
  36. // AMC - added this next line as a temporary workaround for
  37. // listener leakage in AsmManager induced by the Ajde test suite.
  38. // Ajde.getDefault().getModel().removeAllListeners();
  39. }
  40. protected void tearDown() throws Exception {
  41. super.tearDown();
  42. projectDir = null;
  43. sandboxDir = null;
  44. }
  45. /**
  46. * Fill in the working directory with the project files and creates a compiler instance for this project
  47. */
  48. public void initialiseProject(String projectName) {
  49. File projectSrc = new File(testdataSrcDir + File.separatorChar + projectName);
  50. File destination = new File(getWorkingDir(), projectName);
  51. if (!destination.exists()) {
  52. destination.mkdir();
  53. }
  54. copy(projectSrc, destination);
  55. projectDir = destination.getAbsolutePath();
  56. // need to initialize via AjdeUIManager
  57. Ajde.getDefault().init(new TestCompilerConfiguration(projectDir), new TestMessageHandler(), new TestBuildProgressMonitor(),
  58. new TestEditorAdapter(), new TestIdeUIAdapter(), new IconRegistry(), null, // new JFrame(),
  59. new TestRuntimeProperties(), true);
  60. }
  61. /**
  62. * @return the working directory
  63. */
  64. protected File getWorkingDir() {
  65. return sandboxDir;
  66. }
  67. /**
  68. * @return the absolute path of the project directory for example c:\temp\ajcSandbox\ajcTest15200.tmp\myProject
  69. */
  70. protected String getAbsoluteProjectDir() {
  71. return projectDir;
  72. }
  73. /**
  74. * Copy the contents of some directory to another location - the copy is recursive.
  75. */
  76. private void copy(File from, File to) {
  77. String contents[] = from.list();
  78. if (contents == null)
  79. return;
  80. for (String string : contents) {
  81. File f = new File(from, string);
  82. File t = new File(to, string);
  83. if (f.isDirectory()) {
  84. t.mkdir();
  85. copy(f, t);
  86. } else if (f.isFile()) {
  87. try {
  88. org.aspectj.util.FileUtil.copyFile(f, t);
  89. } catch (IOException e) {
  90. throw new AssertionFailedError("Unable to copy " + f + " to " + t);
  91. }
  92. }
  93. }
  94. }
  95. protected File openFile(String path) {
  96. return new File(projectDir + File.separatorChar + path);
  97. }
  98. public void doBuild(String configFile) {
  99. getCompilerForConfigFileWithName(configFile).build();
  100. }
  101. public AjCompiler getCompilerForConfigFileWithName(String configFileName) {
  102. return Ajde.getDefault().getCompilerForConfigFile(projectDir + File.separator + configFileName);
  103. }
  104. public List getErrorMessages(String configFileName) {
  105. return ((TestMessageHandler) getCompilerForConfigFileWithName(configFileName).getMessageHandler()).getErrors();
  106. }
  107. public List getMessages(String configFileName) {
  108. return ((TestMessageHandler) getCompilerForConfigFileWithName(configFileName).getMessageHandler()).getMessages();
  109. }
  110. protected String genStructureModelExternFilePath(String configFilePath) {
  111. return configFilePath.substring(0, configFilePath.lastIndexOf(".lst")) + ".ajsym";
  112. }
  113. }