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

Feature/sling 7768: String Interpolation for ETC Map #15

Merged
merged 15 commits into from Jan 28, 2020

Conversation

schaefa
Copy link
Contributor

@schaefa schaefa commented Jul 30, 2019

Fix for ticket: https://issues.apache.org/jira/browse/SLING-7768 providing a way to make /etc/map configurable for different environments.

schaefa and others added 9 commits July 6, 2018 12:15
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
…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
@schaefa schaefa requested a review from cziegeler July 31, 2019 19:02
@schaefa schaefa self-assigned this Jul 31, 2019
pom.xml Outdated
@@ -63,6 +63,32 @@
</execution>
</executions>
</plugin>
<!--
Copy link
Contributor

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

Copy link
Contributor Author

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. */
Copy link
Contributor

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

Copy link
Contributor Author

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 @@
/*
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor

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;
Copy link
Contributor

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

Copy link
Contributor Author

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"};
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

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")
Copy link
Contributor

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

Copy link
Contributor Author

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 {
Copy link
Contributor

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)

Copy link
Contributor Author

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.

Copy link
Contributor Author

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<>();
Copy link
Contributor

@cziegeler cziegeler Jan 23, 2020

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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);
}
// /**
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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));
Copy link
Contributor

Choose a reason for hiding this comment

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

ResourceUtil.getName() ?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@cziegeler cziegeler left a 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
Copy link

sonarcloud bot commented Jan 28, 2020

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 1 Security Hotspot to review)
Code Smell A 5 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@schaefa schaefa merged commit dc56b45 into master Jan 28, 2020
@schaefa schaefa deleted the feature/SLING-7768 branch January 28, 2020 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants