Search in sources :

Example 1 with HttpFileServer

use of org.gradle.plugins.javascript.envjs.http.HttpFileServer in project gradle by gradle.

the class BrowserEvaluate method doEvaluate.

@TaskAction
void doEvaluate() {
    HttpFileServer fileServer = new SimpleHttpFileServerFactory().start(getContent(), 0);
    try {
        Writer resultWriter = new FileWriter(getResult());
        getEvaluator().evaluate(fileServer.getResourceUrl(getResource()), resultWriter);
        resultWriter.close();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } finally {
        fileServer.stop();
    }
    setDidWork(true);
}
Also used : SimpleHttpFileServerFactory(org.gradle.plugins.javascript.envjs.http.simple.SimpleHttpFileServerFactory) FileWriter(java.io.FileWriter) HttpFileServer(org.gradle.plugins.javascript.envjs.http.HttpFileServer) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 2 with HttpFileServer

use of org.gradle.plugins.javascript.envjs.http.HttpFileServer in project gradle by gradle.

the class SimpleHttpFileServerFactory method start.

public HttpFileServer start(File contentRoot, int port) {
    Container container = new SimpleFileServerContainer(new FileContext(contentRoot));
    try {
        final Server server = new ContainerServer(container);
        Connection connection = new SocketConnection(server);
        InetSocketAddress address = new InetSocketAddress(port);
        InetSocketAddress usedAddress = (InetSocketAddress) connection.connect(address);
        return new SimpleHttpFileServer(contentRoot, usedAddress.getPort(), new Stoppable() {

            public void stop() {
                try {
                    server.stop();
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
        });
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : SimpleFileServerContainer(org.gradle.plugins.javascript.envjs.http.simple.internal.SimpleFileServerContainer) ContainerServer(org.simpleframework.http.core.ContainerServer) Container(org.simpleframework.http.core.Container) SimpleFileServerContainer(org.gradle.plugins.javascript.envjs.http.simple.internal.SimpleFileServerContainer) Server(org.simpleframework.transport.Server) HttpFileServer(org.gradle.plugins.javascript.envjs.http.HttpFileServer) ContainerServer(org.simpleframework.http.core.ContainerServer) SocketConnection(org.simpleframework.transport.connect.SocketConnection) InetSocketAddress(java.net.InetSocketAddress) Connection(org.simpleframework.transport.connect.Connection) SocketConnection(org.simpleframework.transport.connect.SocketConnection) Stoppable(org.gradle.internal.concurrent.Stoppable) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) FileContext(org.simpleframework.http.resource.FileContext)

Aggregations

IOException (java.io.IOException)2 UncheckedIOException (org.gradle.api.UncheckedIOException)2 HttpFileServer (org.gradle.plugins.javascript.envjs.http.HttpFileServer)2 FileWriter (java.io.FileWriter)1 Writer (java.io.Writer)1 InetSocketAddress (java.net.InetSocketAddress)1 Stoppable (org.gradle.internal.concurrent.Stoppable)1 SimpleHttpFileServerFactory (org.gradle.plugins.javascript.envjs.http.simple.SimpleHttpFileServerFactory)1 SimpleFileServerContainer (org.gradle.plugins.javascript.envjs.http.simple.internal.SimpleFileServerContainer)1 Container (org.simpleframework.http.core.Container)1 ContainerServer (org.simpleframework.http.core.ContainerServer)1 FileContext (org.simpleframework.http.resource.FileContext)1 Server (org.simpleframework.transport.Server)1 Connection (org.simpleframework.transport.connect.Connection)1 SocketConnection (org.simpleframework.transport.connect.SocketConnection)1