diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/CommandletManagerImpl.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/CommandletManagerImpl.java index d79afdf33..0120d8778 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/CommandletManagerImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/CommandletManagerImpl.java @@ -1,10 +1,6 @@ package com.devonfw.tools.ide.commandlet; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import com.devonfw.tools.ide.context.IdeContext; import com.devonfw.tools.ide.property.KeywordProperty; @@ -27,6 +23,7 @@ import com.devonfw.tools.ide.tool.quarkus.Quarkus; import com.devonfw.tools.ide.tool.sonar.Sonar; import com.devonfw.tools.ide.tool.terraform.Terraform; +import com.devonfw.tools.ide.tool.tomcat.Tomcat; import com.devonfw.tools.ide.tool.vscode.Vscode; /** @@ -79,6 +76,7 @@ public CommandletManagerImpl(IdeContext context) { add(new Quarkus(context)); add(new Kotlinc(context)); add(new KotlincNative(context)); + add(new Tomcat(context)); add(new Vscode(context)); add(new Azure(context)); add(new Aws(context)); diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/tomcat/Tomcat.java b/cli/src/main/java/com/devonfw/tools/ide/tool/tomcat/Tomcat.java new file mode 100644 index 000000000..b5d56e27a --- /dev/null +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/tomcat/Tomcat.java @@ -0,0 +1,114 @@ +package com.devonfw.tools.ide.tool.tomcat; + +import java.nio.file.Path; +import java.util.Set; + +import com.devonfw.tools.ide.common.Tag; +import com.devonfw.tools.ide.context.IdeContext; +import com.devonfw.tools.ide.environment.EnvironmentVariables; +import com.devonfw.tools.ide.environment.EnvironmentVariablesType; +import com.devonfw.tools.ide.property.EnumProperty; +import com.devonfw.tools.ide.tool.LocalToolCommandlet; + +public class Tomcat extends LocalToolCommandlet { + + public final EnumProperty command; + + /** + * The constructor. + * + * @param context the {@link IdeContext}. + */ + public Tomcat(IdeContext context) { + + super(context, "tomcat", Set.of(Tag.JAVA)); + this.command = add(new EnumProperty<>("", true, "command", TomcatCommand.class)); + add(this.arguments); + } + + @Override + public boolean install(boolean silent) { + + return super.install(silent); + } + + @Override + public void postInstall() { + + super.postInstall(); + + EnvironmentVariables variables = this.context.getVariables(); + EnvironmentVariables typeVariables = variables.getByType(EnvironmentVariablesType.CONF); + + typeVariables.set("CATALINA_HOME", getToolPath().toString(), true); + typeVariables.save(); + } + + @Override + protected void initProperties() { + + // Empty on purpose + } + + @Override + public void run() { + + TomcatCommand command = this.command.getValue(); + + switch (command) { + case START: + // printTomcatPort(); + arguments.setValueAsString("start", context); + super.run(); + break; + case STOP: + arguments.setValueAsString("stop", context); + this.context.warning("TEST 2"); + break; + default: + } + } + + @Override + protected String getBinaryName() { + + TomcatCommand command = this.command.getValue(); + + Path toolBinPath = getToolBinPath(); + + String tomcatHome = null; + + if (this.context.getSystemInfo().isWindows()) { + if (command.equals(TomcatCommand.START)) { + tomcatHome = "startup.bat"; + } else if (command.equals(TomcatCommand.STOP)) { + tomcatHome = "shutdown.bat"; + } else { + this.context.error("Unknown tomcat command"); + } + } else { + if (command.equals(TomcatCommand.START)) { + tomcatHome = "startup.sh"; + } else if (command.equals(TomcatCommand.STOP)) { + tomcatHome = "shutdown.sh"; + } else { + this.context.error("Unknown tomcat command"); + } + } + + return toolBinPath.resolve(tomcatHome).toString(); + } + + // private void printTomcatPort() { + // + // this.context.info("Tomcat is running at localhost on the following port (default 8080):"); + // Path tomcatPropertiesPath = getToolPath().resolve("conf/server.xml"); + // + // Properties tomcatProperties = PropertiesFileUtil.loadProperties(tomcatPropertiesPath); + // String tomcatWebPort = tomcatProperties.getProperty("redirectPort"); + // if (tomcatWebPort != null) { + // this.context.info("TEST: " + tomcatWebPort); + // } + // } + +} diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/tomcat/TomcatCommand.java b/cli/src/main/java/com/devonfw/tools/ide/tool/tomcat/TomcatCommand.java new file mode 100644 index 000000000..f3b3d4293 --- /dev/null +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/tomcat/TomcatCommand.java @@ -0,0 +1,5 @@ +package com.devonfw.tools.ide.tool.tomcat; + +public enum TomcatCommand { + START, STOP +} diff --git a/cli/src/test/java/com/devonfw/tools/ide/tool/tomcat/TomcatTest.java b/cli/src/test/java/com/devonfw/tools/ide/tool/tomcat/TomcatTest.java new file mode 100644 index 000000000..3470eaf5b --- /dev/null +++ b/cli/src/test/java/com/devonfw/tools/ide/tool/tomcat/TomcatTest.java @@ -0,0 +1,55 @@ +package com.devonfw.tools.ide.tool.tomcat; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import com.devonfw.tools.ide.context.AbstractIdeContextTest; +import com.devonfw.tools.ide.context.IdeTestContext; +import com.devonfw.tools.ide.log.IdeLogLevel; +import com.devonfw.tools.ide.os.SystemInfo; +import com.devonfw.tools.ide.os.SystemInfoMock; + +public class TomcatTest extends AbstractIdeContextTest { + + private static final String PROJECT_TOMCAT = "tomcat"; + + @ParameterizedTest + @ValueSource(strings = { "windows", "linux" }) + public void testTomcatInstall(String os) { + + // arrange + IdeTestContext context = newContext(PROJECT_TOMCAT); + SystemInfo systemInfo = SystemInfoMock.of(os); + context.setSystemInfo(systemInfo); + Tomcat tomcatCommandlet = new Tomcat(context); + + // install + tomcatCommandlet.install(); + + // assert + checkInstallation(context); + checkDependencyInstallation(context); + } + + private void checkDependencyInstallation(IdeTestContext context) { + + assertLogMessage(context, IdeLogLevel.INFO, + "Necessary version of the dependency java is already installed in repository"); + + } + + private void checkInstallation(IdeTestContext context) { + + if (context.getSystemInfo().isWindows() || context.getSystemInfo().isLinux()) { + assertThat(context.getSoftwarePath().resolve("tomcat/bin/tomcat")).exists() + .hasContent("#!/bin/bash\n" + "echo \"tomcat $*\""); + assertThat(context.getSoftwarePath().resolve("tomcat/bin/tomcat.cmd")).exists() + .hasContent("@echo off\n" + "echo tomcat %*"); + } else if (context.getSystemInfo().isMac()) { + assertThat(context.getSoftwarePath().resolve("tomcat/tomcat")).exists(); + } + assertThat(context.getSoftwarePath().resolve("tomcat/.ide.software.version")).exists().hasContent("10.1.14"); + assertLogMessage(context, IdeLogLevel.SUCCESS, "Successfully installed tomcat in version 10.1.14"); + } + +} \ No newline at end of file diff --git a/cli/src/test/resources/ide-projects/tomcat/_ide/urls/tomcat/tomcat/dependencies.json b/cli/src/test/resources/ide-projects/tomcat/_ide/urls/tomcat/tomcat/dependencies.json new file mode 100644 index 000000000..105f8eb38 --- /dev/null +++ b/cli/src/test/resources/ide-projects/tomcat/_ide/urls/tomcat/tomcat/dependencies.json @@ -0,0 +1,64 @@ +{ + "dependencies": { + "(10.0.27,10.1.18]": [ + { + "tool": "java", + "versionRange": "[11,21_35]" + } + ], + "(9.0.85,10.0.27]": [ + { + "tool": "java", + "versionRange": "[8,11)" + } + ], + "(8.5.98,9.0.85]*": [ + { + "tool": "java", + "versionRange": "[8,11)" + } + ], + "(8.0.53,8.5.98]": [ + { + "tool": "java", + "versionRange": "[7,8)" + } + ], + "(7.0.109,8.0.53]": [ + { + "tool": "java", + "versionRange": "[7,8)" + } + ], + "(6.0.53,7.0.109]": [ + { + "tool": "java", + "versionRange": "[7,8)" + } + ], + "(5.5.36,6.0.53])": [ + { + "tool": "java", + "versionRange": "[5,7)" + } + ], + "(4.1.40,5.5.36]": [ + { + "tool": "java", + "versionRange": "[1.4,5)" + } + ], + "(3.3.2,4.1.40]": [ + { + "tool": "java", + "versionRange": "[1.3,1.4)" + } + ], + "(3.3.0,3.3.2]": [ + { + "tool": "java", + "versionRange": "[1.1,1.3)" + } + ] + } +} diff --git a/cli/src/test/resources/ide-projects/tomcat/project/conf/ide.properties b/cli/src/test/resources/ide-projects/tomcat/project/conf/ide.properties new file mode 100644 index 000000000..e69de29bb diff --git a/cli/src/test/resources/ide-projects/tomcat/project/home/.ide/ide.properties b/cli/src/test/resources/ide-projects/tomcat/project/home/.ide/ide.properties new file mode 100644 index 000000000..e69de29bb diff --git a/cli/src/test/resources/ide-projects/tomcat/project/home/readme b/cli/src/test/resources/ide-projects/tomcat/project/home/readme new file mode 100644 index 000000000..5e8bc178c --- /dev/null +++ b/cli/src/test/resources/ide-projects/tomcat/project/home/readme @@ -0,0 +1 @@ +this is the users HOME directory \ No newline at end of file diff --git a/cli/src/test/resources/ide-projects/tomcat/project/readme b/cli/src/test/resources/ide-projects/tomcat/project/readme new file mode 100644 index 000000000..256f5732c --- /dev/null +++ b/cli/src/test/resources/ide-projects/tomcat/project/readme @@ -0,0 +1 @@ +this is the IDE_HOME directory \ No newline at end of file diff --git a/cli/src/test/resources/ide-projects/tomcat/project/settings/ide.properties b/cli/src/test/resources/ide-projects/tomcat/project/settings/ide.properties new file mode 100644 index 000000000..459193285 --- /dev/null +++ b/cli/src/test/resources/ide-projects/tomcat/project/settings/ide.properties @@ -0,0 +1,2 @@ +JAVA_VERSION=17.0.10_7 +TOMCAT_VERSION=10.1.14 \ No newline at end of file diff --git a/cli/src/test/resources/ide-projects/tomcat/project/workspaces/main/readme b/cli/src/test/resources/ide-projects/tomcat/project/workspaces/main/readme new file mode 100644 index 000000000..776cee007 --- /dev/null +++ b/cli/src/test/resources/ide-projects/tomcat/project/workspaces/main/readme @@ -0,0 +1 @@ +this is the main workspace of tomcat test case \ No newline at end of file diff --git a/cli/src/test/resources/ide-projects/tomcat/readme b/cli/src/test/resources/ide-projects/tomcat/readme new file mode 100644 index 000000000..15b91829e --- /dev/null +++ b/cli/src/test/resources/ide-projects/tomcat/readme @@ -0,0 +1 @@ +this is the IDE_ROOT directory \ No newline at end of file diff --git a/cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/linux/InstallTest.txt b/cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/linux/InstallTest.txt new file mode 100644 index 000000000..6de7b8c69 --- /dev/null +++ b/cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/linux/InstallTest.txt @@ -0,0 +1 @@ +This is a test file. diff --git a/cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/linux/bin/tomcat b/cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/linux/bin/tomcat new file mode 100644 index 000000000..561c97367 --- /dev/null +++ b/cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/linux/bin/tomcat @@ -0,0 +1,2 @@ +#!/bin/bash +echo "tomcat $*" \ No newline at end of file diff --git a/cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/linux/bin/tomcat.cmd b/cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/linux/bin/tomcat.cmd new file mode 100644 index 000000000..d2bf95e93 --- /dev/null +++ b/cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/linux/bin/tomcat.cmd @@ -0,0 +1,2 @@ +@echo off +echo tomcat %* \ No newline at end of file diff --git a/cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/windows/InstallTest.txt b/cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/windows/InstallTest.txt new file mode 100644 index 000000000..6de7b8c69 --- /dev/null +++ b/cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/windows/InstallTest.txt @@ -0,0 +1 @@ +This is a test file. diff --git a/cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/windows/bin/tomcat b/cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/windows/bin/tomcat new file mode 100644 index 000000000..561c97367 --- /dev/null +++ b/cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/windows/bin/tomcat @@ -0,0 +1,2 @@ +#!/bin/bash +echo "tomcat $*" \ No newline at end of file diff --git a/cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/windows/bin/tomcat.cmd b/cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/windows/bin/tomcat.cmd new file mode 100644 index 000000000..d2bf95e93 --- /dev/null +++ b/cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/windows/bin/tomcat.cmd @@ -0,0 +1,2 @@ +@echo off +echo tomcat %* \ No newline at end of file