Skip to content

Commit 0716e4b

Browse files
committed
Migrate groovy router from Kotlin to Java. We CANNOT call Groovy from Kotlin, only from Java. Migrate App and Config to Java to be able to call Groovy view. Also, migrate unit test to Java.
1 parent 5a4ded7 commit 0716e4b

10 files changed

Lines changed: 471 additions & 412 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Usage
2+
3+
Run with:
4+
5+
```
6+
./gradlew bootRun
7+
```

build.gradle.kts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,24 @@ plugins {
1010

1111
group = "pt.isel"
1212
version = "0.0.1-SNAPSHOT"
13-
java.sourceCompatibility = JavaVersion.VERSION_11
13+
java.sourceCompatibility = JavaVersion.VERSION_17
1414

1515
repositories {
1616
mavenCentral()
1717
mavenLocal()
1818
}
1919

20+
sourceSets {
21+
main {
22+
java {
23+
setSrcDirs(emptyList<String>()) // no source dirs for the java compiler
24+
}
25+
groovy {
26+
setSrcDirs(listOf("src/main/java", "src/main/groovy")) // compile everything in src/ with groovy
27+
}
28+
}
29+
}
30+
2031
dependencies {
2132
implementation("org.slf4j:slf4j-simple:2.0.6")
2233
/**
@@ -57,6 +68,15 @@ tasks.withType<KotlinCompile> {
5768
}
5869
}
5970

71+
tasks
72+
.getByName<AbstractCompile>("compileGroovy")
73+
.dependsOn(tasks.getByName<KotlinCompile>("compileKotlin"))
74+
75+
tasks
76+
.getByName<AbstractCompile>("compileGroovy")
77+
.classpath += files(tasks.getByName<KotlinCompile>("compileKotlin").destinationDirectory)
78+
6079
tasks.withType<Test> {
6180
useJUnitPlatform()
6281
}
82+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package pt.isel.genius;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class GeniusApplication {
8+
9+
public static void main(String[] args) {
10+
/**
11+
* Limit request handler threads to a single worker thread.
12+
* Thus, handlers should be non-blocking to allow multiple requests concurrently.
13+
* NOTICE minimum default to 4.
14+
*/
15+
System.setProperty("reactor.netty.ioWorkerCount", "1"); // minimum default to 4
16+
SpringApplication.run(GeniusApplication.class, args);
17+
}
18+
}
19+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package pt.isel.genius;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.ComponentScan;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.web.reactive.function.server.RouterFunction;
7+
import org.springframework.web.reactive.function.server.ServerResponse;
8+
import pt.isel.genius.groovy.ArtistRouterGroovy;
9+
import pt.isel.genius.htmlflow.ArtistRouterHtmlFlowKt;
10+
import pt.isel.genius.kotlinx.ArtistRouterKotlinxKt;
11+
import pt.isel.genius.thymeleaf.ArtistRouterThymeleafKt;
12+
13+
@Configuration
14+
@ComponentScan
15+
public class WebConfig {
16+
@Bean
17+
public RouterFunction<ServerResponse> routerArtistHtmlFlow() {
18+
return ArtistRouterHtmlFlowKt.artistRouterHtmlFlow();
19+
}
20+
21+
@Bean
22+
public RouterFunction<ServerResponse> routerArtistKotlinX() {
23+
return ArtistRouterKotlinxKt.artistCoRouterKotlinX();
24+
}
25+
26+
@Bean
27+
public RouterFunction<ServerResponse> routerArtistThymeleaf() {
28+
return ArtistRouterThymeleafKt.artistRouterThymeleaf();
29+
}
30+
31+
@Bean
32+
public RouterFunction<ServerResponse> routerArtistGroovy() {
33+
return ArtistRouterGroovy.artistRouterHtmlGroovy();
34+
}
35+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package pt.isel.genius.groovy;
2+
3+
import org.springframework.core.ParameterizedTypeReference;
4+
import org.springframework.http.MediaType;
5+
import org.springframework.web.reactive.function.server.RouterFunction;
6+
import org.springframework.web.reactive.function.server.RouterFunctions;
7+
import org.springframework.web.reactive.function.server.ServerRequest;
8+
import org.springframework.web.reactive.function.server.ServerResponse;
9+
import pt.isel.genius.AppendableWriter;
10+
import pt.isel.genius.GeniusRepositoryKt;
11+
import reactor.core.publisher.Mono;
12+
13+
public class ArtistRouterGroovy {
14+
public static RouterFunction<ServerResponse> artistRouterHtmlGroovy() {
15+
return RouterFunctions
16+
.route()
17+
.path("/groovy", builder -> builder
18+
.GET("/reactive/playlist", req -> handlerPlaylist(req))
19+
)
20+
.build();
21+
}
22+
23+
private static Mono<ServerResponse> handlerPlaylist(ServerRequest req) {
24+
final var out = new AppendableWriter(writer -> {
25+
ArtistViewGroovy.playlistView(writer, GeniusRepositoryKt.getTracks());
26+
return null;
27+
});
28+
return ServerResponse
29+
.ok()
30+
.contentType(MediaType.TEXT_HTML)
31+
.body(out.asFlux(), new ParameterizedTypeReference<String>() {});
32+
}
33+
}

src/main/kotlin/pt/isel/genius/GeniusApplication.kt

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/main/kotlin/pt/isel/genius/WebConfig.kt

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/main/kotlin/pt/isel/genius/groovy/ArtistRouterGroovy.kt

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)