@Override public MergeableManifest2 clone() throws CloneNotSupportedException { return new MergeableManifest2(this); }
/** * Add the set with given bundles to the "Export-Package" main attribute. * * @param exportedPackages The set of all packages to add. */ public void addExportedPackages(Set<String> exportedPackages) { addExportedPackages(exportedPackages.toArray(new String[exportedPackages.size()])); }
/** * Add the set with given bundles to the "Import-Package" main attribute. * * @param importedPackages The set of all packages to add. */ public void addImportedPackages(Set<String> importedPackages) { addImportedPackages(importedPackages.toArray(new String[importedPackages.size()])); }
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 MergeableManifest2 merge = new MergeableManifest2(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(); } } }
@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); byte[] _byteArray = bout.toByteArray(); ByteArrayInputStream _byteArrayInputStream_1 = new ByteArrayInputStream(_byteArray); fileSystemAccess.generateFile(this.getPath(), _byteArrayInputStream_1); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
private void writeEntries(BufferedWriter writer) throws IOException { for (Entry<String, Attributes> entry : entries.entrySet()) { writer.write(newline); writer.append("Name: ").append(entry.getKey()).append(newline); for (Entry<String, String> child : entry.getValue().entrySet()) { String key = child.getKey(); String value = child.getValue(); if (value.isEmpty()) continue; writer.append(make512Safe(new StringBuffer(key + ": " + separateCommas(value)), newline)); } } }
/** * Add the set with given bundles to the "Require-Bundle" main attribute. * * @param requiredBundles The set with all bundles to add. */ public void addRequiredBundles(Set<String> requiredBundles) { addRequiredBundles(requiredBundles.toArray(new String[requiredBundles.size()])); }
/** * Write the contents to the manifest to the given stream. As the stream is * created by the caller the caller is also responsible for closing it. * * @param stream the stream to write the output to. */ public void write(OutputStream stream) throws IOException { write(new BufferedWriter(new OutputStreamWriter(stream))); }
String[] split = line.split(": ", 2); String name = split[0]; if (!isValidName(name)) { throw new IOException("Missing name of value");
/** * Return a string that ensures that no line is longer then 512 characters * and lines are broken according to manifest specification. * * @param input The buffer containing the content that should be made safe * @param newline The string to use to create newlines (usually "\n" or * "\r\n") * @return The string with no longer lines then 512, ready to be read again * by {@link MergeableManifest2}. */ public static String make512Safe(StringBuffer input, String newline) { StringBuilder result = new StringBuilder(); String content = input.toString(); String rest = content; while (!rest.isEmpty()) { if (rest.contains("\n")) { String line = rest.substring(0, rest.indexOf("\n")); rest = rest.substring(rest.indexOf("\n") + 1); if (line.length() > 1 && line.charAt(line.length() - 1) == '\r') line = line.substring(0, line.length() - 1); append512Safe(line, result, newline); } else { append512Safe(rest, result, newline); break; } } return result.toString(); }
private void writeHeader(BufferedWriter writer) throws IOException { if (version == null) return; String manifestVersion = mainAttributes.get(MANIFEST_VERSION); if (manifestVersion != null) writer.append(MANIFEST_VERSION).append(": ").append(manifestVersion).append(newline); String signatureVersion = mainAttributes.get(SIGNATURE_VERSION); if (signatureVersion != null) writer.append(SIGNATURE_VERSION).append(": ").append(signatureVersion).append(newline); for (Entry<String, String> entry : mainAttributes.entrySet()) { String key = entry.getKey(); if (key.equals(MANIFEST_VERSION) || key.equals(SIGNATURE_VERSION)) continue; String value = entry.getValue(); writer.append(make512Safe(new StringBuffer(key + ": " + separateCommas(value)), newline)); } }
String[] split = line.split(": ", 2); String name = split[0]; if (!isValidName(name)) { throw new IOException("Missing name of value");