buildframework/helium/sf/java/legacy/src/com/nokia/ant/util/ToolsProcess.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
/*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
* All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
* This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
* which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
* Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
* Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
* Description: 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
*/
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
package com.nokia.ant.util;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    20
import org.apache.log4j.Logger;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
import com.nokia.tools.Tool;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import com.nokia.tools.ToolsProcessException;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
/**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
 * Utility class to read property value, if property is not defined it will raise an exception.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
 */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
public final class ToolsProcess {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
    private static Logger log;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
    private ToolsProcess() { }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
    public static Tool getTool(String reqTool) throws ToolsProcessException {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
        if (log == null) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
            log = Logger.getLogger(ToolsProcess.class);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
        log.info("processing for tool" + reqTool);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
        Class toolClass = null;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
        String className = "com.nokia.tools."
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
            + reqTool.toLowerCase() + "." + reqTool.toUpperCase()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
            + "Tool";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
        try {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
            toolClass = Class.forName(className);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
            Tool tool = (Tool) toolClass.newInstance();
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
            log.debug("Found tool" + reqTool);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
            return tool;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
        } catch (ClassNotFoundException e1) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
            throw new ToolsProcessException("tool not supported: " + className);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
        } catch (InstantiationException e2) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
            throw new ToolsProcessException("tool " + toolClass
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
                    + "cannot be instantiated");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
        } catch (IllegalAccessException e3) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
            throw new ToolsProcessException("tool " + toolClass
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
                    + " cannot be accessed");
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
}