587
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
package com.nokia.helium.core.plexus.tests;
|
|
18 |
|
628
|
19 |
import static org.junit.Assert.assertTrue;
|
|
20 |
|
587
|
21 |
import org.apache.tools.ant.BuildEvent;
|
|
22 |
import org.apache.tools.ant.BuildListener;
|
|
23 |
import org.apache.tools.ant.Project;
|
|
24 |
import org.apache.tools.ant.taskdefs.Echo;
|
|
25 |
import org.junit.Test;
|
628
|
26 |
|
587
|
27 |
import com.nokia.helium.core.plexus.AntStreamConsumer;
|
|
28 |
|
|
29 |
public class TestAntStreamConsumer {
|
|
30 |
|
|
31 |
public class AntBuildListener implements BuildListener {
|
|
32 |
private StringBuffer log = new StringBuffer();
|
|
33 |
|
|
34 |
public StringBuffer getLog() {
|
|
35 |
return log;
|
|
36 |
}
|
|
37 |
|
|
38 |
@Override
|
|
39 |
public void buildFinished(BuildEvent arg0) {
|
|
40 |
}
|
|
41 |
|
|
42 |
@Override
|
|
43 |
public void buildStarted(BuildEvent arg0) {
|
|
44 |
}
|
|
45 |
|
|
46 |
@Override
|
|
47 |
public void messageLogged(BuildEvent arg0) {
|
|
48 |
log.append(arg0.getMessage());
|
|
49 |
}
|
|
50 |
|
|
51 |
@Override
|
|
52 |
public void targetFinished(BuildEvent arg0) {
|
|
53 |
}
|
|
54 |
|
|
55 |
@Override
|
|
56 |
public void targetStarted(BuildEvent arg0) {
|
|
57 |
}
|
|
58 |
|
|
59 |
@Override
|
|
60 |
public void taskFinished(BuildEvent arg0) {
|
|
61 |
}
|
|
62 |
|
|
63 |
@Override
|
|
64 |
public void taskStarted(BuildEvent arg0) {
|
|
65 |
}
|
|
66 |
|
|
67 |
}
|
|
68 |
|
|
69 |
@Test
|
|
70 |
public void testLoggingThroughAnt() {
|
|
71 |
// Setting up an Ant task
|
|
72 |
Project project = new Project();
|
|
73 |
AntBuildListener listener = new AntBuildListener();
|
|
74 |
project.addBuildListener(listener);
|
|
75 |
project.init();
|
|
76 |
Echo echo = new Echo();
|
|
77 |
echo.setProject(project);
|
|
78 |
echo.setMessage("From the echo task");
|
|
79 |
|
|
80 |
|
|
81 |
// Configuring the Ant consumer
|
|
82 |
AntStreamConsumer consumer = new AntStreamConsumer(echo);
|
|
83 |
consumer.consumeLine("consumed line!");
|
|
84 |
echo.execute();
|
|
85 |
assertTrue(listener.getLog().toString().contains("From the echo task"));
|
|
86 |
assertTrue(listener.getLog().toString().contains("consumed line!"));
|
|
87 |
|
|
88 |
}
|
|
89 |
|
|
90 |
@Test
|
|
91 |
public void testLoggingThroughAntAsError() {
|
|
92 |
// Setting up an Ant task
|
|
93 |
Project project = new Project();
|
|
94 |
AntBuildListener listener = new AntBuildListener();
|
|
95 |
project.addBuildListener(listener);
|
|
96 |
project.init();
|
|
97 |
Echo echo = new Echo();
|
|
98 |
echo.setProject(project);
|
|
99 |
echo.setMessage("From the echo task");
|
|
100 |
|
|
101 |
|
|
102 |
// Configuring the Ant consumer
|
|
103 |
AntStreamConsumer consumer = new AntStreamConsumer(echo, Project.MSG_ERR);
|
|
104 |
consumer.consumeLine("consumed line!");
|
|
105 |
echo.execute();
|
|
106 |
assertTrue(listener.getLog().toString().contains("From the echo task"));
|
|
107 |
assertTrue(listener.getLog().toString().contains("consumed line!"));
|
|
108 |
|
|
109 |
}
|
|
110 |
|
|
111 |
|
|
112 |
}
|