Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/tools/jpackage/windows/WinInstallerIconTest.java
66644 views
1
/*
2
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.awt.Graphics;
25
import java.awt.image.BufferedImage;
26
import java.io.IOException;
27
import java.nio.file.Path;
28
import javax.swing.Icon;
29
import javax.swing.filechooser.FileSystemView;
30
import jdk.jpackage.test.PackageTest;
31
import jdk.jpackage.test.Annotations.Test;
32
import jdk.jpackage.test.JPackageCommand;
33
import jdk.jpackage.test.PackageType;
34
import static jdk.jpackage.test.RunnablePackageTest.Action.CREATE;
35
import jdk.jpackage.test.TKit;
36
37
/**
38
* Test that --icon also changes icon of exe installer.
39
*/
40
41
/*
42
* @test
43
* @summary jpackage with --icon parameter for exe installer
44
* @library ../helpers
45
* @key jpackagePlatformPackage
46
* @build jdk.jpackage.test.*
47
* @build WinInstallerIconTest
48
* @requires (os.family == "windows")
49
* @requires !vm.debug
50
* @modules jdk.jpackage/jdk.jpackage.internal
51
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
52
* --jpt-run=WinInstallerIconTest
53
*/
54
55
/*
56
* note: AWT can throw assertion from GetDiBits() extracting icon
57
* bits in fastdebug mode on windows headless systems. That is why
58
* we have @requires !vm.debug" above.
59
*/
60
public class WinInstallerIconTest {
61
62
@Test
63
public void test() throws IOException {
64
Path customIcon = iconPath("icon");
65
66
BufferedImage[] defaultInstallerIconImg = new BufferedImage[1];
67
68
// Create installer with the default icon
69
long size1 = createInstaller(null, "WithDefaultIcon");
70
71
// Create installer with custom icon.
72
long size2 = createInstaller(customIcon, "WithCustomIcon");
73
74
// Create another installer with custom icon.
75
long size3 = createInstaller(customIcon, null);
76
77
TKit.assertTrue(size2 < size1, "Installer 2 built with custom icon " +
78
"should be smaller than Installer 1 built with default icon");
79
80
TKit.assertTrue(size3 < size1, "Installer 3 built with custom icon " +
81
"should be smaller than Installer 1 built with default icon");
82
83
}
84
85
private long createInstaller(Path icon, String nameSuffix) throws IOException {
86
87
PackageTest test = new PackageTest()
88
.forTypes(PackageType.WIN_EXE)
89
.addInitializer(JPackageCommand::setFakeRuntime)
90
.configureHelloApp();
91
if (icon != null) {
92
test.addInitializer(cmd -> cmd.addArguments("--icon", icon));
93
}
94
95
if (nameSuffix != null) {
96
test.addInitializer(cmd -> {
97
String name = cmd.name() + nameSuffix;
98
cmd.setArgumentValue("--name", name);
99
});
100
}
101
102
Path installerExePath[] = new Path[1];
103
104
test.addBundleVerifier(cmd -> {
105
installerExePath[0] = cmd.outputBundle();
106
});
107
108
test.run(CREATE);
109
110
long size = 0L;
111
if (installerExePath[0] != null) {
112
size = installerExePath[0].toFile().length();
113
TKit.trace(" installer: " + installerExePath[0] + " - size: " + size);
114
if (nameSuffix != null) {
115
TKit.deleteIfExists(installerExePath[0]);
116
}
117
}
118
return size;
119
}
120
121
private static Path iconPath(String name) {
122
return TKit.TEST_SRC_ROOT.resolve(Path.of("resources", name
123
+ TKit.ICON_SUFFIX));
124
}
125
}
126
127