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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 javax.swing.JFrame;
  19. import junit.framework.AssertionFailedError;
  20. import junit.framework.TestCase;
  21. import org.aspectj.ajde.Ajde;
  22. import org.aspectj.ajde.IconRegistry;
  23. import org.aspectj.ajde.core.AjCompiler;
  24. import org.aspectj.ajde.ui.utils.TestBuildProgressMonitor;
  25. import org.aspectj.ajde.ui.utils.TestCompilerConfiguration;
  26. import org.aspectj.ajde.ui.utils.TestEditorAdapter;
  27. import org.aspectj.ajde.ui.utils.TestIdeUIAdapter;
  28. import org.aspectj.ajde.ui.utils.TestMessageHandler;
  29. import org.aspectj.ajde.ui.utils.TestRuntimeProperties;
  30. import org.aspectj.asm.AsmManager;
  31. import org.aspectj.tools.ajc.Ajc;
  32. public class AjdeTestCase extends TestCase {
  33. public final static String testdataSrcDir = "../ajde/testdata";
  34. protected static File sandboxDir;
  35. private String projectDir;
  36. protected void setUp() throws Exception {
  37. super.setUp();
  38. // Create a sandbox in which to work
  39. sandboxDir = Ajc.createEmptySandbox();
  40. // AMC - added this next line as a temporary workaround for
  41. // listener leakage in AsmManager induced by the Ajde test suite.
  42. AsmManager.getDefault().removeAllListeners();
  43. }
  44. protected void tearDown() throws Exception {
  45. super.tearDown();
  46. projectDir = null;
  47. sandboxDir = null;
  48. }
  49. /**
  50. * Fill in the working directory with the project files and
  51. * creates a compiler instance for this project
  52. */
  53. public void initialiseProject(String projectName) {
  54. File projectSrc=new File(testdataSrcDir + File.separatorChar + projectName);
  55. File destination=new File(getWorkingDir(),projectName);
  56. if (!destination.exists()) {destination.mkdir();}
  57. copy(projectSrc,destination);
  58. projectDir = destination.getAbsolutePath();
  59. // need to initialize via AjdeUIManager
  60. Ajde.getDefault().init(
  61. new TestCompilerConfiguration(projectDir),
  62. new TestMessageHandler(),
  63. new TestBuildProgressMonitor(),
  64. new TestEditorAdapter(),
  65. new TestIdeUIAdapter(),
  66. new IconRegistry(),
  67. new JFrame(),
  68. new TestRuntimeProperties(),
  69. true);
  70. }
  71. /**
  72. * @return the working directory
  73. */
  74. protected File getWorkingDir() {
  75. return sandboxDir;
  76. }
  77. /**
  78. * @return the absolute path of the project directory
  79. * for example c:\temp\ajcSandbox\ajcTest15200.tmp\myProject
  80. */
  81. protected String getAbsoluteProjectDir() {
  82. return projectDir;
  83. }
  84. /**
  85. * Copy the contents of some directory to another location - the
  86. * copy is recursive.
  87. */
  88. private void copy(File from, File to) {
  89. String contents[] = from.list();
  90. if (contents==null) return;
  91. for (int i = 0; i < contents.length; i++) {
  92. String string = contents[i];
  93. File f = new File(from,string);
  94. File t = new File(to,string);
  95. if (f.isDirectory()) {
  96. t.mkdir();
  97. copy(f,t);
  98. } else if (f.isFile()) {
  99. try {
  100. org.aspectj.util.FileUtil.copyFile(f,t);
  101. } catch (IOException e) {
  102. throw new AssertionFailedError("Unable to copy " + f + " to " + t);
  103. }
  104. }
  105. }
  106. }
  107. protected File openFile(String path) {
  108. return new File(projectDir + File.separatorChar + path);
  109. }
  110. public void doBuild(String configFile) {
  111. getCompilerForConfigFileWithName(configFile).build();
  112. }
  113. public AjCompiler getCompilerForConfigFileWithName(String configFileName) {
  114. return Ajde.getDefault().getCompilerForConfigFile(projectDir + File.separator + configFileName);
  115. }
  116. public List getErrorMessages(String configFileName) {
  117. return ((TestMessageHandler)getCompilerForConfigFileWithName(configFileName).getMessageHandler()).getErrors();
  118. }
  119. public List getMessages(String configFileName) {
  120. return ((TestMessageHandler)getCompilerForConfigFileWithName(configFileName).getMessageHandler()).getMessages();
  121. }
  122. protected String genStructureModelExternFilePath(String configFilePath) {
  123. return configFilePath.substring(0, configFilePath.lastIndexOf(".lst")) + ".ajsym";
  124. }
  125. }