maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kyle Marek <pspps...@gmail.com>
Subject Custom resource filters; multiple filters
Date Mon, 29 Jul 2019 21:23:11 GMT
Hello Maven Users,

Some context: We are developing a webapp which utilizes React for our UI 
component. It is an known/open issue that React applications need to 
know their deployment location when built, because resource paths are 
embedded into the build output.

See: https://github.com/facebook/create-react-app/issues/2353
See: 
https://web.archive.org/web/20190729194150/https://github.com/facebook/create-react-app/issues/2353



We've worked around the issue by setting our deployment path to some 
constant like PUBLIC_URL_REPLACE_ME and then using a Response filter to 
substitute the the value of request.getContextPath() of the relevant 
resources at run time.

We'd like to instead substitute JSP like "<%=request.getContextPath()%>" 
at build time instead of using a Response filter at run time. However, 
we also need to place a JSP page directive at the beginning of our 
resources to correct Content-Type and either disable or escape EL and 
such, so this isn't as simple as configuring React to use "@PUBLIC_URL@" 
and substituting with the built-in Maven Resources filtering.

I understand maven-resources-plugin supports the usage of one or more 
custom resource filters,

See: 
https://maven.apache.org/plugins/maven-resources-plugin/examples/custom-resource-filters.html
See: 
https://web.archive.org/web/20190729180428/https://maven.apache.org/plugins/maven-resources-plugin/examples/custom-resource-filters.html



but it is not clear to me how this is intended to work, or if its design 
even accomplishes the developers' intent.

For example, I would expect to use the Wrapper design pattern to wrap an 
InputStream or OutputStream as it is used to copy/filter the file 
contents to the destination during copy-resources. While this design 
pattern is supported by the involved MavenFileFilter [1], there is no 
code path from a custom MavenResourcesFiltering [2] implementation to 
add a FilterWrapper to the list [3].

I would expect to use mavenResourcesExecution.addFilterWrapper() in 
filterResources() of my custom MavenResourcesFiltering implementation, 
but custom filters are executed *after* DefaultMavenResourcesFiltering [4].

While the added FilterWrapper would be available to the custom 
MavenResourcesFiltering implementations, one of the implementations 
would need to *duplicate* the logic of DefaultMavenResourcesFiltering 
and do a *second* copy of all of the resources in order to correct the 
lack of custom FilterWrappers when DefaultMavenResourcesFiltering was 
executed. I do not think this approach is sensible, or the intention of 
the custom resources filters support.

Another approach I've seen involves extending 
DefaultMavenResourcesFiltering or DefaultMavenFileFilter with another 
class that takes on the same Plexus hint="default" [5] [6], but this 
approach doesn't even utilize the custom resources filter support 
(you're basically overriding an internal Maven component when doing 
this), nor can it compound unrelated filters.

In all cases, there does not appear to be a way configure custom 
resources filters per execution or per resource directory defined in the 
POM, and information about the resource, like file name, are not passed 
to FilterWrappers (which complicates my ability to correctly set 
Content-Type in the JSP page directive).

So... are these issues just untested oversights and the existing custom 
resources filters support is useless, or am I misunderstanding how they 
are *supposed* to be utilized?

Where do we (either our project, or Maven) go from here? Should this be 
brought to Maven Developer List for collaboration on improving the design?

Thank you,

Kyle Marek


[1]:

See: 
https://maven.apache.org/shared/maven-filtering/apidocs/org/apache/maven/shared/filtering/MavenFileFilter.html#copyFile(java.io.File,%20java.io.File,%20boolean,%20java.util.List,%20java.lang.String)
See: 
https://web.archive.org/web/20190729191655/https://maven.apache.org/shared/maven-filtering/apidocs/org/apache/maven/shared/filtering/MavenFileFilter.html#copyFile(java.io.File,%20java.io.File,%20boolean,%20java.util.List,%20java.lang.String)



[2]:

See: 
https://maven.apache.org/shared/maven-filtering/apidocs/org/apache/maven/shared/filtering/MavenResourcesFiltering.html
See: 
https://web.archive.org/web/20190729191210/https://maven.apache.org/shared/maven-filtering/apidocs/org/apache/maven/shared/filtering/MavenResourcesFiltering.html



[3]:

See: 
https://github.com/apache/maven-filtering/blob/0f4f3eda5b59a303f9657f1e38bff8e54956d377/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java#L233-L236
See: 
https://web.archive.org/web/20190729191319/https://github.com/apache/maven-filtering/blob/0f4f3eda5b59a303f9657f1e38bff8e54956d377/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java#L233-L236



[4]:

See: 
https://github.com/apache/maven-resources-plugin/blob/maven-resources-plugin-3.1.0/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java#L345-L347
See: 
https://web.archive.org/web/20190729191943/https://github.com/apache/maven-resources-plugin/blob/maven-resources-plugin-3.1.0/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java#L345-L347



[5]:

See: 
https://stackoverflow.com/questions/30798935/externalized-filters-when-building-a-maven-project/32184390#32184390
See: 
https://web.archive.org/web/20190729192250/https://stackoverflow.com/questions/30798935/externalized-filters-when-building-a-maven-project/32184390#32184390



[6]:

See: 
https://stackoverflow.com/questions/40216611/custom-mavenresourcesfiltering-hard-to-implement/40220837#40220837
See: 
https://web.archive.org/web/20190729192054/https://stackoverflow.com/questions/40216611/custom-mavenresourcesfiltering-hard-to-implement/40220837#40220837

See: 
https://jeremylong.github.io/velocity-whitespace-resource-filter/xref/org/owasp/maven/tools/VelocityWhitespaceFilter.html
See: 
https://web.archive.org/web/20190729192136/https://jeremylong.github.io/velocity-whitespace-resource-filter/xref/org/owasp/maven/tools/VelocityWhitespaceFilter.html

See: 
https://jeremylong.github.io/velocity-whitespace-resource-filter/xref/org/owasp/maven/tools/VelocityWhitespaceFilterWrapper.html
See: 
https://web.archive.org/web/20190729192214/https://jeremylong.github.io/velocity-whitespace-resource-filter/xref/org/owasp/maven/tools/VelocityWhitespaceFilterWrapper.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Mime
View raw message