Skip to content

Commit

Permalink
Bug 568632 Implement feature grant acquire/release
Browse files Browse the repository at this point in the history
Make Licensing Conditions mining servce to be identified with it's own
meaningful type.

License Acquisition service is about to be identified wit the same
class.

Signed-off-by: eparovyshnaya <[email protected]>
  • Loading branch information
eparovyshnaya committed Nov 9, 2020
1 parent 9be9d47 commit c28ddbb
Show file tree
Hide file tree
Showing 24 changed files with 157 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.function.Supplier;

import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.registry.StringServiceId;
import org.eclipse.passage.lic.internal.api.conditions.mining.ConditionMiningTarget;
import org.eclipse.passage.lic.internal.base.conditions.mining.LocalConditions;
import org.eclipse.passage.lic.internal.base.conditions.mining.MiningEquipment;
import org.eclipse.passage.lic.internal.base.io.LicensingFolder;
Expand All @@ -29,7 +29,7 @@
public class VaultMinedConditions extends LocalConditions {

protected VaultMinedConditions(MiningEquipment equipment) {
super(new StringServiceId("server-conditions"), equipment); //$NON-NLS-1$
super(new ConditionMiningTarget.Of("server-conditions"), equipment); //$NON-NLS-1$
}

@Override
Expand Down
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 @@ -47,7 +47,9 @@ Export-Package: org.eclipse.passage.lic.internal.api;
org.eclipse.passage.lic.json,
org.eclipse.passage.lic.hc,
org.eclipse.passage.lic.licenses.migration,
org.eclipse.passage.lic.base",
org.eclipse.passage.lic.base,
org.eclipse.passage.lic.equinox,
org.eclipse.passage.lic.base.tests",
org.eclipse.passage.lic.internal.api.diagnostic;
x-friends:="org.eclipse.passage.lic.base,
org.eclipse.passage.lic.jface,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*******************************************************************************
* 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.api.conditions;

public interface ConditionSource {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*******************************************************************************
* 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.api.conditions.mining;

import java.util.Objects;

import org.eclipse.passage.lic.internal.api.registry.ServiceId;

/**
* String-valued {@linkplain ServiceId} with mime content type semantics
*/
public abstract class ConditionMiningTarget implements ServiceId {

private final String target;

public ConditionMiningTarget(String target) {
Objects.requireNonNull(target, "ConditionMiningTarget::target"); //$NON-NLS-1$
this.target = target;
}

@Override
public boolean equals(Object object) {
if (!getClass().isInstance(object)) {
return false;
}
return target.equals(((ConditionMiningTarget) object).target());
}

public String target() {
return target;
}

@Override
public int hashCode() {
return target.hashCode();
}

@Override
public String toString() {
return target;
}

public ConditionMiningTarget child(String subtarget) {
Objects.requireNonNull(subtarget, "ConditionMiningTarget::child"); //$NON-NLS-1$
return new Of(String.format("%s/%s", target, subtarget)); //$NON-NLS-1$
}

public static final class Local extends ConditionMiningTarget {

public Local() {
super("local-file-system"); //$NON-NLS-1$
}

}

public static final class Remote extends ConditionMiningTarget {

public Remote() {
super("remote"); //$NON-NLS-1$
}

}

public static final class Of extends ConditionMiningTarget {

public Of(String target) {
super(target.toLowerCase());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.eclipse.passage.lic.internal.api.conditions.Condition;
import org.eclipse.passage.lic.internal.api.conditions.ConditionPack;
import org.eclipse.passage.lic.internal.api.registry.Service;
import org.eclipse.passage.lic.internal.api.registry.StringServiceId;

/**
* <p>
Expand All @@ -39,7 +38,7 @@
* The service is intended to implement the third phase of <i>access cycle</i>.
* </p>
*/
public interface MinedConditions extends Service<StringServiceId> {
public interface MinedConditions extends Service<ConditionMiningTarget> {

/**
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import java.util.function.Supplier;

import org.eclipse.passage.lic.internal.api.registry.Registry;
import org.eclipse.passage.lic.internal.api.registry.StringServiceId;

public interface MinedConditionsRegistry extends Supplier<Registry<StringServiceId, MinedConditions>> {
public interface MinedConditionsRegistry extends Supplier<Registry<ConditionMiningTarget, MinedConditions>> {

}
12 changes: 10 additions & 2 deletions bundles/org.eclipse.passage.lic.base/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ Export-Package: org.eclipse.passage.lic.internal.base;
org.eclipse.passage.loc.workbench.emfforms,
org.eclipse.passage.lic.licenses.migration",
org.eclipse.passage.lic.internal.base.conditions.evaluation;x-internal:=true,
org.eclipse.passage.lic.internal.base.conditions.mining;x-friends:="org.eclipse.passage.lic.jface,org.eclipse.passage.lic.hc,org.eclipse.passage.lbc.base",
org.eclipse.passage.lic.internal.base.conditions.mining;
x-friends:="org.eclipse.passage.lic.jface,
org.eclipse.passage.lic.hc,
org.eclipse.passage.lbc.base,
org.eclipse.passage.lic.equinox,
org.eclipse.passage.lic.base.tests,
org.eclipse.passage.lic.base",
org.eclipse.passage.lic.internal.base.diagnostic;
x-friends:="org.eclipse.passage.lic.equinox.tests,
org.eclipse.passage.lic.equinox,
Expand All @@ -41,7 +47,9 @@ Export-Package: org.eclipse.passage.lic.internal.base;
org.eclipse.passage.lic.equinox,
org.eclipse.passage.lic.floating,
org.eclipse.passage.loc.licenses.core,
org.eclipse.passage.lic.hc",
org.eclipse.passage.lic.hc,
org.eclipse.passage.lic.base,
org.eclipse.passage.lic.base.tests",
org.eclipse.passage.lic.internal.base.observatory;x-internal:=true,
org.eclipse.passage.lic.internal.base.registry;x-friends:="org.eclipse.passage.lbc.base",
org.eclipse.passage.lic.internal.base.requirements;x-internal:=true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ protected ServiceInvocationResult<ExaminationCertificate> stopOnError(Diagnostic
@Override
protected ServiceInvocationResult<ExaminationCertificate> stopOnCertificate(ExaminationCertificate certificate,
Diagnostic diagnostic) {
if (feature().isPresent()) {
return acquire(certificate, diagnostic);
}
return new BaseServiceInvocationResult<ExaminationCertificate>(diagnostic, certificate);
}

Expand All @@ -50,4 +53,11 @@ protected ServiceInvocationResult<ExaminationCertificate> freeWayOut() {
Collections.emptySet()));
}

private ServiceInvocationResult<ExaminationCertificate> acquire(ExaminationCertificate certificate,
Diagnostic diagnostic) {

// TODO: YTBD
return new BaseServiceInvocationResult<ExaminationCertificate>(diagnostic, certificate);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,34 @@
import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.lic.internal.api.conditions.ConditionPack;
import org.eclipse.passage.lic.internal.api.conditions.mining.ConditionMiningTarget;
import org.eclipse.passage.lic.internal.api.conditions.mining.MinedConditions;
import org.eclipse.passage.lic.internal.api.diagnostic.Trouble;
import org.eclipse.passage.lic.internal.api.registry.Registry;
import org.eclipse.passage.lic.internal.api.registry.StringServiceId;
import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult;
import org.eclipse.passage.lic.internal.base.SumOfCollections;
import org.eclipse.passage.lic.internal.base.conditions.ConditionsFeatureFilter;
import org.eclipse.passage.lic.internal.base.diagnostic.code.NoServicesOfType;
import org.eclipse.passage.lic.internal.base.i18n.AccessCycleMessages;

@SuppressWarnings("restriction")
public final class Conditions implements Supplier<ServiceInvocationResult<Collection<ConditionPack>>> {

private final Registry<StringServiceId, MinedConditions> registry;
private final Registry<ConditionMiningTarget, MinedConditions> registry;
private final LicensedProduct product;
private final Function<//
ServiceInvocationResult<Collection<ConditionPack>>, //
ServiceInvocationResult<Collection<ConditionPack>>> filter;

public Conditions(Registry<StringServiceId, MinedConditions> registry, LicensedProduct product, String feature) {
public Conditions(Registry<ConditionMiningTarget, MinedConditions> registry, LicensedProduct product,
String feature) {
this(registry, product, new ConditionsFeatureFilter(feature).get());
}

public Conditions(Registry<StringServiceId, MinedConditions> registry, LicensedProduct product) {
public Conditions(Registry<ConditionMiningTarget, MinedConditions> registry, LicensedProduct product) {
this(registry, product, Function.identity());
}

public Conditions(Registry<StringServiceId, MinedConditions> registry, LicensedProduct product,
public Conditions(Registry<ConditionMiningTarget, MinedConditions> registry, LicensedProduct product,
Function<ServiceInvocationResult<Collection<ConditionPack>>, ServiceInvocationResult<Collection<ConditionPack>>> filter) {
Objects.requireNonNull(registry, "Conditions::registry"); //$NON-NLS-1$
Objects.requireNonNull(product, "Conditions::product"); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ T apply() {
return examine(this::requirements, this::permissions);
}

protected Optional<String> feature() {
return feature;
}

private T examine(Supplier<ServiceInvocationResult<Collection<Requirement>>> requirements, //
Supplier<ServiceInvocationResult<Collection<Permission>>> permissions) {
ServiceInvocationResult<Collection<Requirement>> reqs = requirements.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.lic.internal.api.conditions.ConditionPack;
import org.eclipse.passage.lic.internal.api.conditions.mining.ConditionMiningTarget;
import org.eclipse.passage.lic.internal.api.conditions.mining.LicenseReadingService;
import org.eclipse.passage.lic.internal.api.registry.StringServiceId;

@SuppressWarnings("restriction")
public final class BaseLicenseReadingService implements LicenseReadingService {

private final LicensedProduct product;
Expand All @@ -48,7 +47,7 @@ private static final class OnTheFlyConditions extends LocalConditions {
private final Path license;

private OnTheFlyConditions(Path license, MiningEquipment equipment) {
super(new StringServiceId("on-the-fly"), equipment); //$NON-NLS-1$
super(new ConditionMiningTarget.Of("on-the-fly"), equipment); //$NON-NLS-1$
this.license = license;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.eclipse.passage.lic.internal.api.conditions.mining.ContentType;
import org.eclipse.passage.lic.internal.base.BaseNamedData;

@SuppressWarnings("restriction")
public final class LicensingContentType extends BaseNamedData<ContentType> {

public LicensingContentType(Function<String, ContentType> retrieve) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.lic.internal.api.conditions.Condition;
import org.eclipse.passage.lic.internal.api.conditions.ConditionPack;
import org.eclipse.passage.lic.internal.api.conditions.mining.ConditionMiningTarget;
import org.eclipse.passage.lic.internal.api.conditions.mining.MinedConditions;
import org.eclipse.passage.lic.internal.api.diagnostic.Trouble;
import org.eclipse.passage.lic.internal.api.registry.StringServiceId;
import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult;
import org.eclipse.passage.lic.internal.base.diagnostic.code.ServiceFailedOnInfrastructureDenial;
import org.eclipse.passage.lic.internal.base.i18n.ConditionMiningMessages;
Expand All @@ -38,21 +38,20 @@
* declare.
* </p>
*/
@SuppressWarnings("restriction")
public abstract class LocalConditions implements MinedConditions {

private final StringServiceId id;
private final ConditionMiningTarget id;
private final MiningEquipment equipment;

protected LocalConditions(StringServiceId id, MiningEquipment equipment) {
protected LocalConditions(ConditionMiningTarget id, MiningEquipment equipment) {
Objects.requireNonNull(id, getClass().getSimpleName() + "::id"); //$NON-NLS-1$
Objects.requireNonNull(equipment, getClass().getSimpleName() + "::equipment"); //$NON-NLS-1$
this.id = id;
this.equipment = equipment;
}

@Override
public final StringServiceId id() {
public final ConditionMiningTarget id() {
return id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.eclipse.passage.lic.internal.api.io.StreamCodecRegistry;
import org.eclipse.passage.lic.internal.base.i18n.BaseMessages;

@SuppressWarnings("restriction")
public final class MiningEquipment {

private final KeyKeeperRegistry keys;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.eclipse.passage.lic.internal.api.io.EncryptionAlgorithm;
import org.eclipse.passage.lic.internal.base.BaseNamedData;

@SuppressWarnings("restriction")
public final class SecurityKeyAlgorithm extends BaseNamedData<EncryptionAlgorithm> {

public SecurityKeyAlgorithm(Function<String, EncryptionAlgorithm> retrieve) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.eclipse.passage.lic.internal.api.io.EncryptionKeySize;
import org.eclipse.passage.lic.internal.base.BaseNamedData;

@SuppressWarnings("restriction")
public final class SecurityKeySize extends BaseNamedData<EncryptionKeySize> {

public SecurityKeySize(Function<String, EncryptionKeySize> retrieve) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.function.Supplier;

import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.registry.StringServiceId;
import org.eclipse.passage.lic.internal.api.conditions.mining.ConditionMiningTarget;
import org.eclipse.passage.lic.internal.base.io.LicensingFolder;
import org.eclipse.passage.lic.internal.base.io.PathFromLicensedProduct;
import org.eclipse.passage.lic.internal.base.io.UserHomePath;
Expand All @@ -28,7 +28,7 @@
public final class UserHomeResidentConditions extends LocalConditions {

public UserHomeResidentConditions(MiningEquipment equipment) {
super(new StringServiceId("user-home-conditions"), equipment); //$NON-NLS-1$
super(new ConditionMiningTarget.Local().child("user-home-conditions"), equipment); //$NON-NLS-1$
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import org.eclipse.passage.lic.internal.api.io.DigestExpectation;

@SuppressWarnings("restriction")
public final class BaseDigestExpectation implements DigestExpectation {

private final byte[] digest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.function.Supplier;

import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.registry.StringServiceId;
import org.eclipse.passage.lic.internal.api.conditions.mining.ConditionMiningTarget;
import org.eclipse.passage.lic.internal.base.conditions.mining.LocalConditions;
import org.eclipse.passage.lic.internal.base.conditions.mining.MiningEquipment;
import org.eclipse.passage.lic.internal.base.io.LicensingFolder;
Expand All @@ -28,11 +28,10 @@
* settings folder located under the product {@code configuration} directory
* (supplied by the eclipse platform).
*/
@SuppressWarnings("restriction")
public final class ConfigurationResidentConditions extends LocalConditions {

public ConfigurationResidentConditions(MiningEquipment equipment) {
super(new StringServiceId("configuration-conditions"), equipment); //$NON-NLS-1$
super(new ConditionMiningTarget.Local().child("configuration-conditions"), equipment); //$NON-NLS-1$
}

@Override
Expand Down
Loading

0 comments on commit c28ddbb

Please sign in to comment.