ScriptCollection 4.4.1__py3-none-any.whl → 4.4.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ScriptCollection/Executables.py +1 -1
- ScriptCollection/GeneralUtilities.py +13 -1
- ScriptCollection/Resources/CultureChooser/CultureChooser.js +0 -0
- ScriptCollection/Resources/CultureChooser/index.html +0 -0
- ScriptCollection/Resources/Dependencies/JRE/Version.txt +0 -0
- ScriptCollection/Resources/Dependencies/OpenAPIGenerator/Version.txt +0 -0
- ScriptCollection/Resources/Dependencies/PlantUML/Version.txt +0 -0
- ScriptCollection/Resources/Fonts/DejaVuSans-Bold.ttf +0 -0
- ScriptCollection/Resources/Fonts/DejaVuSans-BoldOblique.ttf +0 -0
- ScriptCollection/Resources/Fonts/DejaVuSans-Oblique.ttf +0 -0
- ScriptCollection/Resources/Fonts/DejaVuSans.ttf +0 -0
- ScriptCollection/Resources/Fonts/LICENSE.txt +0 -0
- ScriptCollection/Resources/MaintenanceSite/MaintenanceSite.html +0 -0
- ScriptCollection/SCLog.py +1 -1
- ScriptCollection/ScriptCollectionCore.py +117 -11
- ScriptCollection/TFCPS/DotNet/TFCPS_CodeUnitSpecific_DotNet.py +1 -1
- ScriptCollection/TFCPS/Flutter/TFCPS_CodeUnitSpecific_Flutter.py +1 -1
- ScriptCollection/TFCPS/Go/TFCPS_CodeUnitSpecific_Go.py +128 -47
- ScriptCollection/TFCPS/Maven/TFCPS_CodeUnitSpecific_Maven.py +139 -7
- ScriptCollection/TFCPS/NodeJS/TFCPS_CodeUnitSpecific_NodeJS.py +8 -2
- ScriptCollection/TFCPS/Rust/TFCPS_CodeUnitSpecific_Rust.py +169 -7
- ScriptCollection/TFCPS/TFCPS_CodeUnitSpecific_Base.py +10 -3
- ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py +3 -3
- ScriptCollection/TFCPS/TFCPS_Tools_General.py +126 -9
- ScriptCollection/TFCPS/TFCPS_VisualRegressionTests.py +446 -0
- ScriptCollection/TFCPS/TypeScript/TFCPS_CodeUnitSpecific_TypeScript.py +188 -0
- ScriptCollection/TFCPS/TypeScript/__init__.py +0 -0
- ScriptCollection/TestKind.py +41 -0
- {scriptcollection-4.4.1.dist-info → scriptcollection-4.4.4.dist-info}/METADATA +168 -168
- {scriptcollection-4.4.1.dist-info → scriptcollection-4.4.4.dist-info}/RECORD +22 -18
- {scriptcollection-4.4.1.dist-info → scriptcollection-4.4.4.dist-info}/WHEEL +0 -0
- {scriptcollection-4.4.1.dist-info → scriptcollection-4.4.4.dist-info}/entry_points.txt +0 -0
- {scriptcollection-4.4.1.dist-info → scriptcollection-4.4.4.dist-info}/top_level.txt +0 -0
|
@@ -1,34 +1,166 @@
|
|
|
1
|
-
|
|
1
|
+
import os
|
|
2
|
+
import re
|
|
3
|
+
import shutil
|
|
4
|
+
import requests
|
|
5
|
+
from lxml import etree
|
|
6
|
+
from ...GeneralUtilities import GeneralUtilities, Dependency
|
|
2
7
|
from ...SCLog import LogLevel
|
|
3
8
|
from ..TFCPS_CodeUnitSpecific_Base import TFCPS_CodeUnitSpecific_Base, TFCPS_CodeUnitSpecific_Base_CLI
|
|
4
9
|
|
|
5
10
|
class TFCPS_CodeUnitSpecific_Maven_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
11
|
+
"""Implements the tasks of a codeunit which contains a maven-project.
|
|
12
|
+
|
|
13
|
+
The maven-project is expected in "<codeunit>/<codeunit>" and it contains its testcases in its own
|
|
14
|
+
"src/test"-folder, because that is the layout maven defines and the layout jacoco measures the
|
|
15
|
+
coverage of without further configuration."""
|
|
16
|
+
|
|
17
|
+
__pom_namespace: str = "http://maven.apache.org/POM/4.0.0"
|
|
6
18
|
|
|
7
19
|
def __init__(self, current_file: str, verbosity: LogLevel, targetenvironmenttype: str, use_cache: bool, is_pre_merge: bool):
|
|
8
20
|
super().__init__(current_file, verbosity, targetenvironmenttype, use_cache, is_pre_merge)
|
|
9
21
|
|
|
22
|
+
@GeneralUtilities.check_arguments
|
|
23
|
+
def get_maven_project_folder(self) -> str:
|
|
24
|
+
"""Returns the folder which contains the pom-file of this codeunit."""
|
|
25
|
+
return os.path.join(self.get_codeunit_folder(), self.get_codeunit_name())
|
|
26
|
+
|
|
27
|
+
@GeneralUtilities.check_arguments
|
|
28
|
+
def get_pom_file(self) -> str:
|
|
29
|
+
return os.path.join(self.get_maven_project_folder(), "pom.xml")
|
|
30
|
+
|
|
10
31
|
@GeneralUtilities.check_arguments
|
|
11
32
|
def build(self) -> None:
|
|
12
|
-
|
|
33
|
+
maven_project_folder = self.get_maven_project_folder()
|
|
34
|
+
target_folder = os.path.join(self.get_artifacts_folder(), "BuildResult_Maven")
|
|
35
|
+
GeneralUtilities.ensure_directory_exists(target_folder)
|
|
36
|
+
# The testcases are executed by RunTestcases.py and not by the build, so that a failing testcase is reported
|
|
37
|
+
# by the quality-check and not by the build-step.
|
|
38
|
+
self.__run_maven("-B -DskipTests clean package")
|
|
39
|
+
build_output_folder = os.path.join(maven_project_folder, "target")
|
|
40
|
+
artifacts = [file for file in GeneralUtilities.get_direct_files_of_folder(build_output_folder) if file.endswith(".jar")]
|
|
41
|
+
GeneralUtilities.assert_condition(0 < len(artifacts), f'The maven-build did not produce a jar-file in "{build_output_folder}".')
|
|
42
|
+
for artifact in artifacts:
|
|
43
|
+
shutil.copyfile(artifact, os.path.join(target_folder, os.path.basename(artifact)))
|
|
44
|
+
self.__generate_bom_for_maven_project()
|
|
45
|
+
self.copy_source_files_to_output_directory()
|
|
46
|
+
|
|
47
|
+
@GeneralUtilities.check_arguments
|
|
48
|
+
def __generate_bom_for_maven_project(self) -> None:
|
|
49
|
+
codeunit_version = self.tfcps_Tools_General.get_version_of_codeunit(self.get_codeunit_file())
|
|
50
|
+
bom_folder = os.path.join(self.get_artifacts_folder(), "BOM")
|
|
51
|
+
GeneralUtilities.ensure_directory_exists(bom_folder)
|
|
52
|
+
self.__run_maven("-B org.cyclonedx:cyclonedx-maven-plugin:makeAggregateBom")
|
|
53
|
+
generated_bom_file = os.path.join(self.get_maven_project_folder(), "target", "bom.xml")
|
|
54
|
+
GeneralUtilities.assert_file_exists(generated_bom_file)
|
|
55
|
+
target_bom_file = os.path.join(bom_folder, f"{self.get_codeunit_name()}.{codeunit_version}.bom.xml")
|
|
56
|
+
shutil.copyfile(generated_bom_file, target_bom_file)
|
|
57
|
+
self._protected_sc.format_xml_file(target_bom_file)
|
|
13
58
|
|
|
14
59
|
@GeneralUtilities.check_arguments
|
|
15
60
|
def linting(self) -> None:
|
|
16
|
-
|
|
61
|
+
# checkstyle is configured in the pom-file of the codeunit, so that the ruleset belongs to the codeunit
|
|
62
|
+
# and not to this implementation.
|
|
63
|
+
self.__run_maven("-B checkstyle:check")
|
|
64
|
+
|
|
65
|
+
@GeneralUtilities.check_arguments
|
|
66
|
+
def do_common_tasks(self, current_codeunit_version: str) -> None:
|
|
67
|
+
self.do_common_tasks_base(current_codeunit_version)
|
|
68
|
+
self.__set_version_in_pom_file(self.get_version_of_project())
|
|
69
|
+
|
|
70
|
+
@GeneralUtilities.check_arguments
|
|
71
|
+
def generate_reference(self) -> None:
|
|
72
|
+
self.generate_reference_using_docfx()
|
|
17
73
|
|
|
18
74
|
@GeneralUtilities.check_arguments
|
|
19
75
|
def run_testcases(self) -> None:
|
|
20
|
-
|
|
76
|
+
codeunit_name = self.get_codeunit_name()
|
|
77
|
+
# "verify" is used instead of "test" because the report of jacoco is bound to that phase.
|
|
78
|
+
self.__run_maven("-B verify")
|
|
79
|
+
jacoco_file = os.path.join(self.get_maven_project_folder(), "target", "site", "jacoco", "jacoco.xml")
|
|
80
|
+
coverage_file = os.path.join(self.get_artifacts_folder(), "TestCoverage", "TestCoverage.xml")
|
|
81
|
+
GeneralUtilities.ensure_file_does_not_exist(coverage_file)
|
|
82
|
+
self.tfcps_Tools_General.convert_jacoco_report_to_cobertura_report(jacoco_file, coverage_file, codeunit_name, self.get_codeunit_folder(), [f"{codeunit_name}/src/main/java", f"{codeunit_name}/src/test/java"])
|
|
83
|
+
self.run_testcases_common_post_task(self.get_repository_folder(), codeunit_name, True, self.get_target_environment_type())
|
|
21
84
|
|
|
85
|
+
@GeneralUtilities.check_arguments
|
|
86
|
+
def __run_maven(self, arguments: str) -> None:
|
|
87
|
+
self._protected_sc.run_program("mvn", arguments, self.get_maven_project_folder(), print_live_output=self.get_verbosity() == LogLevel.Debug)
|
|
88
|
+
|
|
89
|
+
@GeneralUtilities.check_arguments
|
|
22
90
|
def get_dependencies(self) -> dict[str, set[str]]:
|
|
23
|
-
return
|
|
91
|
+
return GeneralUtilities.merge_dependency_lists([self.__get_dependencies_from_pom_file()])
|
|
92
|
+
|
|
93
|
+
@GeneralUtilities.check_arguments
|
|
94
|
+
def __get_dependencies_from_pom_file(self) -> list[Dependency]:
|
|
95
|
+
root: etree._ElementTree = etree.parse(self.get_pom_file())
|
|
96
|
+
namespaces = {"pom": TFCPS_CodeUnitSpecific_Maven_Functions.__pom_namespace}
|
|
97
|
+
result: list[Dependency] = []
|
|
98
|
+
for dependency in root.xpath("//pom:dependencies/pom:dependency", namespaces=namespaces):
|
|
99
|
+
group_id = dependency.xpath("./pom:groupId/text()", namespaces=namespaces)
|
|
100
|
+
artifact_id = dependency.xpath("./pom:artifactId/text()", namespaces=namespaces)
|
|
101
|
+
dependency_version = dependency.xpath("./pom:version/text()", namespaces=namespaces)
|
|
102
|
+
if len(group_id) == 0 or len(artifact_id) == 0:
|
|
103
|
+
continue
|
|
104
|
+
if len(dependency_version) == 0:
|
|
105
|
+
# The version of such a dependency comes from a parent-pom or from a dependency-management-section,
|
|
106
|
+
# so it can not be updated here.
|
|
107
|
+
continue
|
|
108
|
+
result.append(Dependency(f"{group_id[0]}:{artifact_id[0]}", str(dependency_version[0])))
|
|
109
|
+
return result
|
|
24
110
|
|
|
25
111
|
@GeneralUtilities.check_arguments
|
|
26
112
|
def get_available_versions(self, dependencyname: str) -> list[str]:
|
|
27
|
-
|
|
113
|
+
group_id, artifact_id = TFCPS_CodeUnitSpecific_Maven_Functions.__split_dependency_name(dependencyname)
|
|
114
|
+
# The maven-central-search-api answers with the released versions of an artifact, newest first.
|
|
115
|
+
response = requests.get("https://search.maven.org/solrsearch/select", params={"q": f'g:"{group_id}" AND a:"{artifact_id}"', "core": "gav", "rows": "200", "wt": "json"}, timeout=60)
|
|
116
|
+
response.raise_for_status()
|
|
117
|
+
result: list[str] = []
|
|
118
|
+
for found_artifact in response.json()["response"]["docs"]:
|
|
119
|
+
found_version = str(found_artifact["v"])
|
|
120
|
+
if re.match(r"^(\d+)\.(\d+)\.(\d+)$", found_version) is not None:
|
|
121
|
+
result.append(found_version)
|
|
122
|
+
elif re.match(r"^(\d+)\.(\d+)$", found_version) is not None:
|
|
123
|
+
result.append(found_version+".0")
|
|
124
|
+
elif re.match(r"^(\d+)$", found_version) is not None:
|
|
125
|
+
result.append(found_version+".0.0")
|
|
126
|
+
return result
|
|
28
127
|
|
|
29
128
|
@GeneralUtilities.check_arguments
|
|
30
129
|
def set_dependency_version(self, name: str, new_version: str) -> None:
|
|
31
|
-
|
|
130
|
+
group_id, artifact_id = TFCPS_CodeUnitSpecific_Maven_Functions.__split_dependency_name(name)
|
|
131
|
+
pom_file = self.get_pom_file()
|
|
132
|
+
root: etree._ElementTree = etree.parse(pom_file)
|
|
133
|
+
namespaces = {"pom": TFCPS_CodeUnitSpecific_Maven_Functions.__pom_namespace}
|
|
134
|
+
for dependency in root.xpath("//pom:dependencies/pom:dependency", namespaces=namespaces):
|
|
135
|
+
group_id_of_dependency = dependency.xpath("./pom:groupId/text()", namespaces=namespaces)
|
|
136
|
+
artifact_id_of_dependency = dependency.xpath("./pom:artifactId/text()", namespaces=namespaces)
|
|
137
|
+
version_element = dependency.xpath("./pom:version", namespaces=namespaces)
|
|
138
|
+
if len(group_id_of_dependency) == 0 or len(artifact_id_of_dependency) == 0 or len(version_element) == 0:
|
|
139
|
+
continue
|
|
140
|
+
if str(group_id_of_dependency[0]) == group_id and str(artifact_id_of_dependency[0]) == artifact_id:
|
|
141
|
+
version_element[0].text = new_version
|
|
142
|
+
root.write(pom_file, pretty_print=True, xml_declaration=True, encoding="UTF-8")
|
|
143
|
+
|
|
144
|
+
@GeneralUtilities.check_arguments
|
|
145
|
+
def __set_version_in_pom_file(self, new_version: str) -> None:
|
|
146
|
+
pom_file = self.get_pom_file()
|
|
147
|
+
root: etree._ElementTree = etree.parse(pom_file)
|
|
148
|
+
namespaces = {"pom": TFCPS_CodeUnitSpecific_Maven_Functions.__pom_namespace}
|
|
149
|
+
# Only the version of the project itself is set here. A version-element inside a dependency is not touched,
|
|
150
|
+
# which is why the version-element is taken from the project-element directly and not searched anywhere.
|
|
151
|
+
version_elements = root.xpath("/pom:project/pom:version", namespaces=namespaces)
|
|
152
|
+
GeneralUtilities.assert_condition(len(version_elements) == 1, f'The pom-file "{pom_file}" must contain exactly one version-element directly in its project-element.')
|
|
153
|
+
version_elements[0].text = new_version
|
|
154
|
+
root.write(pom_file, pretty_print=True, xml_declaration=True, encoding="UTF-8")
|
|
155
|
+
|
|
156
|
+
@staticmethod
|
|
157
|
+
@GeneralUtilities.check_arguments
|
|
158
|
+
def __split_dependency_name(dependencyname: str) -> tuple[str, str]:
|
|
159
|
+
"""A maven-dependency is identified by its group-id and its artifact-id, so both of them together are used as
|
|
160
|
+
dependency-name in the format "<group-id>:<artifact-id>"."""
|
|
161
|
+
parts = dependencyname.split(":")
|
|
162
|
+
GeneralUtilities.assert_condition(len(parts) == 2, f'The name of a maven-dependency must have the format "<group-id>:<artifact-id>" but was "{dependencyname}".')
|
|
163
|
+
return (parts[0], parts[1])
|
|
32
164
|
|
|
33
165
|
class TFCPS_CodeUnitSpecific_Maven_CLI:
|
|
34
166
|
|
|
@@ -18,6 +18,12 @@ class TFCPS_CodeUnitSpecific_NodeJS_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
|
18
18
|
|
|
19
19
|
@GeneralUtilities.check_arguments
|
|
20
20
|
def build(self) -> None:
|
|
21
|
+
# The sourcecode-artifact of a previous run is removed before the build, because it is a copy of the
|
|
22
|
+
# codeunit inside the codeunit and the build-tools do not know that it is only an artifact. An
|
|
23
|
+
# angular-library for example is built by ng-packagr, which searches the whole project-folder for
|
|
24
|
+
# "ng-package.json"-files to find the entry-points of the package, finds the copied one and aborts. The
|
|
25
|
+
# copy is written again at the end of this method, so nothing is lost.
|
|
26
|
+
GeneralUtilities.ensure_directory_does_not_exist(os.path.join(self.get_codeunit_folder(), "Other", "Artifacts", "SourceCode"))
|
|
21
27
|
self._protected_sc.run_with_epew("npm", "run build", self.get_codeunit_folder(),print_live_output=self.get_verbosity()==LogLevel.Debug,encode_argument_in_base64=True)
|
|
22
28
|
self.standardized_tasks_build_bom_for_node_project()
|
|
23
29
|
self.copy_source_files_to_output_directory()
|
|
@@ -25,13 +31,13 @@ class TFCPS_CodeUnitSpecific_NodeJS_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
|
25
31
|
@GeneralUtilities.check_arguments
|
|
26
32
|
def linting(self) -> None:
|
|
27
33
|
codeunit_folder = self.get_codeunit_folder()
|
|
28
|
-
self._protected_sc.
|
|
34
|
+
self._protected_sc.normalize_invisible_characters_of_files_in_folder(codeunit_folder, ["ts", "js", "css", "scss", "sass"])
|
|
29
35
|
# The OpenAPI-generator writes its '.openapi-generator/FILES' metadata-file with the host's native
|
|
30
36
|
# line-endings (CRLF on Windows, LF on Linux). Normalize it to LF like the other generated text-files
|
|
31
37
|
# so the committed file does not drift between build-hosts.
|
|
32
38
|
for openapi_generator_files_file in self._protected_sc.get_not_git_ignored_files_of_folder(codeunit_folder):
|
|
33
39
|
if os.path.basename(openapi_generator_files_file) == "FILES" and os.path.basename(os.path.dirname(openapi_generator_files_file)) == ".openapi-generator":
|
|
34
|
-
self._protected_sc.
|
|
40
|
+
self._protected_sc.normalize_invisible_characters(openapi_generator_files_file)
|
|
35
41
|
for html_file in self._protected_sc.get_not_git_ignored_files_of_folder(codeunit_folder, ".html"):
|
|
36
42
|
self._protected_sc.format_html_file(html_file, os.path.basename(html_file) == "index.html")
|
|
37
43
|
self._protected_sc.run_with_epew("npm", "run lint", codeunit_folder,print_live_output=self.get_verbosity()==LogLevel.Debug,encode_argument_in_base64=True)
|
|
@@ -1,34 +1,196 @@
|
|
|
1
|
-
|
|
1
|
+
import os
|
|
2
|
+
import re
|
|
3
|
+
import shutil
|
|
4
|
+
import requests
|
|
5
|
+
from lxml import etree
|
|
6
|
+
from ...GeneralUtilities import GeneralUtilities, Dependency
|
|
2
7
|
from ...SCLog import LogLevel
|
|
3
8
|
from ..TFCPS_CodeUnitSpecific_Base import TFCPS_CodeUnitSpecific_Base, TFCPS_CodeUnitSpecific_Base_CLI
|
|
4
9
|
|
|
5
10
|
class TFCPS_CodeUnitSpecific_Rust_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
11
|
+
"""Implements the tasks of a codeunit which contains a cargo-project.
|
|
12
|
+
|
|
13
|
+
The cargo-project is expected in "<codeunit>/<codeunit>" and it contains its testcases in the same
|
|
14
|
+
project, because that is the layout cargo defines: unit-tests live next to the code they test and
|
|
15
|
+
integration-tests live in the "tests"-folder of the project."""
|
|
6
16
|
|
|
7
17
|
def __init__(self, current_file: str, verbosity: LogLevel, targetenvironmenttype: str, use_cache: bool, is_pre_merge: bool):
|
|
8
18
|
super().__init__(current_file, verbosity, targetenvironmenttype, use_cache, is_pre_merge)
|
|
9
19
|
|
|
20
|
+
@GeneralUtilities.check_arguments
|
|
21
|
+
def get_cargo_project_folder(self) -> str:
|
|
22
|
+
"""Returns the folder which contains the Cargo.toml-file of this codeunit."""
|
|
23
|
+
return os.path.join(self.get_codeunit_folder(), self.get_codeunit_name())
|
|
24
|
+
|
|
25
|
+
@GeneralUtilities.check_arguments
|
|
26
|
+
def get_cargo_file(self) -> str:
|
|
27
|
+
return os.path.join(self.get_cargo_project_folder(), "Cargo.toml")
|
|
28
|
+
|
|
10
29
|
@GeneralUtilities.check_arguments
|
|
11
30
|
def build(self) -> None:
|
|
12
|
-
|
|
31
|
+
target_folder = os.path.join(self.get_artifacts_folder(), "BuildResult_Rust")
|
|
32
|
+
GeneralUtilities.ensure_directory_exists(target_folder)
|
|
33
|
+
self.__run_cargo("build --release")
|
|
34
|
+
# cargo puts the executable and the library of the release-profile directly into "target/release"; everything
|
|
35
|
+
# below that folder is intermediate build-output and is therefore not part of the artifact.
|
|
36
|
+
build_output_folder = os.path.join(self.get_cargo_project_folder(), "target", "release")
|
|
37
|
+
artifacts = [file for file in GeneralUtilities.get_direct_files_of_folder(build_output_folder) if TFCPS_CodeUnitSpecific_Rust_Functions.__file_is_build_artifact(file)]
|
|
38
|
+
GeneralUtilities.assert_condition(0 < len(artifacts), f'The cargo-build did not produce an artifact in "{build_output_folder}".')
|
|
39
|
+
for artifact in artifacts:
|
|
40
|
+
shutil.copyfile(artifact, os.path.join(target_folder, os.path.basename(artifact)))
|
|
41
|
+
self.__generate_bom_for_cargo_project()
|
|
42
|
+
self.copy_source_files_to_output_directory()
|
|
43
|
+
|
|
44
|
+
@staticmethod
|
|
45
|
+
@GeneralUtilities.check_arguments
|
|
46
|
+
def __file_is_build_artifact(file: str) -> bool:
|
|
47
|
+
# cargo writes further files (for example ".d"-dependency-files and the "*.pdb"-symbols on windows) next to the
|
|
48
|
+
# executable and the library, so the artifact is selected by its extension instead of taking everything.
|
|
49
|
+
extensions_of_artifacts = ("", ".exe", ".dll", ".so", ".dylib", ".a", ".lib", ".rlib")
|
|
50
|
+
return os.path.splitext(file)[1] in extensions_of_artifacts
|
|
51
|
+
|
|
52
|
+
@GeneralUtilities.check_arguments
|
|
53
|
+
def __generate_bom_for_cargo_project(self) -> None:
|
|
54
|
+
codeunit_version = self.tfcps_Tools_General.get_version_of_codeunit(self.get_codeunit_file())
|
|
55
|
+
bom_folder = os.path.join(self.get_artifacts_folder(), "BOM")
|
|
56
|
+
GeneralUtilities.ensure_directory_exists(bom_folder)
|
|
57
|
+
target_bom_file = os.path.join(bom_folder, f"{self.get_codeunit_name()}.{codeunit_version}.bom.xml")
|
|
58
|
+
self.__run_cargo("cyclonedx --format xml")
|
|
59
|
+
# cargo-cyclonedx writes its result into the folder of the cargo-project and derives the filename from the name
|
|
60
|
+
# of the crate, so the generated file is searched instead of being predicted from the name of the codeunit.
|
|
61
|
+
generated_bom_files = [file for file in GeneralUtilities.get_direct_files_of_folder(self.get_cargo_project_folder()) if file.endswith(".xml")]
|
|
62
|
+
GeneralUtilities.assert_condition(len(generated_bom_files) == 1, f'Expected exactly one generated bill-of-materials in "{self.get_cargo_project_folder()}" but found {len(generated_bom_files)}.')
|
|
63
|
+
shutil.move(generated_bom_files[0], target_bom_file)
|
|
64
|
+
self._protected_sc.format_xml_file(target_bom_file)
|
|
13
65
|
|
|
14
66
|
@GeneralUtilities.check_arguments
|
|
15
67
|
def linting(self) -> None:
|
|
16
|
-
|
|
68
|
+
# "--all-targets" includes the testcases in the check, and "-D warnings" makes clippy exit with a non-zero
|
|
69
|
+
# exit-code for a warning as well, because a warning is a linting-issue too.
|
|
70
|
+
self.__run_cargo("clippy --all-targets --all-features -- -D warnings")
|
|
71
|
+
|
|
72
|
+
@GeneralUtilities.check_arguments
|
|
73
|
+
def do_common_tasks(self, current_codeunit_version: str) -> None:
|
|
74
|
+
self.do_common_tasks_base(current_codeunit_version)
|
|
75
|
+
self.__set_version_in_cargo_file(self.get_version_of_project())
|
|
76
|
+
|
|
77
|
+
@GeneralUtilities.check_arguments
|
|
78
|
+
def generate_reference(self) -> None:
|
|
79
|
+
self.generate_reference_using_docfx()
|
|
17
80
|
|
|
18
81
|
@GeneralUtilities.check_arguments
|
|
19
82
|
def run_testcases(self) -> None:
|
|
20
|
-
|
|
83
|
+
codeunit_name = self.get_codeunit_name()
|
|
84
|
+
coverage_file = os.path.join(self.get_artifacts_folder(), "TestCoverage", "TestCoverage.xml")
|
|
85
|
+
GeneralUtilities.ensure_directory_exists(os.path.dirname(coverage_file))
|
|
86
|
+
GeneralUtilities.ensure_file_does_not_exist(coverage_file)
|
|
87
|
+
# cargo-llvm-cov runs the testcases and writes the coverage-report in the cobertura-format directly, so no
|
|
88
|
+
# conversion of the report-format is required here.
|
|
89
|
+
self.__run_cargo(f"llvm-cov --all-features --cobertura --output-path {coverage_file}")
|
|
90
|
+
GeneralUtilities.assert_file_exists(coverage_file)
|
|
91
|
+
self.__normalize_coverage_file(coverage_file)
|
|
92
|
+
self.run_testcases_common_post_task(self.get_repository_folder(), codeunit_name, True, self.get_target_environment_type())
|
|
21
93
|
|
|
94
|
+
@GeneralUtilities.check_arguments
|
|
95
|
+
def __normalize_coverage_file(self, coverage_file: str) -> None:
|
|
96
|
+
"""Makes the coverage-report which cargo-llvm-cov wrote match the expectations of the further processing:
|
|
97
|
+
it must contain exactly one package which is named like the codeunit, and the filename of a class must be
|
|
98
|
+
relative to the codeunit-folder (cargo-llvm-cov writes it relative to the cargo-project-folder)."""
|
|
99
|
+
codeunit_name = self.get_codeunit_name()
|
|
100
|
+
tree = etree.parse(coverage_file)
|
|
101
|
+
root = tree.getroot()
|
|
102
|
+
for package in root.findall(".//package"):
|
|
103
|
+
package.set("name", codeunit_name)
|
|
104
|
+
for class_element in root.findall(".//class"):
|
|
105
|
+
filename = class_element.get("filename")
|
|
106
|
+
if filename is not None:
|
|
107
|
+
filename_with_slashes = filename.replace("\\", "/")
|
|
108
|
+
class_element.set("filename", f"{codeunit_name}/{filename_with_slashes}")
|
|
109
|
+
class_element.set("name", os.path.basename(filename_with_slashes))
|
|
110
|
+
tree.write(coverage_file, pretty_print=True, xml_declaration=True, encoding="UTF-8")
|
|
111
|
+
self.tfcps_Tools_General.merge_packages(coverage_file, codeunit_name)
|
|
112
|
+
|
|
113
|
+
@GeneralUtilities.check_arguments
|
|
114
|
+
def __run_cargo(self, arguments: str) -> None:
|
|
115
|
+
self._protected_sc.run_program("cargo", arguments, self.get_cargo_project_folder(), print_live_output=self.get_verbosity() == LogLevel.Debug)
|
|
116
|
+
|
|
117
|
+
@GeneralUtilities.check_arguments
|
|
22
118
|
def get_dependencies(self) -> dict[str, set[str]]:
|
|
23
|
-
return
|
|
119
|
+
return GeneralUtilities.merge_dependency_lists([self.__get_dependencies_from_cargo_file()])
|
|
120
|
+
|
|
121
|
+
@GeneralUtilities.check_arguments
|
|
122
|
+
def __get_dependencies_from_cargo_file(self) -> list[Dependency]:
|
|
123
|
+
result: list[Dependency] = []
|
|
124
|
+
for section, name, dependency_version in self.__enumerate_dependency_entries():
|
|
125
|
+
GeneralUtilities.assert_condition(GeneralUtilities.string_has_content(section), "Internal error while reading the dependencies.")
|
|
126
|
+
result.append(Dependency(name, dependency_version))
|
|
127
|
+
return result
|
|
128
|
+
|
|
129
|
+
@GeneralUtilities.check_arguments
|
|
130
|
+
def __enumerate_dependency_entries(self) -> list[tuple[str, str, str]]:
|
|
131
|
+
"""Returns the dependencies of the cargo-file as tuples of the section they are declared in, their name and
|
|
132
|
+
their version. Only a dependency which declares a plain version-string is returned, because a dependency which
|
|
133
|
+
is declared as a table (for example a path- or git-dependency) has no version which could be updated."""
|
|
134
|
+
dependency_sections = ("dependencies", "dev-dependencies", "build-dependencies")
|
|
135
|
+
current_section: str = None
|
|
136
|
+
result: list[tuple[str, str, str]] = []
|
|
137
|
+
for line in GeneralUtilities.read_lines_from_file(self.get_cargo_file()):
|
|
138
|
+
stripped_line = line.strip()
|
|
139
|
+
if stripped_line.startswith("[") and stripped_line.endswith("]"):
|
|
140
|
+
current_section = stripped_line[1:-1].strip()
|
|
141
|
+
continue
|
|
142
|
+
if current_section not in dependency_sections or not GeneralUtilities.string_has_content(stripped_line) or stripped_line.startswith("#"):
|
|
143
|
+
continue
|
|
144
|
+
match = re.match(r'^([A-Za-z0-9_\-]+)\s*=\s*"([^"]+)"$', stripped_line)
|
|
145
|
+
if match is not None:
|
|
146
|
+
result.append((current_section, match.group(1), match.group(2)))
|
|
147
|
+
return result
|
|
24
148
|
|
|
25
149
|
@GeneralUtilities.check_arguments
|
|
26
150
|
def get_available_versions(self, dependencyname: str) -> list[str]:
|
|
27
|
-
|
|
151
|
+
# The crates.io-api answers with all published versions of a crate.
|
|
152
|
+
response = requests.get(f"https://crates.io/api/v1/crates/{dependencyname}/versions", headers={"User-Agent": "ScriptCollection"}, timeout=60)
|
|
153
|
+
response.raise_for_status()
|
|
154
|
+
result: list[str] = []
|
|
155
|
+
for found_version in response.json()["versions"]:
|
|
156
|
+
if found_version.get("yanked", False):
|
|
157
|
+
continue
|
|
158
|
+
version_string = str(found_version["num"])
|
|
159
|
+
if re.match(r"^(\d+)\.(\d+)\.(\d+)$", version_string) is not None:
|
|
160
|
+
result.append(version_string)
|
|
161
|
+
return result
|
|
28
162
|
|
|
29
163
|
@GeneralUtilities.check_arguments
|
|
30
164
|
def set_dependency_version(self, name: str, new_version: str) -> None:
|
|
31
|
-
|
|
165
|
+
cargo_file = self.get_cargo_file()
|
|
166
|
+
new_lines: list[str] = []
|
|
167
|
+
for line in GeneralUtilities.read_lines_from_file(cargo_file):
|
|
168
|
+
match = re.match(r'^(\s*)('+re.escape(name)+r')(\s*=\s*)"([^"]+)"(\s*)$', line)
|
|
169
|
+
if match is None:
|
|
170
|
+
new_lines.append(line)
|
|
171
|
+
else:
|
|
172
|
+
new_lines.append(f'{match.group(1)}{match.group(2)}{match.group(3)}"{new_version}"')
|
|
173
|
+
GeneralUtilities.write_lines_to_file(cargo_file, new_lines)
|
|
174
|
+
|
|
175
|
+
@GeneralUtilities.check_arguments
|
|
176
|
+
def __set_version_in_cargo_file(self, new_version: str) -> None:
|
|
177
|
+
cargo_file = self.get_cargo_file()
|
|
178
|
+
new_lines: list[str] = []
|
|
179
|
+
is_in_package_section: bool = False
|
|
180
|
+
version_was_set: bool = False
|
|
181
|
+
for line in GeneralUtilities.read_lines_from_file(cargo_file):
|
|
182
|
+
stripped_line = line.strip()
|
|
183
|
+
if stripped_line.startswith("[") and stripped_line.endswith("]"):
|
|
184
|
+
is_in_package_section = stripped_line[1:-1].strip() == "package"
|
|
185
|
+
# Only the version in the package-section is the version of the project itself; a version in a
|
|
186
|
+
# dependency-section belongs to a dependency and must not be changed here.
|
|
187
|
+
if is_in_package_section and re.match(r'^version\s*=\s*"[^"]+"$', stripped_line) is not None:
|
|
188
|
+
new_lines.append(f'version = "{new_version}"')
|
|
189
|
+
version_was_set = True
|
|
190
|
+
else:
|
|
191
|
+
new_lines.append(line)
|
|
192
|
+
GeneralUtilities.assert_condition(version_was_set, f'The cargo-file "{cargo_file}" does not contain a version in its package-section.')
|
|
193
|
+
GeneralUtilities.write_lines_to_file(cargo_file, new_lines)
|
|
32
194
|
|
|
33
195
|
class TFCPS_CodeUnitSpecific_Rust_CLI:
|
|
34
196
|
|
|
@@ -109,12 +109,17 @@ class TFCPS_CodeUnitSpecific_Base(ABC):
|
|
|
109
109
|
def get_version_of_project(self)->str:
|
|
110
110
|
return self.tfcps_Tools_General.get_version_of_project(self.get_repository_folder())
|
|
111
111
|
|
|
112
|
+
@staticmethod
|
|
113
|
+
@GeneralUtilities.check_arguments
|
|
114
|
+
def get_expected_xsd_address(codeunitspecificationversion:str)->str:
|
|
115
|
+
"""Returns the address of the xsd-file against which a codeunit-file which uses the given codeunit-specification-version must be validated."""
|
|
116
|
+
return f"https://projects.aniondev.de/PublicProjects/Common/ProjectTemplates/-/raw/v{codeunitspecificationversion}/Conventions/RepositoryStructure/CommonProjectStructure/codeunit.xsd"
|
|
117
|
+
|
|
112
118
|
@staticmethod
|
|
113
119
|
@GeneralUtilities.check_arguments
|
|
114
120
|
def get_expected_schemalocation(codeunitspecificationversion:str)->str:
|
|
115
121
|
"""Returns the value which the xsi:schemaLocation-attribute of a codeunit-file must have when the codeunit-file uses the given codeunit-specification-version."""
|
|
116
|
-
|
|
117
|
-
return f"{TFCPS_CodeUnitSpecific_Base.codeunit_namespace} {xsd_address}"
|
|
122
|
+
return f"{TFCPS_CodeUnitSpecific_Base.codeunit_namespace} {TFCPS_CodeUnitSpecific_Base.get_expected_xsd_address(codeunitspecificationversion)}"
|
|
118
123
|
|
|
119
124
|
@GeneralUtilities.check_arguments
|
|
120
125
|
def do_common_tasks_base(self,current_codeunit_version:str):
|
|
@@ -155,7 +160,9 @@ class TFCPS_CodeUnitSpecific_Base(ABC):
|
|
|
155
160
|
actual_schemalocation = " ".join(str(schemaLocation).split())
|
|
156
161
|
if actual_schemalocation != expected_schemalocation:
|
|
157
162
|
raise ValueError(f'The schema-location must be "{expected_schemalocation}" to match the codeunit-specification-version {supported_codeunitspecificationversion} but was "{actual_schemalocation}".')
|
|
158
|
-
|
|
163
|
+
# The schema-location consists of the namespace and the address of the xsd-file, but xmlschema expects only the address of the xsd-file
|
|
164
|
+
# as schema-source. Passing the whole schema-location made xmlschema download the namespace-uri (which is a html-page) and fail to parse it.
|
|
165
|
+
xmlschema.validate(codeunit_file, TFCPS_CodeUnitSpecific_Base.get_expected_xsd_address(supported_codeunitspecificationversion))
|
|
159
166
|
# TODO check if the properties codeunithastestablesourcecode, codeunithasupdatabledependencies, throwexceptionifcodeunitfilecannotbevalidated, developmentState and description exist and the values are valid
|
|
160
167
|
except Exception as exception:
|
|
161
168
|
self._protected_sc.log.log_exception(f'Codeunitfile "{codeunit_file}" can not be validated due to the following exception:', exception,LogLevel.Warning)
|
|
@@ -250,7 +250,7 @@ class TFCPS_CodeUnit_BuildCodeUnits:
|
|
|
250
250
|
self.sc.format_json_file(workspace_file)
|
|
251
251
|
|
|
252
252
|
#TODO add option to define exceptions (means: files which should not be normalized).
|
|
253
|
-
self.sc.
|
|
253
|
+
self.sc.normalize_invisible_characters_of_files_in_folder(self.repository, ["txt", "md", "py", "json", "xml", "svg", "csv", "yml", "yaml", "toml","gitignore", "gitattributes", "code-workspace"])
|
|
254
254
|
|
|
255
255
|
@GeneralUtilities.check_arguments
|
|
256
256
|
def is_working_branch(self)->bool:
|
|
@@ -307,7 +307,7 @@ class TFCPS_CodeUnit_BuildCodeUnits:
|
|
|
307
307
|
openspec_configuration_file: str = os.path.join(self.repository, "openspec", "config.yaml")
|
|
308
308
|
if os.path.isfile(openspec_configuration_file):
|
|
309
309
|
self.sc.log.log("Update openspec-instruction-files...")
|
|
310
|
-
self.sc.
|
|
310
|
+
self.sc.run_with_epew("openspec", "update --force", self.repository)
|
|
311
311
|
|
|
312
312
|
@GeneralUtilities.check_arguments
|
|
313
313
|
def build_codeunits_in_container(self,base_mount_folder:str) -> tuple[bool, str]:
|
|
@@ -461,7 +461,7 @@ class TFCPS_CodeUnit_BuildCodeUnits:
|
|
|
461
461
|
loc=splitted[2]
|
|
462
462
|
csv_lines.append(f"{v},{t},{loc}")
|
|
463
463
|
GeneralUtilities.write_lines_to_file(loc_data_file,csv_lines)
|
|
464
|
-
self.sc.
|
|
464
|
+
self.sc.normalize_invisible_characters(loc_data_file) # ensure the generated LoC-diagram-csv always uses LF line-endings
|
|
465
465
|
diagram_json = {
|
|
466
466
|
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
|
|
467
467
|
"description": "Lines of Code over time",
|