-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
19 changed files
with
237 additions
and
2 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
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
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
20 changes: 20 additions & 0 deletions
20
cli/src/main/java/com/devonfw/tools/ide/property/PasswordProperty.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,20 @@ | ||
package com.devonfw.tools.ide.property; | ||
|
||
/** | ||
* {@link Property} with {@link #getValueType() value type} {@link String} representing a password. | ||
*/ | ||
public class PasswordProperty extends StringProperty { | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param name the {@link #getName() property name}. | ||
* @param required the {@link #isRequired() required flag}. | ||
* @param alias the {@link #getAlias() property alias}. | ||
*/ | ||
public PasswordProperty(String name, boolean required, String alias) { | ||
|
||
super(name, required, alias); | ||
} | ||
|
||
} |
103 changes: 103 additions & 0 deletions
103
cli/src/main/java/com/devonfw/tools/ide/tool/jasypt/Jasypt.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,103 @@ | ||
package com.devonfw.tools.ide.tool.jasypt; | ||
|
||
import com.devonfw.tools.ide.common.Tag; | ||
import com.devonfw.tools.ide.context.IdeContext; | ||
import com.devonfw.tools.ide.property.EnumProperty; | ||
import com.devonfw.tools.ide.property.PasswordProperty; | ||
import com.devonfw.tools.ide.tool.LocalToolCommandlet; | ||
import com.devonfw.tools.ide.tool.ToolCommandlet; | ||
import com.devonfw.tools.ide.tool.java.Java; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Set; | ||
|
||
/** | ||
* {@link ToolCommandlet} for <a href="http://www.jasypt.org/">Jasypt</a>, The java library which allows to add basic | ||
* encryption capabilities with minimum effort. | ||
*/ | ||
public class Jasypt extends LocalToolCommandlet { | ||
|
||
public final EnumProperty<JasyptCommand> command; | ||
|
||
public final PasswordProperty masterPassword; | ||
|
||
public final PasswordProperty secret; | ||
|
||
private static final String CLASS_NAME_ENCRYPTION = "org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI"; | ||
|
||
private static final String CLASS_NAME_DECRYPTION = "org.jasypt.intf.cli.JasyptPBEStringDecryptionCLI"; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param context the {@link IdeContext}. | ||
*/ | ||
public Jasypt(IdeContext context) { | ||
|
||
super(context, "jasypt", Set.of(Tag.JAVA, Tag.ENCRYPTION)); | ||
|
||
this.command = add(new EnumProperty<>("", true, "command", JasyptCommand.class)); | ||
this.masterPassword = add(new PasswordProperty("", true, "masterPassword")); | ||
this.secret = add(new PasswordProperty("", true, "secret")); | ||
} | ||
|
||
@Override | ||
protected void initProperties() { | ||
|
||
// Empty on purpose | ||
} | ||
|
||
@Override | ||
public boolean doInstall(boolean silent) { | ||
|
||
getCommandlet(Java.class).install(); | ||
|
||
return super.doInstall(silent); | ||
} | ||
|
||
@Override | ||
protected boolean isExtract() { | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
|
||
Path toolPath = getToolPath(); | ||
if (!toolPath.toFile().exists()) { | ||
super.install(true); | ||
} | ||
|
||
JasyptCommand command = this.command.getValue(); | ||
switch (command) { | ||
case ENCRYPT: | ||
runJasypt(CLASS_NAME_ENCRYPTION); | ||
break; | ||
case DECRYPT: | ||
runJasypt(CLASS_NAME_DECRYPTION); | ||
break; | ||
|
||
default: | ||
} | ||
} | ||
|
||
private void runJasypt(String className) { | ||
|
||
Java java = getCommandlet(Java.class); | ||
|
||
String[] jasyptOptions = this.context.getVariables().get("JASYPT_OPTS").split(" "); | ||
String algorithm = jasyptOptions[0]; | ||
String generatorClassName = jasyptOptions[1]; | ||
|
||
java.runTool(null, "-cp", resolveJasyptJarPath().toString(), className, algorithm, generatorClassName, | ||
"password=" + this.masterPassword.getValue(), "input=" + this.secret.getValue()); | ||
} | ||
|
||
private Path resolveJasyptJarPath() { | ||
|
||
Path toolPath = this.getToolPath(); | ||
String installedVersion = getInstalledVersion().toString(); | ||
return toolPath.resolve("jasypt-" + installedVersion + ".jar"); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
cli/src/main/java/com/devonfw/tools/ide/tool/jasypt/JasyptCommand.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,8 @@ | ||
package com.devonfw.tools.ide.tool.jasypt; | ||
|
||
/** | ||
* Represents commands for controlling a jasypt operation in The{@link Jasypt} Tool. | ||
*/ | ||
public enum JasyptCommand { | ||
ENCRYPT, DECRYPT | ||
} |
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
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
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
75 changes: 75 additions & 0 deletions
75
cli/src/test/java/com/devonfw/tools/ide/tool/jasypt/JasyptTest.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,75 @@ | ||
package com.devonfw.tools.ide.tool.jasypt; | ||
|
||
import com.devonfw.tools.ide.commandlet.InstallCommandlet; | ||
import com.devonfw.tools.ide.context.AbstractIdeContextTest; | ||
import com.devonfw.tools.ide.context.IdeTestContext; | ||
import com.devonfw.tools.ide.log.IdeLogLevel; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Integration test of {@link Jasypt}. | ||
*/ | ||
public class JasyptTest extends AbstractIdeContextTest { | ||
|
||
private static final String PROJECT_JASYPT = "jasypt"; | ||
|
||
@Test | ||
public void testJasyptInstallCommandlet() { | ||
|
||
// arrange | ||
IdeTestContext context = newContext(PROJECT_JASYPT); | ||
InstallCommandlet install = context.getCommandletManager().getCommandlet(InstallCommandlet.class); | ||
install.tool.setValueAsString("jasypt", context); | ||
// act | ||
install.run(); | ||
|
||
// assert | ||
checkInstallation(context); | ||
} | ||
|
||
@Test | ||
public void testJasyptInstall() { | ||
|
||
// arrange | ||
IdeTestContext context = newContext(PROJECT_JASYPT); | ||
|
||
Jasypt commandlet = new Jasypt(context); | ||
|
||
// act | ||
commandlet.install(); | ||
|
||
// assert | ||
checkInstallation(context); | ||
} | ||
|
||
@Test | ||
public void testJasyptRun() { | ||
|
||
// arrange | ||
IdeTestContext context = newContext(PROJECT_JASYPT); | ||
Jasypt commandlet = new Jasypt(context); | ||
|
||
commandlet.command.setValue(JasyptCommand.ENCRYPT); | ||
commandlet.masterPassword.setValue("password"); | ||
commandlet.secret.setValue("input"); | ||
|
||
// act | ||
commandlet.run(); | ||
|
||
// assert | ||
assertLogMessage(context, IdeLogLevel.INFO, "executing java:"); | ||
assertLogMessage(context, IdeLogLevel.INFO, "This is a jar file."); | ||
checkInstallation(context); | ||
} | ||
|
||
private void checkInstallation(IdeTestContext context) { | ||
|
||
// install - java | ||
assertThat(context.getSoftwarePath().resolve("java/bin/java")).exists(); | ||
|
||
// commandlet - jasypt | ||
assertThat(context.getSoftwarePath().resolve("jasypt/jasypt-1.9.3.jar")).hasContent("This is a jar file."); | ||
assertThat(context.getSoftwarePath().resolve("jasypt/.ide.software.version")).exists().hasContent("1.9.3"); | ||
assertLogMessage(context, IdeLogLevel.SUCCESS, "Successfully installed jasypt in version 1.9.3"); | ||
} | ||
} |
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 download metadata |
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/jasypt/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 | ||
JASYPT_VERSION=1.9.3 |
1 change: 1 addition & 0 deletions
1
cli/src/test/resources/ide-projects/jasypt/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 jmc 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
cli/src/test/resources/ide-projects/jasypt/repository/jasypt/jasypt/default/jasypt-1.9.3.jar
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 jar file. |
3 changes: 3 additions & 0 deletions
3
cli/src/test/resources/ide-projects/jasypt/repository/java/java/default/bin/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,3 @@ | ||
#!/bin/bash | ||
echo "executing java:" | ||
cat $2 # .jar file |