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

Improve Javadoc etc #83

Merged
merged 2 commits into from
Mar 14, 2017
Merged

Improve Javadoc etc #83

merged 2 commits into from
Mar 14, 2017

Conversation

Emily-Jiang
Copy link
Member

No description provided.

@gunnarmorling
Copy link
Contributor

Hey Emily, could you commit with your e-mail address you are using here on GitHub, too? That way the commits will be properly attributed to you in the contribution history.

Copy link
Contributor

@gunnarmorling gunnarmorling left a comment

Choose a reason for hiding this comment

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

Hi Emily, added some comments inline. Most notably, I don't see the value of ConfigValue at this point.

*/
Optional<String> getString(String propertyName);
String getRawString(String propertyName);
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the rationale for changing it to not return Optional any more?

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume that the method is intended for debugging rather than for business logic, therefore it is counter-productive to wrap the result in an Optional. It would make even sense to me to rename the method to something much more complicated to discourage using the method in normal business logic :) But I'm serious - far too many people would use it for normal code if its name stays like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

it is counter-productive

Why is that? The value may be present or not, which is exactly the semantics of Optional. Optional was introduced to represent an optional return value; let's use it instead of requiring people to think about whether it can be null or not. Optional conveys that clearly.

Copy link
Contributor

@gunnarmorling gunnarmorling Mar 4, 2017

Choose a reason for hiding this comment

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

That said I'm unsure what's the use case for this method in the first place? Should it actually be present here if we are concerned about it being used? Raw values can be obtained from config sources so we may leave it out here in the first round and see whether there's actual demand for it?


UPDATE: I'll create a separate issue to facilitate a discussion on that last comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC, it is really meant for debugging purposes to see what is the final value over all config sources (even if multiple sources provide it), but before it goes into a converter. Since converters work with String, it's natural to return raw value as a String.

Maybe we should leave this method out for now, and only suggest that implementations provide vendor-specific means to access the final raw value, provided that it is only for debugging as I assume.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since converters work with String, it's natural to return raw value as a String.

That's what I meant above, I doubt basing it on String is the right thing to do. I've opened #87 to discuss this separately.

Copy link
Member Author

Choose a reason for hiding this comment

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

This method is useful for debugging purpose as commented by @OndrejM !

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could avoid the getRawString method in config-1.0 and rethink if we need to standardize this or leave it up to the implementations?

Copy link
Contributor

@keilw keilw Mar 14, 2017

Choose a reason for hiding this comment

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

Optional as mentioned in recent calls is quite ugly especially when you try to combine it with type-safety you quickly stretch it beyond its limit.
Typesafe Config just to give one example has String getString(String path); and getters for most other base types including primitives. ConfigObject getObject(String path); returns a ConfigObject which is a specialized ConfigValue And Object getAnyRef(String path); is the "raw" equivalent simply returning the underlying value as Object. No Optional, although the library is now strongly tailored to Java SE 8, e.g. HOCON dealing with java.time values like Duration or LocalDate.


import java.util.Optional;

public interface ConfigValue<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

If these are all the methods on ConfigValue, I don't see good reason for adding it at this point. You'll get the same functionality (and easier to use) when directly injecting values into beans. We should introduce ConfigValue if it provides additional value.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that adding ConfigValue in this PR doesn't make sense at all. It should be either in a separate PR, or coupled with the CDI PR (#42), where I already added it. I think that for a start, it makes sense to have it even with 2 methods, we can add more methods later.

@Emily-Jiang I suggest that you create a PR with ConfigValue against my repo, so that I update the existing PR #42.

I'd discuss direct injection separately, I created PR #86 for this reason.

Copy link
Member Author

Choose a reason for hiding this comment

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

@OndrejM I'll create this against your PR #42 and merge in.

Copy link
Member Author

Choose a reason for hiding this comment

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

ConfigValue can do the injection for the custom class type T. You can do
@Inject @ConfigProperty("myPropName") ConfigValue propValue;

also the injection can cope with dynamic changes.

* @param <T> Type of the configuration value
*/

import java.util.Optional;
Copy link
Contributor

Choose a reason for hiding this comment

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

The import should go before the JavaDoc.

* META-INF/services/javax.config.spi.ConfigSource</p>
* The other custom config source can be added programmatically via {@link org.eclipse.microprofile.config.ConfigProvider}.
* Other custom config source can be added programmatically via {@link org.eclipse.microprofile.config.ConfigProvider}.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would clarify that it is not possible to add a custom config source programmatically into the default config retrieved by ConfigProvider.getConfig(). It is only possible when building a completely new config instance.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it is possible. The calling of ConfigProvider.getConfig() should trigger the builder to add default configure sources and autodiscovered configure sources. Otherwise, the ConfigProvider.getConfig is not useful. Thoughts? We should clarify this.

Copy link
Contributor

Choose a reason for hiding this comment

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

See, that's why I recommended added more test code to demonstrate the usage. This part is not very clear to me. How can I change what is returned by ConfigProvider.getConfig() programmatically? I mean, can I somehow hook into the builder used to build that config, without adding config sources via the service locator? Would this work: ConfigProvider.getBuilder().withSources(myCustomSource); Config configWithMyCustomSource = ConfigProvider.getConfig(); ?

@@ -24,7 +24,7 @@
* <p>A Converter can specify a {@link javax.annotation.Priority}.
Copy link
Contributor

Choose a reason for hiding this comment

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

For supporting @priority, we should include common annotations JSR (JSR-250) into MP, thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see your point, but my experiences with 250 are very mixed.

There are several conflicting dependencies with (parts of) its types out there, some are even in the JDK itself. So it's very prone to cause classpath conflicts, i.e. users will end up with the same types being pulled in multiple times from several dependencies. Which is esp. an issue when thinking about Java 9 / Jigsaw. Hence I'd try to avoid that dependency as much as possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, but I don't see how we get @Priority annotation into MicroProfile then. Which API artifact would bring it? In the current state, there's no way to build an app with @Priority with just MP dependencies.

@gunnarmorling
Copy link
Contributor

gunnarmorling commented Mar 4, 2017 via email

@OndroMih
Copy link
Contributor

OndroMih commented Mar 4, 2017

@gunnarmorling The question is, does it have to be pulled in by the API itself?

I get it now. I was not sure if makes sense to instruct anyone to use @Priority if it is not provided by the container. But since it's an edge case and it is possible to provide the annotation within the application, I'm fine to leave the spec as is.

@Emily-Jiang Emily-Jiang force-pushed the emily-config branch 6 times, most recently from f3bab83 to 7567c03 Compare March 7, 2017 17:33
@Emily-Jiang
Copy link
Member Author

Wondering why my sign off failed ip-validation check? Any suggestions?

@gunnarmorling
Copy link
Contributor

gunnarmorling commented Mar 8, 2017 via email

@struberg
Copy link
Contributor

struberg commented Mar 8, 2017

+1, but please note that we should never squash history which contains commits of different persons as that would destroy code provenance. So please only squash your own commits.

@OndroMih
Copy link
Contributor

OndroMih commented Mar 8, 2017

What I do to pass eclipse IP checks is that I rebase my local branch interactively, and then re-commit each revision with the correct user (email) and sign-off. Then I force push my changes. Not ideal either, but the history is preserved. I don't know how that affects comments in the PR.

Signed-off-by: Emily Jiang <[email protected]>
@Emily-Jiang
Copy link
Member Author

thanks @gunnarmorling @struberg @OndrejM! Finally worked out! I ended up abandoned some commits and redo it under a different PR. I'm going to merge this javadoc changes.

@Emily-Jiang Emily-Jiang merged commit 821e515 into master Mar 14, 2017
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.

5 participants