Skip to content

Commit

Permalink
#1023 publish cli license protection facilities
Browse files Browse the repository at this point in the history
  • Loading branch information
eparovyshnaia committed Feb 6, 2022
1 parent 632c58c commit dcf1121
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ TYPE_PARAMETER_ELEMENT_TYPE_REMOVED_CLASS_BOUND=Error
TYPE_PARAMETER_ELEMENT_TYPE_REMOVED_INTERFACE_BOUND=Error
UNUSED_PROBLEM_FILTERS=Warning
automatically_removed_unused_problem_filters=false
changed_execution_env=Error
changed_execution_env=Warning
eclipse.preferences.version=1
incompatible_api_component_version=Error
incompatible_api_component_version=Warning
incompatible_api_component_version_include_major_without_breaking_change=Disabled
incompatible_api_component_version_include_minor_without_api_change=Disabled
incompatible_api_component_version_report_major_without_breaking_change=Error
incompatible_api_component_version_report_minor_without_api_change=Error
invalid_since_tag_version=Error
malformed_since_tag=Error
missing_since_tag=Error
incompatible_api_component_version_report_major_without_breaking_change=Warning
incompatible_api_component_version_report_minor_without_api_change=Warning
invalid_since_tag_version=Warning
malformed_since_tag=Warning
missing_since_tag=Warning
report_api_breakage_when_major_version_incremented=Disabled
report_resolution_errors_api_component=Warning
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lic.internal.jetty.interaction;
package org.eclipse.passage.lic.equinox.access;

import java.util.Optional;
import java.util.function.Supplier;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -23,21 +24,32 @@
import org.eclipse.passage.lic.base.diagnostic.DiagnosticExplained;
import org.eclipse.passage.lic.equinox.EquinoxPassage;
import org.eclipse.passage.lic.equinox.LicensedApplication;
import org.eclipse.passage.lic.equinox.access.ConsoleInteraction;
import org.eclipse.passage.lic.equinox.access.LicenseCoverageCheck;

final class LicenseProtection {
public final class LicenseProtection {

private final Logger log = LogManager.getLogger(getClass());
private Optional<GrantLockAttempt> lock = Optional.empty();
private final Supplier<Interaction> interaction;

boolean check() {
public LicenseProtection() {
this(ConsoleInteraction::new);
}

public LicenseProtection(Supplier<Interaction> interaction) {
this.interaction = interaction;
}

public boolean check() {
if (licenseCoverageIsNotSufficient()) {
return false;
}
return locAcquired();
}

public void release() {
lock.ifPresent(acq -> new EquinoxPassage().releaseLicense(acq));
}

private boolean locAcquired() {
Optional<GrantLockAttempt> attempt = acquireLicense();
if (!attempt.isPresent()) {
Expand All @@ -51,11 +63,7 @@ private boolean locAcquired() {
}

private boolean licenseCoverageIsNotSufficient() {
return !LicenseCoverageCheck.Result.proceed.equals(new LicenseCoverageCheck(new ConsoleInteraction()).run());
}

void release() {
lock.ifPresent(acq -> new EquinoxPassage().releaseLicense(acq));
return !LicenseCoverageCheck.Result.proceed.equals(new LicenseCoverageCheck(interaction.get()).run());
}

private Optional<GrantLockAttempt> acquireLicense() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.passage.lic.equinox.access.LicenseProtection;
import org.eclipse.passage.lic.internal.jetty.JettyException;
import org.eclipse.passage.lic.internal.jetty.JettyServer;
import org.eclipse.passage.lic.internal.net.connect.Port;
Expand Down

0 comments on commit dcf1121

Please sign in to comment.