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.

OutxmlTest.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* *******************************************************************
  2. * Copyright (c) 2003 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * Matthew Webster initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.ajde;
  13. import java.io.File;
  14. import java.io.IOException;
  15. import java.util.jar.JarEntry;
  16. import java.util.jar.JarFile;
  17. import org.aspectj.util.FileUtil;
  18. public class OutxmlTest extends AjdeTestCase {
  19. public static final String PROJECT_DIR = "OutxmlTest";
  20. public static final String BIN_DIR = "bin";
  21. public static final String OUTJAR_NAME = "/bin/test.jar";
  22. public static final String DEFAULT_AOPXML_NAME = "META-INF/aop.xml";
  23. public static final String CUSTOM_AOPXML_NAME = "custom/aop.xml";
  24. /*
  25. * Ensure the output directory is clean
  26. */
  27. protected void setUp() throws Exception {
  28. super.setUp(PROJECT_DIR);
  29. FileUtil.deleteContents(openFile(BIN_DIR));
  30. }
  31. /*
  32. * Clean up afterwards
  33. */
  34. protected void tearDown() throws Exception {
  35. super.tearDown();
  36. FileUtil.deleteContents(openFile(BIN_DIR));
  37. openFile(BIN_DIR).delete();
  38. }
  39. /**
  40. * Aim: Test "-outxml" option produces the correct xml file
  41. *
  42. */
  43. public void testOutxmlToFile () {
  44. // System.out.println("OutxmlTest.testOutxmlToFile() outputpath='" + ideManager.getProjectProperties().getOutputPath() + "'");
  45. assertTrue("Build failed",doSynchronousBuild("outxml-to-file.lst"));
  46. assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
  47. File aopxml = openFile(BIN_DIR + "/" + DEFAULT_AOPXML_NAME);
  48. assertTrue(DEFAULT_AOPXML_NAME + " missing",aopxml.exists());
  49. }
  50. /**
  51. * Aim: Test "-outxmlfile filename" option produces the correct
  52. * xml file
  53. *
  54. */
  55. public void testOutxmlfileToFile () {
  56. assertTrue("Build failed",doSynchronousBuild("outxmlfile-to-file.lst"));
  57. assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
  58. File aopxml = openFile(BIN_DIR + "/" + CUSTOM_AOPXML_NAME);
  59. assertTrue(CUSTOM_AOPXML_NAME + " missing",aopxml.exists());
  60. }
  61. /**
  62. * Aim: Test "-outxml" option produces the correct
  63. * xml entry in outjar file
  64. *
  65. */
  66. public void testOutxmlToOutjar () {
  67. File outjar = openFile(OUTJAR_NAME);
  68. ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath());
  69. assertTrue("Build failed",doSynchronousBuild("outxml-to-outjar.lst"));
  70. assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
  71. File aopxml = openFile(BIN_DIR + "/" + DEFAULT_AOPXML_NAME);
  72. assertFalse(DEFAULT_AOPXML_NAME + " should not exisit",aopxml.exists());
  73. assertJarContainsEntry(outjar,DEFAULT_AOPXML_NAME);
  74. }
  75. /**
  76. * Aim: Test "-outxmlfile filename" option produces the correct
  77. * xml entry in outjar file
  78. *
  79. */
  80. public void testOutxmlfileToOutjar () {
  81. // System.out.println("OutxmlTest.testOutxmlToOutjar() outputpath='" + ideManager.getProjectProperties().getOutputPath() + "'");
  82. File outjar = openFile(OUTJAR_NAME);
  83. ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath());
  84. assertTrue("Build failed",doSynchronousBuild("outxmlfile-to-outjar.lst"));
  85. assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
  86. File aopxml = openFile(BIN_DIR + "/" + CUSTOM_AOPXML_NAME);
  87. assertFalse(CUSTOM_AOPXML_NAME + " should not exisit",aopxml.exists());
  88. assertJarContainsEntry(outjar,CUSTOM_AOPXML_NAME);
  89. }
  90. private void assertJarContainsEntry (File file, String entryName) {
  91. try {
  92. JarFile jarFile = new JarFile(file);
  93. JarEntry jarEntry = jarFile.getJarEntry(entryName);
  94. assertNotNull(entryName + " missing",jarEntry);
  95. }
  96. catch (IOException ex) {
  97. fail(ex.toString());
  98. }
  99. }
  100. }