Skip to content

Commit

Permalink
Welcome Kotlin!
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldRenard committed Nov 18, 2019
1 parent b97382d commit 9e767d7
Show file tree
Hide file tree
Showing 18 changed files with 302 additions and 325 deletions.
41 changes: 29 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@
buildscript {
ext {
springBootVersion = '2.1.7.RELEASE'
kotlinVersion = '1.3.60'
}
repositories {
jcenter()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url 'http://repo.spring.io/plugins-release' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
classpath("org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion")
}
}

Expand Down Expand Up @@ -57,21 +61,26 @@ subprojects {
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'idea'
apply plugin: 'kotlin'
apply plugin: 'io.spring.dependency-management'

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

compileKotlin.kotlinOptions.jvmTarget = "1.8"
compileTestKotlin.kotlinOptions.jvmTarget = "1.8"

compileJava.options.encoding = 'UTF-8'
compileJava.options.compilerArgs << "-Xlint:deprecation"

ext {
generatedMainJava = "${buildDir}/generated"
generatedMainJava = "$buildDir/generated"

//@formatter:off

// Common Properties
springBootVersion = "${springBootVersion}"
springBootVersion = "$springBootVersion"
kotlinVersion = "$kotlinVersion"
springCloudVersion = 'Greenwich.RELEASE'
springConsulVersion = '2.1.2.RELEASE'
hibernateVersion = '5.3.7.Final'
Expand Down Expand Up @@ -131,20 +140,28 @@ subprojects {
}

dependencies {
compileOnly "org.mapstruct:mapstruct-jdk8:${mapstructVersion}"
compileOnly "org.mapstruct:mapstruct-processor:${mapstructVersion}"
compileOnly "org.projectlombok:lombok:${lombokVersion}"
compileOnly "org.mapstruct:mapstruct-jdk8:$mapstructVersion"
compileOnly "org.mapstruct:mapstruct-processor:$mapstructVersion"
compileOnly "org.projectlombok:lombok:$lombokVersion"
annotationProcessor "javax.xml.bind:jaxb-api"
annotationProcessor "org.hibernate:hibernate-jpamodelgen:${hibernateVersion}"
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.hibernate:hibernate-jpamodelgen:$hibernateVersion"
annotationProcessor "org.mapstruct:mapstruct-processor:$mapstructVersion"
annotationProcessor "org.projectlombok:lombok:$lombokVersion"

compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
compile "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion"

testCompile "org.projectlombok:lombok:${lombokVersion}"
testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}"
testCompile "org.projectlombok:lombok:$lombokVersion"
testAnnotationProcessor "org.projectlombok:lombok:$lombokVersion"
}

dependencyManagement {
imports { mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES) }
imports {
mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES) {
bomProperty("kotlin.version", "$kotlinVersion")
}
}
}
}

Expand Down
19 changes: 10 additions & 9 deletions jb-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.tools.ant.filters.ReplaceTokens

apply plugin: 'application'
apply plugin: 'kotlin-spring'
apply plugin: 'org.springframework.boot'

description = 'JuniperBot Discord Bot Web Application'
Expand All @@ -25,7 +26,7 @@ ext {
moduleName = 'JuniperBot-Web'
}

mainClassName = 'ru.juniperbot.api.JuniperApiApplication'
mainClassName = 'ru.juniperbot.api.Launcher'

bootJar {
archiveFileName = "JuniperBot-API.jar"
Expand All @@ -34,25 +35,25 @@ bootJar {
dependencies {

implementation project(':jb-common')
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
annotationProcessor "org.mapstruct:mapstruct-processor:$mapstructVersion"

implementation "org.springframework.boot:spring-boot-starter-web"
implementation "org.springframework.boot:spring-boot-starter-security"
implementation "org.springframework.security:spring-security-acl"
implementation "org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:${springBootVersion}"
implementation "org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:$springBootVersion"

implementation "org.glassfish.main.external:jmxremote_optional-repackaged:${jmxRemote}"
implementation "org.glassfish.external:opendmk_jmxremote_optional_jar:${jmxRemoteLegacy}"
implementation "org.glassfish.main.external:jmxremote_optional-repackaged:$jmxRemote"
implementation "org.glassfish.external:opendmk_jmxremote_optional_jar:$jmxRemoteLegacy"

implementation "org.openpnp:opencv:${opencvVersion}-0"
implementation "org.opencv:opencv:${opencvVersion}"
implementation "org.opencv:opencv:$opencvVersion"

// SOCIAL DEPENDENCIES
implementation ("com.github.twitch4j:twitch4j:${twitch4jVersion}") {
implementation ("com.github.twitch4j:twitch4j:$twitch4jVersion") {
exclude group: "com.fasterxml.jackson.core", module: "jackson-databind"
}
implementation "com.vk.api:sdk:${vkSdkVersion}"
implementation "com.rometools:rome:${romeVersion}"
implementation "com.vk.api:sdk:$vkSdkVersion"
implementation "com.rometools:rome:$romeVersion"

testImplementation "org.springframework.boot:spring-boot-starter-test"
testImplementation "org.springframework.security:spring-security-test"
Expand Down
78 changes: 0 additions & 78 deletions jb-api/src/main/java/ru/juniperbot/api/JuniperApiApplication.java

This file was deleted.

75 changes: 75 additions & 0 deletions jb-api/src/main/java/ru/juniperbot/api/Launcher.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* This file is part of JuniperBot.
*
* JuniperBot is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* JuniperBot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with JuniperBot. If not, see <http://www.gnu.org/licenses/>.
*/
package ru.juniperbot.api

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientAutoConfiguration
import org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
import org.springframework.boot.autoconfigure.security.servlet.SecurityFilterAutoConfiguration
import org.springframework.boot.autoconfigure.security.servlet.SecurityRequestMatcherProviderAutoConfiguration
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Import
import org.springframework.context.annotation.ImportResource
import org.springframework.web.method.support.HandlerMethodArgumentResolver
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
import ru.juniperbot.api.common.ApiRequestLoggingFilter
import ru.juniperbot.api.common.AtomFeedArgumentResolver
import ru.juniperbot.common.configuration.CommonConfiguration
import ru.juniperbot.common.support.ModuleMessageSource
import ru.juniperbot.common.support.ModuleMessageSourceImpl


@Import(CommonConfiguration::class)
@ImportResource("classpath:security-context.xml")
@SpringBootApplication(exclude = [
SecurityAutoConfiguration::class,
SecurityFilterAutoConfiguration::class,
SecurityRequestMatcherProviderAutoConfiguration::class,
OAuth2ClientAutoConfiguration::class,
OAuth2ResourceServerAutoConfiguration::class
])
class JuniperApiApplication : WebMvcConfigurer {

@Bean
fun webMessages(): ModuleMessageSource = ModuleMessageSourceImpl("web-jbmessages")

override fun addArgumentResolvers(argumentResolvers: MutableList<HandlerMethodArgumentResolver>?) {
argumentResolvers!!.add(AtomFeedArgumentResolver())
}

@Bean
fun requestLoggingFilter(): ApiRequestLoggingFilter = ApiRequestLoggingFilter().apply {
this.setBeforeMessagePrefix("Before Request ")
this.setAfterMessagePrefix("After Request ")
this.setBeforeMessageSuffix("")
this.setAfterMessageSuffix("")
this.setMaxPayloadLength(10000)
this.setIncludeClientInfo(true)
this.setIncludeQueryString(true)
this.setIncludePayload(true)
}
}

object Launcher {

@JvmStatic
fun main(args: Array<String>) {
SpringApplication(JuniperApiApplication::class.java).run(*args)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* You should have received a copy of the GNU General Public License
* along with JuniperBot. If not, see <http://www.gnu.org/licenses/>.
*/
package ru.juniperbot.common.support;
package ru.juniperbot.common.support

public interface ModuleListener {
interface ModuleListener {

void onShutdown();
fun onShutdown()
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* You should have received a copy of the GNU General Public License
* along with JuniperBot. If not, see <http://www.gnu.org/licenses/>.
*/
package ru.juniperbot.common.support;
package ru.juniperbot.common.support

import java.text.MessageFormat;
import java.util.Locale;
import java.text.MessageFormat
import java.util.*

public interface ModuleMessageSource {
interface ModuleMessageSource {

String resolveCodeWithoutArguments(String code, Locale locale);
fun resolveCodeWithoutArguments(code: String, locale: Locale): String?

MessageFormat resolveCode(String code, Locale locale);
fun resolveCode(code: String, locale: Locale): MessageFormat?
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,32 @@
* You should have received a copy of the GNU General Public License
* along with JuniperBot. If not, see <http://www.gnu.org/licenses/>.
*/
package ru.juniperbot.common.support;
package ru.juniperbot.common.support

import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.context.support.ResourceBundleMessageSource
import java.text.MessageFormat
import java.util.*

import java.text.MessageFormat;
import java.util.Locale;
class ModuleMessageSourceImpl(baseName: String) : ResourceBundleMessageSource(), ModuleMessageSource {

public class ModuleMessageSourceImpl extends ResourceBundleMessageSource implements ModuleMessageSource {

public ModuleMessageSourceImpl() {
setDefaultEncoding("UTF-8");
init {
setBasename(baseName)
this.defaultEncoding = "UTF-8"
}

/**
* Resolves the given message code as key in the registered resource bundles,
* returning the value found in the bundle as-is (without MessageFormat parsing).
*/
@Override
public String resolveCodeWithoutArguments(String code, Locale locale) {
return super.resolveCodeWithoutArguments(code, locale);
override fun resolveCodeWithoutArguments(code: String, locale: Locale): String? {
return super.resolveCodeWithoutArguments(code, locale)
}

/**
* Resolves the given message code as key in the registered resource bundles,
* returning the value found in the bundle as-is (without MessageFormat parsing).
*/
@Override
public MessageFormat resolveCode(String code, Locale locale) {
return super.resolveCode(code, locale);
override fun resolveCode(code: String, locale: Locale): MessageFormat? {
return super.resolveCode(code, locale)
}
}
Loading

0 comments on commit 9e767d7

Please sign in to comment.