Skip to content

Commit

Permalink
chore(sonarqube): Applied the sonar-scanner to the project and did so…
Browse files Browse the repository at this point in the history
…me refactoring
  • Loading branch information
JannisDommer committed Dec 13, 2023
1 parent a5b98b0 commit 6bb02dd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 55 deletions.
8 changes: 4 additions & 4 deletions WebSocketClient/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="split.css">
<link rel="stylesheet" href="./split.css">
<link rel="stylesheet" href="./node_modules/intro.js/introjs.css">
<link rel="stylesheet" href="./node_modules/intro.js/themes/introjs-modern.css">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="./style.css">
<title>UVL Playground</title>
</head>
<body>
Expand Down Expand Up @@ -54,9 +54,9 @@ <h1>Get the UVLS VSCode Extension</h1>
use all features use the UVLS - Universal Variability Language Server extension for visual studio code. </p>
</div>
<script type="module">
import {startPythonClient} from "./src/main.ts";
import {startUvlClient} from "./src/main.ts";

startPythonClient();
startUvlClient();
</script>
<script>
// A function is used for dragging and moving
Expand Down
2 changes: 2 additions & 0 deletions WebSocketClient/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ export default {
port: 30000,
languageServerHostName: "localhost",
debug: true,
MAX_NUMBER_LINES: 100,
MAX_NUMBER_CHARACTERS: 10000,
};
51 changes: 15 additions & 36 deletions WebSocketClient/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2018-2022 TypeFox GmbH (http://www.typefox.io). All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import * as monaco from 'monaco-editor';
import {editor} from 'monaco-editor';
import * as vscode from 'vscode';
import {LogLevel, Uri} from 'vscode';
import {whenReady} from '@codingame/monaco-vscode-theme-defaults-default-extension';
import '@codingame/monaco-vscode-python-default-extension';
import {createConfiguredEditor, createModelReference} from 'vscode/monaco';
Expand All @@ -17,13 +14,12 @@ import getThemeServiceOverride from '@codingame/monaco-vscode-theme-service-over
import getTextmateServiceOverride from '@codingame/monaco-vscode-textmate-service-override';
import {initServices, MonacoLanguageClient} from 'monaco-languageclient';
import {CloseAction, ErrorAction, MessageTransports} from 'vscode-languageclient';
import {WebSocketMessageReader, WebSocketMessageWriter, toSocket} from 'vscode-ws-jsonrpc';
import {toSocket, WebSocketMessageReader, WebSocketMessageWriter} from 'vscode-ws-jsonrpc';
import {
RegisteredFileSystemProvider,
registerFileSystemOverlay,
RegisteredMemoryFile
RegisteredMemoryFile,
registerFileSystemOverlay
} from 'vscode/service-override/files';
import {LogLevel, Uri} from 'vscode';
import config from './config.js';
import {instance} from "@viz-js/viz";
import {Message} from 'vscode-jsonrpc';
Expand All @@ -33,7 +29,6 @@ import {ExecuteCommandRequest} from 'vscode-languageserver-protocol'

import {buildWorkerDefinition} from 'monaco-editor-workers';
import {initIntroJS} from "./intro.ts";
import {editor} from "monaco-editor";
import IOverlayWidget = editor.IOverlayWidget;
import IContentWidget = editor.IContentWidget;
import IStandaloneCodeEditor = editor.IStandaloneCodeEditor;
Expand All @@ -47,21 +42,11 @@ let model;
const connectionText = document.getElementById("connection");
let debounceGenGraph;
let updateGraph = false;
const MAX_NUMBER_LINES = 100;
const MAX_NUMBER_CHARACTERS = 10000;

const createUrl = (hostname: string, port: number, path: string, searchParams: Record<string, any> = {}, secure: boolean): string => {
const createUrl = (hostname: string, port: number, path: string, secure: boolean): string => {
const protocol = secure ? 'wss' : 'ws';
const url = new URL(`${protocol}://${hostname}:${port}${path}`);

for (let [key, value] of Object.entries(searchParams)) {
if (value instanceof Array) {
value = value.join(',');
}
if (value) {
url.searchParams.set(key, value);
}
}
return url.toString();
};

Expand Down Expand Up @@ -200,7 +185,7 @@ function createDiagramFromDot(res: string): void {
});
}

export const startPythonClient = async () => {
export const startUvlClient = async () => {
// init vscode-api
const useDebugLogging = config.debug ? LogLevel.Debug : LogLevel.Off;
await initServices({
Expand Down Expand Up @@ -236,12 +221,7 @@ export const startPythonClient = async () => {
registerFileSystemOverlay(1, fileSystemProvider);

// create the web socket and configure to start the language client on open, can add extra parameters to the url if needed.
createWebSocket(createUrl(config.languageServerHostName, config.port, '/', {
// Used to parse an auth token or additional parameters such as import IDs to the language server
authorization: 'UserAuth'
// By commenting above line out and commenting below line in, connection to language server will be denied.
// authorization: 'FailedUserAuth'
}, location.protocol === 'https:'));
createWebSocket(createUrl(config.languageServerHostName, config.port, '/', location.protocol === 'https:'));


// use the file create before
Expand All @@ -263,24 +243,24 @@ export const startPythonClient = async () => {
const lineCount = model?.getLineCount();
let numberLines = aggregateCharacters(model);

if (lineCount && lineCount > MAX_NUMBER_LINES) {
if (lineCount > MAX_NUMBER_LINES + 1) {
if (lineCount && lineCount > config.MAX_NUMBER_LINES) {
if (lineCount > config.MAX_NUMBER_LINES + 1) {
vscode.commands.executeCommand("undo");
} else {
vscode.commands.executeCommand("deleteLeft");
}
if (connectionText) {
displayEditorErrorAtContent(editor, `The Editor only allows content up to ${MAX_NUMBER_LINES} Lines!`);
displayEditorErrorAtContent(editor, `The Editor only allows content up to ${config.MAX_NUMBER_LINES} Lines!`);
}
} else if (numberLines > MAX_NUMBER_CHARACTERS ) {
if (numberLines > MAX_NUMBER_CHARACTERS + 1) {
} else if (numberLines > config.MAX_NUMBER_LINES) {
if (numberLines > config.MAX_NUMBER_LINES + 1) {
vscode.commands.executeCommand("undo");
}
else {
vscode.commands.executeCommand("deleteLeft");
}
if (connectionText) {
displayEditorErrorAtContent(editor, `The Editor only allows content up to ${MAX_NUMBER_CHARACTERS} Characters!`);
displayEditorErrorAtContent(editor, `The Editor only allows content up to ${config.MAX_NUMBER_LINES} Characters!`);
}
}
debouncedSave();
Expand Down Expand Up @@ -381,8 +361,7 @@ function aggregateCharacters(model: editor.ITextModel): number {
let addReducer = (previousValue: number, currentValue: string) => {
return previousValue + currentValue.length
};
const characters: number = model?.getLinesContent().reduce(addReducer, 0);
return characters;
return model?.getLinesContent().reduce(addReducer, 0);
}

function getInitialFm() {
Expand Down
27 changes: 12 additions & 15 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@ services:
traefik:
image: traefik:v3.0
ports:
- 80:80
- 443:443
- 30000:30000
- 3000:3000
- "80:80"
- "443:443"
- "30000:30000"
- "3000:3000"
networks:
- proxy
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- letsencrypt:/letsencrypt
#- /var/log:/var/log
command:
- --api.dashboard=true
- --api.insecure=true
- --log.level=DEBUG
#- --log.filepath=/var/log/traefik.log
- --accesslog=true
#- --accesslog.filepath=/var/log/traefik-access.log
- --providers.docker.network=proxy
- --providers.docker.exposedByDefault=false
- --entrypoints.web.address=:80
Expand All @@ -37,11 +34,11 @@ services:
- --certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json
- --certificatesResolvers.myresolver.acme.caServer=https://acme-v02.api.letsencrypt.org/directory
labels:
- traefik.enable=true
- traefik.http.routers.mydashboard.rule=Host(`${HOSTNAME}`) && (PathPrefix(`/dashboard/`) || PathPrefix(`/api`))
- traefik.http.routers.mydashboard.service=api@internal
- traefik.http.routers.mydashboard.middlewares=myauth
- traefik.http.middlewares.myauth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/
- "traefik.enable=true"
- "traefik.http.routers.mydashboard.rule=Host(`${HOSTNAME}`) && (PathPrefix(`/dashboard/`) || PathPrefix(`/api`))"
- "traefik.http.routers.mydashboard.service=api@internal"
- "traefik.http.routers.mydashboard.middlewares=myauth"
- "traefik.http.middlewares.myauth.basicauth.users=test:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/"

webserver:
build:
Expand All @@ -55,9 +52,9 @@ services:
- "traefik.http.routers.webserver.rule=Host(`${HOSTNAME}`)"
- "traefik.http.services.webserver.loadbalancer.server.port=80"

- traefik.http.middlewares.mywwwredirect.redirectregex.regex=^https://www\.(.*)
- traefik.http.middlewares.mywwwredirect.redirectregex.replacement=https://$${1}
- traefik.http.routers.webserver.middlewares=mywwwredirect
- "traefik.http.middlewares.mywwwredirect.redirectregex.regex=^https://www\.(.*)"
- "traefik.http.middlewares.mywwwredirect.redirectregex.replacement=https://$${1}"
- "traefik.http.routers.webserver.middlewares=mywwwredirect"

languageserver:
build:
Expand Down
1 change: 1 addition & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sonar.projectKey=UVLP

0 comments on commit 6bb02dd

Please sign in to comment.