Skip to content

Commit

Permalink
[#1370] Operator fails on startup
Browse files Browse the repository at this point in the history
Rework ProductOperatorServiceImpl
  • Loading branch information
ruspl-afed committed May 23, 2024
1 parent f68aab6 commit 1207a61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" name="org.eclipse.passage.loc.internal.products.core.ProductOperatorServiceImpl">
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.passage.loc.internal.products.core.ProductOperatorServiceImpl">
<service>
<provide interface="org.eclipse.passage.loc.internal.equinox.OperatorProductService"/>
</service>
<reference cardinality="1..1" field="environment" interface="org.eclipse.osgi.service.environment.EnvironmentInfo" name="environment"/>
<reference cardinality="1..1" field="events" interface="org.osgi.service.event.EventAdmin" name="events"/>
<reference bind="bindEventAdmin" cardinality="1..1" interface="org.osgi.service.event.EventAdmin" name="EventAdmin" unbind="unbindEventAdmin"/>
<implementation class="org.eclipse.passage.loc.internal.products.core.ProductOperatorServiceImpl"/>
</scr:component>
</scr:component>
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,32 @@
*******************************************************************************/
package org.eclipse.passage.loc.internal.products.core;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.osgi.service.environment.EnvironmentInfo;
import org.eclipse.passage.lic.products.model.api.ProductVersion;
import org.eclipse.passage.loc.internal.e4.events.OperatorProductEvents;
import org.eclipse.passage.loc.internal.equinox.OperatorProductService;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.framework.FrameworkUtil;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.event.EventAdmin;

@SuppressWarnings("restriction")
@Component
public class ProductOperatorServiceImpl implements OperatorProductService {
public final class ProductOperatorServiceImpl implements OperatorProductService {

private final List<EventAdmin> events = new ArrayList<>();

private String plugin;
@Reference
private EnvironmentInfo environment;
@Reference
private EventAdmin events;
@Reference(cardinality = ReferenceCardinality.MANDATORY)
public void bindEventAdmin(EventAdmin admin) {
this.events.add(admin);
}

@Activate
public void activate(BundleContext context) {
plugin = context.getBundle().getSymbolicName();
public void unbindEventAdmin(EventAdmin admin) {
this.events.remove(admin);
}

@Override
Expand All @@ -46,11 +48,12 @@ public String createPassword(ProductVersion descriptor) {

@Override
public IStatus createProductKeys(ProductVersion target) {
return new ProductVersionKeys(plugin, this::broadcast).createKeys(target);
return new ProductVersionKeys(FrameworkUtil.getBundle(getClass()).getSymbolicName(), this::broadcast)
.createKeys(target);
}

private void broadcast(String info) {
events.postEvent(new OperatorProductEvents().keysCreated(info));
events.stream().findAny().get().postEvent(new OperatorProductEvents().keysCreated(info));
}

}

0 comments on commit 1207a61

Please sign in to comment.