587
|
1 |
/*
|
628
|
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 |
|
587
|
18 |
package com.nokia.ant;
|
|
19 |
|
|
20 |
import java.util.Iterator;
|
|
21 |
|
|
22 |
import org.apache.tools.ant.BuildListener;
|
|
23 |
import org.apache.tools.ant.BuildLogger;
|
628
|
24 |
import org.apache.tools.ant.Project;
|
|
25 |
import org.apache.tools.ant.types.DataType;
|
|
26 |
|
|
27 |
import com.nokia.helium.core.ant.PostBuildAction;
|
587
|
28 |
|
|
29 |
/**
|
|
30 |
*
|
|
31 |
*/
|
628
|
32 |
public class HelpDef extends DataType implements PostBuildAction {
|
587
|
33 |
|
|
34 |
/**
|
|
35 |
*
|
628
|
36 |
* @param project Object of the project
|
|
37 |
* @param targetNames Array of target names to execute
|
587
|
38 |
*
|
|
39 |
*/
|
628
|
40 |
public void executeOnPostBuild(Project project, String[] targetNames) {
|
587
|
41 |
String firstTarget;
|
|
42 |
// take target
|
628
|
43 |
if (targetNames != null && targetNames.length > 0) {
|
587
|
44 |
firstTarget = targetNames[0];
|
|
45 |
}
|
|
46 |
// no target, so set the default one
|
628
|
47 |
else {
|
587
|
48 |
firstTarget = "help";
|
|
49 |
}
|
|
50 |
|
|
51 |
// If 'help' target is called, just run that and set other
|
|
52 |
// target names as a property
|
628
|
53 |
if (firstTarget.equals("help")) {
|
587
|
54 |
displayHelp(project, targetNames, firstTarget);
|
|
55 |
}
|
|
56 |
}
|
|
57 |
|
628
|
58 |
@SuppressWarnings("unchecked")
|
|
59 |
private void displayHelp(Project project, String[] targetNames, String firstTarget) {
|
|
60 |
if (targetNames.length > 1) {
|
|
61 |
project.setProperty("help.item", targetNames[1]);
|
587
|
62 |
}
|
|
63 |
|
|
64 |
// Set Emacs mode to true for all listeners, so that help text does
|
|
65 |
// not have [echo] at the start of each line
|
|
66 |
Iterator iter = project.getBuildListeners().iterator();
|
628
|
67 |
while (iter.hasNext()) {
|
587
|
68 |
BuildListener listener = (BuildListener) iter.next();
|
628
|
69 |
if (listener instanceof BuildLogger) {
|
587
|
70 |
BuildLogger logger = (BuildLogger) listener;
|
|
71 |
logger.setEmacsMode(true);
|
|
72 |
}
|
|
73 |
}
|
|
74 |
|
|
75 |
// Run the 'help' target
|
|
76 |
project.executeTarget(firstTarget);
|
|
77 |
}
|
|
78 |
}
|