Skip to content

Instantly share code, notes, and snippets.

@basilevs
Created October 23, 2019 09:40
Show Gist options
  • Save basilevs/13f45b43986438000142ba8eb69b1b8d to your computer and use it in GitHub Desktop.
Save basilevs/13f45b43986438000142ba8eb69b1b8d to your computer and use it in GitHub Desktop.
Dumb copy of a project from bundle resource to Eclipse workspace
public static void importProjectFromBundleResource(IWorkspace workspace, Bundle bundle, IPath projectPathInBundle) {
try {
URL descriptionUrl = bundle.getEntry(projectPathInBundle.append(".project").toPortableString());
IProjectDescription description;
try(InputStream descriptorStream = descriptionUrl.openStream()) {
description = workspace.loadProjectDescription(descriptorStream);
}
description.setLocationURI(null);
IProject project = workspace.getRoot().getProject(description.getName());
workspace.run(monitor -> {
project.create(description, monitor);
Iterators.forEnumeration(bundle.getEntryPaths(projectPathInBundle.toPortableString())).forEachRemaining(entryPathString -> {
IPath entryPath = Path.fromPortableString(entryPathString);
Assert.assertTrue(projectPathInBundle.isPrefixOf(entryPath));
try {
if (entryPathString.endsWith("/")) {
project.getFolder(entryPathString).create(true, true, monitor);
} else {
try(InputStream content = bundle.getEntry(entryPathString).openStream()) {
project.getFile(entryPathString).create(content, true, monitor);
}
}
} catch (Exception e) {
throw new AssertionError("Failed to copy " + entryPathString);
}
});
}, null);
} catch (Exception e) {
throw new AssertionError("Failed to load " + bundle.getSymbolicName() + ":" + projectPathInBundle);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment