Updated Branches: refs/heads/master c8a1b8145 -> 12c37d634
o Removed msdos 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/12c37d63 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/12c37d63 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/12c37d63 Branch: refs/heads/master Commit: 12c37d6347a345838952f6c01e7fc86e70248b7f Parents: c8a1b81 Author: Kristian Rosenvold <krosenv...@apache.org> Authored: Thu Dec 20 16:28:44 2012 +0100 Committer: Kristian Rosenvold <krosenv...@apache.org> Committed: Thu Dec 20 16:28:44 2012 +0100 ---------------------------------------------------------------------- .../maven/surefire/util/DefaultScanResult.java | 282 ++++++------ .../apache/maven/surefire/util/LazyTestsToRun.java | 366 +++++++------- .../org/apache/maven/surefire/util/ScanResult.java | 78 ++-- .../apache/maven/surefire/util/ScanResultTest.java | 96 ++-- 4 files changed, 411 insertions(+), 411 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/12c37d63/surefire-api/src/main/java/org/apache/maven/surefire/util/DefaultScanResult.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/util/DefaultScanResult.java b/surefire-api/src/main/java/org/apache/maven/surefire/util/DefaultScanResult.java index b009f34..f8cb61d 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/util/DefaultScanResult.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/util/DefaultScanResult.java @@ -1,141 +1,141 @@ -package org.apache.maven.surefire.util; - -/* - * 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.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Properties; - -/** - * @author Kristian Rosenvold - */ -public class DefaultScanResult - implements ScanResult -{ - private final List files; - - private static final String scanResultNo = "tc."; - - public DefaultScanResult( List files ) - { - this.files = files; - } - - public int size() - { - return files.size(); - } - - public String getClassName( int index ) - { - return (String) files.get( index ); - } - - public void writeTo( Properties properties ) - { - int size = files.size(); - for ( int i = 0; i < size; i++ ) - { - properties.setProperty( scanResultNo + i, (String) files.get( i ) ); - } - } - - public static DefaultScanResult from( Properties properties ) - { - List result = new ArrayList(); - int i = 0; - while ( true ) - { - String item = properties.getProperty( scanResultNo + ( i++ ) ); - if ( item == null ) - { - return new DefaultScanResult( result ); - } - result.add( item ); - } - } - - public boolean isEmpty() - { - return files.isEmpty(); - } - - public List getFiles() - { - return Collections.unmodifiableList( files ); - } - - public TestsToRun applyFilter( ScannerFilter scannerFilter, ClassLoader testClassLoader ) - { - List result = new ArrayList(); - - int size = size(); - for ( int i = 0; i < size; i++ ) - { - String className = getClassName( i ); - - Class testClass = loadClass( testClassLoader, className ); - - if ( scannerFilter == null || scannerFilter.accept( testClass ) ) - { - result.add( testClass ); - } - } - - return new TestsToRun( result ); - } - - public List getClassesSkippedByValidation( ScannerFilter scannerFilter, ClassLoader testClassLoader ) - { - List result = new ArrayList(); - - int size = size(); - for ( int i = 0; i < size; i++ ) - { - String className = getClassName( i ); - - Class testClass = loadClass( testClassLoader, className ); - - if ( scannerFilter != null && !scannerFilter.accept( testClass ) ) - { - result.add( testClass ); - } - } - - return result; - } - - private static Class loadClass( ClassLoader classLoader, String className ) - { - Class testClass; - try - { - testClass = classLoader.loadClass( className ); - } - catch ( ClassNotFoundException e ) - { - throw new NestedRuntimeException( "Unable to create test class '" + className + "'", e ); - } - return testClass; - } - - -} +package org.apache.maven.surefire.util; + +/* + * 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.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Properties; + +/** + * @author Kristian Rosenvold + */ +public class DefaultScanResult + implements ScanResult +{ + private final List files; + + private static final String scanResultNo = "tc."; + + public DefaultScanResult( List files ) + { + this.files = files; + } + + public int size() + { + return files.size(); + } + + public String getClassName( int index ) + { + return (String) files.get( index ); + } + + public void writeTo( Properties properties ) + { + int size = files.size(); + for ( int i = 0; i < size; i++ ) + { + properties.setProperty( scanResultNo + i, (String) files.get( i ) ); + } + } + + public static DefaultScanResult from( Properties properties ) + { + List result = new ArrayList(); + int i = 0; + while ( true ) + { + String item = properties.getProperty( scanResultNo + ( i++ ) ); + if ( item == null ) + { + return new DefaultScanResult( result ); + } + result.add( item ); + } + } + + public boolean isEmpty() + { + return files.isEmpty(); + } + + public List getFiles() + { + return Collections.unmodifiableList( files ); + } + + public TestsToRun applyFilter( ScannerFilter scannerFilter, ClassLoader testClassLoader ) + { + List result = new ArrayList(); + + int size = size(); + for ( int i = 0; i < size; i++ ) + { + String className = getClassName( i ); + + Class testClass = loadClass( testClassLoader, className ); + + if ( scannerFilter == null || scannerFilter.accept( testClass ) ) + { + result.add( testClass ); + } + } + + return new TestsToRun( result ); + } + + public List getClassesSkippedByValidation( ScannerFilter scannerFilter, ClassLoader testClassLoader ) + { + List result = new ArrayList(); + + int size = size(); + for ( int i = 0; i < size; i++ ) + { + String className = getClassName( i ); + + Class testClass = loadClass( testClassLoader, className ); + + if ( scannerFilter != null && !scannerFilter.accept( testClass ) ) + { + result.add( testClass ); + } + } + + return result; + } + + private static Class loadClass( ClassLoader classLoader, String className ) + { + Class testClass; + try + { + testClass = classLoader.loadClass( className ); + } + catch ( ClassNotFoundException e ) + { + throw new NestedRuntimeException( "Unable to create test class '" + className + "'", e ); + } + return testClass; + } + + +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/12c37d63/surefire-api/src/main/java/org/apache/maven/surefire/util/LazyTestsToRun.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/util/LazyTestsToRun.java b/surefire-api/src/main/java/org/apache/maven/surefire/util/LazyTestsToRun.java index 996797c..5974b6a 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/util/LazyTestsToRun.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/util/LazyTestsToRun.java @@ -1,183 +1,183 @@ -package org.apache.maven.surefire.util; - -/* - * 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.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import org.apache.maven.surefire.booter.ForkingRunListener; - -/** - * A variant of TestsToRun that is provided with test class names - * from an {@link InputStream} (e.g. {@code System.in}). The method - * {@link #iterator()} returns an Iterator that blocks on calls to - * {@link Iterator#hasNext()} until new classes are available, or no more - * classes will be available. - * - * @author Andreas Gudian - */ -public class LazyTestsToRun - extends TestsToRun -{ - private List workQueue = new ArrayList(); - - private BufferedReader inputReader; - - private boolean streamClosed = false; - - private ClassLoader testClassLoader; - - private PrintStream originalOutStream; - - /** - * C'tor - * - * @param testSource source to read the tests from - * @param testClassLoader class loader to load the test classes - * @param originalOutStream the output stream to use when requesting new new tests - */ - public LazyTestsToRun( InputStream testSource, ClassLoader testClassLoader, PrintStream originalOutStream ) - { - super( Collections.emptyList() ); - - this.testClassLoader = testClassLoader; - this.originalOutStream = originalOutStream; - - inputReader = new BufferedReader( new InputStreamReader( testSource ) ); - } - - protected void addWorkItem( String className ) - { - synchronized ( workQueue ) - { - workQueue.add( ReflectionUtils.loadClass( testClassLoader, className ) ); - } - } - - protected void requestNextTest() - { - StringBuffer sb = new StringBuffer(); - sb.append( (char) ForkingRunListener.BOOTERCODE_NEXT_TEST ).append( ",0,want more!\n" ); - originalOutStream.print( sb.toString() ); - } - - private class BlockingIterator - implements Iterator - { - private int lastPos = -1; - - public boolean hasNext() - { - int nextPos = lastPos + 1; - synchronized ( workQueue ) - { - if ( workQueue.size() > nextPos ) - { - return true; - } - else - { - if ( needsToWaitForInput( nextPos ) ) - { - requestNextTest(); - - String nextClassName; - try - { - nextClassName = inputReader.readLine(); - } - catch ( IOException e ) - { - streamClosed = true; - return false; - } - - if ( null == nextClassName ) - { - streamClosed = true; - } - else - { - addWorkItem( nextClassName ); - } - } - - return ( workQueue.size() > nextPos ); - } - } - } - - private boolean needsToWaitForInput( int nextPos ) - { - return workQueue.size() == nextPos && !streamClosed; - } - - public Object next() - { - synchronized ( workQueue ) - { - return workQueue.get( ++lastPos ); - } - } - - public void remove() - { - throw new UnsupportedOperationException(); - } - - } - - /* (non-Javadoc) - * @see org.apache.maven.surefire.util.TestsToRun#iterator() - */ - public Iterator iterator() - { - return new BlockingIterator(); - } - - /* (non-Javadoc) - * @see org.apache.maven.surefire.util.TestsToRun#toString() - */ - public String toString() - { - StringBuffer sb = new StringBuffer( "LazyTestsToRun " ); - synchronized ( workQueue ) - { - sb.append( "(more items expected: " ).append( !streamClosed ).append( "): " ); - sb.append( workQueue ); - } - - return sb.toString(); - } - - /* (non-Javadoc) - * @see org.apache.maven.surefire.util.TestsToRun#allowEagerReading() - */ - public boolean allowEagerReading() { - return false; - } - -} +package org.apache.maven.surefire.util; + +/* + * 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.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import org.apache.maven.surefire.booter.ForkingRunListener; + +/** + * A variant of TestsToRun that is provided with test class names + * from an {@link InputStream} (e.g. {@code System.in}). The method + * {@link #iterator()} returns an Iterator that blocks on calls to + * {@link Iterator#hasNext()} until new classes are available, or no more + * classes will be available. + * + * @author Andreas Gudian + */ +public class LazyTestsToRun + extends TestsToRun +{ + private List workQueue = new ArrayList(); + + private BufferedReader inputReader; + + private boolean streamClosed = false; + + private ClassLoader testClassLoader; + + private PrintStream originalOutStream; + + /** + * C'tor + * + * @param testSource source to read the tests from + * @param testClassLoader class loader to load the test classes + * @param originalOutStream the output stream to use when requesting new new tests + */ + public LazyTestsToRun( InputStream testSource, ClassLoader testClassLoader, PrintStream originalOutStream ) + { + super( Collections.emptyList() ); + + this.testClassLoader = testClassLoader; + this.originalOutStream = originalOutStream; + + inputReader = new BufferedReader( new InputStreamReader( testSource ) ); + } + + protected void addWorkItem( String className ) + { + synchronized ( workQueue ) + { + workQueue.add( ReflectionUtils.loadClass( testClassLoader, className ) ); + } + } + + protected void requestNextTest() + { + StringBuffer sb = new StringBuffer(); + sb.append( (char) ForkingRunListener.BOOTERCODE_NEXT_TEST ).append( ",0,want more!\n" ); + originalOutStream.print( sb.toString() ); + } + + private class BlockingIterator + implements Iterator + { + private int lastPos = -1; + + public boolean hasNext() + { + int nextPos = lastPos + 1; + synchronized ( workQueue ) + { + if ( workQueue.size() > nextPos ) + { + return true; + } + else + { + if ( needsToWaitForInput( nextPos ) ) + { + requestNextTest(); + + String nextClassName; + try + { + nextClassName = inputReader.readLine(); + } + catch ( IOException e ) + { + streamClosed = true; + return false; + } + + if ( null == nextClassName ) + { + streamClosed = true; + } + else + { + addWorkItem( nextClassName ); + } + } + + return ( workQueue.size() > nextPos ); + } + } + } + + private boolean needsToWaitForInput( int nextPos ) + { + return workQueue.size() == nextPos && !streamClosed; + } + + public Object next() + { + synchronized ( workQueue ) + { + return workQueue.get( ++lastPos ); + } + } + + public void remove() + { + throw new UnsupportedOperationException(); + } + + } + + /* (non-Javadoc) + * @see org.apache.maven.surefire.util.TestsToRun#iterator() + */ + public Iterator iterator() + { + return new BlockingIterator(); + } + + /* (non-Javadoc) + * @see org.apache.maven.surefire.util.TestsToRun#toString() + */ + public String toString() + { + StringBuffer sb = new StringBuffer( "LazyTestsToRun " ); + synchronized ( workQueue ) + { + sb.append( "(more items expected: " ).append( !streamClosed ).append( "): " ); + sb.append( workQueue ); + } + + return sb.toString(); + } + + /* (non-Javadoc) + * @see org.apache.maven.surefire.util.TestsToRun#allowEagerReading() + */ + public boolean allowEagerReading() { + return false; + } + +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/12c37d63/surefire-api/src/main/java/org/apache/maven/surefire/util/ScanResult.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/util/ScanResult.java b/surefire-api/src/main/java/org/apache/maven/surefire/util/ScanResult.java index 3c453f6..79895ce 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/util/ScanResult.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/util/ScanResult.java @@ -1,39 +1,39 @@ -package org.apache.maven.surefire.util; - -/* - * 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.util.List; -import java.util.Properties; - -/** - * @author Kristian Rosenvold - */ -public interface ScanResult -{ - int size(); - - String getClassName( int index ); - - TestsToRun applyFilter( ScannerFilter scannerFilter, ClassLoader testClassLoader ); - - List getClassesSkippedByValidation( ScannerFilter scannerFilter, ClassLoader testClassLoader ); - - void writeTo( Properties properties ); -} +package org.apache.maven.surefire.util; + +/* + * 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.util.List; +import java.util.Properties; + +/** + * @author Kristian Rosenvold + */ +public interface ScanResult +{ + int size(); + + String getClassName( int index ); + + TestsToRun applyFilter( ScannerFilter scannerFilter, ClassLoader testClassLoader ); + + List getClassesSkippedByValidation( ScannerFilter scannerFilter, ClassLoader testClassLoader ); + + void writeTo( Properties properties ); +} http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/12c37d63/surefire-api/src/test/java/org/apache/maven/surefire/util/ScanResultTest.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/test/java/org/apache/maven/surefire/util/ScanResultTest.java b/surefire-api/src/test/java/org/apache/maven/surefire/util/ScanResultTest.java index 8ca033b..a35ffbe 100644 --- a/surefire-api/src/test/java/org/apache/maven/surefire/util/ScanResultTest.java +++ b/surefire-api/src/test/java/org/apache/maven/surefire/util/ScanResultTest.java @@ -1,48 +1,48 @@ -package org.apache.maven.surefire.util; - -/* - * 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.util.Arrays; -import java.util.List; -import java.util.Properties; - -import junit.framework.TestCase; - -/** - * @author Kristian Rosenvold - */ -public class ScanResultTest - extends TestCase -{ - public void testWriteTo() - throws Exception - { - List files = Arrays.asList( new String[]{ "abc", "cde" } ); - DefaultScanResult scanResult = new DefaultScanResult( files ); - Properties serialized = new Properties(); - scanResult.writeTo( serialized ); - - DefaultScanResult read = DefaultScanResult.from( serialized ); - List files1 = read.getFiles(); - assertEquals( 2, files1.size() ); - assertTrue( files1.contains( "abc" ) ); - assertTrue( files1.contains( "cde" ) ); - } -} +package org.apache.maven.surefire.util; + +/* + * 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.util.Arrays; +import java.util.List; +import java.util.Properties; + +import junit.framework.TestCase; + +/** + * @author Kristian Rosenvold + */ +public class ScanResultTest + extends TestCase +{ + public void testWriteTo() + throws Exception + { + List files = Arrays.asList( new String[]{ "abc", "cde" } ); + DefaultScanResult scanResult = new DefaultScanResult( files ); + Properties serialized = new Properties(); + scanResult.writeTo( serialized ); + + DefaultScanResult read = DefaultScanResult.from( serialized ); + List files1 = read.getFiles(); + assertEquals( 2, files1.size() ); + assertTrue( files1.contains( "abc" ) ); + assertTrue( files1.contains( "cde" ) ); + } +}