mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-22 06:21:25 +07:00
javafx: build artifacts with same ant (IDEA-104029; IDEA-104105)
(cherry picked from commit f99076ddc25b18851ce49262281d01dfef0ca24c)
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.javaFX.packaging;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -22,8 +23,8 @@ import com.intellij.util.Base64Converter;
|
||||
import com.intellij.util.PathUtilRt;
|
||||
import com.intellij.util.io.ZipUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -65,7 +66,7 @@ public abstract class AbstractJavaFxPackager {
|
||||
protected abstract void registerJavaFxPackagerError(final String message);
|
||||
|
||||
|
||||
public void createJarAndDeploy(final String binPath) {
|
||||
public void buildJavaFxArtifact(final String homePath) {
|
||||
if (!checkNotEmpty(getAppClass(), "Application class")) return;
|
||||
if (!checkNotEmpty(getWidth(), "Width")) return;
|
||||
if (!checkNotEmpty(getHeight(), "Height")) return;
|
||||
@@ -76,48 +77,55 @@ public abstract class AbstractJavaFxPackager {
|
||||
try {
|
||||
tempUnzippedArtifactOutput = FileUtil.createTempDirectory("artifact", "unzipped");
|
||||
ZipUtil.extract(new File(zipPath), tempUnzippedArtifactOutput, null);
|
||||
copyLibraries(zipPath, tempUnzippedArtifactOutput);
|
||||
}
|
||||
catch (IOException e) {
|
||||
registerJavaFxPackagerError(e);
|
||||
return;
|
||||
}
|
||||
|
||||
final List<String> commandLine = new ArrayList<String>();
|
||||
addParameter(commandLine, FileUtil.toSystemDependentName(binPath + File.separator + "javafxpackager"));
|
||||
|
||||
addParameter(commandLine, "-createJar");
|
||||
addParameter(commandLine, "-appclass");
|
||||
addParameter(commandLine, getAppClass());
|
||||
|
||||
appendPreloader(commandLine, true);
|
||||
|
||||
addParameter(commandLine, "-srcdir");
|
||||
addParameter(commandLine, tempUnzippedArtifactOutput.getPath());
|
||||
addParameter(commandLine, "-outdir");
|
||||
|
||||
final File tempDirWithJar;
|
||||
final File tempDirectory = new File(tempUnzippedArtifactOutput, "deploy");
|
||||
try {
|
||||
tempDirWithJar = FileUtil.createTempDirectory("javafxpackager", "out");
|
||||
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
buf.append("<project default=\"build artifact\">\n");
|
||||
buf.append("<taskdef resource=\"com/sun/javafx/tools/ant/antlib.xml\" uri=\"javafx:com.sun.javafx.tools.ant\" ")
|
||||
.append("classpath=\"").append(homePath).append("/lib/ant-javafx.jar\"/>\n");
|
||||
buf.append("<target name=\"build artifact\" xmlns:fx=\"javafx:com.sun.javafx.tools.ant\">");
|
||||
final String artifactFileName = getArtifactRootName();
|
||||
final String artifactName = FileUtil.getNameWithoutExtension(artifactFileName);
|
||||
final List<JavaFxAntGenerator.SimpleTag> tags =
|
||||
JavaFxAntGenerator.createJarAndDeployTasks(this, artifactFileName, artifactName, tempUnzippedArtifactOutput.getPath());
|
||||
for (JavaFxAntGenerator.SimpleTag tag : tags) {
|
||||
tag.generate(buf);
|
||||
}
|
||||
buf.append("</target>");
|
||||
buf.append("</project>");
|
||||
|
||||
final int result = startAntTarget(buf.toString(), homePath);
|
||||
if (result == 0) {
|
||||
if (isEnabledSigning()) {
|
||||
signApp(homePath + File.separator + "bin", tempDirectory);
|
||||
}
|
||||
}
|
||||
else {
|
||||
registerJavaFxPackagerError("fx:deploy task has failed.");
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
registerJavaFxPackagerError(e);
|
||||
return;
|
||||
finally {
|
||||
copyResultsToArtifactsOutput(tempDirectory);
|
||||
FileUtil.delete(tempUnzippedArtifactOutput);
|
||||
}
|
||||
addParameter(commandLine, tempDirWithJar.getPath());
|
||||
addParameter(commandLine, "-outfile");
|
||||
}
|
||||
|
||||
addParameter(commandLine, getArtifactRootName());
|
||||
addParameter(commandLine, "-v");
|
||||
|
||||
addParameter(commandLine, "-nocss2bin");
|
||||
|
||||
appendManifestProperties(commandLine);
|
||||
|
||||
final int result = startProcess(commandLine);
|
||||
if (result == 0) {
|
||||
deploy(binPath, tempDirWithJar, tempUnzippedArtifactOutput);
|
||||
} else {
|
||||
registerJavaFxPackagerError("JavaFX createJar task has failed.");
|
||||
private void copyLibraries(String zipPath, File tempUnzippedArtifactOutput) throws IOException {
|
||||
final File[] artifactFiles = new File(getArtifactOutputPath()).listFiles();
|
||||
if (artifactFiles != null) {
|
||||
for (File file : artifactFiles) {
|
||||
if (file.isFile() && !zipPath.equals(file.getPath())) {
|
||||
FileUtil.copy(file, new File(tempUnzippedArtifactOutput, file.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,91 +137,6 @@ public abstract class AbstractJavaFxPackager {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void appendPreloader(List<String> commandLine, boolean appendPreloaderJar) {
|
||||
final String preloaderClass = getPreloaderClass();
|
||||
final String preloaderJar = getPreloaderJar();
|
||||
if (!StringUtil.isEmptyOrSpaces(preloaderClass) && !StringUtil.isEmptyOrSpaces(preloaderJar)) {
|
||||
addParameter(commandLine, "-preloader");
|
||||
addParameter(commandLine, preloaderClass);
|
||||
|
||||
if (appendPreloaderJar) {
|
||||
addParameter(commandLine, "-classpath");
|
||||
addParameter(commandLine, new File(preloaderJar).getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void deploy(final String binPath,
|
||||
final File tempDirWithCreatedJar,
|
||||
final File tempUnzippedArtifactOutput) {
|
||||
final String artifactName = FileUtil.getNameWithoutExtension(getArtifactRootName());
|
||||
final List<String> commandLine = new ArrayList<String>();
|
||||
addParameter(commandLine, FileUtil.toSystemDependentName(binPath + File.separator + "javafxpackager"));
|
||||
|
||||
addParameter(commandLine, "-deploy");
|
||||
|
||||
appendIfNotEmpty(commandLine, "-title", getTitle());
|
||||
appendIfNotEmpty(commandLine, "-vendor", getVendor());
|
||||
appendIfNotEmpty(commandLine, "-description", getDescription());
|
||||
|
||||
addParameter(commandLine, "-appclass");
|
||||
addParameter(commandLine, getAppClass());
|
||||
|
||||
appendPreloader(commandLine, false);
|
||||
|
||||
addParameter(commandLine, "-width");
|
||||
addParameter(commandLine, getWidth());
|
||||
addParameter(commandLine, "-height");
|
||||
addParameter(commandLine, getHeight());
|
||||
|
||||
appendIfNotEmpty(commandLine, "-htmlparamfile", getHtmlParamFile());
|
||||
appendIfNotEmpty(commandLine, "-paramfile", getParamFile());
|
||||
|
||||
addParameter(commandLine, "-updatemode");
|
||||
addParameter(commandLine, getUpdateMode());
|
||||
|
||||
addParameter(commandLine, "-name");
|
||||
addParameter(commandLine, artifactName);
|
||||
|
||||
|
||||
addParameter(commandLine, "-outdir");
|
||||
|
||||
final File tempDirectory;
|
||||
try {
|
||||
tempDirectory = FileUtil.createTempDirectory("javafxpackager", "out");
|
||||
}
|
||||
catch (IOException e) {
|
||||
registerJavaFxPackagerError(e);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
addParameter(commandLine, tempDirectory.getPath());
|
||||
|
||||
addParameter(commandLine, "-outfile");
|
||||
addParameter(commandLine, artifactName);
|
||||
|
||||
addParameter(commandLine, "-srcdir");
|
||||
addParameter(commandLine, tempDirWithCreatedJar.getPath());
|
||||
|
||||
addParameter(commandLine, "-v");
|
||||
|
||||
final int result = startProcess(commandLine);
|
||||
if (result == 0) {
|
||||
if (isEnabledSigning()) {
|
||||
signApp(binPath, tempDirectory);
|
||||
}
|
||||
} else {
|
||||
registerJavaFxPackagerError("JavaFX deploy task has failed.");
|
||||
}
|
||||
}
|
||||
finally {
|
||||
FileUtil.delete(tempUnzippedArtifactOutput);
|
||||
FileUtil.delete(new File(getArtifactOutputFilePath()));
|
||||
copyResultsToArtifactsOutput(tempDirWithCreatedJar);
|
||||
copyResultsToArtifactsOutput(tempDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
private void signApp(String binPath, File tempDirectory) {
|
||||
final boolean selfSigning = isSelfSigning();
|
||||
final int genResult = selfSigning ? genKey(binPath) : 0;
|
||||
@@ -274,14 +197,6 @@ public abstract class AbstractJavaFxPackager {
|
||||
addParameter(signCommandLine, getKeypass(selfSigning));
|
||||
}
|
||||
|
||||
|
||||
private void appendIfNotEmpty(List<String> commandLine, final String propName, String title) {
|
||||
if (!StringUtil.isEmptyOrSpaces(title)) {
|
||||
addParameter(commandLine, propName);
|
||||
addParameter(commandLine, title);
|
||||
}
|
||||
}
|
||||
|
||||
private void copyResultsToArtifactsOutput(final File tempDirectory) {
|
||||
try {
|
||||
final File resultedJar = new File(getArtifactOutputPath());
|
||||
@@ -293,23 +208,6 @@ public abstract class AbstractJavaFxPackager {
|
||||
FileUtil.delete(tempDirectory);
|
||||
}
|
||||
|
||||
private String getManifestString() {
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
final String title = getTitle();
|
||||
if (!StringUtil.isEmptyOrSpaces(title)) {
|
||||
buf.append("Implementation-Title=").append(title).append(";");
|
||||
}
|
||||
final String vendor = getVendor();
|
||||
if (!StringUtil.isEmptyOrSpaces(vendor)) {
|
||||
buf.append("Implementation-Vendor=").append(vendor).append(";");
|
||||
}
|
||||
final int lastIdx = buf.length() - 1;
|
||||
if (lastIdx > 0 && buf.charAt(lastIdx) == ';') {
|
||||
buf.deleteCharAt(lastIdx);
|
||||
}
|
||||
return buf.length() == 0 ? null : buf.toString();
|
||||
}
|
||||
|
||||
private void registerJavaFxPackagerError(Exception ex) {
|
||||
registerJavaFxPackagerError(ex.getMessage());
|
||||
}
|
||||
@@ -321,14 +219,6 @@ public abstract class AbstractJavaFxPackager {
|
||||
}
|
||||
}
|
||||
|
||||
private void appendManifestProperties(List<String> commandLine) {
|
||||
final String manifestAttr = getManifestString();
|
||||
if (manifestAttr != null) {
|
||||
addParameter(commandLine, "-manifestAttrs");
|
||||
addParameter(commandLine, manifestAttr);
|
||||
}
|
||||
}
|
||||
|
||||
private int startProcess(List<String> commands) {
|
||||
try {
|
||||
final Process process = new ProcessBuilder(commands).start();
|
||||
@@ -344,6 +234,63 @@ public abstract class AbstractJavaFxPackager {
|
||||
}
|
||||
}
|
||||
|
||||
private int startAntTarget(String buildText, String javaHome) {
|
||||
final String antHome = getAntHome();
|
||||
if (antHome == null) {
|
||||
registerJavaFxPackagerError("Bundled ant not found.");
|
||||
return -1;
|
||||
}
|
||||
final ArrayList<String> commands = new ArrayList<String>();
|
||||
commands.add(javaHome + File.separator + "bin" + File.separator + "java");
|
||||
|
||||
commands.add("-Dant.home=" + antHome);
|
||||
|
||||
commands.add("-classpath");
|
||||
commands.add(antHome + "/lib/ant.jar" + File.pathSeparator +
|
||||
antHome + "/lib/ant-launcher.jar" + File.pathSeparator +
|
||||
javaHome + "/lib/ant-javafx.jar");
|
||||
commands.add("org.apache.tools.ant.launch.Launcher");
|
||||
commands.add("-f");
|
||||
try {
|
||||
File tempFile = FileUtil.createTempFile("build", ".xml");
|
||||
tempFile.deleteOnExit();
|
||||
OutputStream outputStream = new FileOutputStream(tempFile.getAbsolutePath());
|
||||
try {
|
||||
outputStream.write(buildText.getBytes(Charset.defaultCharset()));
|
||||
}
|
||||
finally {
|
||||
outputStream.close();
|
||||
}
|
||||
commands.add(tempFile.getCanonicalPath());
|
||||
}
|
||||
catch (IOException e) {
|
||||
registerJavaFxPackagerError(e);
|
||||
return -1;
|
||||
}
|
||||
return startProcess(commands);
|
||||
}
|
||||
|
||||
private static String getAntHome() {
|
||||
final String appHome = PathManager.getHomePath();
|
||||
if (appHome == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
File antHome = new File(appHome, "lib" + File.separator + "ant");
|
||||
if (!antHome.exists()) {
|
||||
File communityAntHome = new File(appHome, "community" + File.separator + "lib" + File.separator + "ant");
|
||||
if (communityAntHome.exists()) {
|
||||
antHome = communityAntHome;
|
||||
}
|
||||
}
|
||||
|
||||
if (!antHome.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return antHome.getPath();
|
||||
}
|
||||
|
||||
private String getAlias(boolean selfSigning) {
|
||||
return selfSigning ? "jb" : getAlias();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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.jetbrains.plugins.javaFX.packaging;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 3/28/13
|
||||
*/
|
||||
public class JavaFxAntGenerator {
|
||||
public static List<SimpleTag> createJarAndDeployTasks(AbstractJavaFxPackager packager,
|
||||
String artifactFileName,
|
||||
String artifactName,
|
||||
String tempDirPath) {
|
||||
final List<SimpleTag> topLevelTagsCollector = new ArrayList<SimpleTag>();
|
||||
final String preloaderJar = packager.getPreloaderJar();
|
||||
final String preloaderClass = packager.getPreloaderClass();
|
||||
String preloaderFiles = null;
|
||||
if (!StringUtil.isEmptyOrSpaces(preloaderJar) && !StringUtil.isEmptyOrSpaces(preloaderClass)) {
|
||||
preloaderFiles = artifactName + "_preloader_files";
|
||||
topLevelTagsCollector.add(new SimpleTag("fx:fileset",
|
||||
new Pair<String, String>("id", preloaderFiles),
|
||||
new Pair<String, String>("requiredFor", "preloader"),
|
||||
new Pair<String, String>("dir", tempDirPath),
|
||||
new Pair<String, String>("includes", preloaderJar)));
|
||||
}
|
||||
|
||||
//register application
|
||||
final String appId = artifactName + "_id";
|
||||
Pair[] applicationParams = {
|
||||
new Pair<String, String>("id", appId),
|
||||
new Pair<String, String>("name", artifactName),
|
||||
new Pair<String, String>("mainClass", packager.getAppClass())
|
||||
};
|
||||
if (preloaderFiles != null) {
|
||||
applicationParams = ArrayUtil.append(applicationParams, new Pair<String, String>("preloaderClass", preloaderClass));
|
||||
}
|
||||
|
||||
final SimpleTag applicationTag = new SimpleTag("fx:application", applicationParams);
|
||||
|
||||
appendValuesFromPropertiesFile(applicationTag, packager.getHtmlParamFile(), "fx:htmlParam", false);
|
||||
//also loads fx:argument values
|
||||
appendValuesFromPropertiesFile(applicationTag, packager.getParamFile(), "fx:param", true);
|
||||
|
||||
topLevelTagsCollector.add(applicationTag);
|
||||
|
||||
//create jar task
|
||||
final SimpleTag createJarTag = new SimpleTag("fx:jar",
|
||||
new Pair<String, String>("destfile", tempDirPath + File.separator + artifactFileName));
|
||||
createJarTag.add(new SimpleTag("fx:application", new Pair<String, String>("refid", appId)));
|
||||
createJarTag.add(new SimpleTag("fileset", new Pair<String, String>("dir", tempDirPath)));
|
||||
if (preloaderFiles != null) {
|
||||
final SimpleTag createJarResourcesTag = new SimpleTag("fx:resources");
|
||||
createJarResourcesTag.add(new SimpleTag("fx:fileset", new Pair<String, String>("refid", preloaderFiles)));
|
||||
createJarTag.add(createJarResourcesTag);
|
||||
}
|
||||
topLevelTagsCollector.add(createJarTag);
|
||||
|
||||
//deploy task
|
||||
final SimpleTag deployTag = new SimpleTag("fx:deploy",
|
||||
new Pair<String, String>("width", packager.getWidth()),
|
||||
new Pair<String, String>("height", packager.getHeight()),
|
||||
new Pair<String, String>("updatemode", packager.getUpdateMode()),
|
||||
new Pair<String, String>("outdir", tempDirPath + File.separator + "deploy"),
|
||||
new Pair<String, String>("outfile", artifactName));
|
||||
deployTag.add(new SimpleTag("fx:application", new Pair<String, String>("refid", appId)));
|
||||
|
||||
final List<Pair> infoPairs = new ArrayList<Pair>();
|
||||
appendIfNotEmpty(infoPairs, "title", packager.getTitle());
|
||||
appendIfNotEmpty(infoPairs, "vendor", packager.getVendor());
|
||||
appendIfNotEmpty(infoPairs, "description", packager.getDescription());
|
||||
if (!infoPairs.isEmpty()) {
|
||||
deployTag.add(new SimpleTag("fx:info", infoPairs.toArray(new Pair[infoPairs.size()])));
|
||||
}
|
||||
|
||||
final SimpleTag deployResourcesTag = new SimpleTag("fx:resources");
|
||||
deployResourcesTag.add(new SimpleTag("fx:fileset", new Pair<String, String>("dir", tempDirPath),
|
||||
new Pair<String, String>("includes", artifactFileName)));
|
||||
if (preloaderFiles != null) {
|
||||
deployResourcesTag.add(new SimpleTag("fx:fileset", new Pair<String, String>("refid", preloaderFiles)));
|
||||
}
|
||||
|
||||
deployTag.add(deployResourcesTag);
|
||||
|
||||
topLevelTagsCollector.add(deployTag);
|
||||
return topLevelTagsCollector;
|
||||
}
|
||||
|
||||
private static void appendIfNotEmpty(final List<Pair> pairs, final String propertyName, final String propValue) {
|
||||
if (!StringUtil.isEmptyOrSpaces(propValue)) {
|
||||
pairs.add(Pair.create(propertyName, propValue));
|
||||
}
|
||||
}
|
||||
|
||||
private static void appendValuesFromPropertiesFile(final SimpleTag applicationTag,
|
||||
final String paramFile,
|
||||
final String paramTagName,
|
||||
final boolean allowNoNamed) {
|
||||
if (!StringUtil.isEmptyOrSpaces(paramFile)) {
|
||||
final Properties properties = new Properties();
|
||||
try {
|
||||
final FileInputStream paramsInputStream = new FileInputStream(new File(paramFile));
|
||||
try {
|
||||
properties.load(paramsInputStream);
|
||||
for (Object o : properties.keySet()) {
|
||||
final String propName = (String)o;
|
||||
final String propValue = properties.getProperty(propName);
|
||||
if (!StringUtil.isEmptyOrSpaces(propValue)) {
|
||||
applicationTag
|
||||
.add(new SimpleTag(paramTagName, new Pair<String, String>("name", propName), new Pair<String, String>("value", propValue)));
|
||||
}
|
||||
else if (allowNoNamed) {
|
||||
applicationTag.add(new SimpleTag("fx:argument", propName) {
|
||||
@Override
|
||||
public void generate(StringBuilder buf) {
|
||||
buf.append("<").append(getName()).append(">").append(propName).append("</").append(getName()).append(">");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
paramsInputStream.close();
|
||||
}
|
||||
}
|
||||
catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class SimpleTag {
|
||||
private final String myName;
|
||||
private final Pair[] myPairs;
|
||||
private final List<SimpleTag> mySubTags = new ArrayList<SimpleTag>();
|
||||
private final String myValue;
|
||||
|
||||
public SimpleTag(String name, Pair... pairs) {
|
||||
myName = name;
|
||||
myPairs = pairs;
|
||||
myValue = null;
|
||||
}
|
||||
|
||||
public SimpleTag(String name, String value) {
|
||||
myName = name;
|
||||
myPairs = new Pair[0];
|
||||
myValue = value;
|
||||
}
|
||||
|
||||
public void add(SimpleTag tag) {
|
||||
mySubTags.add(tag);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
public Pair[] getPairs() {
|
||||
return myPairs;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return myValue;
|
||||
}
|
||||
|
||||
public List<SimpleTag> getSubTags() {
|
||||
return mySubTags;
|
||||
}
|
||||
|
||||
public void generate(StringBuilder buf) {
|
||||
buf.append("<").append(getName());
|
||||
for (Pair pair : getPairs()) {
|
||||
buf.append(" ").append(pair.first).append("=\"").append(pair.second).append("\"");
|
||||
}
|
||||
buf.append(">\n");
|
||||
for (SimpleTag tag : getSubTags()) {
|
||||
tag.generate(buf);
|
||||
}
|
||||
buf.append("</").append(getName()).append(">\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
<orderEntry type="module" module-name="xml" scope="TEST" />
|
||||
<orderEntry type="module" module-name="jetgroovy" scope="TEST" />
|
||||
<orderEntry type="module" module-name="java-tests" scope="TEST" />
|
||||
<orderEntry type="module" module-name="common-javaFX-plugin" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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.jetbrains.plugins.javaFX.packaging;
|
||||
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 3/28/13
|
||||
*/
|
||||
public class JavaFxAntTaskTest extends UsefulTestCase{
|
||||
public void testJarDeployNoInfo() throws Exception {
|
||||
doTest("<fx:application id=\"jarDeployNoInfo_id\" name=\"jarDeployNoInfo\" mainClass=\"Main\">\n" +
|
||||
"</fx:application>\n" +
|
||||
"<fx:jar destfile=\"temp" + File.separator + "jarDeployNoInfo.jar\">\n" +
|
||||
"<fx:application refid=\"jarDeployNoInfo_id\">\n" +
|
||||
"</fx:application>\n" +
|
||||
"<fileset dir=\"temp\">\n" +
|
||||
"</fileset>\n" +
|
||||
"</fx:jar>\n" +
|
||||
"<fx:deploy width=\"800\" height=\"400\" updatemode=\"background\" outdir=\"temp" + File.separator + "deploy\" outfile=\"jarDeployNoInfo\">\n" +
|
||||
"<fx:application refid=\"jarDeployNoInfo_id\">\n" +
|
||||
"</fx:application>\n" +
|
||||
"<fx:resources>\n" +
|
||||
"<fx:fileset dir=\"temp\" includes=\"jarDeployNoInfo.jar\">\n" +
|
||||
"</fx:fileset>\n" +
|
||||
"</fx:resources>\n" +
|
||||
"</fx:deploy>\n", Collections.<String, String>emptyMap());
|
||||
}
|
||||
|
||||
public void testJarDeployTitle() throws Exception {
|
||||
doTest("<fx:application id=\"jarDeployTitle_id\" name=\"jarDeployTitle\" mainClass=\"Main\">\n" +
|
||||
"</fx:application>\n" +
|
||||
"<fx:jar destfile=\"temp" + File.separator + "jarDeployTitle.jar\">\n" +
|
||||
"<fx:application refid=\"jarDeployTitle_id\">\n" +
|
||||
"</fx:application>\n" +
|
||||
"<fileset dir=\"temp\">\n" +
|
||||
"</fileset>\n" +
|
||||
"</fx:jar>\n" +
|
||||
"<fx:deploy width=\"800\" height=\"400\" updatemode=\"background\" outdir=\"temp" + File.separator + "deploy\" outfile=\"jarDeployTitle\">\n" +
|
||||
"<fx:application refid=\"jarDeployTitle_id\">\n" +
|
||||
"</fx:application>\n" +
|
||||
"<fx:info title=\"My App\">\n" +
|
||||
"</fx:info>\n" +
|
||||
"<fx:resources>\n" +
|
||||
"<fx:fileset dir=\"temp\" includes=\"jarDeployTitle.jar\">\n" +
|
||||
"</fx:fileset>\n" +
|
||||
"</fx:resources>\n" +
|
||||
"</fx:deploy>\n", Collections.singletonMap("title", "My App"));
|
||||
}
|
||||
|
||||
private void doTest(final String expected, Map<String, String> options) {
|
||||
final String artifactName = getTestName(true);
|
||||
final String artifactFileName = artifactName + ".jar";
|
||||
final MockJavaFxPackager packager = new MockJavaFxPackager(artifactName + File.separator + artifactFileName);
|
||||
if (options.containsKey("title")) {
|
||||
packager.setTitle(options.get("title"));
|
||||
}
|
||||
|
||||
final List<JavaFxAntGenerator.SimpleTag> temp = JavaFxAntGenerator
|
||||
.createJarAndDeployTasks(packager, artifactFileName, artifactName, "temp");
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
for (JavaFxAntGenerator.SimpleTag tag : temp) {
|
||||
tag.generate(buf);
|
||||
}
|
||||
assertEquals(expected, buf.toString());
|
||||
}
|
||||
|
||||
private static class MockJavaFxPackager extends AbstractJavaFxPackager {
|
||||
|
||||
private String myOutputPath;
|
||||
private String myTitle;
|
||||
private String myVendor;
|
||||
private String myDescription;
|
||||
private String myHtmlParams;
|
||||
private String myParams;
|
||||
private String myPreloaderClass;
|
||||
private String myPreloaderJar;
|
||||
|
||||
private MockJavaFxPackager(String outputPath) {
|
||||
myOutputPath = outputPath;
|
||||
}
|
||||
|
||||
private void setTitle(String title) {
|
||||
myTitle = title;
|
||||
}
|
||||
|
||||
private void setVendor(String vendor) {
|
||||
myVendor = vendor;
|
||||
}
|
||||
|
||||
private void setDescription(String description) {
|
||||
myDescription = description;
|
||||
}
|
||||
|
||||
private void setHtmlParams(String htmlParams) {
|
||||
myHtmlParams = htmlParams;
|
||||
}
|
||||
|
||||
private void setParams(String params) {
|
||||
myParams = params;
|
||||
}
|
||||
|
||||
private void setPreloaderClass(String preloaderClass) {
|
||||
myPreloaderClass = preloaderClass;
|
||||
}
|
||||
|
||||
private void setPreloaderJar(String preloaderJar) {
|
||||
myPreloaderJar = preloaderJar;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getArtifactOutputPath() {
|
||||
return new File(myOutputPath).getParent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getArtifactOutputFilePath() {
|
||||
return myOutputPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAppClass() {
|
||||
return "Main";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTitle() {
|
||||
return myTitle;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getVendor() {
|
||||
return myVendor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDescription() {
|
||||
return myDescription;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getWidth() {
|
||||
return "800";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getHeight() {
|
||||
return "400";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getHtmlParamFile() {
|
||||
return myHtmlParams;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getParamFile() {
|
||||
return myParams;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getUpdateMode() {
|
||||
return JavaFxPackagerConstants.UPDATE_MODE_BACKGROUND;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerJavaFxPackagerError(String message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String prepareParam(String param) {
|
||||
return param;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKeypass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStorepass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKeystore() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlias() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelfSigning() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabledSigning() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreloaderClass() {
|
||||
return myPreloaderClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreloaderJar() {
|
||||
return myPreloaderJar;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class JpsJavaFxArtifactBuildTaskProvider extends ArtifactBuildTaskProvide
|
||||
context.processMessage(new CompilerMessage(COMPILER_NAME, BuildMessage.Kind.ERROR, "Java version 7 or higher is required to build JavaFX package"));
|
||||
return;
|
||||
}
|
||||
new JpsJavaFxPackager(myProps, context, myArtifact).createJarAndDeploy(javaSdk.getHomePath() + File.separator + "bin");
|
||||
new JpsJavaFxPackager(myProps, context, myArtifact).buildJavaFxArtifact(javaSdk.getHomePath());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,12 +101,16 @@ public class JavaFxArtifactProperties extends ArtifactProperties<JavaFxArtifactP
|
||||
return;
|
||||
}
|
||||
|
||||
final String binPath = ((JavaSdk)fxCompatibleSdk.getSdkType()).getBinPath(fxCompatibleSdk);
|
||||
|
||||
final JavaFxArtifactProperties properties =
|
||||
(JavaFxArtifactProperties)artifact.getProperties(JavaFxArtifactPropertiesProvider.getInstance());
|
||||
|
||||
new JavaFxPackager(artifact, properties, compileContext).createJarAndDeploy(binPath);
|
||||
|
||||
final JavaFxPackager javaFxPackager = new JavaFxPackager(artifact, properties, project) {
|
||||
@Override
|
||||
protected void registerJavaFxPackagerError(String message) {
|
||||
compileContext.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
|
||||
}
|
||||
};
|
||||
javaFxPackager.buildJavaFxArtifact(fxCompatibleSdk.getHomePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -277,15 +281,15 @@ public class JavaFxArtifactProperties extends ArtifactProperties<JavaFxArtifactP
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class JavaFxPackager extends AbstractJavaFxPackager {
|
||||
public static abstract class JavaFxPackager extends AbstractJavaFxPackager {
|
||||
private final Artifact myArtifact;
|
||||
private final JavaFxArtifactProperties myProperties;
|
||||
private final CompileContext myCompileContext;
|
||||
private final Project myProject;
|
||||
|
||||
public JavaFxPackager(Artifact artifact, JavaFxArtifactProperties properties, CompileContext compileContext) {
|
||||
public JavaFxPackager(Artifact artifact, JavaFxArtifactProperties properties, Project project) {
|
||||
myArtifact = artifact;
|
||||
myProperties = properties;
|
||||
myCompileContext = compileContext;
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -335,17 +339,12 @@ public class JavaFxArtifactProperties extends ArtifactProperties<JavaFxArtifactP
|
||||
|
||||
@Override
|
||||
public String getPreloaderClass() {
|
||||
return myProperties.getPreloaderClass(myArtifact, myCompileContext.getProject());
|
||||
return myProperties.getPreloaderClass(myArtifact, myProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreloaderJar() {
|
||||
return myProperties.getPreloaderJar(myArtifact, myCompileContext.getProject());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerJavaFxPackagerError(String message) {
|
||||
myCompileContext.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
|
||||
return myProperties.getPreloaderJar(myArtifact, myProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.intellij.openapi.projectRoots.JavaSdkType;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.packaging.artifacts.ArtifactManager;
|
||||
import com.intellij.packaging.artifacts.ArtifactType;
|
||||
@@ -34,18 +33,14 @@ import com.intellij.util.Base64Converter;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.javaFX.packaging.JavaFxApplicationArtifactType;
|
||||
import org.jetbrains.plugins.javaFX.packaging.JavaFxArtifactProperties;
|
||||
import org.jetbrains.plugins.javaFX.packaging.JavaFxArtifactPropertiesProvider;
|
||||
import org.jetbrains.plugins.javaFX.packaging.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
@@ -141,71 +136,17 @@ public class JavaFxChunkBuildExtension extends ChunkBuildExtension {
|
||||
final JavaFxArtifactProperties properties =
|
||||
(JavaFxArtifactProperties)artifact.getProperties(JavaFxArtifactPropertiesProvider.getInstance());
|
||||
|
||||
String preloaderFiles = null;
|
||||
final String preloaderJar = properties.getPreloaderJar(artifact, context.getProject());
|
||||
final String preloaderClass = properties.getPreloaderClass(artifact, context.getProject());
|
||||
if (!StringUtil.isEmptyOrSpaces(preloaderJar) && !StringUtil.isEmptyOrSpaces(preloaderClass)) {
|
||||
preloaderFiles = artifactName + "_preloader_files";
|
||||
generator.add(new Tag("fx:fileset",
|
||||
new Pair<String, String>("id", preloaderFiles),
|
||||
new Pair<String, String>("requiredFor", "preloader"),
|
||||
new Pair<String, String>("dir", tempDirPath),
|
||||
new Pair<String, String>("includes", preloaderJar)));
|
||||
final JavaFxArtifactProperties.JavaFxPackager javaFxPackager =
|
||||
new JavaFxArtifactProperties.JavaFxPackager(artifact, properties, context.getProject()) {
|
||||
@Override
|
||||
protected void registerJavaFxPackagerError(String message) {}
|
||||
};
|
||||
final List<JavaFxAntGenerator.SimpleTag> tags =
|
||||
JavaFxAntGenerator.createJarAndDeployTasks(javaFxPackager, artifactFileName, artifactName, tempDirPath);
|
||||
for (JavaFxAntGenerator.SimpleTag tag : tags) {
|
||||
buildTags(generator, tag);
|
||||
}
|
||||
|
||||
//register application
|
||||
final String appId = artifactName + "_id";
|
||||
Pair[] applicationParams = {new Pair<String, String>("id", appId),
|
||||
new Pair<String, String>("name", artifactName),
|
||||
new Pair<String, String>("mainClass", properties.getAppClass())};
|
||||
if (preloaderFiles != null) {
|
||||
applicationParams = ArrayUtil.append(applicationParams, new Pair<String, String>("preloaderClass", preloaderClass));
|
||||
}
|
||||
|
||||
final Tag applicationTag = new Tag("fx:application", applicationParams);
|
||||
|
||||
appendValuesFromPropertiesFile(applicationTag, properties.getHtmlParamFile(), "fx:htmlParam", false);
|
||||
//also loads fx:argument values
|
||||
appendValuesFromPropertiesFile(applicationTag, properties.getParamFile(), "fx:param", true);
|
||||
|
||||
generator.add(applicationTag);
|
||||
|
||||
//create jar task
|
||||
final Tag createJarTag = new Tag("fx:jar",
|
||||
new Pair<String, String>("destfile", tempDirPath + "/" + artifactFileName));
|
||||
createJarTag.add(new Tag("fx:application", new Pair<String, String>("refid", appId)));
|
||||
createJarTag.add(new Tag("fileset", new Pair<String, String>("dir", tempDirPath)));
|
||||
if (preloaderFiles != null) {
|
||||
final Tag createJarResourcesTag = new Tag("fx:resources");
|
||||
createJarResourcesTag.add(new Tag("fx:fileset", new Pair<String, String>("refid", preloaderFiles)));
|
||||
createJarTag.add(createJarResourcesTag);
|
||||
}
|
||||
generator.add(createJarTag);
|
||||
|
||||
//deploy task
|
||||
final Tag deployTag = new Tag("fx:deploy",
|
||||
new Pair<String, String>("width", properties.getWidth()),
|
||||
new Pair<String, String>("height", properties.getHeight()),
|
||||
new Pair<String, String>("updatemode", properties.getUpdateMode()),
|
||||
new Pair<String, String>("outdir", tempDirPath + "/deploy"),
|
||||
new Pair<String, String>("outfile", artifactName));
|
||||
deployTag.add(new Tag("fx:application", new Pair<String, String>("refid", appId)));
|
||||
|
||||
deployTag.add(new Tag("fx:info",
|
||||
new Pair<String, String>("title", properties.getTitle()),
|
||||
new Pair<String, String>("vendor", properties.getVendor()),
|
||||
new Pair<String, String>("description", properties.getDescription())));
|
||||
final Tag deployResourcesTag = new Tag("fx:resources");
|
||||
deployResourcesTag.add(new Tag("fx:fileset", new Pair<String, String>("dir", tempDirPath),
|
||||
new Pair<String, String>("includes", artifactFileName)));
|
||||
if (preloaderFiles != null) {
|
||||
deployResourcesTag.add(new Tag("fx:fileset", new Pair<String, String>("refid", preloaderFiles)));
|
||||
}
|
||||
|
||||
deployTag.add(deployResourcesTag);
|
||||
|
||||
generator.add(deployTag);
|
||||
|
||||
if (properties.isEnabledSigning()) {
|
||||
|
||||
final boolean selfSigning = properties.isSelfSigning();
|
||||
@@ -248,38 +189,23 @@ public class JavaFxChunkBuildExtension extends ChunkBuildExtension {
|
||||
generator.add(deleteTag);
|
||||
}
|
||||
|
||||
private static void appendValuesFromPropertiesFile(final Tag applicationTag,
|
||||
final String htmlParamFile,
|
||||
final String paramTagName,
|
||||
final boolean allowNoNamed) {
|
||||
if (!StringUtil.isEmptyOrSpaces(htmlParamFile)) {
|
||||
final Properties htmlProperties = new Properties();
|
||||
try {
|
||||
final FileInputStream paramsInputStream = new FileInputStream(new File(htmlParamFile));
|
||||
try {
|
||||
htmlProperties.load(paramsInputStream);
|
||||
for (Object o : htmlProperties.keySet()) {
|
||||
final String propName = (String)o;
|
||||
final String propValue = htmlProperties.getProperty(propName);
|
||||
if (!StringUtil.isEmptyOrSpaces(propValue)) {
|
||||
applicationTag.add(new Tag(paramTagName, new Pair<String, String>("name", propName), new Pair<String, String>("value", propValue)));
|
||||
} else if (allowNoNamed) {
|
||||
applicationTag.add(new Generator() {
|
||||
@Override
|
||||
public void generate(PrintWriter out) throws IOException {
|
||||
out.print("<fx:argument>" + propName + "</fx:argument>");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
paramsInputStream.close();
|
||||
private static void buildTags(CompositeGenerator generator, final JavaFxAntGenerator.SimpleTag tag) {
|
||||
final Tag newTag = new Tag(tag.getName(), tag.getPairs()){
|
||||
@Override
|
||||
public void generate(PrintWriter out) throws IOException {
|
||||
final String value = tag.getValue();
|
||||
if (value == null) {
|
||||
super.generate(out);
|
||||
} else {
|
||||
out.print("<" + tag.getName() + ">" + value + "</" + tag.getName() + ">");
|
||||
}
|
||||
}
|
||||
catch (IOException ignore) {
|
||||
}
|
||||
};
|
||||
|
||||
for (JavaFxAntGenerator.SimpleTag simpleTag : tag.getSubTags()) {
|
||||
buildTags(newTag, simpleTag);
|
||||
}
|
||||
generator.add(newTag);
|
||||
}
|
||||
|
||||
private static String artifactBasedProperty(final String property, String artifactName) {
|
||||
|
||||
Reference in New Issue
Block a user