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.

FileSpec.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*******************************************************************************
  2. * Copyright (c) 2010 Contributors
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * Andy Clement - SpringSource
  10. *******************************************************************************/
  11. package org.aspectj.testing;
  12. import java.io.File;
  13. import org.aspectj.tools.ajc.AjcTestCase;
  14. /**
  15. * Support simple file system operations in a test spec. Example:<br>
  16. * &lt;file deletefile="foo.jar"/&gt; will delete the file foo.jar from the sandbox.
  17. *
  18. * @author Andy Clement
  19. */
  20. public class FileSpec implements ITestStep {
  21. private String toDelete;
  22. // private String dir;
  23. // private AjcTest test;
  24. public FileSpec() {
  25. }
  26. public void setDeletefile(String file) {
  27. this.toDelete = file;
  28. }
  29. public void addExpectedMessage(ExpectedMessageSpec message) {
  30. }
  31. public void execute(AjcTestCase inTestCase) {
  32. File sandbox = inTestCase.getSandboxDirectory();
  33. if (toDelete != null) {
  34. File targetForDeletion = new File(sandbox, toDelete);
  35. if (targetForDeletion.isFile()) {
  36. targetForDeletion.delete();
  37. } else {
  38. recursiveDelete(targetForDeletion);
  39. }
  40. }
  41. }
  42. private void recursiveDelete(File toDelete) {
  43. if (toDelete.isDirectory()) {
  44. File[] files = toDelete.listFiles();
  45. for (File f: files) {
  46. recursiveDelete(f);
  47. }
  48. }
  49. toDelete.delete();
  50. }
  51. public void setBaseDir(String dir) {
  52. // this.dir = dir;
  53. }
  54. public void setTest(AjcTest test) {
  55. // this.test = test;
  56. }
  57. }