Skip to content
Browse files

Cleanup, minimalise for 1.0 release

  • Loading branch information...
1 parent 6f996d2 commit 00bc24fd173d232958f1b4100157eef16a4a50a3 @markhibberd committed Jun 19, 2011
Showing with 490 additions and 305 deletions.
  1. +1 −0 .gitignore
  2. +0 −15 NOTES
  3. +56 −4 README
  4. +0 −12 config.scala
  5. +0 −5 efoil
  6. BIN efoil.jar
  7. +202 −0 etc/licenses/jetty/LICENSE-2.0.txt
  8. +0 −27 etc/licenses/pirate/LICENSE
  9. +0 −6 etc/proguard.conf
  10. +0 −1 src/demo/file/config.scala
  11. +25 −0 src/demo/java/JavaDemo.java
  12. +15 −0 src/demo/java/JavaDemo.java~
  13. +20 −0 src/example/compound/config.scala
  14. +9 −0 src/example/compound/config.scala~
  15. +1 −0 src/example/compound/static/example.text
  16. 0 src/{demo/war → example/file}/config.scala
  17. 0 src/{demo/war-exploded → example/hotswap}/config.scala
  18. 0 src/{demo/servlet → example/http}/config.scala
  19. +3 −0 src/example/jrebel/config.scala
  20. 0 src/{demo/jrebel → example/servlet}/config.scala
  21. 0 src/{demo/http → example/war-exploded}/config.scala
  22. 0 src/{demo/hotswap → example/war}/config.scala
  23. 0 src/prod/io/mth/crux/ph
  24. +9 −0 src/prod/io/mth/foil/Foil.scala
  25. +9 −0 src/prod/io/mth/foil/FoilRunner.scala
  26. +2 −2 src/prod/io/mth/foil/{server → }/Jetty.scala
  27. +2 −2 src/prod/io/mth/foil/{server → }/JettyBind.scala
  28. +57 −0 src/prod/io/mth/foil/JettyConfig.scala
  29. +10 −6 src/prod/io/mth/foil/{server/JettyConfig.scala → JettyConfig.scala~}
  30. 0 src/prod/io/mth/foil/cli/ph
  31. +0 −5 src/prod/io/mth/foil/fabric/http/HttpEndpoint.java
  32. +0 −3 src/prod/io/mth/foil/fabric/http/HttpRequest.scala
  33. +0 −3 src/prod/io/mth/foil/fabric/http/HttpResponse.scala
  34. +0 −9 src/prod/io/mth/foil/fabric/http/HttpShim.scala
  35. +0 −12 src/prod/io/mth/foil/fabric/servlet/InteractiveFoil.scala
  36. +7 −0 src/prod/io/mth/foil/j/Config.java
  37. +10 −0 src/prod/io/mth/foil/j/Configs.java
  38. +20 −0 src/prod/io/mth/foil/j/DefaultConfigs.scala
  39. +12 −0 src/prod/io/mth/foil/j/DefaultFoils.scala
  40. +7 −0 src/prod/io/mth/foil/j/Foil.java
  41. +5 −0 src/prod/io/mth/foil/j/Foils.java
  42. 0 src/prod/io/mth/foil/launch/embedded/ph
  43. +0 −102 src/prod/io/mth/foil/launch/standalone/Main.scala
  44. +5 −0 src/prod/io/mth/foil/package.scala
  45. +3 −0 src/prod/io/mth/foil/package.scala~
  46. +0 −13 src/prod/io/mth/foil/server/Foil.scala
  47. +0 −12 src/prod/io/mth/foil/server/Slot.scala
  48. +0 −66 src/prod/io/mth/foil/server/Slots.scala
View
1 .gitignore
@@ -1,4 +1,5 @@
*.iws
+*~
gen
tmp
out
View
15 NOTES
@@ -1,16 +1 @@
-QUARK GLUONS
-PROTON NEUTRON ELECTRON
-ATOM MOLECULE
-crux - lineedit
-foil.cli - command line / dynamic config
-foil.fabric - container independent scaffolding
-foil.launch - laucher
-foil.server - server
-
-
-/usr/src/lib/libedit
-
-rlwrap
-
-jline
View
60 README
@@ -6,12 +6,64 @@ DESCRIPTION
jetty) providing quick config and launch, as well as an
interactive console.
-USAGE
- T.B.A.
+USAGE
+ Scala
+
+ The scala api consists of a number of data types to build
+ up a configuration, then a server, and then the server
+ can be started.
+
+ The important types are:
+
+ JettyConfig -- Only supported config for version 1.0
+ Foil -- The foil server configuration
+ FoilRunner -- Foil run operation
+
+ For example:
+
+ import io.mth.foil._
+
+ val config = compound(List(
+ servlet("/", "/*", new DemoServlet()), // bind DemoServlet to / context, matching all urls
+ path("/static", "static") // bind diretory resources to /static url.
+ ))
+
+ val foil = Foil("demp", 10080, config) // create server
+ runfoil(foil) // run server
+
+
+
+ Java
+
+ There is a thin java veneer around the scala api. The api
+ consists of `Configs` to build up the server configuration
+ and `Foils` to construct and start the server.
+
+ For example (matching the scala example):
+
+ import io.mth.foil.j.*;
+
+ public class DemoServer {
+ private static final Foils f = new DefaultFoils();
+ private static final Configs c = new DefaultConfigs();
+
+ public static void main(String[] args) {
+ Config config = c.compound(
+ c.servlet("/", "/*", new DemoServlet()), // bind DemoServlet to / context, matching all urls
+ c.path("/static", "resources") // bind diretory resources to /static url.
+ );
+ Foil foil = f.nu("demo", 10080, config); // create server
+ foil.run(); // run server
+ }
+ }
+
STATE
- The `foil` library is currently in an incubation stage and is
- considered experimental and subject to breaking change.
+ The `foil` library is currently has a stable api for creating
+ a runnable server.
+
+ The `foil` command line api is under development and will not
+ be stable until a 2.0 release.
AUTHOR
Mark Hibberd <mark@hibberd.id.au>
View
12 config.scala
@@ -1,12 +0,0 @@
-import io.mth.foil.fabric.servlet.InteractiveFoil
-import io.mth.foil.server._
-import java.io.File
-
-val c1 = JettyConfig.servlet("/a", "/*", new InteractiveFoil)
-val c2 = JettyConfig.path("/b", ".")
-val c3 = JettyConfig.path("/", "/home/mth")
-val compound = JettyConfig.compound(List(c1, c3, c2))
-
-slots.register(Foil(10081, c1), true)
-slots.register(Foil(10082, c2), true)
-slots.register(Foil(10080, compound), true)
View
5 efoil
@@ -1,5 +0,0 @@
-#!/bin/sh
-exec scala -cp `dirname $0`/lib/run/\*:gen/dist/foil.jar -savecompiled "$0" "$@"
-!#
-
-println("hello ...")
View
BIN efoil.jar
Binary file not shown.
View
202 etc/licenses/jetty/LICENSE-2.0.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
View
27 etc/licenses/pirate/LICENSE
@@ -1,27 +0,0 @@
-Copyright (c) 2010, Mark Hibberd <mark@hibberd.id.au>, Karl Roberts <karl.roberts@owtelse.com>
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of the <ORGANIZATION> nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
View
6 etc/proguard.conf
@@ -1,6 +0,0 @@
--libraryjars <java.home>/lib/rt.jar
--keep class io.mth.foil.** { *; }
--dontwarn
--dontoptimize
--dontobfuscate
-
View
1 src/demo/file/config.scala
@@ -1 +0,0 @@
-
View
25 src/demo/java/JavaDemo.java
@@ -0,0 +1,25 @@
+import io.mth.foil.j.*;
+import javax.servlet.http.*;
+import java.io.*;
+
+public class JavaDemo {
+ private static final Foils f = new DefaultFoils();
+ private static final Configs c = new DefaultConfigs();
+
+ public static class DemoServlet extends HttpServlet {
+ protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+ String path = req.getPathInfo();
+ PrintWriter writer = resp.getWriter();
+ writer.println("hello from " + path);
+ }
+ }
+
+ public static void main(String[] args) {
+ Config config = c.compound(
+ c.servlet("/", "/*", new DemoServlet()), // bind DemoServlet to / context, matching all urls
+ c.path("/static", "static") // bind diretory resources to /static url.
+ );
+ Foil foil = f.nu("demo", 10080, config); // create server
+ foil.run(); // run server
+ }
+}
View
15 src/demo/java/JavaDemo.java~
@@ -0,0 +1,15 @@
+import io.mth.foil.j.*;
+
+public class DemoServer {
+ private static final Foils f = new DefaultFoils();
+ private static final Configs c = new DefaultConfigs();
+
+ public static void main(String[] args) {
+ Config config = c.compound(
+ c.servlet("/", "/*", new DemoServlet()), // bind DemoServlet to / context, matching all urls
+ c.path("/static", "resources") // bind diretory resources to /static url.
+ );
+ Foil foil = f.nu("demo", 10080, config); // create server
+ foil.run(); // run server
+ }
+}
View
20 src/example/compound/config.scala
@@ -0,0 +1,20 @@
+import io.mth.foil._
+
+import javax.servlet.http._
+
+class DemoServlet extends HttpServlet {
+ override def service(req: HttpServletRequest, resp: HttpServletResponse) = {
+ val path = req.getPathInfo
+ val writer = resp.getWriter
+ writer.println("hello from " + path)
+ }
+}
+
+val config = compound(List(
+ servlet("/", "/*", new DemoServlet), // bind DemoServlet to / context, matching all urls
+ path("/static", "static") // bind directory resources to /static url.
+))
+
+val foil = Foil("demp", 10080, config) // create server
+runfoil(foil) // run server
+
View
9 src/example/compound/config.scala~
@@ -0,0 +1,9 @@
+ import io.mth.foil._
+
+ val config = compound(List(
+ servlet("/", "/*", new DemoServlet()), // bind DemoServlet to / context, matching all urls
+ path("/static", "resources") // bind diretory resources to /static url.
+ ))
+
+ val foil = Foil("demp", 10080, config) // create server
+ runfoil(foil) // run server
View
1 src/example/compound/static/example.text
@@ -0,0 +1 @@
+example static resources
View
0 src/demo/war/config.scala → src/example/file/config.scala
File renamed without changes.
View
0 src/demo/war-exploded/config.scala → src/example/hotswap/config.scala
File renamed without changes.
View
0 src/demo/servlet/config.scala → src/example/http/config.scala
File renamed without changes.
View
3 src/example/jrebel/config.scala
@@ -0,0 +1,3 @@
+
+
+
View
0 src/demo/jrebel/config.scala → src/example/servlet/config.scala
File renamed without changes.
View
0 src/demo/http/config.scala → src/example/war-exploded/config.scala
File renamed without changes.
View
0 src/demo/hotswap/config.scala → src/example/war/config.scala
File renamed without changes.
View
0 src/prod/io/mth/crux/ph
No changes.
View
9 src/prod/io/mth/foil/Foil.scala
@@ -0,0 +1,9 @@
+package io.mth.foil
+
+case class Foil(uuid: String, port: Int, config: JettyConfig) {
+ def this(port: Int, config: JettyConfig) = this(java.util.UUID.randomUUID().toString, port, config)
+}
+
+object Foil {
+ def apply(port: Int, config: JettyConfig): Foil = new Foil(port, config)
+}
View
9 src/prod/io/mth/foil/FoilRunner.scala
@@ -0,0 +1,9 @@
+package io.mth.foil
+
+object FoilRunner {
+ def run(foil: Foil) = {
+ val jetty = Jetty.server(foil.port, foil.config)
+ jetty.start
+ jetty.join
+ }
+}
View
4 src/prod/io/mth/foil/server/Jetty.scala → src/prod/io/mth/foil/Jetty.scala
@@ -1,4 +1,4 @@
-package io.mth.foil.server
+package io.mth.foil
import org.eclipse.jetty.server.handler._
import org.eclipse.jetty.server.Server
@@ -14,4 +14,4 @@ object Jetty {
binder(server)
server
}
-}
+}
View
4 src/prod/io/mth/foil/server/JettyBind.scala → src/prod/io/mth/foil/JettyBind.scala
@@ -1,4 +1,4 @@
-package io.mth.foil.server
+package io.mth.foil
import javax.servlet.Servlet
import org.eclipse.jetty.servlet.ServletContextHandler.NO_SESSIONS
@@ -81,4 +81,4 @@ object JettyBind {
}
-}
+}
View
57 src/prod/io/mth/foil/JettyConfig.scala
@@ -0,0 +1,57 @@
+package io.mth.foil
+
+import scala.collection.JavaConversions._
+import javax.servlet.Servlet
+
+trait JettyConfig {
+ def fold[T](
+ war: String => String => T,
+ path: String => String => T,
+ servlet: String => String => Servlet => T,
+ compound: List[JettyConfig] => T
+ ): T
+}
+
+
+object JettyConfig extends JettyConfigs
+
+trait JettyConfigs {
+ def war(context: String, w: String): JettyConfig = new JettyConfig {
+ def fold[T](
+ war: String => String => T,
+ path: String => String => T,
+ servlet: String => String => Servlet => T,
+ compound: List[JettyConfig] => T
+ ) = war(context)(w)
+ }
+
+ def path(context: String, p: String): JettyConfig = new JettyConfig {
+ def fold[T](
+ war: String => String => T,
+ path: String => String => T,
+ servlet: String => String => Servlet => T,
+ compound: List[JettyConfig] => T
+ ) = path(context)(p)
+ }
+
+ def servlet(context: String, pattern: String, s: Servlet): JettyConfig = new JettyConfig {
+ def fold[T](
+ war: String => String => T,
+ path: String => String => T,
+ servlet: String => String => Servlet => T,
+ compound: List[JettyConfig] => T
+ ) = servlet(context)(pattern)(s)
+ }
+
+ def compound(configs: List[JettyConfig]): JettyConfig = new JettyConfig {
+ def fold[T](
+ war: String => String => T,
+ path: String => String => T,
+ servlet: String => String => Servlet => T,
+ compound: List[JettyConfig] => T
+ ) = compound(configs)
+ }
+
+}
+
+
View
16 ...prod/io/mth/foil/server/JettyConfig.scala → src/prod/io/mth/foil/JettyConfig.scala~
@@ -1,5 +1,6 @@
-package io.mth.foil.server
+package io.mth.foil
+import scala.collection.JavaConversions._
import javax.servlet.Servlet
trait JettyConfig {
@@ -12,7 +13,7 @@ trait JettyConfig {
}
object JettyConfig {
- def war(context: String, w: String) = new JettyConfig {
+ def war(context: String, w: String): JettyConfig = new JettyConfig {
def fold[T](
war: String => String => T,
path: String => String => T,
@@ -21,7 +22,7 @@ object JettyConfig {
) = war(context)(w)
}
- def path(context: String, p: String) = new JettyConfig {
+ def path(context: String, p: String): JettyConfig = new JettyConfig {
def fold[T](
war: String => String => T,
path: String => String => T,
@@ -30,7 +31,7 @@ object JettyConfig {
) = path(context)(p)
}
- def servlet(context: String, pattern: String, s: Servlet) = new JettyConfig {
+ def servlet(context: String, pattern: String, s: Servlet): JettyConfig = new JettyConfig {
def fold[T](
war: String => String => T,
path: String => String => T,
@@ -39,12 +40,15 @@ object JettyConfig {
) = servlet(context)(pattern)(s)
}
- def compound(configs: List[JettyConfig]) = new JettyConfig {
+ def compound(configs: List[JettyConfig]): JettyConfig = new JettyConfig {
def fold[T](
war: String => String => T,
path: String => String => T,
servlet: String => String => Servlet => T,
compound: List[JettyConfig] => T
) = compound(configs)
}
-}
+
+}
+
+
View
0 src/prod/io/mth/foil/cli/ph
No changes.
View
5 src/prod/io/mth/foil/fabric/http/HttpEndpoint.java
@@ -1,5 +0,0 @@
-package io.mth.foil.fabric.http;
-
-public interface HttpEndpoint {
-
-}
View
3 src/prod/io/mth/foil/fabric/http/HttpRequest.scala
@@ -1,3 +0,0 @@
-package io.mth.foil.fabric.http
-
-class HttpRequest
View
3 src/prod/io/mth/foil/fabric/http/HttpResponse.scala
@@ -1,3 +0,0 @@
-package io.mth.foil.fabric.http
-
-case class HttpResponse(response: Int)
View
9 src/prod/io/mth/foil/fabric/http/HttpShim.scala
@@ -1,9 +0,0 @@
-package io.mth.foil.fabric.http
-
-import javax.servlet.http.{HttpServletResponse, HttpServletRequest, HttpServlet}
-
-class HttpShim extends HttpServlet {
- override def service(req: HttpServletRequest, resp: HttpServletResponse) = {
-
- }
-}
View
12 src/prod/io/mth/foil/fabric/servlet/InteractiveFoil.scala
@@ -1,12 +0,0 @@
-package io.mth.foil.fabric.servlet
-
-import javax.servlet.http.{HttpServletResponse, HttpServletRequest, HttpServlet}
-
-class InteractiveFoil extends HttpServlet {
- override def service(req: HttpServletRequest, resp: HttpServletResponse) = {
- val out = resp.getWriter
- out.println("content-type: " + req.getContentType)
- out.println("context-path: " + req.getContextPath)
- out.println("request-meth: " + req.getMethod)
- }
-}
View
7 src/prod/io/mth/foil/j/Config.java
@@ -0,0 +1,7 @@
+package io.mth.foil.j;
+
+import io.mth.foil.JettyConfig;
+
+public interface Config {
+ JettyConfig jetty();
+}
View
10 src/prod/io/mth/foil/j/Configs.java
@@ -0,0 +1,10 @@
+package io.mth.foil.j;
+
+import javax.servlet.Servlet;
+
+public interface Configs {
+ Config war(String context, String war);
+ Config path(String context, String path);
+ Config servlet(String context, String pattern, Servlet s);
+ Config compound(Config... configs);
+}
View
20 src/prod/io/mth/foil/j/DefaultConfigs.scala
@@ -0,0 +1,20 @@
+package io.mth.foil.j
+
+import java.lang.String
+import javax.servlet.Servlet
+import io.mth.foil.JettyConfig
+
+
+class DefaultConfigs extends Configs {
+ def config(j: JettyConfig): Config = new Config {
+ val jetty = j
+ }
+
+ def compound(configs:Config*) = config(JettyConfig.compound(configs.toList map (_.jetty)))
+
+ def servlet(context: String, pattern: String, s: Servlet) = config(JettyConfig.servlet(context, pattern, s))
+
+ def path(context: String, path: String) = config(JettyConfig.path(context, path))
+
+ def war(context: String, war: String) = config(JettyConfig.war(context, war))
+}
View
12 src/prod/io/mth/foil/j/DefaultFoils.scala
@@ -0,0 +1,12 @@
+package io.mth.foil.j
+
+import java.lang.String
+import io.mth.foil.{Foil => F, FoilRunner}
+
+class DefaultFoils extends Foils{
+ def nu(name: String, port: Int, config: Config): Foil = new Foil {
+ def run = {
+ FoilRunner.run(F(name, port, config.jetty))
+ }
+ }
+}
View
7 src/prod/io/mth/foil/j/Foil.java
@@ -0,0 +1,7 @@
+package io.mth.foil.j;
+
+public interface Foil {
+ void run();
+}
+
+
View
5 src/prod/io/mth/foil/j/Foils.java
@@ -0,0 +1,5 @@
+package io.mth.foil.j;
+
+public interface Foils {
+ Foil nu(String name, int port, Config config);
+}
View
0 src/prod/io/mth/foil/launch/embedded/ph
No changes.
View
102 src/prod/io/mth/foil/launch/standalone/Main.scala
@@ -1,102 +0,0 @@
-package io.mth.foil.launch.standalone
-
-import tools.nsc.{GenericRunnerSettings, Settings}
-import io.mth.foil.server.{Slot, Slots}
-import java.net.URLClassLoader
-import tools.nsc.io.File
-
-
-object Main {
- def usage = """
- | foil [-h] [-e expression] [-c] [-v] [<config.scala>]
- |
- | Options:
- | -e, --eval <expression> evalute expression instead of dropping
- | into console.
- | -c, --console drop into console after startup (this
- | is the default if no config specified)
- | -h, --help display this usage message
- | -v, --version display version information
- |
- | Arguments:
- | <config.scala> config file, in scala. commands run as
- | per console. Config is optional, no
- | config is equivalent to `--console`.
- |
- """.stripMargin
-
- // FIX read from manifest...
- def version = "foil development version 0"
-
- def main(args: Array[String]) = {
- // FIX some awesomely inefficient command line parsing... or non-parsing as it would be. replace with pirate
-
-
- def mungeToPositional(l: List[String]): List[String] = {
- var acc = l;
- while (acc.size > 0) {
- val x = acc(0)
- val toDrop = if (x == "-e" || x == "--eval") 2
- else if (x.startsWith("-")) 1
- else return acc
- acc.drop(toDrop)
- }
- List[String]()
- }
-
-
- val splitter = args.indexOf("--")
- val trunced = if (splitter > 0) args.slice(0, splitter) else args
- val positional = if (splitter > 0) args.slice(splitter + 1, args.length)
- else mungeToPositional(args.toList).toArray
-
-
- def hasFlag(short: String, long: String) = trunced.exists(s => s == short || s == long)
- def positionOfFlag(short: String, long: String) = trunced.indexWhere(s => s == short || s == long)
-
- if (hasFlag("-h", "--help")) {
- println(usage)
- System.exit(0)
- }
-
- if (hasFlag("-v", "--version")) {
- println(version)
- System.exit(0)
- }
-
- val eval: Option[String] = if (hasFlag("-e", "--eval")) {
- val idx = positionOfFlag("-e", "--eval")
- if (trunced.length < idx + 1) {
- System.err.println("--eval expects argument")
- System.err.println(usage)
- System.exit(1)
- }
- Some(trunced(idx + 1))
- } else None
-
- val console = hasFlag("-c", "--console")
-
- val slots = Slots()
-
- val settings = new GenericRunnerSettings(Console.println _)
-
- val cls = classOf[Slot]
- val loader: URLClassLoader = cls.getClassLoader.asInstanceOf[URLClassLoader]
- val paths = loader.getURLs.map(x => x.getFile)
- paths.foreach(settings.classpath.append _)
-
- val x = new scala.tools.nsc.InterpreterLoop(None, new java.io.PrintWriter(System.out)) {
- override def createInterpreter() {
- super.createInterpreter()
- interpreter.beQuietDuring {
- interpreter.bind("slots", "io.mth.foil.server.Slots", slots)
- }
- interpretAllFrom(File(new java.io.File("config.scala")))
- }
- }
-
- x.main(settings)
-
- slots.stop()
- }
-}
View
5 src/prod/io/mth/foil/package.scala
@@ -0,0 +1,5 @@
+package io.mth
+
+package object foil extends JettyConfigs {
+ def runfoil(foil: Foil) = FoilRunner.run(foil)
+}
View
3 src/prod/io/mth/foil/package.scala~
@@ -0,0 +1,3 @@
+package io.mth
+
+package object foil extends JettyConfig
View
13 src/prod/io/mth/foil/server/Foil.scala
@@ -1,13 +0,0 @@
-package io.mth.foil.server
-
-import java.util.UUID
-
-
-case class Foil(uuid: String, port: Int, config: JettyConfig)
-
-object Foil {
- def apply(port: Int, config: JettyConfig): Foil = Foil(UUID.randomUUID().toString, port, config)
-}
-
-
-
View
12 src/prod/io/mth/foil/server/Slot.scala
@@ -1,12 +0,0 @@
-package io.mth.foil.server
-
-
-trait Slot {
- def foil: Foil
-
- def start()
-
- def stop()
-
- def status: Boolean
-}
View
66 src/prod/io/mth/foil/server/Slots.scala
@@ -1,66 +0,0 @@
-package io.mth.foil.server
-
-trait Slots {
- def status(pred: Foil => Boolean): List[Boolean]
-
- def status(uuid: String): Boolean = status((foil: Foil) => foil.uuid == uuid).head
-
- def status(foil: Foil): Boolean = status(foil.uuid)
-
- def status(): List[Boolean] = status((foil: Foil) => true)
-
- def start(pred: Foil => Boolean): Unit
-
- def start(uuid: String): Unit = start((foil: Foil) => foil.uuid == uuid)
-
- def start(foil: Foil): Unit = start(foil.uuid)
-
- def start(): Unit = start((foil: Foil) => true)
-
- def stop(pred: Foil => Boolean): Unit
-
- def stop(uuid: String): Unit = stop((foil: Foil) => foil.uuid == uuid)
-
- def stop(foil: Foil): Unit = stop(foil.uuid)
-
- def stop(): Unit = stop((foil: Foil) => true): Unit
-
- def update(pred: Foil => Boolean)(f: Foil => Foil): Unit
-
- def update(uuid: String)(f: Foil => Foil): Unit = update((foil: Foil) => foil.uuid == uuid)(f)
-
- def update(f: Foil => Foil): Unit = update((foil: Foil) => true)(f)
-
- def register(foil: Foil, start: Boolean): Unit
-}
-
-object Slots {
- def apply() = new Slots {
- var guts: List[Slot] = List()
-
- def start(pred: Foil => Boolean) = (guts filter (s => pred(s.foil))) foreach (_.start())
-
- def stop(pred: Foil => Boolean) = (guts filter (s => pred(s.foil))) foreach (_.stop())
-
- def status(pred: Foil => Boolean) = (guts filter (s => pred(s.foil))) map (_.status)
-
- def update(pred: Foil => Boolean)(f: Foil => Foil): Unit = {
-
- }
-
- def register(f: Foil, start: Boolean) = {
- if (guts.exists(_.foil.uuid == f.uuid))
- throw new IllegalArgumentException("Duplicate UUID [" + f.uuid + "].")
- val jetty = Jetty.server(f.port, f.config)
- val slot = new Slot {
- def foil = f
- def start = jetty.start()
- def stop = jetty.stop()
- def status = jetty.isRunning
- }
- if (start)
- slot.start
- guts = slot :: guts
- }
- }
-}

0 comments on commit 00bc24f

Please sign in to comment.
Something went wrong with that request. Please try again.