GeertPt
GeertPt

Reputation: 17874

Install4j custom action to merge new and old properties file

In install4j, we can set the Overwrite policy for a file "If newer, otherwise ask", or "Always ask", etc..

I want to upgrade an application which has a .properties configuration file that end users can edit. In newer versions, some properties will be added, but we don't want to update customized existing properties.

So I'd set the Overwrite policy to "never", and create a custom action to merge the new properties in. I could use the "Append text to a file", but I'd like to do it more dynamically, by comparing the old and the new file, and only append those properties whose keys do not exist in the old file.

So my questions:

  1. Can I detect if the action is called during an install or an upgrade?
  2. How can I get the content of the new file if it didn't overwrite the old file?

Upvotes: 1

Views: 586

Answers (1)

Ingo Kegel
Ingo Kegel

Reputation: 48105

Can I detect if the action is called during an install or an upgrade?

Yes, you can use

context.isUpdateInstallation()

in condition expressions or other scripts.

How can I get the content of the new file if it didn't overwrite the old file?

If a file is not installed, the content is not accessible. I would suggest the following:

  1. Install the properties file to a different path
  2. In the case of a new installation, copy it to the target path with a "Copy files" action
  3. In the case of the upgrade installation, merge the properties files
  4. In all cases, delete the template file from step 1 with a "Delete files" action

Upvotes: 1

Related Questions