1 /* |
1 /* |
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of the License "Eclipse Public License v1.0" |
5 * under the terms of the License "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
8 * |
8 * |
9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 package com.nokia.ant; |
18 package com.nokia.ant; |
19 |
19 |
20 import java.util.Iterator; |
20 import java.util.Iterator; |
21 |
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; |
22 import org.apache.tools.ant.BuildListener; |
27 import org.apache.tools.ant.BuildLogger; |
23 import org.apache.tools.ant.BuildLogger; |
|
24 import org.apache.tools.ant.Project; |
|
25 import org.apache.tools.ant.types.DataType; |
|
26 |
|
27 import com.nokia.helium.core.ant.PostBuildAction; |
28 |
28 |
29 /** |
29 /** |
30 * |
30 * |
31 */ |
31 */ |
32 public class HelpDef extends HlmPostDefImpl |
32 public class HelpDef extends DataType implements PostBuildAction { |
33 { |
|
34 |
33 |
35 /** |
34 /** |
36 * |
35 * |
37 * @param project |
36 * @param project Object of the project |
38 * Object of the project |
37 * @param targetNames Array of target names to execute |
39 * @param targetNames |
|
40 * Array of target names to execute |
|
41 * |
38 * |
42 */ |
39 */ |
43 public void execute(Project project, String module, String[] targetNames) |
40 public void executeOnPostBuild(Project project, String[] targetNames) { |
44 { |
|
45 String firstTarget; |
41 String firstTarget; |
46 |
|
47 // take target |
42 // take target |
48 if (targetNames != null && targetNames.length > 0) |
43 if (targetNames != null && targetNames.length > 0) { |
49 { |
|
50 firstTarget = targetNames[0]; |
44 firstTarget = targetNames[0]; |
51 } |
45 } |
52 else |
|
53 // no target, so set the default one |
46 // no target, so set the default one |
54 { |
47 else { |
55 firstTarget = "help"; |
48 firstTarget = "help"; |
56 } |
49 } |
57 |
50 |
58 // If 'help' target is called, just run that and set other |
51 // If 'help' target is called, just run that and set other |
59 // target names as a property |
52 // target names as a property |
60 if (firstTarget.equals("help")) |
53 if (firstTarget.equals("help")) { |
61 { |
|
62 displayHelp(project, targetNames, firstTarget); |
54 displayHelp(project, targetNames, firstTarget); |
63 } |
55 } |
64 |
|
65 project.addBuildListener(new UnsubstListener()); |
|
66 } |
56 } |
67 |
57 |
68 class UnsubstListener implements BuildListener { |
58 @SuppressWarnings("unchecked") |
69 public void buildFinished(BuildEvent event) { |
59 private void displayHelp(Project project, String[] targetNames, String firstTarget) { |
70 Project project = event.getProject(); |
60 if (targetNames.length > 1) { |
71 String drivenotdef = project.getProperty("build.drive.notdefined"); |
61 project.setProperty("help.item", targetNames[1]); |
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 } |
62 } |
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 |
63 |
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 |
64 // Set Emacs mode to true for all listeners, so that help text does |
101 // not have [echo] at the start of each line |
65 // not have [echo] at the start of each line |
102 Iterator iter = project.getBuildListeners().iterator(); |
66 Iterator iter = project.getBuildListeners().iterator(); |
103 while (iter.hasNext()) |
67 while (iter.hasNext()) { |
104 { |
|
105 BuildListener listener = (BuildListener) iter.next(); |
68 BuildListener listener = (BuildListener) iter.next(); |
106 if (listener instanceof BuildLogger) |
69 if (listener instanceof BuildLogger) { |
107 { |
|
108 BuildLogger logger = (BuildLogger) listener; |
70 BuildLogger logger = (BuildLogger) listener; |
109 logger.setEmacsMode(true); |
71 logger.setEmacsMode(true); |
110 } |
72 } |
111 } |
73 } |
112 |
74 |
113 // Run the 'help' target |
75 // Run the 'help' target |
114 project.executeTarget(firstTarget); |
76 project.executeTarget(firstTarget); |
115 } |
77 } |
116 |
|
117 } |
78 } |