Skip to content

Commit

Permalink
#61 Do not preset Manifest headers
Browse files Browse the repository at this point in the history
* remove Built-By, Created-By and Tool from Manifest creation
* replace TinybundlesVersion by Pax-TinyBundles containing version only
  • Loading branch information
oliverlietz committed Sep 28, 2023
1 parent de7ab25 commit a85b197
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@
*/
public abstract class AbstractBuilder implements Builder {

private static final String BUILT_BY = "Built-By";

private static final String ENTRY_MANIFEST = "META-INF/MANIFEST.MF";

private static final String TOOL = "Tool";

private static final String CREATED_BY = "Created-By";
private static final String MANIFEST_HEADER_NAME = "Pax-TinyBundles";

private final Logger logger = LoggerFactory.getLogger(AbstractBuilder.class);

Expand Down Expand Up @@ -104,14 +100,8 @@ private void copy(final InputStream source, final OutputStream sink) throws IOEx
protected Manifest createManifest(final Set<Map.Entry<String, String>> headers) {
logger.debug("Creating manifest from added headers.");
final Manifest manifest = new Manifest();
final String tool = "pax-tinybundles-" + Info.getPaxTinybundlesVersion();

manifest.getMainAttributes().putValue("Manifest-Version", "1.0");
manifest.getMainAttributes().putValue(BUILT_BY, System.getProperty("user.name"));
manifest.getMainAttributes().putValue(CREATED_BY, tool);
manifest.getMainAttributes().putValue(TOOL, tool);
manifest.getMainAttributes().putValue("TinybundlesVersion", tool);

manifest.getMainAttributes().putValue(MANIFEST_HEADER_NAME, Info.getPaxTinybundlesVersion());
for (final Map.Entry<String, String> entry : headers) {
logger.debug("{} = {}", entry.getKey(), entry.getValue());
manifest.getMainAttributes().putValue(entry.getKey(), entry.getValue());
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/org/ops4j/pax/tinybundles/test/BndTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ public class BndTest {
*/
@Test
public void bndCustomHeaders() throws IOException {
final String createdBy = String.format("%s (%s)", System.getProperty("java.version"), System.getProperty("java.vendor"));
final InputStream bundle = bundle()
.build(bndBuilder());
final Attributes attributes = getManifest(bundle).getMainAttributes();
assertThat("Header Originally-Created-By", attributes.getValue("Originally-Created-By"), is("pax-tinybundles-" + Info.getPaxTinybundlesVersion()));
assertThat("Header Tool", attributes.getValue("Tool"), is(BND));
assertThat("Header TinybundlesVersion", attributes.getValue("TinybundlesVersion"), is("pax-tinybundles-" + Info.getPaxTinybundlesVersion()));
assertThat(attributes.getValue("Built-By"), is(System.getProperty("user.name")));
assertThat(attributes.getValue("Created-By"), is(createdBy));
assertThat("Manifest Header: Built-By", attributes.getValue("Built-By"), is(nullValue()));
assertThat("Manifest Header: Tool", attributes.getValue("Tool"), is(BND));
assertThat("Manifest Header: Pax-TinyBundles", attributes.getValue("Pax-TinyBundles"), is(Info.getPaxTinybundlesVersion()));
}

@Test
Expand Down
16 changes: 4 additions & 12 deletions src/test/java/org/ops4j/pax/tinybundles/test/RawTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.osgi.framework.Constants;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.ops4j.pax.tinybundles.TinyBundles.bundle;
import static org.ops4j.pax.tinybundles.TinyBundles.rawBuilder;
Expand All @@ -44,14 +45,6 @@
*/
public class RawTest {

private static final String HEADER_CREATED_BY = "Created-By";

private static final String HEADER_TOOL = "Tool";

private static final String HEADER_TINYBUNDLES_VERSION = "TinybundlesVersion";

private static final String HEADER_BUILT_BY = "Built-By";

private static InputStream createTestBundle(final String symbolicName) {
return bundle()
.addClass(HelloWorldActivator.class)
Expand Down Expand Up @@ -101,10 +94,9 @@ public void testDefaultPropertiesAreSetCorrectly() throws IOException {
final InputStream bundle = bundle()
.build(rawBuilder());
final Attributes attributes = getManifest(bundle).getMainAttributes();
assertThat(attributes.getValue(HEADER_CREATED_BY), is("pax-tinybundles-" + Info.getPaxTinybundlesVersion()));
assertThat(attributes.getValue(HEADER_TOOL), is("pax-tinybundles-" + Info.getPaxTinybundlesVersion()));
assertThat(attributes.getValue(HEADER_TINYBUNDLES_VERSION), is("pax-tinybundles-" + Info.getPaxTinybundlesVersion()));
assertThat(attributes.getValue(HEADER_BUILT_BY), is(System.getProperty("user.name")));
assertThat("Manifest Header: Created-By", attributes.getValue("Created-By"), is(nullValue()));
assertThat("Manifest Header: Built-By", attributes.getValue("Built-By"), is(nullValue()));
assertThat("Manifest Header: Pax-TinyBundles", attributes.getValue("Pax-TinyBundles"), is(Info.getPaxTinybundlesVersion()));
}

@Test
Expand Down

0 comments on commit a85b197

Please sign in to comment.