├── src ├── it │ ├── resources │ │ └── .gitkeep │ └── scala │ │ └── io │ │ └── github │ │ └── yeghishe │ │ └── .gitkeep ├── main │ ├── resources │ │ ├── .gitkeep │ │ └── log4j.properties │ └── scala │ │ └── io │ │ └── github │ │ └── yeghishe │ │ ├── .gitkeep │ │ ├── Config.scala │ │ └── Main.scala └── test │ ├── resources │ └── .gitkeep │ └── scala │ └── io │ └── github │ └── yeghishe │ └── .gitkeep ├── .gitignore ├── .travis.yml ├── libexec └── activator-launch-1.3.10.jar ├── project ├── build.properties └── plugins.sbt ├── .scalafmt.conf ├── activator.properties ├── LICENSE ├── README.md ├── tutorial └── index.html ├── scalastyle-config.xml └── bin ├── activator.bat └── activator /src/it/resources/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/test/resources/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/it/scala/io/github/yeghishe/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/scala/io/github/yeghishe/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/test/scala/io/github/yeghishe/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .ensime* 3 | target/ 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: scala 2 | jdk: 3 | - oraclejdk8 4 | scala: 5 | - 2.12.1 6 | -------------------------------------------------------------------------------- /libexec/activator-launch-1.3.10.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yeghishe/scala-aws-lambda-seed/HEAD/libexec/activator-launch-1.3.10.jar -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | #Activator-generated Properties 2 | #Wed Sep 07 18:36:16 PDT 2016 3 | template.uuid=3d9081e7-6769-4356-8979-a461e983dd46 4 | sbt.version=0.13.12 5 | -------------------------------------------------------------------------------- /src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log = . 2 | log4j.rootLogger = DEBUG, LAMBDA 3 | 4 | log4j.appender.LAMBDA=com.amazonaws.services.lambda.runtime.log4j.LambdaAppender 5 | log4j.appender.LAMBDA.layout=org.apache.log4j.PatternLayout 6 | log4j.appender.LAMBDA.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss} <%X{AWSRequestId}> %-5p %c{1}:%L - %m%n 7 | -------------------------------------------------------------------------------- /.scalafmt.conf: -------------------------------------------------------------------------------- 1 | style = defaultWithAlign 2 | maxColumn = 120 3 | align.openParenCallSite = false 4 | align.openParenDefnSite = false 5 | danglingParentheses = true 6 | 7 | rewrite.rules = [RedundantBraces, RedundantParens, SortImports, PreferCurlyFors] 8 | rewrite.redundantBraces.includeUnitMethods = true 9 | rewrite.redundantBraces.stringInterpolation = true 10 | -------------------------------------------------------------------------------- /activator.properties: -------------------------------------------------------------------------------- 1 | name=scala-aws-lambda-seed 2 | title=Scala AWS Lambda Seed 3 | description=This is a seed project to create AWS Lambdas in Sala and upload to S3. 4 | tags=scala,aws,lambda,seed,starter 5 | authorName=Yeghishe Piruzyan 6 | authorLink=http://yeghishe.github.io/ 7 | authorTwitter=ypiruzyan 8 | authorLogo=https://avatars2.githubusercontent.com/u/1479173 9 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | resolvers += Classpaths.sbtPluginReleases 2 | 3 | addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "0.5.5") 4 | addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0") 5 | addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.0") 6 | addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.3") 7 | addSbtPlugin("com.typesafe.sbt" % "sbt-s3" % "0.9") 8 | -------------------------------------------------------------------------------- /src/main/scala/io/github/yeghishe/Config.scala: -------------------------------------------------------------------------------- 1 | package io.github.yeghishe 2 | 3 | import com.typesafe.config.ConfigFactory 4 | import net.ceedubs.ficus.Ficus 5 | import net.ceedubs.ficus.readers.ArbitraryTypeReader 6 | import net.ceedubs.ficus.readers.namemappers.implicits 7 | 8 | trait Config { 9 | import Ficus._ 10 | import ArbitraryTypeReader._ 11 | import implicits.hyphenCase 12 | 13 | private val config = ConfigFactory.load() 14 | } 15 | 16 | object Config extends Config 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Licensed under the Apache License, Version 2.0 (the "License"); 2 | you may not use this file except in compliance with the License. 3 | You may obtain a copy of the License at 4 | 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | -------------------------------------------------------------------------------- /src/main/scala/io/github/yeghishe/Main.scala: -------------------------------------------------------------------------------- 1 | package io.github.yeghishe 2 | 3 | import com.amazonaws.services.lambda.runtime.Context 4 | 5 | import scala.concurrent.Future 6 | import io.circe.generic.auto._ 7 | import io.github.yeghishe.lambda._ 8 | 9 | // handler io.github.yeghishe.MySimpleHander::handler 10 | // input "foo" 11 | object MySimpleHander extends App { 12 | def handler(name: String, context: Context): String = s"Hello $name" 13 | } 14 | 15 | case class Name(name: String) 16 | case class Greeting(message: String) 17 | 18 | // handler io.github.yeghishe.MyHandler 19 | // input {"name": "Yeghishe"} 20 | class MyHandler extends Handler[Name, Greeting] { 21 | def handler(name: Name, context: Context): Greeting = { 22 | logger.info(s"Name is $name") 23 | Greeting(s"Hello ${name.name}") 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | scala-aws-lambda-seed 2 | ========================= 3 | 4 | **Deprecated in favor of [yeghishe/scala-aws-lambda-seed.g8](https://github.com/yeghishe/scala-aws-lambda-seed.g8)** 5 | 6 | [![Build Status][build-status-badge]][build-status-url] 7 | [![Code Quality][code-quality-badge]][code-quality-url] 8 | 9 | [![Issues][issues-badge]][issues-url] 10 | 11 | [![License][license-badge]][license-url] 12 | [![Chat][chat-badge]][chat-url] 13 | 14 | This is a seed project to create AWS Lambdas in Sala 15 | 16 | ## To create a new project run 17 | 18 | ``` 19 | activator new scala-aws-lambda-seed 20 | ``` 21 | 22 | ## Overview 23 | The project is intended to be used as an activator template to generate AWS Lambda projects. 24 | From the command line, you can execute `activator new scala-aws-lambda-seed$` to generate a project. From activator UI find the template named `scala-aws-lambda-seed$` and generate your project using it. 25 | 26 | Once the project is generated you get few things out of the box: 27 | * [Config](https://github.com/yeghishe/minimal-scala-akka-http-seed/blob/master/src/main/scala/io/github/yeghishe/Config.scala) is handled using [Ficus](https://github.com/ceedubs/ficus). Make sure to create your case classes for new config values you add in typesafe config. You can later mix in `Config` trait or import your values from `Config` object. 28 | * [Scalafmt](https://github.com/olafurpg/scalafmt) is being used for code formatting. 29 | * [Scalastyle](http://www.scalastyle.org/) is being used fro code style checking. 30 | * [Scoverage](https://github.com/scoverage/sbt-scoverage) is being used for code coverage . 31 | * [Sbt Assembly](https://github.com/sbt/sbt-assembly) is being used for packaging. 32 | * [Sbt S3](https://github.com/sbt/sbt-s3) is being used for deployment to S3. 33 | 34 | 35 | [build-status-badge]: https://img.shields.io/travis/yeghishe/scala-aws-lambda-seed.svg?style=flat-square 36 | [build-status-url]: https://travis-ci.org/yeghishe/scala-aws-lambda-seed 37 | [code-quality-badge]: https://img.shields.io/codacy/07a7abfa2f134206a9e864a58d7759e2.svg?style=flat-square 38 | [code-quality-url]: https://www.codacy.com/app/ypiruzyan/scala-aws-lambda-seed 39 | [issues-badge]: https://img.shields.io/github/issues/yeghishe/scala-aws-lambda-seed.svg?style=flat-square 40 | [issues-url]: https://github.com/yeghishe/scala-aws-lambda-seed/issues 41 | [license-badge]: https://img.shields.io/badge/License-Apache%202-blue.svg?style=flat-square 42 | [license-url]: LICENSE 43 | [chat-badge]: https://img.shields.io/badge/gitter-join%20chat-brightgreen.svg?style=flat-square 44 | [chat-url]: https://gitter.im/yeghishe/scala-aws-lambda-seed 45 | -------------------------------------------------------------------------------- /tutorial/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Scala AWS Lambda Seed Tutorial 6 | 7 | 8 |
9 |

Simple handler for primitives

10 |

11 | To create a simple handler that takes primitives as arguments and responds with a primitive. 12 |

13 |
 14 | 
 15 |   object MySimpleHander extends App {
 16 |     def handler(name: String, context: Context): String = s"Hello $name"
 17 |   }
 18 | 
 19 |       
20 |

21 | To execute this specify <YOUR PACKAGE>.MySimpleHander::handler as the handler for Lambda and "example" quoted string as input. 22 |

23 |
24 | 25 |
26 |

Handler that take a case class and responds with a case class

27 |

28 | 29 | To create a handler that takes a case class and responds with a case class. 30 |

31 |
 32 | 
 33 | case class Name(name: String)
 34 | case class Greeting(message: String)
 35 | 
 36 | class MyHandler extends Handler[Name, Greeting] {
 37 |   def handler(name: Name, context: Context): Greeting = {
 38 |     logger.info(s"Name is $name")
 39 |     Greeting(s"Hello ${name.name}")
 40 |   }
 41 | }
 42 | 
 43 |       
44 |

45 | To execute this specify <YOUR PACKAGE>MyHandler as the handler for Lambda and {"name": "example"} json as input. 46 |

47 |
48 | 49 |
50 |

Handler that take a case class and doesn't return a respondse

51 |

52 | 53 | To create a handler that take a case class and doesn't return a respondse. 54 |

55 |
 56 | 
 57 | case class Name(name: String)
 58 | case class Greeting(message: String)
 59 | 
 60 | class MyHandler extends Handler[Name, Unit] {
 61 |   def handler(name: Name, context: Context): Unit = {
 62 |     logger.info(s"Name is $name")
 63 |     logger.info(Greeting(s"Hello ${name.name}"))
 64 |   }
 65 | }
 66 | 
 67 |       
68 |

69 | To execute this specify <YOUR PACKAGE>MyHandler as the handler for Lambda and {"name": "example"} json as input. 70 |

71 |
72 | 73 |
74 |

Handler that take a case class and returns future respondse

75 |

76 | 77 | To create a handler that take a case class and returns future respondse. 78 |

79 |
 80 | 
 81 | case class Name(name: String)
 82 | case class Greeting(message: String)
 83 | 
 84 | class MyHandler extends FutureHandler[Name, Greeting] {
 85 |   def handlerFuture(name: Name, context: Context): Future[Greeting] = {
 86 |     logger.info(s"Name is $name")
 87 |     Future(Thread.sleep(2000)).map(_ => Greeting(s"Hello ${name.name}"))
 88 |   }
 89 | }
 90 | 
 91 |       
92 |

93 | To execute this specify <YOUR PACKAGE>MyHandler as the handler for Lambda and {"name": "example"} json as input. 94 |

95 |
96 | 97 |
98 |

Handler that take a case class and returns future unit

99 |

100 | 101 | To create a handler that take a case class and returns future unit. 102 |

103 |
104 | 
105 | case class Name(name: String)
106 | case class Greeting(message: String)
107 | 
108 | class MyFutureHandler2 extends FutureHandler[Name, Unit] {
109 |   def handlerFuture(name: Name, context: Context): Future[Unit] = {
110 |     logger.info(s"Name is $name")
111 |     Future(Thread.sleep(2000)).map(_ => logger.info(Greeting(s"Hello ${name.name}")))
112 |   }
113 | }
114 | 
115 |       
116 |

117 | To execute this specify <YOUR PACKAGE>MyHandler as the handler for Lambda and {"name": "example"} json as input. 118 |

119 |
120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /scalastyle-config.xml: -------------------------------------------------------------------------------- 1 | 2 | Scalastyle standard configuration 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /bin/activator.bat: -------------------------------------------------------------------------------- 1 | @REM activator launcher script 2 | @REM 3 | @REM Environment: 4 | @REM In order for Activator to work you must have Java available on the classpath 5 | @REM JAVA_HOME - location of a JDK home dir (optional if java on path) 6 | @REM CFG_OPTS - JVM options (optional) 7 | @REM Configuration: 8 | @REM activatorconfig.txt found in the ACTIVATOR_HOME or ACTIVATOR_HOME/ACTIVATOR_VERSION 9 | @setlocal enabledelayedexpansion 10 | 11 | @echo off 12 | 13 | set "var1=%~1" 14 | if defined var1 ( 15 | if "%var1%"=="help" ( 16 | echo. 17 | echo Usage activator [options] [command] 18 | echo. 19 | echo Commands: 20 | echo ui Start the Activator UI 21 | echo new [name] [template-id] Create a new project with [name] using template [template-id] 22 | echo list-templates Print all available template names 23 | echo help Print this message 24 | echo. 25 | echo Options: 26 | echo -jvm-debug [port] Turn on JVM debugging, open at the given port. Defaults to 9999 if no port given. 27 | echo. 28 | echo Environment variables ^(read from context^): 29 | echo JAVA_OPTS Environment variable, if unset uses "" 30 | echo SBT_OPTS Environment variable, if unset uses "" 31 | echo ACTIVATOR_OPTS Environment variable, if unset uses "" 32 | echo. 33 | echo Please note that in order for Activator to work you must have Java available on the classpath 34 | echo. 35 | goto :end 36 | ) 37 | ) 38 | 39 | @REM determine ACTIVATOR_HOME environment variable 40 | set BIN_DIRECTORY=%~dp0 41 | set BIN_DIRECTORY=%BIN_DIRECTORY:~0,-1% 42 | for %%d in (%BIN_DIRECTORY%) do set ACTIVATOR_HOME=%%~dpd 43 | set ACTIVATOR_HOME=%ACTIVATOR_HOME:~0,-1% 44 | 45 | echo ACTIVATOR_HOME=%ACTIVATOR_HOME% 46 | 47 | set ERROR_CODE=0 48 | set APP_VERSION=1.3.10 49 | set ACTIVATOR_LAUNCH_JAR=activator-launch-%APP_VERSION%.jar 50 | 51 | rem Detect if we were double clicked, although theoretically A user could 52 | rem manually run cmd /c 53 | for %%x in (%cmdcmdline%) do if %%~x==/c set DOUBLECLICKED=1 54 | 55 | set SBT_HOME=%BIN_DIRECTORY 56 | 57 | rem Detect if we were double clicked, although theoretically A user could 58 | rem manually run cmd /c 59 | for %%x in (%cmdcmdline%) do if %%~x==/c set DOUBLECLICKED=1 60 | 61 | rem FIRST we load the config file of extra options. 62 | set FN=%SBT_HOME%\..\conf\sbtconfig.txt 63 | set CFG_OPTS= 64 | FOR /F "tokens=* eol=# usebackq delims=" %%i IN ("%FN%") DO ( 65 | set DO_NOT_REUSE_ME=%%i 66 | rem ZOMG (Part #2) WE use !! here to delay the expansion of 67 | rem CFG_OPTS, otherwise it remains "" for this loop. 68 | set CFG_OPTS=!CFG_OPTS! !DO_NOT_REUSE_ME! 69 | ) 70 | 71 | rem FIRST we load a config file of extra options (if there is one) 72 | set "CFG_FILE_HOME=%UserProfile%\.activator\activatorconfig.txt" 73 | set "CFG_FILE_VERSION=%UserProfile%\.activator\%APP_VERSION%\activatorconfig.txt" 74 | if exist %CFG_FILE_VERSION% ( 75 | FOR /F "tokens=* eol=# usebackq delims=" %%i IN ("%CFG_FILE_VERSION%") DO ( 76 | set DO_NOT_REUSE_ME=%%i 77 | rem ZOMG (Part #2) WE use !! here to delay the expansion of 78 | rem CFG_OPTS, otherwise it remains "" for this loop. 79 | set CFG_OPTS=!CFG_OPTS! !DO_NOT_REUSE_ME! 80 | ) 81 | ) 82 | if "%CFG_OPTS%"=="" ( 83 | if exist %CFG_FILE_HOME% ( 84 | FOR /F "tokens=* eol=# usebackq delims=" %%i IN ("%CFG_FILE_HOME%") DO ( 85 | set DO_NOT_REUSE_ME=%%i 86 | rem ZOMG (Part #2) WE use !! here to delay the expansion of 87 | rem CFG_OPTS, otherwise it remains "" for this loop. 88 | set CFG_OPTS=!CFG_OPTS! !DO_NOT_REUSE_ME! 89 | ) 90 | ) 91 | ) 92 | 93 | rem We use the value of the JAVACMD environment variable if defined 94 | set _JAVACMD=%JAVACMD% 95 | 96 | if "%_JAVACMD%"=="" ( 97 | if not "%JAVA_HOME%"=="" ( 98 | if exist "%JAVA_HOME%\bin\java.exe" set "_JAVACMD=%JAVA_HOME%\bin\java.exe" 99 | 100 | rem if there is a java home set we make sure it is the first picked up when invoking 'java' 101 | SET "PATH=%JAVA_HOME%\bin;%PATH%" 102 | ) 103 | ) 104 | 105 | if "%_JAVACMD%"=="" set _JAVACMD=java 106 | 107 | rem Detect if this java is ok to use. 108 | for /F %%j in ('"%_JAVACMD%" -version 2^>^&1') do ( 109 | if %%~j==java set JAVAINSTALLED=1 110 | if %%~j==openjdk set JAVAINSTALLED=1 111 | ) 112 | 113 | rem Detect the same thing about javac 114 | if "%_JAVACCMD%"=="" ( 115 | if not "%JAVA_HOME%"=="" ( 116 | if exist "%JAVA_HOME%\bin\javac.exe" set "_JAVACCMD=%JAVA_HOME%\bin\javac.exe" 117 | ) 118 | ) 119 | if "%_JAVACCMD%"=="" set _JAVACCMD=javac 120 | for /F %%j in ('"%_JAVACCMD%" -version 2^>^&1') do ( 121 | if %%~j==javac set JAVACINSTALLED=1 122 | ) 123 | 124 | rem BAT has no logical or, so we do it OLD SCHOOL! Oppan Redmond Style 125 | set JAVAOK=true 126 | if not defined JAVAINSTALLED set JAVAOK=false 127 | if not defined JAVACINSTALLED set JAVAOK=false 128 | 129 | if "%JAVAOK%"=="false" ( 130 | echo. 131 | echo A Java JDK is not installed or can't be found. 132 | if not "%JAVA_HOME%"=="" ( 133 | echo JAVA_HOME = "%JAVA_HOME%" 134 | ) 135 | echo. 136 | echo Please go to 137 | echo http://www.oracle.com/technetwork/java/javase/downloads/index.html 138 | echo and download a valid Java JDK and install before running Activator. 139 | echo. 140 | echo If you think this message is in error, please check 141 | echo your environment variables to see if "java.exe" and "javac.exe" are 142 | echo available via JAVA_HOME or PATH. 143 | echo. 144 | if defined DOUBLECLICKED pause 145 | exit /B 1 146 | ) 147 | 148 | rem Check what Java version is being used to determine what memory options to use 149 | for /f "tokens=3" %%g in ('java -version 2^>^&1 ^| findstr /i "version"') do ( 150 | set JAVA_VERSION=%%g 151 | ) 152 | 153 | rem Strips away the " characters 154 | set JAVA_VERSION=%JAVA_VERSION:"=% 155 | 156 | rem TODO Check if there are existing mem settings in JAVA_OPTS/CFG_OPTS and use those instead of the below 157 | for /f "delims=. tokens=1-3" %%v in ("%JAVA_VERSION%") do ( 158 | set MAJOR=%%v 159 | set MINOR=%%w 160 | set BUILD=%%x 161 | 162 | set META_SIZE=-XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=256M 163 | if "!MINOR!" LSS "8" ( 164 | set META_SIZE=-XX:PermSize=64M -XX:MaxPermSize=256M 165 | ) 166 | 167 | set MEM_OPTS=!META_SIZE! 168 | ) 169 | 170 | rem We use the value of the JAVA_OPTS environment variable if defined, rather than the config. 171 | set _JAVA_OPTS=%JAVA_OPTS% 172 | if "%_JAVA_OPTS%"=="" set _JAVA_OPTS=%CFG_OPTS% 173 | 174 | set DEBUG_OPTS= 175 | 176 | rem Loop through the arguments, building remaining args in args variable 177 | set args= 178 | :argsloop 179 | if not "%~1"=="" ( 180 | rem Checks if the argument contains "-D" and if true, adds argument 1 with 2 and puts an equal sign between them. 181 | rem This is done since batch considers "=" to be a delimiter so we need to circumvent this behavior with a small hack. 182 | set arg1=%~1 183 | if "!arg1:~0,2!"=="-D" ( 184 | set "args=%args% "%~1"="%~2"" 185 | shift 186 | shift 187 | goto argsloop 188 | ) 189 | 190 | if "%~1"=="-jvm-debug" ( 191 | if not "%~2"=="" ( 192 | rem This piece of magic somehow checks that an argument is a number 193 | for /F "delims=0123456789" %%i in ("%~2") do ( 194 | set var="%%i" 195 | ) 196 | if defined var ( 197 | rem Not a number, assume no argument given and default to 9999 198 | set JPDA_PORT=9999 199 | ) else ( 200 | rem Port was given, shift arguments 201 | set JPDA_PORT=%~2 202 | shift 203 | ) 204 | ) else ( 205 | set JPDA_PORT=9999 206 | ) 207 | shift 208 | 209 | set DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=!JPDA_PORT! 210 | goto argsloop 211 | ) 212 | rem else 213 | set "args=%args% "%~1"" 214 | shift 215 | goto argsloop 216 | ) 217 | 218 | :run 219 | 220 | if "!args!"=="" ( 221 | if defined DOUBLECLICKED ( 222 | set CMDS="ui" 223 | ) else set CMDS=!args! 224 | ) else set CMDS=!args! 225 | 226 | rem We add a / in front, so we get file:///C: instead of file://C: 227 | rem Java considers the later a UNC path. 228 | rem We also attempt a solid effort at making it URI friendly. 229 | rem We don't even bother with UNC paths. 230 | set JAVA_FRIENDLY_HOME_1=/!ACTIVATOR_HOME:\=/! 231 | set JAVA_FRIENDLY_HOME=/!JAVA_FRIENDLY_HOME_1: =%%20! 232 | 233 | rem Checks if the command contains spaces to know if it should be wrapped in quotes or not 234 | set NON_SPACED_CMD=%_JAVACMD: =% 235 | if "%_JAVACMD%"=="%NON_SPACED_CMD%" %_JAVACMD% %DEBUG_OPTS% %MEM_OPTS% %ACTIVATOR_OPTS% %SBT_OPTS% %_JAVA_OPTS% "-Dactivator.home=%JAVA_FRIENDLY_HOME%" -jar "%ACTIVATOR_HOME%\libexec\%ACTIVATOR_LAUNCH_JAR%" %CMDS% 236 | if NOT "%_JAVACMD%"=="%NON_SPACED_CMD%" "%_JAVACMD%" %DEBUG_OPTS% %MEM_OPTS% %ACTIVATOR_OPTS% %SBT_OPTS% %_JAVA_OPTS% "-Dactivator.home=%JAVA_FRIENDLY_HOME%" -jar "%ACTIVATOR_HOME%\libexec\%ACTIVATOR_LAUNCH_JAR%" %CMDS% 237 | 238 | if ERRORLEVEL 1 goto error 239 | goto end 240 | 241 | :error 242 | set ERROR_CODE=1 243 | 244 | :end 245 | 246 | @endlocal 247 | 248 | exit /B %ERROR_CODE% 249 | -------------------------------------------------------------------------------- /bin/activator: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ### ------------------------------- ### 4 | ### Helper methods for BASH scripts ### 5 | ### ------------------------------- ### 6 | 7 | realpath () { 8 | ( 9 | TARGET_FILE="$1" 10 | FIX_CYGPATH="$2" 11 | 12 | cd "$(dirname "$TARGET_FILE")" 13 | TARGET_FILE=$(basename "$TARGET_FILE") 14 | 15 | COUNT=0 16 | while [ -L "$TARGET_FILE" -a $COUNT -lt 100 ] 17 | do 18 | TARGET_FILE=$(readlink "$TARGET_FILE") 19 | cd "$(dirname "$TARGET_FILE")" 20 | TARGET_FILE=$(basename "$TARGET_FILE") 21 | COUNT=$(($COUNT + 1)) 22 | done 23 | 24 | # make sure we grab the actual windows path, instead of cygwin's path. 25 | if [[ "x$FIX_CYGPATH" != "x" ]]; then 26 | echo "$(cygwinpath "$(pwd -P)/$TARGET_FILE")" 27 | else 28 | echo "$(pwd -P)/$TARGET_FILE" 29 | fi 30 | ) 31 | } 32 | 33 | 34 | # Uses uname to detect if we're in the odd cygwin environment. 35 | is_cygwin() { 36 | local os=$(uname -s) 37 | case "$os" in 38 | CYGWIN*) return 0 ;; 39 | *) return 1 ;; 40 | esac 41 | } 42 | 43 | # TODO - Use nicer bash-isms here. 44 | CYGWIN_FLAG=$(if is_cygwin; then echo true; else echo false; fi) 45 | 46 | 47 | # This can fix cygwin style /cygdrive paths so we get the 48 | # windows style paths. 49 | cygwinpath() { 50 | local file="$1" 51 | if [[ "$CYGWIN_FLAG" == "true" ]]; then 52 | echo $(cygpath -w $file) 53 | else 54 | echo $file 55 | fi 56 | } 57 | 58 | # Make something URI friendly 59 | make_url() { 60 | url="$1" 61 | local nospaces=${url// /%20} 62 | if is_cygwin; then 63 | echo "/${nospaces//\\//}" 64 | else 65 | echo "$nospaces" 66 | fi 67 | } 68 | 69 | declare -a residual_args 70 | declare -a java_args 71 | declare -a scalac_args 72 | declare -a sbt_commands 73 | declare java_cmd=java 74 | declare java_version 75 | declare -r real_script_path="$(realpath "$0")" 76 | declare -r sbt_home="$(realpath "$(dirname "$(dirname "$real_script_path")")")" 77 | declare -r sbt_bin_dir="$(dirname "$real_script_path")" 78 | declare -r app_version="1.3.10" 79 | 80 | declare -r script_name=activator 81 | declare -r java_opts=( "${ACTIVATOR_OPTS[@]}" "${SBT_OPTS[@]}" "${JAVA_OPTS[@]}" "${java_opts[@]}" ) 82 | userhome="$HOME" 83 | if is_cygwin; then 84 | # cygwin sets home to something f-d up, set to real windows homedir 85 | userhome="$USERPROFILE" 86 | fi 87 | declare -r activator_user_home_dir="${userhome}/.activator" 88 | declare -r java_opts_config_home="${activator_user_home_dir}/activatorconfig.txt" 89 | declare -r java_opts_config_version="${activator_user_home_dir}/${app_version}/activatorconfig.txt" 90 | 91 | echoerr () { 92 | echo 1>&2 "$@" 93 | } 94 | vlog () { 95 | [[ $verbose || $debug ]] && echoerr "$@" 96 | } 97 | dlog () { 98 | [[ $debug ]] && echoerr "$@" 99 | } 100 | 101 | jar_file () { 102 | echo "$(cygwinpath "${sbt_home}/libexec/activator-launch-${app_version}.jar")" 103 | } 104 | 105 | acquire_sbt_jar () { 106 | sbt_jar="$(jar_file)" 107 | 108 | if [[ ! -f "$sbt_jar" ]]; then 109 | echoerr "Could not find launcher jar: $sbt_jar" 110 | exit 2 111 | fi 112 | } 113 | 114 | execRunner () { 115 | # print the arguments one to a line, quoting any containing spaces 116 | [[ $verbose || $debug ]] && echo "# Executing command line:" && { 117 | for arg; do 118 | if printf "%s\n" "$arg" | grep -q ' '; then 119 | printf "\"%s\"\n" "$arg" 120 | else 121 | printf "%s\n" "$arg" 122 | fi 123 | done 124 | echo "" 125 | } 126 | 127 | # THis used to be exec, but we loose the ability to re-hook stty then 128 | # for cygwin... Maybe we should flag the feature here... 129 | "$@" 130 | } 131 | 132 | addJava () { 133 | dlog "[addJava] arg = '$1'" 134 | java_args=( "${java_args[@]}" "$1" ) 135 | } 136 | addSbt () { 137 | dlog "[addSbt] arg = '$1'" 138 | sbt_commands=( "${sbt_commands[@]}" "$1" ) 139 | } 140 | addResidual () { 141 | dlog "[residual] arg = '$1'" 142 | residual_args=( "${residual_args[@]}" "$1" ) 143 | } 144 | addDebugger () { 145 | addJava "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$1" 146 | } 147 | 148 | get_mem_opts () { 149 | # if we detect any of these settings in ${JAVA_OPTS} we need to NOT output our settings. 150 | # The reason is the Xms/Xmx, if they don't line up, cause errors. 151 | if [[ "${JAVA_OPTS}" == *-Xmx* ]] || [[ "${JAVA_OPTS}" == *-Xms* ]] || [[ "${JAVA_OPTS}" == *-XX:MaxPermSize* ]] || [[ "${JAVA_OPTS}" == *-XX:MaxMetaspaceSize* ]] || [[ "${JAVA_OPTS}" == *-XX:ReservedCodeCacheSize* ]]; then 152 | echo "" 153 | else 154 | # a ham-fisted attempt to move some memory settings in concert 155 | # so they need not be messed around with individually. 156 | local mem=${1:-1024} 157 | local codecache=$(( $mem / 8 )) 158 | (( $codecache > 128 )) || codecache=128 159 | (( $codecache < 512 )) || codecache=512 160 | local class_metadata_size=$(( $codecache * 2 )) 161 | local class_metadata_opt=$([[ "$java_version" < "1.8" ]] && echo "MaxPermSize" || echo "MaxMetaspaceSize") 162 | 163 | echo "-Xms${mem}m -Xmx${mem}m -XX:ReservedCodeCacheSize=${codecache}m -XX:${class_metadata_opt}=${class_metadata_size}m" 164 | fi 165 | } 166 | 167 | require_arg () { 168 | local type="$1" 169 | local opt="$2" 170 | local arg="$3" 171 | if [[ -z "$arg" ]] || [[ "${arg:0:1}" == "-" ]]; then 172 | echo "$opt requires <$type> argument" 173 | exit 1 174 | fi 175 | } 176 | 177 | is_function_defined() { 178 | declare -f "$1" > /dev/null 179 | } 180 | 181 | # If we're *not* running in a terminal, and we don't have any arguments, then we need to add the 'ui' parameter 182 | detect_terminal_for_ui() { 183 | [[ ! -t 0 ]] && [[ "${#residual_args}" == "0" ]] && { 184 | addResidual "ui" 185 | } 186 | # SPECIAL TEST FOR MAC 187 | [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]] && [[ "${#residual_args}" == "0" ]] && { 188 | echo "Detected MAC OSX launched script...." 189 | echo "Swapping to UI" 190 | addResidual "ui" 191 | } 192 | } 193 | 194 | process_args () { 195 | while [[ $# -gt 0 ]]; do 196 | case "$1" in 197 | -h|-help) usage; exit 1 ;; 198 | -v|-verbose) verbose=1 && shift ;; 199 | -d|-debug) debug=1 && shift ;; 200 | 201 | -ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;; 202 | -mem) require_arg integer "$1" "$2" && sbt_mem="$2" && shift 2 ;; 203 | -jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;; 204 | -batch) exec &1 | awk -F '"' '/version/ {print $2}') 223 | vlog "[process_args] java_version = '$java_version'" 224 | } 225 | 226 | # Detect that we have java installed. 227 | checkJava() { 228 | local required_version="$1" 229 | # Now check to see if it's a good enough version 230 | if [[ "$java_version" == "" ]]; then 231 | echo 232 | echo No java installations was detected. 233 | echo Please go to http://www.java.com/getjava/ and download 234 | echo 235 | exit 1 236 | elif [[ ! "$java_version" > "$required_version" ]]; then 237 | echo 238 | echo The java installation you have is not up to date 239 | echo $script_name requires at least version $required_version+, you have 240 | echo version $java_version 241 | echo 242 | echo Please go to http://www.java.com/getjava/ and download 243 | echo a valid Java Runtime and install before running $script_name. 244 | echo 245 | exit 1 246 | fi 247 | } 248 | 249 | 250 | run() { 251 | # no jar? download it. 252 | [[ -f "$sbt_jar" ]] || acquire_sbt_jar "$sbt_version" || { 253 | # still no jar? uh-oh. 254 | echo "Download failed. Obtain the sbt-launch.jar manually and place it at $sbt_jar" 255 | exit 1 256 | } 257 | 258 | # process the combined args, then reset "$@" to the residuals 259 | process_args "$@" 260 | detect_terminal_for_ui 261 | set -- "${residual_args[@]}" 262 | argumentCount=$# 263 | 264 | # TODO - java check should be configurable... 265 | checkJava "1.6" 266 | 267 | #If we're in cygwin, we should use the windows config, and terminal hacks 268 | if [[ "$CYGWIN_FLAG" == "true" ]]; then 269 | stty -icanon min 1 -echo > /dev/null 2>&1 270 | addJava "-Djline.terminal=jline.UnixTerminal" 271 | addJava "-Dsbt.cygwin=true" 272 | fi 273 | 274 | # run sbt 275 | execRunner "$java_cmd" \ 276 | "-Dactivator.home=$(make_url "$sbt_home")" \ 277 | ${SBT_OPTS:-$default_sbt_opts} \ 278 | $(get_mem_opts $sbt_mem) \ 279 | ${JAVA_OPTS} \ 280 | ${java_args[@]} \ 281 | -jar "$sbt_jar" \ 282 | "${sbt_commands[@]}" \ 283 | "${residual_args[@]}" 284 | 285 | exit_code=$? 286 | 287 | # Clean up the terminal from cygwin hacks. 288 | if [[ "$CYGWIN_FLAG" == "true" ]]; then 289 | stty icanon echo > /dev/null 2>&1 290 | fi 291 | exit $exit_code 292 | } 293 | 294 | 295 | declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy" 296 | declare -r sbt_opts_file=".sbtopts" 297 | declare -r etc_sbt_opts_file="${sbt_home}/conf/sbtopts" 298 | declare -r win_sbt_opts_file="${sbt_home}/conf/sbtconfig.txt" 299 | 300 | usage() { 301 | cat < path to global settings/plugins directory (default: ~/.sbt) 316 | -sbt-boot path to shared boot directory (default: ~/.sbt/boot in 0.11 series) 317 | -ivy path to local Ivy repository (default: ~/.ivy2) 318 | -mem set memory options (default: $sbt_mem, which is $(get_mem_opts $sbt_mem)) 319 | -no-share use all local caches; no sharing 320 | -no-global uses global caches, but does not use global ~/.sbt directory. 321 | -jvm-debug Turn on JVM debugging, open at the given port. 322 | -batch Disable interactive mode 323 | 324 | # sbt version (default: from project/build.properties if present, else latest release) 325 | -sbt-version use the specified version of sbt 326 | -sbt-jar use the specified jar as the sbt launcher 327 | -sbt-rc use an RC version of sbt 328 | -sbt-snapshot use a snapshot version of sbt 329 | 330 | # java version (default: java from PATH, currently $(java -version 2>&1 | grep version)) 331 | -java-home alternate JAVA_HOME 332 | 333 | # jvm options and output control 334 | JAVA_OPTS environment variable, if unset uses "$java_opts" 335 | SBT_OPTS environment variable, if unset uses "$default_sbt_opts" 336 | ACTIVATOR_OPTS Environment variable, if unset uses "" 337 | .sbtopts if this file exists in the current directory, it is 338 | prepended to the runner args 339 | /etc/sbt/sbtopts if this file exists, it is prepended to the runner args 340 | -Dkey=val pass -Dkey=val directly to the java runtime 341 | -J-X pass option -X directly to the java runtime 342 | (-J is stripped) 343 | -S-X add -X to sbt's scalacOptions (-S is stripped) 344 | 345 | In the case of duplicated or conflicting options, the order above 346 | shows precedence: JAVA_OPTS lowest, command line options highest. 347 | EOM 348 | } 349 | 350 | 351 | 352 | process_my_args () { 353 | while [[ $# -gt 0 ]]; do 354 | case "$1" in 355 | -no-colors) addJava "-Dsbt.log.noformat=true" && shift ;; 356 | -no-share) addJava "$noshare_opts" && shift ;; 357 | -no-global) addJava "-Dsbt.global.base=$(pwd)/project/.sbtboot" && shift ;; 358 | -sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;; 359 | -sbt-dir) require_arg path "$1" "$2" && addJava "-Dsbt.global.base=$2" && shift 2 ;; 360 | -debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;; 361 | -batch) exec