Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plugin.properties mechanism in eclipse RCP

My project includes multiple plugins and every plugin includes the plugin.properties file with near to 20 translations. The MANIFEST.MF file defines the name of the properties files where the external plugin strings are stored.

Bundle-Localization: plugin

The name of the plugin i define like

%plugin.name

Eclipse will search the "%plugin.name" in the plugin.properties file at runtime.

Which class read out the MANIFEST.MF Bundle-Localization entry and at which point is the string with the starting '%' suffix is searched in the "plugin.properties" file?

I want to find and patch these class in that way, that i can first look into some other directories/files for the "%plugin.name" identifier. With these new mechanism i can add fragments to my product and overwrite single lines in a "plugin.properties" file without changing the original plugin. With these mechanism i could create a build process for multiple customers just by adding different fragments. The fragments including the customer names and special string they want to change.

I want to do it that way, because the fragment mechanism only add files to the original plugin. When the "plugin.properties" file is existing in the plugin, the fragment "plugin.properties" files are ignored.

UPDATE 1:

The method

class ManifestLocalization{
...
protected ResourceBundle getResourceBundle(String localeString) {
}
...
}

returns the ResourceBundle of the properties file for the given locale string. When somebody nows how i can now first look into the fragment to get the resource path please post it.

UPDATE 2:

The method in class ManifestLocalization

    private URL findInResolved(String filePath, AbstractBundle bundleHost) {

        URL result = findInBundle(filePath, bundleHost);
        if (result != null)
            return result;
        return findInFragments(filePath, bundleHost);
    }

Searchs for the properties file and cache it. The translations can than get from the cached file. The problem is, that the complete file is cached and not single translations.

A solution would be to first read the fragment file, than read the bundle file. When both files are existing merge them into one file and write the new properties file to the disk. The URL of the new properties file returns, so that the new propetries file can cached.

like image 489
Markus Lausberg Avatar asked Mar 23 '09 12:03

Markus Lausberg


People also ask

What is Eclipse RCP plugin?

The Eclipse Rich Client Platform (RCP) is a generic Java platform for running applications. It provides the basic blocks for building a rich client application GUI using the OSGi framework. Eclipse RCP is an SWT base for building GUI applications. Eclipse plug-ins extend the functionality of the Eclipse IDE.

How do I get Properties view in Eclipse?

Basic>Properties. Now goto Go to Window>Show View>Other... and select "Sample Category/Sample1 View" and you should see the view being shown below. When you select the "Button" in the view, notice that the properties view is changed to display the current properties of the button.

What are plugins in eclipse?

Plugin , which is an abstract class that provides generic facilities for managing plug-ins. An Eclipse installation includes a plugins folder where individual plug-ins are deployed. Each plug-in is installed in its own folder under the plugins folder. A plug-in is described in an XML manifest file, called plugin.

What is plugin XML in Eclipse?

The plug-in manifest file, plugin.xml, describes how the plug-in extends the platform, what extensions it publishes itself, and how it implements its functionality. The manifest file is written in XML and is parsed by the platform when the plug-in is loaded into the platform.


1 Answers

Although I got the information wrong ... I had exactly the same problem. The plugin is not activated twice and I cannot get to the fragments Bundle-Localization key.

I want all my language translations in the plugin.properties (I know this is frowned upon but it is much easier to manage a single file).

I (half)solved the problem by using

public void populate(Bundle bundle) {
    String localisation = (String) bundle.getHeaders().get("Bundle-Localization");
    Locale locale = Locale.getDefault();

    populate(bundle.getEntry(getFileName(localisation)));
    populate(bundle.getEntry(getFileName(localisation, locale.getLanguage())));
    populate(bundle.getEntry(getFileName(localisation, locale.getLanguage(), locale.getCountry())));
    populate(bundle.getResource(getFileName("fragment")));
    populate(bundle.getResource(getFileName("fragment", locale.getLanguage())));
    populate(bundle.getResource(getFileName("fragment", locale.getLanguage(), locale.getCountry())));
}

and simply call my fragment localisation file name 'fragment.properties'.

This is not particularly elegant, but it works.

By the way, to get files from the fragment you need the getResource, it seems that fragment files are on the classpath, or are only searched when using getResource.

If someone has a better approach, please correct me.

All the best,

Mark.

like image 199
Mark Miller Avatar answered Oct 03 '22 03:10

Mark Miller