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.

JarManifestTest.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*******************************************************************************
  2. * Copyright (c) 2004 IBM Corporation and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available 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. * IBM Corporation - initial API and 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.FileInputStream;
  15. import java.io.IOException;
  16. import java.util.jar.JarInputStream;
  17. import java.util.jar.Manifest;
  18. import org.aspectj.ajde.core.AjdeCoreTestCase;
  19. import org.aspectj.ajde.core.TestCompilerConfiguration;
  20. import org.aspectj.ajde.core.TestMessageHandler;
  21. public class JarManifestTest extends AjdeCoreTestCase {
  22. public static final String outjarName = "/bin/output.jar";
  23. private String[] weave = { "src" + File.separator + "Main.java",
  24. "src" + File.separator + "Logging.aj" };
  25. private TestMessageHandler handler;
  26. private TestCompilerConfiguration compilerConfig;
  27. protected void setUp() throws Exception {
  28. super.setUp();
  29. initialiseProject("JarManifestTest");
  30. handler = (TestMessageHandler) getCompiler().getMessageHandler();
  31. compilerConfig = (TestCompilerConfiguration) getCompiler()
  32. .getCompilerConfiguration();
  33. }
  34. protected void tearDown() throws Exception {
  35. super.tearDown();
  36. handler = null;
  37. compilerConfig = null;
  38. }
  39. public void testWeave () {
  40. File outjar = openFile(outjarName);
  41. compilerConfig.setOutjar(outjar.getAbsolutePath());
  42. compilerConfig.setProjectSourceFiles(getSourceFileList(weave));
  43. doBuild(true);
  44. assertTrue("Expected no compiler errors or warnings but found "
  45. + handler.getMessages(), handler.getMessages().isEmpty());
  46. checkManifest(outjar);
  47. }
  48. public void testNoWeave () {
  49. File outjar = openFile(outjarName);
  50. compilerConfig.setOutjar(outjar.getAbsolutePath());
  51. compilerConfig.setProjectSourceFiles(getSourceFileList(weave));
  52. compilerConfig.setNonStandardOptions("-XterminateAfterCompilation");
  53. doBuild(true);
  54. assertTrue("Expected no compiler errors or warnings but found "
  55. + handler.getMessages(), handler.getMessages().isEmpty());
  56. checkManifest(outjar);
  57. }
  58. private void checkManifest (File outjarFile) {
  59. Manifest manifest = null;
  60. try {
  61. JarInputStream outjar = new JarInputStream(new FileInputStream(outjarFile));
  62. manifest = outjar.getManifest();
  63. outjar.close();
  64. assertNotNull("'" + outjarFile.getCanonicalPath() + "' should contain a manifest",manifest);
  65. }
  66. catch (IOException ex) {
  67. fail(ex.toString());
  68. }
  69. }
  70. }