Source Code Cross Referenced for NoUnitTask.java in  » Test-Coverage » NoUnit » net » firstpartners » nounit » ant » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Test Coverage » NoUnit » net.firstpartners.nounit.ant 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.firstpartners.nounit.ant;
002:
003:        import net.firstpartners.nounit.ui.common.CommandPackage;
004:        import net.firstpartners.nounit.ui.common.IProcessor;
005:        import net.firstpartners.nounit.ui.common.Processor;
006:        import net.firstpartners.nounit.ui.common.XMLProcessor;
007:        import net.firstpartners.nounit.utility.NoUnitException;
008:
009:        import org.apache.log4j.BasicConfigurator;
010:        import org.apache.log4j.PropertyConfigurator;
011:        import org.apache.log4j.Logger;
012:
013:        import org.apache.tools.ant.BuildException;
014:        import org.apache.tools.ant.Task;
015:
016:        import java.io.File;
017:
018:        /**
019:         * NoUnitTask
020:         * 
021:         * @see ant-run-nounit-report.xml for example of using task
022:         * @since Mar 24, 2003  
023:         * @author aglover
024:         * @version 0.7
025:         *
026:         */
027:        public class NoUnitTask extends Task {
028:
029:            private String startDirectory;
030:            private String outputDirectory;
031:            private String reportClass;
032:            private String userMessage;
033:            private String reportName;
034:            private String outputFile;
035:            private String xmlFileName;
036:            private String log4jConfig;
037:
038:            //handle to logger
039:            static Logger log = Logger.getLogger(NoUnitTask.class);
040:
041:            /**
042:             * Constructor for NoUnitTask.
043:             */
044:            public NoUnitTask() {
045:                super ();
046:            }
047:
048:            /**
049:             * Called by ant as part of initialisation process
050:             */
051:            public void init() {
052:
053:                //Call any other initialisation
054:                super .init();
055:
056:                //	Make sure Log4j is initialised property
057:                //Set up a simple configuration that logs on the console.
058:                if (this .log4jConfig == null) {
059:                    //Use Default Configuator
060:                    BasicConfigurator.configure();
061:                    System.out.println("using Default log4j file"); //ironic , but ensures logging
062:
063:                } else {
064:                    //Set configuration using supplied config file
065:                    PropertyConfigurator.configure(log4jConfig);
066:                    File logFile = new File(log4jConfig);
067:                    System.out.println("Using Log4j config file:"
068:                            + logFile.getAbsolutePath()); //ironic , but ensures logging
069:                }
070:
071:            }
072:
073:            /**
074:             * Method runs no unit against supplied attributes
075:             * @throws BuildException
076:             */
077:            public void execute() throws BuildException {
078:
079:                try {
080:                    //first validate
081:                    this .validateAttributes();
082:
083:                    //Get a command package - ie whatever way the parameters were passed in
084:                    // as a single easy to handle package
085:                    CommandPackage pckage = this .getCommandPackage();
086:
087:                    //Processor - what actually does the NoUnit work		
088:                    IProcessor mainProcessor = this .getProcessor();
089:
090:                    //Do the NoUnit Stuff
091:                    CommandPackage results = mainProcessor.transform(pckage);
092:
093:                    //show the result if any
094:                    super .handleOutput(results
095:                            .getString(CommandPackage.USER_MESSAGE));
096:
097:                } catch (NoUnitException ex) {
098:
099:                    //handle NoUnitExceptions
100:                    logExceptionTrace(ex);
101:                    throw new BuildException(
102:                            "NoUnitException occurred in Ant Task", ex);
103:
104:                } catch (Exception ex) {
105:
106:                    //handle all other exceptions
107:                    logExceptionTrace(ex);
108:                    throw new BuildException("Exception occurred in Ant Task",
109:                            ex);
110:                }
111:            }
112:
113:            /**
114:             * Utility method to log exception stack traces
115:             * @param exception exceptionToPrint
116:             */
117:            private void logExceptionTrace(Exception exceptionToPrint) {
118:
119:                //Get the Stack Elements
120:                StackTraceElement[] stackElements = exceptionToPrint
121:                        .getStackTrace();
122:
123:                //Now send them for Ant to display
124:                for (int a = 0; a < stackElements.length; a++) {
125:
126:                    super .handleErrorOutput(stackElements[a].toString());
127:                }
128:
129:            }
130:
131:            /**
132:             * 
133:             * @return IProcessor
134:             */
135:            private IProcessor getProcessor() {
136:                IProcessor processr = null;
137:
138:                //if report name and class are null, then we'll assume 
139:                //they want just the xml file processor
140:                if (this .isPropertyValid(this .reportClass)
141:                        && this .isPropertyValid(this .reportName)) {
142:                    processr = new Processor();
143:                    this .log("using the default processor");
144:                } else {
145:                    processr = new XMLProcessor();
146:                    this .log("using the XML Only processor");
147:                }
148:                return processr;
149:            }
150:
151:            /**
152:             * Get a Command (which actually runs NoUnit) initialized 
153:             * with the various parameters
154:             * @return CommandPackage
155:             */
156:            private CommandPackage getCommandPackage() {
157:
158:                CommandPackage pckage = new CommandPackage();
159:                //start dir and output dir are required 
160:                pckage.addValue(CommandPackage.START_DIR, this .startDirectory);
161:                pckage
162:                        .addValue(CommandPackage.OUTPUT_DIR,
163:                                this .outputDirectory);
164:
165:                if (this .isPropertyValid(this .reportClass)) {
166:                    pckage.addValue(CommandPackage.REPORT_CLASS,
167:                            this .reportClass);
168:                }
169:                if (this .isPropertyValid(this .reportName)) {
170:                    pckage.addValue("report_name", this .reportName);
171:                }
172:                if (this .isPropertyValid(this .outputFile)) {
173:                    pckage.addValue("output_file", this .outputFile);
174:                }
175:                if (this .isPropertyValid(this .xmlFileName)) {
176:                    pckage.addValue(CommandPackage.XML_OUTPUT_NAME,
177:                            this .xmlFileName);
178:                }
179:
180:                return pckage;
181:            }
182:
183:            /**
184:             * 
185:             * @param property
186:             * @return boolean
187:             */
188:            private boolean isPropertyValid(String property) {
189:                return (property != null && !property.equals(""));
190:            }
191:
192:            /**
193:             * quick and dirty data validation- there probably is a cleaner way
194:             * to do this....
195:             * @throws BuildException			  	
196:             */
197:            public void validateAttributes() throws BuildException {
198:                if ((this .startDirectory == null)
199:                        || (this .startDirectory.equals(""))
200:                        || (this .outputDirectory == null)
201:                        || (this .outputDirectory.equals(""))) {
202:                    throw new BuildException("Missing required attribute!");
203:                }
204:            }
205:
206:            /**
207:             * Sets the outputFile - accessor method
208:             * @param outputFile The outputFile to set
209:             */
210:            public void setOutputFile(String outputFile) {
211:                this .outputFile = outputFile;
212:            }
213:
214:            /**
215:             * Sets the reportClass - accessor method
216:             * @param reportClass The reportClass to set
217:             */
218:            public void setReportClass(String reportClass) {
219:                this .reportClass = reportClass;
220:            }
221:
222:            /**
223:             * Sets the reportName - accessor method
224:             * @param reportName The reportName to set
225:             */
226:            public void setReportName(String reportName) {
227:                this .reportName = reportName;
228:            }
229:
230:            /**
231:             * Sets the startDirectory  - accessor method
232:             * @param startDirectory The startDirectory to set
233:             */
234:            public void setStartDirectory(String startDirectory) {
235:                this .startDirectory = startDirectory;
236:                this .log("set start directory to:" + startDirectory);
237:            }
238:
239:            /**
240:             * Sets the userMessage- accessor method
241:             * @param userMessage The userMessage to set
242:             */
243:            public void setUserMessage(String userMessage) {
244:                this .userMessage = userMessage;
245:            }
246:
247:            /**
248:             * Sets the outputDirectory- accessor method
249:             * @param outputDirectory The outputDirectory to set
250:             */
251:            public void setOutputDirectory(String outputDirectory) {
252:                this .outputDirectory = outputDirectory;
253:                log.debug("Setting output directory to:" + outputDirectory);
254:            }
255:
256:            /**
257:             * Sets the XML File Name (interim file) - accessor method
258:             * @param string
259:             */
260:            public void setXmlFileName(String string) {
261:                xmlFileName = string;
262:                log.debug("Setting xml file name to:" + string);
263:            }
264:
265:            /**
266:             * Sets the XML File Name (interim file) - accessor method
267:             * @param string
268:             */
269:            public void setLog4jConfig(String string) {
270:                log4jConfig = string;
271:                log.debug("Setting log4j config to:" + string);
272:            }
273:
274:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.