Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

17 лет назад
17 лет назад
9 лет назад
17 лет назад
5 лет назад
17 лет назад
17 лет назад
17 лет назад
17 лет назад
17 лет назад
17 лет назад
17 лет назад
17 лет назад
17 лет назад
17 лет назад
17 лет назад
17 лет назад
17 лет назад
17 лет назад
17 лет назад
17 лет назад
9 лет назад
17 лет назад
17 лет назад
17 лет назад
17 лет назад
17 лет назад
17 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /********************************************************************
  2. * Copyright (c) 2003 Contributors. All rights reserved.
  3. * This program and the accompanying materials are made available
  4. * under the terms of the Eclipse Public License v 2.0
  5. * which accompanies this distribution and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  7. *
  8. * Contributors:
  9. * Matthew Webster initial implementation
  10. * Helen Hawkins Converted to new interface (bug 148190)
  11. *******************************************************************/
  12. package org.aspectj.ajde.core.tests;
  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.ajde.core.AjdeCoreTestCase;
  21. import org.aspectj.ajde.core.TestCompilerConfiguration;
  22. import org.aspectj.ajde.core.TestMessageHandler;
  23. import org.aspectj.ajde.core.TestMessageHandler.TestMessage;
  24. import org.aspectj.bridge.Constants;
  25. public class OutxmlTest extends AjdeCoreTestCase {
  26. public static final String PROJECT_DIR = "OutxmlTest";
  27. public static final String BIN_DIR = "bin";
  28. public static final String OUTJAR_NAME = "/bin/test.jar";
  29. public static final String DEFAULT_AOPXML_NAME = Constants.AOP_AJC_XML;
  30. public static final String CUSTOM_AOPXML_NAME = "custom/aop.xml";
  31. private String[] files = new String[]{
  32. "src" + File.separator + "TestAbstractAspect.aj",
  33. "src" + File.separator + "TestClass.java",
  34. "src" + File.separator + "TestConcreteAspect.aj",
  35. "src" + File.separator + "TestInterface.java"
  36. };
  37. private TestMessageHandler handler;
  38. private TestCompilerConfiguration compilerConfig;
  39. protected void setUp() throws Exception {
  40. super.setUp();
  41. initialiseProject(PROJECT_DIR);
  42. handler = (TestMessageHandler) getCompiler().getMessageHandler();
  43. compilerConfig = (TestCompilerConfiguration) getCompiler()
  44. .getCompilerConfiguration();
  45. }
  46. protected void tearDown() throws Exception {
  47. super.tearDown();
  48. handler = null;
  49. compilerConfig = null;
  50. }
  51. /**
  52. * Aim: Test "-outxml" option produces the correct xml file
  53. */
  54. public void testOutxmlToFile () {
  55. compilerConfig.setProjectSourceFiles(getSourceFileList(files));
  56. compilerConfig.setNonStandardOptions("-outxml");
  57. doBuild(true);
  58. assertTrue("Expected no compiler errors or warnings but found "
  59. + handler.getMessages(), handler.getMessages().isEmpty());
  60. File aopxml = openFile(BIN_DIR + "/" + DEFAULT_AOPXML_NAME);
  61. assertTrue(DEFAULT_AOPXML_NAME + " missing",aopxml.exists());
  62. }
  63. /**
  64. * Aim: Test "-outxmlfile filename" option produces the correct
  65. * xml file
  66. *
  67. */
  68. public void testOutxmlfileToFile () {
  69. compilerConfig.setProjectSourceFiles(getSourceFileList(files));
  70. compilerConfig.setNonStandardOptions("-outxmlfile custom/aop.xml");
  71. doBuild(true);
  72. assertTrue("Expected no compiler errors or warnings but found "
  73. + handler.getMessages(), handler.getMessages().isEmpty());
  74. File aopxml = openFile(BIN_DIR + "/" + CUSTOM_AOPXML_NAME);
  75. assertTrue(CUSTOM_AOPXML_NAME + " missing",aopxml.exists());
  76. }
  77. /**
  78. * Aim: Test "-outxml" option produces the correct
  79. * xml entry in outjar file
  80. *
  81. */
  82. public void testOutxmlToOutjar () {
  83. File outjar = openFile(OUTJAR_NAME);
  84. compilerConfig.setOutjar(outjar.getAbsolutePath());
  85. compilerConfig.setProjectSourceFiles(getSourceFileList(files));
  86. compilerConfig.setNonStandardOptions("-outxml");
  87. doBuild(true);
  88. assertTrue("Expected no compiler errors or warnings but found "
  89. + handler.getMessages(), handler.getMessages().isEmpty());
  90. File aopxml = openFile(BIN_DIR + "/" + DEFAULT_AOPXML_NAME);
  91. assertFalse(DEFAULT_AOPXML_NAME + " should not exisit",aopxml.exists());
  92. assertJarContainsEntry(outjar,DEFAULT_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( getAbsoluteProjectDir() + File.separator + "src-resources" + File.separator + "testjar.jar");
  101. Set<File> roots = new HashSet<>();
  102. roots.add(f);
  103. compilerConfig.setInpath(roots);
  104. File outjar = openFile(OUTJAR_NAME);
  105. compilerConfig.setOutjar(outjar.getAbsolutePath());
  106. compilerConfig.setNonStandardOptions("-outxml");
  107. doBuild(true);
  108. assertFalse("Expected compiler errors or warnings but didn't find any "
  109. + handler.getMessages(), handler.getMessages().isEmpty());
  110. List<TestMessage> msgs = handler.getMessages();
  111. String msg = msgs.get(0).getContainedMessage().getMessage();
  112. String exp = "-outxml/-outxmlfile option ignored because resource already exists:";
  113. assertTrue("Expected message to start with : " + exp + " but found message " + msg,msg.startsWith(exp));
  114. File aopxml = openFile(BIN_DIR + "/" + DEFAULT_AOPXML_NAME);
  115. assertFalse(DEFAULT_AOPXML_NAME + " should not exisit",aopxml.exists());
  116. assertJarContainsEntry(outjar,DEFAULT_AOPXML_NAME);
  117. }
  118. /**
  119. * Aim: Test "-outxmlfile filename" option produces the correct
  120. * xml entry in outjar file
  121. */
  122. public void testOutxmlfileToOutjar () {
  123. File outjar = openFile(OUTJAR_NAME);
  124. compilerConfig.setOutjar(outjar.getAbsolutePath());
  125. compilerConfig.setProjectSourceFiles(getSourceFileList(files));
  126. compilerConfig.setNonStandardOptions("-outxmlfile custom/aop.xml");
  127. doBuild(true);
  128. assertTrue("Expected no compiler errors or warnings but found "
  129. + handler.getMessages(), handler.getMessages().isEmpty());
  130. File aopxml = openFile(BIN_DIR + "/" + CUSTOM_AOPXML_NAME);
  131. assertFalse(CUSTOM_AOPXML_NAME + " should not exisit",aopxml.exists());
  132. assertJarContainsEntry(outjar,CUSTOM_AOPXML_NAME);
  133. }
  134. private void assertJarContainsEntry (File file, String entryName) {
  135. try (JarFile jarFile = new JarFile(file)) {
  136. JarEntry jarEntry = jarFile.getJarEntry(entryName);
  137. assertNotNull(entryName + " missing",jarEntry);
  138. }
  139. catch (IOException ex) {
  140. fail(ex.toString());
  141. }
  142. }
  143. }