buildframework/helium/sf/java/legacy/src/com/nokia/ant/HelpDef.java
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 587 85df38eb4012
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
/*
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
     2
 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
     3
 * All rights reserved.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
     4
 * This component and the accompanying materials are made available
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
     6
 * which accompanies this distribution, and is available
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
     8
 *
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
     9
 * Initial Contributors:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    10
 * Nokia Corporation - initial contribution.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    11
 *
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    12
 * Contributors:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    13
 *
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    14
 * Description: 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    15
 *
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    16
 */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    17
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
package com.nokia.ant;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
import java.util.Iterator;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
import org.apache.tools.ant.BuildListener;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import org.apache.tools.ant.BuildLogger;
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    24
import org.apache.tools.ant.Project;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    25
import org.apache.tools.ant.types.DataType;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    26
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    27
import com.nokia.helium.core.ant.PostBuildAction;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
/**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
 * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
 */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    32
public class HelpDef extends DataType implements PostBuildAction {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
     * 
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    36
     * @param project Object of the project
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    37
     * @param targetNames Array of target names to execute
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
     * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
     */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    40
    public void executeOnPostBuild(Project project, String[] targetNames) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
        String firstTarget;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
        // take target
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    43
        if (targetNames != null && targetNames.length > 0) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
            firstTarget = targetNames[0];
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
        // no target, so set the default one
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    47
        else {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
            firstTarget = "help";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
        // If 'help' target is called, just run that and set other
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
        // target names as a property
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    53
        if (firstTarget.equals("help")) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
            displayHelp(project, targetNames, firstTarget);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    58
    @SuppressWarnings("unchecked")
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    59
    private void displayHelp(Project project, String[] targetNames, String firstTarget) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    60
        if (targetNames.length > 1) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    61
            project.setProperty("help.item", targetNames[1]);
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
        // Set Emacs mode to true for all listeners, so that help text does
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
        // not have [echo] at the start of each line
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
        Iterator iter = project.getBuildListeners().iterator();
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    67
        while (iter.hasNext()) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
            BuildListener listener = (BuildListener) iter.next();
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    69
            if (listener instanceof BuildLogger) {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
                BuildLogger logger = (BuildLogger) listener;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
                logger.setEmacsMode(true);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
            }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
        // Run the 'help' target
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
        project.executeTarget(firstTarget);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
}