1 /* 2 * Copyright (c) 2018, 2019, 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.nio.file.Path; 25 import jdk.jpackage.test.TKit; 26 import jdk.jpackage.test.PackageTest; 27 import jdk.jpackage.test.PackageType; 28 import jdk.jpackage.test.FileAssociations; 29 import jdk.jpackage.test.Annotations.Test; 30 31 /** 32 * Test --file-associations parameter. Output of the test should be 33 * fileassociationstest*.* installer. The output installer should provide the 34 * same functionality as the default installer (see description of the default 35 * installer in SimplePackageTest.java) plus configure file associations. After 36 * installation files with ".jptest1" and ".jptest2" suffixes should be 37 * associated with the test app. 38 * 39 * Suggested test scenario is to create empty file with ".jptest1" suffix, 40 * double click on it and make sure that test application was launched in 41 * response to double click event with the path to test .jptest1 file on the 42 * commend line. The same applies to ".jptest2" suffix. 43 * 44 * On Linux use "echo > foo.jptest1" and not "touch foo.jptest1" to create test 45 * file as empty files are always interpreted as plain text and will not be 46 * opened with the test app. This is a known bug. 47 * 48 * Icon associated with the main launcher should be associated with files with 49 * ".jptest1" suffix. Different icon should be associated with files with with 50 * ".jptest2" suffix. Icon for files with ".jptest1" suffix is platform specific 51 * and is one of 'icon.*' files in test/jdk/tools/jpackage/resources directory. 52 */ 53 54 /* 55 * @test 56 * @summary jpackage with --file-associations 57 * @library ../helpers 58 * @key jpackagePlatformPackage 59 * @build jdk.jpackage.test.* 60 * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal 61 * @compile FileAssociationsTest.java 62 * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main 63 * --jpt-run=FileAssociationsTest 64 */ 65 public class FileAssociationsTest { 66 @Test 67 public static void test() { 68 PackageTest packageTest = new PackageTest(); 69 70 // Not supported 71 packageTest.excludeTypes(PackageType.MAC_DMG); 72 73 new FileAssociations("jptest1").applyTo(packageTest); 74 75 Path icon = TKit.TEST_SRC_ROOT.resolve(Path.of("resources", "icon" 76 + TKit.ICON_SUFFIX)); 77 78 icon = TKit.createRelativePathCopy(icon); 79 80 new FileAssociations("jptest2") 81 .setFilename("fa2") 82 .setIcon(icon) 83 .applyTo(packageTest); 84 85 packageTest.run(); 86 } 87 }