Skip to content

Commit

Permalink
Rename the property
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Jan 5, 2025
1 parent 65da797 commit 02ff25f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.repository.Transport;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.spi.AgentServicename;
import org.eclipse.equinox.p2.core.spi.AgentServiceName;
import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.osgi.service.component.annotations.Component;
Expand All @@ -28,7 +28,7 @@
* the transport.
*/
@Component(service = IAgentServiceFactory.class)
@AgentServicename(ArtifactManager.class)
@AgentServiceName(ArtifactManager.class)
public class DefaultArtifactManagerServiceFactory implements IAgentServiceFactory {

@Override
Expand Down
11 changes: 11 additions & 0 deletions bundles/org.eclipse.equinox.p2.core/.settings/.api_filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.equinox.p2.core" version="2">
<resource path="src/org/eclipse/equinox/p2/core/spi/IAgentServiceFactory.java" type="org.eclipse.equinox.p2.core.spi.IAgentServiceFactory">
<filter id="403767336">
<message_arguments>
<message_argument value="org.eclipse.equinox.p2.core.spi.IAgentServiceFactory"/>
<message_argument value="PROP_AGENT_SERVICE_NAME"/>
</message_arguments>
</filter>
</resource>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* Factory for creating {@link IProvisioningEventBus} instances.
*/
@Component(service = IAgentServiceFactory.class, property = IAgentServiceFactory.PROP_CREATED_SERVICE_NAME + "="
@Component(service = IAgentServiceFactory.class, property = IAgentServiceFactory.PROP_AGENT_SERVICE_NAME + "="
+ IProvisioningEventBus.SERVICE_NAME, name = "org.eclipse.equinox.p2.core.eventbus")
public class EventBusComponent implements IAgentServiceFactory {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public Object getService(String serviceName) {
//attempt to get factory service from service registry
Collection<ServiceReference<IAgentServiceFactory>> refs;
try {
refs = context.getServiceReferences(IAgentServiceFactory.class, "(" + IAgentServiceFactory.PROP_CREATED_SERVICE_NAME + '=' + serviceName + ')'); //$NON-NLS-1$
refs = context.getServiceReferences(IAgentServiceFactory.class,
String.format("(|(%s=%s)(p2.agent.servicename=%s)", //$NON-NLS-1$ use old property as fallback
IAgentServiceFactory.PROP_AGENT_SERVICE_NAME, serviceName, serviceName));
} catch (InvalidSyntaxException e) {
e.printStackTrace();
return null;
Expand Down Expand Up @@ -171,7 +173,7 @@ public void modifiedService(ServiceReference<IAgentServiceFactory> reference, Ob
public void removedService(ServiceReference<IAgentServiceFactory> reference, Object factoryService) {
if (stopped)
return;
String serviceName = (String) reference.getProperty(IAgentServiceFactory.PROP_CREATED_SERVICE_NAME);
String serviceName = getAgentServiceName(reference);
if (serviceName == null)
return;
Object registered = agentServices.get(serviceName);
Expand All @@ -186,4 +188,13 @@ public void removedService(ServiceReference<IAgentServiceFactory> reference, Obj
}
}

private String getAgentServiceName(ServiceReference<IAgentServiceFactory> reference) {
Object property = reference.getProperty(IAgentServiceFactory.PROP_AGENT_SERVICE_NAME);
if (property instanceof String s) {
return s;
}
// backward compatibility
return (String) reference.getProperty("p2.agent.servicename"); //$NON-NLS-1$
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
/**
* This component property type can be used to annotate a declarative service
* component that provides an {@link IAgentServiceFactory} to provides the
* required {@link IAgentServiceFactory#PROP_CREATED_SERVICE_NAME}.
* required {@link IAgentServiceFactory#PROP_AGENT_SERVICE_NAME}.
*
* @since 2.13
*/
@Retention(CLASS)
@Target(TYPE)
@ComponentPropertyType
public @interface AgentServicename {
public @interface AgentServiceName {

public static final String PREFIX_ = "p2."; //$NON-NLS-1$

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,30 @@ public interface IAgentServiceFactory {
/**
* The service name for the factory service.
*/
public static final String SERVICE_NAME = IAgentServiceFactory.class.getName();
String SERVICE_NAME = IAgentServiceFactory.class.getName();

/**
* The service property specifying the name of the service created by this factory.
* The service property specifying the name of the service created by this
* factory.
*
* @deprecated use {@link #PROP_AGENT_SERVICE_NAME} instead
*/
@Deprecated()
String PROP_CREATED_SERVICE_NAME = "p2.agent.servicename"; //$NON-NLS-1$

/**
* The service property specifying the name of the service created by this
* factory.
*
* @since 2.13
*/
public static final String PROP_CREATED_SERVICE_NAME = "p2.agent.servicename"; //$NON-NLS-1$
String PROP_AGENT_SERVICE_NAME = "p2.agent.service.name"; //$NON-NLS-1$

/**
* Instantiates a service instance for the given provisioning agent.
*
* @param agent The agent this service will belong to
* @return The created service
*/
public Object createService(IProvisioningAgent agent);
Object createService(IProvisioningAgent agent);
}

0 comments on commit 02ff25f

Please sign in to comment.