587
|
1 |
/*
|
|
2 |
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
3 |
* contributor license agreements. See the NOTICE file distributed with
|
|
4 |
* this work for additional information regarding copyright ownership.
|
|
5 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
6 |
* (the "License"); you may not use this file except in compliance with
|
|
7 |
* the License. You may obtain a copy of the License at
|
|
8 |
*
|
|
9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10 |
*
|
|
11 |
* Unless required by applicable law or agreed to in writing, software
|
|
12 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14 |
* See the License for the specific language governing permissions and
|
|
15 |
* limitations under the License.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
/* Portion Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. */
|
|
20 |
|
|
21 |
package com.nokia.ant.taskdefs;
|
|
22 |
|
|
23 |
import java.util.Hashtable;
|
628
|
24 |
|
587
|
25 |
import org.apache.tools.ant.BuildException;
|
|
26 |
import org.apache.tools.ant.Project;
|
|
27 |
import org.apache.tools.ant.taskdefs.Recorder;
|
|
28 |
|
588
|
29 |
import com.nokia.ant.listener.CoverageRecorderEntry;
|
|
30 |
|
587
|
31 |
/**
|
|
32 |
* Adds a listener, which inherits the Ant Record task, to the current build process that records the
|
|
33 |
* output to a XML file.
|
|
34 |
*/
|
|
35 |
public class CoverageRecorderTask extends Recorder {
|
|
36 |
|
|
37 |
//////////////////////////////////////////////////////////////////////
|
|
38 |
// ATTRIBUTES
|
|
39 |
|
|
40 |
/** The list of recorder entries. */
|
|
41 |
private static Hashtable<String, CoverageRecorderEntry> recorderEntries = new Hashtable<String, CoverageRecorderEntry>();
|
|
42 |
|
|
43 |
/** The name of the file to record to. */
|
|
44 |
private String filename;
|
|
45 |
/**
|
|
46 |
* Whether to start or stop recording. Need Boolean to record an unset
|
|
47 |
* state (null).
|
|
48 |
*/
|
|
49 |
private Boolean start;
|
|
50 |
/** The level to log at. A level of -1 means not initialized yet. */
|
|
51 |
private int loglevel = -1;
|
|
52 |
|
|
53 |
//////////////////////////////////////////////////////////////////////
|
|
54 |
// ACCESSOR METHODS
|
|
55 |
|
|
56 |
/**
|
|
57 |
* Sets the name of the file to log to, and the name of the recorder
|
|
58 |
* entry.
|
|
59 |
*
|
|
60 |
* @param fname File name of logfile.
|
|
61 |
*/
|
|
62 |
public void setName(String fname) {
|
|
63 |
filename = fname;
|
|
64 |
}
|
|
65 |
|
|
66 |
|
|
67 |
/**
|
|
68 |
* Sets the action for the associated recorder entry.
|
|
69 |
*
|
|
70 |
* @param action The action for the entry to take: start or stop.
|
|
71 |
*/
|
|
72 |
public void setAction(ActionChoices action) {
|
|
73 |
if (action.getValue().equalsIgnoreCase("start")) {
|
|
74 |
start = Boolean.TRUE;
|
|
75 |
} else {
|
|
76 |
start = Boolean.FALSE;
|
|
77 |
}
|
|
78 |
}
|
|
79 |
|
|
80 |
|
|
81 |
/**
|
|
82 |
* Sets the level to which this recorder entry should log to.
|
|
83 |
* @param level the level to set.
|
|
84 |
* see VerbosityLevelChoices
|
|
85 |
*/
|
|
86 |
public void setLoglevel(VerbosityLevelChoices level) {
|
|
87 |
loglevel = level.getLevel();
|
|
88 |
}
|
|
89 |
|
|
90 |
//////////////////////////////////////////////////////////////////////
|
|
91 |
// CORE / MAIN BODY
|
|
92 |
|
|
93 |
/**
|
|
94 |
* The main execution.
|
|
95 |
* @throws BuildException on error
|
|
96 |
*/
|
|
97 |
public void execute() {
|
|
98 |
if (filename == null) {
|
|
99 |
throw new BuildException("No filename specified");
|
|
100 |
}
|
|
101 |
|
|
102 |
getProject().log("setting a recorder for name " + filename,
|
|
103 |
Project.MSG_DEBUG);
|
|
104 |
|
|
105 |
String recordTaskName = this.getTaskName();
|
|
106 |
|
|
107 |
// get the recorder entry
|
|
108 |
CoverageRecorderEntry recorder = getRecorder(filename, getProject(), recordTaskName);
|
|
109 |
if (start != null) {
|
|
110 |
if (start.booleanValue()) {
|
|
111 |
//recorder.reopenFile();
|
|
112 |
recorder.setRecordState(start);
|
|
113 |
} else {
|
|
114 |
recorder.setRecordState(start);
|
|
115 |
recorder.cleanup();
|
|
116 |
}
|
|
117 |
}
|
|
118 |
}
|
|
119 |
|
|
120 |
/**
|
|
121 |
* Gets the recorder that's associated with the passed in name. If the
|
|
122 |
* recorder doesn't exist, then a new one is created.
|
|
123 |
* @param name the name of the recoder
|
|
124 |
* @param proj the current project
|
|
125 |
* @return a recorder
|
|
126 |
* @throws BuildException on error
|
|
127 |
*/
|
|
128 |
protected CoverageRecorderEntry getRecorder(String name, Project proj, String recordTaskName)
|
|
129 |
{
|
|
130 |
CoverageRecorderEntry entry = recorderEntries.get(name);
|
|
131 |
|
|
132 |
if (entry == null) {
|
|
133 |
// create a recorder entry
|
|
134 |
entry = new CoverageRecorderEntry(name, recordTaskName);
|
|
135 |
entry.setProject(proj);
|
|
136 |
recorderEntries.put(name, entry);
|
|
137 |
}
|
|
138 |
return entry;
|
|
139 |
}
|
|
140 |
}
|
|
141 |
|