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 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-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.HashSet;
  16. import java.util.List;
  17. import java.util.Set;
  18. import java.util.jar.JarEntry;
  19. import java.util.jar.JarFile;
  20. import org.aspectj.bridge.Constants;
  21. import org.aspectj.util.FileUtil;
  22. public class OutxmlTest extends AjdeTestCase {
  23. public static final String PROJECT_DIR = "OutxmlTest";
  24. public static final String BIN_DIR = "bin";
  25. public static final String OUTJAR_NAME = "/bin/test.jar";
  26. public static final String DEFAULT_AOPXML_NAME = Constants.AOP_AJC_XML;
  27. public static final String CUSTOM_AOPXML_NAME = "custom/aop.xml";
  28. /*
  29. * Ensure the output directory is clean
  30. */
  31. protected void setUp() throws Exception {
  32. super.setUp(PROJECT_DIR);
  33. FileUtil.deleteContents(openFile(BIN_DIR));
  34. }
  35. /*
  36. * Clean up afterwards
  37. */
  38. protected void tearDown() throws Exception {
  39. super.tearDown();
  40. FileUtil.deleteContents(openFile(BIN_DIR));
  41. openFile(BIN_DIR).delete();
  42. }
  43. /**
  44. * Aim: Test "-outxml" option produces the correct xml file
  45. *
  46. */
  47. public void testOutxmlToFile () {
  48. // System.out.println("OutxmlTest.testOutxmlToFile() outputpath='" + ideManager.getProjectProperties().getOutputPath() + "'");
  49. assertTrue("Build failed",doSynchronousBuild("outxml-to-file.lst"));
  50. assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
  51. File aopxml = openFile(BIN_DIR + "/" + DEFAULT_AOPXML_NAME);
  52. assertTrue(DEFAULT_AOPXML_NAME + " missing",aopxml.exists());
  53. }
  54. /**
  55. * Aim: Test "-outxmlfile filename" option produces the correct
  56. * xml file
  57. *
  58. */
  59. public void testOutxmlfileToFile () {
  60. assertTrue("Build failed",doSynchronousBuild("outxmlfile-to-file.lst"));
  61. assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
  62. File aopxml = openFile(BIN_DIR + "/" + CUSTOM_AOPXML_NAME);
  63. assertTrue(CUSTOM_AOPXML_NAME + " missing",aopxml.exists());
  64. }
  65. /**
  66. * Aim: Test "-outxml" option produces the correct
  67. * xml entry in outjar file
  68. *
  69. */
  70. public void testOutxmlToOutjar () {
  71. File outjar = openFile(OUTJAR_NAME);
  72. ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath());
  73. assertTrue("Build failed",doSynchronousBuild("outxml-to-outjar.lst"));
  74. assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
  75. File aopxml = openFile(BIN_DIR + "/" + DEFAULT_AOPXML_NAME);
  76. assertFalse(DEFAULT_AOPXML_NAME + " should not exisit",aopxml.exists());
  77. assertJarContainsEntry(outjar,DEFAULT_AOPXML_NAME);
  78. }
  79. /**
  80. * Aim: Test "-outxmlfile filename" option produces the correct
  81. * xml entry in outjar file
  82. *
  83. */
  84. public void testOutxmlfileToOutjar () {
  85. // System.out.println("OutxmlTest.testOutxmlToOutjar() outputpath='" + ideManager.getProjectProperties().getOutputPath() + "'");
  86. File outjar = openFile(OUTJAR_NAME);
  87. ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath());
  88. assertTrue("Build failed",doSynchronousBuild("outxmlfile-to-outjar.lst"));
  89. assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
  90. File aopxml = openFile(BIN_DIR + "/" + CUSTOM_AOPXML_NAME);
  91. assertFalse(CUSTOM_AOPXML_NAME + " should not exisit",aopxml.exists());
  92. assertJarContainsEntry(outjar,CUSTOM_AOPXML_NAME);
  93. }
  94. /**
  95. * Aim: Test "-outxml" option produces a warning if "META-INF/aop.xml
  96. * already exists in source
  97. *
  98. */
  99. public void testOutxmlToOutjarWithAop_xml () {
  100. File f = new File( AjdeTests.testDataPath(PROJECT_DIR + "/src-resources"));
  101. Set roots = new HashSet();
  102. roots.add(f);
  103. ideManager.getProjectProperties().setSourceRoots(roots);
  104. File outjar = openFile(OUTJAR_NAME);
  105. ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath());
  106. assertTrue("Build failed: " + ideManager.getCompilationSourceLineTasks(),doSynchronousBuild("outxml-to-outjar-with-aop_xml.lst"));
  107. // assertTrue("Build warnings: " + ideManager.getCompilationSourceLineTasks(),ideManager.getCompilationSourceLineTasks().isEmpty());
  108. assertFalse("Build warnings for exisiting resource expected",ideManager.getCompilationSourceLineTasks().isEmpty());
  109. List msgs = NullIdeManager.getIdeManager().getCompilationSourceLineTasks();
  110. String msg = ((NullIdeTaskListManager.SourceLineTask)msgs.get(0)).message.getMessage();
  111. assertTrue("Wrong message: " + msg,msg.startsWith("-outxml/-outxmlfile option ignored because resource already exists:"));
  112. File aopxml = openFile(BIN_DIR + "/" + DEFAULT_AOPXML_NAME);
  113. assertFalse(DEFAULT_AOPXML_NAME + " should not exisit",aopxml.exists());
  114. assertJarContainsEntry(outjar,DEFAULT_AOPXML_NAME);
  115. }
  116. private void assertJarContainsEntry (File file, String entryName) {
  117. try {
  118. JarFile jarFile = new JarFile(file);
  119. JarEntry jarEntry = jarFile.getJarEntry(entryName);
  120. assertNotNull(entryName + " missing",jarEntry);
  121. }
  122. catch (IOException ex) {
  123. fail(ex.toString());
  124. }
  125. }
  126. }