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.

DuplicateManifestTest.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. * 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.Set;
  17. import java.util.jar.JarFile;
  18. import java.util.jar.Manifest;
  19. import org.aspectj.ajde.core.AjdeCoreTestCase;
  20. import org.aspectj.ajde.core.TestCompilerConfiguration;
  21. import org.aspectj.ajde.core.TestMessageHandler;
  22. public class DuplicateManifestTest extends AjdeCoreTestCase {
  23. public static final String injarName = "injar.jar";
  24. public static final String aspectjarName = "aspectjar.jar";
  25. public static final String outjarName = "outjar.jar";
  26. private TestMessageHandler handler;
  27. private TestCompilerConfiguration compilerConfig;
  28. protected void setUp() throws Exception {
  29. super.setUp();
  30. initialiseProject("DuplicateManifestTest");
  31. handler = (TestMessageHandler) getCompiler().getMessageHandler();
  32. compilerConfig = (TestCompilerConfiguration) getCompiler()
  33. .getCompilerConfiguration();
  34. }
  35. protected void tearDown() throws Exception {
  36. super.tearDown();
  37. handler = null;
  38. compilerConfig = null;
  39. }
  40. public void testWeave() {
  41. Set<File> injars = new HashSet<>();
  42. injars.add(openFile(injarName));
  43. compilerConfig.setInpath(injars);
  44. Set<File> aspectpath = new HashSet<>();
  45. aspectpath.add(openFile(aspectjarName));
  46. compilerConfig.setAspectPath(aspectpath);
  47. File outjar = openFile(outjarName);
  48. compilerConfig.setOutjar(outjar.getAbsolutePath());
  49. doBuild(true);
  50. assertTrue("Expected no compiler errors or warnings but found "
  51. + handler.getMessages(), handler.getMessages().isEmpty());
  52. compareManifests(openFile(injarName), openFile(outjarName));
  53. }
  54. private void compareManifests(File inFile, File outFile) {
  55. try {
  56. JarFile inJar = new JarFile(inFile);
  57. Manifest inManifest = inJar.getManifest();
  58. inJar.close();
  59. JarFile outJar = new JarFile(outFile);
  60. Manifest outManifest = outJar.getManifest();
  61. outJar.close();
  62. assertTrue("The manifests in '" + inFile.getCanonicalPath()
  63. + "' and '" + outFile.getCanonicalPath()
  64. + "' sould be the same", inManifest.equals(outManifest));
  65. } catch (IOException ex) {
  66. fail(ex.toString());
  67. }
  68. }
  69. }