Verified Commit 7c10b571 authored by Lukas Wiest's avatar Lukas Wiest 🚂
Browse files

feat: major rework of MoDoCoT

parents 0e7ec0ac 19e0fb0c
target/
!.mvn/wrapper/maven-wrapper.jar
# ignore local development files
docker-compose.yml
/*.properties
### STS ###
.classpath
.factorypath
......
{
"tagPrefix": "",
"commitUrlFormat": "https://transfer.hft-stuttgart.de/gitlab/HFTSoftwareProject/MoDoCoT-Backend/-/commit/{{hash}}",
"compareUrlFormat": "https://transfer.hft-stuttgart.de/gitlab/HFTSoftwareProject/MoDoCoT-Backend/-/compare/{{previousTag}}...{{currentTag}}",
"issueUrlFormat": "https://transfer.hft-stuttgart.de/gitlab/HFTSoftwareProject/MoDoCoT-Backend/-/issues/{{id}}"
}
#Dockerfile
#base image
FROM alpine
FROM openjdk:11-jre-slim
#Proxy
ENV http_proxy 'http://proxy.hft-stuttgart.de:80'
ENV https_proxy 'http://proxy.hft-stuttgart.de:80'
#jdk11
RUN apk add openjdk11 git
VOLUME /tmp
ADD target/modocot-backend-1.0.2-SNAPSHOT.jar app.jar
RUN sh -c 'touch /app.jar'
ADD target/modocot-backend.jar app.jar
# Prepare environment.
# Create needed folders
RUN mkdir /home/modocot && \
mkdir /home/modocot/libs
RUN mkdir /modocot && \
mkdir /modocot/data && \
mkdir /modocot/config
VOLUME /modocot/data
# Download needed libs for compilation
ADD https://repo1.maven.org/maven2/junit/junit/4.13/junit-4.13.jar /home/modocot/libs/junit.jar
ADD https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/2.2/hamcrest-core-2.2.jar /home/modocot/libs/hamcrest.jar
env SPRING_CONFIG_ADDITIONAL_LOCATION "file:/home/modocot/config/"
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=server","-jar","/app.jar"]
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
def version = ""
pipeline {
environment {
registry = "hftstuttgart/modocot-backend"
registryCredential = 'Dockerhub'
dockerImage = ''
}
agent any
tools {
jdk 'Java11'
maven 'Maven_Home'
}
stages {
stage('Checkout') {
stage('prepare') {
steps {
echo 'Checkout Repository..'
git branch: 'master',
url: 'https://transfer.hft-stuttgart.de/gitlab/HFTSoftwareProject/MoDoCoT-Backend.git'
checkout ([
$class: 'GitSCM',
branches: scm.branches,
extensions: scm.extensions + [[$class: 'CloneOption', noTags: false, reference: '', shallow: false]],
userRemoteConfigs: scm.userRemoteConfigs
])
script {
version = sh(script: 'git describe --tags --always', returnStdout: true).trim()
echo sh(script: 'env|sort', returnStdout: true)
}
}
}
stage('Build') {
stage('compile') {
steps {
echo 'Maven Build..'
sh 'mvn clean package -DskipTests=false'
sh 'mvn clean package'
}
}
stage('Docker Build..') {
steps{
stage('build Docker image') {
steps {
script {
dockerImage = docker.build registry + ":latest"
dockerImage = docker.build registry
}
}
}
stage('Push to Dockerhub..') {
steps{
script {
docker.withRegistry( '', registryCredential ) {
dockerImage.push()
}
}
stage('push development image') {
steps {
script {
docker.withRegistry( '', registryCredential ) {
dockerImage.push("${env.GIT_BRANCH}")
}
}
}
}
stage('ShellScript') {
stage('release') {
when {
expression { version ==~ /[0-9]+.[0-9]+.[0-9]+/ }
}
steps {
echo 'Exectue Shellscript..'
sh 'chmod 744 restart_modocot_backend.sh && ./restart_modocot_backend.sh'
script {
docker.withRegistry( '', registryCredential ) {
dockerImage.push("latest")
dockerImage.push("${version}")
}
}
}
}
}
......
version: '3'
services:
backend:
build:
context: .
environment:
- DOCKER_HOST=unix:///var/run/docker.sock
container_name: modocot-devel-backend
ports:
- 127.0.0.1:8080:8080
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
- '/tmp/modocot-tests:/tmp/modocot-tests'
#!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven2 Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
#
# Look for the Apple JDKs first to preserve the existing behaviour, and then look
# for the new JDKs provided by Oracle.
#
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then
#
# Apple JDKs
#
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
fi
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then
#
# Apple JDKs
#
export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
fi
if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then
#
# Oracle JDKs
#
export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
fi
if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
#
# Apple JDKs
#
export JAVA_HOME=`/usr/libexec/java_home`
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Migwn, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
# TODO classpath?
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
fi
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
local basedir=$(pwd)
local wdir=$(pwd)
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
wdir=$(cd "$wdir/.."; pwd)
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} "$@"
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven2 Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
set MAVEN_CMD_LINE_ARGS=%*
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar""
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%
\ No newline at end of file
......@@ -4,7 +4,7 @@
<groupId>de.hftstuttgart</groupId>
<artifactId>modocot-backend</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>2.0.0</version>
<packaging>jar</packaging>
<name>Modocot-Backend</name>
......@@ -20,34 +20,18 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<docker.image.prefix>hftstuttgart</docker.image.prefix>
<skipTests>true</skipTests>
</properties>
<dependencies>
<dependency>
<groupId>com.github.zeripath</groupId>
<artifactId>java-gitea-api</artifactId>
<version>1.7.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.9.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-core</artifactId>
<version>3.2.6</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.30</version>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-transport-httpclient5</artifactId>
<version>3.2.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
......@@ -58,33 +42,17 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.jgit/org.eclipse.jgit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>5.7.0.202003110725-r</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.jgit/org.eclipse.jgit -->
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>5.7.0.202003110725-r</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
......@@ -98,19 +66,12 @@
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<skipTests>${skipTests}</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
</project>
#!/bin/bash
# Stop the running backend
docker stop modocot-backend
# Delete the existing container
docker rm modocot-backend
# Pull the new version from DockerHub
docker pull hftstuttgart/modocot-backend
# Build the container and start it
docker run --name modocot-backend -p 8888:8081 hftstuttgart/modocot-backend:latest &
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="LogToConsole" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="modocotbackend" level="debug" additivity="false">
<AppenderRef ref="LogToConsole"/>
</Logger>
<Root level="debug">
<AppenderRef ref="LogToConsole"/>
</Root>
</Loggers>
</Configuration>
\ No newline at end of file
package de.hftstuttgart;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.junit.ComparisonFailure;
import org.junit.runner.notification.Failure;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import javax.tools.Diagnostic;
import javax.tools.JavaFileObject;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.Locale;
@SpringBootApplication
@PropertySource("classpath:git-credentials.properties")
public class ModocotBackendApplication {
public static void main(String[] args) {
SpringApplication.run(ModocotBackendApplication.class, args);
}
/**
* Configuration for the Jackson JSON serializer
*/
@Bean
@Primary
public Jackson2ObjectMapperBuilder jacksonConfiguration() {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
builder.indentOutput(true)
.serializationInclusion(JsonInclude.Include.NON_NULL) // Don’t include null values in the JSON
.serializerByType(Diagnostic.class, new DiagnosticSerializer())
.serializerByType(Failure.class, new FailureSerializer());
return builder;
}
/**
* Custom serializer for the {@link Diagnostic} class used by Jackson
*/
private class DiagnosticSerializer extends JsonSerializer<Diagnostic> {
@Override
public void serialize(Diagnostic diagnostic, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException {
gen.writeStartObject();
gen.writeStringField("code", diagnostic.getCode());
gen.writeNumberField("columnNumber", diagnostic.getColumnNumber());
gen.writeStringField("kind", diagnostic.getKind().toString());
gen.writeNumberField("lineNumber", diagnostic.getLineNumber());
gen.writeStringField("message", diagnostic.getMessage(Locale.ENGLISH));
gen.writeNumberField("position", diagnostic.getPosition());
URI uri = ((JavaFileObject) diagnostic.getSource()).toUri();
gen.writeStringField("javaFileName", new File(uri).getName());
gen.writeNumberField("startPosition", diagnostic.getStartPosition());
gen.writeNumberField("endPosition", diagnostic.getEndPosition());
gen.writeEndObject();
}
}
/**
* Custom serializer for the {@link Failure} class used by Jackson
*/
private class FailureSerializer extends JsonSerializer<Failure> {
@Override
public void serialize(Failure failure, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException {
gen.writeStartObject();
gen.writeStringField("testHeader", failure.getTestHeader());
gen.writeStringField("message", failure.getMessage());
gen.writeStringField("trace", failure.getTrace());
Throwable exception = failure.getException();
if (exception instanceof ComparisonFailure) {
gen.writeStringField("expected", ((ComparisonFailure) exception).getExpected());
gen.writeStringField("actual", ((ComparisonFailure) exception).getActual());
}
gen.writeEndObject();
}
}
}
package de.hftstuttgart.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ModocotProperties {
private final String dockerHostIp;
private final String jenkinsApiToken;
private final String jenkinsBaseUrl;
private final String modocotParentDirectory;
private final String modocotAssignmentFolderPrefix;
private final String modocotTestFolderName;
private final String gitTeaBasePath;
private final String gitTeaUsername;
private final String gitTeaPassword;
private final String gitTeaDefaultCommitMessage;
private final String gitTeaOrigin;
public ModocotProperties(@Value("${docker.hostIp}") String dockerHostIp,
@Value("${jenkins.api.token}") String jenkinsApiToken,
@Value("${jenkins.url}") String jenkinsBaseUrl,
@Value("${modocot.dir.parent}") String modocotParentDirectory,
@Value("${modocot.dir.assignment.prefix}") String modocotAssignmentFolderPrefix,
@Value("${modocot.dir.test.folder.name}") String modocotTestFolderName,
@Value("${gitTea.basePath}") String gitTeaBasePath,
@Value("${gitTea.username}") String gitTeaUsername,
@Value("${gitTea.password}") String gitTeaPassword,
@Value("${gitTea.defaultCommitMessage}") String gitTeaDefaultCommitMessage,
@Value("${gitTea.defaultOrigin}") String gitTeaOrigin) {
this.dockerHostIp = dockerHostIp;
this.jenkinsApiToken = jenkinsApiToken;
this.jenkinsBaseUrl = jenkinsBaseUrl;
this.modocotParentDirectory = modocotParentDirectory;
this.modocotAssignmentFolderPrefix = modocotAssignmentFolderPrefix;
this.modocotTestFolderName = modocotTestFolderName;
this.gitTeaBasePath = gitTeaBasePath;
this.gitTeaUsername = gitTeaUsername;
this.gitTeaPassword = gitTeaPassword;
this.gitTeaDefaultCommitMessage = gitTeaDefaultCommitMessage;
this.gitTeaOrigin = gitTeaOrigin;
}
public String getDockerHostIp() {
return dockerHostIp;
}
public String getJenkinsApiToken() {
return jenkinsApiToken;
}
public String getJenkinsBaseUrl() {
return jenkinsBaseUrl;
}
public String getModocotParentDirectory() {
return modocotParentDirectory;
}
public String getModocotAssignmentFolderPrefix() {
return modocotAssignmentFolderPrefix;
}
public String getModocotTestFolderName() {
return modocotTestFolderName;
}
public String getGitTeaBasePath() {
return gitTeaBasePath;
}
public String getGitTeaUsername() {
return gitTeaUsername;
}
public String getGitTeaPassword() {
return gitTeaPassword;
}
public String getGitTeaDefaultCommitMessage() {
return gitTeaDefaultCommitMessage;
}
public String getGitTeaOrigin() {
return gitTeaOrigin;
}
}
package de.hftstuttgart.config;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import java.io.IOException;
import java.net.*;
import java.util.*;
import java.util.stream.Collectors;
@Configuration
/**
* Configures Proxy once on startup
*/
public class ProxySetup extends ProxySelector
{
private static final Logger LOG = LogManager.getLogger(ProxySetup.class);
List<Proxy> noProxy;
List<Proxy> setProxy;
Set<String> noProxyHosts;
public ProxySetup(Environment env) {
String ignoredHostNames = env.getProperty("proxy.ignoredHostNames");
if (Objects.isNull(ignoredHostNames)) {
ignoredHostNames = "";
}
String proxy = env.getProperty("proxy");
LOG.info("Configuring Proxy");
noProxy = Collections.singletonList(Proxy.NO_PROXY);
if (Objects.nonNull(proxy)) {
String[] proxyValues = proxy.split(":");
Proxy p = new Proxy(
Proxy.Type.HTTP,
new InetSocketAddress(proxyValues[0], Integer.parseInt(proxyValues[1])));
setProxy = Collections.singletonList(p);
LOG.info(String.format("set proxy: %s", p.address().toString()));
}
noProxyHosts = Arrays.stream(ignoredHostNames.split(","))
.map(String::toLowerCase)
.collect(Collectors.toCollection(HashSet::new));
LOG.info(String.format("Hosts to be ignored: %s", noProxyHosts));
ProxySelector.setDefault(this);
}
@Override
public List<Proxy> select(URI uri) {
LOG.debug(String.format("Proxy selection for URI: %s", uri.getHost()));
// No proxy for given hosts
if (noProxyHosts.contains(uri.getHost().toLowerCase())) {
LOG.debug(String.format("Proxy disabled for host %s", uri.getHost()));
return noProxy;
}
// no proxy if no proxy was set
if (Objects.nonNull(setProxy)) {
LOG.debug(String.format("Proxy used for host %s", uri.getHost()));
return setProxy;
}
LOG.debug("No proxy configured to choose from");
return noProxy;
}
@Override
public void connectFailed(URI uri, SocketAddress socketAddress, IOException e) {
LOG.error(String.format("connection to %s failed with %s", uri.getHost(), e.getMessage()));
}
}
Manifest-Version: 1.0
Created-By: 11.0.7 (Oracle Corporation)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment