587
|
1 |
/*
|
628
|
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 |
*/
|
587
|
17 |
|
|
18 |
package com.nokia.helium.core.ant.types;
|
|
19 |
|
628
|
20 |
import org.apache.log4j.Logger;
|
|
21 |
import org.apache.tools.ant.BuildException;
|
587
|
22 |
import org.apache.tools.ant.BuildListener;
|
628
|
23 |
import org.apache.tools.ant.Project;
|
|
24 |
import org.apache.tools.ant.types.DataType;
|
|
25 |
|
|
26 |
import com.nokia.helium.core.ant.PreBuildAction;
|
587
|
27 |
|
|
28 |
/**
|
|
29 |
* This class implements a listener registration action.
|
|
30 |
*
|
|
31 |
* @ant.type name="listenerdef" category="Core"
|
|
32 |
*/
|
628
|
33 |
public class HlmListenerDef extends DataType implements PreBuildAction {
|
587
|
34 |
|
|
35 |
private String classname;
|
|
36 |
private Logger log = Logger.getLogger(HlmListenerDef.class);
|
|
37 |
|
|
38 |
public void setClassname(String classname) {
|
|
39 |
this.classname = classname;
|
|
40 |
}
|
|
41 |
|
|
42 |
/**
|
|
43 |
* Register given listener to the project.
|
|
44 |
*/
|
628
|
45 |
public void executeOnPreBuild(Project project, String[] targetNames) {
|
587
|
46 |
try {
|
|
47 |
Class<?> listenerClass = Class.forName(classname);
|
|
48 |
BuildListener listener = (BuildListener) listenerClass
|
|
49 |
.newInstance();
|
628
|
50 |
project.addBuildListener(listener);
|
|
51 |
log.debug(classname + " is registered");
|
587
|
52 |
} catch (ClassNotFoundException ex) {
|
628
|
53 |
throw new BuildException("Class not found exception:"
|
|
54 |
+ ex.getMessage(), ex);
|
587
|
55 |
} catch (InstantiationException ex1) {
|
628
|
56 |
throw new BuildException("Class Instantiation exception:"
|
|
57 |
+ ex1.getMessage(), ex1);
|
587
|
58 |
} catch (IllegalAccessException ex1) {
|
628
|
59 |
throw new BuildException("Illegal Class Access exception:"
|
|
60 |
+ ex1.getMessage(), ex1);
|
587
|
61 |
}
|
|
62 |
}
|
|
63 |
} |