Search in sources :

Example 1 with MergeableManifest2

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) StringInputStream(org.eclipse.xtext.util.StringInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MergeableManifest2(org.eclipse.xtext.util.MergeableManifest2)

Example 2 with MergeableManifest2

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);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) InputStream(java.io.InputStream) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) MergeableManifest2(org.eclipse.xtext.util.MergeableManifest2) IProject(org.eclipse.core.resources.IProject)

Example 3 with MergeableManifest2

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MergeableManifest2(org.eclipse.xtext.util.MergeableManifest2)

Example 4 with MergeableManifest2

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", ""));
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) InputStream(java.io.InputStream) Attributes(org.eclipse.xtext.util.MergeableManifest2.Attributes) MergeableManifest2(org.eclipse.xtext.util.MergeableManifest2) Test(org.junit.Test)

Example 5 with MergeableManifest2

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());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) InputStream(java.io.InputStream) MergeableManifest2(org.eclipse.xtext.util.MergeableManifest2) Test(org.junit.Test)

Aggregations

MergeableManifest2 (org.eclipse.xtext.util.MergeableManifest2)11 InputStream (java.io.InputStream)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 StringInputStream (org.eclipse.xtext.util.StringInputStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Test (org.junit.Test)5 IFile (org.eclipse.core.resources.IFile)3 Attributes (org.eclipse.xtext.util.MergeableManifest2.Attributes)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 OutputStream (java.io.OutputStream)1 Manifest (java.util.jar.Manifest)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1