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