-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
AppImage.java
241 lines (205 loc) · 7.34 KB
/
AppImage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2020-2022 The JReleaser authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jreleaser.model;
import org.jreleaser.util.PlatformUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.jreleaser.model.Distribution.DistributionType.BINARY;
import static org.jreleaser.model.Distribution.DistributionType.JAVA_BINARY;
import static org.jreleaser.model.Distribution.DistributionType.JLINK;
import static org.jreleaser.model.Distribution.DistributionType.NATIVE_IMAGE;
import static org.jreleaser.util.CollectionUtils.setOf;
import static org.jreleaser.util.FileType.TAR;
import static org.jreleaser.util.FileType.TAR_GZ;
import static org.jreleaser.util.FileType.TAR_XZ;
import static org.jreleaser.util.FileType.TGZ;
import static org.jreleaser.util.FileType.TXZ;
import static org.jreleaser.util.FileType.ZIP;
import static org.jreleaser.util.StringUtils.isBlank;
import static org.jreleaser.util.StringUtils.isFalse;
/**
* @author Andres Almiray
* @since 1.2.0
*/
public class AppImage extends AbstractRepositoryPackager<AppImage> {
public static final String TYPE = "appimage";
public static final String SKIP_APPIMAGE = "skipAppImage";
private static final Map<Distribution.DistributionType, Set<String>> SUPPORTED = new LinkedHashMap<>();
static {
Set<String> extensions = setOf(
TAR_GZ.extension(),
TAR_XZ.extension(),
TGZ.extension(),
TXZ.extension(),
TAR.extension(),
ZIP.extension());
SUPPORTED.put(BINARY, extensions);
SUPPORTED.put(JAVA_BINARY, extensions);
SUPPORTED.put(JLINK, extensions);
SUPPORTED.put(NATIVE_IMAGE, extensions);
}
private final AppImageRepository repository = new AppImageRepository();
private final List<Screenshot> screenshots = new ArrayList<>();
private final List<Icon> icons = new ArrayList<>();
private final List<String> categories = new ArrayList<>();
private String componentId;
private String developerName;
private Boolean requiresTerminal;
public AppImage() {
super(TYPE);
}
@Override
public void freeze() {
super.freeze();
screenshots.forEach(ModelObject::freeze);
icons.forEach(ModelObject::freeze);
}
@Override
public void merge(AppImage source) {
freezeCheck();
super.merge(source);
this.componentId = merge(this.componentId, source.componentId);
this.developerName = merge(this.developerName, source.developerName);
this.requiresTerminal = merge(this.requiresTerminal, source.requiresTerminal);
setRepository(source.repository);
setCategories(merge(this.categories, source.categories));
setScreenshots(merge(this.screenshots, source.screenshots));
setIcons(merge(this.icons, source.icons));
}
@Override
public Set<Stereotype> getSupportedStereotypes() {
return setOf(Stereotype.CLI, Stereotype.DESKTOP);
}
public String getComponentId() {
return componentId;
}
public void setComponentId(String componentId) {
freezeCheck();
this.componentId = componentId;
}
public List<String> getCategories() {
return freezeWrap(categories);
}
public void setCategories(List<String> tags) {
freezeCheck();
this.categories.clear();
this.categories.addAll(tags);
}
public String getDeveloperName() {
return developerName;
}
public void setDeveloperName(String developerName) {
freezeCheck();
this.developerName = developerName;
}
public boolean isRequiresTerminal() {
return requiresTerminal != null && requiresTerminal;
}
public void setRequiresTerminal(Boolean requiresTerminal) {
freezeCheck();
this.requiresTerminal = requiresTerminal;
}
public boolean isRequiresTerminalSet() {
return requiresTerminal != null;
}
public List<Screenshot> getScreenshots() {
return freezeWrap(screenshots);
}
public void setScreenshots(List<Screenshot> screenshots) {
freezeCheck();
this.screenshots.clear();
this.screenshots.addAll(screenshots);
}
public void addScreenshot(Screenshot screenshot) {
freezeCheck();
if (null != screenshot) {
this.screenshots.add(screenshot);
}
}
public List<Icon> getIcons() {
return freezeWrap(icons);
}
public void setIcons(List<Icon> icons) {
freezeCheck();
this.icons.clear();
this.icons.addAll(icons);
}
public void addIcon(Icon icon) {
freezeCheck();
if (null != icon) {
this.icons.add(icon);
}
}
public AppImageRepository getRepository() {
return repository;
}
public void setRepository(AppImageRepository repository) {
this.repository.merge(repository);
}
@Override
protected void asMap(boolean full, Map<String, Object> map) {
super.asMap(full, map);
map.put("componentId", componentId);
map.put("categories", categories);
map.put("developerName", developerName);
map.put("requiresTerminal", isRequiresTerminal());
Map<String, Map<String, Object>> sm = new LinkedHashMap<>();
int i = 0;
for (Screenshot screenshot : screenshots) {
sm.put("screenshot " + (i++), screenshot.asMap(full));
}
map.put("screenshots", sm);
sm = new LinkedHashMap<>();
i = 0;
for (Icon icon : icons) {
sm.put("icon " + (i++), icon.asMap(full));
}
map.put("icons", sm);
map.put("repository", repository.asMap(full));
}
@Override
public RepositoryTap getRepositoryTap() {
return repository;
}
@Override
public boolean supportsPlatform(String platform) {
return isBlank(platform) ||
PlatformUtils.isLinux(platform) && PlatformUtils.isIntel64(platform) && !PlatformUtils.isAlpineLinux(platform);
}
@Override
public boolean supportsDistribution(Distribution distribution) {
return SUPPORTED.containsKey(distribution.getType());
}
@Override
public Set<String> getSupportedExtensions(Distribution distribution) {
return Collections.unmodifiableSet(SUPPORTED.getOrDefault(distribution.getType(), Collections.emptySet()));
}
@Override
protected boolean isNotSkipped(Artifact artifact) {
return isFalse(artifact.getExtraProperties().get(SKIP_APPIMAGE));
}
public static class AppImageRepository extends AbstractRepositoryTap<AppImageRepository> {
public AppImageRepository() {
super("appimage", "appimage");
}
}
}