Skip to content

Commit

Permalink
Javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
nixel2007 committed Jun 9, 2023
1 parent 41c6752 commit 9390f85
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 21 deletions.
5 changes: 4 additions & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@
import java.util.Map;
import java.util.Optional;

/**
* Поставщик линзы для запуска всех тестов в текущем файле.
*/
@Component
@RequiredArgsConstructor
@Slf4j
public class RunAllTestsCodeLensSupplier
implements CodeLensSupplier<DefaultCodeLensData> {

private static final String COMMAND_ID = "language-1c-bsl.languageServer.runAllTests";

private final TestRunnerAdapter testRunnerAdapter;
private final LanguageServerConfiguration configuration;
private final Resources resources;
Expand All @@ -58,7 +63,7 @@ public class RunAllTestsCodeLensSupplier
/**
* Обработчик события {@link LanguageServerInitializeRequestReceivedEvent}.
* <p>
* Анализирует параметры запроса и подготавливает данные для слежения за родительским процессом.
* Анализирует тип подключенного клиента и управляет применимостью линзы.
*
* @param event Событие
*/
Expand All @@ -72,16 +77,17 @@ public void handleEvent(LanguageServerInitializeRequestReceivedEvent event) {
clientIsSupported = "Visual Studio Code".equals(clientName);
}

@Override
public String getId() {
return "language-1c-bsl.languageServer.runAllTests";
}

/**
* {@inheritDoc}
*/
@Override
public boolean isApplicable(DocumentContext documentContext) {
return documentContext.getFileType() == FileType.OS && clientIsSupported;
}

/**
* {@inheritDoc}
*/
@Override
public List<CodeLens> getCodeLenses(DocumentContext documentContext) {

Expand All @@ -97,6 +103,9 @@ public List<CodeLens> getCodeLenses(DocumentContext documentContext) {
return List.of(toCodeLens(firstMethod, documentContext));
}

/**
* {@inheritDoc}
*/
@Override
public CodeLens resolve(DocumentContext documentContext, CodeLens unresolved, DefaultCodeLensData data) {
var path = Paths.get(documentContext.getUri());
Expand All @@ -108,22 +117,25 @@ public CodeLens resolve(DocumentContext documentContext, CodeLens unresolved, De

var command = new Command();
command.setTitle(resources.getResourceString(getClass(), "runAllTests"));
command.setCommand(getId());
command.setCommand(COMMAND_ID);
command.setArguments(List.of(Map.of("text", runText)));

unresolved.setCommand(command);

return unresolved;
}

/**
* {@inheritDoc}
*/
@Override
public Class<DefaultCodeLensData> getCodeLensDataClass() {
return DefaultCodeLensData.class;
}

private CodeLens toCodeLens(MethodSymbol method, DocumentContext documentContext) {
private static CodeLens toCodeLens(MethodSymbol method, DocumentContext documentContext) {

var codeLensData = new DefaultCodeLensData(documentContext.getUri(), getId());
var codeLensData = new DefaultCodeLensData(documentContext.getUri(), COMMAND_ID);

var codeLens = new CodeLens(method.getSubNameRange());
codeLens.setData(codeLensData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,17 @@
import java.util.Optional;
import java.util.stream.Collectors;

/**
* Поставщик линз для запуска теста по конкретному тестовому методу.
*/
@Component
@RequiredArgsConstructor
@Slf4j
public class RunTestCodeLensSupplier
implements CodeLensSupplier<RunTestCodeLensSupplier.RunTestCodeLensData> {

private static final String COMMAND_ID = "language-1c-bsl.languageServer.runTest";

private final TestRunnerAdapter testRunnerAdapter;
private final LanguageServerConfiguration configuration;
private final Resources resources;
Expand All @@ -64,7 +69,7 @@ public class RunTestCodeLensSupplier
/**
* Обработчик события {@link LanguageServerInitializeRequestReceivedEvent}.
* <p>
* Анализирует параметры запроса и подготавливает данные для слежения за родительским процессом.
* Анализирует тип подключенного клиента и управляет применимостью линзы.
*
* @param event Событие
*/
Expand All @@ -78,16 +83,17 @@ public void handleEvent(LanguageServerInitializeRequestReceivedEvent event) {
clientIsSupported = "Visual Studio Code".equals(clientName);
}

@Override
public String getId() {
return "language-1c-bsl.languageServer.runTest";
}

/**
* {@inheritDoc}
*/
@Override
public boolean isApplicable(DocumentContext documentContext) {
return documentContext.getFileType() == FileType.OS && clientIsSupported;
}

/**
* {@inheritDoc}
*/
@Override
public List<CodeLens> getCodeLenses(DocumentContext documentContext) {

Expand All @@ -105,11 +111,17 @@ public List<CodeLens> getCodeLenses(DocumentContext documentContext) {
.collect(Collectors.toList());
}

/**
* {@inheritDoc}
*/
@Override
public Class<RunTestCodeLensData> getCodeLensDataClass() {
return RunTestCodeLensData.class;
}

/**
* {@inheritDoc}
*/
@Override
public CodeLens resolve(DocumentContext documentContext, CodeLens unresolved, RunTestCodeLensData data) {

Expand All @@ -123,7 +135,7 @@ public CodeLens resolve(DocumentContext documentContext, CodeLens unresolved, Ru

var command = new Command();
command.setTitle(resources.getResourceString(getClass(), "runTest"));
command.setCommand(getId());
command.setCommand(COMMAND_ID);
command.setArguments(List.of(Map.of("text", runText)));

unresolved.setCommand(command);
Expand All @@ -133,7 +145,7 @@ public CodeLens resolve(DocumentContext documentContext, CodeLens unresolved, Ru

private CodeLens toCodeLens(MethodSymbol method, DocumentContext documentContext) {
var testId = method.getName();
var codeLensData = new RunTestCodeLensData(documentContext.getUri(), getId(), testId);
var codeLensData = new RunTestCodeLensData(documentContext.getUri(), COMMAND_ID, testId);

var codeLens = new CodeLens(method.getSubNameRange());
codeLens.setData(codeLensData);
Expand All @@ -153,6 +165,11 @@ public static class RunTestCodeLensData extends DefaultCodeLensData {
*/
String testId;

/**
* @param uri URI документа.
* @param id Идентификатор линзы.
* @param testId Идентификатор теста.
*/
@ConstructorProperties({"uri", "id", "testId"})
public RunTestCodeLensData(URI uri, String id, String testId) {
super(uri, id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
* Расчетчик списка тестов в документе.
* Физически выполняет команды по получению идентификаторов тестов на основании конфигурации.
*/
@Component
@RequiredArgsConstructor
@Slf4j
Expand All @@ -57,6 +61,12 @@ public class TestRunnerAdapter {

private final LanguageServerConfiguration configuration;

/**
* Получить идентификаторы тестов, содержащихся в файле.
*
* @param documentContext Контекст документа с тестами.
* @return Список идентификаторов тестов.
*/
public List<String> getTestIds(DocumentContext documentContext) {
var cacheKey = Pair.of(documentContext, documentContext.getVersion());

Expand All @@ -70,8 +80,7 @@ private List<String> computeTestIds(DocumentContext documentContext) {
var path = Paths.get(documentContext.getUri()).toString();
var arguments = String.format(options.getGetTestsArguments(), path);

var getTestsCommand = new CommandLine(executable)
.addArguments(arguments, false);
var getTestsCommand = new CommandLine(executable).addArguments(arguments, false);

var timeout = 10_000L;
var watchdog = new ExecuteWatchdog(timeout);
Expand Down Expand Up @@ -100,7 +109,7 @@ private List<String> computeTestIds(DocumentContext documentContext) {
}

var getTestsRegex = Pattern.compile(options.getGetTestsResultPattern());

Charset charset;
if (SystemUtils.IS_OS_WINDOWS) {
charset = Charset.forName("cp866");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* This file is a part of BSL Language Server.
*
* Copyright (c) 2018-2023
* Alexey Sosnoviy <[email protected]>, Nikita Fedkin <[email protected]> and contributors
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* BSL Language Server is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* BSL Language Server 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with BSL Language Server.
*/
/**
* Запуск инструментов тестирования.
*/
@DefaultAnnotation(NonNull.class)
package com.github._1c_syntax.bsl.languageserver.codelenses.testrunner;

import edu.umd.cs.findbugs.annotations.DefaultAnnotation;
import edu.umd.cs.findbugs.annotations.NonNull;
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class CodeLensOptions {
@JsonDeserialize(using = ParametersDeserializer.class)
private Map<String, Either<Boolean, Map<String, Object>>> parameters = new HashMap<>();

/**
* Параметры запускателя тестового фреймворка.
*/
@JsonProperty("testRunner")
private TestRunnerAdapterOptions testRunnerAdapterOptions = new TestRunnerAdapterOptions();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,45 @@
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.SystemUtils;

/**
* Параметры запускателя тестового фреймворка.
*/
@Data
@AllArgsConstructor(onConstructor = @__({@JsonCreator(mode = JsonCreator.Mode.DISABLED)}))
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class TestRunnerAdapterOptions {

/**
* Имя исполняемого файла тестового фреймворка (linux и macOS).
*/
private String executable = "1testrunner";
/**
* Имя исполняемого файла тестового фреймворка (windows).
*/
private String executableWin = "1testrunner.bat";
/**
* Аргументы для получения списка тестов.
*/
private String getTestsArguments = "-show %s";
/**
* Регулярное выражение для получения списка тестов.
*/
private String getTestsResultPattern = "^[^<]*Имя\\sтеста\\s<([^>]+)>.*";
/**
* Аргументы для запуска одного теста.
*/
private String runTestArguments = "-run %s %s";
/**
* Аргументы для запуска всех тестов.
*/
private String runAllTestsArguments = "-run %s";

/**
* Получить имя исполняемого файла тестового фреймворка для текущей ОС.
*
* @return Имя исполняемого файла тестового фреймворка для текущей ОС.
*/
public String getExecutableForCurrentOS() {
return SystemUtils.IS_OS_WINDOWS ? executableWin : executable;
}
Expand Down

0 comments on commit 9390f85

Please sign in to comment.