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 |
|
|
18 |
package com.nokia.ant;
|
|
19 |
|
|
20 |
import java.util.Iterator;
|
|
21 |
|
|
22 |
import org.apache.tools.ant.BuildEvent;
|
|
23 |
import org.apache.tools.ant.Project;
|
|
24 |
import com.nokia.helium.core.ant.types.*;
|
|
25 |
|
|
26 |
import org.apache.tools.ant.BuildListener;
|
|
27 |
import org.apache.tools.ant.BuildLogger;
|
|
28 |
|
|
29 |
/**
|
|
30 |
*
|
|
31 |
*/
|
|
32 |
public class HelpDef extends HlmPostDefImpl
|
|
33 |
{
|
|
34 |
|
|
35 |
/**
|
|
36 |
*
|
|
37 |
* @param project
|
|
38 |
* Object of the project
|
|
39 |
* @param targetNames
|
|
40 |
* Array of target names to execute
|
|
41 |
*
|
|
42 |
*/
|
|
43 |
public void execute(Project project, String module, String[] targetNames)
|
|
44 |
{
|
|
45 |
String firstTarget;
|
|
46 |
|
|
47 |
// take target
|
|
48 |
if (targetNames != null && targetNames.length > 0)
|
|
49 |
{
|
|
50 |
firstTarget = targetNames[0];
|
|
51 |
}
|
|
52 |
else
|
|
53 |
// no target, so set the default one
|
|
54 |
{
|
|
55 |
firstTarget = "help";
|
|
56 |
}
|
|
57 |
|
|
58 |
// If 'help' target is called, just run that and set other
|
|
59 |
// target names as a property
|
|
60 |
if (firstTarget.equals("help"))
|
|
61 |
{
|
|
62 |
displayHelp(project, targetNames, firstTarget);
|
|
63 |
}
|
|
64 |
|
|
65 |
project.addBuildListener(new UnsubstListener());
|
|
66 |
}
|
|
67 |
|
|
68 |
class UnsubstListener implements BuildListener {
|
|
69 |
public void buildFinished(BuildEvent event) {
|
|
70 |
Project project = event.getProject();
|
|
71 |
String drivenotdef = project.getProperty("build.drive.notdefined");
|
|
72 |
if (System.getProperty("os.name").toLowerCase().startsWith("win") && drivenotdef != null && drivenotdef.equals("true"))
|
|
73 |
{
|
|
74 |
String drive = project.getProperty("build.drive");
|
|
75 |
try {
|
|
76 |
if (drive != null) {
|
|
77 |
Runtime.getRuntime().exec("subst /d " + drive);
|
|
78 |
}
|
|
79 |
} catch (java.io.IOException e) {
|
|
80 |
e = null; // ignoring the error
|
|
81 |
}
|
|
82 |
}
|
|
83 |
}
|
|
84 |
|
|
85 |
public void buildStarted(BuildEvent event) { }
|
|
86 |
public void targetStarted(BuildEvent event) { }
|
|
87 |
public void targetFinished(BuildEvent event) { }
|
|
88 |
public void taskStarted(BuildEvent event) { }
|
|
89 |
public void taskFinished(BuildEvent event) { }
|
|
90 |
public void messageLogged(BuildEvent event) { }
|
|
91 |
}
|
|
92 |
|
|
93 |
private void displayHelp(Project project, String[] targetNames, String firstTarget)
|
|
94 |
{
|
|
95 |
if (targetNames.length > 1)
|
|
96 |
{
|
|
97 |
project.setProperty("help.target", targetNames[1]);
|
|
98 |
}
|
|
99 |
|
|
100 |
// Set Emacs mode to true for all listeners, so that help text does
|
|
101 |
// not have [echo] at the start of each line
|
|
102 |
Iterator iter = project.getBuildListeners().iterator();
|
|
103 |
while (iter.hasNext())
|
|
104 |
{
|
|
105 |
BuildListener listener = (BuildListener) iter.next();
|
|
106 |
if (listener instanceof BuildLogger)
|
|
107 |
{
|
|
108 |
BuildLogger logger = (BuildLogger) listener;
|
|
109 |
logger.setEmacsMode(true);
|
|
110 |
}
|
|
111 |
}
|
|
112 |
|
|
113 |
// Run the 'help' target
|
|
114 |
project.executeTarget(firstTarget);
|
|
115 |
}
|
|
116 |
|
|
117 |
}
|