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
Feature/sling 7768: String Interpolation for ETC Map #15
Conversation
This provides the ability to define placeholders that then can be used inside /etc/map to define environment w/o having to create multiple /etc/map trees.
…ated a test suite to test the String Interpolation Provider with Map Entries
…me of the unit tests to consolidate them
…ed some common test code into MockTestUtil class
…urceResolverTest to make sure the Sling Interpolation works with Resource Resolving
# Conflicts: # pom.xml # src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java # src/test/java/org/apache/sling/resourceresolver/impl/EtcMappingResourceResolverTest.java # src/test/java/org/apache/sling/resourceresolver/impl/SimpleValueMapImpl.java # src/test/java/org/apache/sling/resourceresolver/impl/mapping/AbstractMappingMapEntriesTest.java # src/test/java/org/apache/sling/resourceresolver/impl/mapping/EtcMappingMapEntriesTest.java # src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java # src/test/java/org/apache/sling/resourceresolver/util/MockTestUtil.java
…tests and fixed some merge problems
…uted the StringInterpolationProviderImpl to make it work
pom.xml
Outdated
@@ -63,6 +63,32 @@ | |||
</execution> | |||
</executions> | |||
</plugin> | |||
<!-- |
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.
Changes in the build should not be part of this PR - unless they are strictly required
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.
Done
@@ -107,6 +109,19 @@ | |||
@Reference | |||
EventAdmin eventAdmin; | |||
|
|||
/** Event admin. */ |
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.
Comment above seems to be wrong :) Please make the reference greedy and remove the commented out lines below
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.
Done
@@ -0,0 +1,154 @@ | |||
/* |
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.
It's ok to have a copy here for getting the functionality in, but we should rather directly use the class from Apache Felix by embedding just that class (and using the maven shade plugin to move it to a different package). But we can do this in a follow up commit
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 class is not exported from the Bundle (AFAI can tell) and so I could not use it.
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 reverted everything back to the code from Felix with the exception of added logging statements and constants
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 can embed it, exactly because it is not exported - but there is no strict need for it, other than to avoid code duplication - and as mentioned we can do this later on
@@ -140,8 +142,10 @@ | |||
|
|||
private boolean updateBloomFilterFile = false; | |||
|
|||
private StringInterpolationProvider stringInterpolationProvider; |
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 can be marked as final
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.
Done
"The key is not permitted to contain a '=' sign and the first occurrence of '=' " + | ||
"separates the key from the value. If no '=' is found the entire key / value pair " + | ||
"is dropped.") | ||
String[] placeHolderKeyValuePairs() default {"phv.default.host.name=localhost"}; |
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.
Do we really need such a default value?
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.
That was here because I wanted to illustrate it. I am going to remove it.
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.
Done
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 still see it :)
import java.util.Map; | ||
|
||
@Designate(ocd = StringInterpolationProviderConfiguration.class) | ||
@Component(name = "org.apache.sling.resourceresolver.impl.mapping.StringInterpolationProviderImpl") |
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.
name attribute is not needed
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.
Done
v = getVariableFromEnvironment(name); | ||
} else if (TYPE_PROP.equals(type)) { | ||
v = getVariableFromProperty(name); | ||
} else { |
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 define a type for this, like "config:" and not let all types fallback to this. The fallback prevents adding new types later on (if required)
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 did not like the fallback either but I wanted to avoid forcing the user to write 'config:' for each value. That said etc-mapping is not easy by any chance and so I guess we add that.
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.
Done. This required the tests to be adjusted as now $[config: is required.
/** Logger. */ | ||
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
|
||
private Map<String, String> placeholderEntries = new HashMap<>(); |
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.
You either need to make this a concurrent map or change the logic in activate as modified() can change the map while it is used
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.
Thanks for point this out
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.
Opted to replace the Map in activate (modified)
/** | ||
* Activates this component (called by SCR before) | ||
*/ | ||
@Activate |
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 suggest to change this to a constructor
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.
You want to make the activate method part of the constructor? Can OCD being part of the constructor?
int n = fullpath.lastIndexOf("/"); | ||
return fullpath.substring(n+1); | ||
} | ||
// /** |
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.
Please remove the commented code
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.
Not my change but will do
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.
Done
@@ -399,7 +400,7 @@ private Resource buildResource(String fullpath, Iterable<Resource> children) { | |||
@SuppressWarnings("unchecked") | |||
private Resource buildResource(String fullpath, Iterable<Resource> children, ResourceResolver resourceResolver, ResourceProvider<?> provider, String ... properties) { | |||
Resource resource = Mockito.mock(Resource.class); | |||
Mockito.when(resource.getName()).thenReturn(getName(fullpath)); | |||
Mockito.when(resource.getName()).thenReturn(getResourceName(fullpath)); |
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.
ResourceUtil.getName() ?
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 merge in some changes from master to make it easier to merge and so this is not a change of mine.
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.
Kept it as this was not my change
@@ -16,12 +16,40 @@ | |||
*/ | |||
package org.apache.sling.resourceresolver.impl.mapping; |
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 are a lot of changes in this test and I can't see whether these are just improvements or tests need to be adapted?
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.
As far as I can tell I did not change anything here beside that I might have removed commented out code.
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 are some additional tests cases to deal with types and defaults but the rest did change little.
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.
Lgtm, thanks @schaefa
SonarCloud Quality Gate failed. 0 Bugs |
Fix for ticket: https://issues.apache.org/jira/browse/SLING-7768 providing a way to make /etc/map configurable for different environments.