You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ag...@apache.org on 2013/04/27 14:28:15 UTC
git commit: [SUREFIRE-991] fixed yet another NPE with null testClass
in Description,
fixed file reporting for the case that illegal characters were part of the
file name
Updated Branches:
refs/heads/master 2feedb6b1 -> 3d903eb72
[SUREFIRE-991] fixed yet another NPE with null testClass in Description, fixed file reporting for the case that illegal characters were part of the file name
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/3d903eb7
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/3d903eb7
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/3d903eb7
Branch: refs/heads/master
Commit: 3d903eb72c04231c2ad75cfd8dd385b5e478e19f
Parents: 2feedb6
Author: Andreas Gudian <ag...@apache.org>
Authored: Sat Apr 27 14:27:53 2013 +0200
Committer: Andreas Gudian <ag...@apache.org>
Committed: Sat Apr 27 14:27:53 2013 +0200
----------------------------------------------------------------------
.../maven/plugin/surefire/report/FileReporter.java | 14 +++--
.../plugin/surefire/report/FileReporterUtils.java | 50 +++++++++++++++
.../surefire/report/StatelessXmlReporter.java | 10 ++-
.../junitcore/NonConcurrentRunListener.java | 40 +++++++++---
4 files changed, 98 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/3d903eb7/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporter.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporter.java
index 3bab9f5..f2e8e28 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporter.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporter.java
@@ -27,9 +27,11 @@ import java.util.List;
import org.apache.maven.surefire.report.ReportEntry;
import org.apache.maven.surefire.report.ReporterException;
+import static org.apache.maven.plugin.surefire.report.FileReporterUtils.stripIllegalFilenameChars;
+
/**
* Base class for file reporters.
- *
+ *
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @author Kristian Rosenvold
*/
@@ -55,12 +57,12 @@ public class FileReporter
File reportDir = reportFile.getParentFile();
- //noinspection ResultOfMethodCallIgnored
+ // noinspection ResultOfMethodCallIgnored
reportDir.mkdirs();
if ( deleteOnStarting && reportFile.exists() )
{
- //noinspection ResultOfMethodCallIgnored
+ // noinspection ResultOfMethodCallIgnored
reportFile.delete();
}
@@ -89,11 +91,13 @@ public class FileReporter
if ( reportNameSuffix != null && reportNameSuffix.length() > 0 )
{
- reportFile = new File( reportsDirectory, reportEntryName + "-" + reportNameSuffix + fileExtension );
+ reportFile =
+ new File( reportsDirectory, stripIllegalFilenameChars( reportEntryName + "-" + reportNameSuffix
+ + fileExtension ) );
}
else
{
- reportFile = new File( reportsDirectory, reportEntryName + fileExtension );
+ reportFile = new File( reportsDirectory, stripIllegalFilenameChars( reportEntryName + fileExtension ) );
}
return reportFile;
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/3d903eb7/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterUtils.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterUtils.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterUtils.java
new file mode 100644
index 0000000..5009da9
--- /dev/null
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterUtils.java
@@ -0,0 +1,50 @@
+package org.apache.maven.plugin.surefire.report;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Utils class for file-based reporters
+ *
+ * @author Andreas Gudian
+ */
+public class FileReporterUtils
+{
+ public static String stripIllegalFilenameChars( String original )
+ {
+ String result = original;
+ String illegalChars = getOSSpecificIllegalChars();
+ for ( int i = 0; i < illegalChars.length(); i++ )
+ result = result.replace( illegalChars.charAt( i ), '_' );
+
+ return result;
+ }
+
+ private static String getOSSpecificIllegalChars()
+ {
+ if ( System.getProperty( "os.name" ).toLowerCase().startsWith( "win" ) )
+ {
+ return "\\/:*?\"<>|\0";
+ }
+ else
+ {
+ return "/\0";
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/3d903eb7/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java
index d72a08e..cb3314f 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java
@@ -32,6 +32,8 @@ import org.apache.maven.surefire.report.ReportEntry;
import org.apache.maven.surefire.report.ReporterException;
import org.apache.maven.surefire.report.SafeThrowable;
+import static org.apache.maven.plugin.surefire.report.FileReporterUtils.stripIllegalFilenameChars;
+
/**
* XML format reporter writing to <code>TEST-<i>reportName</i>[-<i>suffix</i>].xml</code> file like written and read
* by Ant's <a href="http://ant.apache.org/manual/Tasks/junit.html"><code><junit></code></a> and
@@ -148,16 +150,18 @@ public class StatelessXmlReporter
if ( reportNameSuffix != null && reportNameSuffix.length() > 0 )
{
- reportFile = new File( reportsDirectory, "TEST-" + report.getName() + "-" + reportNameSuffix + ".xml" );
+ reportFile =
+ new File( reportsDirectory, stripIllegalFilenameChars( "TEST-" + report.getName() + "-"
+ + reportNameSuffix + ".xml" ) );
}
else
{
- reportFile = new File( reportsDirectory, "TEST-" + report.getName() + ".xml" );
+ reportFile = new File( reportsDirectory, stripIllegalFilenameChars( "TEST-" + report.getName() + ".xml" ) );
}
return reportFile;
}
-
+
private static void startTestElement( XMLWriter ppw, WrappedReportEntry report, String reportNameSuffix )
{
ppw.startElement( "testcase" );
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/3d903eb7/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/NonConcurrentRunListener.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/NonConcurrentRunListener.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/NonConcurrentRunListener.java
index cf4d19d..dcf8615 100644
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/NonConcurrentRunListener.java
+++ b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/NonConcurrentRunListener.java
@@ -24,7 +24,6 @@ import org.apache.maven.surefire.report.ConsoleOutputReceiver;
import org.apache.maven.surefire.report.RunListener;
import org.apache.maven.surefire.report.SimpleReportEntry;
import org.apache.maven.surefire.testset.TestSetFailedException;
-
import org.junit.runner.Description;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
@@ -39,7 +38,7 @@ public class NonConcurrentRunListener
implements ConsoleOutputReceiver
{
- private java.lang.Class<?> currentTestClass;
+ private Description currentTestSetDescription;
private Description lastFinishedDescription;
@@ -57,14 +56,20 @@ public class NonConcurrentRunListener
protected SimpleReportEntry createReportEntry( Description description )
{
- return new SimpleReportEntry( description.getClassName(), description.getDisplayName()/*,
- (int) ( System.currentTimeMillis() - startTime ) */);
+ return new SimpleReportEntry( description.getClassName(), description.getDisplayName()/*
+ * , (int) (
+ * System.currentTimeMillis
+ * () - startTime )
+ */);
}
protected SimpleReportEntry createReportEntryForTestSet( Description description )
{
- return new SimpleReportEntry( description.getClassName(), description.getClassName() /*,
- (int) ( System.currentTimeMillis() - startTime ) */);
+ return new SimpleReportEntry( description.getClassName(), description.getClassName() /*
+ * , (int) (
+ * System.currentTimeMillis
+ * () - startTime )
+ */);
}
@Override
@@ -77,9 +82,9 @@ public class NonConcurrentRunListener
private void finishLastTestSetIfNeccessary( Description description )
{
- if ( !description.getTestClass().equals( currentTestClass ) )
+ if ( describesNewTestSet( description ) )
{
- currentTestClass = description.getTestClass();
+ currentTestSetDescription = description;
if ( lastFinishedDescription != null )
{
reporter.testSetCompleted( createReportEntryForTestSet( lastFinishedDescription ) );
@@ -89,6 +94,25 @@ public class NonConcurrentRunListener
}
}
+ private boolean describesNewTestSet( Description description )
+ {
+ if ( currentTestSetDescription != null )
+ {
+ if ( null != description.getTestClass() )
+ {
+ return !description.getTestClass().equals( currentTestSetDescription.getTestClass() );
+ }
+ else if ( description.isSuite() )
+ {
+ return description.getChildren().equals( currentTestSetDescription.getChildren() );
+ }
+
+ return false;
+ }
+
+ return true;
+ }
+
@Override
public void testFinished( Description description )
throws Exception