钩子在Eclipse插件中保存动作
我想为Eclipse创建一个Google Closure Compiler插件。 我已经有一个弹出菜单项,可以将JavaScript文件编译为其缩小版本。 但是,如果每次保存*.js
都会自动生成缩小版本,那将非常有用。 我读/听说过自然和构建器,扩展点和IResourceChangeListener
。 但我没有设法弄清楚我应该使用什么,特别是如何使它工作。
是否有一个插件的工作示例执行“相同类型的事情”,所以我可以从那个或教程编写这样的?
通过下面的答案,我搜索了使用IResourceChangeListener
项目,并提出了以下代码:
清单: http : //codepaste.net/3yahwe
plugin.xml
: http : //codepaste.net/qek3rw
激活者: http : //codepaste.net/s7xowm
DummyStartup: http ://codepaste.net/rkub82
MinifiedJavascriptUpdater: http ://codepaste.net/koweuh
MinifiedJavascriptUpdater.java
中包含IResourceChangeListener
的代码,从未到达resourceChanged()
函数。
从这里回答http://www.eclipse.org/forums/index.php/t/362425/
解决方案是将代码放入激活器并摆脱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; } }
你想要一个建设者。 Eclipse广泛支持您想要做的事情,即随着事情的变化需要维护的生成工件的概念。 本文将帮助您入门(尽管它很老,但它完全准确)。
所有语言插件(JDT,CDT等)在编译代码时都会这样做。
- Maven依赖项未添加到WEB-INF / lib
- 在Eclipse上,“首选项 – >常规 – >工作区 – >使用本机挂钩或轮询刷新”是做什么的?
- 如何让JLabel显示在JButton上?
- Windows和Mac上的Android库项目
- Play Framework 2.1 Java / Eclipse:自动重新加载不起作用
- 在另一个项目Eclipse中调用一个类
- java.lang.ClassNotFoundException:org.springframework.web.servlet.DispatcherServlet错误
- 为SWT应用程序构建多平台可执行文件(Eclipse)
- Eclipse包资源管理器为空