Skip to content

Commit

Permalink
[Misc] Fix location of template resources in platform-web-templates t…
Browse files Browse the repository at this point in the history
…o be consistent with other templates in other modules. Also makes the PageTest setup simpler, and makes way for flamingo skin templates.
  • Loading branch information
vmassol committed Apr 30, 2021
1 parent 2ea2ec2 commit bd419a5
Show file tree
Hide file tree
Showing 212 changed files with 3 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ public class PageTest
{
private static final String SKIN_PROPERTIES_PATH = "/skins/flamingo/skin.properties";

private static final String SKIN_FLAMINGO_PREFIX_PATH = "/skins/flamingo";

@InjectMockitoOldcore
protected MockitoOldcore oldcore;

Expand Down Expand Up @@ -339,18 +337,10 @@ protected void initializeEnvironmentResources() throws Exception
String resourceName = (String) invocation.getArguments()[0];
// Algorithm:
// - Try to load the passed resource name from the CL first
// - If the resource is a template (ends in .vm) then remove the /skins/flamingo prefix from the
// resource name and try again to load it from the CL
// - If not found, then let tests be able to override {@code getEnvironmentResource()}.
URL url = getClass().getResource(resourceName);
if (url == null) {
String shortName = getShortTemplateResourceName(resourceName);
if (shortName != null) {
url = getClass().getResource(shortName);
}
if (url == null) {
url = getEnvironmentResource(resourceName);
}
url = getEnvironmentResource(resourceName);
}
return url;
});
Expand All @@ -359,29 +349,15 @@ protected void initializeEnvironmentResources() throws Exception
String resourceName = (String) invocation.getArguments()[0];
// Algorithm:
// - Try to load the passed resource name from the CL first
// - If the resource is a template (ends in .vm) then remove the /skins/flamingo prefix from the
// resource name and try again to load it from the CL
// - If not found, then let tests be able to override {@code getEnvironmentResource()}.
InputStream is = getClass().getResourceAsStream(resourceName);
if (is == null) {
String shortName = getShortTemplateResourceName(resourceName);
if (shortName != null) {
is = getClass().getResourceAsStream(shortName);
}
if (is == null) {
is = getEnvironmentResourceAsStream(resourceName);
}
is = getEnvironmentResourceAsStream(resourceName);
}
return is;
});
}

private String getShortTemplateResourceName(String resourceName)
{
return resourceName.startsWith(SKIN_FLAMINGO_PREFIX_PATH) ?
StringUtils.substringAfter(resourceName, SKIN_FLAMINGO_PREFIX_PATH) : null;
}

protected URL getEnvironmentResource(String resourceName) throws Exception
{
// Tests should override this if they need to serve the resource from a location other than the classloader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<excludes>META-INF/**</excludes>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/${project.build.finalName}/templates</outputDirectory>
<outputDirectory>${project.build.directory}/${project.build.finalName}</outputDirectory>
</configuration>
</execution>
</executions>
Expand Down

0 comments on commit bd419a5

Please sign in to comment.