1
|
|
/*
|
2
|
|
* The Apache Software License, Version 1.1
|
3
|
|
*
|
4
|
|
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
|
5
|
|
* reserved.
|
6
|
|
*
|
7
|
|
* Redistribution and use in source and binary forms, with or without
|
8
|
|
* modification, are permitted provided that the following conditions
|
9
|
|
* are met:
|
10
|
|
*
|
11
|
|
* 1. Redistributions of source code must retain the above copyright
|
12
|
|
* notice, this list of conditions and the following disclaimer.
|
13
|
|
*
|
14
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
15
|
|
* notice, this list of conditions and the following disclaimer in
|
16
|
|
* the documentation and/or other materials provided with the
|
17
|
|
* distribution.
|
18
|
|
*
|
19
|
|
* 3. The end-user documentation included with the redistribution, if
|
20
|
|
* any, must include the following acknowlegement:
|
21
|
|
* "This product includes software developed by the
|
22
|
|
* Apache Software Foundation (http://www.apache.org/)."
|
23
|
|
* Alternately, this acknowlegement may appear in the software itself,
|
24
|
|
* if and wherever such third-party acknowlegements normally appear.
|
25
|
|
*
|
26
|
|
* 4. The names "Ant" and "Apache Software
|
27
|
|
* Foundation" must not be used to endorse or promote products derived
|
28
|
|
* from this software without prior written permission. For written
|
29
|
|
* permission, please contact apache@apache.org.
|
30
|
|
*
|
31
|
|
* 5. Products derived from this software may not be called "Apache"
|
32
|
|
* nor may "Apache" appear in their names without prior written
|
33
|
|
* permission of the Apache Group.
|
34
|
|
*
|
35
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
36
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
37
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
38
|
|
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
39
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
40
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
41
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
42
|
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
43
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
44
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
45
|
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
46
|
|
* SUCH DAMAGE.
|
47
|
|
* ====================================================================
|
48
|
|
*
|
49
|
|
* This software consists of voluntary contributions made by many
|
50
|
|
* individuals on behalf of the Apache Software Foundation. For more
|
51
|
|
* information on the Apache Software Foundation, please see
|
52
|
|
* <http://www.apache.org/>.
|
53
|
|
*/
|
54
|
|
package org.apache.tools.ant.taskdefs.optional.junit;
|
55
|
|
|
56
|
|
import java.io.BufferedOutputStream;
|
57
|
|
import java.io.ByteArrayOutputStream;
|
58
|
|
import java.io.File;
|
59
|
|
import java.io.FileOutputStream;
|
60
|
|
import java.io.IOException;
|
61
|
|
import java.io.OutputStream;
|
62
|
|
import java.io.PrintWriter;
|
63
|
|
import java.io.StringWriter;
|
64
|
|
import java.lang.reflect.Field;
|
65
|
|
import org.apache.tools.ant.BuildException;
|
66
|
|
import org.apache.tools.ant.Project;
|
67
|
|
|
68
|
|
/**
|
69
|
|
* Command class that encapsulate specific behavior for each
|
70
|
|
* Xalan version. The right executor will be instantiated at
|
71
|
|
* runtime via class lookup. For instance, it will check first
|
72
|
|
* for Xalan2, then for Xalan1.
|
73
|
|
*/
|
74
|
|
abstract class XalanExecutor {
|
75
|
|
/** the transformer caller */
|
76
|
|
protected AggregateTransformer caller;
|
77
|
|
|
78
|
|
/** set the caller for this object. */
|
79
|
1
|
private final void setCaller(AggregateTransformer caller){
|
80
|
1
|
this.caller = caller;
|
81
|
|
}
|
82
|
|
|
83
|
|
/** get the appropriate stream based on the format (frames/noframes) */
|
84
|
1
|
protected OutputStream getOutputStream() throws IOException {
|
85
|
1
|
if (AggregateTransformer.FRAMES.equals(caller.format)){
|
86
|
|
// dummy output for the framed report
|
87
|
|
// it's all done by extension...
|
88
|
1
|
return new ByteArrayOutputStream();
|
89
|
|
} else {
|
90
|
0
|
return new BufferedOutputStream(new FileOutputStream(new File(caller.toDir, "junit-noframes.html")));
|
91
|
|
}
|
92
|
|
}
|
93
|
|
|
94
|
|
/** override to perform transformation */
|
95
|
|
abstract void execute() throws Exception;
|
96
|
|
|
97
|
|
/**
|
98
|
|
* Create a valid Xalan executor. It checks first if Xalan2 is
|
99
|
|
* present, if not it checks for xalan1. If none is available, it
|
100
|
|
* fails.
|
101
|
|
* @param caller object containing the transformation information.
|
102
|
|
* @throws BuildException thrown if it could not find a valid xalan
|
103
|
|
* executor.
|
104
|
|
*/
|
105
|
1
|
static XalanExecutor newInstance(AggregateTransformer caller) throws BuildException {
|
106
|
1
|
Class procVersion = null;
|
107
|
1
|
XalanExecutor executor = null;
|
108
|
1
|
try {
|
109
|
1
|
procVersion = Class.forName("org.apache.xalan.processor.XSLProcessorVersion");
|
110
|
1
|
executor = (XalanExecutor) Class.forName(
|
111
|
|
"org.apache.tools.ant.taskdefs.optional.junit.Xalan2Executor").newInstance();
|
112
|
|
} catch (Exception xalan2missing){
|
113
|
0
|
StringWriter swr = new StringWriter();
|
114
|
0
|
xalan2missing.printStackTrace(new PrintWriter(swr));
|
115
|
0
|
caller.task.log("Didn't find Xalan2.", Project.MSG_DEBUG);
|
116
|
0
|
caller.task.log(swr.toString(), Project.MSG_DEBUG);
|
117
|
0
|
try {
|
118
|
0
|
procVersion = Class.forName("org.apache.xalan.xslt.XSLProcessorVersion");
|
119
|
0
|
executor = (XalanExecutor) Class.forName(
|
120
|
|
"org.apache.tools.ant.taskdefs.optional.junit.Xalan1Executor").newInstance();
|
121
|
|
} catch (Exception xalan1missing){
|
122
|
0
|
swr = new StringWriter();
|
123
|
0
|
xalan1missing.printStackTrace(new PrintWriter(swr));
|
124
|
0
|
caller.task.log("Didn't find Xalan1.", Project.MSG_DEBUG);
|
125
|
0
|
caller.task.log(swr.toString(), Project.MSG_DEBUG);
|
126
|
0
|
throw new BuildException("Could not find xalan2 nor xalan1 in the classpath. Check http://xml.apache.org/xalan-j");
|
127
|
|
}
|
128
|
|
}
|
129
|
1
|
String version = getXalanVersion(procVersion);
|
130
|
1
|
caller.task.log("Using Xalan version: " + version);
|
131
|
1
|
executor.setCaller(caller);
|
132
|
1
|
return executor;
|
133
|
|
}
|
134
|
|
|
135
|
|
/** pretty useful data (Xalan version information) to display. */
|
136
|
1
|
private static String getXalanVersion(Class procVersion) {
|
137
|
1
|
try {
|
138
|
1
|
Field f = procVersion.getField("S_VERSION");
|
139
|
1
|
return f.get(null).toString();
|
140
|
|
} catch (Exception e){
|
141
|
0
|
return "?";
|
142
|
|
}
|
143
|
|
}
|
144
|
|
}
|
145
|
|
|