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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. * Aim: Test "-outxml" option produces the correct xml file
  33. *
  34. */
  35. public void testOutxmlToFile () {
  36. // System.out.println("OutxmlTest.testOutxmlToFile() outputpath='" + ideManager.getProjectProperties().getOutputPath() + "'");
  37. assertTrue("Build failed",doSynchronousBuild("outxml-to-file.lst"));
  38. assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
  39. File aopxml = openFile(BIN_DIR + "/" + DEFAULT_AOPXML_NAME);
  40. assertTrue(DEFAULT_AOPXML_NAME + " missing",aopxml.exists());
  41. }
  42. /**
  43. * Aim: Test "-outxmlfile filename" option produces the correct
  44. * xml file
  45. *
  46. */
  47. public void testOutxmlfileToFile () {
  48. assertTrue("Build failed",doSynchronousBuild("outxmlfile-to-file.lst"));
  49. assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
  50. File aopxml = openFile(BIN_DIR + "/" + CUSTOM_AOPXML_NAME);
  51. assertTrue(CUSTOM_AOPXML_NAME + " missing",aopxml.exists());
  52. }
  53. /**
  54. * Aim: Test "-outxmlfile filename" option produces the correct
  55. * xml entry in outjar file
  56. *
  57. */
  58. public void testOutxmlfileToOutjar () {
  59. // System.out.println("OutxmlTest.testOutxmlToOutjar() outputpath='" + ideManager.getProjectProperties().getOutputPath() + "'");
  60. File outjar = openFile(OUTJAR_NAME);
  61. ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath());
  62. assertTrue("Build failed",doSynchronousBuild("outxmlfile-to-outjar.lst"));
  63. assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
  64. File aopxml = openFile(BIN_DIR + "/" + CUSTOM_AOPXML_NAME);
  65. assertFalse(CUSTOM_AOPXML_NAME + " should not exisit",aopxml.exists());
  66. assertJarContainsEntry(outjar,CUSTOM_AOPXML_NAME);
  67. }
  68. private void assertJarContainsEntry (File file, String entryName) {
  69. try {
  70. JarFile jarFile = new JarFile(file);
  71. JarEntry jarEntry = jarFile.getJarEntry(entryName);
  72. assertNotNull(entryName + " missing",jarEntry);
  73. }
  74. catch (IOException ex) {
  75. fail(ex.toString());
  76. }
  77. }
  78. }