【问题标题】:How do I import an Eclipse project from a .zip file programmatically?如何以编程方式从 .zip 文件导入 Eclipse 项目?
【发布时间】:2012-09-18 20:00:41
【问题描述】:

我正在尝试弄清楚如何以编程方式从存档文件 (.zip) 导入 Eclipse 项目 - 我想做导入向导所做的同样的事情,但自动执行(定期重新导入同一个项目使用向导开始感觉很啰嗦)。我发现了一些相关的问题(例如 Programmatically importing an existing project into Eclipse),但我不知道如何让 .zip 导入同样的事情。

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

这有意义吗? (如果不是,请问我应该怎么做?)如果是,我应该如何从.zip 获取项目描述?

【问题讨论】:

  • 假设您已经安装了 PDE SDK,一旦导入向导可见,您应该能够按 Ctrl-Alt-F1,从而获取向导页面类的名称,然后您可以查看内部巫师课是怎么回事。我发现代码检查通常比谷歌搜索更容易。 :)

标签: eclipse import eclipse-plugin


【解决方案1】:

对于它的价值,这似乎有效(预先整理):

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());

【讨论】:

    猜你喜欢
    • 2016-10-23
    • 2012-09-06
    • 1970-01-01
    • 2020-03-15
    • 1970-01-01
    • 1970-01-01
    • 2010-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多