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

fix filtering of web resources using system properties and escaping #451

Merged
merged 1 commit into from
Mar 17, 2023

Conversation

jtnord
Copy link
Member

@jtnord jtnord commented Mar 15, 2023

  • Filtering webResources now consults System.getProperties() (again?)
  • Filtering is now escapable so you can write \${project.version} and not have it replaced by the project version. (this matches Mavens' default behaviour

Replaces code from plexus-util with maven-filtering.

The code still directly uses some plexus-util so the dependency is not removed but the comment was no longer correct so that was removed.

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@jtnord jtnord changed the title cccccbctuhtruclkrtlutufdjrekenhtcnfihniedbunreplace plexus-util filtering with maven-filtering replace plexus-util filtering with maven-filtering Mar 15, 2023
@jtnord jtnord removed the chore label Mar 15, 2023
@jtnord jtnord changed the title replace plexus-util filtering with maven-filtering fix filtering of web resources using system properties Mar 15, 2023
@@ -212,7 +217,6 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<!-- generated help mojo has a dependency on plexus utils -->
Copy link
Member Author

Choose a reason for hiding this comment

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

the generated file did not contain any plexus-util imports

src/it/warResources/verify.groovy Outdated Show resolved Hide resolved
src/it/warResources/verify.groovy Outdated Show resolved Hide resolved
@jtnord jtnord force-pushed the replace-filtering-2 branch 2 times, most recently from 1893d78 to d8aca59 Compare March 16, 2023 11:30
replace plexus-util filtering with maven-filtering

The code still in directly uses some plexus-util so the dependency is not removed
but the comment was no longer correct so that was removed.
@jtnord jtnord changed the title fix filtering of web resources using system properties fix filtering of web resources using system properties and escaping Mar 16, 2023
or
\@prop2\@ @prop2@
and these will be replaced at build time
it is even possible to use system properties
\@java.class.version\@ ${java.class.version}
\@java.vendor.url\@ ${java.vendor.url}
Copy link
Member Author

Choose a reason for hiding this comment

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

class version is of the JVM not the compiled classes - so this would on java17 etc. replaced with vendor.rul which is very jvm specific - but it is 2023 so if this is not a https:// url then someone should fix the JVM...

MavenResourcesExecution mavenResourcesExecution =
new MavenResourcesExecution(resources, webappDirectory, project, StandardCharsets.UTF_8.name(), filters,
Collections.emptyList(), session);
mavenResourcesExecution.setEscapeString("\\");
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 means we can escape things - which is what you would get with regular maven filtering.

technically this is a breaking change - but looking through projects of the 5 I found adding webResources non used filtering anyway... so making this compatible would appear to be overkill

An argument could be made therefor to remove this code entirely - but as the webResources are of type Resource it would mean we would take options that would be discarded.

// assert globalConfigHelp.contains("\\@java.class.version\\@ 55.0");
assert globalConfigHelp.contains('${prop1} hello');
assert globalConfigHelp.contains('@prop2@ goodbye');
assert globalConfigHelp.contains('@java.vendor.url@ https://');
Copy link
Member Author

Choose a reason for hiding this comment

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

showing a System property is now resolved.

assert globalConfigHelp.contains("\\@prop2\\@ goodbye");
// code claims to add System properties but this fails
// assert globalConfigHelp.contains("\\@java.class.version\\@ 55.0");
assert globalConfigHelp.contains('${prop1} hello');
Copy link
Member Author

Choose a reason for hiding this comment

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

the escapes are now working - so they get replaced with the literal (in other words the escape string is correctly removed.

@jtnord jtnord requested review from olamy and basil March 16, 2023 13:08
@basil basil merged commit cf6507d into jenkinsci:master Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants