Skip to content

Commit

Permalink
[OSGi] - Cleanup BudleActivator and Service registration, Update bnd …
Browse files Browse the repository at this point in the history
…and osgi deps (#9361)

refactor: OSGi improvements 

* update bnd-version

Signed-off-by: Stefan Bischof <[email protected]>

* update osgi dependency and version

Signed-off-by: Stefan Bischof <[email protected]>

* fix mocking osgi-classes

Signed-off-by: Stefan Bischof <[email protected]>

* OSGiResourceProvider uses @component to declare the service

Signed-off-by: Stefan Bischof <[email protected]>

* VaadinBundleTracker uses @component to declare the service

Signed-off-by: Stefan Bischof <[email protected]>

* Remove `empty` BundleActivator

Signed-off-by: Stefan Bischof <[email protected]>

* use constants for osgi.http.whiteboard.servlet.pattern

Signed-off-by: Stefan Bischof <[email protected]>

* fix unregister Service PolymerPublishedEventRpcHandler

Signed-off-by: Stefan Bischof <[email protected]>

* registers PolymerPublishedEventRpcHandler as a declarative service

Signed-off-by: Stefan Bischof <[email protected]>
  • Loading branch information
stbischof authored Nov 11, 2020
1 parent f28e07a commit 1df5b02
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 125 deletions.
2 changes: 1 addition & 1 deletion flow-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<artifactId>osgi.core</artifactId>
<version>${osgi.core.version}</version>
<scope>provided</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion flow-data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<artifactId>osgi.core</artifactId>
<version>${osgi.core.version}</version>
<scope>provided</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion flow-dnd/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<artifactId>osgi.core</artifactId>
<version>${osgi.core.version}</version>
<scope>provided</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion flow-lit-template/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<artifactId>osgi.core</artifactId>
<version>${osgi.core.version}</version>
<scope>provided</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion flow-polymer-template/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@

<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<artifactId>osgi.core</artifactId>
<version>${osgi.core.version}</version>
<scope>provided</scope>
</dependency>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.polymertemplate.PolymerTemplate;
import com.vaadin.flow.component.template.internal.DeprecatedPolymerPublishedEventHandler;
import com.vaadin.flow.di.Lookup;
import com.vaadin.flow.internal.StateNode;
import com.vaadin.flow.templatemodel.ModelType;

Expand All @@ -31,8 +32,11 @@
/**
* Polymer utilitiy class for handling polymer rpc events for @EventHandler.
*
* Registers {@link PolymerPublishedEventRpcHandler} as a service to make it
* available in {@link Lookup} in an OSGi container. *
* @since
*/
@org.osgi.service.component.annotations.Component(immediate = true)
public class PolymerPublishedEventRpcHandler
implements DeprecatedPolymerPublishedEventHandler {

Expand Down
2 changes: 1 addition & 1 deletion flow-push/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<artifactId>osgi.core</artifactId>
<version>${osgi.core.version}</version>
<scope>provided</scope>
</dependency>
Expand Down
1 change: 0 additions & 1 deletion flow-server/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ Import-Package: org.atmosphere*;resolution:=optional;version='${atmosphere.runti
*
Export-Package: com.vaadin.flow.client,\
!com.vaadin.flow.push*, com.vaadin.flow*;-noimport:=true
Bundle-Activator: com.vaadin.flow.server.osgi.ServletContainerInitializerExtender
9 changes: 8 additions & 1 deletion flow-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,18 @@

<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<artifactId>osgi.core</artifactId>
<version>${osgi.core.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.cmpn</artifactId>
<version>${osgi.compendium.version}</version>
<scope>provided</scope>
</dependency>

<!-- Connect Dependencies -->
<dependency>
<groupId>javax.validation</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@

import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;

import org.osgi.service.component.annotations.Component;
import com.vaadin.flow.di.ResourceProvider;
import com.vaadin.flow.server.VaadinServletService;

/**
* OSGi capable implementation of {@link ResourceProvider}.
* ServiceComponentRuntime activates this Service because of @Component
*
* @author Vaadin Ltd
* @since
*
*/
@Component
public class OSGiResourceProvider implements ResourceProvider {

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
import org.osgi.framework.BundleEvent;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.wiring.BundleWiring;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
import org.osgi.util.tracker.BundleTracker;
import org.slf4j.LoggerFactory;

Expand All @@ -54,10 +58,12 @@
* The tracker scans for all classes in active bundles which have
* <b>Vaadin-OSGi-Extender</b> header and report them to the {@link OSGiAccess}
* instance.
*
*
* OSGi ServiceComponentRuntime creates the Service immediate while activating the bundle.
* @author Vaadin Ltd
* @since 1.2
*/
@Component(immediate = true)
public class VaadinBundleTracker extends BundleTracker<Bundle> {

private final Bundle flowServerBundle;
Expand Down Expand Up @@ -99,15 +105,26 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)

/**
* Creates a new instance of a bundle tracker.
*
* OSGi ServiceComponentRuntime injects the BundleContext because of the @Activate
* @param context
* the {@code BundleContext} against which the tracking is done
*/
@Activate
public VaadinBundleTracker(BundleContext context) {
super(context, Bundle.ACTIVE | Bundle.RESOLVED, null);
flowServerBundle = context.getBundle();
open();
}


/**
* OSGi ServiceComponentRuntime calls this method while unregister the Service(e.g when stop/uninstall the bundle)
*/
@Deactivate
public void deactivate() {
close();
}

@Override
public Bundle addingBundle(Bundle bundle, BundleEvent event) {
if ((bundle.getState() & Bundle.ACTIVE) != 0) {
Expand Down Expand Up @@ -145,7 +162,7 @@ public Bundle addingBundle(Bundle bundle, BundleEvent event) {

private void registerPushResources(Bundle pushBundle) {
Hashtable<String, Object> properties = new Hashtable<>();
properties.put("osgi.http.whiteboard.servlet.pattern",
properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN,
"/VAADIN/static/push/*");
servletPushRegistration.compareAndSet(null,
pushBundle.getBundleContext().registerService(Servlet.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public synchronized Class<?> loadClass(String name)
Builder<Exception> builder = new ByteBuddy()
.subclass(Exception.class);
return builder.name("org.osgi.framework.InvalidSyntaxException")
.make().load(this, ClassLoadingStrategy.Default.WRAPPER)
.make().load(this, ClassLoadingStrategy.Default.CHILD_FIRST.allowExistingTypes())
.getLoaded();
} else if (name.equals("org.osgi.framework.FrameworkUtil")) {
Builder<Object> builder = new ByteBuddy()
Expand All @@ -81,7 +81,7 @@ public synchronized Class<?> loadClass(String name)
.withParameter(Class.class)
.intercept(MethodDelegation.to(Interceptor.class))
.name(name).make()
.load(this, ClassLoadingStrategy.Default.WRAPPER)
.load(this, ClassLoadingStrategy.Default.CHILD_FIRST.allowExistingTypes())
.getLoaded();
return fwUtil;
} else if (name.startsWith(vaadinPackagePrefix)) {
Expand All @@ -106,7 +106,7 @@ private Class<?> defineBundleClass() {
Builder<?> builder = new ByteBuddy().makeInterface();

Class<?> bundleClass = builder.name("org.osgi.framework.Bundle")
.make().load(this, ClassLoadingStrategy.Default.WRAPPER)
.make().load(this, ClassLoadingStrategy.Default.CHILD_FIRST.allowExistingTypes())
.getLoaded();
return bundleClass;
}
Expand Down
30 changes: 30 additions & 0 deletions flow-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,36 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>${bnd.version}</version>
<executions>
<execution>
<goals>
<goal>bnd-process</goal>
</goals>
<configuration>
<bnd><![CDATA[-fixupmessages: "Classes found in the wrong directory";is:=warning]]>
</bnd>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
<index>false</index>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion flow-tests/test-root-context/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<artifactId>osgi.core</artifactId>
<version>${osgi.core.version}</version>
<scope>provided</scope>
</dependency>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
<osgi.bundle.version>
${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}
</osgi.bundle.version>
<bnd.version>3.3.0</bnd.version>
<osgi.core.version>6.0.0</osgi.core.version>
<bnd.version>5.2.0</bnd.version>
<osgi.core.version>7.0.0</osgi.core.version>
<osgi.compendium.version>7.0.0</osgi.compendium.version>

<maven.test.skip>false</maven.test.skip>
Expand Down

0 comments on commit 1df5b02

Please sign in to comment.