diff --git a/bundles/org.eclipse.passage.lbc.jetty/src/org/eclipse/passage/lbc/internal/jetty/FlsJettyActivator.java b/bundles/org.eclipse.passage.lbc.jetty/src/org/eclipse/passage/lbc/internal/jetty/FlsJettyActivator.java
index ca50a6ab3..b8092f16e 100644
--- a/bundles/org.eclipse.passage.lbc.jetty/src/org/eclipse/passage/lbc/internal/jetty/FlsJettyActivator.java
+++ b/bundles/org.eclipse.passage.lbc.jetty/src/org/eclipse/passage/lbc/internal/jetty/FlsJettyActivator.java
@@ -19,7 +19,7 @@
import org.eclipse.passage.lbc.internal.base.api.FloatingState;
import org.eclipse.passage.lic.internal.equinox.io.FileFromBundle;
import org.eclipse.passage.lic.internal.jetty.JettyHandler;
-import org.eclipse.passage.lic.internal.jetty.ui.LicensedJettyActivator;
+import org.eclipse.passage.lic.internal.jetty.interaction.LicensedJettyActivator;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
diff --git a/bundles/org.eclipse.passage.lic.jetty/.settings/.api_filters b/bundles/org.eclipse.passage.lic.jetty/.settings/.api_filters
deleted file mode 100644
index 8b54a69f8..000000000
--- a/bundles/org.eclipse.passage.lic.jetty/.settings/.api_filters
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
diff --git a/bundles/org.eclipse.passage.lic.jetty/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.lic.jetty/META-INF/MANIFEST.MF
index ddc960ead..f9ea2f954 100644
--- a/bundles/org.eclipse.passage.lic.jetty/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.passage.lic.jetty/META-INF/MANIFEST.MF
@@ -16,5 +16,5 @@ Require-Bundle: javax.servlet;bundle-version="0.0.0",
org.eclipse.passage.lic.net;bundle-version="1.0.100",
org.eclipse.passage.lic.equinox;bundle-version="1.0.201"
Export-Package: org.eclipse.passage.lic.internal.jetty;x-friends:="org.eclipse.passage.lbc.base,org.eclipse.passage.lbc.jetty,org.eclipse.passage.lac.jetty",
- org.eclipse.passage.lic.internal.jetty.ui
+ org.eclipse.passage.lic.internal.jetty.interaction;x-friends:="org.eclipse.passage.lbc.jetty"
Bundle-ActivationPolicy: lazy
diff --git a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/Command.java b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/Command.java
new file mode 100644
index 000000000..01b5762c4
--- /dev/null
+++ b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/Command.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.internal.jetty.interaction;
+
+public abstract class Command {
+
+ private final Scope scope;
+ private final String[] names;
+
+ public Command(Scope scope, String[] names) {
+ this.scope = scope;
+ this.names = names;
+ }
+
+ public final Scope scope() {
+ return scope;
+ }
+
+ public final String[] commands() {
+ return names;
+ }
+
+}
diff --git a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/Commands.java b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/Commands.java
new file mode 100644
index 000000000..6a74ac7f7
--- /dev/null
+++ b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/Commands.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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.internal.jetty.interaction;
+
+import java.util.Hashtable;
+
+import org.eclipse.passage.lic.internal.jetty.JettyServer;
+import org.osgi.framework.BundleContext;
+
+final class Commands {
+
+ private ServerHandles server;
+
+ void register(BundleContext context, JettyServer jetty) {
+ registerSelfStatus(context);
+ registerServerHandles(context, jetty);
+ }
+
+ ServerHandles server() {
+ return server;
+ }
+
+ private void registerSelfStatus(BundleContext context) {
+ register(context, new LicenseStatus());
+ }
+
+ private void registerServerHandles(BundleContext context, JettyServer jetty) {
+ this.server = new ServerHandles(jetty);
+ register(context, server);
+ }
+
+ private void register(BundleContext context, Command command) {
+ Hashtable props = new Hashtable<>();
+ props.put("osgi.command.scope", //$NON-NLS-1$
+ command.scope().id());
+ props.put("osgi.command.function", //$NON-NLS-1$
+ command.commands());
+ context.registerService(command.getClass().getName(), command, props);
+ }
+
+}
diff --git a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/ui/LicensedJettyActivator.java b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/LicenseProtection.java
similarity index 66%
rename from bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/ui/LicensedJettyActivator.java
rename to bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/LicenseProtection.java
index 15fefc1fc..ace195edb 100644
--- a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/ui/LicensedJettyActivator.java
+++ b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/LicenseProtection.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2020, 2021 ArSysOp
+ * 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
@@ -10,61 +10,28 @@
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
-package org.eclipse.passage.lic.internal.jetty.ui;
+package org.eclipse.passage.lic.internal.jetty.interaction;
-import java.nio.file.Path;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.LicensingException;
import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.lic.internal.api.access.GrantLockAttempt;
import org.eclipse.passage.lic.internal.api.restrictions.ExaminationCertificate;
import org.eclipse.passage.lic.internal.base.diagnostic.DiagnosticExplained;
-import org.eclipse.passage.lic.internal.base.logging.Logging;
import org.eclipse.passage.lic.internal.base.restrictions.CertificateWorthAttention;
import org.eclipse.passage.lic.internal.equinox.EquinoxPassage;
import org.eclipse.passage.lic.internal.equinox.LicensedApplication;
-import org.eclipse.passage.lic.internal.jetty.JettyHandler;
-import org.eclipse.passage.lic.internal.jetty.JettyServer;
-import org.eclipse.passage.lic.internal.net.connect.Port;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-public abstract class LicensedJettyActivator implements BundleActivator {
+final class LicenseProtection {
- private final Logger log;
- private final JettyServer jetty;
+ private final Logger log = LogManager.getLogger(getClass());
private Optional lock = Optional.empty();
- public LicensedJettyActivator() {
- configureLogging();
- this.log = LogManager.getLogger(getClass());
- this.jetty = new JettyServer(this::handler);
- }
-
- @Override
- public final void start(BundleContext context) throws Exception {
- registerCommands(context);
- if (checkLicense()) {
- jetty.launch(new Port(Platform.getApplicationArgs(), 8090));
- }
- }
-
- @Override
- public final void stop(BundleContext context) throws Exception {
- lock.ifPresent(acq -> new EquinoxPassage().releaseLicense(acq));
- jetty.terminate();
- }
-
- private void configureLogging() {
- new Logging(this::logConfig).configure();
- }
-
- private boolean checkLicense() {
+ boolean check() {
lock = acquireLicense();
if (!lock.isPresent()) {
return false;
@@ -81,6 +48,10 @@ private boolean checkLicense() {
return true;
}
+ void release() {
+ lock.ifPresent(acq -> new EquinoxPassage().releaseLicense(acq));
+ }
+
private Optional acquireLicense() {
return product().flatMap(this::acquireLicense);
}
@@ -110,12 +81,4 @@ private boolean successful(ServiceInvocationResult response) {
return response.data().map(GrantLockAttempt::successful).orElse(Boolean.FALSE);
}
- private void registerCommands(BundleContext context) {
- // new Commands().register(context, jetty);
- }
-
- protected abstract JettyHandler handler();
-
- protected abstract Path logConfig() throws Exception;
-
}
diff --git a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/LicenseStatus.java b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/LicenseStatus.java
new file mode 100644
index 000000000..463c60251
--- /dev/null
+++ b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/LicenseStatus.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * 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.internal.jetty.interaction;
+
+import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
+import org.eclipse.passage.lic.internal.api.diagnostic.Diagnostic;
+import org.eclipse.passage.lic.internal.api.restrictions.ExaminationCertificate;
+import org.eclipse.passage.lic.internal.base.diagnostic.DiagnosticExplained;
+import org.eclipse.passage.lic.internal.equinox.EquinoxPassageLicenseCoverage;
+
+final class LicenseStatus extends Command {
+
+ public LicenseStatus() {
+ super(new Scope.Self(), new String[] { "status" });//$NON-NLS-1$
+ }
+
+ public void status() {
+ ServiceInvocationResult response = new EquinoxPassageLicenseCoverage().assess();
+ if (response.data().isPresent()) {
+ reportCertificate(response.data().get());
+ }
+ reportDiagnostic(response.diagnostic());
+ }
+
+ private void reportCertificate(ExaminationCertificate certificate) {
+ System.out.printf("\n%s\n", new RequirementsLicensingStatusExplained(certificate).get()); //$NON-NLS-1$
+ }
+
+ private void reportDiagnostic(Diagnostic diagnostic) {
+ System.out.printf("\n%s\n", new DiagnosticExplained(diagnostic).get()); //$NON-NLS-1$
+ }
+
+}
diff --git a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/LicensedJettyActivator.java b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/LicensedJettyActivator.java
new file mode 100644
index 000000000..25d430c47
--- /dev/null
+++ b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/LicensedJettyActivator.java
@@ -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.internal.jetty.interaction;
+
+import java.nio.file.Path;
+
+import org.eclipse.passage.lic.internal.base.logging.Logging;
+import org.eclipse.passage.lic.internal.jetty.JettyHandler;
+import org.eclipse.passage.lic.internal.jetty.JettyServer;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public abstract class LicensedJettyActivator implements BundleActivator {
+
+ private final JettyServer jetty;
+ private ServerHandles server;
+
+ public LicensedJettyActivator() {
+ configureLogging();
+ this.jetty = new JettyServer(this::handler);
+ }
+
+ @Override
+ public final void start(BundleContext context) throws Exception {
+ registerCommands(context);
+ server.start();
+ }
+
+ @Override
+ public final void stop(BundleContext context) throws Exception {
+ server.stop();
+ }
+
+ private void configureLogging() {
+ new Logging(this::logConfig).configure();
+ }
+
+ private void registerCommands(BundleContext context) {
+ Commands commands = new Commands();
+ commands.register(context, jetty);
+ this.server = commands.server();
+ }
+
+ protected abstract JettyHandler handler();
+
+ protected abstract Path logConfig() throws Exception;
+
+}
diff --git a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/ui/RequirementsLicensingStatusExplained.java b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/RequirementsLicensingStatusExplained.java
similarity index 95%
rename from bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/ui/RequirementsLicensingStatusExplained.java
rename to bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/RequirementsLicensingStatusExplained.java
index 03d61aacf..ccfcbbaf1 100644
--- a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/ui/RequirementsLicensingStatusExplained.java
+++ b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/RequirementsLicensingStatusExplained.java
@@ -10,7 +10,7 @@
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
-package org.eclipse.passage.lic.internal.jetty.ui;
+package org.eclipse.passage.lic.internal.jetty.interaction;
import org.eclipse.passage.lic.internal.api.restrictions.ExaminationCertificate;
import org.eclipse.passage.lic.internal.base.diagnostic.LicensingStatus;
diff --git a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/Scope.java b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/Scope.java
new file mode 100644
index 000000000..fa2982cfe
--- /dev/null
+++ b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/Scope.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * 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.internal.jetty.interaction;
+
+import java.util.Objects;
+
+public abstract class Scope {
+
+ private final String id;
+
+ protected Scope(String id) {
+ Objects.requireNonNull(id, "Scope::id"); //$NON-NLS-1$
+ this.id = id;
+ }
+
+ public String id() {
+ return id;
+ }
+
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof Scope)) {
+ return false;
+ }
+ return ((Scope) obj).id.equals(id);
+ }
+
+ @Override
+ public String toString() {
+ return id;
+ }
+
+ public static final class Self extends Scope {
+
+ public Self() {
+ super("self"); //$NON-NLS-1$
+ }
+
+ }
+
+ public static final class Server extends Scope {
+
+ public Server() {
+ super("server"); //$NON-NLS-1$
+ }
+
+ }
+
+ public static final class Of extends Scope {
+
+ public Of(String id) {
+ super(id);
+ }
+
+ }
+
+}
diff --git a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/ServerHandles.java b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/ServerHandles.java
new file mode 100644
index 000000000..148c74d82
--- /dev/null
+++ b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/interaction/ServerHandles.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * 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.internal.jetty.interaction;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.eclipse.core.runtime.Platform;
+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;
+
+final class ServerHandles extends Command {
+
+ private final Logger log = LogManager.getLogger(getClass());
+ private final JettyServer server;
+ private final Port port;
+ private final LicenseProtection license = new LicenseProtection();
+
+ ServerHandles(JettyServer server) {
+ super(//
+ new Scope.Server(), //
+ new String[] { //
+ "start", //$NON-NLS-1$
+ "stop", //$NON-NLS-1$
+ "restart" //$NON-NLS-1$
+ });
+ this.server = server;
+ this.port = new Port(Platform.getApplicationArgs(), 8090);
+ }
+
+ public void start() {
+ if (!license.check()) {
+ return;
+ }
+ try {
+ server.launch(port);
+ } catch (JettyException e) {
+ log.error("failed to launch Jetty server", e); //$NON-NLS-1$
+ }
+ }
+
+ public void stop() {
+ license.release();
+ try {
+ server.terminate();
+ } catch (JettyException e) {
+ log.error("failed to terminate Jetty server", e); //$NON-NLS-1$
+ }
+ }
+
+ public void restart() {
+ stop();
+ start();
+ }
+
+}