From 2f2e3a612762bf03df8a6f93c25ec864c19b866e Mon Sep 17 00:00:00 2001 From: Elena Parovyshnaia Date: Sun, 28 Mar 2021 08:45:06 +0300 Subject: [PATCH 1/3] Bug 566482 implement license grants uploading interface promote ExternalLicense installation util for reuse Signed-off-by: eparovyshnaya --- .../internal/base/io}/ExternalLicense.java | 21 +++++++++++-------- .../licensing/ImportLicenseDialog.java | 1 + 2 files changed, 13 insertions(+), 9 deletions(-) rename bundles/{org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing => org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/io}/ExternalLicense.java (65%) diff --git a/bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/ExternalLicense.java b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/io/ExternalLicense.java similarity index 65% rename from bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/ExternalLicense.java rename to bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/io/ExternalLicense.java index efd041f01..46b928dc9 100644 --- a/bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/ExternalLicense.java +++ b/bundles/org.eclipse.passage.lic.base/src/org/eclipse/passage/lic/internal/base/io/ExternalLicense.java @@ -10,30 +10,33 @@ * Contributors: * ArSysOp - initial API and implementation *******************************************************************************/ -package org.eclipse.passage.lic.internal.jface.dialogs.licensing; +package org.eclipse.passage.lic.internal.base.io; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import org.eclipse.passage.lic.internal.api.LicensedProduct; -import org.eclipse.passage.lic.internal.base.io.LicensingFolder; -import org.eclipse.passage.lic.internal.base.io.PathFromLicensedProduct; -import org.eclipse.passage.lic.internal.base.io.UserHomePath; -final class ExternalLicense { +public final class ExternalLicense { private final LicensedProduct product; - ExternalLicense(LicensedProduct product) { + public ExternalLicense(LicensedProduct product) { this.product = product; } - void install(Path license) throws IOException { + public void install(Path... pack) throws IOException { + for (Path file : pack) { + installLicenseFile(file); + } + } + + private void installLicenseFile(Path file) throws IOException { Path target = new PathFromLicensedProduct(new LicensingFolder(new UserHomePath()), product).get() - .resolve(license.getFileName()); + .resolve(file.getFileName()); target.toFile().getParentFile().mkdirs(); - Files.copy(license, target); + Files.copy(file, target); } } diff --git a/bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/ImportLicenseDialog.java b/bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/ImportLicenseDialog.java index ca2ddbccb..44b527c6e 100644 --- a/bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/ImportLicenseDialog.java +++ b/bundles/org.eclipse.passage.lic.jface/src/org/eclipse/passage/lic/internal/jface/dialogs/licensing/ImportLicenseDialog.java @@ -29,6 +29,7 @@ import org.eclipse.passage.lic.internal.api.conditions.mining.LicenseReadingService; import org.eclipse.passage.lic.internal.api.diagnostic.Diagnostic; import org.eclipse.passage.lic.internal.base.conditions.BaseValidityPeriodClosed; +import org.eclipse.passage.lic.internal.base.io.ExternalLicense; import org.eclipse.passage.lic.internal.equinox.EquinoxPassage; import org.eclipse.passage.lic.internal.equinox.LicenseReadingServiceRequest; import org.eclipse.passage.lic.internal.jface.i18n.ImportLicenseDialogMessages; From 7880b832a3ca97e82e2a9c9e507add96e3fc4840 Mon Sep 17 00:00:00 2001 From: Elena Parovyshnaia Date: Sun, 28 Mar 2021 08:48:00 +0300 Subject: [PATCH 2/3] Bug 566482 implement license grants uploading interface Add 'state' Server handle Signed-off-by: eparovyshnaya --- .../lic/internal/jetty/JettyServer.java | 8 +++++++ .../lic/internal/jetty/i18n/Messages.java | 1 + .../internal/jetty/i18n/Messages.properties | 1 + .../internal/jetty/interaction/Command.java | 17 ++++++++------ .../internal/jetty/interaction/Commands.java | 23 +++++-------------- .../interaction/LicensedJettyActivator.java | 9 ++++++-- .../jetty/interaction/ServerHandles.java | 15 +++++++++--- 7 files changed, 45 insertions(+), 29 deletions(-) diff --git a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/JettyServer.java b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/JettyServer.java index 217085837..7765e94cd 100644 --- a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/JettyServer.java +++ b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/JettyServer.java @@ -52,6 +52,14 @@ public void terminate() throws JettyException { } } + public String state() throws JettyException { + try { + return server.getState(); + } catch (Exception e) { + throw new JettyException(Messages.error_onstate, e); + } + } + private void logAndRethrow(Exception e, String template) throws JettyException { String message = String.format(template, e.getClass(), e.getMessage()); log.error(message, e); diff --git a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/i18n/Messages.java b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/i18n/Messages.java index e4d2c8249..86e45c132 100644 --- a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/i18n/Messages.java +++ b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/i18n/Messages.java @@ -30,6 +30,7 @@ public final class Messages { public static final String not_running = getString("server_not_running"); //$NON-NLS-1$ public static final String error_onstart = getString("error_onstart"); //$NON-NLS-1$ public static final String error_onstop = getString("error_onstop"); //$NON-NLS-1$ + public static final String error_onstate = getString("error_onstate"); //$NON-NLS-1$ private Messages() { } diff --git a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/i18n/Messages.properties b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/i18n/Messages.properties index bd9ae06b6..4cf3ae0f8 100644 --- a/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/i18n/Messages.properties +++ b/bundles/org.eclipse.passage.lic.jetty/src/org/eclipse/passage/lic/internal/jetty/i18n/Messages.properties @@ -17,3 +17,4 @@ server_already_running=Server is already running \n server_not_running=No running server found \n error_onstart=Server couldn't be started due to %s: %s \n error_onstop=Server couldn't be stopped due to %s: %s \n +error_onstate=Server failed to report its state \ No newline at end of file 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 index 01b5762c4..2fe4ea30f 100644 --- 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 @@ -12,9 +12,13 @@ *******************************************************************************/ package org.eclipse.passage.lic.internal.jetty.interaction; +import java.util.Hashtable; + +import org.osgi.framework.BundleContext; + public abstract class Command { - private final Scope scope; + protected final Scope scope; private final String[] names; public Command(Scope scope, String[] names) { @@ -22,12 +26,11 @@ public Command(Scope scope, String[] names) { this.names = names; } - public final Scope scope() { - return scope; - } - - public final String[] commands() { - return names; + public final void register(BundleContext context) { + Hashtable properties = new Hashtable<>(); + properties.put("osgi.command.scope", scope.id());//$NON-NLS-1$ + properties.put("osgi.command.function", names);//$NON-NLS-1$ + context.registerService(getClass().getName(), this, properties); } } 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 index 6a74ac7f7..0d9f3ddba 100644 --- 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 @@ -12,8 +12,6 @@ *******************************************************************************/ 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; @@ -21,9 +19,9 @@ final class Commands { private ServerHandles server; - void register(BundleContext context, JettyServer jetty) { + void register(BundleContext context, JettyServer jetty, String name) { registerSelfStatus(context); - registerServerHandles(context, jetty); + registerServerHandles(context, jetty, name); } ServerHandles server() { @@ -31,21 +29,12 @@ ServerHandles 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); + new LicenseStatus().register(context); } - 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); + private void registerServerHandles(BundleContext context, JettyServer jetty, String name) { + this.server = new ServerHandles(jetty, name); + this.server.register(context); } } 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 index 25d430c47..8ef5ad60a 100644 --- 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 @@ -33,7 +33,7 @@ public LicensedJettyActivator() { @Override public final void start(BundleContext context) throws Exception { registerCommands(context); - server.start(); + server.start(); // temporal coupling here: server is initialized during commands registration } @Override @@ -47,12 +47,17 @@ private void configureLogging() { private void registerCommands(BundleContext context) { Commands commands = new Commands(); - commands.register(context, jetty); + commands.register(context, jetty, name()); this.server = commands.server(); + // registerCustomCommands(context); } + protected abstract String name(); + protected abstract JettyHandler handler(); protected abstract Path logConfig() throws Exception; + // protected abstract void registerCustomCommands(BundleContext context); + } 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 index 148c74d82..a96a4fb52 100644 --- 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 @@ -26,13 +26,14 @@ final class ServerHandles extends Command { private final Port port; private final LicenseProtection license = new LicenseProtection(); - ServerHandles(JettyServer server) { + ServerHandles(JettyServer server, String name) { super(// - new Scope.Server(), // + new Scope.Of(name), // new String[] { // "start", //$NON-NLS-1$ "stop", //$NON-NLS-1$ - "restart" //$NON-NLS-1$ + "restart", //$NON-NLS-1$ + "state" //$NON-NLS-1$ }); this.server = server; this.port = new Port(Platform.getApplicationArgs(), 8090); @@ -63,4 +64,12 @@ public void restart() { start(); } + public void state() { + try { + System.out.println(server.state()); + } catch (JettyException e) { + log.error("failed to report state of Jetty server", e); //$NON-NLS-1$ + } + } + } From 233817b80531fee3528c8ecd312ee5bacd33ed2a Mon Sep 17 00:00:00 2001 From: Elena Parovyshnaia Date: Sun, 28 Mar 2021 08:50:39 +0300 Subject: [PATCH 3/3] Bug 566482 implement license grants uploading interface - make server's command set replenishable - make server's handles to reside in domain specific scope - design 'upload license' command interface Signed-off-by: eparovyshnaya --- .../lbc/internal/jetty/FlsCommands.java | 23 +++++++++ .../lbc/internal/jetty/FlsJettyActivator.java | 11 +++++ .../lbc/internal/jetty/UploadLicense.java | 49 +++++++++++++++++++ .../interaction/LicensedJettyActivator.java | 4 +- 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 bundles/org.eclipse.passage.lbc.jetty/src/org/eclipse/passage/lbc/internal/jetty/FlsCommands.java create mode 100644 bundles/org.eclipse.passage.lbc.jetty/src/org/eclipse/passage/lbc/internal/jetty/UploadLicense.java diff --git a/bundles/org.eclipse.passage.lbc.jetty/src/org/eclipse/passage/lbc/internal/jetty/FlsCommands.java b/bundles/org.eclipse.passage.lbc.jetty/src/org/eclipse/passage/lbc/internal/jetty/FlsCommands.java new file mode 100644 index 000000000..490d15bc2 --- /dev/null +++ b/bundles/org.eclipse.passage.lbc.jetty/src/org/eclipse/passage/lbc/internal/jetty/FlsCommands.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * 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.lbc.internal.jetty; + +import org.osgi.framework.BundleContext; + +final class FlsCommands { + + void register(BundleContext context, String name) { + new UploadLicense(name).register(context); + } + +} 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 b8092f16e..16aa57cb5 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 @@ -21,6 +21,7 @@ import org.eclipse.passage.lic.internal.jetty.JettyHandler; import org.eclipse.passage.lic.internal.jetty.interaction.LicensedJettyActivator; import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; public final class FlsJettyActivator extends LicensedJettyActivator { @@ -31,6 +32,11 @@ public FlsJettyActivator() { this.state = new EagerFloatingState(); } + @Override + protected String name() { + return "fls"; //$NON-NLS-1$ + } + @Override protected JettyHandler handler() { return new JettyHandler(request -> new FlotingRequestHandled(new StatedRequest(request, state)).get()); @@ -42,4 +48,9 @@ protected Path logConfig() throws Exception { return new FileFromBundle(bundle, "config/log4j2.xml").get(); //$NON-NLS-1$ } + @Override + protected void registerCustomCommands(BundleContext context) { + new FlsCommands().register(context, name()); + } + } diff --git a/bundles/org.eclipse.passage.lbc.jetty/src/org/eclipse/passage/lbc/internal/jetty/UploadLicense.java b/bundles/org.eclipse.passage.lbc.jetty/src/org/eclipse/passage/lbc/internal/jetty/UploadLicense.java new file mode 100644 index 000000000..69e9e0aeb --- /dev/null +++ b/bundles/org.eclipse.passage.lbc.jetty/src/org/eclipse/passage/lbc/internal/jetty/UploadLicense.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * 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.lbc.internal.jetty; + +import org.eclipse.passage.lic.internal.jetty.interaction.Command; +import org.eclipse.passage.lic.internal.jetty.interaction.Scope; + +final class UploadLicense extends Command { + + public UploadLicense(String scope) { + super(new Scope.Of(scope), new String[] { "upload" }); //$NON-NLS-1$ + } + + public void upload(String from) { + // new IncomingLicense(from).upload(); + } + + public void upload(String from, String product, String version) { + // new IncomingLicense(from).uploadForProduct(product, version); + } + + public void upload(String... args) { + if (args.length == 1) { + upload(args[0]); + } else if (args.length == 3) { + upload(args[0], args[1], args[2]); + } else { + System.out.println(help()); + } + } + + private String help() { + return "[fls:upload] places the given floating license pack at the Server's disposal.\n" + //$NON-NLS-1$ + "Usage:\n\t" + //$NON-NLS-1$ + scope.id() + ":upload \n\t" + //$NON-NLS-1$ + scope.id() + ":upload \n"; //$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 index 8ef5ad60a..b2fe73676 100644 --- 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 @@ -49,7 +49,7 @@ private void registerCommands(BundleContext context) { Commands commands = new Commands(); commands.register(context, jetty, name()); this.server = commands.server(); - // registerCustomCommands(context); + registerCustomCommands(context); } protected abstract String name(); @@ -58,6 +58,6 @@ private void registerCommands(BundleContext context) { protected abstract Path logConfig() throws Exception; - // protected abstract void registerCustomCommands(BundleContext context); + protected abstract void registerCustomCommands(BundleContext context); }