|
14 | 14 | import os |
15 | 15 | from typing import Optional, Union |
16 | 16 | from pydantic import BaseModel, Field, ConfigDict, field_validator |
| 17 | +import javaproperties as jp |
17 | 18 |
|
18 | 19 |
|
19 | 20 | class PropertiesBase(BaseModel): |
@@ -71,32 +72,6 @@ def read_properties_txt(properties_url): |
71 | 72 |
|
72 | 73 | return r.text |
73 | 74 |
|
74 | | -def parse_text(properties_raw): |
75 | | - field_pattern = re.compile(r"^([a-zA-z]+)\s*=(.*)") |
76 | | - |
77 | | - properties_dict = {} |
78 | | - field_name = "" |
79 | | - field_value = "" |
80 | | - properties_lines = properties_raw.split('\n') |
81 | | - for line in properties_lines: |
82 | | - if line.startswith('#') or not line.strip(): |
83 | | - continue |
84 | | - if line_match := field_pattern.match(line): |
85 | | - # store previous key-value pair |
86 | | - if field_name: |
87 | | - properties_dict[field_name] = field_value |
88 | | - # process current line |
89 | | - field_name = line_match[1].strip() |
90 | | - field_value = line_match[2].strip() |
91 | | - field_value = field_value.split('#')[0].strip() |
92 | | - else: |
93 | | - field_value += " " + line.strip() |
94 | | - # store last key-pair |
95 | | - if field_name: |
96 | | - properties_dict[field_name] = field_value |
97 | | - |
98 | | - return properties_dict |
99 | | - |
100 | 75 | def validate_existing(properties_dict): |
101 | 76 | # validation on existing contribution is weaker |
102 | 77 | properties = PropertiesExisting.model_validate(properties_dict) |
@@ -151,9 +126,9 @@ def set_output_error(msg): |
151 | 126 |
|
152 | 127 | try: |
153 | 128 | if type_ == 'library': |
154 | | - props = validate_new_library(parse_text(properties_raw)) |
| 129 | + props = validate_new_library(jp.loads(properties_raw)) |
155 | 130 | else: |
156 | | - props = validate_new(parse_text(properties_raw)) |
| 131 | + props = validate_new(jp.loads(properties_raw)) |
157 | 132 | except Exception as e: |
158 | 133 | set_output_error(f'Errors when parsing file. Please check all required fields, and file format.\n\n{e}') |
159 | 134 | raise e |
|
0 commit comments