Skip to content

Commit

Permalink
Added licence headers, javadoc, did some minor renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
agudian authored and krosenvold committed Nov 17, 2012
1 parent 9c6ce9b commit 05aa3a6
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down Expand Up @@ -46,6 +87,9 @@ public synchronized int read() throws IOException {
}
}

/**
* Signal that a new test is to be provided.
*/
public void provideNewTest() {
semaphore.release();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -35,6 +51,13 @@ public class LazyTestsToRun extends TestsToRun {
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());

Expand Down Expand Up @@ -104,6 +127,9 @@ public void remove() {

}

/* (non-Javadoc)
* @see org.apache.maven.surefire.util.TestsToRun#iterator()
*/
public Iterator iterator() {
return new BlockingIterator();
}
Expand All @@ -122,6 +148,9 @@ public Class[] getLocatedClasses() {
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) {
Expand Down

0 comments on commit 05aa3a6

Please sign in to comment.