Search in sources :

Example 11 with MergeableManifest2

use of org.eclipse.xtext.util.MergeableManifest2 in project xtext-xtend by eclipse.

the class AbstractLibClasspathAdder method addToPluginManifest.

protected boolean addToPluginManifest(IProject project, IProgressMonitor monitor) throws IOException, CoreException {
    IResource manifestFile = project.findMember("META-INF/MANIFEST.MF");
    if (manifestFile != null && manifestFile.isAccessible() && !manifestFile.getResourceAttributes().isReadOnly() && manifestFile instanceof IFile) {
        OutputStream output = null;
        InputStream input = null;
        try {
            MergeableManifest2 manifest = createMergableManifest(manifestFile);
            manifest.addRequiredBundles(getBundleIds());
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            output = new BufferedOutputStream(out);
            manifest.write(output);
            ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
            input = new BufferedInputStream(in);
            ((IFile) manifestFile).setContents(input, true, true, monitor);
            return true;
        } finally {
            if (output != null)
                output.close();
            if (input != null)
                input.close();
        }
    }
    return false;
}
Also used : IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MergeableManifest2(org.eclipse.xtext.util.MergeableManifest2) BufferedOutputStream(java.io.BufferedOutputStream) IResource(org.eclipse.core.resources.IResource)

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