Capture to save actions in Eclipse plugin

I want to create a Google Closure Compiler plugin for Eclipse. I already have a popup menu entry for compiling a JavaScript file into its shortened version. But it would be more useful if every time you save *.js , this mini-version will be generated automatically. I read / heard about nature and builders, extension points and IResourceChangeListener . But I was not able to figure out what I should use, and especially how to make it work.

Is there a working example of a plugin that does the โ€œsame thingโ€, so I can work with this or a tutorial to write one?

With the answer below, I searched for projects that use IResourceChangeListener , and came up with this code:

Manifesto: http://codepaste.net/3yahwe

plugin.xml : http://codepaste.net/qek3rw

Activator: http://codepaste.net/s7xowm

DummyStartup: http://codepaste.net/rkub82

MinifiedJavascriptUpdater: http://codepaste.net/koweuh

In MinifiedJavascriptUpdater.java , which contains the code for IResourceChangeListener , the resourceChanged() function will never be reached.

+6
source share
2 answers

The answer is from here http://www.eclipse.org/forums/index.php/t/362425/

The solution is to get the code in the activator and get rid of MinifiedJavascriptUpdater :

 package closure_compiler_save; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle */ public class Activator extends AbstractUIPlugin { // The plug-in ID public static final String PLUGIN_ID = "closure-compiler-save"; //$NON-NLS-1$ // The shared instance private static Activator plugin; /** * The constructor */ public Activator() { } //gets here @Override public void start(BundleContext context) throws Exception { super.start(context); Activator.plugin = this; ResourcesPlugin.getWorkspace().addResourceChangeListener(new IResourceChangeListener() { public void resourceChanged(IResourceChangeEvent event) { System.out.println("Something changed!"); } }); } @Override public void stop(BundleContext context) throws Exception { Activator.plugin = null; super.stop(context); } /** * Returns the shared instance * * @return the shared instance */ public static Activator getDefault() { return plugin; } } 
+5
source

To do this, you need a builder. Eclipse has extensive support for just what you want to do, the concept of generated artifacts that need to be maintained as things change. This document will help you get started (even if it is very old, it is completely accurate).

All language plugins (JDT, CDT, etc.) do such things when compiling the code.

+1
source

Source: https://habr.com/ru/post/917188/


All Articles