Permalink
Browse files

Added licence headers, javadoc, did some minor renaming

  • Loading branch information...
1 parent 9c6ce9b commit 05aa3a60015883588f47f48a8bc92a05c1efb075 @agudian agudian committed with krosenvold Nov 16, 2012
@@ -29,7 +29,7 @@
import java.util.jar.Manifest;
import org.apache.maven.plugin.surefire.AbstractSurefireMojo;
-import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.ProcessAwareCommandline;
+import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.OutputStreamFlushableCommandline;
import org.apache.maven.plugin.surefire.util.Relocator;
import org.apache.maven.shared.utils.StringUtils;
import org.apache.maven.shared.utils.cli.Commandline;
@@ -128,17 +128,17 @@ else if ( forkMode.equals( FORK_NEVER ) || forkMode.equals( FORK_ONCE ) ||
* @throws org.apache.maven.surefire.booter.SurefireBooterForkException
* when unable to perform the fork
*/
- public ProcessAwareCommandline createCommandLine( List<String> classPath, ClassLoaderConfiguration classpathConfiguration,
+ public OutputStreamFlushableCommandline createCommandLine( List<String> classPath, ClassLoaderConfiguration classpathConfiguration,
boolean shadefire, int threadNumber )
throws SurefireBooterForkException
{
return createCommandLine( classPath, classpathConfiguration.isManifestOnlyJarRequestedAndUsable(), shadefire, threadNumber );
}
- public ProcessAwareCommandline createCommandLine( List<String> classPath, boolean useJar, boolean shadefire, int threadNumber )
+ public OutputStreamFlushableCommandline createCommandLine( List<String> classPath, boolean useJar, boolean shadefire, int threadNumber )
throws SurefireBooterForkException
{
- ProcessAwareCommandline cli = new ProcessAwareCommandline();
+ OutputStreamFlushableCommandline cli = new OutputStreamFlushableCommandline();
cli.setExecutable( jvmExecutable );
@@ -40,7 +40,7 @@
import org.apache.maven.plugin.surefire.CommonReflector;
import org.apache.maven.plugin.surefire.StartupReportConfiguration;
import org.apache.maven.plugin.surefire.SurefireProperties;
-import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.ProcessAwareCommandline;
+import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.OutputStreamFlushableCommandline;
import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.TestProvidingInputStream;
import org.apache.maven.plugin.surefire.booterclient.output.ForkClient;
import org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsumer;
@@ -365,7 +365,7 @@ private RunResult fork( Object testSet, KeyValueSource providerProperties, ForkC
// Surefire-booter if !useSystemClassLoader
Classpath bootClasspath = Classpath.join( bootClasspathConfiguration, additionlClassPathUrls );
- @SuppressWarnings( "unchecked" ) ProcessAwareCommandline cli =
+ @SuppressWarnings( "unchecked" ) OutputStreamFlushableCommandline cli =
forkConfiguration.createCommandLine( bootClasspath.getClassPath(),
startupConfiguration.getClassLoaderConfiguration(),
startupConfiguration.isShadefire(), threadNumber );
@@ -1,7 +1,37 @@
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;
+/**
+ * Something that can be flushed.
+ *
+ * @author Andreas Gudian
+ *
+ */
public interface FlushReceiver {
+ /**
+ * Performs a flush, releasing any buffered resources.
+ *
+ * @throws IOException in case the flush operation failed
+ */
void flush() throws IOException;
}
@@ -1,5 +1,34 @@
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.
+ */
+
+/**
+ * Provides a {@link FlushReceiver}.
+ *
+ * @author Andreas Gudian
+ *
+ */
public interface FlushReceiverProvider {
+
+ /**
+ * @return a {@link FlushReceiver}
+ */
FlushReceiver getFlushReceiver();
}
@@ -0,0 +1,73 @@
+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.OutputStream;
+
+import org.apache.maven.shared.utils.cli.CommandLineException;
+import org.apache.maven.shared.utils.cli.Commandline;
+
+/**
+ * A {@link Commandline} implementation that provides the output stream of
+ * the executed process in form of a {@link FlushReceiver}, for it to be
+ * flushed on demand.
+ *
+ * @author Andreas Gudian
+ *
+ */
+public class OutputStreamFlushableCommandline extends Commandline implements FlushReceiverProvider {
+ /**
+ * Wraps an output stream in order to delegate a flush.
+ *
+ */
+ private final class OutputStreamFlushReceiver implements FlushReceiver {
+ private final OutputStream outputStream;
+
+ private OutputStreamFlushReceiver(OutputStream outputStream) {
+ this.outputStream = outputStream;
+ }
+
+ public void flush() throws IOException {
+ outputStream.flush();
+ }
+ }
+
+ private FlushReceiver flushReceiver;
+
+ @Override
+ public Process execute() throws CommandLineException {
+ Process process = super.execute();
+
+ if (process.getOutputStream() != null) {
+ flushReceiver = new OutputStreamFlushReceiver(process.getOutputStream());
+ }
+
+ return process;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.maven.plugin.surefire.booterclient.lazytestprovider.FlushReceiverProvider#getFlushReceiver()
+ */
+ public FlushReceiver getFlushReceiver() {
+ return flushReceiver;
+ }
+
+}
@@ -1,41 +0,0 @@
-package org.apache.maven.plugin.surefire.booterclient.lazytestprovider;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-import org.apache.maven.shared.utils.cli.CommandLineException;
-import org.apache.maven.shared.utils.cli.Commandline;
-
-
-
-public class ProcessAwareCommandline extends Commandline implements FlushReceiverProvider {
- private final class OutputStreamFlushReceiver implements FlushReceiver {
- private final OutputStream outputStream;
-
- private OutputStreamFlushReceiver(OutputStream outputStream) {
- this.outputStream = outputStream;
- }
-
- public void flush() throws IOException {
- outputStream.flush();
- }
- }
-
- private FlushReceiver flushReceiver;
-
- @Override
- public Process execute() throws CommandLineException {
- Process process = super.execute();
-
- if (process.getOutputStream() != null) {
- flushReceiver = new OutputStreamFlushReceiver(process.getOutputStream());
- }
-
- return process;
- }
-
- public FlushReceiver getFlushReceiver() {
- return flushReceiver;
- }
-
-}
@@ -1,21 +1,62 @@
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;
+ /**
+ * 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;
}
@@ -46,6 +87,9 @@ public synchronized int read() throws IOException {
}
}
+ /**
+ * Signal that a new test is to be provided.
+ */
public void provideNewTest() {
semaphore.release();
}
@@ -1,8 +1,24 @@
-/**
- *
- */
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;
@@ -16,7 +32,7 @@
import org.apache.maven.surefire.booter.ForkingRunListener;
/**
- * A variant of TestsToRun that is provided with test class names asynchronously
+ * 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
@@ -35,6 +51,13 @@
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());
@@ -104,6 +127,9 @@ public void remove() {
}
+ /* (non-Javadoc)
+ * @see org.apache.maven.surefire.util.TestsToRun#iterator()
+ */
public Iterator iterator() {
return new BlockingIterator();
}
@@ -122,6 +148,9 @@ public int size() {
throw new UnsupportedOperationException("use method iterator()");
}
+ /* (non-Javadoc)
+ * @see org.apache.maven.surefire.util.TestsToRun#toString()
+ */
public String toString() {
StringBuffer sb = new StringBuffer("LazyTestsToRun ");
synchronized (workQueue) {

0 comments on commit 05aa3a6

Please sign in to comment.