628
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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 |
|
|
18 |
package com.nokia.helium.environment.ant.listener;
|
|
19 |
|
|
20 |
import java.io.FileWriter;
|
|
21 |
import java.io.IOException;
|
|
22 |
import java.util.ArrayList;
|
|
23 |
import java.util.Hashtable;
|
|
24 |
import java.util.Iterator;
|
|
25 |
import java.util.List;
|
|
26 |
|
|
27 |
import org.apache.log4j.Logger;
|
|
28 |
import org.apache.tools.ant.BuildEvent;
|
|
29 |
import org.apache.tools.ant.BuildListener;
|
|
30 |
import org.apache.tools.ant.Project;
|
|
31 |
import org.apache.tools.ant.RuntimeConfigurable;
|
|
32 |
import org.apache.tools.ant.Task;
|
|
33 |
import org.apache.tools.ant.UnknownElement;
|
|
34 |
|
|
35 |
/**
|
|
36 |
* Checks for uses of the <exec> task and logs them to a CSV file.
|
|
37 |
*
|
|
38 |
* The ExecListener.file property should be used to define a file to log the output to.
|
|
39 |
*/
|
|
40 |
public class ExecListener implements BuildListener {
|
|
41 |
private static List<String> execCalls = new ArrayList<String>();
|
|
42 |
|
|
43 |
private Logger logger = Logger.getLogger(this.getClass());
|
|
44 |
|
|
45 |
public static List<String> getExecCalls() {
|
|
46 |
return execCalls;
|
|
47 |
}
|
|
48 |
|
|
49 |
@Override
|
|
50 |
public void buildStarted(BuildEvent event) {
|
|
51 |
logger.debug("ExecListener started");
|
|
52 |
}
|
|
53 |
|
|
54 |
@Override
|
|
55 |
public void buildFinished(BuildEvent event) {
|
|
56 |
try {
|
|
57 |
String file = event.getProject().getProperty("ExecListener.file");
|
|
58 |
if (file != null && file.length() > 0) {
|
|
59 |
FileWriter out = new FileWriter(file);
|
|
60 |
for (Iterator<String> iterator = execCalls.iterator(); iterator.hasNext();) {
|
|
61 |
String execCall = (String) iterator.next();
|
|
62 |
out.write(execCall + "\n");
|
|
63 |
}
|
|
64 |
out.close();
|
|
65 |
}
|
|
66 |
}
|
|
67 |
catch (IOException e) {
|
|
68 |
e.printStackTrace();
|
|
69 |
}
|
|
70 |
}
|
|
71 |
|
|
72 |
@Override
|
|
73 |
public void messageLogged(BuildEvent event) {
|
|
74 |
}
|
|
75 |
|
|
76 |
@Override
|
|
77 |
public void targetStarted(BuildEvent event) {
|
|
78 |
}
|
|
79 |
|
|
80 |
@Override
|
|
81 |
public void targetFinished(BuildEvent event) {
|
|
82 |
}
|
|
83 |
|
|
84 |
@Override
|
|
85 |
public void taskStarted(BuildEvent event) {
|
|
86 |
}
|
|
87 |
|
|
88 |
/**
|
|
89 |
* Attempt to log the name of the an exec task if one is executed.
|
|
90 |
*/
|
|
91 |
@SuppressWarnings("unchecked")
|
|
92 |
@Override
|
|
93 |
public void taskFinished(BuildEvent event) {
|
|
94 |
Task task = event.getTask();
|
|
95 |
String taskName = task.getTaskName();
|
|
96 |
if (taskName != null && taskName.equals("exec")) {
|
|
97 |
logger.debug("Found exec task");
|
|
98 |
if (task instanceof UnknownElement) {
|
|
99 |
RuntimeConfigurable configurable = ((UnknownElement) task).getRuntimeConfigurableWrapper();
|
|
100 |
Hashtable<String, String> map = configurable.getAttributeMap();
|
|
101 |
String executable = (String) map.get("executable");
|
|
102 |
Project project = event.getProject();
|
|
103 |
executable = project.replaceProperties(executable);
|
|
104 |
logger.debug("ExecListener: executable is run: " + executable);
|
|
105 |
execCalls.add(executable);
|
|
106 |
}
|
|
107 |
}
|
|
108 |
}
|
|
109 |
}
|
|
110 |
|
|
111 |
|
|
112 |
|