use of org.eclipse.xtext.util.MergeableManifest2 in project xtext-xtend by eclipse.
the class WorkbenchTestHelper method changeManifest.
public static boolean changeManifest(IProject project, Function<MergeableManifest2, Boolean> config) throws Exception {
IFile manifest = project.getFile("META-INF/MANIFEST.MF");
InputStream content = manifest.getContents();
MergeableManifest2 mf;
try {
mf = new MergeableManifest2(content);
} finally {
content.close();
}
if (config.apply(mf)) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
mf.write(stream);
manifest.setContents(new ByteArrayInputStream(stream.toByteArray()), true, false, null);
return true;
}
return false;
}
use of org.eclipse.xtext.util.MergeableManifest2 in project xtext-xtend by eclipse.
the class AbstractJunitLibClasspathAdderTestCase method assertRequireBundles.
protected void assertRequireBundles(final String[] expectedBundleIds) {
try {
try (final InputStream contents = new Function0<InputStream>() {
@Override
public InputStream apply() {
try {
IProject _project = AbstractJunitLibClasspathAdderTestCase.this.workbenchHelper.getProject();
Path _path = new Path("META-INF/MANIFEST.MF");
return _project.getFile(_path).getContents();
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
}.apply()) {
final MergeableManifest2 manifest = new MergeableManifest2(contents);
final String requireBunbles = manifest.getMainAttributes().get(MergeableManifest2.REQUIRE_BUNDLE);
for (final String bundleId : expectedBundleIds) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("require bundle entry ");
_builder.append(bundleId);
_builder.append(" is present");
Assert.assertTrue(_builder.toString(), requireBunbles.contains(bundleId));
}
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.util.MergeableManifest2 in project xtext-xtend by eclipse.
the class AccessRestrictionInWorkspaceTest method configureExportedPackages.
private IJavaProject configureExportedPackages(final IJavaProject pluginProject) throws Exception {
final IFile manifestFile = pluginProject.getProject().getFile("META-INF/MANIFEST.MF");
final InputStream contents = manifestFile.getContents();
MergeableManifest2 _xtrycatchfinallyexpression = null;
try {
_xtrycatchfinallyexpression = new MergeableManifest2(contents);
} finally {
contents.close();
}
final MergeableManifest2 manifest = _xtrycatchfinallyexpression;
manifest.addExportedPackages(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("allowed", "discouraged;x-internal:=true")));
final ByteArrayOutputStream out = new ByteArrayOutputStream();
manifest.write(out);
byte[] _byteArray = out.toByteArray();
final ByteArrayInputStream in = new ByteArrayInputStream(_byteArray);
manifestFile.setContents(in, true, true, null);
return pluginProject;
}
use of org.eclipse.xtext.util.MergeableManifest2 in project xtext-core by eclipse.
the class ManifestMerger2Test method testMergeRequiredBundles.
@Test
public void testMergeRequiredBundles() 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.REQUIRE_BUNDLE).replaceAll("\\s", "");
manifest.addRequiredBundles(Collections.singleton("foo.bar.baz"));
String after = attrs.get(MergeableManifest2.REQUIRE_BUNDLE);
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 testMergeExportedPackages.
@Test
public void testMergeExportedPackages() throws Exception {
String packageName = getClass().getPackage().getName().replace('.', '/');
InputStream resourceAsStream = getClass().getResourceAsStream("/" + packageName + "/Test_Manifest.MF");
MergeableManifest2 manifest = new MergeableManifest2(resourceAsStream);
assertFalse(manifest.isModified());
manifest.addExportedPackages(Collections.singleton("org.eclipse.xtext"));
assertFalse(manifest.isModified());
manifest.addRequiredBundles(Collections.singleton("org.eclipse.xtend"));
assertFalse(manifest.isModified());
manifest.addImportedPackages(Collections.singleton("org.apache.log4j"));
assertFalse(manifest.isModified());
}
Aggregations