Skip to content

Commit

Permalink
Format the generated manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Dec 27, 2023
1 parent e2c3009 commit a62f3b1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<String, String> 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$
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public ProjectJar(IProject project, Predicate<IResource> 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
Expand Down

0 comments on commit a62f3b1

Please sign in to comment.