1 /* 2 * Copyright (c) 2014, 2016 Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 */ 5 package com.oracle.appbundlers.tests.functionality; 6 7 import static com.oracle.appbundlers.tests.functionality.IconTest.iconExtension; 8 import static com.oracle.appbundlers.utils.Config.CONFIG_INSTANCE; 9 import static com.oracle.appbundlers.utils.installers.AbstractBundlerUtils.ASSOCIATED_EXTENSIONS; 10 import static com.oracle.appbundlers.utils.installers.AbstractBundlerUtils.WIN_SYSTEM_WIDE_FILE_ASSOCIATIONS; 11 import static com.oracle.appbundlers.utils.installers.AbstractBundlerUtils.WIN_USER_FILE_ASSOCIATIONS; 12 13 import java.io.IOException; 14 import java.util.Arrays; 15 import java.util.HashMap; 16 import java.util.Map; 17 import java.util.concurrent.ExecutionException; 18 import java.util.concurrent.TimeUnit; 19 20 import com.oracle.appbundlers.tests.functionality.functionalinterface.AdditionalParams; 21 import com.oracle.appbundlers.tests.functionality.functionalinterface.VerifiedOptions; 22 import com.oracle.appbundlers.utils.AppWrapper; 23 import com.oracle.appbundlers.utils.BundlerUtils; 24 import com.oracle.appbundlers.utils.BundlingManagers; 25 import com.oracle.appbundlers.utils.ExtensionType; 26 import com.oracle.appbundlers.utils.Source; 27 import com.oracle.appbundlers.utils.Utils; 28 29 import javafx.util.Pair; 30 31 /** 32 * @author Dmitry Ginzburg <dmitry.x.ginzburg@oracle.com> 33 */ 34 35 public class FileAssociationTest extends TestBase { 36 public static final String RM_FULLNAME = "testapp.RmApp"; 37 public static final String RM_NAME = "RmApp"; 38 public static final String ext1 = "foo", ext2 = "bar", ext3 = "baz", 39 ext4 = "qux"; 40 41 @Override 42 protected BundlerUtils[] getBundlerUtils() { 43 return new BundlerUtils[] { BundlerUtils.MAC_APP, BundlerUtils.PKG, 44 BundlerUtils.DMG, 45 46 BundlerUtils.EXE, BundlerUtils.MSI, BundlerUtils.DEB, 47 BundlerUtils.RPM }; 48 } 49 50 @Override 51 protected BundlingManagers[] getBundlingManagers() { 52 return new BundlingManagers[] { BundlingManagers.JAVA_API, 53 BundlingManagers.ANT }; 54 } 55 56 protected AdditionalParams getAdditionalParams() { 57 return () -> { 58 Map<String, Object> additionalParams = new HashMap<>(); 59 Map<String, Object> association1 = new HashMap<>(); 60 association1.put(FA_EXTENSIONS, Arrays.asList(ext1, ext2)); 61 association1.put(FA_CONTENT_TYPE, 62 Arrays.asList("application/example")); 63 association1.put(FA_DESCRIPTION, "The sample description"); 64 Map<String, Object> association2 = new HashMap<>(); 65 association2.put(FA_EXTENSIONS, Arrays.asList(ext3, ext4)); 66 association2.put(FA_CONTENT_TYPE, Arrays.asList("hello/world")); 67 association2.put(FA_ICON, CONFIG_INSTANCE 68 .getResourceFilePath("icon2." + iconExtension()).toFile()); 69 additionalParams.put(FILE_ASSOCIATIONS, 70 Arrays.asList(association1, association2)); 71 additionalParams.put(SYSTEM_WIDE, true); 72 return additionalParams; 73 }; 74 } 75 76 protected VerifiedOptions getVerifiedOptions() { 77 return () -> { 78 Map<String, Object> verifiedOptions = new HashMap<>( 79 getAdditionalParams().getAdditionalParams()); 80 verifiedOptions.put(ASSOCIATED_EXTENSIONS, 81 Arrays.asList(ext1, ext2, ext3, ext4)); 82 verifiedOptions.put(WIN_SYSTEM_WIDE_FILE_ASSOCIATIONS, 83 getAdditionalParams().getAdditionalParams() 84 .get(FILE_ASSOCIATIONS)); 85 verifiedOptions.remove(WIN_USER_FILE_ASSOCIATIONS); 86 return verifiedOptions; 87 }; 88 } 89 90 private AppWrapper getNewApp(ExtensionType extension) throws IOException { 91 Map<String, String> replacementsInSrcCodeInternal = new HashMap<>(); 92 replacementsInSrcCodeInternal.put(APP_NAME_REPLACEMENT_STATEMENT, 93 RM_NAME); 94 String templateName = Utils.isMacOS() ? "MacRmApp.java.template" 95 : "RmApp.java.template"; 96 String mainClassfullyQualifiedName = "com.rm.testapp.RmApp"; 97 switch (extension) { 98 default: 99 return new AppWrapper(Utils.getTempSubDir(WORK_DIRECTORY), 100 mainClassfullyQualifiedName, new Source(mainClassfullyQualifiedName, templateName, "rmApp", 101 replacementsInSrcCodeInternal)); 102 case ExplodedModules: 103 case Jmods: 104 case ModularJar: 105 Map<String, String> classNameToTemplateMap = new HashMap<String, String>(); 106 classNameToTemplateMap.put(mainClassfullyQualifiedName, templateName); 107 return new AppWrapper(Utils.getTempSubDir(WORK_DIRECTORY), 108 mainClassfullyQualifiedName, 109 new Source("com.rm", "com.rm.module.info.template", 110 classNameToTemplateMap, mainClassfullyQualifiedName, 111 "rmApp", replacementsInSrcCodeInternal, true)); 112 } 113 } 114 115 @Override 116 public String getResultingAppName() { 117 return RM_NAME; 118 } 119 120 @Override 121 protected Pair<TimeUnit, Integer> getDelayAfterInstall() { 122 return new Pair<>(TimeUnit.MILLISECONDS, 123 CONFIG_INSTANCE.getAfterInstallationPause()); 124 } 125 126 @Override 127 protected void prepareApp(AppWrapper app, ExtensionType extension) 128 throws IOException, ExecutionException { 129 final String makeJavacReadClassesFromRtJar = "-XDignore.symbol.file=true"; 130 app.preinstallApp(extension); 131 app.writeSourcesToAppDirectory(); 132 app.compileApp(new String[] { makeJavacReadClassesFromRtJar }); 133 app.jarApp(extension); 134 } 135 136 @Override 137 public void overrideParameters(ExtensionType extension) throws IOException { 138 this.currentParameter.setAdditionalParams(getAdditionalParams()); 139 this.currentParameter.setVerifiedOptions(getVerifiedOptions()); 140 this.currentParameter.setApp(getNewApp(extension)); 141 } 142 }