Skip to content

Commit

Permalink
Merge pull request #2 from MEITREX/java-version-issues
Browse files Browse the repository at this point in the history
Java version issues
  • Loading branch information
myluki2000 authored Jun 28, 2024
2 parents 271cfa8 + cb845ef commit c32f1b0
Show file tree
Hide file tree
Showing 45 changed files with 348 additions and 241 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name: Building Docker Image

on:
workflow_run:
workflows:
- Testing CI pipeline
types:
- completed
workflow_dispatch:
# enable when deployment is ready
# workflow_run:
# workflows:
# - Testing CI pipeline
# types:
# - completed

jobs:
docker-build:
Expand Down
21 changes: 14 additions & 7 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,32 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v3
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3
uses: gradle/wrapper-validation-action@v2
- name: Run chmod to make gradlew executable
run: chmod +x gradlew

- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Execute tests
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629
uses: gradle/gradle-build-action@v3
with:
arguments: cleanTest test jacocoTestReport sonar





13 changes: 11 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# syntax=docker/dockerfile:experimental
FROM gradle:7.6.2-jdk17 AS build
FROM gradle:8-jdk21 AS build
WORKDIR /workspace/app

# Copy only gradle files to container so we can install them
COPY ./build.gradle ./settings.gradle /workspace/app/

# install dependencies. This will be cached by the docker layered cache. This command will fail because the
# app code is still missing, so we return 0 so docker thinks the command executed successfully (but the
# dependencies are still downloaded even if the command fails so now we have them cached)
RUN gradle clean build -x test || return 0

# Now copy the actual app code and build it
COPY . /workspace/app
RUN gradle clean build -x test
RUN mkdir -p build/dependency && (cd build/dependency; jar -xf ../libs/*-SNAPSHOT.jar)
Expand All @@ -12,4 +21,4 @@ ARG DEPENDENCY=/workspace/app/build/dependency
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","de.unistuttgart.iste.gits.flashcard_service.FlashcardServiceApplication"]
ENTRYPOINT ["java","-cp","app:app/lib/*","de.unistuttgart.iste.meitrex.flashcard_service.FlashcardServiceApplication"]
62 changes: 45 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.6'
id 'io.spring.dependency-management' version '1.1.0'
id "io.github.kobylynskyi.graphql.codegen" version "5.7.2"
id "org.sonarqube" version "4.0.0.2929"
id 'org.springframework.boot' version '3.+'
id 'io.spring.dependency-management' version '1.+'
id "io.github.kobylynskyi.graphql.codegen" version "5.+"
id "org.sonarqube" version "5.+"
id "jacoco"

}

group = 'de.unistuttgart.iste.gits'
group = 'de.unistuttgart.iste.meitrex'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
sourceCompatibility = '21'

def jacocoEnabled = System.properties.getProperty("jacocoEnabled") ?: "true"

Expand All @@ -26,15 +26,35 @@ sonarqube {
property("sonar.organization", "meitrex")
property("sonar.host.url", "https://sonarcloud.io")
}
}

// workaround to fetch schema files from external repositories
// as gradle only supports java dependencies
def fetchFilesFromRepo(String repository, List<String> files) {
def baseurl = "https://raw.githubusercontent.com/MEITREX/"
def fileUrl = "${baseurl}${repository}/main/src/main/resources/graphql/"
def outputDir = "src/main/resources/graphql"

files.each { file ->
tasks.register("fetchExternalSchema-${file.capitalize()}", Exec) {
commandLine 'curl', "${fileUrl}${file}", '-o', "${outputDir}/${repository}/${file}"
}
}
}

fetchFilesFromRepo("common", ["directives.graphqls", "scalars.graphqls", "sortFilterPagination.graphqls"])

// run this task to fetch the latest schema files from the external github repositories
tasks.register("fetchAllExternalSchemas", Task) {
dependsOn tasks.matching { it.name.startsWith("fetchExternalSchema-") }
}

// Automatically generate DTOs from GraphQL schema:
graphqlCodegen {
// all config options:
// https://github.com/kobylynskyi/graphql-java-codegen/blob/main/docs/codegen-options.md
outputDir = new File("$buildDir/generated")
packageName = "de.unistuttgart.iste.gits.generated.dto"
packageName = "de.unistuttgart.iste.meitrex.generated.dto"
generatedAnnotation = "jakarta.annotation.Generated"
modelValidationAnnotation = "jakarta.validation.constraints.NotNull"
generateApis = false // set to false as the generator does not support spring boot graphQL
Expand All @@ -48,6 +68,7 @@ graphqlCodegen {
]
generateEqualsAndHashCode = true
generateToString = true
fieldsWithResolvers = ["@OnDemand"]
}

// Automatically generate GraphQL code on project build:
Expand All @@ -56,6 +77,16 @@ compileJava.dependsOn 'graphqlCodegen'
// Add generated sources to your project source sets:
sourceSets.main.java.srcDir "$buildDir/generated"

// Automatically generate API documentation on project build:
// Remark: Only works on Windows
tasks.register('generateApiDocs', Exec) {
commandLine 'cmd', '/c', 'generate_api_doc.bat'
}

tasks.named('assemble') {
finalizedBy('generateApiDocs')
}

configurations {
compileOnly {
extendsFrom annotationProcessor
Expand All @@ -67,35 +98,32 @@ repositories {
}

dependencies {
implementation 'de.unistuttgart.iste.gits:gits-common:0.6.4'
implementation 'com.google.code.findbugs:jsr305:3.0.2' // removes a gradle warning about an unknown annotation
implementation 'de.unistuttgart.iste.meitrex:meitrex-common:1.0.6'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-graphql'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.modelmapper:modelmapper:3.+'
implementation 'com.graphql-java:graphql-java-extended-scalars:20.0'
implementation 'com.graphql-java:graphql-java-extended-validation:20.0'
implementation 'com.graphql-java:graphql-java-extended-scalars:22.0'
implementation 'com.graphql-java:graphql-java-extended-validation:22.0'
implementation 'io.dapr:dapr-sdk:1.9.0' // Dapr's core SDK with all features, except Actors.
implementation 'io.dapr:dapr-sdk-springboot:1.9.0' // Dapr's SDK integration with SpringBoot
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'de.unistuttgart.iste.gits:gits-common-test:0.3.2'
testImplementation 'de.unistuttgart.iste.meitrex:meitrex-common-test:1.0.6'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework:spring-webflux'
testImplementation 'org.springframework.graphql:spring-graphql-test'
testImplementation "org.mockito:mockito-core:3.+"
testImplementation "org.mockito:mockito-core:5.+"
testImplementation 'org.hamcrest:hamcrest:2.+'
testImplementation "org.testcontainers:postgresql:1.18.3"
testImplementation "org.testcontainers:junit-jupiter:1.18.3"
testImplementation "org.testcontainers:postgresql:1.+"
testImplementation "org.testcontainers:junit-jupiter:1.+"
}

tasks.named('test') {
useJUnitPlatform()
}

tasks.withType(Test).configureEach { testLogging.showStandardStreams = true }
2 changes: 1 addition & 1 deletion components/pubsub.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: gits
name: meitrex
spec:
type: pubsub.redis
version: v1
Expand Down
16 changes: 13 additions & 3 deletions generate_api_doc.bat
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
@echo off
echo Generating API documentation...
echo This requires the service to be running
echo This requires npm to be installed!

REM clear old docs
del api.md
REM Delete the combined file
del combined.graphql

set port=6001
set title=Flashcard Service API

REM install graphql-markdown if not installed
if not exist node_modules\graphql-markdown (
npm install graphql-markdown
)

npx graphql-markdown "http://localhost:%port%/graphql" --title "%title%" > api.md
REM Concatenate all graphql files into one
for /r src\main\resources\graphql %%i in (*.graphqls) do type "%%i" >> combined.graphql

REM Run npx in a separate cmd instance
cmd /c npx graphql-markdown combined.graphql --title "%title%" > api.md

echo API documentation generated.

REM Delete the combined file
del combined.graphql
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
7 changes: 3 additions & 4 deletions jacoco.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
jacoco {
toolVersion = "0.8.8"
toolVersion = "0.8.11"
}

test {
finalizedBy jacocoTestReport
}


jacocoTestReport {
reports {
xml.enabled true
html.enabled true
xml.required.set(true)
html.required.set(true)
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
}
}
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ rootProject.name = 'flashcard_service'

sourceControl {
gitRepository(uri('https://github.com/MEITREX/common')) {
producesModule('de.unistuttgart.iste.gits:gits-common')
producesModule('de.unistuttgart.iste.meitrex:meitrex-common')
}
gitRepository(uri('https://github.com/MEITREX/common_test')) {
producesModule('de.unistuttgart.iste.gits:gits-common-test')
producesModule('de.unistuttgart.iste.meitrex:meitrex-common-test')
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.unistuttgart.iste.gits.flashcard_service;
package de.unistuttgart.iste.meitrex.flashcard_service;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package de.unistuttgart.iste.gits.flashcard_service.config;
package de.unistuttgart.iste.meitrex.flashcard_service.config;


import de.unistuttgart.iste.gits.common.dapr.MockTopicPublisher;
import de.unistuttgart.iste.gits.common.dapr.TopicPublisher;
import de.unistuttgart.iste.meitrex.common.dapr.MockTopicPublisher;
import de.unistuttgart.iste.meitrex.common.dapr.TopicPublisher;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
* This is a dev-config for the TopicPublisher. It is intended to be used for development only.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.unistuttgart.iste.gits.flashcard_service.config;
package de.unistuttgart.iste.meitrex.flashcard_service.config;

import graphql.scalars.ExtendedScalars;
import graphql.validation.rules.OnValidationErrorStrategy;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.unistuttgart.iste.gits.flashcard_service.config;
package de.unistuttgart.iste.meitrex.flashcard_service.config;

import org.modelmapper.ModelMapper;
import org.springframework.context.annotation.Bean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.unistuttgart.iste.gits.flashcard_service.config;
package de.unistuttgart.iste.meitrex.flashcard_service.config;

import de.unistuttgart.iste.gits.common.user_handling.RequestHeaderUserProcessor;
import de.unistuttgart.iste.meitrex.common.user_handling.RequestHeaderUserProcessor;
import lombok.SneakyThrows;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.unistuttgart.iste.gits.flashcard_service.config;
package de.unistuttgart.iste.meitrex.flashcard_service.config;


import de.unistuttgart.iste.gits.common.dapr.TopicPublisher;
import de.unistuttgart.iste.meitrex.common.dapr.TopicPublisher;
import io.dapr.client.DaprClientBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package de.unistuttgart.iste.gits.flashcard_service.controller;

import de.unistuttgart.iste.gits.common.exception.NoAccessToCourseException;
import de.unistuttgart.iste.gits.common.user_handling.LoggedInUser;
import de.unistuttgart.iste.gits.common.user_handling.LoggedInUser.UserRoleInCourse;
import de.unistuttgart.iste.gits.flashcard_service.persistence.entity.FlashcardSetEntity;
import de.unistuttgart.iste.gits.flashcard_service.service.FlashcardService;
import de.unistuttgart.iste.gits.flashcard_service.service.FlashcardUserProgressDataService;
import de.unistuttgart.iste.gits.generated.dto.*;
package de.unistuttgart.iste.meitrex.flashcard_service.controller;

import de.unistuttgart.iste.meitrex.common.exception.NoAccessToCourseException;
import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser;
import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser.UserRoleInCourse;
import de.unistuttgart.iste.meitrex.flashcard_service.persistence.entity.FlashcardSetEntity;
import de.unistuttgart.iste.meitrex.flashcard_service.service.FlashcardService;
import de.unistuttgart.iste.meitrex.flashcard_service.service.FlashcardUserProgressDataService;
import de.unistuttgart.iste.meitrex.generated.dto.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.graphql.data.method.annotation.*;
Expand All @@ -15,8 +15,8 @@
import java.util.List;
import java.util.UUID;

import static de.unistuttgart.iste.gits.common.user_handling.UserCourseAccessValidator.validateUserHasAccessToCourse;
import static de.unistuttgart.iste.gits.common.user_handling.UserCourseAccessValidator.validateUserHasAccessToCourses;
import static de.unistuttgart.iste.meitrex.common.user_handling.UserCourseAccessValidator.validateUserHasAccessToCourse;
import static de.unistuttgart.iste.meitrex.common.user_handling.UserCourseAccessValidator.validateUserHasAccessToCourses;


@Slf4j
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package de.unistuttgart.iste.gits.flashcard_service.controller;
package de.unistuttgart.iste.meitrex.flashcard_service.controller;

import de.unistuttgart.iste.gits.common.event.ContentChangeEvent;
import de.unistuttgart.iste.gits.flashcard_service.service.FlashcardService;
import de.unistuttgart.iste.meitrex.common.event.ContentChangeEvent;
import de.unistuttgart.iste.meitrex.flashcard_service.service.FlashcardService;
import io.dapr.Topic;
import io.dapr.client.domain.CloudEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

/**
Expand Down
Loading

0 comments on commit c32f1b0

Please sign in to comment.