Created
October 23, 2019 09:40
-
-
Save basilevs/13f45b43986438000142ba8eb69b1b8d to your computer and use it in GitHub Desktop.
Dumb copy of a project from bundle resource to Eclipse workspace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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