通过使用片段在插件中修补/合并plugin.properties文件 [英] Patch/Merge plugin.properties file in plugin by using fragment

查看:140
本文介绍了通过使用片段在插件中修补/合并plugin.properties文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的插件中,de.support.help是plugin.properties文件。
这些属性文件包括首选项页面的字符串。



我想为不同的客户使用此插件,但客户名称在属性文件中。



我想使用eclipse片段机制来修补属性文件。至于我现在,片段插件可以在运行时修补相应的插件。



我的插件de.support.help中包含了plugin.properties文件,其中包括该行

  plugin.name =版权所有XYZ 

我有fragemt de.support.help.fragment,其中包含文件plugin.properties,行

  plugin.name =版权所有ABC 

我期望在运行时的字符串版权ABC 显示,但不是。我很久以前用java类测试过,我记得他的工作。来自片段的java代码被放置到原始插件。



你有什么想法来处理吗?或者我误解了片段机制?



谢谢



编辑: p>

当我从de.support.help插件中删除plugin.properties文件时,它按预期工作。片段文件被复制到插件目录中,并在运行时使用。



或者我必须修补somce eclipse类 Can_fragments_be_used_to_patch_a_plug

解决方案

解决方案我已经实现了像



首先查找特殊的片段属性文件,而不是查找默认属性文件。



代码是(Bundle名称被更改)

  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){
//在没有可以找到外部片段文件的情况下使用此插件中的邮件
}

尝试{
返回RESOURCE_BUNDLE .getString(键);
} 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 +'!';
}
}
}


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

I want to use this plugin for different customers, but the customer name is inside the properties files.

I want to patch the properties files by using the eclipse fragment mechanism. As far as i now the fragment plugin can patch the coresponding plugin at runtime.

I do have the file plugin.properties in plugin de.support.help which includes the line

plugin.name = Copyright XYZ

And i do have the fragemt de.support.help.fragment which includes the file plugin.properties with line

plugin.name = Copyright ABC

I expect that at runtime the string "Copyright ABC" is shown, but it is not. I had tested the same with java classes a long time ago and i remember that t his was working. The java code from the fragment was placed to the original plugin.

Do you have any idea to handle this? Or do i misunderstand the fragment mechanism?

Thanks

EDIT:

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

Or do i have to patch the somce eclipse class Can_fragments_be_used_to_patch_a_plug

解决方案

The solution i have implemented is like

First look for special fragment property file and than look for the default property file.

The code is (Bundle names were 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 + '!';
        }
    }
}

这篇关于通过使用片段在插件中修补/合并plugin.properties文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆