Search in sources :

Example 6 with MergeableManifest2

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

Example 7 with MergeableManifest2

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", ""));
}
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 8 with MergeableManifest2

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

Example 9 with MergeableManifest2

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

Example 10 with MergeableManifest2

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

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