-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Includes the tests for tool dependencies
- Loading branch information
Showing
18 changed files
with
257 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
cli/src/main/java/com/devonfw/tools/ide/tool/tomcat/Tomcat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TomcatCommand> 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); | ||
// } | ||
// } | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
cli/src/main/java/com/devonfw/tools/ide/tool/tomcat/TomcatCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.devonfw.tools.ide.tool.tomcat; | ||
|
||
public enum TomcatCommand { | ||
START, STOP | ||
} |
55 changes: 55 additions & 0 deletions
55
cli/src/test/java/com/devonfw/tools/ide/tool/tomcat/TomcatTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
cli/src/test/resources/ide-projects/tomcat/_ide/urls/tomcat/tomcat/dependencies.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)" | ||
} | ||
] | ||
} | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
this is the users HOME directory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
this is the IDE_HOME directory |
2 changes: 2 additions & 0 deletions
2
cli/src/test/resources/ide-projects/tomcat/project/settings/ide.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
JAVA_VERSION=17.0.10_7 | ||
TOMCAT_VERSION=10.1.14 |
1 change: 1 addition & 0 deletions
1
cli/src/test/resources/ide-projects/tomcat/project/workspaces/main/readme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
this is the main workspace of tomcat test case |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
this is the IDE_ROOT directory |
1 change: 1 addition & 0 deletions
1
...test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/linux/InstallTest.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a test file. |
2 changes: 2 additions & 0 deletions
2
cli/src/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/linux/bin/tomcat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
echo "tomcat $*" |
2 changes: 2 additions & 0 deletions
2
.../test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/linux/bin/tomcat.cmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@echo off | ||
echo tomcat %* |
1 change: 1 addition & 0 deletions
1
...st/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/windows/InstallTest.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a test file. |
2 changes: 2 additions & 0 deletions
2
...rc/test/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/windows/bin/tomcat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
echo "tomcat $*" |
2 changes: 2 additions & 0 deletions
2
...est/resources/ide-projects/tomcat/repository/tomcat/tomcat/default/windows/bin/tomcat.cmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@echo off | ||
echo tomcat %* |