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

devonfw / IDEasy / 12088062306

29 Nov 2024 04:30PM UTC coverage: 67.008% (+0.01%) from 66.998%
12088062306

push

github

web-flow
#739: removed "not inside an IDE installation message" (#753)

2506 of 4088 branches covered (61.3%)

Branch coverage included in aggregate %.

6534 of 9403 relevant lines covered (69.49%)

3.06 hits per line

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

81.82
cli/src/main/java/com/devonfw/tools/ide/commandlet/EnvironmentCommandlet.java
1
package com.devonfw.tools.ide.commandlet;
2

3
import java.util.List;
4
import java.util.Map;
5
import java.util.stream.Collectors;
6

7
import com.devonfw.tools.ide.cli.CliExitException;
8
import com.devonfw.tools.ide.context.AbstractIdeContext;
9
import com.devonfw.tools.ide.context.IdeContext;
10
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
11
import com.devonfw.tools.ide.environment.VariableLine;
12
import com.devonfw.tools.ide.log.IdeLogLevel;
13
import com.devonfw.tools.ide.log.IdeSubLogger;
14
import com.devonfw.tools.ide.os.WindowsPathSyntax;
15
import com.devonfw.tools.ide.property.FlagProperty;
16

17
/**
18
 * {@link Commandlet} to print the environment variables.
19
 */
20
public final class EnvironmentCommandlet extends Commandlet {
21

22
  /** {@link FlagProperty} to enable Bash (MSys) path conversion on Windows. */
23
  public final FlagProperty bash;
24

25
  /**
26
   * The constructor.
27
   *
28
   * @param context the {@link IdeContext}.
29
   */
30
  public EnvironmentCommandlet(IdeContext context) {
31

32
    super(context);
3✔
33
    addKeyword(getName());
4✔
34
    this.bash = add(new FlagProperty("--bash"));
9✔
35
  }
1✔
36

37
  @Override
38
  public String getName() {
39

40
    return "env";
2✔
41
  }
42

43
  @Override
44
  public boolean isIdeHomeRequired() {
45

46
    return false;
2✔
47
  }
48

49
  @Override
50
  public boolean isProcessableOutput() {
51

52
    return true;
×
53
  }
54

55
  @Override
56
  public void run() {
57
    if (context.getIdeHome() == null) {
4!
58
      throw new CliExitException();
×
59
    }
60
    boolean winCmd = false;
2✔
61
    WindowsPathSyntax pathSyntax = null;
2✔
62
    IdeSubLogger logger = this.context.level(IdeLogLevel.PROCESSABLE);
5✔
63
    if (this.context.getSystemInfo().isWindows()) {
5!
64
      if (this.bash.isTrue()) {
×
65
        pathSyntax = WindowsPathSyntax.MSYS;
×
66
      } else {
67
        winCmd = true;
×
68
        pathSyntax = WindowsPathSyntax.WINDOWS;
×
69
      }
70
    }
71
    ((AbstractIdeContext) this.context).setPathSyntax(pathSyntax);
5✔
72
    List<VariableLine> variables = this.context.getVariables().collectVariables();
5✔
73
    if (this.context.debug().isEnabled()) {
5✔
74
      Map<EnvironmentVariablesType, List<VariableLine>> type2lines = variables.stream().collect(Collectors.groupingBy(l -> l.getSource().type()));
11✔
75
      for (EnvironmentVariablesType type : EnvironmentVariablesType.values()) {
16✔
76
        List<VariableLine> lines = type2lines.get(type);
5✔
77
        if (lines != null) {
2✔
78
          boolean sourcePrinted = false;
2✔
79
          sortVariables(lines);
2✔
80
          for (VariableLine line : lines) {
10✔
81
            if (!sourcePrinted) {
2✔
82
              this.context.debug("from {}:", line.getSource());
11✔
83
              sourcePrinted = true;
2✔
84
            }
85
            logger.log(format(line, winCmd));
6✔
86
          }
1✔
87
        }
88
      }
89
    } else {
1✔
90
      sortVariables(variables);
2✔
91
      for (VariableLine line : variables) {
10✔
92
        logger.log(format(line, winCmd));
6✔
93
      }
1✔
94
    }
95
  }
1✔
96

97
  private static void sortVariables(List<VariableLine> lines) {
98
    lines.sort((c1, c2) -> c1.getName().compareTo(c2.getName()));
9✔
99
  }
1✔
100

101
  private String format(VariableLine line, boolean winCmd) {
102

103
    if (winCmd) {
2!
104
      return line.getName() + "=" + line.getValue();
×
105
    } else {
106
      String lineValue = line.getValue();
3✔
107
      lineValue = "\"" + lineValue + "\"";
3✔
108
      line = line.withValue(lineValue);
4✔
109
      return line.toString();
3✔
110
    }
111
  }
112
}
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