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.

IgnoreJava9JarElements.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*******************************************************************************
  2. * Copyright (c) 2019 Contributors
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *******************************************************************************/
  8. package org.aspectj.ajde.core.tests;
  9. import java.io.File;
  10. import java.io.IOException;
  11. import java.util.Enumeration;
  12. import java.util.HashSet;
  13. import java.util.Set;
  14. import java.util.jar.JarEntry;
  15. import java.util.jar.JarFile;
  16. import java.util.jar.Manifest;
  17. import org.aspectj.ajde.core.AjdeCoreTestCase;
  18. import org.aspectj.ajde.core.TestCompilerConfiguration;
  19. import org.aspectj.ajde.core.TestMessageHandler;
  20. public class IgnoreJava9JarElements extends AjdeCoreTestCase {
  21. public static final String injarName = "build/libs/IgnoreJava9JarElements.jar";
  22. public static final String outjarName = "outjar.jar";
  23. private TestMessageHandler handler;
  24. private TestCompilerConfiguration compilerConfig;
  25. protected void setUp() throws Exception {
  26. super.setUp();
  27. initialiseProject("IgnoreJava9JarElements");
  28. handler = (TestMessageHandler) getCompiler().getMessageHandler();
  29. compilerConfig = (TestCompilerConfiguration) getCompiler()
  30. .getCompilerConfiguration();
  31. }
  32. protected void tearDown() throws Exception {
  33. super.tearDown();
  34. handler = null;
  35. compilerConfig = null;
  36. }
  37. public void testWeave() {
  38. Set<File> injars = new HashSet<File>();
  39. injars.add(openFile(injarName));
  40. compilerConfig.setInpath(injars);
  41. Set<File> aspectpath = new HashSet<File>();
  42. compilerConfig.setAspectPath(aspectpath);
  43. File outjar = openFile(outjarName);
  44. compilerConfig.setOutjar(outjar.getAbsolutePath());
  45. doBuild(true);
  46. assertTrue("Expected no compiler errors or warnings but found "
  47. + handler.getMessages(), handler.getMessages().isEmpty());
  48. compareManifests(openFile(injarName), openFile(outjarName));
  49. }
  50. private void compareManifests(File inFile, File outFile) {
  51. try {
  52. JarFile inJar = new JarFile(inFile);
  53. Manifest inManifest = inJar.getManifest();
  54. inJar.close();
  55. JarFile outJar = new JarFile(outFile);
  56. Manifest outManifest = outJar.getManifest();
  57. outJar.close();
  58. assertTrue("The manifests in '" + inFile.getCanonicalPath()
  59. + "' and '" + outFile.getCanonicalPath()
  60. + "' sould be the same", inManifest.equals(outManifest));
  61. } catch (IOException ex) {
  62. fail(ex.toString());
  63. }
  64. }
  65. }