Browse Source

checkstyle

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@587872 13f79535-47bb-0310-9956-ffa450edef68
master
Jan Materne 18 years ago
parent
commit
5a0b8d7b35
2 changed files with 32 additions and 24 deletions
  1. +23
    -14
      src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java
  2. +9
    -10
      src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java

+ 23
- 14
src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java View File

@@ -64,7 +64,7 @@ import org.apache.tools.ant.util.FileUtils;
* the failing test cases in a static list. Because we dont have a finalizer * the failing test cases in a static list. Because we dont have a finalizer
* method in the formatters "lifecycle", we register this formatter as * method in the formatters "lifecycle", we register this formatter as
* BuildListener and generate the new java source on taskFinished event. * BuildListener and generate the new java source on taskFinished event.
*
*
* @since Ant 1.8.0 * @since Ant 1.8.0
*/ */
public class FailureRecorder extends DataType implements JUnitResultFormatter, BuildListener { public class FailureRecorder extends DataType implements JUnitResultFormatter, BuildListener {
@@ -91,7 +91,7 @@ public class FailureRecorder extends DataType implements JUnitResultFormatter, B
/** A writer for writing the generated source to. */ /** A writer for writing the generated source to. */
private PrintWriter writer; private PrintWriter writer;
/** /**
* Location and name of the generated JUnit class. * Location and name of the generated JUnit class.
* Lazy instantiated via getLocationName(). * Lazy instantiated via getLocationName().
@@ -121,7 +121,8 @@ public class FailureRecorder extends DataType implements JUnitResultFormatter, B
} else { } else {
locationName = DEFAULT_CLASS_LOCATION; locationName = DEFAULT_CLASS_LOCATION;
verbose("System property '" + MAGIC_PROPERTY_CLASS_LOCATION + "' not set, so use " verbose("System property '" + MAGIC_PROPERTY_CLASS_LOCATION + "' not set, so use "
+ "value as location for collector class: '" + DEFAULT_CLASS_LOCATION + "'");
+ "value as location for collector class: '"
+ DEFAULT_CLASS_LOCATION + "'");
} }
File locationFile = new File(locationName); File locationFile = new File(locationName);
@@ -132,14 +133,14 @@ public class FailureRecorder extends DataType implements JUnitResultFormatter, B
+ " use absolute path instead (" + locationName + ")"); + " use absolute path instead (" + locationName + ")");
} }
} }
return locationName; return locationName;
} }
/** /**
* This method is called by the Ant runtime by reflection. We use the project reference for * This method is called by the Ant runtime by reflection. We use the project reference for
* registration of this class as BuildListener. * registration of this class as BuildListener.
*
*
* @param project * @param project
* project reference * project reference
*/ */
@@ -149,7 +150,7 @@ public class FailureRecorder extends DataType implements JUnitResultFormatter, B
// check if already registered // check if already registered
boolean alreadyRegistered = false; boolean alreadyRegistered = false;
Vector allListeners = project.getBuildListeners(); Vector allListeners = project.getBuildListeners();
for(int i=0; i<allListeners.size(); i++) {
for (int i = 0; i < allListeners.size(); i++) {
Object listener = allListeners.get(i); Object listener = allListeners.get(i);
if (listener instanceof FailureRecorder) { if (listener instanceof FailureRecorder) {
alreadyRegistered = true; alreadyRegistered = true;
@@ -162,9 +163,9 @@ public class FailureRecorder extends DataType implements JUnitResultFormatter, B
project.addBuildListener(this); project.addBuildListener(this);
} }
} }
// ===== JUnitResultFormatter ===== // ===== JUnitResultFormatter =====
/** /**
* Not used * Not used
* {@inheritDoc} * {@inheritDoc}
@@ -242,7 +243,7 @@ public class FailureRecorder extends DataType implements JUnitResultFormatter, B
try { try {
File sourceFile = new File((getLocationName() + ".java")); File sourceFile = new File((getLocationName() + ".java"));
verbose("Write collector class to '" + sourceFile.getAbsolutePath() + "'"); verbose("Write collector class to '" + sourceFile.getAbsolutePath() + "'");
sourceFile.delete(); sourceFile.delete();
writer = new PrintWriter(new FileOutputStream(sourceFile)); writer = new PrintWriter(new FileOutputStream(sourceFile));
@@ -295,10 +296,17 @@ public class FailureRecorder extends DataType implements JUnitResultFormatter, B
} }
// ===== Helper classes and methods ===== // ===== Helper classes and methods =====
/**
* Logging facade in INFO-mode.
*/
public void log(String message) { public void log(String message) {
getProject().log(LOG_PREFIX + " " + message, Project.MSG_INFO); getProject().log(LOG_PREFIX + " " + message, Project.MSG_INFO);
} }
/**
* Logging facade in VERBOSE-mode.
*/
public void verbose(String message) { public void verbose(String message) {
getProject().log(LOG_PREFIX + " " + message, Project.MSG_VERBOSE); getProject().log(LOG_PREFIX + " " + message, Project.MSG_VERBOSE);
} }
@@ -351,7 +359,7 @@ public class FailureRecorder extends DataType implements JUnitResultFormatter, B
} }
} }
} }
// ===== BuildListener ===== // ===== BuildListener =====
/** /**
@@ -390,8 +398,9 @@ public class FailureRecorder extends DataType implements JUnitResultFormatter, B
} }
/** /**
* The task outside of this JUnitResultFormatter is the <junit> task. So all tests passed
* and we could create the new java class.
* The task outside of this JUnitResultFormatter is the <junit> task. So all tests passed
* and we could create the new java class.
* @param event not used
* @see org.apache.tools.ant.BuildListener#taskFinished(org.apache.tools.ant.BuildEvent) * @see org.apache.tools.ant.BuildListener#taskFinished(org.apache.tools.ant.BuildEvent)
*/ */
public void taskFinished(BuildEvent event) { public void taskFinished(BuildEvent event) {
@@ -406,5 +415,5 @@ public class FailureRecorder extends DataType implements JUnitResultFormatter, B
*/ */
public void taskStarted(BuildEvent event) { public void taskStarted(BuildEvent event) {
} }
} }

+ 9
- 10
src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java View File

@@ -98,7 +98,6 @@ public class FormatterElement {
* @param type the enumerated value to use. * @param type the enumerated value to use.
*/ */
public void setType(TypeAttribute type) { public void setType(TypeAttribute type) {
//TODO: Besseren Zugriffsalgorithums: TypeAttribut.getClassname()
if ("xml".equals(type.getValue())) { if ("xml".equals(type.getValue())) {
setClassname(XML_FORMATTER_CLASS_NAME); setClassname(XML_FORMATTER_CLASS_NAME);
} else { } else {
@@ -240,8 +239,8 @@ public class FormatterElement {
public void setProject(Project project) { public void setProject(Project project) {
this.project = project; this.project = project;
} }
/** /**
* @since Ant 1.6 * @since Ant 1.6
*/ */
@@ -270,7 +269,7 @@ public class FormatterElement {
"Using loader " + loader + " on class " + classname "Using loader " + loader + " on class " + classname
+ ": " + e, e); + ": " + e, e);
} }
Object o = null; Object o = null;
try { try {
o = f.newInstance(); o = f.newInstance();
@@ -279,7 +278,7 @@ public class FormatterElement {
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new BuildException(e); throw new BuildException(e);
} }
if (!(o instanceof JUnitTaskMirror.JUnitResultFormatterMirror)) { if (!(o instanceof JUnitTaskMirror.JUnitResultFormatterMirror)) {
throw new BuildException(classname + " is not a JUnitResultFormatter"); throw new BuildException(classname + " is not a JUnitResultFormatter");
} }
@@ -293,7 +292,7 @@ public class FormatterElement {
} }
} }
r.setOutput(out); r.setOutput(out);


boolean needToSetProjectReference = true; boolean needToSetProjectReference = true;
try { try {
@@ -306,17 +305,17 @@ public class FormatterElement {
} catch (Exception e) { } catch (Exception e) {
// no field present, so no previous reference exists // no field present, so no previous reference exists
} }
if (needToSetProjectReference) { if (needToSetProjectReference) {
Method setter; Method setter;
try { try {
setter = r.getClass().getMethod("setProject", new Class[] { Project.class });
setter.invoke(r, new Object[] { project });
setter = r.getClass().getMethod("setProject", new Class[] {Project.class});
setter.invoke(r, new Object[] {project} );
} catch (Exception e) { } catch (Exception e) {
// no setProject to invoke; just ignore // no setProject to invoke; just ignore
} }
} }
return r; return r;
} }




Loading…
Cancel
Save