如何以编程方式从.zip文件导入Eclipse项目? [英] How do I import an Eclipse project from a .zip file programmatically?

查看:618
本文介绍了如何以编程方式从.zip文件导入Eclipse项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何从存档文件(一个 .zip )以编程方式导入Eclipse项目 - 我想做同样的事情导入向导确实,但是自动(使用向导定期重新导入同一个项目开始感觉真的很长)。我发现了一些相关问题(例如以编程方式将现有项目导入Eclipse ),但我不知道如何获得与 .zip 导入相同的事情。


$ b $我目前的想法如下:如果我可以从 .zip 获得项目描述,那么我可以以编程方式创建项目(根据引用的问题)。从那里,我希望我可以:





这是否有意义? (如果没有,请问我该怎么办?)如果是这样,我应该如何从 .zip 中获取项目描述?

解决方案

为什么值得,这似乎有效(预处理):

  IWorkspace workspace = this.project.getWorkspace(); 
IProjectDescription newProjectDescription = workspace.newProjectDescription(projectName);
IProject newProject = workspace.getRoot()。getProject(projectName);
newProject.create(newProjectDescription,null);
newProject.open(null);

zipFile = new ZipFile(workspace.getRoot()。getLocation()+/+ projectName +.zip);
IOverwriteQuery overwriteQuery = new IOverwriteQuery(){
public String queryOverwrite(String file){return ALL; }
};
ZipLeveledStructureProvider provider = new ZipLeveledStructureProvider(zipFile);
列表< Object> fileSystemObjects = new ArrayList< Object>();
枚举<?扩展ZipEntry> entries = zipFile.entries();
while(entries.hasMoreElements()){
fileSystemObjects.add((Object)entries.nextElement());
}
ImportOperation importOperation = new ImportOperation(newProject.getFullPath(),新的ZipEntry(projectName),provider,overwriteQuery,fileSystemObjects);
importOperation.setCreateContainerStructure(false);
importOperation.run(new NullProgressMonitor());


I'm trying to figure out how to import an Eclipse project from an archive file (a .zip) programmatically - I want to do the same thing the import wizard does, but automatically (re-importing the same project regularly using the wizard is starting to feel really long-winded). I've found some related questions (e.g. Programmatically importing an existing project into Eclipse), but I can't figure out how to get the same sort of thing working for the .zip import.

My current thinking is as follows: if I can get a project description from the .zip somehow, then I can programmatically create the project (as per the referenced question). From there, I'm hoping I can:

Does this make any sense? (If not, what should I be doing please?) If so, how should I be going about getting a project description from the .zip?

解决方案

For what it's worth, this seems to work (pre-tidying):

IWorkspace workspace = this.project.getWorkspace();
IProjectDescription newProjectDescription = workspace.newProjectDescription(projectName);
IProject newProject = workspace.getRoot().getProject(projectName);
newProject.create(newProjectDescription, null);
newProject.open(null);

zipFile = new ZipFile(workspace.getRoot().getLocation() + "/" + projectName + ".zip");
IOverwriteQuery overwriteQuery = new IOverwriteQuery() {
    public String queryOverwrite(String file) { return ALL; }
};
ZipLeveledStructureProvider provider = new ZipLeveledStructureProvider(zipFile);
List<Object> fileSystemObjects = new ArrayList<Object>();
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
    fileSystemObjects.add((Object)entries.nextElement());
}
ImportOperation importOperation = new ImportOperation(newProject.getFullPath(), new ZipEntry(projectName), provider, overwriteQuery, fileSystemObjects);
importOperation.setCreateContainerStructure(false);
importOperation.run(new NullProgressMonitor());

这篇关于如何以编程方式从.zip文件导入Eclipse项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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