opal-tools icon indicating copy to clipboard operation
opal-tools copied to clipboard

Token replacement (e.g. #project.version# with the current version of the patch) of files via regular expressions

Open daust opened this issue 5 years ago • 3 comments

Christoph made a great suggestions to replace placeholders during 1.copy or 3.install.

This way we could use a placeholder like #project.version# in the definition of the APEX application: image

and replace this with the setting version in the opal-installer.json file: image

This way we can make sure that the version information is ALWAYS correctly propagated the to the installed APEX version. We could also use this to replace placeholders in the package files.

This can be done similar to the gradle build file that I am using. When building the software binaries and the distribution - zip file, I replace specific placeholder in some files, e.g. all files in the folder src/doc: image

This could be implemented for example like this:

  "replacements": [
    {
      "fileRegEx": "/sql/.*apex.*/.*f*sql",
      "tokens": [{"#project.version#": "1.1"}, {"#var2#": "value2"}]
    },

The token values could ideally pick up values from environment variables or application/version in this opal-installer.json file itself. With that approach we could also limit the replacement using regular expressions to the files that we want to be affected. Working with replacements of text snippets in files can also have undesired side effects.

daust avatar Dec 04 '20 11:12 daust

Moved to v2.7.0 so that we can push out all name changes to an official release. Further enhancements come later.

daust avatar Dec 11 '20 12:12 daust

Using https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/StringSubstitutor.html for substituting each attribute value seems to be good idea.

daust avatar Dec 11 '20 15:12 daust

Here are two more pointers:

  • https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/lookup/StrSubstitutor.html
  • https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/lookup/StrLookup.html

daust avatar Feb 01 '22 16:02 daust