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
* method in the formatters "lifecycle", we register this formatter as
* BuildListener and generate the new java source on taskFinished event.
*
*
* @since Ant 1.8.0
*/
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. */
private PrintWriter writer;
/**
* Location and name of the generated JUnit class.
* Lazy instantiated via getLocationName().
@@ -121,7 +121,8 @@ public class FailureRecorder extends DataType implements JUnitResultFormatter, B
} else {
locationName = DEFAULT_CLASS_LOCATION;
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);
@@ -132,14 +133,14 @@ public class FailureRecorder extends DataType implements JUnitResultFormatter, B
+ " use absolute path instead (" + locationName + ")");
}
}
return locationName;
}
/**
* This method is called by the Ant runtime by reflection. We use the project reference for
* registration of this class as BuildListener.
*
*
* @param project
* project reference
*/
@@ -149,7 +150,7 @@ public class FailureRecorder extends DataType implements JUnitResultFormatter, B
// check if already registered
boolean alreadyRegistered = false;
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);
if (listener instanceof FailureRecorder) {
alreadyRegistered = true;
@@ -162,9 +163,9 @@ public class FailureRecorder extends DataType implements JUnitResultFormatter, B
project.addBuildListener(this);
}
}
// ===== JUnitResultFormatter =====
/**
* Not used
* {@inheritDoc}
@@ -242,7 +243,7 @@ public class FailureRecorder extends DataType implements JUnitResultFormatter, B
try {
File sourceFile = new File((getLocationName() + ".java"));
verbose("Write collector class to '" + sourceFile.getAbsolutePath() + "'");
sourceFile.delete();
writer = new PrintWriter(new FileOutputStream(sourceFile));
@@ -295,10 +296,17 @@ public class FailureRecorder extends DataType implements JUnitResultFormatter, B
}
// ===== Helper classes and methods =====
/**
* Logging facade in INFO-mode.
*/
public void log(String message) {
getProject().log(LOG_PREFIX + " " + message, Project.MSG_INFO);
}
/**
* Logging facade in VERBOSE-mode.
*/
public void verbose(String message) {
getProject().log(LOG_PREFIX + " " + message, Project.MSG_VERBOSE);
}
@@ -351,7 +359,7 @@ public class FailureRecorder extends DataType implements JUnitResultFormatter, B
}
}
}
// ===== 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)
*/
public void taskFinished(BuildEvent event) {
@@ -406,5 +415,5 @@ public class FailureRecorder extends DataType implements JUnitResultFormatter, B
*/
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.
*/
public void setType(TypeAttribute type) {
//TODO: Besseren Zugriffsalgorithums: TypeAttribut.getClassname()
if ("xml".equals(type.getValue())) {
setClassname(XML_FORMATTER_CLASS_NAME);
} else {
@@ -240,8 +239,8 @@ public class FormatterElement {
public void setProject(Project project) {
this.project = project;
}
/**
* @since Ant 1.6
*/
@@ -270,7 +269,7 @@ public class FormatterElement {
"Using loader " + loader + " on class " + classname
+ ": " + e, e);
}
Object o = null;
try {
o = f.newInstance();
@@ -279,7 +278,7 @@ public class FormatterElement {
} catch (IllegalAccessException e) {
throw new BuildException(e);
}
if (!(o instanceof JUnitTaskMirror.JUnitResultFormatterMirror)) {
throw new BuildException(classname + " is not a JUnitResultFormatter");
}
@@ -293,7 +292,7 @@ public class FormatterElement {
}
}
r.setOutput(out);

boolean needToSetProjectReference = true;
try {
@@ -306,17 +305,17 @@ public class FormatterElement {
} catch (Exception e) {
// no field present, so no previous reference exists
}
if (needToSetProjectReference) {
Method setter;
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) {
// no setProject to invoke; just ignore
}
}
return r;
}



Loading…
Cancel
Save