Skip to content

Commit

Permalink
#1100 Upgrade TinyBundles to 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverlietz committed Oct 12, 2023
1 parent f7b7c76 commit 916ba17
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@
import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.TestContainerException;
import org.ops4j.pax.swissbox.framework.RemoteFramework;
import org.ops4j.pax.tinybundles.core.TinyBundles;
import org.ops4j.pax.tinybundles.TinyBundles;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.launch.FrameworkFactory;

import static org.ops4j.pax.tinybundles.TinyBundles.rawBuilder;

public class ForkedFrameworkFactoryTest {

private File storage;
Expand Down Expand Up @@ -150,11 +152,11 @@ Collections.<String, String> emptyMap(), frameworkProperties, null,
}

private File generateBundle() throws IOException {
InputStream stream = TinyBundles.bundle().add(ClasspathTestActivator.class)
.set(Constants.BUNDLE_SYMBOLICNAME, "boot.classpath.test.generated")
.set(Constants.IMPORT_PACKAGE, "org.osgi.framework, org.kohsuke.metainf_services")
.set(Constants.BUNDLE_ACTIVATOR, ClasspathTestActivator.class.getName())
.build();
InputStream stream = TinyBundles.bundle().addClass(ClasspathTestActivator.class)
.setHeader(Constants.BUNDLE_SYMBOLICNAME, "boot.classpath.test.generated")
.setHeader(Constants.IMPORT_PACKAGE, "org.osgi.framework, org.kohsuke.metainf_services")
.setHeader(Constants.BUNDLE_ACTIVATOR, ClasspathTestActivator.class.getName())
.build(rawBuilder());

File bundle = new File("target/bundles/boot-classpath-generated.jar");
FileUtils.copyInputStreamToFile(stream, bundle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
import org.ops4j.pax.exam.options.UrlReference;
import org.ops4j.pax.exam.spi.PaxExamRuntime;
import org.ops4j.pax.tinybundles.core.TinyBundles;
import org.ops4j.pax.tinybundles.TinyBundles;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;

import static org.ops4j.pax.tinybundles.TinyBundles.rawBuilder;

public class ForkedTestContainerFactoryTest {

@Test
Expand Down Expand Up @@ -75,6 +77,8 @@ public void failWithoutBootClasspath() throws BundleException, IOException,
Assert.assertEquals(ClassNotFoundException.class.getName(),
cause.getClass().getName());

cause.printStackTrace();

Assert.assertEquals("org.kohsuke.metainf_services.AnnotationProcessorImpl",
cause.getMessage());
}
Expand Down Expand Up @@ -128,12 +132,12 @@ public void startWithBootClasspath(UrlReference url) throws BundleException,
}

private File generateBundle() throws IOException {
InputStream stream = TinyBundles.bundle().add(ClasspathTestActivator.class)
.set(Constants.BUNDLE_MANIFESTVERSION, "2")
.set(Constants.BUNDLE_SYMBOLICNAME, "boot.classpath.test.generated")
.set(Constants.IMPORT_PACKAGE, "org.osgi.framework, org.kohsuke.metainf_services")
.set(Constants.BUNDLE_ACTIVATOR, ClasspathTestActivator.class.getName())
.build();
InputStream stream = TinyBundles.bundle().addClass(ClasspathTestActivator.class)
.setHeader(Constants.BUNDLE_MANIFESTVERSION, "2")
.setHeader(Constants.BUNDLE_SYMBOLICNAME, "boot.classpath.test.generated")
.setHeader(Constants.IMPORT_PACKAGE, "org.osgi.framework, org.kohsuke.metainf_services")
.setHeader(Constants.BUNDLE_ACTIVATOR, ClasspathTestActivator.class.getName())
.build(rawBuilder());

File bundle = new File("target/bundles/boot-classpath-generated.jar");
FileUtils.copyInputStreamToFile(stream, bundle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import org.ops4j.pax.exam.cm.internal.ConfigurationOptionActivator;
import org.ops4j.pax.exam.cm.internal.ConfigurationOptionConfigurationListener;
import org.ops4j.pax.exam.options.ProvisionOption;
import org.ops4j.pax.tinybundles.core.TinyBundle;
import org.ops4j.pax.tinybundles.core.TinyBundles;
import org.ops4j.pax.tinybundles.TinyBundle;
import org.ops4j.pax.tinybundles.TinyBundles;
import org.osgi.framework.Constants;

/**
Expand Down Expand Up @@ -201,14 +201,14 @@ private static ProvisionOption<?> createProvisionOption(ConfigurationOption conf
}
ByteArrayInputStream stream = new ByteArrayInputStream(outputStream.toByteArray());
TinyBundle bundle = TinyBundles.bundle();
bundle.add(ConfigurationOptionConfigurationListener.class);
bundle.add(ConfigurationOptionActivator.class).add("override.obj", stream);
bundle.addClass(ConfigurationOptionConfigurationListener.class);
bundle.addClass(ConfigurationOptionActivator.class).addResource("override.obj", stream);
bundle
.set(Constants.BUNDLE_SYMBOLICNAME, "PAXExamConfigurationOption-" + UUID.randomUUID());
bundle.set(Constants.IMPORT_PACKAGE,
.setHeader(Constants.BUNDLE_SYMBOLICNAME, "PAXExamConfigurationOption-" + UUID.randomUUID());
bundle.setHeader(Constants.IMPORT_PACKAGE,
"org.osgi.framework,org.osgi.service.cm,org.osgi.util.tracker,org.slf4j");
bundle.set(Constants.BUNDLE_ACTIVATOR, ConfigurationOptionActivator.class.getName());
bundle.set(Constants.BUNDLE_MANIFESTVERSION, "2");
bundle.setHeader(Constants.BUNDLE_ACTIVATOR, ConfigurationOptionActivator.class.getName());
bundle.setHeader(Constants.BUNDLE_MANIFESTVERSION, "2");
return CoreOptions.streamBundle(bundle.build()).startLevel(1).start(true).update(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package org.ops4j.pax.exam.spi.intern;

import static org.ops4j.pax.exam.Constants.PROBE_EXECUTABLE;
import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle;
import static org.ops4j.pax.tinybundles.core.TinyBundles.withClassicBuilder;
import static org.ops4j.pax.tinybundles.TinyBundles.bundle;
import static org.ops4j.pax.tinybundles.TinyBundles.rawBuilder;

import java.io.File;
import java.io.IOException;
Expand All @@ -42,7 +42,7 @@
import org.ops4j.pax.exam.TestProbeBuilder;
import org.ops4j.pax.exam.TestProbeProvider;
import org.ops4j.pax.exam.spi.ContentCollector;
import org.ops4j.pax.tinybundles.core.TinyBundle;
import org.ops4j.pax.tinybundles.TinyBundle;
import org.ops4j.store.Store;
import org.osgi.framework.Constants;

Expand Down Expand Up @@ -120,7 +120,7 @@ public TestProbeProvider build() {
try {
TinyBundle bundle = prepareProbeBundle(createExtraIgnores());
return new DefaultTestProbeProvider(getTests(), store, store.store(bundle
.build(withClassicBuilder())));
.build(rawBuilder())));

}
catch (IOException e) {
Expand All @@ -129,20 +129,20 @@ public TestProbeProvider build() {
}

private TinyBundle prepareProbeBundle(Properties p) throws IOException {
TinyBundle bundle = bundle(store).set(Constants.DYNAMICIMPORT_PACKAGE, "*");
TinyBundle bundle = bundle(store).setHeader(Constants.DYNAMICIMPORT_PACKAGE, "*");

bundle.set(Constants.BUNDLE_SYMBOLICNAME, "");
bundle.set(Constants.BUNDLE_MANIFESTVERSION, "2");
bundle.setHeader(Constants.BUNDLE_SYMBOLICNAME, "");
bundle.setHeader(Constants.BUNDLE_MANIFESTVERSION, "2");
for (Object key : extraProperties.keySet()) {
bundle.set((String) key, (String) extraProperties.get(key));
bundle.setHeader((String) key, (String) extraProperties.get(key));
}
for (Object key : p.keySet()) {
bundle.set((String) key, (String) p.get(key));
bundle.setHeader((String) key, (String) p.get(key));
}

Map<String, URL> map = collectResources();
for (String item : map.keySet()) {
bundle.add(item, map.get(item));
bundle.addResource(item, map.get(item));
}
return bundle;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
import static org.ops4j.pax.exam.regression.karaf.RegressionConfiguration.featureRepoStandard;
import static org.ops4j.pax.exam.regression.karaf.RegressionConfiguration.regressionDefaults;
import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle;
import static org.ops4j.pax.tinybundles.core.TinyBundles.withBnd;
import static org.ops4j.pax.tinybundles.TinyBundles.bundle;
import static org.ops4j.pax.tinybundles.TinyBundles.withBnd;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -128,9 +128,9 @@ private String readResponse(URLConnection conn) throws IOException {

private InputStream createTestBundle() {
return bundle()
.add(EchoServlet.class)
.add(ServletActivator.class)
.set(Constants.BUNDLE_ACTIVATOR, ServletActivator.class.getName())
.build(withBnd());
.addClass(EchoServlet.class)
.addClass(ServletActivator.class)
.setHeader(Constants.BUNDLE_ACTIVATOR, ServletActivator.class.getName())
.build(bndBuilder());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerMethod;
import org.ops4j.pax.swissbox.tracker.ServiceLookup;
import org.ops4j.pax.tinybundles.core.TinyBundle;
import org.ops4j.pax.tinybundles.core.TinyBundles;
import org.ops4j.pax.tinybundles.TinyBundle;
import org.ops4j.pax.tinybundles.TinyBundles;
import org.ops4j.store.StoreFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
Expand All @@ -64,10 +64,10 @@ public Option[] config() {
private InputStream createFragmentBundle() {
try {
TinyBundle bundle = TinyBundles.bundle(StoreFactory.anonymousStore())
.set(Constants.FRAGMENT_HOST, "org.ops4j.pax.exam.sample9.pde")
.set(Constants.BUNDLE_MANIFESTVERSION, "2")
.set(Constants.BUNDLE_SYMBOLICNAME, "org.ops4j.pax.exam.sample9.fragment")
.add("messages.properties", getClass().getResource("/messages.properties"));
.setHeader(Constants.FRAGMENT_HOST, "org.ops4j.pax.exam.sample9.pde")
.setHeader(Constants.BUNDLE_MANIFESTVERSION, "2")
.setHeader(Constants.BUNDLE_SYMBOLICNAME, "org.ops4j.pax.exam.sample9.fragment")
.addResource("messages.properties", getClass().getResource("/messages.properties"));
return bundle.build();
}
catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
import org.ops4j.pax.exam.TestContainerException;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.swissbox.tracker.ServiceLookup;
import org.ops4j.pax.tinybundles.core.TinyBundle;
import org.ops4j.pax.tinybundles.core.TinyBundles;
import org.ops4j.pax.tinybundles.TinyBundle;
import org.ops4j.pax.tinybundles.TinyBundles;
import org.ops4j.store.Handle;
import org.ops4j.store.Store;
import org.ops4j.store.StoreFactory;
Expand All @@ -63,10 +63,10 @@ public Option[] config() {

private URL createFragmentBundle() {
TinyBundle bundle = TinyBundles.bundle()
.set(Constants.FRAGMENT_HOST, "org.ops4j.pax.exam.sample9.pde")
.set(Constants.BUNDLE_MANIFESTVERSION, "2")
.set(Constants.BUNDLE_SYMBOLICNAME, "org.ops4j.pax.exam.sample9.fragment")
.add("messages.properties", getClass().getResource("/messages.properties"));
.setHeader(Constants.FRAGMENT_HOST, "org.ops4j.pax.exam.sample9.pde")
.setHeader(Constants.BUNDLE_MANIFESTVERSION, "2")
.setHeader(Constants.BUNDLE_SYMBOLICNAME, "org.ops4j.pax.exam.sample9.fragment")
.addResource("messages.properties", getClass().getResource("/messages.properties"));

try {
Store<InputStream> store = StoreFactory.anonymousStore();
Expand Down
2 changes: 1 addition & 1 deletion pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependency.paxurl.version>2.6.8</dependency.paxurl.version>
<dependency.pax.logging.version>1.10.3</dependency.pax.logging.version>
<dependency.swissbox.version>1.8.3</dependency.swissbox.version>
<dependency.tinybundles.version>2.1.1</dependency.tinybundles.version>
<dependency.tinybundles.version>4.0.0</dependency.tinybundles.version>
<dependency.base.version>1.5.1</dependency.base.version>
<dependency.slf4j.version>1.7.25</dependency.slf4j.version>
<dependency.junit.version>4.13.2</dependency.junit.version>
Expand Down

0 comments on commit 916ba17

Please sign in to comment.