Skip to content

Commit

Permalink
Cherrypicked from OpenLiberty#27148
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAure committed Jan 10, 2024
1 parent cfe0c48 commit 5052997
Show file tree
Hide file tree
Showing 6 changed files with 311 additions and 57 deletions.
43 changes: 22 additions & 21 deletions dev/io.openliberty.concurrent.internal/bnd.bnd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#*******************************************************************************
# Copyright (c) 2021, 2022 IBM Corporation and others.
# Copyright (c) 2021, 2023 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
Expand Down Expand Up @@ -48,23 +48,24 @@ instrument.classesExcludes: io/openliberty/concurrent/internal/resources/*.class
io.openliberty.concurrent.internal.trigger.ZonedTriggerService

-buildpath: \
com.ibm.websphere.appserver.spi.kernel.service;version=latest,\
com.ibm.websphere.appserver.spi.logging;version=latest,\
com.ibm.websphere.org.osgi.core;version=latest,\
com.ibm.websphere.org.osgi.service.cm;version=latest,\
com.ibm.websphere.org.osgi.service.component;version=latest,\
com.ibm.wsspi.org.osgi.service.cm;version=latest,\
com.ibm.wsspi.org.osgi.service.component.annotations;version=latest,\
com.ibm.wsspi.org.osgi.service.metatype;version=latest,\
com.ibm.ws.concurrency.policy;version=latest,\
com.ibm.ws.concurrent.jakarta;version=latest,\
com.ibm.ws.config;version=latest,\
com.ibm.ws.container.service;version=latest,\
com.ibm.ws.context;version=latest,\
com.ibm.ws.injection;version=latest,\
com.ibm.ws.javaee.dd.common;version=latest,\
com.ibm.ws.kernel.service;version=latest,\
com.ibm.ws.logging.core;version=latest,\
com.ibm.ws.resource;version=latest,\
com.ibm.ws.org.osgi.annotation.versioning;version=latest,\
io.openliberty.jakarta.concurrency.3.0;version=latest
com.ibm.websphere.appserver.spi.kernel.service;version=latest,\
com.ibm.websphere.appserver.spi.logging;version=latest,\
com.ibm.websphere.org.osgi.core;version=latest,\
com.ibm.websphere.org.osgi.service.cm;version=latest,\
com.ibm.websphere.org.osgi.service.component;version=latest,\
com.ibm.wsspi.org.osgi.service.cm;version=latest,\
com.ibm.wsspi.org.osgi.service.component.annotations;version=latest,\
com.ibm.wsspi.org.osgi.service.metatype;version=latest,\
com.ibm.ws.concurrency.policy;version=latest,\
com.ibm.ws.concurrent.jakarta;version=latest,\
com.ibm.ws.config;version=latest,\
com.ibm.ws.container.service;version=latest,\
com.ibm.ws.context;version=latest,\
com.ibm.ws.injection;version=latest,\
com.ibm.ws.javaee.dd.common;version=latest,\
com.ibm.ws.javaee.version;version=latest,\
com.ibm.ws.kernel.service;version=latest,\
com.ibm.ws.logging.core;version=latest,\
com.ibm.ws.resource;version=latest,\
com.ibm.ws.org.osgi.annotation.versioning;version=latest,\
io.openliberty.jakarta.concurrency.3.1;version=latest
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*******************************************************************************
* Copyright (c) 2021,2022 IBM Corporation and others.
* Copyright (c) 2021, 2023 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
Expand Down Expand Up @@ -45,9 +45,12 @@ public class ContextServiceDefinitionBinding extends InjectionBinding<ContextSer
private static final String KEY_DESCRIPTION = "description";
private static final String KEY_PROPAGATED = "propagated";
private static final String KEY_UNCHANGED = "unchanged";
private static final String KEY_QUALIFIERS = "qualifiers";

private static final String[] DEFAULT_CLEARED = new String[] { ContextServiceDefinition.TRANSACTION };
private static final String[] DEFAULT_PROPAGATED = new String[] { ContextServiceDefinition.ALL_REMAINING };
private static final String[] DEFAULT_UNCHANGED = new String[] {};
private static final Class<?>[] DEFAULT_QUALIFIERS = new Class<?>[] {};

private String[] cleared;
private boolean XMLcleared;
Expand All @@ -58,12 +61,15 @@ public class ContextServiceDefinitionBinding extends InjectionBinding<ContextSer
private String[] propagated;
private boolean XMLpropagated;

private Map<String, String> properties;
private final Set<String> XMLProperties = new HashSet<String>();

private String[] unchanged;
private boolean XMLunchanged;

private Class<?>[] qualifiers;
private boolean XMLqualifers;

private Map<String, String> properties;
private final Set<String> XMLProperties = new HashSet<String>();

public ContextServiceDefinitionBinding(String jndiName, ComponentNameSpaceConfiguration nameSpaceConfig) {
super(null, nameSpaceConfig);
setJndiName(jndiName);
Expand All @@ -86,7 +92,8 @@ public void merge(ContextServiceDefinition annotation, Class<?> instanceClass, M
Tr.entry(this, tc, "merge", toString(annotation), instanceClass, member,
(XMLcleared ? " (xml)" : " ") + "cleared: " + toString(cleared) + " << " + toString(annotation.cleared()),
(XMLpropagated ? "(xml)" : " ") + "propagated: " + toString(propagated) + " << " + toString(annotation.propagated()),
(XMLunchanged ? " (xml)" : " ") + "unchanged: " + toString(unchanged) + " << " + toString(annotation.unchanged()));
(XMLunchanged ? " (xml)" : " ") + "unchanged: " + toString(unchanged) + " << " + toString(annotation.unchanged()),
(XMLqualifers ? " (xml)" : " ") + "qualifiers: " + toString(qualifiers) + " << " + toString(annotation.qualifiers()));

if (member != null) {
// ContextServiceDefinition is a class-level annotation only.
Expand All @@ -101,15 +108,18 @@ public void merge(ContextServiceDefinition annotation, Class<?> instanceClass, M
propagated = mergeAnnotationValue(propagated == DEFAULT_PROPAGATED ? null : propagated,
XMLpropagated, annotation.propagated(), KEY_PROPAGATED, DEFAULT_PROPAGATED);

properties = mergeAnnotationProperties(properties, XMLProperties, new String[] {}); // ContextServiceDefinition has no properties attribute
unchanged = mergeAnnotationValue(unchanged, XMLunchanged, annotation.unchanged(), KEY_UNCHANGED, DEFAULT_UNCHANGED);

unchanged = mergeAnnotationValue(unchanged, XMLunchanged, annotation.unchanged(), KEY_UNCHANGED, new String[0]);
qualifiers = mergeAnnotationValue(qualifiers, XMLqualifers, annotation.qualifiers(), KEY_QUALIFIERS, DEFAULT_QUALIFIERS);

properties = mergeAnnotationProperties(properties, XMLProperties, new String[] {}); // ContextServiceDefinition has no properties attribute

if (trace)
Tr.exit(this, tc, "merge", new String[] {
(XMLcleared ? " (xml)" : " ") + "cleared= " + toString(cleared),
(XMLpropagated ? "(xml)" : " ") + "propagated= " + toString(propagated),
(XMLunchanged ? " (xml)" : " ") + "unchanged= " + toString(unchanged)
(XMLunchanged ? " (xml)" : " ") + "unchanged= " + toString(unchanged),
(XMLqualifers ? " (xml)" : " ") + "qualifiers= " + toString(qualifiers)
});
}

Expand All @@ -119,7 +129,8 @@ void mergeXML(ContextService csd) throws InjectionConfigurationException {
Tr.entry(this, tc, "mergeXML", csd, csd.getName(),
(XMLcleared ? " (xml)" : " ") + "cleared: " + toString(cleared) + " << " + toString(csd.getCleared()),
(XMLpropagated ? "(xml)" : " ") + "propagated: " + toString(propagated) + " << " + toString(csd.getPropagated()),
(XMLunchanged ? " (xml)" : " ") + "unchanged: " + toString(unchanged) + " << " + toString(csd.getUnchanged()));
(XMLunchanged ? " (xml)" : " ") + "unchanged: " + toString(unchanged) + " << " + toString(csd.getUnchanged()),
(XMLqualifers ? " (xml)" : " ") + "qualifiers: " + toString(qualifiers) + " << " + toString(csd.getQualifiers()));

List<Description> descriptionList = csd.getDescriptions();

Expand All @@ -146,20 +157,33 @@ void mergeXML(ContextService csd) throws InjectionConfigurationException {
XMLpropagated = true;
}

List<Property> csdProps = csd.getProperties();
properties = mergeXMLProperties(properties, XMLProperties, csdProps);

String[] unchangedValues = csd.getUnchanged();
if (unchangedValues != null && unchangedValues.length > 0) {
unchanged = mergeXMLValue(unchanged, unchangedValues, "unchanged", KEY_UNCHANGED, null);
XMLunchanged |= true;
}

String[] qualifierValues = csd.getQualifiers();
if (qualifierValues == null || qualifierValues.length == 0) {
if (qualifiers == null)
qualifiers = DEFAULT_QUALIFIERS;
} else if (qualifierValues.length == 1 && qualifierValues[0].isEmpty()) {
qualifiers = DEFAULT_QUALIFIERS;
XMLqualifers = true;
} else {
qualifiers = mergeXMLValue(qualifiers, toQualifierClassArray(qualifierValues), "qualifier", KEY_QUALIFIERS, null);
XMLqualifers = true;
}

List<Property> csdProps = csd.getProperties();
properties = mergeXMLProperties(properties, XMLProperties, csdProps);

if (trace)
Tr.exit(this, tc, "mergeXML", new String[] {
(XMLcleared ? " (xml)" : " ") + "cleared= " + toString(cleared),
(XMLpropagated ? "(xml)" : " ") + "propagated= " + toString(propagated),
(XMLunchanged ? " (xml)" : " ") + "unchanged= " + toString(unchanged)
(XMLunchanged ? " (xml)" : " ") + "unchanged= " + toString(unchanged),
(XMLqualifers ? " (xml)" : " ") + "qualifiers= " + toString(qualifiers)
});
}

Expand All @@ -170,8 +194,10 @@ public void mergeSaved(InjectionBinding<ContextServiceDefinition> injectionBindi
mergeSavedValue(cleared, contextServiceBinding.cleared, "cleared");
mergeSavedValue(description, contextServiceBinding.description, "description");
mergeSavedValue(propagated, contextServiceBinding.propagated, "propagated");
mergeSavedValue(properties, contextServiceBinding.properties, "properties");
mergeSavedValue(unchanged, contextServiceBinding.unchanged, "unchanged");
mergeSavedValue(qualifiers, contextServiceBinding.qualifiers, "qualifier");
mergeSavedValue(properties, contextServiceBinding.properties, "properties");

}

void resolve() throws InjectionException {
Expand All @@ -186,6 +212,7 @@ void resolve() throws InjectionException {
addOrRemoveProperty(props, KEY_DESCRIPTION, description);
addOrRemoveProperty(props, KEY_PROPAGATED, propagated);
addOrRemoveProperty(props, KEY_UNCHANGED, unchanged);
addOrRemoveProperty(props, KEY_QUALIFIERS, qualifiers);

setObjects(null, createDefinitionReference(null, jakarta.enterprise.concurrent.ContextService.class.getName(), props));
}
Expand All @@ -198,17 +225,33 @@ static final String toString(ContextServiceDefinition anno) {
.append(", cleared=").append(Arrays.toString(anno.cleared())) //
.append(", propagated=").append(Arrays.toString(anno.propagated())) //
.append(", unchanged=").append(Arrays.toString(anno.unchanged())) //
.append(", qualifiers=").append(Arrays.toString(anno.qualifiers())) //
.append(")");
return b.toString();
}

@Trivial
private static final String toString(String[] list) {
private static final <T> String toString(T[] list) {
if (list == null || list.length == 0)
return "Unspecified";
boolean none = true;
for (int i = 0; none && i < list.length; i++)
none &= list[i] == null || list[i].length() == 0;
none &= list[i] == null || list[i].toString().isEmpty();
return none ? "None" : Arrays.toString(list);
}

@Trivial
private static final Class<?>[] toQualifierClassArray(String[] classList) throws IllegalArgumentException {
Class<?>[] clazzArray = new Class<?>[classList.length];
for (int i = 0; i < classList.length; i++) {
try {
//TODO is there a certain classloader I should be using to load this class? ApplicationClassLoader?
clazzArray[i] = Class.forName(classList[i]);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(Tr.formatMessage(tc, "CWWKC1205.qualifier.class.not.found", classList[i]), e);
}
}

return clazzArray;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
Expand Down
Loading

0 comments on commit 5052997

Please sign in to comment.