From d9355f8bad975b739fe66164d3776b43274876c1 Mon Sep 17 00:00:00 2001 From: Thorsten Marx Date: Thu, 26 Sep 2024 10:43:10 +0200 Subject: [PATCH 1/2] add command to install all required modules --- .../cms/cli/commands/ModuleCommands.java | 6 +- .../cli/commands/modules/GetAllCommand.java | 90 +++++++++++++++++++ distribution/build.xml | 4 +- 3 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 cms-server/src/main/java/com/condation/cms/cli/commands/modules/GetAllCommand.java diff --git a/cms-server/src/main/java/com/condation/cms/cli/commands/ModuleCommands.java b/cms-server/src/main/java/com/condation/cms/cli/commands/ModuleCommands.java index 55322202d..8a232d208 100644 --- a/cms-server/src/main/java/com/condation/cms/cli/commands/ModuleCommands.java +++ b/cms-server/src/main/java/com/condation/cms/cli/commands/ModuleCommands.java @@ -23,6 +23,7 @@ */ +import com.condation.cms.cli.commands.modules.GetAllCommand; import com.condation.cms.cli.commands.modules.GetCommand; import com.condation.cms.cli.commands.modules.InfoCommand; import com.condation.cms.cli.commands.modules.RemoveCommand; @@ -38,13 +39,14 @@ subcommands = { InfoCommand.class, GetCommand.class, - RemoveCommand.class + RemoveCommand.class, + GetAllCommand.class }) @Slf4j public class ModuleCommands implements Runnable { @Override public void run() { - System.out.println("Subcommand needed: 'get', 'remove' or 'info'"); + System.out.println("Subcommand needed: 'get', 'get-all', 'remove' or 'info'"); } } diff --git a/cms-server/src/main/java/com/condation/cms/cli/commands/modules/GetAllCommand.java b/cms-server/src/main/java/com/condation/cms/cli/commands/modules/GetAllCommand.java new file mode 100644 index 000000000..5d0ea4046 --- /dev/null +++ b/cms-server/src/main/java/com/condation/cms/cli/commands/modules/GetAllCommand.java @@ -0,0 +1,90 @@ +package com.condation.cms.cli.commands.modules; + +/*- + * #%L + * cms-server + * %% + * Copyright (C) 2023 - 2024 CondationCMS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * #L% + */ +import com.condation.cms.CMSServer; +import com.condation.cms.cli.tools.ModulesUtil; +import com.condation.cms.extensions.repository.InstallationHelper; +import java.nio.file.Path; +import lombok.extern.slf4j.Slf4j; +import picocli.CommandLine; + +/** + * + * @author t.marx + */ +@Slf4j +@CommandLine.Command(name = "get-all") +public class GetAllCommand extends AbstractModuleCommand implements Runnable { + + @CommandLine.Option(names = "-f", description = "force the update if module is already installed") + boolean forceUpdate; + + @Override + public void run() { + + if (CMSServer.isRunning()) { + System.out.println("modules can not be modified in running system"); + return; + } + + var modules = ModulesUtil.getRequiredModules(); + log.trace("check required modules: " + modules); + if (!ModulesUtil.allInstalled(modules)) { + var toInstall = ModulesUtil.filterUnInstalled(modules); + System.out.println("following modules are missing and will be installed: " + String.join(", ", toInstall)); + toInstall.forEach(this::installModule); + } else { + System.out.println("all required modules are intalled"); + } + } + + private boolean installModule(String module) { + if (isInstalled(module) && !forceUpdate) { + System.err.println("module '%s' is already installed, use -f to force an update".formatted(module)); + return false; + } + + if (isInstalled(module)) { + InstallationHelper.deleteDirectory(getModuleFolder(module).toFile()); + } + + if (getRepository().exists(module)) { + + if (!isCompatibleWithServer(module)) { + System.err.println("module '%s' is not compatible with server version".formatted(module)); + return false; + } + + var info = getRepository().getInfo(module).get(); + + System.out.printf("get module %s \r\n", module); + getRepository().download(info.getFile(), Path.of("modules/")); + System.out.println("module downloaded"); + return true; + } else { + System.out.printf("can not find module %s in registry", module); + return false; + } + } + +} diff --git a/distribution/build.xml b/distribution/build.xml index bc0b333fe..8259c2227 100644 --- a/distribution/build.xml +++ b/distribution/build.xml @@ -1,8 +1,8 @@ - 6.1.1 + 6.2.0 - v2.0.0 + v2.1.0 download template implementation modules From c0c4b6a96ff714ccf753f8f720db8831b4c0baca Mon Sep 17 00:00:00 2001 From: Thorsten Marx Date: Thu, 26 Sep 2024 10:46:33 +0200 Subject: [PATCH 2/2] extend get-all to update modules --- .../condation/cms/cli/commands/modules/GetAllCommand.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cms-server/src/main/java/com/condation/cms/cli/commands/modules/GetAllCommand.java b/cms-server/src/main/java/com/condation/cms/cli/commands/modules/GetAllCommand.java index 5d0ea4046..cace9d231 100644 --- a/cms-server/src/main/java/com/condation/cms/cli/commands/modules/GetAllCommand.java +++ b/cms-server/src/main/java/com/condation/cms/cli/commands/modules/GetAllCommand.java @@ -49,10 +49,13 @@ public void run() { var modules = ModulesUtil.getRequiredModules(); log.trace("check required modules: " + modules); - if (!ModulesUtil.allInstalled(modules)) { + if (!ModulesUtil.allInstalled(modules) && !forceUpdate) { var toInstall = ModulesUtil.filterUnInstalled(modules); System.out.println("following modules are missing and will be installed: " + String.join(", ", toInstall)); toInstall.forEach(this::installModule); + } else if (forceUpdate) { + System.out.println("following modules wil be installed or updated: " + String.join(", ", modules)); + modules.forEach(this::installModule); } else { System.out.println("all required modules are intalled"); }