Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions c4-server/src/main/java/com/structurizr/dsl/DslPackage.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package com.structurizr.dsl;

import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

public class DslPackage {

public record Line(int lineNumber, String source) {
public record Line(int number, String source) {
}

public static LinkedList<Line> processPreProcessLines(Object result) {
public static List<Line> processPreProcessLines(Object result) {
return ((List<?>)result)
.stream()
.sequential()
.map(DslLine.class::cast)
.map(dl -> new Line(dl.getLineNumber(), dl.getSource()))
.collect(Collectors.toCollection(LinkedList::new));
.map(dl -> new Line(dl.getLineNumber(), dl.getSource())).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,10 @@ public Integer call() throws Exception {
// Get the computed result from LS.
startListening.get();
}

}
catch (ExecutionException e) {
} catch (ExecutionException | InterruptedException | IOException e) {
logger.error(e.getMessage());
Thread.currentThread().interrupt();
}
catch (InterruptedException e) {
logger.error(e.getMessage());
}
catch (IOException e) {
logger.error(e.getMessage());
}

return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static C4ExecuteCommandResult execute(String command, List<Object> argume
switch (command) {

case UPDATE_CONFIGURATION:
logger.info("Update configuration {}", arguments.get(0).toString());
logger.info("Update configuration {}", arguments.get(0));
return C4ExecuteCommandResult.OK;

case CALCULATE_TEXT_DECORATIONS:
Expand Down
45 changes: 21 additions & 24 deletions c4-server/src/main/java/ru/beeatlas/c4/custom/Custom.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public class Custom {
private Map<String, List<CompletionItem>> beelineCloudFlavors = new HashMap<>();
private Map<String, List<CompletionItem>> beelineCloudImages = new HashMap<>();

private final static String TECH_PATTERN = "tech:";
private static final String TECH_PATTERN = "tech:";
private Map<String, String> adrs = new HashMap<>();

LanguageClient client;
Expand Down Expand Up @@ -165,7 +165,7 @@ private HttpsURLConnection beelineApiConnection(String method, String path, Stri
contentType = "";
}

if(certVerification == false) {
if(!certVerification) {
conn.setHostnameVerifier(allTrustingHostnameVerifier);
conn.setSSLSocketFactory(allTrustingTrustManager);
}
Expand Down Expand Up @@ -209,7 +209,7 @@ private HttpsURLConnection beelineCloudConnection(String method, String path) th

HttpsURLConnection conn = (HttpsURLConnection) new URL(cloudUrl + path).openConnection();
conn.setRequestMethod(method);
if(certVerification == false) {
if(!certVerification) {
conn.setHostnameVerifier(allTrustingHostnameVerifier);
conn.setSSLSocketFactory(allTrustingTrustManager);
}
Expand Down Expand Up @@ -250,7 +250,7 @@ public Custom() {
TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
return new X509Certificate[0];
}

@Override
Expand All @@ -262,14 +262,10 @@ public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };

SSLContext sc = SSLContext.getInstance("SSL");
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
allTrustingTrustManager = sc.getSocketFactory();
allTrustingHostnameVerifier = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
allTrustingHostnameVerifier = (String hostname, SSLSession session) -> true;
} catch (Exception e) {
}
}
Expand Down Expand Up @@ -347,8 +343,8 @@ private void updateTerms() {
logger.debug(e.getMessage());
}

List<String> glossariesAList = Arrays.asList(glossaries.split(",")).stream()
.map(String::toLowerCase).collect(Collectors.toList());
List<String> glossariesAList = Arrays.asList(glossaries.split(",")).stream().map(String::toLowerCase)
.toList();
Map<String, Term> map = new HashMap<>();
String path = "/dashboard/api/v1/data-model/glossaries";
HttpsURLConnection conn = beelineApiConnection("GET", path, null, null);
Expand Down Expand Up @@ -397,7 +393,7 @@ public String loadFrom(String themeLocation, int timeoutInMilliseconds) {
try {
HttpsURLConnection conn = (HttpsURLConnection) new URL(themeLocation).openConnection();
conn.setRequestMethod("GET");
if (certVerification == false) {
if (!certVerification) {
conn.setHostnameVerifier(allTrustingHostnameVerifier);
conn.setSSLSocketFactory(allTrustingTrustManager);
}
Expand Down Expand Up @@ -442,7 +438,7 @@ public List<CompletionItem> calcCompletionsAdr(String uri, Position position) {
return Collections.emptyList();
}
String text = line.get().substring(character - TECH_PATTERN.length(), character);
if (!text.toLowerCase().equals(TECH_PATTERN)) {
if (!text.equalsIgnoreCase(TECH_PATTERN)) {
return Collections.emptyList();
}
return technologiesCompletion();
Expand Down Expand Up @@ -647,7 +643,7 @@ public List<CompletionItem> dynamicViewCompletion(String destination, C4Document
return Collections.emptyList();
}
Container container = (Container) element.get().getObject();
ArrayList<CompletionItem> completionItems = new ArrayList<CompletionItem>();
ArrayList<CompletionItem> completionItems = new ArrayList<>();
container.getComponents().stream()
.filter(c -> c.getProperties().getOrDefault("type", "").equalsIgnoreCase("capability"))
.map(c -> c.getProperties().get("code")).filter(Objects::nonNull).forEach(c -> {
Expand Down Expand Up @@ -755,7 +751,7 @@ public List<CompletionItem> comleteProperties(List<LineToken> tokens, CursorLoca
}
lineNumberForward++;
}
if(isTypeCapability == false) {
if(!isTypeCapability) {
while(docModel.getSurroundingScope(lineNumberBackward).equals("PropertiesDslContext")) {
String line = docModel.getLineAt(lineNumberBackward);
if(line == null) {
Expand Down Expand Up @@ -783,9 +779,9 @@ public List<CompletionItem> comleteProperties(List<LineToken> tokens, CursorLoca
LineToken firstToken = tokens.get(0);
String firstTokenName = C4Utils.trimStringByString(firstToken.token(), "\"").toLowerCase();

if(isTypeCapability == true) {
if(isTypeCapability) {
if(firstTokenName.equals("code") && LineTokenizer.isInsideToken(cursor, 1)) {
Set<Integer> idUsed = new HashSet<Integer>();
Set<Integer> idUsed = new HashSet<>();

docModel.getC4PropertiesByName("code").forEach(e -> {
try {
Expand All @@ -794,8 +790,9 @@ public List<CompletionItem> comleteProperties(List<LineToken> tokens, CursorLoca
}
});

List<String> ids = new ArrayList<String>();
Integer i = 0, id = 0;
List<String> ids = new ArrayList<>();
Integer i = 0;
Integer id = 0;
while(i < 20) {
id++;
if(idUsed.contains(id)) {
Expand Down Expand Up @@ -861,7 +858,7 @@ public List<CompletionItem> completeContainer(List<LineToken> tokens, CursorLoca
if(LineTokenizer.isInsideToken(cursor, 2)) {
return C4CompletionItemCreator.identifierCompletion(model.getIdentifiers()).stream()
.filter( item -> item.getLabel().startsWith(tokens.get(2).token()))
.collect(Collectors.toList());
.toList();
}
}
return Collections.emptyList();
Expand Down Expand Up @@ -936,7 +933,7 @@ public void closeScope(C4CompletionScope scope, C4DocumentModel model) {
}
}
}
if(isApi == true && isSlaPresent == false && apiUrl.isBlank() == false) {
if(isApi && !isSlaPresent && !apiUrl.isBlank()) {
List<LineToken> tokens;
int i = 0;
do {
Expand Down Expand Up @@ -978,7 +975,7 @@ public void completionTelemety() {
private void startTelemetry() {
String message = MessageFormat.format("'{'\"version\": \"{0}\", \"action\": \"start\", \"user\": \"{1}\", \"cmdb\": \"{2}\"'}'", version, username, cmdb);
CompletableFuture.runAsync(() -> {
if(started == false) {
if(!started) {
started = sendTelemetry(message);
}
});
Expand Down Expand Up @@ -1013,7 +1010,7 @@ private boolean sendTelemetry(String message) {
logger.debug(e.getMessage());
}

if(telemetryEnabled == false) {
if(!telemetryEnabled) {
return false;
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
package ru.beeatlas.c4.intercept;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
Expand Down Expand Up @@ -62,52 +59,36 @@ public class InterceptParserAspect {
StructurizrDslParserListener parserListener;

private static final Logger logger = LoggerFactory.getLogger(InterceptParserAspect.class);
private static final String BOM = "\uFEFF";

@After("within(com.structurizr.dsl.StructurizrDslParser) && execution(* startContext(com.structurizr.dsl.DslContext)) && args(dslContext)")
public void interceptStartContextAfter(Object dslContext) throws Exception {
public void interceptStartContextAfter(Object dslContext) {
parserListener.onStartContext(dslContext.hashCode(), dslContext.getClass().getSimpleName());
}

@After("within(com.structurizr.dsl.StructurizrDslParser) && execution(* parse(com.structurizr.dsl.DslParserContext, java.io.File)) && args(*, file) ")
public void interceptParseAfter(File file) throws Exception {
public void interceptParseAfter(File file) {
parserListener.onExtendsBy(file);
}

@AfterReturning(pointcut = "withincode(* com.structurizr.dsl.StructurizrDslParser.endContext(..)) && call(* java.util.Stack.pop(..))", returning = "result")
public void interceptEndContextBefore(Object result) throws Exception {
public void interceptEndContextBefore(Object result) {
parserListener.onEndContext(result.hashCode(), result.getClass().getSimpleName());
}

@Around("within(com.structurizr.dsl.StructurizrDslParser) && execution(* parse(java.util.List<String>, java.io.File, boolean, boolean))")
public void interceptParseAround(ProceedingJoinPoint joinPoint) throws StructurizrDslParserException {
Object[] args = joinPoint.getArgs();
File file = (File)args[1];
parserListener.onStartFile(file);
String content = parserListener.findContent(file);
if(content != null) {
List<String> lines = Arrays.asList(content.split("\\r?\\n"));
List<String> paddedLines = new ArrayList<>();
String leadingSpace = "";
for (String unpaddedLine : lines) {
if (unpaddedLine.startsWith(BOM)) {
// this caters for files encoded as "UTF-8 with BOM"
unpaddedLine = unpaddedLine.substring(1);
}
paddedLines.add(leadingSpace + unpaddedLine);
}
args[0] = paddedLines;
}
@Around("within(com.structurizr.dsl.StructurizrDslParser) && execution(* parse(java.util.List<String>, java.io.File, boolean, boolean)) && args(lines, dslFile, fragment, includeInDslSourceLines)")
public void interceptParseAround(ProceedingJoinPoint joinPoint, List<String> lines, File dslFile, boolean fragment,
boolean includeInDslSourceLines) throws StructurizrDslParserException {
parserListener.onStartFile(dslFile);
try {
joinPoint.proceed(args);
joinPoint.proceed();
} catch (Throwable e) {
parserListener.onException((StructurizrDslParserException) e);
}
parserListener.onEndFile();
}

@After("within(com.structurizr.dsl.DslLine) && execution(* getSource())")
public void interceptGetSourceAfter() throws Exception {
public void interceptGetSourceAfter() {
parserListener.onNewLine();
}

Expand Down Expand Up @@ -188,7 +169,7 @@ public void interceptPersonParser(Person person) {

@AfterReturning(pointcut = "!within(com.structurizr.dsl.DslPackage) && !within(InterceptParserAspect) && target(com.structurizr.dsl.StructurizrDslParser) && execution(* preProcessLines(java.util.List<String>))", returning = "result")
public void interceptPreProcessLinesAfterReturning(Object result) {
LinkedList<Line> lines = DslPackage.processPreProcessLines(result);
List<Line> lines = DslPackage.processPreProcessLines(result);
parserListener.onLines(lines);
}

Expand Down Expand Up @@ -255,11 +236,16 @@ public void interceptAddFileAfter(File file) {
public Object interceptloadFromAround(ProceedingJoinPoint joinPoint) {
Object[] args = joinPoint.getArgs();
try {
return (String) joinPoint.proceed(args);
return joinPoint.proceed(args);
} catch (Throwable e) {
String themeLocation = (String)args[0];
int timeoutInMilliseconds = (int)args[1];
return Custom.getInstance().loadFrom(themeLocation, timeoutInMilliseconds);
}
}

@AfterReturning(pointcut = "withincode(* parse(java.util.List<String>, java.io.File, boolean, boolean)) && call(* java.lang.String.substring(int, int))", returning = "leadingSpace")
public void interceptSubstringAfter(String leadingSpace) {
parserListener.onLeadingSpace(leadingSpace.length());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package ru.beeatlas.c4.intercept;

import java.io.File;
import java.util.LinkedList;
import java.util.List;

import com.structurizr.model.Element;
Expand All @@ -28,7 +27,7 @@

public interface StructurizrDslParserListener {

default void onLines(LinkedList<Line> lines) { }
default void onLines(List<Line> lines) { }

default void onNewLine() { }

Expand Down Expand Up @@ -60,5 +59,5 @@ default void onEndFile() { }

default void onExtendsBy(File file) { }

default String findContent(File file) { return null; }
default void onLeadingSpace(int leadingSpace) { }
}
Loading