From a62f3b12d6603aca4d4b10e7daa6a4ca99dabc89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Wed, 27 Dec 2023 08:50:57 +0100 Subject: [PATCH] Format the generated manifest Fix https://github.com/eclipse-pde/eclipse.pde/issues/804 --- .../core/bnd/FormatedManifestResource.java | 52 +++++++++++++++++++ .../pde/internal/core/bnd/ProjectJar.java | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/FormatedManifestResource.java diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/FormatedManifestResource.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/FormatedManifestResource.java new file mode 100644 index 0000000000..f7668bdb46 --- /dev/null +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/FormatedManifestResource.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2023 Christoph Läubrich and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Christoph Läubrich - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.internal.core.bnd; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; +import java.util.Map; +import java.util.jar.Manifest; + +import org.eclipse.osgi.util.ManifestElement; +import org.eclipse.pde.internal.core.util.ManifestUtils; +import org.osgi.framework.BundleException; + +import aQute.bnd.osgi.ManifestResource; + +public class FormatedManifestResource extends ManifestResource { + + public FormatedManifestResource(Manifest manifest) { + super(manifest); + } + + @Override + public void write(OutputStream out) throws IOException { + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + super.write(bout); + try { + Map map = ManifestElement.parseBundleManifest(new ByteArrayInputStream(bout.toByteArray()), + null); + try (OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8)) { + ManifestUtils.writeManifest(map, writer); + } + } catch (BundleException e) { + throw new IOException("invalid manifest", e); //$NON-NLS-1$ + } + } + +} diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/ProjectJar.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/ProjectJar.java index d7b3e94881..32ac8174ef 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/ProjectJar.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/bnd/ProjectJar.java @@ -85,7 +85,7 @@ public ProjectJar(IProject project, Predicate filter) throws CoreExce @Override public void setManifest(Manifest manifest) { super.setManifest(manifest); - ManifestResource resource = new ManifestResource(manifest); + ManifestResource resource = new FormatedManifestResource(manifest); // We must handle this with a little care here, first we put it as a // resource, what will make other parts of BND find it and copy it to // the output location(so it can be found when using the output as a