Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 564328 API revision | conditions | rethink key interfaces #251

Merged
merged 3 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class EvaluationType {
private final String identifier;

protected EvaluationType(String identifier) {
Objects.requireNonNull(identifier, "Identifier is mandatory for condition type"); //$NON-NLS-1$
Objects.requireNonNull(identifier, "EvaluationType::identifier"); //$NON-NLS-1$
this.identifier = identifier.trim().toLowerCase();
}

Expand Down
1 change: 1 addition & 0 deletions bundles/org.eclipse.passage.lic.base/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Export-Package: org.eclipse.passage.lic.base,
org.eclipse.passage.lic.base.requirements,
org.eclipse.passage.lic.base.restrictions,
org.eclipse.passage.lic.internal.base;x-internal:=true,
org.eclipse.passage.lic.internal.base.conditions;x-internal:=true,
org.eclipse.passage.lic.internal.base.i18n;x-internal:=true,
org.eclipse.passage.lic.internal.base.permission;x-internal:=true,
org.eclipse.passage.lic.internal.base.permission.observatory;x-internal:=true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*******************************************************************************
* 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.base.conditions;

import java.util.Objects;

import org.eclipse.passage.lic.internal.api.conditions.Condition;
import org.eclipse.passage.lic.internal.api.conditions.EvaluationInstructions;
import org.eclipse.passage.lic.internal.api.conditions.ValidityPeriod;
import org.eclipse.passage.lic.internal.api.conditions.VersionMatch;

@SuppressWarnings("restriction")
public final class BaseCondition implements Condition {

private final String identifier;
private final VersionMatch version;
private final ValidityPeriod period;
private final EvaluationInstructions instructions;

public BaseCondition(String identifier, VersionMatch version, ValidityPeriod period,
EvaluationInstructions instructions) {
Objects.requireNonNull(identifier, "BaseCondition::Identifier"); //$NON-NLS-1$
Objects.requireNonNull(version, "BaseCondition::VersionMatch"); //$NON-NLS-1$
Objects.requireNonNull(period, "BaseCondition::ValidityPeriod"); //$NON-NLS-1$
Objects.requireNonNull(instructions, "BaseCondition::EvaluationInstructions"); //$NON-NLS-1$
this.identifier = identifier;
this.version = version;
this.period = period;
this.instructions = instructions;
}

@Override
public String feature() {
return identifier;
}

@Override
public VersionMatch versionMatch() {
return version;
}

@Override
public ValidityPeriod validityPeriod() {
return period;
}

@Override
public EvaluationInstructions evaluationInstructions() {
return instructions;
}

}
Original file line number Diff line number Diff line change
@@ -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.base.conditions;

import java.util.Objects;

import org.eclipse.passage.lic.internal.api.conditions.EvaluationInstructions;
import org.eclipse.passage.lic.internal.api.conditions.EvaluationType;

@SuppressWarnings("restriction")
public final class BaseEvaluationInstructions implements EvaluationInstructions {

private final EvaluationType type;
private final String expression;

public BaseEvaluationInstructions(EvaluationType type, String expression) {
Objects.requireNonNull(type, "BaseEvaluationInstructions::type"); //$NON-NLS-1$
Objects.requireNonNull(expression, "BaseEvaluationInstructions::expression"); //$NON-NLS-1$
this.type = type;
this.expression = expression;
}

@Override
public EvaluationType type() {
return type;
}

@Override
public String expression() {
return expression;
}

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

import java.util.Date;
import java.util.Objects;

import org.eclipse.passage.lic.internal.api.conditions.ValidityPeriodClosed;

@SuppressWarnings("restriction")
public final class BaseValidityPeriodClosed implements ValidityPeriodClosed {

private final Date from;
private final Date to;

public BaseValidityPeriodClosed(Date from, Date to) {
Objects.requireNonNull(from, "BaseValidityPeriodClosed::from"); //$NON-NLS-1$
Objects.requireNonNull(to, "BaseValidityPeriodClosed:to"); //$NON-NLS-1$
if (!from.before(to)) {
throw new IllegalStateException("BaseValidityPeriodClosed: 'from' must be strictly less than 'to'"); //$NON-NLS-1$
}
this.from = from;
this.to = to;
}

@Override
public Date from() {
return new Date(from.getTime());
}

@Override
public Date to() {
return new Date(to.getTime());
}

@Override
public boolean valid(Date date) {
Objects.requireNonNull(date, "BaseValidityPeriodClosed::valid::date"); //$NON-NLS-1$
return (from.before(date) || date.equals(from)) && //
(date.before(to) || date.equals(to));
}

}
Original file line number Diff line number Diff line change
@@ -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.base.conditions;

import java.util.Objects;

import org.eclipse.passage.lic.internal.api.conditions.MatchingRule;
import org.eclipse.passage.lic.internal.api.conditions.VersionMatch;

@SuppressWarnings("restriction")
public final class BaseVersionMatch implements VersionMatch {

private final String version;
private final MatchingRule rule;

public BaseVersionMatch(String version, MatchingRule rule) {
Objects.requireNonNull(version, "BaseVersionMatch::Version"); //$NON-NLS-1$
Objects.requireNonNull(rule, "BaseVersionMatch::MatchingRule"); //$NON-NLS-1$
this.version = version;
this.rule = rule;
}

@Override
public String version() {
return version;
}

@Override
public MatchingRule rule() {
return rule;
}

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

/**
* <p>
* We check two versions {@code required} (comes from requirements) and
* {@code allowed} (originated in licenses) to find out out if the requirement
* version is s <i>compatible</i> to the allowed one or not
* </p>
* <p>
* Key segment to check is {@code minor}. For successful matching
* {@code required.minor} must be greater or equal to {@code allowed.minor}.All
* higher segments (major) are expected to be equal for successful match. All
* lower segments (service, qualifier) are ignored and do not affect the
* matching.
* </p>
* <p>
* So, formally, {@code required} and {@code allowed} are <i>compatible</i> iff
* </p>
* <ul>
* <li>their {@code major} segments are equal AND</li>
* <li>{@code required.minor} >= {@code allowed.minor}</li>
* </ul>
* <p>
* {@code default required} always matches to any {@code allowed} version.
* </p>
*/
public final class MatchingRuleCompatible extends StrictMatchingRule {

@Override
public String identifier() {
return "compatible"; //$NON-NLS-1$
}

@Override
protected boolean safeMatch(String required, String allowed) {
return new RequiredVersionVsAllowedVersion(required, allowed).match(1);
}

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

@SuppressWarnings("restriction")
public final class MatchingRuleDefault extends StrictMatchingRule {

private final StrictMatchingRule assignee;

public MatchingRuleDefault() {
assignee = new MatchingRuleCompatible();
}

@Override
public String identifier() {
return assignee.identifier();
}

@Override
protected boolean safeMatch(String required, String allowed) {
return assignee.safeMatch(required, allowed);
}

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

/**
* <p>
* We check two versions: {@code required} (comes from requirements) and
* {@code allowed} (originated in licenses) to find out if the requirement
* version is s <i>equivalent</i> to the allowed one or not.
* </p>
* <p>
* Key segment to check is {@code service}. For successful matching
* {@code required.service} must be greater or equal to
* {@code allowed.service}.All higher segments (major, minor) are expected to be
* equal for successful match. All lower segments (qualifier) are ignored and do
* not affect the matching.
* </p>
* <p>
* So, formally, {@code required} and {@code allowed} are <i>equivalent</i> iff
* </p>
* <ul>
* <li>their {@code major} segments are equal AND</li>
* <li>their {@code minor} segments are equal AND</li>
* <li>{@code required.service} >= {@code allowed.service}</li>
* </ul>
* <p>
* {@code default required} always matches to any {@code allowed} version.
* </p>
*/
public final class MatchingRuleEquivalent extends StrictMatchingRule {

@Override
public String identifier() {
return "equivalent"; //$NON-NLS-1$
}

@Override
protected boolean safeMatch(String required, String allowed) {
return new RequiredVersionVsAllowedVersion(required, allowed).match(2);
}

}
Loading