Fixed line endings
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/7373de82 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/7373de82 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/7373de82 Branch: refs/heads/master Commit: 7373de82c552f17070801cfeb362acba48b828d9 Parents: 18ac0e2 Author: Kristian Rosenvold <krosenv...@apache.org> Authored: Tue Jan 29 16:15:20 2013 +0100 Committer: Kristian Rosenvold <krosenv...@apache.org> Committed: Tue Jan 29 16:15:20 2013 +0100 ---------------------------------------------------------------------- .../lazytestprovider/TestProvidingInputStream.java | 248 +++++++------- .../maven/plugin/surefire/SurefirePluginTest.java | 226 +++++++------- 2 files changed, 237 insertions(+), 237 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7373de82/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java ---------------------------------------------------------------------- diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java index df14d35..7304435 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java @@ -1,125 +1,125 @@ -package org.apache.maven.plugin.surefire.booterclient.lazytestprovider; - -/* - * 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 java.io.IOException; -import java.io.InputStream; -import java.util.Queue; -import java.util.concurrent.Semaphore; - -/** - * An {@link InputStream} that, when read, provides test class names out of a queue. - * <p/> - * The Stream provides only one test at a time, but only after {@link #provideNewTest()} has been invoked. - * <p/> - * After providing each test class name, followed by a newline character, a flush is performed on the - * {@link FlushReceiver} provided by the {@link FlushReceiverProvider} that can be set using - * {@link #setFlushReceiverProvider(FlushReceiverProvider)}. - * - * @author Andreas Gudian - */ -public class TestProvidingInputStream - extends InputStream -{ - private final Queue<String> testItemQueue; - - private byte[] currentBuffer; - - private int currentPos; - - private Semaphore semaphore = new Semaphore( 0 ); - - private FlushReceiverProvider flushReceiverProvider; - - private boolean closed = false; - - /** - * C'tor - * - * @param testItemQueue source of the tests to be read from this stream - */ - public TestProvidingInputStream( Queue<String> testItemQueue ) - { - this.testItemQueue = testItemQueue; - } - - /** - * @param flushReceiverProvider the provider for a flush receiver. - */ - public void setFlushReceiverProvider( FlushReceiverProvider flushReceiverProvider ) - { - this.flushReceiverProvider = flushReceiverProvider; - } - - @Override - public synchronized int read() - throws IOException - { - if ( null == currentBuffer ) - { - if ( null != flushReceiverProvider && null != flushReceiverProvider.getFlushReceiver() ) - { - flushReceiverProvider.getFlushReceiver().flush(); - } - - semaphore.acquireUninterruptibly(); - - if ( closed ) - { - return -1; - } - - String currentElement = testItemQueue.poll(); - if ( null != currentElement ) - { - currentBuffer = currentElement.getBytes(); - currentPos = 0; - } - else - { - return -1; - } - } - - if ( currentPos < currentBuffer.length ) - { - return ( currentBuffer[currentPos++] & 0xff ); - } - else - { - currentBuffer = null; - return ( '\n' & 0xff ); - } - } - - /** - * Signal that a new test is to be provided. - */ - public void provideNewTest() - { - semaphore.release(); - } - - public void close() - { - closed = true; - semaphore.release(); - } +package org.apache.maven.plugin.surefire.booterclient.lazytestprovider; + +/* + * 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 java.io.IOException; +import java.io.InputStream; +import java.util.Queue; +import java.util.concurrent.Semaphore; + +/** + * An {@link InputStream} that, when read, provides test class names out of a queue. + * <p/> + * The Stream provides only one test at a time, but only after {@link #provideNewTest()} has been invoked. + * <p/> + * After providing each test class name, followed by a newline character, a flush is performed on the + * {@link FlushReceiver} provided by the {@link FlushReceiverProvider} that can be set using + * {@link #setFlushReceiverProvider(FlushReceiverProvider)}. + * + * @author Andreas Gudian + */ +public class TestProvidingInputStream + extends InputStream +{ + private final Queue<String> testItemQueue; + + private byte[] currentBuffer; + + private int currentPos; + + private Semaphore semaphore = new Semaphore( 0 ); + + private FlushReceiverProvider flushReceiverProvider; + + private boolean closed = false; + + /** + * C'tor + * + * @param testItemQueue source of the tests to be read from this stream + */ + public TestProvidingInputStream( Queue<String> testItemQueue ) + { + this.testItemQueue = testItemQueue; + } + + /** + * @param flushReceiverProvider the provider for a flush receiver. + */ + public void setFlushReceiverProvider( FlushReceiverProvider flushReceiverProvider ) + { + this.flushReceiverProvider = flushReceiverProvider; + } + + @Override + public synchronized int read() + throws IOException + { + if ( null == currentBuffer ) + { + if ( null != flushReceiverProvider && null != flushReceiverProvider.getFlushReceiver() ) + { + flushReceiverProvider.getFlushReceiver().flush(); + } + + semaphore.acquireUninterruptibly(); + + if ( closed ) + { + return -1; + } + + String currentElement = testItemQueue.poll(); + if ( null != currentElement ) + { + currentBuffer = currentElement.getBytes(); + currentPos = 0; + } + else + { + return -1; + } + } + + if ( currentPos < currentBuffer.length ) + { + return ( currentBuffer[currentPos++] & 0xff ); + } + else + { + currentBuffer = null; + return ( '\n' & 0xff ); + } + } + + /** + * Signal that a new test is to be provided. + */ + public void provideNewTest() + { + semaphore.release(); + } + + public void close() + { + closed = true; + semaphore.release(); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/7373de82/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java ---------------------------------------------------------------------- diff --git a/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java b/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java index 8d97ffc..6fbe4bd 100644 --- a/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java +++ b/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java @@ -1,113 +1,113 @@ -package org.apache.maven.plugin.surefire; -/* - * 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 java.lang.reflect.Field; -import org.apache.maven.plugin.surefire.booterclient.ForkConfiguration; -import org.apache.maven.toolchain.Toolchain; - -import junit.framework.TestCase; - -public class SurefirePluginTest - extends TestCase -{ - - public void testForkMode() - throws NoSuchFieldException, IllegalAccessException - { - SurefirePlugin surefirePlugin = new SurefirePlugin(); - setFieldValue( surefirePlugin, "toolchain", new MyToolChain() ); - setFieldValue( surefirePlugin, "forkMode", "never" ); - assertEquals( ForkConfiguration.FORK_ONCE, surefirePlugin.getEffectiveForkMode() ); - } - - public void testForkCountComputation() - { - SurefirePlugin surefirePlugin = new SurefirePlugin(); - assertConversionFails( surefirePlugin, "nothing" ); - - assertConversionFails( surefirePlugin, "5,0" ); - assertConversionFails( surefirePlugin, "5.0" ); - assertConversionFails( surefirePlugin, "5,0C" ); - assertConversionFails( surefirePlugin, "5.0CC" ); - - assertForkCount( surefirePlugin, 5, "5" ); - - int availableProcessors = Runtime.getRuntime().availableProcessors(); - assertForkCount( surefirePlugin, 3*availableProcessors, "3C" ); - assertForkCount( surefirePlugin, (int) ( 2.5*availableProcessors ), "2.5C" ); - assertForkCount( surefirePlugin, availableProcessors, "1.0001 C" ); - } - - private void assertForkCount( SurefirePlugin surefirePlugin, int expected, String value ) - { - assertEquals( expected, surefirePlugin.convertWithCoreCount( value )); - } - - private void assertConversionFails( SurefirePlugin surefirePlugin, String value ) - { - try { - surefirePlugin.convertWithCoreCount( value ); - } catch (NumberFormatException nfe) - { - return; - } - fail( "Expected NumberFormatException when converting " + value ); - } - - private void setFieldValue( SurefirePlugin plugin, String fieldName, Object value ) - throws NoSuchFieldException, IllegalAccessException - { - Field field = findField( plugin.getClass(), fieldName ); - field.setAccessible( true ); - field.set( plugin, value ); - - } - - private Field findField( Class clazz, String fieldName ) - { - while ( clazz != null ) - { - try - { - return clazz.getDeclaredField( fieldName ); - } - catch ( NoSuchFieldException e ) - { - clazz = clazz.getSuperclass(); - } - } - throw new IllegalArgumentException( "Field not found" ); - } - - private class MyToolChain - implements Toolchain - { - public String getType() - { - return null; - } - - public String findTool( String s ) - { - return null; - } - } -} +package org.apache.maven.plugin.surefire; +/* + * 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 java.lang.reflect.Field; +import org.apache.maven.plugin.surefire.booterclient.ForkConfiguration; +import org.apache.maven.toolchain.Toolchain; + +import junit.framework.TestCase; + +public class SurefirePluginTest + extends TestCase +{ + + public void testForkMode() + throws NoSuchFieldException, IllegalAccessException + { + SurefirePlugin surefirePlugin = new SurefirePlugin(); + setFieldValue( surefirePlugin, "toolchain", new MyToolChain() ); + setFieldValue( surefirePlugin, "forkMode", "never" ); + assertEquals( ForkConfiguration.FORK_ONCE, surefirePlugin.getEffectiveForkMode() ); + } + + public void testForkCountComputation() + { + SurefirePlugin surefirePlugin = new SurefirePlugin(); + assertConversionFails( surefirePlugin, "nothing" ); + + assertConversionFails( surefirePlugin, "5,0" ); + assertConversionFails( surefirePlugin, "5.0" ); + assertConversionFails( surefirePlugin, "5,0C" ); + assertConversionFails( surefirePlugin, "5.0CC" ); + + assertForkCount( surefirePlugin, 5, "5" ); + + int availableProcessors = Runtime.getRuntime().availableProcessors(); + assertForkCount( surefirePlugin, 3*availableProcessors, "3C" ); + assertForkCount( surefirePlugin, (int) ( 2.5*availableProcessors ), "2.5C" ); + assertForkCount( surefirePlugin, availableProcessors, "1.0001 C" ); + } + + private void assertForkCount( SurefirePlugin surefirePlugin, int expected, String value ) + { + assertEquals( expected, surefirePlugin.convertWithCoreCount( value )); + } + + private void assertConversionFails( SurefirePlugin surefirePlugin, String value ) + { + try { + surefirePlugin.convertWithCoreCount( value ); + } catch (NumberFormatException nfe) + { + return; + } + fail( "Expected NumberFormatException when converting " + value ); + } + + private void setFieldValue( SurefirePlugin plugin, String fieldName, Object value ) + throws NoSuchFieldException, IllegalAccessException + { + Field field = findField( plugin.getClass(), fieldName ); + field.setAccessible( true ); + field.set( plugin, value ); + + } + + private Field findField( Class clazz, String fieldName ) + { + while ( clazz != null ) + { + try + { + return clazz.getDeclaredField( fieldName ); + } + catch ( NoSuchFieldException e ) + { + clazz = clazz.getSuperclass(); + } + } + throw new IllegalArgumentException( "Field not found" ); + } + + private class MyToolChain + implements Toolchain + { + public String getType() + { + return null; + } + + public String findTool( String s ) + { + return null; + } + } +}