1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
/* *******************************************************************
* Copyright (c) 2003 Contributors.
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Matthew Webster initial implementation
* ******************************************************************/
package org.aspectj.ajde;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.aspectj.util.FileUtil;
public class OutxmlTest extends AjdeTestCase {
public static final String PROJECT_DIR = "OutxmlTest";
public static final String BIN_DIR = "bin";
public static final String OUTJAR_NAME = "/bin/test.jar";
public static final String DEFAULT_AOPXML_NAME = "META-INF/aop.xml";
public static final String CUSTOM_AOPXML_NAME = "custom/aop.xml";
/*
* Ensure the output directory is clean
*/
protected void setUp() throws Exception {
super.setUp(PROJECT_DIR);
FileUtil.deleteContents(openFile(BIN_DIR));
}
/*
* Clean up afterwards
*/
protected void tearDown() throws Exception {
super.tearDown();
FileUtil.deleteContents(openFile(BIN_DIR));
openFile(BIN_DIR).delete();
}
/**
* Aim: Test "-outxml" option produces the correct xml file
*
*/
public void testOutxmlToFile () {
// System.out.println("OutxmlTest.testOutxmlToFile() outputpath='" + ideManager.getProjectProperties().getOutputPath() + "'");
assertTrue("Build failed",doSynchronousBuild("outxml-to-file.lst"));
assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
File aopxml = openFile(BIN_DIR + "/" + DEFAULT_AOPXML_NAME);
assertTrue(DEFAULT_AOPXML_NAME + " missing",aopxml.exists());
}
/**
* Aim: Test "-outxmlfile filename" option produces the correct
* xml file
*
*/
public void testOutxmlfileToFile () {
assertTrue("Build failed",doSynchronousBuild("outxmlfile-to-file.lst"));
assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
File aopxml = openFile(BIN_DIR + "/" + CUSTOM_AOPXML_NAME);
assertTrue(CUSTOM_AOPXML_NAME + " missing",aopxml.exists());
}
/**
* Aim: Test "-outxml" option produces the correct
* xml entry in outjar file
*
*/
public void testOutxmlToOutjar () {
File outjar = openFile(OUTJAR_NAME);
ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath());
assertTrue("Build failed",doSynchronousBuild("outxml-to-outjar.lst"));
assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
File aopxml = openFile(BIN_DIR + "/" + DEFAULT_AOPXML_NAME);
assertFalse(DEFAULT_AOPXML_NAME + " should not exisit",aopxml.exists());
assertJarContainsEntry(outjar,DEFAULT_AOPXML_NAME);
}
/**
* Aim: Test "-outxmlfile filename" option produces the correct
* xml entry in outjar file
*
*/
public void testOutxmlfileToOutjar () {
// System.out.println("OutxmlTest.testOutxmlToOutjar() outputpath='" + ideManager.getProjectProperties().getOutputPath() + "'");
File outjar = openFile(OUTJAR_NAME);
ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath());
assertTrue("Build failed",doSynchronousBuild("outxmlfile-to-outjar.lst"));
assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
File aopxml = openFile(BIN_DIR + "/" + CUSTOM_AOPXML_NAME);
assertFalse(CUSTOM_AOPXML_NAME + " should not exisit",aopxml.exists());
assertJarContainsEntry(outjar,CUSTOM_AOPXML_NAME);
}
/**
* Aim: Test "-outxml" option produces a warning if "META-INF/aop.xml
* already exists in source
*
*/
public void testOutxmlToOutjarWithAop_xml () {
File f = new File( AjdeTests.testDataPath(PROJECT_DIR + "/src-resources"));
Set roots = new HashSet();
roots.add(f);
ideManager.getProjectProperties().setSourceRoots(roots);
File outjar = openFile(OUTJAR_NAME);
ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath());
assertTrue("Build failed: " + ideManager.getCompilationSourceLineTasks(),doSynchronousBuild("outxml-to-outjar-with-aop_xml.lst"));
// assertTrue("Build warnings: " + ideManager.getCompilationSourceLineTasks(),ideManager.getCompilationSourceLineTasks().isEmpty());
assertFalse("Build warnings for exisiting resource expected",ideManager.getCompilationSourceLineTasks().isEmpty());
List msgs = NullIdeManager.getIdeManager().getCompilationSourceLineTasks();
String msg = ((NullIdeTaskListManager.SourceLineTask)msgs.get(0)).message.getMessage();
assertTrue("Wrong message: " + msg,msg.startsWith("-outxml/-outxmlfile option ignored because resource already exists:"));
File aopxml = openFile(BIN_DIR + "/" + DEFAULT_AOPXML_NAME);
assertFalse(DEFAULT_AOPXML_NAME + " should not exisit",aopxml.exists());
assertJarContainsEntry(outjar,DEFAULT_AOPXML_NAME);
}
private void assertJarContainsEntry (File file, String entryName) {
try {
JarFile jarFile = new JarFile(file);
JarEntry jarEntry = jarFile.getJarEntry(entryName);
assertNotNull(entryName + " missing",jarEntry);
}
catch (IOException ex) {
fail(ex.toString());
}
}
}
|