This repository was archived by the owner on Jan 6, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
src/main/kotlin/de/debuglevel/sparkutils/port Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11buildscript {
2- ext. kotlin_version = ' 1.2.41 '
2+ ext. kotlin_version = ' 1.2.50 '
33
44 repositories {
5- mavenCentral ()
5+ jcenter ()
66 }
77 dependencies {
88 classpath " org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version "
99 }
1010}
1111
1212plugins {
13- id ' java'
13+ id ' java-library'
14+ id ' org.jetbrains.kotlin.jvm' version " 1.2.50"
15+ }
16+
17+ compileKotlin {
18+ kotlinOptions. jvmTarget = " 1.8"
19+ }
20+ compileTestKotlin {
21+ kotlinOptions. jvmTarget = " 1.8"
1422}
1523
1624group ' de.debuglevel.sparkutils'
1725version ' 0.0.1-SNAPSHOT'
1826
19- apply plugin : ' kotlin'
20-
2127sourceCompatibility = 1.8
2228
2329repositories {
24- mavenCentral ()
30+ jcenter ()
2531}
2632
2733dependencies {
28- compile " org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version "
29- testCompile group : ' junit' , name : ' junit' , version : ' 4.12'
30- }
34+ implementation " org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version "
3135
32- compileKotlin {
33- kotlinOptions. jvmTarget = " 1.8"
36+ // Tests
37+ testImplementation ' org.junit.jupiter:junit-jupiter-api:5.2.0'
38+ testRuntime ' org.junit.jupiter:junit-jupiter-engine:5.2.0'
39+ testImplementation ' org.junit.jupiter:junit-jupiter-params:5.2.0'
40+ testImplementation ' org.assertj:assertj-core:3.10.0'
41+
42+ // Logging
43+ implementation ' io.github.microutils:kotlin-logging:1.4.9'
44+ // compile 'org.slf4j:slf4j-api:1.7.5'
45+ // compile 'org.slf4j:slf4j-simple:1.7.5'
46+
47+ // Spark (REST Server)
48+ compileOnly ' com.sparkjava:spark-kotlin:1.0.0-alpha'
3449}
35- compileTestKotlin {
36- kotlinOptions. jvmTarget = " 1.8"
37- }
50+
51+ // test {
52+ // useJUnitPlatform()
53+ //
54+ // testLogging {
55+ // events "passed", "skipped", "failed"
56+ // }
57+ //
58+ // reports {
59+ // html.enabled = true
60+ // }
61+ // }
Original file line number Diff line number Diff line change 1+ # Sat Jun 16 17:57:44 CEST 2018
12distributionBase =GRADLE_USER_HOME
23distributionPath =wrapper/dists
34zipStoreBase =GRADLE_USER_HOME
45zipStorePath =wrapper/dists
5- distributionUrl =https\://services.gradle.org/distributions/gradle-4.4-bin .zip
6+ distributionUrl =https\://services.gradle.org/distributions/gradle-4.4-all .zip
Original file line number Diff line number Diff line change 1+ package de.debuglevel.microservices.spark
2+
3+ import mu.KotlinLogging
4+ import spark.kotlin.port
5+
6+ private val logger = KotlinLogging .logger {}
7+
8+ /* *
9+ * Gets the value of the PORT environment variable, or 4567 if no such environment variable is set.
10+ *
11+ * @return value of the PORT environment variable, or 4567 if no such environment variable is set.
12+ */
13+ private fun getEnvironmentPort (): Int {
14+ // TODO: add more options to figure out a port configuration
15+
16+ val processBuilder = ProcessBuilder ()
17+ return if (processBuilder.environment()[" PORT" ] != null ) {
18+ Integer .parseInt(processBuilder.environment()[" PORT" ])
19+ } else {
20+ 4567
21+ }
22+ }
23+
24+ /* *
25+ * Sets the port to a configured port.
26+ *
27+ * Currently, only the environment variable "PORT" is evaluated.
28+ */
29+ fun configuredPort () {
30+ // TODO: Spark fails silently if port is already taken. There should be thrown an exception
31+
32+ val port = getEnvironmentPort()
33+ logger.info(" Setting port to $port ..." )
34+ port(port)
35+ // logger.info("Setting port to $port succeeded.")
36+ }
You can’t perform that action at this time.
0 commit comments