You are viewing a plain text version of this content. The canonical link for it is here.
Posted to surefire-commits@maven.apache.org by kr...@apache.org on 2010/12/02 22:30:01 UTC
svn commit: r1041591 - in
/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient:
ForkStarter.java output/FileOutputConsumerProxy.java
output/SynchronizedOutputConsumer.java
Author: krosenvold
Date: Thu Dec 2 21:30:01 2010
New Revision: 1041591
URL: http://svn.apache.org/viewvc?rev=1041591&view=rev
Log:
o Fixed another threading issue inside the streamconsumers from the fork output
Go for green, grid !
Added:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/SynchronizedOutputConsumer.java (with props)
Modified:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/FileOutputConsumerProxy.java
Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java?rev=1041591&r1=1041590&r2=1041591&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java Thu Dec 2 21:30:01 2010
@@ -24,6 +24,7 @@ import org.apache.maven.plugin.surefire.
import org.apache.maven.plugin.surefire.booterclient.output.StandardOutputConsumer;
import org.apache.maven.plugin.surefire.booterclient.output.SupressFooterOutputConsumerProxy;
import org.apache.maven.plugin.surefire.booterclient.output.SupressHeaderOutputConsumerProxy;
+import org.apache.maven.plugin.surefire.booterclient.output.SynchronizedOutputConsumer;
import org.apache.maven.surefire.booter.BooterConfiguration;
import org.apache.maven.surefire.booter.Classpath;
import org.apache.maven.surefire.booter.ProviderConfiguration;
@@ -195,20 +196,16 @@ public class ForkStarter
cli.createArg().setFile( systemProperties );
}
- ForkingStreamConsumer out =
- getForkingStreamConsumer( showHeading, showFooter, starterConfiguration.isRedirectTestOutputToFile() );
+ final boolean willBeSharingConsumer = starterConfiguration.isRedirectTestOutputToFile();
- StreamConsumer err;
+ ForkingStreamConsumer out =
+ getForkingStreamConsumer( showHeading, showFooter, starterConfiguration.isRedirectTestOutputToFile(),
+ willBeSharingConsumer );
- if ( starterConfiguration.isRedirectTestOutputToFile() )
- {
- err = out;
- }
- else
- {
- err =
- getForkingStreamConsumer( showHeading, showFooter, starterConfiguration.isRedirectTestOutputToFile() );
- }
+ StreamConsumer err = willBeSharingConsumer
+ ? out
+ : getForkingStreamConsumer( showHeading, showFooter, starterConfiguration.isRedirectTestOutputToFile(),
+ willBeSharingConsumer );
if ( forkConfiguration.isDebug() )
{
@@ -266,7 +263,7 @@ public class ForkStarter
}
private ForkingStreamConsumer getForkingStreamConsumer( boolean showHeading, boolean showFooter,
- boolean redirectTestOutputToFile )
+ boolean redirectTestOutputToFile, boolean mustBeThreadSafe )
{
OutputConsumer outputConsumer = new StandardOutputConsumer();
@@ -279,11 +276,17 @@ public class ForkStarter
{
outputConsumer = new SupressHeaderOutputConsumerProxy( outputConsumer );
}
+
if ( !showFooter )
{
outputConsumer = new SupressFooterOutputConsumerProxy( outputConsumer );
}
+ if ( mustBeThreadSafe )
+ {
+ outputConsumer = new SynchronizedOutputConsumer( outputConsumer );
+ }
+
return new ForkingStreamConsumer( outputConsumer );
}
Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/FileOutputConsumerProxy.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/FileOutputConsumerProxy.java?rev=1041591&r1=1041590&r2=1041591&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/FileOutputConsumerProxy.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/FileOutputConsumerProxy.java Thu Dec 2 21:30:01 2010
@@ -65,6 +65,13 @@ public class FileOutputConsumerProxy
{
throw new IllegalStateException( "testSetStarting called twice" );
}
+
+ if ( !reportsDirectory.exists() )
+ {
+ //noinspection ResultOfMethodCallIgnored
+ reportsDirectory.mkdirs();
+ }
+
File file = new File( reportsDirectory, reportEntry.getName() + "-output.txt" );
try
{
Added: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/SynchronizedOutputConsumer.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/SynchronizedOutputConsumer.java?rev=1041591&view=auto
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/SynchronizedOutputConsumer.java (added)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/SynchronizedOutputConsumer.java Thu Dec 2 21:30:01 2010
@@ -0,0 +1,59 @@
+package org.apache.maven.plugin.surefire.booterclient.output;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.surefire.report.ReportEntry;
+
+/**
+ * Imposes synchronization on a non-thredsafe OutputConsumer
+ * @author Kristian Rosenvold
+ */
+public class SynchronizedOutputConsumer implements OutputConsumer {
+
+ final OutputConsumer target;
+
+ public SynchronizedOutputConsumer(OutputConsumer target) {
+ this.target = target;
+ }
+
+ public synchronized void consumeHeaderLine(String line) {
+ target.consumeHeaderLine(line);
+ }
+
+ public synchronized void consumeMessageLine(String line) {
+ target.consumeMessageLine(line);
+ }
+
+ public synchronized void consumeFooterLine(String line) {
+ target.consumeFooterLine(line);
+ }
+
+ public synchronized void consumeOutputLine(String line) {
+ target.consumeOutputLine(line);
+ }
+
+ public synchronized void testSetStarting(ReportEntry reportEntry) {
+ target.testSetStarting(reportEntry);
+ }
+
+ public synchronized void testSetCompleted() {
+ target.testSetCompleted();
+ }
+}
Propchange: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/SynchronizedOutputConsumer.java
------------------------------------------------------------------------------
svn:eol-style = native