buildframework/helium/sf/java/logging/src/com/nokia/helium/logger/ant/taskdefs/TriggerLoggerTask.java
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 588 c7c26511138f
child 645 b8d81fa19e7d
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     1
/*
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     2
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     3
* All rights reserved.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     4
* This component and the accompanying materials are made available
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     6
* which accompanies this distribution, and is available
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     8
*
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
     9
* Initial Contributors:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    11
*
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    12
* Contributors:
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    13
*
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    14
* Description:  
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    15
*
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    16
*/
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    17
package com.nokia.helium.logger.ant.taskdefs;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    18
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    19
import org.apache.log4j.Logger;
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    20
import org.apache.tools.ant.Project;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    21
import org.apache.tools.ant.Task;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    22
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    23
import com.nokia.helium.logger.ant.listener.AntLoggingHandler;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    24
import com.nokia.helium.logger.ant.listener.StatusAndLogListener;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    25
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    26
/**
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    27
 * This task is used to start the helium logging listener.
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    28
 * @ant.task name="triggerlogger" category="Logging"
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    29
 */
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    30
public class TriggerLoggerTask extends Task {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    31
    
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    32
    private Logger log = Logger.getLogger(TriggerLoggerTask.class);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    33
    
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    34
    public void execute() {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    35
        log.debug("Registering Ant logging to StatusAndLogListener listener");
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    36
        if (StatusAndLogListener.getStatusAndLogListener() == null) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    37
            this.log("The StatusAndLogListener is not available.", Project.MSG_WARN);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    38
            return;
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    39
        }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    40
        AntLoggingHandler antLoggingHandler = new AntLoggingHandler(getProject());
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    41
        StatusAndLogListener.getStatusAndLogListener().register(antLoggingHandler);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    42
        if (antLoggingHandler != null ) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    43
            if (!antLoggingHandler.getLoggingStarted()) {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    44
                log.debug("Starting Logging using 'AntLoggingHandler' first time.");
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    45
                antLoggingHandler.setLoggingStarted(true);
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    46
            } else {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    47
                log.debug("'AntLoggingHandler' is already started logging.");
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    48
            }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    49
        } else {
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    50
            log.debug("Could not find the AntLoggingHandler instance.");
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    51
        }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    52
    }
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    53
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents:
diff changeset
    54
}