Javafx: Support application icon in JavaFX self-contained app deployment - use absolute path when building artifact and relative path when generating Ant build file (IDEA-134616)

This commit is contained in:
Pavel Dolgov
2016-04-13 18:53:51 +03:00
parent b947362002
commit 48b75ae491
5 changed files with 87 additions and 21 deletions
@@ -104,7 +104,7 @@ public abstract class AbstractJavaFxPackager {
buf.append("<target name=\"build artifact\" xmlns:fx=\"javafx:com.sun.javafx.tools.ant\">");
final String artifactFileName = getArtifactRootName();
final List<JavaFxAntGenerator.SimpleTag> tags =
JavaFxAntGenerator.createJarAndDeployTasks(this, artifactFileName, getArtifactName(), tempUnzippedArtifactOutput.getPath());
JavaFxAntGenerator.createJarAndDeployTasks(this, artifactFileName, getArtifactName(), tempUnzippedArtifactOutput.getPath(), false);
for (JavaFxAntGenerator.SimpleTag tag : tags) {
tag.generate(buf);
}
@@ -33,7 +33,8 @@ public class JavaFxAntGenerator {
public static List<SimpleTag> createJarAndDeployTasks(AbstractJavaFxPackager packager,
String artifactFileName,
String artifactName,
String tempDirPath) {
String tempDirPath,
boolean isRelativeIconPath) {
final String artifactFileNameWithoutExtension = FileUtil.getNameWithoutExtension(artifactFileName);
final List<SimpleTag> topLevelTagsCollector = new ArrayList<SimpleTag>();
final String preloaderJar = packager.getPreloaderJar();
@@ -119,7 +120,7 @@ public class JavaFxAntGenerator {
topLevelTagsCollector.add(createJarTag);
final JavaFxPackagerConstants.NativeBundles bundle = packager.getNativeBundle();
final SimpleTag iconTag = appendApplicationIconPath(topLevelTagsCollector, bundle, packager.getIcons());
final SimpleTag iconTag = appendApplicationIconPath(topLevelTagsCollector, bundle, packager.getIcons(), isRelativeIconPath);
//deploy task
final SimpleTag deployTag = new SimpleTag("fx:deploy",
@@ -155,32 +156,33 @@ public class JavaFxAntGenerator {
private static SimpleTag appendApplicationIconPath(List<SimpleTag> topLevelTagsCollector,
JavaFxPackagerConstants.NativeBundles bundle,
JavaFxApplicationIcons appIcons) {
JavaFxApplicationIcons appIcons,
boolean isRelativeIconPath) {
boolean haveAppIcon = false;
if (appIcons == null || bundle == null || appIcons.isEmpty()) return null;
if (bundle.isOnLinux()) {
String iconPath = appIcons.getRelativeLinuxIcon();
String iconPath = appIcons.getLinuxIcon(isRelativeIconPath);
if (!StringUtil.isEmpty(iconPath)) {
final SimpleTag and = new SimpleTag("and");
and.add(new SimpleTag("os", Couple.of("family", "unix")));
final SimpleTag not = new SimpleTag("not");
not.add(new SimpleTag("os", Couple.of("family", "mac")));
and.add(not);
appendIconPropertyTag(topLevelTagsCollector, iconPath, and);
appendIconPropertyTag(topLevelTagsCollector, iconPath, isRelativeIconPath, and);
haveAppIcon = true;
}
}
if (bundle.isOnMac()) {
String iconPath = appIcons.getRelativeMacIcon();
String iconPath = appIcons.getMacIcon(isRelativeIconPath);
if (!StringUtil.isEmpty(iconPath)) {
appendIconPropertyTag(topLevelTagsCollector, iconPath, new SimpleTag("os", Couple.of("family", "mac")));
appendIconPropertyTag(topLevelTagsCollector, iconPath, isRelativeIconPath, new SimpleTag("os", Couple.of("family", "mac")));
haveAppIcon = true;
}
}
if (bundle.isOnWindows()) {
String iconPath = appIcons.getRelativeWindowsIcon();
String iconPath = appIcons.getWindowsIcon(isRelativeIconPath);
if (!StringUtil.isEmpty(iconPath)) {
appendIconPropertyTag(topLevelTagsCollector, iconPath, new SimpleTag("os", Couple.of("family", "windows")));
appendIconPropertyTag(topLevelTagsCollector, iconPath, isRelativeIconPath, new SimpleTag("os", Couple.of("family", "windows")));
haveAppIcon = true;
}
}
@@ -190,10 +192,13 @@ public class JavaFxAntGenerator {
return null;
}
private static void appendIconPropertyTag(List<SimpleTag> tagsCollector, String iconPath, SimpleTag osFamily) {
private static void appendIconPropertyTag(List<SimpleTag> tagsCollector,
String iconPath,
boolean isRelativeIconPath,
SimpleTag osFamily) {
final SimpleTag condition = new SimpleTag("condition",
Couple.of("property", "app.icon.path"),
Couple.of("value", "${basedir}/" + iconPath));
Couple.of("value", isRelativeIconPath ? "${basedir}/" + iconPath : iconPath));
condition.add(osFamily);
tagsCollector.add(condition);
}
@@ -17,8 +17,8 @@ public class JavaFxApplicationIcons {
return myLinuxIcon;
}
public String getRelativeLinuxIcon() {
return getRelativeIcon(myLinuxIcon);
public String getLinuxIcon(boolean isRelative) {
return isRelative ? getRelativeIcon(myLinuxIcon) : myLinuxIcon;
}
public void setLinuxIcon(String linuxIcon) {
@@ -29,8 +29,8 @@ public class JavaFxApplicationIcons {
return myMacIcon;
}
public String getRelativeMacIcon() {
return getRelativeIcon(myMacIcon);
public String getMacIcon(boolean isRelative) {
return isRelative ? getRelativeIcon(myMacIcon) : myMacIcon;
}
public void setMacIcon(String macIcon) {
@@ -41,8 +41,8 @@ public class JavaFxApplicationIcons {
return myWindowsIcon;
}
public String getRelativeWindowsIcon() {
return getRelativeIcon(myWindowsIcon);
public String getWindowsIcon(boolean isRelative) {
return isRelative ? getRelativeIcon(myWindowsIcon) : myWindowsIcon;
}
public void setWindowsIcon(String windowsIcon) {
@@ -16,6 +16,7 @@
package org.jetbrains.plugins.javaFX.packaging;
import com.intellij.testFramework.UsefulTestCase;
import com.intellij.util.containers.ContainerUtil;
import java.io.File;
import java.util.Collections;
@@ -32,6 +33,7 @@ public class JavaFxAntTaskTest extends UsefulTestCase{
private static final String PRELOADER_CLASS = "preloaderClass";
private static final String TITLE = "title";
private static final String ICONS = "icons";
private static final String RELATIVE_PATH = "relativePath";
private static final String PRELOADER_JAR = "preloaderJar";
private static final String SIGNED = "signed";
@@ -143,7 +145,64 @@ public class JavaFxAntTaskTest extends UsefulTestCase{
"<fx:fileset refid=\"all_jarDeployIcon\">\n" +
"</fx:fileset>\n" +
"</fx:resources>\n" +
"</fx:deploy>\n", Collections.singletonMap(ICONS, "app_icon.png,app_icon.icns,app_icon.ico"));
"</fx:deploy>\n", new ContainerUtil.ImmutableMapBuilder<String, String>()
.put(ICONS, "/project_dir/app_icon.png,/project_dir/app_icon.icns,/project_dir/app_icon.ico,/project_dir")
.put(RELATIVE_PATH, "true")
.build());
}
public void testJarDeployIconAbsolute() throws Exception {
doTest("<fx:fileset id=\"all_but_jarDeployIconAbsolute\" dir=\"temp\" includes=\"**/*.jar\">\n" +
"<exclude name=\"jarDeployIconAbsolute.jar\">\n" +
"</exclude>\n" +
"</fx:fileset>\n" +
"<fx:fileset id=\"all_jarDeployIconAbsolute\" dir=\"temp\" includes=\"**/*.jar\">\n" +
"</fx:fileset>\n" +
"<fx:application id=\"jarDeployIconAbsolute_id\" name=\"jarDeployIconAbsolute\" mainClass=\"Main\">\n" +
"</fx:application>\n" +
"<fx:jar destfile=\"temp/jarDeployIconAbsolute.jar\">\n" +
"<fx:application refid=\"jarDeployIconAbsolute_id\">\n" +
"</fx:application>\n" +
"<fileset dir=\"temp\" excludes=\"**/*.jar\">\n" +
"</fileset>\n" +
"<fx:resources>\n" +
"<fx:fileset refid=\"all_but_jarDeployIconAbsolute\">\n" +
"</fx:fileset>\n" +
"</fx:resources>\n" +
"</fx:jar>\n" +
"<condition property=\"app.icon.path\" value=\"/project_dir/app_icon.png\">\n" +
"<and>\n" +
"<os family=\"unix\">\n" +
"</os>\n" +
"<not>\n" +
"<os family=\"mac\">\n" +
"</os>\n" +
"</not>\n" +
"</and>\n" +
"</condition>\n" +
"<condition property=\"app.icon.path\" value=\"/project_dir/app_icon.icns\">\n" +
"<os family=\"mac\">\n" +
"</os>\n" +
"</condition>\n" +
"<condition property=\"app.icon.path\" value=\"/project_dir/app_icon.ico\">\n" +
"<os family=\"windows\">\n" +
"</os>\n" +
"</condition>\n" +
"<fx:deploy width=\"800\" height=\"400\" updatemode=\"background\" outdir=\"temp/deploy\" outfile=\"jarDeployIconAbsolute\" nativeBundles=\"all\">\n" +
"<fx:application refid=\"jarDeployIconAbsolute_id\">\n" +
"</fx:application>\n" +
"<fx:info>\n" +
"<fx:icon href=\"${app.icon.path}\">\n" +
"</fx:icon>\n" +
"</fx:info>\n" +
"<fx:resources>\n" +
"<fx:fileset refid=\"all_jarDeployIconAbsolute\">\n" +
"</fx:fileset>\n" +
"</fx:resources>\n" +
"</fx:deploy>\n", new ContainerUtil.ImmutableMapBuilder<String, String>()
.put(ICONS, "/project_dir/app_icon.png,/project_dir/app_icon.icns,/project_dir/app_icon.ico,/project_dir")
.put(RELATIVE_PATH, "false")
.build());
}
public void testJarDeploySigned() throws Exception {
@@ -229,6 +288,7 @@ public class JavaFxAntTaskTest extends UsefulTestCase{
packager.setTitle(title);
}
boolean isRelativeIconPath = Boolean.valueOf(options.get(RELATIVE_PATH));
final String icon = options.get(ICONS);
if (icon != null) {
final String[] icons = icon.split(",");
@@ -236,6 +296,7 @@ public class JavaFxAntTaskTest extends UsefulTestCase{
appIcons.setLinuxIcon(icons[0]);
appIcons.setMacIcon(icons[1]);
appIcons.setWindowsIcon(icons[2]);
appIcons.setBaseDir(icons[3]);
packager.setIcons(appIcons);
packager.setNativeBundle(JavaFxPackagerConstants.NativeBundles.all);
}
@@ -255,7 +316,7 @@ public class JavaFxAntTaskTest extends UsefulTestCase{
}
final List<JavaFxAntGenerator.SimpleTag> temp = JavaFxAntGenerator
.createJarAndDeployTasks(packager, artifactFileName, artifactName, "temp");
.createJarAndDeployTasks(packager, artifactFileName, artifactName, "temp", isRelativeIconPath);
final StringBuilder buf = new StringBuilder();
for (JavaFxAntGenerator.SimpleTag tag : temp) {
tag.generate(buf);
@@ -146,7 +146,7 @@ public class JavaFxChunkBuildExtension extends ChunkBuildExtension {
protected void registerJavaFxPackagerError(String message) {}
};
final List<JavaFxAntGenerator.SimpleTag> tags =
JavaFxAntGenerator.createJarAndDeployTasks(javaFxPackager, artifactFileName, artifact.getName(), tempDirPath);
JavaFxAntGenerator.createJarAndDeployTasks(javaFxPackager, artifactFileName, artifact.getName(), tempDirPath, true);
for (JavaFxAntGenerator.SimpleTag tag : tags) {
buildTags(generator, tag);
}