Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Системная информация. Часть1. #233

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from

Conversation

dmpas
Copy link
Collaborator

@dmpas dmpas commented Nov 26, 2022

No description provided.

@dmpas dmpas requested a review from otymko November 26, 2022 17:02
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

76.2% 76.2% Coverage
0.0% 0.0% Duplication

Copy link
Owner

@otymko otymko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmpas, начало положено, спасибо!

@GlobalContextClass
public class SystemEnvironmentGlobalContext implements AttachableContext {
public static final ContextInfo INFO = ContextInfo.createByClass(SystemEnvironmentGlobalContext.class);
private static final Map<String, String> environmentVariables = getEnvironmentVariablesSnapshot();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmpas, мне не очень нравится текущее решение с static field, т.к. при многократном использовании контекста будет будут просачиваться значения из других. Давай пока сделаем синглтон + todo на исправление с DI, потом переделаем.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужен какой-то стейт на процесс выполнения (


@ContextMethod(name = "УстановитьПеременнуюСреды", alias = "SetEnvironmentVariable")
public void setEnvironmentVariable(String name, String value) {
environmentVariables.put(name, value);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmpas, как это работает дальше? Ну изменили мы у себя кеш, а на систему как это влияет?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@otymko На систему никак не влияет.
В рамках работы движка скрипты будут получать значение, установленное внутри скрипта(движка).
При запуске процесса из скрипта в него будем передавать переменные отсюда.
Ну либо пилить нативную либу. Других вариантов гугель не предложил, так что тут либо костыли, либо C++

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmpas, а в оскрипте как?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@otymko в дотнете оно из коробки умеет ставить переменные среды в ОС

https://learn.microsoft.com/ru-ru/dotnet/api/system.environment.setenvironmentvariable?view=net-7.0

import java.util.TreeMap;

@GlobalContextClass
public class SystemEnvironmentGlobalContext implements AttachableContext {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmpas, добавь, плиз, jdoc

*/
public static PlatformType parse(String osName, boolean is64) {
var prepared = osName.toUpperCase();
if (prepared.contains("WINDOWS"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmpas, узоры: скобочки { }

*/
@ContextProperty(name = "КоличествоПроцессоров", alias = "ProcessorCount")
public int getProcessorCount() {
return Runtime.getRuntime().availableProcessors();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmpas, кстати, в v8 возвращается количество физический или логических процессоров?

*/
@ContextProperty(name = "ВремяРаботыСМоментаЗагрузки", alias = "TickCount")
public long getTickCount() {
return System.currentTimeMillis();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmpas, System.currentTimeMillis возвращает не ВремяРаботыСМоментаЗагрузки. Смотри как в https://github.com/oshi/oshi работает getSystemUptime

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно здесь закинуть нон-саппортед, а а отдельной задаче реализовать.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@otymko getSystemUptime - там ад, если честно. Куча if (os1) get_os1(); if (os2) get_os2();

import com.github.otymko.jos.runtime.context.TestScript;

@TestScript(script = "src/test/resources/tests/SystemInfo.os")
public class V8SystemInfoTest extends BaseScriptTest {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmpas, public можно убрать


Процедура ТестДолжен_ПолучитьВремяРаботыСМоментаЗагрузки() Экспорт
Си = Новый СистемнаяИнформация();
юТест.ПроверитьБольше(Си.ВремяРаботыСМоментаЗагрузки,0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmpas, плохой тестовый кейс (

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@otymko принял... придумаем лучше...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants