/
report-normal-operation.xml
executable file
·198 lines (178 loc) · 7.24 KB
/
report-normal-operation.xml
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?xml version='1.0'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one *
or more contributor license agreements. See the NOTICE file *
distributed with this work for additional information *
regarding copyright ownership. The ASF licenses this file *
to you under the Apache License, Version 2.0 (the *
"License"); you may not use this file except in compliance *
with the License. You may obtain a copy of the License at *
*
http://www.apache.org/licenses/LICENSE-2.0 *
*
Unless required by applicable law or agreed to in writing, *
software distributed under the License is distributed on an *
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
KIND, either express or implied. See the License for the *
specific language governing permissions and limitations *
under the License. *
-->
<project name='report-normal-operation'
default="allTests"
xmlns:au="antlib:org.apache.ant.antunit"
xmlns:rat="antlib:org.apache.rat.anttasks">
<property name="output.dir" location="../../../../target/testoutput"/>
<mkdir dir="${output.dir}/dest"/>
<path id="all-classes-needed-for-tests">
<pathelement location="${jar.name}" />
<pathelement path="${test.classpath}" />
<pathelement location="${output.dir}/dest" />
</path>
<taskdef uri="antlib:org.apache.ant.antunit"
resource="org/apache/ant/antunit/antlib.xml"
classpathref="all-classes-needed-for-tests"
loaderref="testloader"/>
<taskdef uri="antlib:org.apache.rat.anttasks"
resource="org/apache/rat/anttasks/antlib.xml"
classpathref="all-classes-needed-for-tests"
loaderref="testloader"/>
<target name="setUp">
<pathconvert dirsep="/" property="file.name">
<path>
<pathelement location="${ant.file}"/>
</path>
</pathconvert>
<property name="expectedOutput" value=" AL ${file.name}"/>
<property name="expectedOutputXML" value="<resource name='${file.name}'"/>
<property name="expectedOutputXML2" value="<header-type name='AL '"/>
</target>
<target name="allTests">
<au:antunit xmlns:au="antlib:org.apache.ant.antunit"
failonerror="false" errorproperty="antunit.failed">
<file file="${ant.file}"/>
<au:plainlistener/>
<propertyset>
<propertyref name="test.classpath"/>
<propertyref name="jar.name"/>
</propertyset>
</au:antunit>
</target>
<target name="tearDown">
<delete dir="${output.dir}" quiet="true"/>
</target>
<target name="xtestWithReportSentToAnt">
<rat:report>
<file file="${ant.file}"/>
</rat:report>
<au:assertLogContains text="${expectedOutput}"/>
</target>
<target name="testWithReportSentToFile" depends="fileReportTest">
<rat:report reportFile="${report.file}">
<file file="${ant.file}"/>
</rat:report>
<au:assertLogDoesntContain text="${expectedOutput}"/>
<au:assertFileExists file="${report.file}"/>
<assertReportContains text="${expectedOutput}"/>
</target>
<target name="testXMLReportSentToFile" depends="fileReportTest">
<rat:report reportFile="${report.file}.xml" format="xml">
<file file="${ant.file}"/>
</rat:report>
<au:assertLogDoesntContain text="${expectedOutputXML}"/>
<au:assertLogDoesntContain text="${expectedOutputXML2}"/>
<au:assertFileExists file="${report.file}.xml"/>
<assertReportContains text="${expectedOutputXML}"
file="${report.file}.xml"/>
<assertReportContains text="${expectedOutputXML2}"
file="${report.file}.xml"/>
</target>
<target name="xtestWithASLUnknown">
<rat:report addDefaultLicenseMatchers="false">
<file file="${ant.file}"/>
<rat:w3c/>
</rat:report>
<au:assertLogDoesntContain text="${expectedOutput}"/>
<au:assertLogContains text="!????? ${file.name}"/>
</target>
<target name="testWithASLUnknownSentToFile" depends="fileReportTest">
<rat:report addDefaultLicenseMatchers="false" reportFile="${report.file}">
<file file="${ant.file}"/>
<rat:w3c/>
</rat:report>
<au:assertLogDoesntContain text="${expectedOutput}"/>
<au:assertLogDoesntContain text="!????? ${file.name}"/>
<assertReportContains text="!????? ${file.name}"/>
</target>
<target name="xtestCustomMatcher" depends="prepareCustomMatcher">
<rat:report>
<file file="${ant.file}"/>
<exmpl/>
<exmpl-license/>
</rat:report>
<au:assertLogDoesntContain text="${expectedOutput}"/>
<au:assertLogContains text=" EXMPL ${file.name}"/>
</target>
<target name="testCustomMatcherSentToFile"
depends="fileReportTest,prepareCustomMatcher">
<rat:report reportFile="${report.file}">
<file file="${ant.file}"/>
<exmpl/>
<exmpl-license/>
</rat:report>
<au:assertLogDoesntContain text="${expectedOutput}"/>
<au:assertLogDoesntContain text=" EXMPL ${file.name}"/>
<assertReportContains text=" EXMPL ${file.name}"/>
</target>
<target name="fileReportTest" depends="setUp">
<property name="report.file" location="${output.dir}/selftest.report"/>
<au:assertFileDoesntExist file="${report.file}"/>
<macrodef name="assertReportContains">
<attribute name="text"/>
<attribute name="file" default="${report.file}"/>
<sequential>
<loadfile srcFile="@{file}" property="report"/>
<au:assertTrue message="expected report to contain '@{text}' but was '${report}'">
<contains string="${report}" substring="@{text}"/>
</au:assertTrue>
</sequential>
</macrodef>
</target>
<target name="prepareCustomMatcher">
<mkdir dir="${output.dir}/dest"/>
<mkdir dir="${output.dir}/src/org/example"/>
<echo file="${output.dir}/src/org/example/Matcher.java"><![CDATA[
package org.example;
import org.apache.rat.analysis.IHeaderMatcher;
import org.apache.rat.analysis.license.BaseLicense;
import org.apache.rat.report.claim.IClaimReporter;
import org.apache.rat.analysis.RatHeaderAnalysisException;
public class Matcher extends BaseLicense implements IHeaderMatcher {
public Matcher() {
super("EXMPL", "Example License", "");
}
public void reset() {}
public boolean match(String subject, String line, IClaimReporter reporter) throws RatHeaderAnalysisException {
reportOnLicense(subject, reporter);
return true;
}
}
]]></echo>
<echo file="${output.dir}/src/org/example/LicenseFamily.java"><![CDATA[
package org.example;
import org.apache.rat.license.ILicenseFamily;
public class LicenseFamily implements ILicenseFamily {
public String getFamilyName() {
return "Example License";
}
}
]]></echo>
<javac srcdir="${output.dir}/src" destdir="${output.dir}/dest"
classpath="${test.classpath}"/>
<typedef name="exmpl" classname="org.example.Matcher"
classpathref="all-classes-needed-for-tests"
loaderref="testloader"/>
<typedef name="exmpl-license" classname="org.example.LicenseFamily"
classpathref="all-classes-needed-for-tests"
loaderref="testloader"/>
</target>
</project>