2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common Development
8
* and Distribution License("CDDL") (collectively, the "License"). You
9
* may not use this file except in compliance with the License. You can
10
* obtain a copy of the License at
11
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
12
* or packager/legal/LICENSE.txt. See the License for the specific
13
* language governing permissions and limitations under the License.
15
* When distributing the software, include this License Header Notice in each
16
* file and include the License file at packager/legal/LICENSE.txt.
18
* GPL Classpath Exception:
19
* Oracle designates this particular file as subject to the "Classpath"
20
* exception as provided by Oracle in the GPL Version 2 section of the License
21
* file that accompanied this code.
24
* If applicable, add the following below the License Header, with the fields
25
* enclosed by brackets [] replaced by your own identifying information:
26
* "Portions Copyright [year] [name of copyright owner]"
29
* If you wish your version of this file to be governed by only the CDDL or
30
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31
* elects to include this software in this distribution under the [CDDL or GPL
32
* Version 2] license." If you don't indicate a single choice of license, a
33
* recipient has the option to distribute your version of this file under
34
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35
* its licensees as provided above. However, if you add GPL Version 2 code
36
* and therefore, elected the GPL Version 2 license, then the option applies
37
* only if the new code is made subject to such option by the copyright
43
import java.io.FileOutputStream;
44
import java.io.PrintStream;
46
import org.apache.tools.ant.BuildEvent;
47
import org.apache.tools.ant.BuildListener;
48
import org.apache.tools.ant.DefaultLogger;
49
import org.apache.tools.ant.Project;
50
import org.apache.tools.ant.ProjectHelper;
51
import org.kohsuke.args4j.CmdLineParser;
54
* Processor that runs samples.
57
* <li>Ryan Shoemaker, Sun Microsystems, Inc.</li>
59
* @version $Revision: 1.1 $
61
public class AntBuildProcessor implements Processor {
66
* @see processor.Processor#process(java.io.File)
68
public boolean process(File dir, boolean verbose) {
69
boolean continueProcessing = true;
73
new File(dir,"build.xml");
75
// buildDotXml should exist, so just attempt to launch it
76
continueProcessing = launchAnt(dir, buildDotXml, verbose);
78
return continueProcessing;
85
private boolean launchAnt(File dir, File buildDotXml, boolean verbose) {
86
boolean continueProcessing = true;
88
new File(dir,"build.out");
90
BuildResultListener buildResultListener = new BuildResultListener();
93
trace("launching " + buildDotXml, verbose);
95
final Project project = new Project();
96
//AntListener listener = new AntListener();
97
DefaultLogger listener = new DefaultLogger();
99
new PrintStream(new FileOutputStream(buildDotOut));
100
listener.setOutputPrintStream(logTo);
101
listener.setErrorPrintStream(logTo);
102
listener.setMessageOutputLevel(Project.MSG_INFO);
103
project.addBuildListener(listener);
104
project.addBuildListener(buildResultListener);
106
Throwable exception = null;
108
project.fireBuildStarted();
110
ProjectHelper.configureProject(project, buildDotXml);
111
project.executeTarget(project.getDefaultTarget());
112
} catch (Throwable t) {
115
project.fireBuildFinished(exception);
118
if( buildResultListener.getCause()!=null ) {
119
System.out.println("build failed!");
120
buildResultListener.getCause().printStackTrace(System.out);
121
continueProcessing = false;
123
} catch (Exception e) {
125
continueProcessing = false;
128
return continueProcessing;
131
private void trace(String msg, boolean verbose) {
133
System.out.println("AntBuildProcessor: " + msg);
136
public void addCmdLineOptions(CmdLineParser parser) {
141
* {@link BuildListener} that checks if the build
142
* was successful or a failure.
144
static final class BuildResultListener implements BuildListener {
147
* Cause of the failure.
149
private Throwable cause;
151
Throwable getCause() {
155
public void buildStarted(BuildEvent event) {
158
public void buildFinished(BuildEvent event) {
159
cause = event.getException();
162
public void targetStarted(BuildEvent event) {
164
public void targetFinished(BuildEvent event) {
166
public void taskStarted(BuildEvent event) {
168
public void taskFinished(BuildEvent event) {
170
public void messageLogged(BuildEvent event) {