Skip to content

Commit

Permalink
Merge pull request #266 from eclipse-passage/564566
Browse files Browse the repository at this point in the history
564566 [Passage] API revision | rework passage settings dirs supplying
  • Loading branch information
eparovyshnaya authored Jun 26, 2020
2 parents dcc81ec + bbe0f20 commit 6fb3dd3
Show file tree
Hide file tree
Showing 28 changed files with 470 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@
package org.eclipse.passage.lic.api;

/**
* <p>Runtime descriptor for the configuration being examined for restrictions.</p>
* <p>
* Runtime descriptor for the configuration being examined for restrictions.
* </p>
*
* <p>Represents the pair <code>{id, version}</code> for the running product. </p>
* <p>
* Represents the pair <code>{id, version}</code> for the running product.
* </p>
*
* @since 0.4.0
* @deprecated use LicensedProduct
*/
@Deprecated
public interface LicensingConfiguration {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@
package org.eclipse.passage.lic.api;

/**
* <p>A checked exception representing a failure.</p>
* <p> Licensing exceptions contain a result object describing the cause of the exception. </p>
* <p>
* A checked exception representing a failure.
* </p>
* <p>
* Licensing exceptions contain a result object describing the cause of the
* exception.
* </p>
*
* @see LicensingResult
* @deprecated use internal version
* @since 0.4.0
*/
@Deprecated
public class LicensingException extends Exception {

private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* 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;

import org.eclipse.passage.lic.internal.api.conditions.mining.MinedConditionsRegistry;
import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirementsRegistry;

/**
* Supplies all the service that runtime <i>access cycle</i> can count on.
*/
public interface AccessCycleConfiguration {

ResolvedRequirementsRegistry requirementsRegistry();

MinedConditionsRegistry conditionsRegistry();

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
*******************************************************************************/
package org.eclipse.passage.lic.internal.api;

import org.eclipse.passage.lic.internal.api.conditions.mining.MinedConditionsRegistry;
import org.eclipse.passage.lic.internal.api.requirements.ResolvedRequirementsRegistry;

/**
* <p>
* All the framework-relying constructions are to originate from this point this
Expand All @@ -37,8 +34,8 @@
*/
public interface Framework {

ResolvedRequirementsRegistry requirementsRegistry();
LicensedProduct product();

MinedConditionsRegistry conditionsRegistry();
AccessCycleConfiguration accessCycleConfiguration();

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

public interface LicensedProduct {

String identifier();

String version();

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

/**
* As licensing runtime is a complicated and infrastructure-dependent, wide
* variety of things can occasionally go south. This general purpose exception
* serves misbehaviors in crucial parts.
*/
public final class LicensingException extends Exception {

/**
* generated
*/
private static final long serialVersionUID = 7746884069745071894L;

public LicensingException(String message, Throwable cause) {
super(message, cause);
}

public LicensingException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
package org.eclipse.passage.lic.base;

import java.util.Map;
import java.util.Objects;

import org.eclipse.passage.lic.api.LicensingConfiguration;
import org.eclipse.passage.lic.internal.base.BaseLicensingConfiguration;
import org.eclipse.passage.lic.internal.base.BaseLicensedProduct;
import org.eclipse.passage.lic.internal.base.NamedData;
import org.eclipse.passage.lic.internal.base.ProductIdentifier;
import org.eclipse.passage.lic.internal.base.ProductVersion;

/**
*
* @deprecated use {@linkplain NamedData}, {@linkplain ProductInfo} or
* another implementations, {@linkplain BaseLicensingConfiguration}
* @deprecated use {@linkplain NamedData}, {@linkplain ProductInfo} or another
* implementations, {@linkplain BaseLicensedProduct}
*/
@Deprecated
public final class LicensingConfigurations {
Expand All @@ -32,21 +35,72 @@ public final class LicensingConfigurations {

public static final String IDENTIFIER_INVALID = "org.eclipse.passage.lic.api.configuration.invalid"; //$NON-NLS-1$

public static final LicensingConfiguration INVALID = new BaseLicensingConfiguration(IDENTIFIER_INVALID,
public static final LicensingConfiguration INVALID = new LicConfig(IDENTIFIER_INVALID,
LicensingVersions.VERSION_DEFAULT);

private LicensingConfigurations() {
// block
}

public static LicensingConfiguration create(String product, String version) {
return new BaseLicensingConfiguration(String.valueOf(product), String.valueOf(version));
return new LicConfig(String.valueOf(product), String.valueOf(version));
}

public static LicensingConfiguration create(Map<String, Object> properties) {
String product = String.valueOf(properties.get(LICENSING_PRODUCT_IDENTIFIER));
String version = String.valueOf(properties.get(LICENSING_PRODUCT_VERSION));
return new BaseLicensingConfiguration(product, version);
return new LicConfig(product, version);
}

private static final class LicConfig implements LicensingConfiguration {

private final String id;
private final String version;

private LicConfig(String id, String version) {
this.id = id;
this.version = version;
}

@Override
public String getProductIdentifier() {
return id;
}

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

@Override
public int hashCode() {
return Objects.hash(id, version);
}

@Override
public boolean equals(Object obj) {
if (!LicensingConfiguration.class.isInstance(obj)) {
return false;
}
LicensingConfiguration other = (LicensingConfiguration) obj;
if (!Objects.equals(id, other.getProductIdentifier())) {
return false;
}
if (!Objects.equals(version, other.getProductVersion())) {
return false;
}
return true;
}

@Override
public String toString() {
StringBuilder output = new StringBuilder();
new NamedData.Writable<String>(new ProductIdentifier(id)).write(output);
output.append(';');
new NamedData.Writable<String>(new ProductVersion(version)).write(output);
return output.toString();
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public Access(Framework framework) {
}

public boolean canUse(String feature) {
Set<Requirement> requirements = new Requirements(framework.requirementsRegistry().get(), feature).get();
Set<Requirement> requirements = new Requirements(
framework.accessCycleConfiguration().requirementsRegistry().get(), feature).get();
if (requirements.isEmpty()) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,61 +14,54 @@

import java.util.Objects;

import org.eclipse.passage.lic.api.LicensingConfiguration;
import org.eclipse.passage.lic.internal.api.LicensedProduct;

/**
* Default data-driven implementation of {@code LicensingConfiguration}. True
* {@code data-class}.
* Default data-driven implementation of {@code LicensedProduct} represents
* configuration of the running product. True {@code data-class}.
*
* @see LicensingConfiguration
* @see LicensedProduct
* @see ProductIdentifier
* @see ProductVersion
*/
public final class BaseLicensingConfiguration implements LicensingConfiguration {
@SuppressWarnings("restriction")
public final class BaseLicensedProduct implements LicensedProduct {

private final String identifier;
private final String version;

public BaseLicensingConfiguration(String product, String version) {
public BaseLicensedProduct(String product, String version) {
Objects.requireNonNull(product, "BaseLicensedProduct::product"); //$NON-NLS-1$
Objects.requireNonNull(version, "BaseLicensedProduct::version"); //$NON-NLS-1$
this.identifier = product;
this.version = version;
}

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

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

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((identifier == null) ? 0 : identifier.hashCode());
result = prime * result + ((version == null) ? 0 : version.hashCode());
return result;
return Objects.hash(identifier, version);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
if (!LicensedProduct.class.isInstance(obj)) {
return false;
}
BaseLicensingConfiguration other = (BaseLicensingConfiguration) obj;
if (!Objects.equals(identifier, other.identifier)) {
LicensedProduct other = (LicensedProduct) obj;
if (!Objects.equals(identifier, other.identifier())) {
return false;
}
if (!Objects.equals(version, other.version)) {
if (!Objects.equals(version, other.version())) {
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,33 @@
*******************************************************************************/
package org.eclipse.passage.lic.internal.base;

import org.eclipse.passage.lic.api.LicensingConfiguration;
import org.eclipse.passage.lic.internal.api.LicensedProduct;

/**
* {@linkplain LicensingConfiguration} is a key piece of data for an
* {@code access cycle}. For the cases any sabotage is detected this <i>
* {@linkplain LicensedProduct} is a key piece of data for an
* {@code access cycle}. For the cases of any sabotage is detected this <i>
* knowingly invalid</i> configuration is used to make an {@code access cycle}
* fail.
*/
public final class InvalidLicensingConfiguration implements LicensingConfiguration {
@SuppressWarnings("restriction")
public final class InvalidLicensedProduct implements LicensedProduct {

private final BaseLicensingConfiguration delegate;
private final BaseLicensedProduct delegate;

public InvalidLicensingConfiguration() {
delegate = new BaseLicensingConfiguration(//
public InvalidLicensedProduct() {
delegate = new BaseLicensedProduct(//
"org.eclipse.passage.lic.api.configuration.invalid", //$NON-NLS-1$ ,
"0.0.0"); //$NON-NLS-1$
}

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

@Override
public String getProductVersion() {
return delegate.getProductVersion();
public String version() {
return delegate.version();
}

@Override
Expand Down
Loading

0 comments on commit 6fb3dd3

Please sign in to comment.