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

jreleaser / jreleaser / #477

04 Apr 2025 05:53PM UTC coverage: 35.124% (-5.1%) from 40.183%
#477

push

github

aalmiray
fix(deploy): Add missing Forgejo messages

Related to #1842

18210 of 51845 relevant lines covered (35.12%)

0.35 hits per line

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

64.29
/api/jreleaser-utils/src/main/java/org/jreleaser/util/FileType.java
1
/*
2
 * SPDX-License-Identifier: Apache-2.0
3
 *
4
 * Copyright 2020-2025 The JReleaser authors.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     https://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
package org.jreleaser.util;
19

20
import java.nio.file.Path;
21
import java.util.LinkedHashSet;
22
import java.util.Locale;
23
import java.util.Optional;
24
import java.util.Set;
25

26
import static org.jreleaser.util.StringUtils.isBlank;
27

28
/**
29
 * @author Andres Almiray
30
 * @since 0.10.0
31
 */
32
public enum FileType {
1✔
33
    ASC("asc"),
1✔
34
    BAT("bat"),
1✔
35
    CMD("cmd"),
1✔
36
    DEB("deb"),
1✔
37
    DMG("dmg"),
1✔
38
    EXE("exe"),
1✔
39
    JAR("jar"),
1✔
40
    MSI("msi"),
1✔
41
    NUGET("nuget"),
1✔
42
    PKG("pkg"),
1✔
43
    PS1("ps1"),
1✔
44
    RPM("rpm"),
1✔
45
    SH("sh"),
1✔
46
    SIG("sig"),
1✔
47
    TAR("tar", true),
1✔
48
    TAR_BZ2("tar.bz2", true),
1✔
49
    TAR_GZ("tar.gz", true),
1✔
50
    TAR_XZ("tar.xz", true),
1✔
51
    TAR_ZST("tar.zst", true),
1✔
52
    TBZ2("tbz2", true),
1✔
53
    TGZ("tgz", true),
1✔
54
    TXZ("txz", true),
1✔
55
    ZIP("zip", true),
1✔
56
    ZST("zst", true);
1✔
57

58
    private final String type;
59
    private final boolean archive;
60

61
    FileType(String type) {
62
        this(type, false);
1✔
63
    }
1✔
64

65
    FileType(String type, boolean archive) {
1✔
66
        this.type = type;
1✔
67
        this.archive = archive;
1✔
68
    }
1✔
69

70
    public boolean archive() {
71
        return this.archive;
×
72
    }
73

74
    public String type() {
75
        return this.type;
1✔
76
    }
77

78
    public String extension() {
79
        return "." + this.type;
1✔
80
    }
81

82
    public String formatted() {
83
        return type();
×
84
    }
85

86
    public static FileType of(String str) {
87
        if (isBlank(str)) return null;
1✔
88
        return FileType.valueOf(str.toUpperCase(Locale.ENGLISH).trim()
1✔
89
            .replace(".", "_"));
1✔
90
    }
91

92
    public static Set<String> getSupportedTypes() {
93
        Set<String> set = new LinkedHashSet<>();
×
94
        for (FileType value : values()) {
×
95
            set.add(value.type());
×
96
        }
97
        return set;
×
98
    }
99

100
    public static Set<String> getSupportedExtensions() {
101
        Set<String> set = new LinkedHashSet<>();
1✔
102
        for (FileType value : values()) {
1✔
103
            set.add(value.extension());
1✔
104
        }
105
        return set;
1✔
106
    }
107

108
    public static Optional<FileType> getFileType(Path path) {
109
        if (null != path) {
×
110
            return getFileType(path.getFileName().toString());
×
111
        }
112
        return Optional.empty();
×
113
    }
114

115
    public static Optional<FileType> getFileType(String path) {
116
        if (isBlank(path)) return Optional.empty();
×
117

118
        for (FileType value : values()) {
×
119
            if (path.endsWith(value.extension())) {
×
120
                return Optional.of(value);
×
121
            }
122
        }
123

124
        return Optional.empty();
×
125
    }
126

127
    public static String getType(Path path) {
128
        if (null != path) {
×
129
            return getType(path.getFileName().toString());
×
130
        }
131
        return "";
×
132
    }
133

134
    public static String getType(String path) {
135
        if (isBlank(path)) return "";
1✔
136

137
        for (FileType value : values()) {
1✔
138
            if (path.endsWith(value.extension())) {
1✔
139
                return value.type();
1✔
140
            }
141
        }
142

143
        return "";
1✔
144
    }
145

146
    public static String getExtension(Path path) {
147
        if (null != path) {
×
148
            return getExtension(path.getFileName().toString());
×
149
        }
150
        return "";
×
151
    }
152

153
    public static String getExtension(String path) {
154
        if (isBlank(path)) return "";
×
155

156
        for (FileType value : values()) {
×
157
            if (path.endsWith(value.extension())) {
×
158
                return value.extension();
×
159
            }
160
        }
161

162
        return "";
×
163
    }
164
}
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