|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| Output.java | 50% | 83,3% | 92,9% | 81,8% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* Copyright (C) 2003, Marco Jansen / Contrado Technologies (http://www.contrado.nl)
|
|
| 3 |
*
|
|
| 4 |
* This program is free software; you can redistribute it and/or
|
|
| 5 |
* modify it under the terms of the GNU General Public License as
|
|
| 6 |
* published by the Free Software Foundation; either version 2 of the
|
|
| 7 |
* License, or (at your option) any later version.
|
|
| 8 |
*
|
|
| 9 |
* This program is distributed in the hope that it will be useful, but
|
|
| 10 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
| 12 |
* General Public License for more details.
|
|
| 13 |
*/
|
|
| 14 |
|
|
| 15 |
package net.sourceforge.anttestsetgen;
|
|
| 16 |
|
|
| 17 |
import net.sourceforge.anttestsetgen.renderer.JavaRenderer;
|
|
| 18 |
import net.sourceforge.anttestsetgen.renderer.PropertyFileRenderer;
|
|
| 19 |
import net.sourceforge.anttestsetgen.renderer.Renderer;
|
|
| 20 |
import net.sourceforge.anttestsetgen.renderer.XMLRenderer;
|
|
| 21 |
import org.apache.tools.ant.BuildException;
|
|
| 22 |
import org.apache.tools.ant.Task;
|
|
| 23 |
|
|
| 24 |
import java.util.HashMap;
|
|
| 25 |
import java.util.Map;
|
|
| 26 |
|
|
| 27 |
/**
|
|
| 28 |
* The Output object describes how the TestSetGenerator should generate files.
|
|
| 29 |
*
|
|
| 30 |
* @author <a href="mailto:m.c.jansen.spam at planet.nl">Marco Jansen (Contrado Technologies)</a>
|
|
| 31 |
* @version $Id: Output.java,v 1.1 2004/01/04 15:00:18 mcjansen Exp $
|
|
| 32 |
*/
|
|
| 33 |
public class Output extends Task { |
|
| 34 |
|
|
| 35 |
private static Map RENDERERS = new HashMap(); |
|
| 36 |
private String type;
|
|
| 37 |
private String destination;
|
|
| 38 |
private String packageName;
|
|
| 39 |
private String className;
|
|
| 40 |
private String file;
|
|
| 41 |
private Renderer renderer;
|
|
| 42 |
private String root;
|
|
| 43 |
private boolean onlyxml = false; |
|
| 44 |
|
|
| 45 |
static {
|
|
| 46 | 24 |
RENDERERS.put("JAVA", new JavaRenderer()); |
| 47 | 24 |
RENDERERS.put("XML", new XMLRenderer()); |
| 48 | 24 |
RENDERERS.put("PROPERTYFILE", new PropertyFileRenderer()); |
| 49 |
} |
|
| 50 |
|
|
| 51 |
/**
|
|
| 52 |
* Set the type of outputfile that should be generated.
|
|
| 53 |
*
|
|
| 54 |
* @param type The type of output file
|
|
| 55 |
* @throws BuildException In case the type is invalid.
|
|
| 56 |
*/
|
|
| 57 | 68 |
public void setType(String type) { |
| 58 | 68 |
if (type == null) { |
| 59 | 0 |
throw new BuildException("Type should not be null"); |
| 60 |
} |
|
| 61 |
|
|
| 62 | 68 |
if (RENDERERS.containsKey(type.toUpperCase())) {
|
| 63 | 66 |
this.type = type.toUpperCase();
|
| 64 | 66 |
this.renderer = (Renderer) RENDERERS.get(type.toUpperCase());
|
| 65 |
} else {
|
|
| 66 | 2 |
throw new BuildException("Type should contain one of the following values: " + RENDERERS.keySet()); |
| 67 |
} |
|
| 68 |
} |
|
| 69 |
|
|
| 70 |
/** Set the destination where the files should be generated.
|
|
| 71 |
*
|
|
| 72 |
* @param destination A valid path in the file system.
|
|
| 73 |
*/
|
|
| 74 | 14 |
public void setDestination(String destination) { |
| 75 | 14 |
this.destination = destination;
|
| 76 |
} |
|
| 77 |
|
|
| 78 |
/**
|
|
| 79 |
* Retrieve the destination.
|
|
| 80 |
*
|
|
| 81 |
* @return A path in the file system.
|
|
| 82 |
*/
|
|
| 83 | 24 |
public String getDestination() {
|
| 84 | 24 |
return destination;
|
| 85 |
} |
|
| 86 |
|
|
| 87 |
/**
|
|
| 88 |
* Set the name of the java package.
|
|
| 89 |
*
|
|
| 90 |
* @param packageName A java package name
|
|
| 91 |
*/
|
|
| 92 | 6 |
public void setPackageName(String packageName) { |
| 93 | 6 |
this.packageName = packageName;
|
| 94 |
} |
|
| 95 |
|
|
| 96 |
/**
|
|
| 97 |
* Retrieve the name of the java package
|
|
| 98 |
* @return A java package name
|
|
| 99 |
*/
|
|
| 100 | 24 |
public String getPackageName() {
|
| 101 | 24 |
return packageName;
|
| 102 |
} |
|
| 103 |
|
|
| 104 |
/**
|
|
| 105 |
* Set the name of the Java class to be generated.
|
|
| 106 |
*
|
|
| 107 |
* @param className The name of a Java class.
|
|
| 108 |
*/
|
|
| 109 | 6 |
public void setClassName(String className) { |
| 110 | 6 |
this.className = className;
|
| 111 |
} |
|
| 112 |
|
|
| 113 |
/**
|
|
| 114 |
* Retrieve the name of the Java class to be generated.
|
|
| 115 |
* @return the name of a Java class
|
|
| 116 |
*/
|
|
| 117 | 98 |
public String getClassName() {
|
| 118 | 98 |
return className;
|
| 119 |
} |
|
| 120 |
|
|
| 121 |
/**
|
|
| 122 |
* Set the name of the file to be generated.
|
|
| 123 |
*
|
|
| 124 |
* @param file A file name (a path can be included)
|
|
| 125 |
*/
|
|
| 126 | 78 |
public void setFile(String file) { |
| 127 | 78 |
this.file = file;
|
| 128 |
} |
|
| 129 |
|
|
| 130 |
/**
|
|
| 131 |
* Retrieve the name of the file to be generated.
|
|
| 132 |
*
|
|
| 133 |
* @return A file name (a path can be included)
|
|
| 134 |
*/
|
|
| 135 | 130 |
public String getFile() {
|
| 136 | 130 |
return file;
|
| 137 |
} |
|
| 138 |
|
|
| 139 |
/**
|
|
| 140 |
* Set the name of the root of the XML-message.
|
|
| 141 |
*
|
|
| 142 |
* @param root The root name
|
|
| 143 |
*/
|
|
| 144 | 20 |
public void setRoot(String root) { |
| 145 | 20 |
this.root = root;
|
| 146 |
} |
|
| 147 |
|
|
| 148 |
/**
|
|
| 149 |
* Retrieve the name of the root of the XML-message.
|
|
| 150 |
*
|
|
| 151 |
* @return The root name
|
|
| 152 |
*/
|
|
| 153 | 68 |
public String getRoot() {
|
| 154 | 68 |
return root;
|
| 155 |
} |
|
| 156 |
|
|
| 157 |
/**
|
|
| 158 |
* Set the 'Generate Only XML' flag.
|
|
| 159 |
*
|
|
| 160 |
* @param onlyxml Flag used to indicates that no Java code needs to be generated.
|
|
| 161 |
*/
|
|
| 162 | 0 |
public void setOnlyxml(String onlyxml) { |
| 163 | 0 |
if (onlyxml == null) { |
| 164 | 0 |
this.onlyxml = false; |
| 165 |
} else {
|
|
| 166 | 0 |
this.onlyxml = "TRUE".equals(onlyxml.toUpperCase()); |
| 167 |
} |
|
| 168 |
} |
|
| 169 |
|
|
| 170 |
/**
|
|
| 171 |
* Check if only xml should be generated, and no java code.
|
|
| 172 |
*
|
|
| 173 |
* @return true: generated only XML, false: generated both Java and XML.
|
|
| 174 |
*/
|
|
| 175 | 12 |
public boolean onlyxml() { |
| 176 | 12 |
return onlyxml;
|
| 177 |
} |
|
| 178 |
|
|
| 179 |
/**
|
|
| 180 |
* Render the content of the TestSetGenerator to this output type.
|
|
| 181 |
* @param testSetGenerator
|
|
| 182 |
*/
|
|
| 183 | 62 |
public void render(TestSetGenerator testSetGenerator) { |
| 184 | 62 |
renderer.render(testSetGenerator, this);
|
| 185 |
} |
|
| 186 |
|
|
| 187 |
} |
|
| 188 |
|
|
||||||||||