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

devonfw / IDEasy / 8144002629

04 Mar 2024 04:56PM UTC coverage: 58.928% (+0.7%) from 58.254%
8144002629

push

github

web-flow
#208: improve test infrastructure # 219: fix wrong executable (#238)

* Add first implementation

* Add javadoc

* Add javadoc

* Using target path instead of ressource path to make sure one-to-one copy of set up folders is used

* Add JavaDoc and mac mock program

* Add support for multiple dependencies while testing

* Minor changes

* Modify mock programs for testing

* Refactored example JmcTest

* Add possibility to set execution path by using the context

* Reenable test after related issue 228 has been merged

* Replace ternary with regular if

* Add missing javadoc

* Add missing javadoc

* remove unnecessary semicolon

* Fix spelling typo

* Minor test changes

* Refactoring FileExtractor class for more modularity

* using const

* Add missing extensions

* Remove unnecessary execption declaration and minor rename

* Fix spelling

* Add javadoc

* Forget dot

* minor change

* Revert "minor change"

This reverts commit ec81c3ce6.

* Revert "Merge branch 'main' into feature/208-MockOutToolRepoRefactorTestInfra"

This reverts commit d58847230, reversing
changes made to f38b3105f.

* Revert "Revert "Merge branch 'main' into feature/208-MockOutToolRepoRefactorTestInfra""

This reverts commit 3e49a0b3d.

* Revert "Revert "minor change""

This reverts commit 2f7b94624.

* fix typo

* #208: review and complete rework

* #208: improved system path

* #208: found and fixed bug on windows

* #208: improve OS mocking

* #208: improve test logging

reveal logs/errors so the developer actually sees what is happening instead of leaving them in the dark

* #208: improve OS detection

* #208: fixed

found and fixed bug in MacOS app detection for JMC, fixed copy file to folder bug, moved !extract logic back to FileAccess, f... (continued)

1580 of 2930 branches covered (53.92%)

Branch coverage included in aggregate %.

4047 of 6619 relevant lines covered (61.14%)

2.65 hits per line

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

80.26
cli/src/main/java/com/devonfw/tools/ide/io/TarCompression.java
1
package com.devonfw.tools.ide.io;
2

3
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
4
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
5

6
import java.io.IOException;
7
import java.io.InputStream;
8
import java.util.Locale;
9

10
/**
11
 * {@link Enum} with the available compression modes of a TAR archive file. A GNU Tape ARchive is the standard archive
12
 * format on Linux systems. It is similar to ZIP but it allows to represent advanced metadata such as file permissions
13
 * (e.g. executable flags). Further, it has no compression and is therefore typically combined with generic file
14
 * compressions like {@link #GZ GNU zip} (not to be confused with Windows ZIP) or {@link #BZIP2}.
15
 */
16
public enum TarCompression {
3✔
17

18
  /** No compression (uncompressed TAR). */
19
  NONE("", "tar", null),
9✔
20

21
  /** GNU-Zip compression. */
22
  GZ("gz", "tgz", "-z") {
17✔
23
    @Override
24
    InputStream unpackRaw(InputStream in) throws IOException {
25

26
      return new GzipCompressorInputStream(in);
5✔
27
    }
28
  },
29

30
  /** BZip2 compression. */
31
  BZIP2("bz2", "tbz2", "-j", "bzip2") {
19✔
32
    @Override
33
    InputStream unpackRaw(InputStream in) throws IOException {
34

35
      return new BZip2CompressorInputStream(in);
5✔
36
    }
37
  };
38

39
  private final String extension;
40

41
  private final String combinedExtension;
42

43
  private final String tarOption;
44

45
  private final String altExtension;
46

47
  private TarCompression(String extension, String combinedExtension, String tarOption) {
48

49
    this(extension, combinedExtension, tarOption, null);
8✔
50
  }
1✔
51

52
  private TarCompression(String extension, String combinedExtension, String tarOption, String altExtension) {
4✔
53

54
    this.extension = extension;
3✔
55
    this.combinedExtension = combinedExtension;
3✔
56
    this.tarOption = tarOption;
3✔
57
    this.altExtension = altExtension;
3✔
58
  }
1✔
59

60
  /**
61
   * @return the (default) file extension of this compression (excluding the dot). E.g. "gz" for a "tar.gz" or "tgz"
62
   * file.
63
   */
64
  public String getExtension() {
65

66
    return this.extension;
×
67
  }
68

69
  /**
70
   * @return the compact file extension of this compression combined with the tar archive information. E.g. "tgz" or
71
   * "tbz2".
72
   */
73
  public String getCombinedExtension() {
74

75
    return this.combinedExtension;
×
76
  }
77

78
  /**
79
   * @return the CLI option to enable this compression in the GNU tar command.
80
   */
81
  public String getTarOption() {
82

83
    return this.tarOption;
×
84
  }
85

86
  /**
87
   * @return altExtension
88
   */
89
  public String getAltExtension() {
90

91
    return this.altExtension;
×
92
  }
93

94
  /**
95
   * @param in the {@link InputStream} to wrap for unpacking.
96
   * @return an {@link InputStream} to read the unpacked payload of the given {@link InputStream}.
97
   */
98
  public final InputStream unpack(InputStream in) {
99

100
    try {
101
      return unpackRaw(in);
4✔
102
    } catch (IOException e) {
×
103
      throw new IllegalStateException("Failed to open unpacking stream!", e);
×
104
    }
105
  }
106

107
  InputStream unpackRaw(InputStream in) throws IOException {
108

109
    return in;
2✔
110
  }
111

112
  /**
113
   * @param filename the filename or extension (e.g. "archive.tar.bzip2", "tgz", ".tar.gz", etc.)
114
   * @return the {@link TarCompression} detected from the given {@code filename} or {@code null} if none was detected.
115
   */
116
  public static TarCompression of(String filename) {
117

118
    if ((filename == null) || filename.isEmpty()) {
5!
119
      return null;
×
120
    }
121
    String ext = filename.toLowerCase(Locale.ROOT);
4✔
122
    int tarIndex = ext.lastIndexOf("tar");
4✔
123
    if (tarIndex >= 0) {
2✔
124
      if ((tarIndex == 0) || (ext.charAt(tarIndex - 1) == '.')) {
9!
125
        int tarEnd = tarIndex + 3;
4✔
126
        int rest = ext.length() - tarEnd;
5✔
127
        if (rest == 0) {
2✔
128
          return NONE;
2✔
129
        }
130
        if (ext.charAt(tarEnd) == '.') {
5!
131
          String compression = ext.substring(tarEnd + 1);
6✔
132
          for (TarCompression cmp : values()) {
16✔
133
            if (compression.equals(cmp.extension) || compression.equals(cmp.altExtension)) {
10✔
134
              return cmp;
2✔
135
            }
136
          }
137
        }
138
      }
139
      return null;
2✔
140
    }
141
    int lastDot = ext.lastIndexOf('.');
4✔
142
    if (lastDot > 0) {
2✔
143
      ext = ext.substring(lastDot + 1);
6✔
144
    }
145
    for (TarCompression cmp : values()) {
16✔
146
      if (ext.equals(cmp.combinedExtension) || (ext.endsWith(cmp.combinedExtension)
10!
147
          && ext.charAt(ext.length() - cmp.combinedExtension.length() - 1) == '.')) {
×
148
        return cmp;
2✔
149
      }
150
    }
151
    return null;
2✔
152
  }
153

154
}
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

© 2026 Coveralls, Inc