Skip to content

Commit

Permalink
Merge pull request #656 from eclipse-passage/571190
Browse files Browse the repository at this point in the history
Bug 571190 build the solution on Framework services host
  • Loading branch information
eparovyshnaya authored Feb 15, 2021
2 parents fc1e185 + f242aee commit 4b9458e
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 53 deletions.
4 changes: 3 additions & 1 deletion bundles/org.eclipse.passage.lic.api/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion bundles/org.eclipse.passage.lic.equinox/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Collection<RuntimeEnvironment>> {
public final class Environments extends SuppliedFrameworkAware implements Supplier<Collection<RuntimeEnvironment>> {

@Override
public Collection<RuntimeEnvironment> get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExaminationCertificate> assess() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<S> {

private final BundleContext context;
private final Class<S> component;
private final Function<S, Optional<Framework>> constructor;

protected FrameworkAware() {
protected FrameworkAware(Class<S> cls, Function<S, Optional<Framework>> 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<ServiceReference<FrameworkSupplier>> 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 <T> ServiceInvocationResult<T> withFrameworkService(
Function<Framework, ServiceInvocationResult<T>> invoke) {
return withReference(//
reference -> //
Optional.ofNullable(context.getService(reference))//
.flatMap(constructor::apply)//
.map(invoke::apply)//
.orElseGet(this::noFramework), //
this::noFramework, //
this::severalFrameworks);
}

protected final <T> Optional<T> withFramework(Function<Framework, T> invoke) {
return withReference(//
reference -> //
Optional.ofNullable(context.getService(reference))//
.flatMap(constructor::apply)//
.map(invoke::apply), //
Optional::empty, //
any -> Optional.empty());
}

private <T> ServiceInvocationResult<T> noFramework() {
Expand All @@ -66,7 +83,7 @@ private <T> ServiceInvocationResult<T> noFramework() {
);
}

private <T> ServiceInvocationResult<T> severalFrameworks(Collection<ServiceReference<FrameworkSupplier>> findings) {
private <T> ServiceInvocationResult<T> severalFrameworks(Collection<ServiceReference<S>> findings) {
return new BaseServiceInvocationResult<T>(//
new BaseDiagnostic(//
findings.stream()//
Expand All @@ -76,39 +93,17 @@ private <T> ServiceInvocationResult<T> severalFrameworks(Collection<ServiceRefer
));
}

private Trouble foreignFramework(int singlings, ServiceReference<FrameworkSupplier> foreign) {
private Trouble foreignFramework(int singlings, ServiceReference<S> foreign) {
return new Trouble(//
new SeveralFrameworks(singlings), //
String.format(AccessMessages.EquinoxPassage_foreign_framework, foreign.getBundle().getSymbolicName()));
}

protected <T> ServiceInvocationResult<T> withFrameworkService(
Function<Framework, ServiceInvocationResult<T>> invoke) {
return withReference(//
reference -> //
Optional.ofNullable(context.getService(reference))//
.flatMap(FrameworkSupplier::get)//
.map(invoke::apply)//
.orElseGet(this::noFramework), //
this::noFramework, //
this::severalFrameworks);
}

protected <T> Optional<T> withFramework(Function<Framework, T> invoke) {
return withReference(//
reference -> //
Optional.ofNullable(context.getService(reference))//
.flatMap(FrameworkSupplier::get)//
.map(invoke::apply), //
Optional::empty, //
any -> Optional.empty());
}

private <K> K withReference(//
Function<ServiceReference<FrameworkSupplier>, K> onFramework, //
Function<ServiceReference<S>, K> onFramework, //
Supplier<K> onNoFramework, //
Function<Collection<ServiceReference<FrameworkSupplier>>, K> onSeveralFrameworks) {
Collection<ServiceReference<FrameworkSupplier>> candidates = frameworks();
Function<Collection<ServiceReference<S>>, K> onSeveralFrameworks) {
Collection<ServiceReference<S>> candidates = frameworks();
if (candidates.isEmpty()) {
return onNoFramework.get();
}
Expand All @@ -118,13 +113,21 @@ private <K> K withReference(//
// ref.getBundle().getSignerCertificates(Bundle.SIGNERS_TRUSTED);
return onSeveralFrameworks.apply(candidates);
}
ServiceReference<FrameworkSupplier> reference = candidates.iterator().next(); // size is precisely 1

ServiceReference<S> reference = candidates.iterator().next(); // size is precisely 1
try {
return onFramework.apply(reference);
} finally {
context.ungetService(reference);
}
}

private Collection<ServiceReference<S>> frameworks() {
try {
// DI is used only to get rid of overwhelming dependencies here
return context.getServiceReferences(component, null);
} catch (InvalidSyntaxException e) {
return Collections.emptyList();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ServiceInvocationResult<LicenseReadingService>> {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
* <p>
* Base for services relying in a framework facilities.
* </p>
* <p>
* Use {@code withFrameworkService} to implement client level secondary services
* or {@code withFramework} to retrieve parts of configuration directly.
*/
public abstract class SuppliedFrameworkAware extends FrameworkAware<FrameworkSupplier> {

protected SuppliedFrameworkAware() {
super(FrameworkSupplier.class, FrameworkSupplier::get);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public final class BundleKeyKeeper implements KeyKeeper {
private final Bundle bundle;
private final String midpath;

public BundleKeyKeeper(Supplier<LicensedProduct> product, Supplier<Bundle> bundle) {
this(product, bundle.get());
}

public BundleKeyKeeper(Supplier<LicensedProduct> product, Bundle bundle) {
this(product, bundle, "OSGI-INF"); //$NON-NLS-1$
}
Expand Down
15 changes: 10 additions & 5 deletions bundles/org.eclipse.passage.lic.net/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,37 @@ 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
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
Original file line number Diff line number Diff line change
@@ -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<R extends NetRequest> extends FrameworkAware<FrameworkConstructor> {

protected NetFrameworkAware(ProductUserRequest<R> request) {
super(FrameworkConstructor.class, ctor -> Optional.of(ctor.forRequest(request)));
}

}
Original file line number Diff line number Diff line change
@@ -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 {

<R extends NetRequest> Framework forRequest(ProductUserRequest<R> request); //

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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<Optional<StreamCodec>> {
public final class CodecSupplier extends SuppliedFrameworkAware implements Supplier<Optional<StreamCodec>> {

private final LicensedProduct product;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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$
}

}

0 comments on commit 4b9458e

Please sign in to comment.