use of org.eclipse.xtext.util.MergeableManifest2 in project xtext-core by eclipse.
the class ManifestMerger2Test method testNoLongLine.
@Test
public void testNoLongLine() throws Exception {
String packageName = getClass().getPackage().getName().replace('.', '/');
InputStream resourceAsStream = getClass().getResourceAsStream("/" + packageName + "/Test_Manifest.MF");
MergeableManifest2 manifest = new MergeableManifest2(resourceAsStream);
manifest.addExportedPackages(Collections.singleton("foobar"));
assertTrue(manifest.isModified());
ByteArrayOutputStream out = new ByteArrayOutputStream();
manifest.write(out);
String result = out.toString();
String lookup = "Require-Bundle: org.eclipse.xtext,";
int idx = result.indexOf(lookup);
assertTrue(idx != -1);
idx += lookup.length();
String lineDelimiter = Strings.newLine();
for (int i = 0; i < lineDelimiter.length(); i++) {
assertEquals(result, lineDelimiter.charAt(i), result.charAt(idx + i));
}
assertEquals(result, ' ', result.charAt(idx + lineDelimiter.length()));
}
use of org.eclipse.xtext.util.MergeableManifest2 in project xtext-core by eclipse.
the class ManifestMerger2Test method testNoChanges.
@Test
public void testNoChanges() throws Exception {
String packageName = getClass().getPackage().getName().replace('.', '/');
InputStream resourceAsStream = getClass().getResourceAsStream("/" + packageName + "/Test_Manifest.MF");
MergeableManifest2 manifest = new MergeableManifest2(resourceAsStream);
Attributes attrs = manifest.getMainAttributes();
String before = attrs.get(MergeableManifest2.EXPORT_PACKAGE).replaceAll("\\s", "");
manifest.addExportedPackages(Collections.singleton("foo.bar.baz"));
String after = attrs.get(MergeableManifest2.EXPORT_PACKAGE);
assertEquals(before + ",foo.bar.baz", after.replaceAll("\\s", ""));
}
use of org.eclipse.xtext.util.MergeableManifest2 in project xtext-core by eclipse.
the class ManifestMerger2Test method testSplit512Length.
@Test
public void testSplit512Length() throws Exception {
String packageName = getClass().getPackage().getName().replace('.', '/');
InputStream resourceAsStream = getClass().getResourceAsStream("/" + packageName + "/Test_Manifest.MF");
MergeableManifest2 manifest = new MergeableManifest2(resourceAsStream);
char[] buff = new char[712];
Arrays.fill(buff, 'c');
manifest.addExportedPackages(Collections.singleton(new String(buff)));
assertTrue(manifest.isModified());
ByteArrayOutputStream out = new ByteArrayOutputStream();
manifest.write(out);
String result = out.toString();
try {
new Manifest(new StringInputStream(result));
} catch (Exception e) {
fail("long line has not been splitted into chunks");
}
}
use of org.eclipse.xtext.util.MergeableManifest2 in project xtext-core by eclipse.
the class ManifestAccess method writeTo.
@Override
public void writeTo(final IFileSystemAccess2 fileSystemAccess) {
try {
if ((fileSystemAccess != null)) {
CharSequence _content = this.getContent();
StringBuffer _stringBuffer = new StringBuffer(_content);
final String contentToWrite = MergeableManifest2.make512Safe(_stringBuffer, this.lineDelimiter);
byte[] _bytes = contentToWrite.getBytes("UTF-8");
ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_bytes);
final MergeableManifest2 mergeableManifest = new MergeableManifest2(_byteArrayInputStream);
mergeableManifest.setLineDelimiter(this.lineDelimiter);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
mergeableManifest.write(bout);
String _path = this.getPath();
byte[] _byteArray = bout.toByteArray();
ByteArrayInputStream _byteArrayInputStream_1 = new ByteArrayInputStream(_byteArray);
fileSystemAccess.generateFile(_path, _byteArrayInputStream_1);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.util.MergeableManifest2 in project xtext-core by eclipse.
the class XtextGenerator method mergeManifest.
protected void mergeManifest(ManifestAccess manifest, IXtextGeneratorFileSystemAccess metaInf) throws IOException {
InputStream in = null;
try {
in = metaInf.readBinaryFile(manifest.getPath());
MergeableManifest2 merge = new MergeableManifest2(in, manifest.getBundleName());
merge.setLineDelimiter(codeConfig.getLineDelimiter());
merge.addExportedPackages(manifest.getExportedPackages());
merge.addRequiredBundles(manifest.getRequiredBundles());
merge.addImportedPackages(manifest.getImportedPackages());
if (manifest.getActivator() != null && Strings.isNullOrEmpty(merge.getBundleActivator())) {
merge.setBundleActivator(manifest.getActivator().getName());
}
if (merge.isModified()) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
merge.write(out);
metaInf.generateFile(manifest.getPath(), new ByteArrayInputStream(out.toByteArray()));
}
} finally {
if (in != null) {
in.close();
}
}
}
Aggregations