├── .java-version
├── project
├── assembly.sbt
└── build.properties
├── .travis.yml
├── libexec
└── activator-launch-1.3.10.jar
├── src
└── main
│ ├── resources
│ └── application.conf
│ └── java
│ └── com
│ └── ferhtaydn
│ └── akkahttpjavaclient
│ ├── models
│ ├── GeoPosition.java
│ ├── CsvCity.java
│ └── City.java
│ ├── client
│ ├── settings
│ │ ├── SettingsImpl.java
│ │ └── Settings.java
│ ├── ClientApp.java
│ └── AkkaHttpJavaClient.java
│ ├── helpers
│ └── CsvHelper.java
│ └── GoEuroTest.java
├── .gitignore
├── tutorial
└── index.html
├── activator.properties
├── README.md
├── bin
├── activator.bat
└── activator
└── LICENSE
/.java-version:
--------------------------------------------------------------------------------
1 | 1.8
2 |
--------------------------------------------------------------------------------
/project/assembly.sbt:
--------------------------------------------------------------------------------
1 | addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.3")
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: scala
2 | jdk:
3 | - oraclejdk8
4 | scala:
5 | - 2.11.8
6 |
7 |
--------------------------------------------------------------------------------
/libexec/activator-launch-1.3.10.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ferhtaydn/akka-http-java-client/HEAD/libexec/activator-launch-1.3.10.jar
--------------------------------------------------------------------------------
/project/build.properties:
--------------------------------------------------------------------------------
1 | #Activator-generated Properties
2 | #Mon Jun 27 22:58:54 EEST 2016
3 | template.uuid=9cbaa284-7f8c-4ef2-b48e-fc3ee73a11eb
4 | sbt.version=0.13.8
5 |
--------------------------------------------------------------------------------
/src/main/resources/application.conf:
--------------------------------------------------------------------------------
1 | akka {
2 | loglevel: INFO
3 | }
4 |
5 | http {
6 | host = "api.goeuro.com"
7 | port = 80
8 | uri = "http://api.goeuro.com/api/v2/position/suggest/en/"
9 |
10 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | logs
2 | projectFilesBackup
3 | version.properties
4 | project/project
5 | project/target
6 | target
7 | tmp
8 | .history
9 | dist
10 | /.idea
11 | /*.iml
12 | /out
13 | /.idea_modules
14 | /.classpath
15 | /.project
16 | /RUNNING_PID
17 | /.settings
18 | app/*/.DS_Store
19 | .DS_Store
20 |
--------------------------------------------------------------------------------
/tutorial/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Akka HTTP Java Client
5 |
6 |
7 |
8 |
Akka HTTP Java8 Client Examples
9 |
This project shows how akka-http client examples can be used by simple examples.
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/activator.properties:
--------------------------------------------------------------------------------
1 | name=akka-http-java8-client
2 | title=Example Project to use Akka HTTP as a http client with java8.
3 | description=A java8 seed project with akka-http client. HostLevel, ConnectionLevel and RequestLevel client examples.
4 | tags=akka-http, client, java8, java, seed
5 | authorName=Ferhat Aydın
6 | authorLink=gıthub.com/ferhtaydn
7 | authorTwitter=@ferhtaydn
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | #### akka-http based simple Java http client.
3 |
4 | ##### Simple akka-http client level examples:
5 | * hostLevel
6 | * connectionLevel
7 | * requestLevel
8 |
9 | ##### Simple endpoint of GoEuro is used
10 | * the response json is written to a csv file.
11 | * settings are read from application.conf
12 | * jar can be created with:
13 |
14 | ```sh
15 | sbt assembly
16 | ```
17 | * jar can be called with:
18 |
19 | ```sh
20 | java -jar target/scala-2.11/GoEuroTest.jar Berlin
21 | ```
22 |
--------------------------------------------------------------------------------
/src/main/java/com/ferhtaydn/akkahttpjavaclient/models/GeoPosition.java:
--------------------------------------------------------------------------------
1 | package com.ferhtaydn.akkahttpjavaclient.models;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 |
5 | public final class GeoPosition {
6 |
7 | @JsonProperty("latitude")
8 | private Double latitude;
9 | @JsonProperty("longitude")
10 | private Double longitude;
11 |
12 | public Double getLatitude() {
13 | return latitude;
14 | }
15 |
16 | public Double getLongitude() {
17 | return longitude;
18 | }
19 | }
--------------------------------------------------------------------------------
/src/main/java/com/ferhtaydn/akkahttpjavaclient/client/settings/SettingsImpl.java:
--------------------------------------------------------------------------------
1 | package com.ferhtaydn.akkahttpjavaclient.client.settings;
2 |
3 | import akka.actor.Extension;
4 | import com.typesafe.config.Config;
5 |
6 | public class SettingsImpl implements Extension {
7 |
8 | public final String URI;
9 | public final String HOST;
10 | public final int PORT;
11 |
12 | public SettingsImpl(Config config) {
13 | URI = config.getString("http.uri");
14 | HOST = config.getString("http.host");
15 | PORT = config.getInt("http.port");
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/ferhtaydn/akkahttpjavaclient/client/settings/Settings.java:
--------------------------------------------------------------------------------
1 | package com.ferhtaydn.akkahttpjavaclient.client.settings;
2 |
3 | import akka.actor.AbstractExtensionId;
4 | import akka.actor.ExtendedActorSystem;
5 | import akka.actor.ExtensionIdProvider;
6 |
7 | public class Settings extends AbstractExtensionId implements ExtensionIdProvider {
8 |
9 | public final static Settings SettingsProvider = new Settings();
10 |
11 | private Settings() {}
12 |
13 | public Settings lookup() {
14 | return Settings.SettingsProvider;
15 | }
16 |
17 | public SettingsImpl createExtension(ExtendedActorSystem system) {
18 | return new SettingsImpl(system.settings().config());
19 | }
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/src/main/java/com/ferhtaydn/akkahttpjavaclient/helpers/CsvHelper.java:
--------------------------------------------------------------------------------
1 | package com.ferhtaydn.akkahttpjavaclient.helpers;
2 |
3 | import com.fasterxml.jackson.databind.ObjectWriter;
4 | import com.fasterxml.jackson.dataformat.csv.CsvMapper;
5 | import com.fasterxml.jackson.dataformat.csv.CsvSchema;
6 | import com.ferhtaydn.akkahttpjavaclient.models.City;
7 | import com.ferhtaydn.akkahttpjavaclient.models.CsvCity;
8 |
9 | import java.io.File;
10 | import java.io.IOException;
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | public class CsvHelper {
15 |
16 | private static CsvMapper mapper = new CsvMapper();
17 | private static final String CSV_EXTENSION = ".csv";
18 | private static CsvSchema schema = mapper.schemaFor(CsvCity.class).withHeader();
19 | private static ObjectWriter writer = mapper.writer(schema.withLineSeparator("\n"));
20 |
21 | public void writeToCSV(List objects, String fileName) {
22 |
23 | ArrayList csvCities = new ArrayList<>();
24 | for (City c : objects) {
25 | csvCities.add(new CsvCity(c.getId(), c.getName(), c.getType(), c.getLatitude(), c.getLongitude()));
26 | }
27 |
28 | try {
29 | writer.writeValue(new File(fileName.concat(CSV_EXTENSION)), csvCities);
30 | } catch (IOException e) {
31 | e.printStackTrace();
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/ferhtaydn/akkahttpjavaclient/models/CsvCity.java:
--------------------------------------------------------------------------------
1 | package com.ferhtaydn.akkahttpjavaclient.models;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 | import com.fasterxml.jackson.annotation.JsonProperty;
5 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
6 |
7 | @JsonIgnoreProperties(ignoreUnknown = true)
8 | @JsonPropertyOrder(value = { "_id", "name", "type", "latitude", "longitude" })
9 | public final class CsvCity {
10 |
11 | @JsonProperty("_id")
12 | private Long id;
13 | @JsonProperty("name")
14 | private String name;
15 | @JsonProperty("type")
16 | private String type;
17 | @JsonProperty("latitude")
18 | private Double latitude;
19 | @JsonProperty("longitude")
20 | private Double longitude;
21 |
22 | public CsvCity(Long id, String name, String type, Double latitude, Double longitude) {
23 | this.id = id;
24 | this.name = name;
25 | this.type = type;
26 | this.latitude = latitude;
27 | this.longitude = longitude;
28 | }
29 |
30 | public Long getId() {
31 | return id;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | public String getType() {
39 | return type;
40 | }
41 |
42 | public Double getLatitude() {
43 | return latitude;
44 | }
45 |
46 | public Double getLongitude() {
47 | return longitude;
48 | }
49 |
50 |
51 | }
--------------------------------------------------------------------------------
/src/main/java/com/ferhtaydn/akkahttpjavaclient/GoEuroTest.java:
--------------------------------------------------------------------------------
1 | package com.ferhtaydn.akkahttpjavaclient;
2 |
3 | import akka.actor.ActorSystem;
4 | import akka.http.javadsl.marshallers.jackson.Jackson;
5 | import akka.stream.ActorMaterializer;
6 | import com.ferhtaydn.akkahttpjavaclient.client.AkkaHttpJavaClient;
7 | import com.ferhtaydn.akkahttpjavaclient.helpers.CsvHelper;
8 | import com.ferhtaydn.akkahttpjavaclient.models.City;
9 |
10 | import java.util.Arrays;
11 | import java.util.Optional;
12 |
13 | public class GoEuroTest {
14 |
15 | public static void main(String[] args) {
16 |
17 | ActorSystem actorSystem = ActorSystem.create("client");
18 |
19 | AkkaHttpJavaClient client = new AkkaHttpJavaClient(actorSystem, ActorMaterializer.create(actorSystem));
20 |
21 | if (args.length == 0) {
22 | System.err.println("Enter a city name!");
23 | System.exit(0);
24 | } else {
25 | String cityName = args[0];
26 | System.out.println(cityName);
27 | if (cityName != null && !cityName.isEmpty()) {
28 | client.requestLevelFutureBased(Optional.of(cityName), success ->
29 | Jackson.unmarshaller(City[].class)
30 | .unmarshall(success.entity(),
31 | client.getSystem().dispatcher(),
32 | client.getMaterializer())
33 | .thenApply(Arrays::asList))
34 | .thenAccept(cities -> new CsvHelper().writeToCSV(cities, cityName))
35 | .whenComplete((success, throwable) -> client.close());
36 | } else {
37 | System.err.println("Enter a city name!");
38 | System.exit(0);
39 | }
40 | }
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/ferhtaydn/akkahttpjavaclient/client/ClientApp.java:
--------------------------------------------------------------------------------
1 | package com.ferhtaydn.akkahttpjavaclient.client;
2 |
3 | import akka.NotUsed;
4 | import akka.actor.ActorSystem;
5 | import akka.http.javadsl.marshallers.jackson.Jackson;
6 | import akka.stream.ActorMaterializer;
7 | import akka.util.ByteString;
8 | import com.ferhtaydn.akkahttpjavaclient.helpers.CsvHelper;
9 | import com.ferhtaydn.akkahttpjavaclient.models.City;
10 |
11 | import java.util.Arrays;
12 | import java.util.Optional;
13 |
14 | public class ClientApp {
15 |
16 | public static void main(String[] args) {
17 |
18 | ActorSystem actorSystem = ActorSystem.create("client");
19 | ActorSystem actorSystemCsv = ActorSystem.create("clientCsv");
20 |
21 | AkkaHttpJavaClient client = new AkkaHttpJavaClient(actorSystem, ActorMaterializer.create(actorSystem));
22 | AkkaHttpJavaClient clientCsv = new AkkaHttpJavaClient(actorSystemCsv, ActorMaterializer.create(actorSystemCsv));
23 |
24 | System.out.println("request level: ");
25 | clientCsv.requestLevelFutureBased(Optional.of("Paris"), success ->
26 | Jackson.unmarshaller(City[].class)
27 | .unmarshall(success.entity(),
28 | clientCsv.getSystem().dispatcher(),
29 | clientCsv.getMaterializer())
30 | .thenApply(Arrays::asList))
31 | .thenAccept(cities -> new CsvHelper().writeToCSV(cities, "Paris"))
32 | .whenComplete((success, throwable) -> clientCsv.close());
33 |
34 |
35 | System.out.println("connection level: ");
36 | client.connectionLevel(Optional.of("NewYork"), success ->
37 | success.entity()
38 | .getDataBytes()
39 | .runForeach(byteString -> System.out.println("Result: " + byteString.utf8String()),
40 | client.getMaterializer())
41 | ).whenComplete((success, throwable) -> client.close());
42 |
43 |
44 | System.out.println("host level: ");
45 | client.hostLevel(Optional.of("Istanbul"), success ->
46 | success.first().get().entity()
47 | .getDataBytes()
48 | .runFold(ByteString.empty(), ByteString::concat, client.getMaterializer())
49 | .handle((byteString, f) -> {
50 | if (f != null) {
51 | System.err.println("Failure when handle the HttpEntity: " + f.getMessage());
52 | } else {
53 | System.out.println("Result: " + byteString.utf8String());
54 | }
55 | return NotUsed.getInstance();
56 | })
57 | ).whenComplete((success, throwable) -> client.close());
58 | }
59 | }
--------------------------------------------------------------------------------
/src/main/java/com/ferhtaydn/akkahttpjavaclient/client/AkkaHttpJavaClient.java:
--------------------------------------------------------------------------------
1 | package com.ferhtaydn.akkahttpjavaclient.client;
2 |
3 | import akka.actor.ActorSystem;
4 | import akka.http.javadsl.ConnectHttp;
5 | import akka.http.javadsl.HostConnectionPool;
6 | import akka.http.javadsl.Http;
7 | import akka.http.javadsl.OutgoingConnection;
8 | import akka.http.javadsl.model.*;
9 | import akka.japi.Pair;
10 | import akka.stream.Materializer;
11 | import akka.stream.javadsl.Flow;
12 | import akka.stream.javadsl.Sink;
13 | import akka.stream.javadsl.Source;
14 |
15 | import com.ferhtaydn.akkahttpjavaclient.client.settings.Settings;
16 | import com.ferhtaydn.akkahttpjavaclient.client.settings.SettingsImpl;
17 | import scala.util.Try;
18 |
19 | import java.util.Optional;
20 | import java.util.concurrent.CompletionStage;
21 | import java.util.function.Function;
22 |
23 | public class AkkaHttpJavaClient {
24 |
25 | private final ActorSystem system;
26 | private final Materializer materializer;
27 | private final SettingsImpl settings;
28 | private final Flow> connectionFlow;
29 | private final Flow, Pair, Integer>, HostConnectionPool> poolClientFlow;
30 |
31 | public AkkaHttpJavaClient(ActorSystem sys, Materializer mat) {
32 | system = sys;
33 | materializer = mat;
34 | settings = Settings.SettingsProvider.get(system);
35 | connectionFlow = Http.get(system).outgoingConnection(ConnectHttp.toHost(settings.HOST, settings.PORT));
36 | poolClientFlow = Http.get(system).cachedHostConnectionPool(ConnectHttp.toHost(settings.HOST, settings.PORT), materializer);
37 | }
38 |
39 | public ActorSystem getSystem() {
40 | return system;
41 | }
42 |
43 | public Materializer getMaterializer() {
44 | return materializer;
45 | }
46 |
47 | public void close() {
48 | System.out.println("Shutting down client");
49 | Http.get(system).shutdownAllConnectionPools().whenComplete((s, f) -> system.terminate());
50 | }
51 |
52 | private Uri getUri(Optional s) {
53 | return Uri.create(settings.URI + s.orElse("").replace(" ", "%20"));
54 | }
55 |
56 | public CompletionStage connectionLevel(Optional s,
57 | Function> responseHandler) {
58 | return Source.single(HttpRequest.create().withUri(getUri(s)))
59 | .via(connectionFlow)
60 | .runWith(Sink.head(), materializer)
61 | .thenComposeAsync(responseHandler);
62 | }
63 |
64 | public CompletionStage hostLevel(Optional s,
65 | Function, Integer>, CompletionStage> responseHandler) {
66 | return Source.single(Pair.create(HttpRequest.create().withUri(getUri(s)), 42))
67 | .via(poolClientFlow)
68 | .runWith(Sink.head(), materializer)
69 | .thenComposeAsync(responseHandler);
70 | }
71 |
72 | public CompletionStage requestLevelFutureBased(Optional s,
73 | Function> responseHandler) {
74 | return Http.get(system)
75 | .singleRequest(HttpRequest.create().withUri(getUri(s)), materializer)
76 | .thenComposeAsync(responseHandler);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/com/ferhtaydn/akkahttpjavaclient/models/City.java:
--------------------------------------------------------------------------------
1 | package com.ferhtaydn.akkahttpjavaclient.models;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 | import com.fasterxml.jackson.annotation.JsonProperty;
5 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
6 |
7 | import java.util.Map;
8 |
9 | /**
10 | *
11 | {
12 | "_id": 407183,
13 | "key": null,
14 | "name": "Istanbul",
15 | "fullName": "Istanbul, Turkey",
16 | "iata_airport_code": null,
17 | "type": "location",
18 | "country": "Turkey",
19 | "geo_position": {
20 | "latitude": 41.01384,
21 | "longitude": 28.94966
22 | },
23 | "locationId": 39417,
24 | "inEurope": false,
25 | "countryId": 217,
26 | "countryCode": "TR",
27 | "coreCountry": false,
28 | "distance": null,
29 | "names": {
30 | "it": "Istanbul",
31 | "es": "Estambul",
32 | "tr": "İstanbul",
33 | "pl": "Stambuł",
34 | "pt": "Istambul",
35 | "fr": "Istanbul",
36 | "ru": "Стамбул",
37 | "is": "Istanbúl",
38 | "de": "Istanbul",
39 | "en": "Istanbul",
40 | "ca": "Istanbul",
41 | "nl": "Istanbul"
42 | },
43 | "alternativeNames": {}
44 | }
45 | *
46 | */
47 | @JsonIgnoreProperties(ignoreUnknown = true)
48 | @JsonPropertyOrder(value = { "_id", "name", "type", "latitude", "longitude" })
49 | public final class City {
50 |
51 | @JsonProperty("_id")
52 | private Long id;
53 | @JsonProperty("key")
54 | private String key;
55 | @JsonProperty("name")
56 | private String name;
57 | @JsonProperty("fullName")
58 | private String fullName;
59 | @JsonProperty("iata_airport_code")
60 | private String iataAirPortCode;
61 | @JsonProperty("type")
62 | private String type;
63 | @JsonProperty("country")
64 | private String country;
65 | @JsonProperty("geo_position")
66 | private GeoPosition geoPosition;
67 | @JsonProperty("locationId")
68 | private Long locationId;
69 | @JsonProperty("inEurope")
70 | private Boolean inEurope;
71 | @JsonProperty("countryId")
72 | private Long countryId;
73 | @JsonProperty("countryCode")
74 | private String countryCode;
75 | @JsonProperty("coreCountry")
76 | private Boolean coreCountry;
77 | @JsonProperty("distance")
78 | private String distance;
79 | @JsonProperty("names")
80 | private Map names;
81 | @JsonProperty("alternativeNames")
82 | private Map alternativeNames;
83 |
84 | public Double getLatitude() {
85 | return getGeoPosition().getLatitude();
86 | }
87 |
88 | public Double getLongitude() {
89 | return getGeoPosition().getLongitude();
90 | }
91 |
92 | @Override
93 | public String toString() {
94 | return String.format("%d,%s,%s,%f,%f", id, name, type, getLatitude(), getLongitude());
95 | }
96 |
97 | public Long getId() {
98 | return id;
99 | }
100 |
101 | public String getKey() {
102 | return key;
103 | }
104 |
105 | public String getName() {
106 | return name;
107 | }
108 |
109 | public String getFullName() {
110 | return fullName;
111 | }
112 |
113 | public String getIataAirPortCode() {
114 | return iataAirPortCode;
115 | }
116 |
117 | public String getType() {
118 | return type;
119 | }
120 |
121 | public String getCountry() {
122 | return country;
123 | }
124 |
125 | public GeoPosition getGeoPosition() {
126 | return geoPosition;
127 | }
128 |
129 | public Long getLocationId() {
130 | return locationId;
131 | }
132 |
133 | public Boolean isInEurope() {
134 | return inEurope;
135 | }
136 |
137 | public Long getCountryId() {
138 | return countryId;
139 | }
140 |
141 | public String getCountryCode() {
142 | return countryCode;
143 | }
144 |
145 | public Boolean isCoreCountry() {
146 | return coreCountry;
147 | }
148 |
149 | public String getDistance() {
150 | return distance;
151 | }
152 |
153 | public Map getNames() {
154 | return names;
155 | }
156 |
157 | public Map getAlternativeNames() {
158 | return alternativeNames;
159 | }
160 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/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