Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit dd4fd8a

Browse files
committed
added SparkUtils code
1 parent c341798 commit dd4fd8a

3 files changed

Lines changed: 76 additions & 15 deletions

File tree

build.gradle

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,61 @@
11
buildscript {
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

1212
plugins {
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

1624
group 'de.debuglevel.sparkutils'
1725
version '0.0.1-SNAPSHOT'
1826

19-
apply plugin: 'kotlin'
20-
2127
sourceCompatibility = 1.8
2228

2329
repositories {
24-
mavenCentral()
30+
jcenter()
2531
}
2632

2733
dependencies {
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+
//}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#Sat Jun 16 17:57:44 CEST 2018
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
34
zipStoreBase=GRADLE_USER_HOME
45
zipStorePath=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
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}

0 commit comments

Comments
 (0)