• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 11060995883

26 Sep 2024 10:09PM UTC coverage: 66.053% (-0.05%) from 66.107%
11060995883

Pull #652

github

web-flow
Merge 3cdc5b3b2 into ad80f56d2
Pull Request #652: #593: #651: #564: #439: fixed bugs, refactored tool dependencies

2312 of 3848 branches covered (60.08%)

Branch coverage included in aggregate %.

6078 of 8854 relevant lines covered (68.65%)

3.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.07
cli/src/main/java/com/devonfw/tools/ide/tool/jasypt/Jasypt.java
1
package com.devonfw.tools.ide.tool.jasypt;
2

3
import java.nio.file.Path;
4
import java.util.ArrayList;
5
import java.util.Arrays;
6
import java.util.List;
7
import java.util.Set;
8

9
import com.devonfw.tools.ide.common.Tag;
10
import com.devonfw.tools.ide.context.IdeContext;
11
import com.devonfw.tools.ide.nls.NlsBundle;
12
import com.devonfw.tools.ide.property.EnumProperty;
13
import com.devonfw.tools.ide.property.PasswordProperty;
14
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
15
import com.devonfw.tools.ide.tool.ToolCommandlet;
16
import com.devonfw.tools.ide.tool.java.Java;
17

18
/**
19
 * {@link ToolCommandlet} for <a href="http://www.jasypt.org/">Jasypt</a>, The java library which allows to add basic encryption capabilities with minimum
20
 * effort.
21
 */
22
public class Jasypt extends LocalToolCommandlet {
23

24
  /** {@link EnumProperty} for the command (encrypt or decrypt) */
25
  public final EnumProperty<JasyptCommand> command;
26

27
  /** {@link PasswordProperty} for the master password */
28
  public final PasswordProperty masterPassword;
29

30
  /** {@link PasswordProperty} for the secret to be encrypted or decrypted */
31
  public final PasswordProperty secret;
32

33
  private static final String CLASS_NAME_ENCRYPTION = "org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI";
34

35
  private static final String CLASS_NAME_DECRYPTION = "org.jasypt.intf.cli.JasyptPBEStringDecryptionCLI";
36

37
  /**
38
   * The constructor.
39
   *
40
   * @param context the {@link IdeContext}.
41
   */
42
  public Jasypt(IdeContext context) {
43

44
    super(context, "jasypt", Set.of(Tag.JAVA, Tag.ENCRYPTION));
7✔
45

46
    this.command = add(new EnumProperty<>("", true, "command", JasyptCommand.class));
12✔
47
    this.masterPassword = add(new PasswordProperty("", true, "masterPassword"));
11✔
48
    this.secret = add(new PasswordProperty("", true, "secret"));
11✔
49
  }
1✔
50

51
  @Override
52
  protected void initProperties() {
53

54
    // Empty on purpose
55
  }
1✔
56

57
  @Override
58
  protected void installDependencies() {
59

60
    // TODO create jasypt/jasypt/dependencies.json file in ide-urls and delete this method
61
    getCommandlet(Java.class).install();
6✔
62
  }
1✔
63

64
  @Override
65
  protected boolean isExtract() {
66

67
    return false;
2✔
68
  }
69

70
  @Override
71
  public void run() {
72

73
    Path toolPath = getToolPath();
3✔
74
    if (!toolPath.toFile().exists()) {
4!
75
      super.install(true);
4✔
76
    }
77

78
    JasyptCommand command = this.command.getValue();
5✔
79
    switch (command) {
5!
80
      case ENCRYPT:
81
        runJasypt(CLASS_NAME_ENCRYPTION);
3✔
82
        break;
1✔
83
      case DECRYPT:
84
        runJasypt(CLASS_NAME_DECRYPTION);
×
85
        break;
×
86

87
      default:
88
    }
89
  }
1✔
90

91
  private void runJasypt(String className) {
92

93
    List<String> arguments = new ArrayList<>(
11✔
94
        Arrays.asList("-cp", resolveJasyptJarPath().toString(), className, "password=" + this.masterPassword.getValue(),
22✔
95
            "input=" + this.secret.getValue()));
4✔
96

97
    String jasyptOpts = this.context.getVariables().get("JASYPT_OPTS");
6✔
98
    if (jasyptOpts != null && !jasyptOpts.trim().isEmpty()) {
6!
99
      String[] jasyptOptions = jasyptOpts.split("\\s+");
4✔
100

101
      arguments.addAll(Arrays.asList(jasyptOptions));
5✔
102
    }
103

104
    Java java = getCommandlet(Java.class);
5✔
105
    java.runTool(arguments.toArray(i -> new String[i]));
9✔
106
  }
1✔
107

108
  private Path resolveJasyptJarPath() {
109

110
    Path toolPath = this.getToolPath();
3✔
111
    String installedVersion = getInstalledVersion().toString();
4✔
112
    return toolPath.resolve("jasypt-" + installedVersion + ".jar");
5✔
113
  }
114

115
  @Override
116
  public void printHelp(NlsBundle bundle) {
117

118
    this.context.info(
×
119
        "To get detailed help about the usage of the jasypt CLI tools, see http://www.jasypt.org/cli.html#");
120
  }
×
121
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc