Advertisement
class101

Eclipse plugin to fix -plugincustomization option

Jul 19th, 2017
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.17 KB | None | 0 0
  1. /**
  2.  * This is an Eclipse plugin fixing an issue with the built-in eclipse.ini file and
  3.  * the option -plugincustomization /path/to/plugincustomization.ini where a few option
  4.  * are not read properly.
  5.  
  6.  * You can now store Eclipse perspectives properly, code cleanups, formatters aswell, maven M2E external install
  7.  * Also take cares to recurse into configuration nodes
  8.  *
  9.  * More infos or have questions use this link : https://bugs.eclipse.org/bugs/show_bug.cgi?id=281487
  10.  */
  11. public class Main implements IStartup {
  12.  
  13.     @SuppressWarnings("serial")
  14.     private final Map<String, String> buggedNameSpace = new HashMap<String, String>() {
  15.         {
  16.             // this.put("org.eclipse.jdt.ui",
  17.             // "sp_cleanup|java_|semanticHighlighting|editor_save_participant_org|formatter_|org.eclipse.jdt.ui.formatterprofiles");
  18.             this.put("org.eclipse.jdt.ui", "sp_cleanup|java_|semanticHighlighting|editor_save_participant_org");
  19.             this.put("org.eclipse.e4.ui.css.swt.theme", null);
  20.             this.put("org.eclipse.e4.ui.workbench.renderers.swt", null);
  21.             this.put("org.eclipse.wst.jsdt.ui", "java_|semanticHighlighting");
  22.             this.put("org.eclipse.jst.jsp.ui", null);
  23.             this.put("org.eclipse.wst.dtd.ui", null);
  24.             this.put("org.eclipse.wst.xml.ui", null);
  25.             this.put("org.eclipse.wst.xsl.ui", null);
  26.             this.put("org.eclipse.wst.css.ui", null);
  27.             this.put("org.eclipse.wst.html.ui", null);
  28.             this.put("org.eclipse.ant.ui", "org.eclipse.ant.ui");
  29.             this.put("org.eclipse.ui.workbench", "SDR");
  30.             this.put("org.eclipse.m2e.core", null);
  31.         }
  32.     };
  33.  
  34.     @Override
  35.     public void earlyStartup() {
  36.  
  37.         final Iterator<Entry<String, String>> it = this.buggedNameSpace.entrySet().iterator();
  38.  
  39.         while (it.hasNext()) {
  40.             final Map.Entry<String, String> pair = it.next();
  41.             final String nameSpace = pair.getKey();
  42.             final String[] filters = StringUtils.split(pair.getValue(), "|");
  43.  
  44.             this.start(nameSpace, filters);
  45.  
  46.             it.remove();
  47.         }
  48.  
  49.     }
  50.  
  51.     private void start(final String nameSpace, final String[] filters) {
  52.         final Preferences pluginCustomizationPreferences = DefaultScope.INSTANCE.getNode(nameSpace);
  53.         final Preferences workspacePreferences = InstanceScope.INSTANCE.getNode(nameSpace);
  54.  
  55.         try {
  56.             if (pluginCustomizationPreferences.childrenNames() != null && pluginCustomizationPreferences.childrenNames().length > 0) {
  57.                 for (int i = 0; i < pluginCustomizationPreferences.childrenNames().length; i++) {
  58.                     final String newNameSpace = nameSpace + "/" + pluginCustomizationPreferences.childrenNames()[i];
  59.                     if (StringUtils.isNotBlank(newNameSpace)) {
  60.                         this.start(newNameSpace, filters);
  61.                     }
  62.                 }
  63.             }
  64.         } catch (final BackingStoreException e1) {
  65.             e1.printStackTrace();
  66.         }
  67.  
  68.         try {
  69.             for (final String key : pluginCustomizationPreferences.keys()) {
  70.                 final String defaultPluginCustomizationValue = pluginCustomizationPreferences.get(key, StringUtils.EMPTY);
  71.                 if (StringUtils.isNotBlank(defaultPluginCustomizationValue) && (filters == null || StringUtils.startsWithAny(key, filters))) {
  72.                     workspacePreferences.put(key, defaultPluginCustomizationValue);
  73.                 }
  74.             }
  75.             workspacePreferences.flush();
  76.         } catch (final Exception e) {
  77.             e.printStackTrace();
  78.         }
  79.  
  80.     }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement