eclipse plugin develop ---how to access eclipse workspace?(eclipse 插件开发)
来源:互联网 发布:淘宝客服投诉电话人工 编辑:程序博客网 时间:2024/05/21 19:23
在开发eclipse pluin的时候,某些情况下我们需要访问eclipse workspace,例如:在插件中以编程的方式调用ant命令等。
如何做到这一点?
public void execute(){
IWorkspace ws = ResourcesPlugin.getWorkspace();
IProject[] ps = ws.getRoot().getProjects();
System.out.println(ws.getRoot().getFullPath().makeAbsolute().toOSString());
for(int i=0;i<ps.length;i++){
IProject p = ps[i];
IPath location = p.getLocation();
IFile ifile = p.getFile("build.xml");
System.out.println(ifile.getLocation().toFile().getAbsolutePath());
File f = new File(ifile.getLocation().toFile().getAbsolutePath());
if(!f.exists()){
continue;
}
Project pro = new Project();
pro.setBasedir(location.toFile().getAbsolutePath());
pro.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
helper.parse(pro, f);
Hashtable tars = pro.getTargets();
System.out.println("name==="+name);
Target t = (Target) tars.get(name);
if(t==null){
return;
}
DefaultLogger consoleLogger = new DefaultLogger();
consoleLogger.setErrorPrintStream(System.err);
consoleLogger.setOutputPrintStream(System.out);
consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
pro.addBuildListener(consoleLogger);
pro.executeTarget(this.name);
break;
}
}
以上代码(单独编译不会通过,请把 name换位ant 的target)可以放到插件的代码中。
以上代码的含义:
获得eclipse workspace的引用,对workspace下的pronjects进行循环,如果该project下有build.xml并且 该文件中有name的target那么就以ant的方式调用,并把ant运行的输出输出到eclipse的console。
- eclipse plugin develop ---how to access eclipse workspace?(eclipse 插件开发)
- eclipse plugin develop
- how to debug eclipse plugin ;)
- how to access current Project in eclipse?
- eclipse plugin develop java.lang.NoClassDefFoundError
- Eclipse plugin插件安装
- hadoop eclipse plugin 插件
- eclipse plugin 插件 推荐
- eclipse maven plugin 插件
- Eclipse 插件 plugin
- Eclipse插件开发之plugin.xml进阶
- Eclipse Plugin 开发 备忘贴 (Contribution to Eclipse)
- How To Install Eclipse SVN And Trac Plugin
- How to install plugin for Eclipse from .zip
- Eclipse插件开发:关于警告“Discouraged access: *****”
- Eclipse plugin开发总结
- Eclipse插件开发 获取Workspace下所有的项目
- how to install eclipse
- 码率失真优化算法
- 程序“运行方式...”的替代
- 11/11/11/11/11(十一月十一日十一点十一分十一秒)
- 喷绘与写真的图象输出要求及注意事项
- 兔罝
- eclipse plugin develop ---how to access eclipse workspace?(eclipse 插件开发)
- 記得留存檔案11/11
- Java数组学习心得
- 2005.11.11
- Struts 体系结构与工作原理(图)
- 经典的色彩悖论
- 关于combox的map的设计
- Windows下完全删除ORACLE!
- Java编程思想读书笔记(第2-7章)一