From f242aee13f9a8e9f94ed1174dab64fc61d43c979 Mon Sep 17 00:00:00 2001 From: eparovyshnaya Date: Mon, 15 Feb 2021 13:58:14 +0300 Subject: [PATCH] Bug 571190 build the solution on Framework services host Rework FrameworkAware unit to be used with another type of Framework producing service Signed-off-by: eparovyshnaya --- .../META-INF/MANIFEST.MF | 4 +- .../META-INF/MANIFEST.MF | 6 +- .../lic/internal/equinox/Environments.java | 2 +- .../lic/internal/equinox/EquinoxPassage.java | 2 +- .../EquinoxPassageLicenseCoverage.java | 2 +- .../lic/internal/equinox/FrameworkAware.java | 81 ++++++++++--------- .../equinox/LicenseReadingServiceRequest.java | 2 +- .../equinox/SuppliedFrameworkAware.java | 31 +++++++ .../internal/equinox/io/BundleKeyKeeper.java | 4 + .../META-INF/MANIFEST.MF | 15 ++-- .../lic/internal/net/NetFrameworkAware.java | 28 +++++++ .../net/api/FrameworkConstructor.java | 23 ++++++ .../internal/net/i18n/NetMessages.properties | 1 + .../loc/internal/api/CodecSupplier.java | 4 +- .../equinox/io/BundleKeyKeeperTest.java | 3 +- 15 files changed, 155 insertions(+), 53 deletions(-) create mode 100644 bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/SuppliedFrameworkAware.java create mode 100644 bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/NetFrameworkAware.java create mode 100644 bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/api/FrameworkConstructor.java diff --git a/bundles/org.eclipse.passage.lic.api/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.lic.api/META-INF/MANIFEST.MF index aa4ab6eff..633ee5564 100644 --- a/bundles/org.eclipse.passage.lic.api/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.lic.api/META-INF/MANIFEST.MF @@ -36,7 +36,9 @@ Export-Package: org.eclipse.passage.lic.internal.api; org.eclipse.passage.lic.json, org.eclipse.passage.lic.oshi, org.eclipse.passage.loc.products.core, - org.eclipse.passage.lac", + org.eclipse.passage.lac, + org.eclipse.passage.lic.licenses.migration, + org.eclipse.passage.lac.seal", org.eclipse.passage.lic.internal.api.access; x-friends:="org.eclipse.passage.lic.base, org.eclipse.passage.lic.e4.ui, diff --git a/bundles/org.eclipse.passage.lic.equinox/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.lic.equinox/META-INF/MANIFEST.MF index 5c9c26953..2439d7c23 100644 --- a/bundles/org.eclipse.passage.lic.equinox/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.lic.equinox/META-INF/MANIFEST.MF @@ -12,7 +12,11 @@ Require-Bundle: org.eclipse.osgi;bundle-version="0.0.0";visibility:=reexport, org.eclipse.core.runtime;bundle-version="0.0.0";visibility:=reexport, org.eclipse.passage.lic.api;bundle-version="1.0.0";visibility:=reexport, org.eclipse.passage.lic.base;bundle-version="1.0.0";visibility:=reexport -Export-Package: org.eclipse.passage.lic.internal.equinox;x-friends:="org.eclipse.passage.seal.demo,org.eclipse.passage.lic.jface,org.eclipse.passage.lic.e4.ui", +Export-Package: org.eclipse.passage.lic.internal.equinox; + x-friends:="org.eclipse.passage.lic.e4.ui, + org.eclipse.passage.lic.jface, + org.eclipse.passage.seal.demo, + org.eclipse.passage.lic.net", org.eclipse.passage.lic.internal.equinox.acquire;x-internal:=true, org.eclipse.passage.lic.internal.equinox.conditions;x-internal:=true, org.eclipse.passage.lic.internal.equinox.events; diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/Environments.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/Environments.java index 099311688..fff0d83ce 100644 --- a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/Environments.java +++ b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/Environments.java @@ -19,7 +19,7 @@ import org.eclipse.passage.lic.internal.api.Framework; import org.eclipse.passage.lic.internal.api.inspection.RuntimeEnvironment; -public final class Environments extends FrameworkAware implements Supplier> { +public final class Environments extends SuppliedFrameworkAware implements Supplier> { @Override public Collection get() { diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxPassage.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxPassage.java index 2dccf08a1..3c761b953 100644 --- a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxPassage.java +++ b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxPassage.java @@ -19,7 +19,7 @@ import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult; import org.eclipse.passage.lic.internal.base.access.Access; -public final class EquinoxPassage extends FrameworkAware implements Passage { +public final class EquinoxPassage extends SuppliedFrameworkAware implements Passage { @Override public boolean canUse(String feature) { diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxPassageLicenseCoverage.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxPassageLicenseCoverage.java index a57201c49..5ec477562 100644 --- a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxPassageLicenseCoverage.java +++ b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/EquinoxPassageLicenseCoverage.java @@ -17,7 +17,7 @@ import org.eclipse.passage.lic.internal.api.restrictions.ExaminationCertificate; import org.eclipse.passage.lic.internal.base.access.Access; -public final class EquinoxPassageLicenseCoverage extends FrameworkAware implements PassageLicenseCoverage { +public final class EquinoxPassageLicenseCoverage extends SuppliedFrameworkAware implements PassageLicenseCoverage { @Override public ServiceInvocationResult assess() { diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/FrameworkAware.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/FrameworkAware.java index 546549e7f..f6e6a5465 100644 --- a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/FrameworkAware.java +++ b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/FrameworkAware.java @@ -20,7 +20,6 @@ import java.util.stream.Collectors; import org.eclipse.passage.lic.internal.api.Framework; -import org.eclipse.passage.lic.internal.api.FrameworkSupplier; import org.eclipse.passage.lic.internal.api.ServiceInvocationResult; import org.eclipse.passage.lic.internal.api.diagnostic.Trouble; import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult; @@ -41,21 +40,39 @@ * Use {@code withFrameworkService} to implement client level secondary services * or {@code withFramework} to retrieve parts of configuration directly. */ -public abstract class FrameworkAware { +public abstract class FrameworkAware { private final BundleContext context; + private final Class component; + private final Function> constructor; - protected FrameworkAware() { + protected FrameworkAware(Class cls, Function> constructor) { + // get this exact bundle, not a bundle of an ancestor class this.context = FrameworkUtil.getBundle(FrameworkAware.class).getBundleContext(); + this.component = cls; + this.constructor = constructor; } - private Collection> frameworks() { - try { - // DI is used only to get rid of overwhelming dependencies here - return context.getServiceReferences(FrameworkSupplier.class, null); - } catch (InvalidSyntaxException e) { - return Collections.emptyList(); - } + protected final ServiceInvocationResult withFrameworkService( + Function> invoke) { + return withReference(// + reference -> // + Optional.ofNullable(context.getService(reference))// + .flatMap(constructor::apply)// + .map(invoke::apply)// + .orElseGet(this::noFramework), // + this::noFramework, // + this::severalFrameworks); + } + + protected final Optional withFramework(Function invoke) { + return withReference(// + reference -> // + Optional.ofNullable(context.getService(reference))// + .flatMap(constructor::apply)// + .map(invoke::apply), // + Optional::empty, // + any -> Optional.empty()); } private ServiceInvocationResult noFramework() { @@ -66,7 +83,7 @@ private ServiceInvocationResult noFramework() { ); } - private ServiceInvocationResult severalFrameworks(Collection> findings) { + private ServiceInvocationResult severalFrameworks(Collection> findings) { return new BaseServiceInvocationResult(// new BaseDiagnostic(// findings.stream()// @@ -76,39 +93,17 @@ private ServiceInvocationResult severalFrameworks(Collection foreign) { + private Trouble foreignFramework(int singlings, ServiceReference foreign) { return new Trouble(// new SeveralFrameworks(singlings), // String.format(AccessMessages.EquinoxPassage_foreign_framework, foreign.getBundle().getSymbolicName())); } - protected ServiceInvocationResult withFrameworkService( - Function> invoke) { - return withReference(// - reference -> // - Optional.ofNullable(context.getService(reference))// - .flatMap(FrameworkSupplier::get)// - .map(invoke::apply)// - .orElseGet(this::noFramework), // - this::noFramework, // - this::severalFrameworks); - } - - protected Optional withFramework(Function invoke) { - return withReference(// - reference -> // - Optional.ofNullable(context.getService(reference))// - .flatMap(FrameworkSupplier::get)// - .map(invoke::apply), // - Optional::empty, // - any -> Optional.empty()); - } - private K withReference(// - Function, K> onFramework, // + Function, K> onFramework, // Supplier onNoFramework, // - Function>, K> onSeveralFrameworks) { - Collection> candidates = frameworks(); + Function>, K> onSeveralFrameworks) { + Collection> candidates = frameworks(); if (candidates.isEmpty()) { return onNoFramework.get(); } @@ -118,8 +113,7 @@ private K withReference(// // ref.getBundle().getSignerCertificates(Bundle.SIGNERS_TRUSTED); return onSeveralFrameworks.apply(candidates); } - ServiceReference reference = candidates.iterator().next(); // size is precisely 1 - + ServiceReference reference = candidates.iterator().next(); // size is precisely 1 try { return onFramework.apply(reference); } finally { @@ -127,4 +121,13 @@ private K withReference(// } } + private Collection> frameworks() { + try { + // DI is used only to get rid of overwhelming dependencies here + return context.getServiceReferences(component, null); + } catch (InvalidSyntaxException e) { + return Collections.emptyList(); + } + } + } diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/LicenseReadingServiceRequest.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/LicenseReadingServiceRequest.java index fd75e2a10..06ddebc17 100644 --- a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/LicenseReadingServiceRequest.java +++ b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/LicenseReadingServiceRequest.java @@ -18,7 +18,7 @@ import org.eclipse.passage.lic.internal.api.conditions.mining.LicenseReadingService; import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult; -public final class LicenseReadingServiceRequest extends FrameworkAware +public final class LicenseReadingServiceRequest extends SuppliedFrameworkAware implements Supplier> { @Override diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/SuppliedFrameworkAware.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/SuppliedFrameworkAware.java new file mode 100644 index 000000000..ce8871f85 --- /dev/null +++ b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/SuppliedFrameworkAware.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2020 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.lic.internal.equinox; + +import org.eclipse.passage.lic.internal.api.FrameworkSupplier; + +/** + *

+ * Base for services relying in a framework facilities. + *

+ *

+ * Use {@code withFrameworkService} to implement client level secondary services + * or {@code withFramework} to retrieve parts of configuration directly. + */ +public abstract class SuppliedFrameworkAware extends FrameworkAware { + + protected SuppliedFrameworkAware() { + super(FrameworkSupplier.class, FrameworkSupplier::get); + } + +} diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/io/BundleKeyKeeper.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/io/BundleKeyKeeper.java index 45c051058..76f476cc1 100644 --- a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/io/BundleKeyKeeper.java +++ b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/io/BundleKeyKeeper.java @@ -40,6 +40,10 @@ public final class BundleKeyKeeper implements KeyKeeper { private final Bundle bundle; private final String midpath; + public BundleKeyKeeper(Supplier product, Supplier bundle) { + this(product, bundle.get()); + } + public BundleKeyKeeper(Supplier product, Bundle bundle) { this(product, bundle, "OSGI-INF"); //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.passage.lic.net/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.lic.net/META-INF/MANIFEST.MF index 638fed01d..bfc572b68 100644 --- a/bundles/org.eclipse.passage.lic.net/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.lic.net/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Automatic-Module-Name: org.eclipse.passage.lic.net Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.passage.lic.net -Bundle-Version: 1.1.1.qualifier +Bundle-Version: 1.1.0.qualifier Bundle-Name: %Bundle-Name Bundle-Vendor: %Bundle-Vendor Bundle-Copyright: %Bundle-Copyright @@ -10,24 +10,29 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Require-Bundle: org.eclipse.emf.ecore.xmi;bundle-version="0.0.0", org.eclipse.passage.lic.floating.model;bundle-version="0.1.0", org.eclipse.passage.lic.base;bundle-version="1.0.101";visibility:=reexport, - org.apache.logging.log4j;bundle-version="2.8.2" + org.apache.logging.log4j;bundle-version="2.8.2", + org.eclipse.passage.lic.equinox;bundle-version="1.0.101" Export-Package: org.eclipse.passage.lic.internal.net; x-friends:="org.eclipse.passage.lbc.base, org.eclipse.passage.lic.hc, org.eclipse.passage.lbc.jetty, - org.eclipse.passage.lbc.base.tests", + org.eclipse.passage.lbc.base.tests, + org.eclipse.passage.lac", + org.eclipse.passage.lic.internal.net.api;x-friends:="org.eclipse.passage.lac.seal", org.eclipse.passage.lic.internal.net.api.handle; x-friends:="org.eclipse.passage.lac, org.eclipse.passage.lac.jetty, org.eclipse.passage.lbc.base, org.eclipse.passage.lbc.base.tests, org.eclipse.passage.lbc.jetty, - org.eclipse.passage.lic.jetty", + org.eclipse.passage.lic.jetty, + org.eclipse.passage.lac.seal", org.eclipse.passage.lic.internal.net.connect, org.eclipse.passage.lic.internal.net.handle; x-friends:="org.eclipse.passage.lac, org.eclipse.passage.lbc.base, org.eclipse.passage.lic.jetty, org.eclipse.passage.lbc.jetty, - org.eclipse.passage.lbc.base.tests" + org.eclipse.passage.lbc.base.tests, + org.eclipse.passage.lac.seal" Bundle-ActivationPolicy: lazy diff --git a/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/NetFrameworkAware.java b/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/NetFrameworkAware.java new file mode 100644 index 000000000..619e9b500 --- /dev/null +++ b/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/NetFrameworkAware.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.lic.internal.net; + +import java.util.Optional; + +import org.eclipse.passage.lic.internal.equinox.FrameworkAware; +import org.eclipse.passage.lic.internal.net.api.FrameworkConstructor; +import org.eclipse.passage.lic.internal.net.api.handle.NetRequest; +import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest; + +public abstract class NetFrameworkAware extends FrameworkAware { + + protected NetFrameworkAware(ProductUserRequest request) { + super(FrameworkConstructor.class, ctor -> Optional.of(ctor.forRequest(request))); + } + +} diff --git a/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/api/FrameworkConstructor.java b/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/api/FrameworkConstructor.java new file mode 100644 index 000000000..0adc95a5d --- /dev/null +++ b/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/api/FrameworkConstructor.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.lic.internal.net.api; + +import org.eclipse.passage.lic.internal.api.Framework; +import org.eclipse.passage.lic.internal.net.api.handle.NetRequest; +import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest; + +public interface FrameworkConstructor { + + Framework forRequest(ProductUserRequest request); // + +} diff --git a/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/i18n/NetMessages.properties b/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/i18n/NetMessages.properties index 64ac0652e..a97599fab 100644 --- a/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/i18n/NetMessages.properties +++ b/bundles/org.eclipse.passage.lic.net/src/org/eclipse/passage/lic/internal/net/i18n/NetMessages.properties @@ -10,5 +10,6 @@ # Contributors: # ArSysOp - initial API and implementation ############################################################################### +DecodedParam.DecodedParam_decode_failed=Failed to decode url param value [%s] LicensingServerCoordinatesFromSettings.settings_are_blank=%s cannot be blank LicensingServerCoordinatesFromSettings.settings_not_found=%s is not found diff --git a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/CodecSupplier.java b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/CodecSupplier.java index 9142395d3..77aa74341 100644 --- a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/CodecSupplier.java +++ b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/CodecSupplier.java @@ -18,10 +18,10 @@ import org.eclipse.passage.lic.internal.api.Framework; import org.eclipse.passage.lic.internal.api.LicensedProduct; import org.eclipse.passage.lic.internal.api.io.StreamCodec; -import org.eclipse.passage.lic.internal.equinox.FrameworkAware; +import org.eclipse.passage.lic.internal.equinox.SuppliedFrameworkAware; @SuppressWarnings("restriction") -public final class CodecSupplier extends FrameworkAware implements Supplier> { +public final class CodecSupplier extends SuppliedFrameworkAware implements Supplier> { private final LicensedProduct product; diff --git a/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/io/BundleKeyKeeperTest.java b/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/io/BundleKeyKeeperTest.java index 4d1f0a8ac..c821391b0 100644 --- a/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/io/BundleKeyKeeperTest.java +++ b/tests/org.eclipse.passage.lic.equinox.tests/src/org/eclipse/passage/lic/internal/equinox/io/BundleKeyKeeperTest.java @@ -63,7 +63,7 @@ public void productIsMandatory() { @Test(expected = NullPointerException.class) public void bundleIsMandatory() { - new BundleKeyKeeper(this::productWithKey, null); + new BundleKeyKeeper(this::productWithKey, (Bundle) null); } private Bundle bundle() { @@ -77,4 +77,5 @@ private LicensedProduct productWithKey() { private LicensedProduct productWithoutKey() { return new BaseLicensedProduct("another-fake-product", "1.0.0"); //$NON-NLS-1$ //$NON-NLS-2$ } + }