From 30563cd141945c449d1e2113dd49e84be38b2b26 Mon Sep 17 00:00:00 2001 From: "elena.parovyshnaya" Date: Tue, 16 Jun 2020 16:09:41 +0300 Subject: [PATCH 1/4] Bug 564328 API revision | conditions | rethink key interfaces - 'LicensingCondition' interface reconstructed Signed-off-by: elena.parovyshnaya --- .../META-INF/MANIFEST.MF | 1 + .../api/conditions/LicensingCondition.java | 104 +++++++++--------- .../internal/api/conditions/Condition.java | 63 +++++++++++ .../conditions/EvaluationInstructions.java | 43 ++++++++ .../api/conditions/EvaluationType.java | 81 ++++++++++++++ .../internal/api/conditions/MatchingRule.java | 45 ++++++++ .../api/conditions/ValidityPeriod.java | 31 ++++++ .../internal/api/conditions/VersionMatch.java | 44 ++++++++ .../internal/api/conditions/package-info.java | 24 ++++ .../api/restrictions/RestrictionLevel.java | 2 - 10 files changed, 386 insertions(+), 52 deletions(-) create mode 100644 bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/Condition.java create mode 100644 bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/EvaluationInstructions.java create mode 100644 bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/EvaluationType.java create mode 100644 bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/MatchingRule.java create mode 100644 bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/ValidityPeriod.java create mode 100644 bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/VersionMatch.java create mode 100644 bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/package-info.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 869a7842d..c10ada2c6 100644 --- a/bundles/org.eclipse.passage.lic.api/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.lic.api/META-INF/MANIFEST.MF @@ -22,6 +22,7 @@ Export-Package: org.eclipse.passage.lic.api, org.eclipse.passage.loc.products.ui, org.eclipse.passage.loc.users.ui, org.eclipse.passage.loc.api", + org.eclipse.passage.lic.internal.api.conditions;x-internal:=true, org.eclipse.passage.lic.internal.api.registry;x-internal:=true, org.eclipse.passage.lic.internal.api.requirements;x-internal:=true, org.eclipse.passage.lic.internal.api.restrictions;x-internal:=true diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/api/conditions/LicensingCondition.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/api/conditions/LicensingCondition.java index c3eac25d6..f2bdb9f10 100644 --- a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/api/conditions/LicensingCondition.java +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/api/conditions/LicensingCondition.java @@ -17,72 +17,76 @@ import org.eclipse.passage.lic.api.access.PermissionEmitter; /** - * Defines the set of terms under which the identified {@code Feature} can be used. - * to be evaluated by {@link PermissionEmitter}
+ * Defines the set of terms under which the identified {@code Feature} can be + * used. to be evaluated by {@link PermissionEmitter}
* Obtained from {@link ConditionMiner} * + * @deprecated use {@linkplain Condition} instead * @since 0.5.0 */ +@Deprecated public interface LicensingCondition { - /** - * Returns unique identifier of a feature under licensing. - * - * @return feature identifier - * @since 0.5.0 - */ + /** + * Returns unique identifier of a feature under licensing. + * + * @return feature identifier + * @since 0.5.0 + */ String getFeatureIdentifier(); - /** - * Returns descriptor of the feature version allowed by this licensing condition. - * - * @return version descriptor - * @since 0.5.0 - */ + /** + * Returns descriptor of the feature version allowed by this licensing + * condition. + * + * @return version descriptor + * @since 0.5.0 + */ String getMatchVersion(); - /** - * Returns rule of version matching, like "perfect match" or "equal or greater". - * - * @return match rule - * @since 0.5.0 - */ + /** + * Returns rule of version matching, like "perfect match" or "equal or greater". + * + * @return match rule + * @since 0.5.0 + */ String getMatchRule(); - /** - * Returns the validity period start date of this licensing condition. This is - * the value of its "validFrom" attribute. - * - * @return the valid from - * @since 0.5.0 - */ + /** + * Returns the validity period start date of this licensing condition. This is + * the value of its "validFrom" attribute. + * + * @return the valid from + * @since 0.5.0 + */ Date getValidFrom(); - /** - * Returns the validity period end date of this licensing condition. This is the - * value of its "validUntil" attribute. - * - * @return the valid until - * @since 0.5.0 - */ + /** + * Returns the validity period end date of this licensing condition. This is the + * value of its "validUntil" attribute. + * + * @return the valid until + * @since 0.5.0 + */ Date getValidUntil(); - /** - * The type of condition like "time" or "hardware". - * Defines the way the condition will be evaluated in a running environment. - * - * @return condition type - * @since 0.5.0 - */ + /** + * The type of condition like "time" or "hardware". Defines the way the + * condition will be evaluated in a running environment. + * + * @return condition type + * @since 0.5.0 + */ String getConditionType(); - /** - * Returns additional data encoded in a single string value. - * The expression is utilized by {@link PermissionEmitter} in conjunction with {@code conditionType} - * - * @return enlistment of additional information of this licencing condition - * @see PermissionEmitter - * @see #getConditionType - * @since 0.5.0 - */ + /** + * Returns additional data encoded in a single string value. The expression is + * utilized by {@link PermissionEmitter} in conjunction with + * {@code conditionType} + * + * @return enlistment of additional information of this licensing condition + * @see PermissionEmitter + * @see #getConditionType + * @since 0.5.0 + */ String getConditionExpression(); } diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/Condition.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/Condition.java new file mode 100644 index 000000000..8686f6781 --- /dev/null +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/Condition.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * 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; + +/** + *

+ * Regarding each feature under licensing there is a series of statements in a + * license of some kind. + *

+ *

+ * These statements demands the feature to be used under curtain + * {@code condition}s, such as "only version older than 2.14.1 on a workstation + * under Windows OS with hard disk of serial AB0123C4DEFJHI and only for two + * years starting from the 1st of May, 2020." {@code Condition} represents such + * a bundle of demands. + *

+ */ +public interface Condition { + + /** + * @return unique identifier of a feature under licensing. + */ + String feature(); + + /** + * Define the actual {@code version} representing string that has been mined in + * the scope of this condition (typically from license of sorts). + * + * @see VersionMatch + */ + VersionMatch versionMatch(); + + /** + * Period of this condition applicability. + * + * @see ValidityPeriod + */ + ValidityPeriod validityPeriod(); + + /** + *

+ * Defined how exactly the condition is to be evaluates. + *

+ *

+ * Type of a license dictates how Passage can evaluate the condition (check if + * all it's demands are met). For example, "hardware" license requires examining + * of the actual workstation hardware. + *

+ * + * @see EvaluationInstructions + */ + EvaluationInstructions evaluationInstructions(); +} diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/EvaluationInstructions.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/EvaluationInstructions.java new file mode 100644 index 000000000..82e981a68 --- /dev/null +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/EvaluationInstructions.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * 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; + +/** + *

+ * Condition definition contains sufficient amount of instructions on how + * exactly can we say if this condition is satisfied or not. + *

+ *

+ * For example, condition of {@code hardware} type requires actual workstation + * hardware evaluation and assessing it against condition's expectations. These + * ones can demand particular hardware part of have predefined serial id. + *

+ */ +public interface EvaluationInstructions { + + /** + * Meta classifier of the way this condition can be evaluated + * + * @see EvaluationType + */ + EvaluationType type(); + + /** + * Precise data for evaluation. Each evaluation type can expect it's own format + * here. + * + * @return raw string mined from a license + */ + String expression(); + +} diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/EvaluationType.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/EvaluationType.java new file mode 100644 index 000000000..0dddccb67 --- /dev/null +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/EvaluationType.java @@ -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; + +import java.util.Objects; + +/** + *

+ * Defines the way the condition will be evaluated in a running environment. The + * type of condition like "time" or "hardware". + *

+ *

+ * Designed to be a data-class. + *

+ */ +public abstract class EvaluationType { + + private final String identifier; + + protected EvaluationType(String identifier) { + Objects.requireNonNull(identifier, "Identifier is mandatory for condition type"); //$NON-NLS-1$ + this.identifier = identifier.trim().toLowerCase(); + } + + public final String identifier() { + return identifier; + } + + @Override + public final int hashCode() { + return Objects.hash(identifier()); + } + + @Override + public final boolean equals(Object object) { + if (!EvaluationType.class.isInstance(object)) { + return false; + } + return identifier.equals(((EvaluationType) object).identifier); + } + + @Override + public final String toString() { + return identifier; + } + + public static final class Time extends EvaluationType { + + public Time() { + super("time"); //$NON-NLS-1$ + } + + } + + public static final class Hardware extends EvaluationType { + + public Hardware() { + super("hardware"); //$NON-NLS-1$ + } + + } + + public static final class Of extends EvaluationType { + + public Of(String identifier) { + super(identifier); + } + + } + +} diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/MatchingRule.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/MatchingRule.java new file mode 100644 index 000000000..a63514a41 --- /dev/null +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/MatchingRule.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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; + +/** + *

+ * Defines the way a actual string (tested) can be matched with a predefined + * one. (beacon). + *

+ *

+ * For example {@code perfect match} for any string type would mean absolute + * equality, and {@code not less} match rule for a {@code version} strings would + * mean that match is successful iff the tested version is greater or equal than + * the beacon one. + *

+ * + * @see VersionMatch + * @see Condition + */ +public abstract interface MatchingRule { + + /** + * Descriptive identifier of a rule. + * + * @return + */ + String identifier(); + + /** + * Find out if the {@code tested} string {@code matches} with the {@code beacon} + * one. + */ + boolean match(String tested, String beacon); + +} diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/ValidityPeriod.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/ValidityPeriod.java new file mode 100644 index 000000000..b6cdddf9b --- /dev/null +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/ValidityPeriod.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.api.conditions; + +import java.util.Date; + +/** + * Time period in which {@code Condition} is valid. + */ +public interface ValidityPeriod { + + /** + * Check if the given {@code date} belongs to the validity period. + * + * @param not null date to be checked if it belongs to the period of validity or + * not + * @return {@code true} if date is valid and {@code false} otherwise + */ + boolean valid(Date date); + +} diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/VersionMatch.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/VersionMatch.java new file mode 100644 index 000000000..e69f8d25e --- /dev/null +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/VersionMatch.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * 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; + +/** + * + *

+ * Part of licensing {@linkplain Condition} that declares license demands + * regarding the feature version. + *

+ *

+ * This way or another a license defines which version of a feature is allowed + * to use. It also defines how far from this specified version can be the + * actual version of the feature that has been plugged to the product under + * licensing. + *

+ * + * @see Condition + */ +public interface VersionMatch { + + /** + * @return {@code version} definition string, can contain wildcards like + * {@code 1.12.*} meaning any build of version {@code 1.12} + */ + String version(); + + /** + * @return rule of version matching, like "perfect match" or "equal or greater". + * @see MatchingRule + */ + MatchingRule rule(); + +} diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/package-info.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/package-info.java new file mode 100644 index 000000000..561b5aa98 --- /dev/null +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/package-info.java @@ -0,0 +1,24 @@ +/* ***************************************************************************** + * 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 + *******************************************************************************/ + +/** + *

+ * Here we cover condition mining phase of access cycle. + *

+ *

+ * {@code null}-free zone: no interface or class is intended to receive or + * return {@code null}. Implementations must extend and satisfy the + * corresponding contract tests. + *

+ */ +package org.eclipse.passage.lic.internal.api.conditions; \ No newline at end of file diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/restrictions/RestrictionLevel.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/restrictions/RestrictionLevel.java index e9c4141a3..c866d33bd 100644 --- a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/restrictions/RestrictionLevel.java +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/restrictions/RestrictionLevel.java @@ -24,8 +24,6 @@ */ public abstract class RestrictionLevel { - // FIXME: to be used further - // private final String meta = "licensing.restriction.level"; //$NON-NLS-1$ private final String identifier; protected RestrictionLevel(String identifier) { From 9b5b0d64b37c9693ceaab5b9a9eeaf9effa279a9 Mon Sep 17 00:00:00 2001 From: "elena.parovyshnaya" Date: Tue, 16 Jun 2020 21:09:06 +0300 Subject: [PATCH 2/4] Bug 564328 API revision | conditions | rethink key interfaces - update MatchingRule documentation Signed-off-by: elena.parovyshnaya --- .../internal/api/conditions/MatchingRule.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/MatchingRule.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/MatchingRule.java index a63514a41..bf5f38a2d 100644 --- a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/MatchingRule.java +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/MatchingRule.java @@ -12,16 +12,20 @@ *******************************************************************************/ package org.eclipse.passage.lic.internal.api.conditions; +import org.eclipse.passage.lic.internal.api.requirements.Requirement; + /** *

- * Defines the way a actual string (tested) can be matched with a predefined - * one. (beacon). + * Defines the way a two strings can be matched. + *

+ *

+ * In scope of condition evaluation we find out if version comes from + * {@linkplain Requirement} ({@code required}) {@code match} to version + * definition string that comes from a license of source through + * {@linkplain Condition} ({@code allowed}). *

*

- * For example {@code perfect match} for any string type would mean absolute - * equality, and {@code not less} match rule for a {@code version} strings would - * mean that match is successful iff the tested version is greater or equal than - * the beacon one. + * For example {@code perfect match} match rule would mean absolute equality. *

* * @see VersionMatch @@ -37,9 +41,9 @@ public abstract interface MatchingRule { String identifier(); /** - * Find out if the {@code tested} string {@code matches} with the {@code beacon} - * one. + * Find out if the {@code required} ({@code actual}) string {@code matches} with + * the {@code allowed} one ({@code expected}). */ - boolean match(String tested, String beacon); + boolean match(String required, String allowed); } From 1ba1478dc38ad4f79589952df9920b53c9272194 Mon Sep 17 00:00:00 2001 From: "elena.parovyshnaya" Date: Wed, 17 Jun 2020 08:14:38 +0300 Subject: [PATCH 3/4] Bug 564328 API revision | conditions | rethink key interfaces - get rid of Time EvaluationType as it is far from implementation - fix EvaluationType javadoc Signed-off-by: elena.parovyshnaya --- .../internal/api/conditions/EvaluationType.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/EvaluationType.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/EvaluationType.java index 0dddccb67..4c0d8adbf 100644 --- a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/EvaluationType.java +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/EvaluationType.java @@ -16,8 +16,10 @@ /** *

- * Defines the way the condition will be evaluated in a running environment. The - * type of condition like "time" or "hardware". + * Defines the way the condition will be evaluated in a running environment. For + * example, "hardware" means that specially dedicated module is going to access + * a workstation hardware in order to supply enough information to verify if the + * condition is met. *

*

* Designed to be a data-class. @@ -54,14 +56,6 @@ public final String toString() { return identifier; } - public static final class Time extends EvaluationType { - - public Time() { - super("time"); //$NON-NLS-1$ - } - - } - public static final class Hardware extends EvaluationType { public Hardware() { From 9bdd424f902f412fbcf92e9a5a1f0517a65dc7c5 Mon Sep 17 00:00:00 2001 From: "elena.parovyshnaya" Date: Wed, 17 Jun 2020 08:45:33 +0300 Subject: [PATCH 4/4] Bug 564328 API revision | conditions | rethink key interfaces - fix VersionMatch javadoc Signed-off-by: elena.parovyshnaya --- .../lic/internal/api/conditions/VersionMatch.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/VersionMatch.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/VersionMatch.java index e69f8d25e..ba2365b34 100644 --- a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/VersionMatch.java +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/conditions/VersionMatch.java @@ -21,16 +21,21 @@ *

* This way or another a license defines which version of a feature is allowed * to use. It also defines how far from this specified version can be the - * actual version of the feature that has been plugged to the product under - * licensing. + * actual version of the feature that is found at runtime. + *

+ *

+ * The class aggregates both data (a string describing version demands) + * and algorithmic (knowing how to match couple of version-supplying + * strings) parts. *

* * @see Condition + * @see MatchingRule */ public interface VersionMatch { /** - * @return {@code version} definition string, can contain wildcards like + * @return {@code version} definition string, can contain wild cards like * {@code 1.12.*} meaning any build of version {@code 1.12} */ String version();