-
Notifications
You must be signed in to change notification settings - Fork 592
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
Add support for default property values #2100
Conversation
- getIceProperty - getIcePropertyAsInt - getIcePropertyAsList
self.srcFile.write( | ||
r' new Property("/^%s\.%s/", false, null),\n' | ||
% (self.currentSection, self.fix(propertyName)) | ||
line = 'new Property("^{section}\\.{name}$", {defaultValue}, {deprecated}, {deprecatedBy})'.format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex for JavaScript was broken. The /XXX/
wrapping is incorrect.
/// @param key The property name. | ||
/// @param logWarnings Whether to log relevant warnings. | ||
/// @return The property if found, nullopt otherwise. | ||
optional<Property> findProperty(string_view key, bool logWarnings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the various languages, this lookup logic was only found in setProperty
. I've moved this code into a new function.
|
||
|
||
class PropertiesTestSuite(TestSuite): | ||
def setup(self, current): | ||
if isinstance(self.getMapping(), PhpMapping) or isinstance( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHP and Matlab don't have any config file tests
cpp/src/Ice/Properties.cpp
Outdated
/// @param key The ice property name. | ||
/// @return The default value for the property. | ||
/// @throws std::invalid_argument if the property is unknown. | ||
string getDefaultValue(string_view key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return a string_view since the backing type is a const char*?
csharp/src/Ice/PropertiesI.cs
Outdated
@@ -89,6 +106,12 @@ public string[] getPropertyAsList(string key) | |||
return getPropertyAsListWithDefault(key, null); | |||
} | |||
|
|||
public string[] getIcePropertyAsList(string key) | |||
{ | |||
string[] defaultList = IceUtilInternal.StringUtil.splitString(getDefaultProperty(key), ", \t\r\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the same as our splitSting deals with "quoted" properties.
csharp/src/Ice/Property.cs
Outdated
@@ -4,9 +4,10 @@ namespace IceInternal; | |||
|
|||
public sealed class Property | |||
{ | |||
public Property(string pattern, bool deprecated, string deprecatedBy) | |||
public Property(string pattern, string defaultValue, bool deprecated, string deprecatedBy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using a readonly record class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do that in a follow-up PR.
csharp/src/Ice/Property.cs
Outdated
@@ -17,6 +18,12 @@ public string | |||
return _pattern; | |||
} | |||
|
|||
public string | |||
defaultValue() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a C# property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll clean up this class in a follow-up pr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
// Check for case-insensitive match. | ||
|
||
if (IceUtilInternal::match( | ||
IceUtilInternal::toUpper(string{key}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can update toUpper/toLower to work with string_view in a follow up PR, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should get rid of this check entirely
cpp/src/Ice/PropertyNames.cpp
Outdated
// Copyright (c) ZeroC, Inc. All rights reserved. | ||
// | ||
// Generated by makeprops.py from file ../config/PropertyNames.xml, Fri Apr 26 11:24:58 2024 | ||
// Copyright (c) ZeroC, Inc. All rights reserved.// Generated by makeprops.py from file ./config/PropertyNames.xml, Wed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems there is a missing new line in the generator for this file.
cpp/src/Ice/PropertyNames.h
Outdated
// Copyright (c) ZeroC, Inc. All rights reserved. | ||
// | ||
// Generated by makeprops.py from file ../config/PropertyNames.xml, Fri Apr 26 11:24:58 2024 | ||
// Copyright (c) ZeroC, Inc. All rights reserved.// Generated by makeprops.py from file ./config/PropertyNames.xml, Wed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing new line in the generator
test(retryIntervals.size() == 1); | ||
test(retryIntervals[0] == "0"); | ||
cout << "ok" << endl; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be complete we should also test that you don't get the default when the property is set to a different value. But maybe not worth because the code is simple enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's needed. The rest of the tests will cover this when we start using it.
php/src/Properties.cpp
Outdated
Ice::PropertiesPtr _this = Wrapper<Ice::PropertiesPtr>::value(getThis()); | ||
assert(_this); | ||
|
||
string propName(name, nameLen); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we create a string_view?
Co-authored-by: Jose <[email protected]>
Co-authored-by: Jose <[email protected]>
5e368df
to
41bebb1
Compare
* Get an Ice property by key. If the property is not set, its default value is returned. | ||
* @param key The property key. | ||
* @return The property value or the default value. | ||
* @see #setProperty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should document @throws std::invalid_argument
for getIceXxx
methods.
// If the property is deprecated by another property, use the new property key | ||
if (prop != null && prop.deprecatedBy() != null) | ||
{ | ||
key = prop.deprecatedBy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unrelated to your changes, but the behavior here seems odd. The code assumes the new property values are compatible with the deprecated property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I want to get rid of this code as well.
This PR adds support for setting default property values in PropertyNames.xml.
I've only added a handful of defaults for now, we can add more in follow-up PRs.
In addition it also adds three new property functions for fetching these properties:
getIceProperty
getIcePropertyAsInt
getIcePropertyAsList
Additionally, JavaScript's
setProperty
validation was broken. I fixed it for this PR and will open an issue to fix 3.7.Fixe #2072