public Archive createArchive(Set<EPackage> packages, String pluginID, String pathPrefix)
throws IOException {
String qualifier = qualifierFormat.format(Calendar.getInstance()
.getTime());
Archive archive = new Archive(pluginID + "_1.0.0.v" + qualifier
+ ".jar");
StringBuilder pluginBuilder = new StringBuilder(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<?eclipse version=\"3.0\"?>\n" + "<plugin>\n");
StringBuilder xmlExtension = new StringBuilder(
"\t<extension point=\"org.eclipse.wst.xml.core.catalogContributions\"><catalogContribution>\n");
for (EPackage pkg : packages) {
ResourceSet rs = createResourceSet();
Resource resource = addSchemaResource(rs, pkg);
EObject obj = resource.getContents().get(0);
String fileName = resource.getURI().lastSegment();
String ecoreEntryPath = pathPrefix + "/" + fileName;
xmlExtension.append(saveSchema(archive, ecoreEntryPath, resource,
((XSDSchema) obj).getTargetNamespace(), pluginID));
// Save memory
System.gc();
}
xmlExtension.append("\t</catalogContribution></extension>\n");
pluginBuilder.append(xmlExtension);
pluginBuilder.append("</plugin>");
archive.addEntry(FRAGMENT_XML_ENTRY, pluginBuilder.toString());
return archive;
}