From 23e875017199c6b569bbc968fd7de9b80a7a04da Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Thu, 24 Sep 2015 08:35:48 -0500 Subject: [PATCH] Initial commit. --- .gitignore | 3 ++ build.gradle | 20 +++++++++ .../net/GroovyDirectoryServer.groovy | 43 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 .gitignore create mode 100644 build.gradle create mode 100755 src/main/groovy/com/jdbernard/net/GroovyDirectoryServer.groovy diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3f1f880 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build/ +*.sw? +.gradle/ diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..fcfcfc5 --- /dev/null +++ b/build.gradle @@ -0,0 +1,20 @@ +apply plugin: "groovy" +apply plugin: "application" + +group = "com.jdbernard" +version = "1.0" + +mainClassName = "com.jdbernard.net.GroovyDirectoryServer" + +repositories { + mavenLocal() + mavenCentral() } + +dependencies { + compile 'org.codehaus.groovy:groovy-all:2.3.6' + compile 'org.slf4j:slf4j-api:1.7.10' + compile 'ch.qos.logback:logback-core:1.1.2' + compile 'ch.qos.logback:logback-classic:1.1.2' + compile 'javax.servlet:servlet-api:2.4' + compile 'javax.servlet.jsp:jsp-api:2.1' + compile 'org.eclipse.jetty.aggregate:jetty-all:7.6.15.v20140411' } diff --git a/src/main/groovy/com/jdbernard/net/GroovyDirectoryServer.groovy b/src/main/groovy/com/jdbernard/net/GroovyDirectoryServer.groovy new file mode 100755 index 0000000..965eafb --- /dev/null +++ b/src/main/groovy/com/jdbernard/net/GroovyDirectoryServer.groovy @@ -0,0 +1,43 @@ +package com.jdbernard.net + +import org.eclipse.jetty.server.Server +import org.eclipse.jetty.servlet.* +import groovy.servlet.* + +public class GroovyDirectoryServer { + + public static final String VERSION = "1.0" + + public static void main(String[] args) { + def port = 9002 + + if (args.length < 1) { println "Defaulting to port 9002" } + + else try { port = args[0] as int } + catch(Exception e) { + println "Usage: GroovyDirectoryServer.grooy " + System.exit(1) } + + println "Starting Jetty on port $port, press Ctrl-C to stop." + runJetty(port) + } + + public static void runJetty(int port) { + def server = new Server(port) + + def handler = new ServletContextHandler(ServletContextHandler.SESSIONS) + handler.contextPath = '/' + handler.resourceBase = '.' + + // Groovy Scripts + handler.addServlet(GroovyServlet, '*.groovy') + + // Files + def filesHolder = handler.addServlet(DefaultServlet, '/') + filesHolder.setInitParameter('resourceBase', '.') + + server.handler = handler + server.start() + } + +}