Patch / Merge plugin.properties file in plugin using snippet

In my plugin, de.support.help files are plugin.properties files. These property files include strings for the preference page.

I want to use this plugin for different clients, but the client name is inside the property files.

I want to fix property files using the eclipse fragment mechanism. As far as I can now the fragment plugin can fix the built-in plugin at runtime.

I have a plugin.properties file in the de.support.help plugin that includes the line

plugin.name = Copyright XYZ 

And I have fragemt de.support.help.fragment which includes a plugin.properties file with line

 plugin.name = Copyright ABC 

I expect the "Copyright ABC" line to be displayed at runtime, but it is not. I tested the same with Java classes, and I remember that it worked. The java code from the fragment was placed in the source plugin.

Do you have an idea to handle this? Or am I misunderstanding the mechanism of the fragment?

thanks

EDIT:

When I remove the plugin.properties file from the de.support.help plugin, it works as expected. The fragment file is copied to the plugin directory and used at runtime.

Or do I need to fix the somce eclipse class Can_fragments_be_used_to_patch_a_plug

+2
eclipse merge plugins fragment patch
source share
3 answers

Implementation i implemented as

First, find the custom fragment properties file and find the default properties file.

Code (folder names have been changed)

 public final class FrameworkMessages { private static final String BUNDLE_NAME = "de.rts.messages"; //$NON-NLS-1$ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); private static final String BUNDLE_FRAGMENT_NAME = "de.rts.fragment"; //$NON-NLS-1$ private FrameworkMessages() { } public static String getString(String key) { try { return ResourceBundle.getBundle(BUNDLE_FRAGMENT_NAME).getString(key); } catch (MissingResourceException e) { // Use messages in this plugin when no external fragment files can found } try { return RESOURCE_BUNDLE.getString(key); } catch (MissingResourceException e) { return '!' + key + '!'; } } public static String getString(String pKey, Object[] pArgument) { try { return MessageFormat.format(RESOURCE_BUNDLE.getString(pKey), pArgument); } catch (MissingResourceException e) { return '!' + pKey + '!'; } } } 
+1
source share

According to How to Internationalize an Eclipse Plug-In Article

The plug-in flag provides additional functionality to its target plug-in.
At runtime, these liners are included along with all dependent fragments.

These contributions may include contributions to the code and contributions of resources related to the plug-in, such as properties and HTML files.

In other words, the plugin has access to the contents of the fragment through the class loader plugins.

The Eclipse platform combines plug-in fragments in such a way that the runtime elements in the fragment increase the source target plug-in.
The target plugin does not move, delete, or change in any way.

Because the fragment resources are located at the class loader, the plug-in developer does not need to know whether the resources are loaded from the plug-in JAR file or one of its JAR files.


I suspect classLoader has detected plugin.name in the de.support.help plugin before the de.support.help.fragment .

At this point, I'm not sure that this can be done, since it was undertaken earlier (for the Eclipse CheckStyle plugin ) without much success.

+1
source share

You cannot replace the contents of a file with a fragment - add additional files. This is true for classes, file properties, images, ...

There are several standard methods for solving this problem:

  • You can add an extension point with this and other customer related information.
  • you can first find a special file, and that’s back to the general one - like Marcus did.
  • you may have an optional dependency on a plugin with relevant information.

I prefer the latter solution, as it also allows you to choose between alternative algorithms and other things that are not included in the .properties files ...

+1
source share

All Articles