generated from NicolaiRuckel/python-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sebastian Simon
committed
Oct 10, 2024
1 parent
7e1a83d
commit 84e98bf
Showing
7 changed files
with
146 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# This file is part of the CfgNet module. | ||
# | ||
# This program is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU General Public License as published by the Free Software | ||
# Foundation, either version 3 of the License, or (at your option) any later | ||
# version. | ||
# | ||
# This program 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 General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program. If not, see <https://www.gnu.org/licenses/>. | ||
import os | ||
from cfgnet.config_types.config_types import ConfigType | ||
from cfgnet.plugins.file_type.configparser_plugin import ConfigParserPlugin | ||
|
||
|
||
class GradlePlugin(ConfigParserPlugin): | ||
def __init__(self): | ||
super().__init__("gradle") | ||
|
||
def is_responsible(self, abs_file_path): | ||
file_name = os.path.basename(abs_file_path) | ||
return file_name == "gradle.properties" | ||
|
||
def get_config_type(self, option_name: str) -> ConfigType: | ||
|
||
if option_name.endswith(("home", "projectcachedir")): | ||
return ConfigType.PATH | ||
|
||
if option_name.endswith(("max")): | ||
return ConfigType.NUMBER | ||
|
||
if option_name.endswith(("console", "level", "mode")): | ||
return ConfigType.MODE | ||
|
||
if option_name.endswith("idletimeout"): | ||
return ConfigType.TIME | ||
|
||
# if option_name.endswith("user"): | ||
# return ConfigType.USERNAME | ||
|
||
# if option_name.endswith("password"): | ||
# return ConfigType.PASSWORD | ||
|
||
return ConfigType.UNKNOWN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# This file is part of the CfgNet module. | ||
# | ||
# This program is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU General Public License as published by the Free Software | ||
# Foundation, either version 3 of the License, or (at your option) any later | ||
# version. | ||
# | ||
# This program 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 General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
import os | ||
|
||
import pytest | ||
|
||
from cfgnet.plugins.concept.gradle_plugin import GradlePlugin | ||
from cfgnet.config_types.config_types import ConfigType | ||
from tests.utility.id_creator import make_id | ||
|
||
|
||
@pytest.fixture(name="get_plugin") | ||
def get_plugin_(): | ||
plugin = GradlePlugin() | ||
return plugin | ||
|
||
|
||
def test_is_responsible(get_plugin): | ||
plugin = get_plugin | ||
|
||
assert plugin.is_responsible("tests/files/gradle.properties") | ||
assert not plugin.is_responsible("tests/files/test.properties") | ||
|
||
|
||
def test_config_types(get_plugin): | ||
plugin = get_plugin | ||
gradle_file = os.path.abspath("tests/files/gradle.properties") | ||
artifact = plugin.parse_file(gradle_file, "gradle.properties") | ||
nodes = artifact.get_nodes() | ||
|
||
for node in nodes: | ||
print(node, node.config_type) | ||
|
||
name_node = next(filter(lambda x: x.id == make_id("gradle.properties", "appname", "MyApp"), nodes)) | ||
boolean_node = next(filter(lambda x: x.id == make_id("gradle.properties", "org.gradle.daemon", "true"), nodes)) | ||
time_node = next(filter(lambda x: x.id == make_id("gradle.properties", "org.gradle.daemon.idletimeout", "1000"), nodes)) | ||
version_node = next(filter(lambda x: x.id == make_id("gradle.properties", "projectversion", "1.0.0"), nodes)) | ||
user_node = next(filter(lambda x: x.id == make_id("gradle.properties", "systemprop.gradle.wrapperuser", "myuser"), nodes)) | ||
password_node = next(filter(lambda x: x.id == make_id("gradle.properties", "systemprop.gradle.wrapperpassword", "12345"), nodes)) | ||
|
||
assert name_node.config_type == ConfigType.NAME | ||
assert boolean_node.config_type == ConfigType.BOOLEAN | ||
assert time_node.config_type == ConfigType.TIME | ||
assert version_node.config_type == ConfigType.VERSION_NUMBER | ||
assert user_node.config_type == ConfigType.USERNAME | ||
assert password_node.config_type == ConfigType.PASSWORD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Project-wide Gradle settings | ||
org.gradle.daemon=true | ||
org.gradle.parallel=true | ||
org.gradle.configureondemand=true | ||
org.gradle.daemon.idletimeout=1000 | ||
|
||
# JVM memory settings | ||
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -Dfile.encoding=UTF-8 | ||
|
||
# Custom properties | ||
projectVersion=1.0.0 | ||
isRelease=false | ||
appName=MyApp | ||
|
||
systemProp.pts.enabled=true | ||
systemProp.log4j2.disableJmx=true | ||
systemProp.file.encoding = UTF-8 | ||
systemProp.gradle.wrapperUser=myuser | ||
systemProp.gradle.wrapperPassword=12345 |