Java 类org.eclipse.xtext.util.MergeableManifest 实例源码

项目:xtext-core    文件:ManifestAccess.java   
@Override
public void writeTo(final IFileSystemAccess2 fileSystemAccess) {
  try {
    if ((fileSystemAccess != null)) {
      CharSequence _content = this.getContent();
      StringBuffer _stringBuffer = new StringBuffer(_content);
      final String contentToWrite = MergeableManifest.make512Safe(_stringBuffer, this.lineDelimiter);
      byte[] _bytes = contentToWrite.getBytes("UTF-8");
      ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_bytes);
      final MergeableManifest mergableManifest = new MergeableManifest(_byteArrayInputStream);
      mergableManifest.setLineDelimiter(this.lineDelimiter);
      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      mergableManifest.write(bout);
      byte[] _byteArray = bout.toByteArray();
      ByteArrayInputStream _byteArrayInputStream_1 = new ByteArrayInputStream(_byteArray);
      fileSystemAccess.generateFile(this.getPath(), _byteArrayInputStream_1);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-core    文件:ManifestMergerTest.java   
@Test public void testNoLongLine() throws Exception {
    String packageName = getClass().getPackage().getName().replace('.', '/');
    InputStream resourceAsStream = getClass().getResourceAsStream("/" + packageName + "/Test_Manifest.MF");
    MergeableManifest manifest = new MergeableManifest(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()));
}
项目:xtext-core    文件:ManifestMergerTest.java   
@Test public void testSplit512Length() throws Exception {
    String packageName = getClass().getPackage().getName().replace('.', '/');
    InputStream resourceAsStream = getClass().getResourceAsStream("/" + packageName + "/Test_Manifest.MF");
    MergeableManifest manifest = new MergeableManifest(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");
    }
}
项目:gemoc-studio-modeldebugging    文件:ManifestUtil.java   
private static MergeableManifest createMergableManifest(
        IResource manifestFile) throws IOException, CoreException {
    InputStream originalManifest = ((IFile) manifestFile).getContents();
    try {
        return new MergeableManifest(originalManifest);
    } finally {
        originalManifest.close();
    }
}
项目:xtext-core    文件:XtextGenerator.java   
protected void mergeManifest(final ManifestAccess manifest, final IXtextGeneratorFileSystemAccess metaInf) throws IOException {
  InputStream in = null;
  try {
    in = metaInf.readBinaryFile(manifest.getPath());
    String _bundleName = manifest.getBundleName();
    final MergeableManifest merge = new MergeableManifest(in, _bundleName);
    merge.setLineDelimiter(this.codeConfig.getLineDelimiter());
    merge.addExportedPackages(manifest.getExportedPackages());
    merge.addRequiredBundles(manifest.getRequiredBundles());
    merge.addImportedPackages(manifest.getImportedPackages());
    if (((manifest.getActivator() != null) && StringExtensions.isNullOrEmpty(merge.getBundleActivator()))) {
      merge.setBundleActivator(manifest.getActivator().getName());
    }
    boolean _isModified = merge.isModified();
    if (_isModified) {
      final ByteArrayOutputStream out = new ByteArrayOutputStream();
      merge.write(out);
      byte[] _byteArray = out.toByteArray();
      ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
      metaInf.generateFile(manifest.getPath(), _byteArrayInputStream);
    }
  } finally {
    if ((in != null)) {
      in.close();
    }
  }
}
项目:xtext-core    文件:ManifestMergerTest.java   
@Test public void testMergeRequiredBundles() throws Exception {
    String packageName = getClass().getPackage().getName().replace('.', '/');
    InputStream resourceAsStream = getClass().getResourceAsStream("/" + packageName + "/Test_Manifest.MF");
    MergeableManifest manifest = new MergeableManifest(resourceAsStream);
    Attributes attrs = manifest.getMainAttributes();
    String before = ((String) attrs.get(MergeableManifest.REQUIRE_BUNDLE)).replaceAll("\\s","");
    manifest.addRequiredBundles(Collections.singleton("foo.bar.baz"));
    String after = (String) attrs.get(MergeableManifest.REQUIRE_BUNDLE);
    assertEquals(before + ",foo.bar.baz", after.replaceAll("\\s",""));
}
项目:xtext-core    文件:ManifestMergerTest.java   
@Test public void testMergeExportedPackages() throws Exception {
    String packageName = getClass().getPackage().getName().replace('.', '/');
    InputStream resourceAsStream = getClass().getResourceAsStream("/" + packageName + "/Test_Manifest.MF");
    MergeableManifest manifest = new MergeableManifest(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());
}
项目:xtext-core    文件:ManifestMergerTest.java   
@Test public void testNoChanges() throws Exception {
    String packageName = getClass().getPackage().getName().replace('.', '/');
    InputStream resourceAsStream = getClass().getResourceAsStream("/" + packageName + "/Test_Manifest.MF");
    MergeableManifest manifest = new MergeableManifest(resourceAsStream);
    Attributes attrs = manifest.getMainAttributes();
    String before = ((String) attrs.get(MergeableManifest.EXPORT_PACKAGE)).replaceAll("\\s","");
    manifest.addExportedPackages(Collections.singleton("foo.bar.baz"));
    String after = (String) attrs.get(MergeableManifest.EXPORT_PACKAGE);
    assertEquals(before + ",foo.bar.baz", after.replaceAll("\\s",""));
}
项目:xtext-core    文件:ManifestMergerTest.java   
@Test public void testMergeIntoCommaSeparatedList() throws Exception {
    LinkedHashSet<String> toMerge = new LinkedHashSet<String>();
    toMerge.add("foo");
    toMerge.add("bar");
    toMerge.add("baz");

    assertEquals("bar,foo,baz", removeWS(MergeableManifest.mergeIntoCommaSeparatedList("bar", toMerge, Wrapper.wrap(false), NL)));
    assertEquals("bar,x,foo,baz", removeWS(MergeableManifest.mergeIntoCommaSeparatedList("bar ,    x", toMerge, Wrapper.wrap(false), NL)));
    assertEquals("baz,bar,foo", removeWS(MergeableManifest.mergeIntoCommaSeparatedList("baz,bar,foo", toMerge, Wrapper.wrap(false), NL)));
    assertEquals("foo,bar,baz", removeWS(MergeableManifest.mergeIntoCommaSeparatedList("", toMerge, Wrapper.wrap(false), NL)));
    assertEquals("foo,bar,baz", removeWS(MergeableManifest.mergeIntoCommaSeparatedList(null, toMerge, Wrapper.wrap(false), NL)));
}
项目:xtext-core    文件:ManifestMergerTest.java   
@Test public void testMergeIntoCommaSeparatedListWithParams() throws Exception {
    LinkedHashSet<String> toMerge = new LinkedHashSet<String>();
    toMerge.add("foo");
    toMerge.add("bar");
    toMerge.add("baz");

    assertEquals("bar;version=\"0.7.0\",foo,baz", removeWS(MergeableManifest.mergeIntoCommaSeparatedList(
            "bar;version=\"0.7.0\"", toMerge, Wrapper.wrap(false), NL)));
    assertEquals("bar;special=foo,x,foo,baz", removeWS(MergeableManifest.mergeIntoCommaSeparatedList(
            "bar;special=foo ,    x", toMerge, Wrapper.wrap(false), NL)));
}
项目:xtext-core    文件:ManifestMergerTest.java   
@Test public void testMergeIntoCommaSeparatedListWithCommaSeparatedParams() throws Exception {
    LinkedHashSet<String> toMerge = new LinkedHashSet<String>();
    toMerge.add("foo");
    toMerge.add("bar");
    toMerge.add("baz");

    assertEquals("bar;x-friends=\"xxx,foo,bar,zzz\",foo,baz", removeWS(MergeableManifest.mergeIntoCommaSeparatedList(
            "bar;x-friends=\"xxx,foo,bar,zzz\"", toMerge, Wrapper.wrap(false), NL)));
}
项目:ModelDebugging    文件:ManifestUtil.java   
private static MergeableManifest createMergableManifest(
        IResource manifestFile) throws IOException, CoreException {
    InputStream originalManifest = ((IFile) manifestFile).getContents();
    try {
        return new MergeableManifest(originalManifest);
    } finally {
        originalManifest.close();
    }
}
项目:ModelDebugging    文件:ManifestUtil.java   
public static boolean addToPluginManifest(IProject project,
        IProgressMonitor monitor, String pluginToAdd) 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 {
            MergeableManifest manifest = createMergableManifest(manifestFile);
            List<String> plunginsToAdd = new ArrayList<String>();
            plunginsToAdd.add(pluginToAdd);
            manifest.addRequiredBundles(newHashSet(plunginsToAdd));
            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;
}
项目:ModelDebugging    文件:ManifestUtil.java   
public static boolean setRequiredExecutionEnvironmentToPluginManifest(IProject project,
        IProgressMonitor monitor, String requiredExecutionEnvironment) 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 {
            MergeableManifest manifest = createMergableManifest(manifestFile);
            Attributes atts = manifest.getMainAttributes();
            atts.putValue("Bundle-RequiredExecutionEnvironment", requiredExecutionEnvironment);
            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;
}
项目:xtext-core    文件:ManifestMergerTest.java   
@Test public void testMergeIntoCommaSeparatedListValidParam() throws Exception {
    LinkedHashSet<String> toMerge = new LinkedHashSet<String>();
    toMerge.add("foo;foo=version");
    assertEquals("bar,foo;foo=version", removeWS(MergeableManifest.mergeIntoCommaSeparatedList(
            "bar", toMerge, Wrapper.wrap(false), NL)));
}
项目:xtext-core    文件:ManifestMergerTest.java   
@Test public void testMergeIntoCommaSeparatedListSkipWhenParamExists() throws Exception {
    LinkedHashSet<String> toMerge = new LinkedHashSet<String>();
    toMerge.add("foo;foo=other");
    assertEquals("foo;version=\"0.7.0\"", removeWS(MergeableManifest.mergeIntoCommaSeparatedList(
            "foo;version=\"0.7.0\"", toMerge, Wrapper.wrap(false), NL)));
}
项目:xtext-core    文件:ManifestMergerTest.java   
@Test public void testMergeIntoCommaSeparatedListAddParam() throws Exception {
    LinkedHashSet<String> toMerge = new LinkedHashSet<String>();
    toMerge.add("foo;version=\"0.7.0\"");
    assertEquals("foo;version=\"0.7.0\"", removeWS(MergeableManifest.mergeIntoCommaSeparatedList(
            "foo", toMerge, Wrapper.wrap(false), NL)));
}