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 574848 Extract plain Passage implementation out of PassageEquinox #839

Merged
merged 5 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -19,7 +19,6 @@
import org.eclipse.passage.lic.internal.net.api.handle.NetRequest;
import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest;

@SuppressWarnings("restriction")
final class RuntimeFramework implements Framework {

private final ProductUserRequest<? extends NetRequest> request;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp
* Copyright (c) 2020, 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
Expand All @@ -18,7 +18,6 @@
import org.eclipse.passage.lic.api.FrameworkSupplier;
import org.osgi.service.component.annotations.Component;

@SuppressWarnings("restriction")
@Component
public final class FlsFrameworkSupplier implements FrameworkSupplier {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.eclipse.passage.lic.base.requirements.BaseFeature;
import org.eclipse.passage.lic.base.requirements.BaseRequirement;

@SuppressWarnings("restriction")
public final class DefaultProductRequirement implements Supplier<Requirement> {

private final Supplier<String> product;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.eclipse.pde.core.plugin.IPluginExtension;
import org.eclipse.pde.core.plugin.IPluginReference;

@SuppressWarnings("restriction")
public class LicensedE3ProductTemplateSection extends BaseLicensedProductSection {

private static final String LICENSED_E3_PRODUCT = "LicensedE3Product"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.eclipse.pde.core.plugin.IPluginExtension;
import org.eclipse.pde.core.plugin.IPluginReference;

@SuppressWarnings("restriction")
@Deprecated
public class LicensedE4ProductTemplateSection extends BaseLicensedProductSection {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.eclipse.passage.lic.base.requirements.BaseFeature;
import org.eclipse.passage.lic.base.requirements.BaseRequirement;

@SuppressWarnings("restriction")
public final class AntimagicShieldFeatureLicRequirement implements Supplier<Requirement> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.eclipse.pde.core.plugin.IPluginExtension;
import org.eclipse.pde.core.plugin.IPluginReference;

@SuppressWarnings("restriction")
public final class LicensedE4FullFeatherProductTemplateSection extends BaseLicensedProductSection {

public LicensedE4FullFeatherProductTemplateSection() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*******************************************************************************
* Copyright (c) 2020, 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.base;

import org.eclipse.passage.lic.api.LicensedProduct;
import org.eclipse.passage.lic.api.Passage;
import org.eclipse.passage.lic.api.ServiceInvocationResult;
import org.eclipse.passage.lic.api.access.GrantLockAttempt;
import org.eclipse.passage.lic.api.restrictions.ExaminationCertificate;
import org.eclipse.passage.lic.base.access.Access;

/**
* @since 1.1
*/
public final class BasePassage implements Passage {

private final FrameworkAware delegate;

public BasePassage(FrameworkAware delegate) {
this.delegate = delegate;
}

@Override
public boolean canUse(String feature) {
return delegate.withFramework(framework -> new Access(framework).canUse(feature)).orElse(Boolean.FALSE);
}

@Override
public ServiceInvocationResult<ExaminationCertificate> assess() {
return delegate.withFrameworkService(framework -> new Access(framework).assess());
}

@Override
public ServiceInvocationResult<GrantLockAttempt> acquireLicense(String feature) {
return delegate.withFrameworkService(framework -> new Access(framework).acquire(feature));
}

@Override
public ServiceInvocationResult<Boolean> releaseLicense(GrantLockAttempt lock) {
return delegate.withFrameworkService(framework -> new Access(framework).release(lock));
}

@Override
public ServiceInvocationResult<LicensedProduct> product() {
return delegate.withFrameworkService(framework -> new BaseServiceInvocationResult<>(framework.product()));
}

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

import java.util.Optional;
import java.util.function.Function;

import org.eclipse.passage.lic.api.Framework;
import org.eclipse.passage.lic.api.ServiceInvocationResult;

/**
* @since 1.1
*/
public interface FrameworkAware {

<T> ServiceInvocationResult<T> withFrameworkService(Function<Framework, ServiceInvocationResult<T>> invoke);

<T> Optional<T> withFramework(Function<Framework, T> invoke);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.passage.lic.e4.core
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.passage.lic.e4.core
Bundle-Version: 1.0.100.qualifier
Bundle-Version: 1.0.200.qualifier
Bundle-Vendor: %Bundle-Vendor
Bundle-Copyright: %Bundle-Copyright
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Properties file for org.eclipse.passage.lic.e4.core
###############################################################################
# Copyright (c) 2019, 2020 ArSysOp and others
# Copyright (c) 2019, 2021 ArSysOp and others
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -14,7 +14,7 @@

Bundle-Name = Passage LIC E4 Core
Bundle-Vendor = Eclipse Passage
Bundle-Copyright = Copyright (c) 2019, 2020 ArSysOp and others.\n\
Bundle-Copyright = Copyright (c) 2019, 2021 ArSysOp and others.\n\
\n\
This program and the accompanying materials are made\n\
available under the terms of the Eclipse Public License 2.0\n\
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp
* Copyright (c) 2020, 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
Expand All @@ -24,7 +24,6 @@
* Execute the command with the given id and parameters using the given context
*
*/
@SuppressWarnings("restriction")
public class ExecuteCommand implements Function<Map<String, Object>, Object> {

private String id;
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.eclipse.passage.lic.e4.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.passage.lic.e4.ui
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.passage.lic.e4.ui
Bundle-Version: 1.0.100.qualifier
Bundle-Version: 1.0.200.qualifier
Bundle-Vendor: %Bundle-Vendor
Bundle-Copyright: %Bundle-Copyright
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
/**
* @since 2.0
*/
@SuppressWarnings("restriction")
public final class ResourceLoadFailed extends TroubleCode {

public ResourceLoadFailed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
/**
* @since 2.0
*/
@SuppressWarnings("restriction")
public final class ResourceSaveFailed extends TroubleCode {

public ResourceSaveFailed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
*/
public final class Environments implements Supplier<Collection<RuntimeEnvironment>> {

private final FrameworkAware<?> delegate;
private final EquinoxFrameworkAware<?> delegate;

public Environments() {
this(new SuppliedFrameworkAware());
}

public Environments(FrameworkAware<?> delegate) {
public Environments(EquinoxFrameworkAware<?> delegate) {
this.delegate = delegate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.passage.lic.api.ServiceInvocationResult;
import org.eclipse.passage.lic.api.diagnostic.Trouble;
import org.eclipse.passage.lic.base.BaseServiceInvocationResult;
import org.eclipse.passage.lic.base.FrameworkAware;
import org.eclipse.passage.lic.base.diagnostic.BaseDiagnostic;
import org.eclipse.passage.lic.base.diagnostic.code.NoFramework;
import org.eclipse.passage.lic.base.diagnostic.code.SeveralFrameworks;
Expand All @@ -42,19 +43,20 @@
*
* @since 2.1
*/
public abstract class FrameworkAware<S> {
public abstract class EquinoxFrameworkAware<S> implements FrameworkAware {

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

protected FrameworkAware(Class<S> cls, Function<S, Optional<Framework>> constructor) {
protected EquinoxFrameworkAware(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.context = FrameworkUtil.getBundle(EquinoxFrameworkAware.class).getBundleContext();
this.component = cls;
this.constructor = constructor;
}

@Override
public final <T> ServiceInvocationResult<T> withFrameworkService(
Function<Framework, ServiceInvocationResult<T>> invoke) {
return withReference(//
Expand All @@ -67,6 +69,7 @@ public final <T> ServiceInvocationResult<T> withFrameworkService(
this::severalFrameworks);
}

@Override
public final <T> Optional<T> withFramework(Function<Framework, T> invoke) {
return withReference(//
reference -> //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,47 @@
import org.eclipse.passage.lic.api.ServiceInvocationResult;
import org.eclipse.passage.lic.api.access.GrantLockAttempt;
import org.eclipse.passage.lic.api.restrictions.ExaminationCertificate;
import org.eclipse.passage.lic.base.BaseServiceInvocationResult;
import org.eclipse.passage.lic.base.access.Access;
import org.eclipse.passage.lic.base.BasePassage;
import org.eclipse.passage.lic.base.FrameworkAware;

/**
* @since 2.1
*/
public final class EquinoxPassage implements Passage {

private final FrameworkAware<?> delegate;
private final BasePassage delegate;

public EquinoxPassage() {
this(new SuppliedFrameworkAware());
}

public EquinoxPassage(FrameworkAware<?> delegate) {
this.delegate = delegate;
public EquinoxPassage(FrameworkAware delegate) {
this.delegate = new BasePassage(delegate);
}

@Override
public boolean canUse(String feature) {
return delegate.withFramework(framework -> new Access(framework).canUse(feature)).orElse(Boolean.FALSE);
return delegate.canUse(feature);
}

@Override
public ServiceInvocationResult<ExaminationCertificate> assess() {
return delegate.withFrameworkService(framework -> new Access(framework).assess());
return delegate.assess();
}

@Override
public ServiceInvocationResult<GrantLockAttempt> acquireLicense(String feature) {
return delegate.withFrameworkService(framework -> new Access(framework).acquire(feature));
return delegate.acquireLicense(feature);
}

@Override
public ServiceInvocationResult<Boolean> releaseLicense(GrantLockAttempt lock) {
return delegate.withFrameworkService(framework -> new Access(framework).release(lock));
return delegate.releaseLicense(lock);
}

@Override
public ServiceInvocationResult<LicensedProduct> product() {
return delegate.withFrameworkService(framework -> new BaseServiceInvocationResult<>(framework.product()));
return delegate.product();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
*/
public final class EquinoxPassageLicenseCoverage implements PassageLicenseCoverage {

private final FrameworkAware<?> delegate;
private final EquinoxFrameworkAware<?> delegate;

public EquinoxPassageLicenseCoverage() {
this(new SuppliedFrameworkAware());
}

public EquinoxPassageLicenseCoverage(FrameworkAware<?> delegate) {
public EquinoxPassageLicenseCoverage(EquinoxFrameworkAware<?> delegate) {
this.delegate = delegate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
*/
public final class LicenseReadingServiceRequest implements Supplier<ServiceInvocationResult<LicenseReadingService>> {

private final FrameworkAware<?> delegate;
private final EquinoxFrameworkAware<?> delegate;

public LicenseReadingServiceRequest() {
this(new SuppliedFrameworkAware());
}

public LicenseReadingServiceRequest(FrameworkAware<?> delegate) {
public LicenseReadingServiceRequest(EquinoxFrameworkAware<?> delegate) {
this.delegate = delegate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @since 2.1
*/
public final class SuppliedFrameworkAware extends FrameworkAware<FrameworkSupplier> {
public final class SuppliedFrameworkAware extends EquinoxFrameworkAware<FrameworkSupplier> {

public SuppliedFrameworkAware() {
super(FrameworkSupplier.class, FrameworkSupplier::get);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.eclipse.passage.lic.licenses.model.api.SignatureAttribute;
import org.eclipse.passage.lic.licenses.model.meta.LicensesFactory;

@SuppressWarnings("restriction")
public final class EIssuerSignature implements Supplier<Signature> {

private final IssuerSignature signature;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.eclipse.passage.lic.licenses.model.api.Signature;
import org.eclipse.passage.lic.licenses.model.api.SignatureAttribute;

@SuppressWarnings("restriction")
public final class PIssuerSignature implements Supplier<IssuerSignature> {

private final Signature signature;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.eclipse.passage.lic.base.conditions.MatchingRuleForIdentifier;
import org.eclipse.passage.lic.licenses.VersionMatchDescriptor;

@SuppressWarnings("restriction")
public final class PVersionMatch implements Supplier<VersionMatch> {

private final VersionMatchDescriptor descriptor;
Expand Down
Loading