javafx jps packaging

(cherry picked from commit a14343caa4b12601c57392441fcc75c829b684b6)
This commit is contained in:
anna
2013-03-15 21:52:39 +01:00
parent 825ebc8b6c
commit 0d9a3f3e70
21 changed files with 664 additions and 261 deletions
+2
View File
@@ -26,6 +26,7 @@
<module fileurl="file://$PROJECT_DIR$/plugins/commander/commander.iml" filepath="$PROJECT_DIR$/plugins/commander/commander.iml" group="plugins" />
<module fileurl="file://$PROJECT_DIR$/plugins/eclipse/common-eclipse-util/common-eclipse-util.iml" filepath="$PROJECT_DIR$/plugins/eclipse/common-eclipse-util/common-eclipse-util.iml" group="plugins" />
<module fileurl="file://$PROJECT_DIR$/community-main.iml" filepath="$PROJECT_DIR$/community-main.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/javaFX/common-javaFX-plugin/common-javaFX-plugin.iml" filepath="$PROJECT_DIR$/plugins/javaFX/common-javaFX-plugin/common-javaFX-plugin.iml" group="community/plugins" />
<module fileurl="file://$PROJECT_DIR$/community-resources/community-resources.iml" filepath="$PROJECT_DIR$/community-resources/community-resources.iml" />
<module fileurl="file://$PROJECT_DIR$/java/compiler/impl/compiler-impl.iml" filepath="$PROJECT_DIR$/java/compiler/impl/compiler-impl.iml" group="java/compiler" />
<module fileurl="file://$PROJECT_DIR$/java/compiler/openapi/compiler-openapi.iml" filepath="$PROJECT_DIR$/java/compiler/openapi/compiler-openapi.iml" group="java/compiler" />
@@ -75,6 +76,7 @@
<module fileurl="file://$PROJECT_DIR$/java/java-tests/java-tests.iml" filepath="$PROJECT_DIR$/java/java-tests/java-tests.iml" group="java" />
<module fileurl="file://$PROJECT_DIR$/plugins/javaFX/javaFX.iml" filepath="$PROJECT_DIR$/plugins/javaFX/javaFX.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/javaFX/javaFX-CE/javaFX-CE.iml" filepath="$PROJECT_DIR$/plugins/javaFX/javaFX-CE/javaFX-CE.iml" group="community/plugins" />
<module fileurl="file://$PROJECT_DIR$/plugins/javaFX/javaFX-jps-plugin/javaFX-jps-plugin.iml" filepath="$PROJECT_DIR$/plugins/javaFX/javaFX-jps-plugin/javaFX-jps-plugin.iml" />
<module fileurl="file://$PROJECT_DIR$/java/compiler/javac2/javac2.iml" filepath="$PROJECT_DIR$/java/compiler/javac2/javac2.iml" group="java/compiler" />
<module fileurl="file://$PROJECT_DIR$/plugins/cvs/javacvs-src/javacvs-src.iml" filepath="$PROJECT_DIR$/plugins/cvs/javacvs-src/javacvs-src.iml" group="plugins/VCS/cvs" />
<module fileurl="file://$PROJECT_DIR$/plugins/groovy/jetgroovy.iml" filepath="$PROJECT_DIR$/plugins/groovy/jetgroovy.iml" group="plugins/Groovy" />
+6
View File
@@ -185,6 +185,12 @@ def layoutFull(String home, String targetDirectory, String patchedDescriptorDir
module("javaFX")
module("javaFX-CE")
}
jar("javaFX-jps-plugin.jar") {
module("javaFX-jps-plugin")
}
jar("common-javaFX-plugin.jar") {
module("common-javaFX-plugin")
}
}
}
}
+1
View File
@@ -96,6 +96,7 @@
<orderEntry type="module" module-name="ui-designer-jps-plugin" scope="TEST" />
<orderEntry type="module" module-name="colorSchemes" />
<orderEntry type="module" module-name="javaFX-CE" />
<orderEntry type="module" module-name="javaFX-jps-plugin" />
</component>
</module>
@@ -16,6 +16,7 @@
package org.jetbrains.jps.incremental;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.Nullable;
@@ -46,6 +47,25 @@ public class ExternalProcessUtil {
}
}
private static final char QUOTE = '\uEFEF';
// please keep in sync with GeneralCommandLine.prepareCommand()
public static String prepareCommand(String parameter) {
if (SystemInfo.isWindows) {
if (parameter.contains("\"")) {
parameter = StringUtil.replace(parameter, "\"", "\\\"");
}
else if (parameter.length() == 0) {
parameter = "\"\"";
}
}
if (parameter.length() >= 2 && parameter.charAt(0) == QUOTE && parameter.charAt(parameter.length() - 1) == QUOTE) {
parameter = '"' + parameter.substring(1, parameter.length() - 1) + '"';
}
return parameter;
}
public static List<String> buildJavaCommandLine(String javaExecutable,
String mainClass,
List<String> bootClasspath,
@@ -262,8 +262,8 @@ public class GeneralCommandLine implements UserDataHolder {
return result;
}
// please keep in sync with com.intellij.rt.execution.junit.ProcessBuilder.prepareCommand()
private static String prepareCommand(String parameter) {
// please keep in sync with com.intellij.rt.execution.junit.ProcessBuilder.prepareCommand() && org.jetbrains.jps.incremental.ExternalProcessUtil.prepareCommand()
public static String prepareCommand(String parameter) {
if (SystemInfo.isWindows) {
if (parameter.contains("\"")) {
parameter = StringUtil.replace(parameter, "\"", "\\\"");
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="util" />
</component>
</module>
@@ -0,0 +1,214 @@
/*
* 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.diagnostic.Logger;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.io.ZipUtil;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* User: anna
* Date: 3/12/13
*/
public abstract class AbstractJavaFxPackager {
private static final Logger LOG = Logger.getInstance("#" + AbstractJavaFxPackager.class.getName());
//artifact description
protected abstract String getArtifactName();
protected abstract String getArtifactOutputPath();
protected abstract String getArtifactOutputFilePath();
//artifact properties
protected abstract String getAppClass();
protected abstract String getTitle();
protected abstract String getVendor();
protected abstract String getDescription();
protected abstract void registerJavaFxPackagerError(final String message);
public void createJarAndDeploy(final String binPath) {
final String zipPath = getArtifactOutputFilePath();
final File tempUnzippedArtifactOutput;
try {
tempUnzippedArtifactOutput = FileUtil.createTempDirectory("artifact", "unzipped");
ZipUtil.extract(new File(zipPath), tempUnzippedArtifactOutput, null);
}
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());
addParameter(commandLine, "-srcdir");
addParameter(commandLine, tempUnzippedArtifactOutput.getPath());
addParameter(commandLine, "-outdir");
final File tempDirWithJar;
try {
tempDirWithJar = FileUtil.createTempDirectory("javafxpackager", "out");
}
catch (IOException e) {
registerJavaFxPackagerError(e);
return;
}
addParameter(commandLine, tempDirWithJar.getPath());
addParameter(commandLine, "-outfile");
addParameter(commandLine, getArtifactName());
addParameter(commandLine, "-v");
addParameter(commandLine, "-nocss2bin");
appendManifestProperties(commandLine);
final int result = startProcess(commandLine);
if (result == 0) {
deploy(binPath, tempDirWithJar, tempUnzippedArtifactOutput);
}
}
private void deploy(String binPath,
final File tempDirWithCreatedJar,
final File tempUnzippedArtifactOutput) {
final List<String> commandLine = new ArrayList<String>();
addParameter(commandLine, FileUtil.toSystemDependentName(binPath + File.separator + "javafxpackager"));
addParameter(commandLine, "-deploy");
final String title = getTitle();
if (!StringUtil.isEmptyOrSpaces(title)) {
addParameter(commandLine, "-title");
addParameter(commandLine, title);
}
final String vendor = getVendor();
if (!StringUtil.isEmptyOrSpaces(vendor)) {
addParameter(commandLine, "-vendor");
addParameter(commandLine, vendor);
}
final String description = getDescription();
if (!StringUtil.isEmptyOrSpaces(description)) {
addParameter(commandLine, "-description");
addParameter(commandLine, description);
}
addParameter(commandLine, "-appclass");
addParameter(commandLine, getAppClass());
addParameter(commandLine, "-width");
addParameter(commandLine, "600");
addParameter(commandLine, "-height");
addParameter(commandLine, "400");
addParameter(commandLine, "-name");
addParameter(commandLine, getArtifactName());
addParameter(commandLine, "-outdir");
final File tempDirectory;
try {
tempDirectory = FileUtil.createTempDirectory("javafxpackager", "out");
}
catch (IOException e) {
registerJavaFxPackagerError(e);
return;
}
addParameter(commandLine, tempDirectory.getPath());
addParameter(commandLine, "-outfile");
addParameter(commandLine, getArtifactName());
addParameter(commandLine, "-srcdir");
addParameter(commandLine, tempDirWithCreatedJar.getPath());
addParameter(commandLine, "-v");
final int result = startProcess(commandLine);
FileUtil.delete(tempUnzippedArtifactOutput);
FileUtil.delete(new File(getArtifactOutputFilePath()));
copyResultsToArtifactsOutput(tempDirectory);
copyResultsToArtifactsOutput(tempDirWithCreatedJar);
}
private void copyResultsToArtifactsOutput(final File tempDirectory) {
try {
final File resultedJar = new File(getArtifactOutputPath());
FileUtil.copyDir(tempDirectory, resultedJar);
}
catch (IOException e) {
LOG.info(e);
}
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());
}
protected void addParameter(List<String> commandLine, String param) {
commandLine.add(param);
}
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();
return process.waitFor();
}
catch (Exception e) {
registerJavaFxPackagerError(e);
return -1;
}
}
}
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="jps-builders" />
<orderEntry type="module" module-name="jps-model-api" />
<orderEntry type="module" module-name="jps-model-serialization" />
<orderEntry type="module" module-name="common-javaFX-plugin" />
</component>
</module>
@@ -0,0 +1 @@
org.jetbrains.plugins.javaFX.JpsJavaFxArtifactBuildTaskProvider
@@ -0,0 +1 @@
org.jetbrains.plugins.javaFX.JavaFxBuilderService
@@ -0,0 +1 @@
org.jetbrains.plugins.javaFX.JpsJavaFxModelSerializerExtension
@@ -0,0 +1,19 @@
package org.jetbrains.plugins.javaFX;
import org.jetbrains.jps.builders.BuildTargetType;
import org.jetbrains.jps.incremental.BuilderService;
import org.jetbrains.jps.incremental.artifacts.ArtifactBuildTargetType;
import java.util.Arrays;
import java.util.List;
/**
* User: anna
* Date: 3/13/13
*/
public class JavaFxBuilderService extends BuilderService {
@Override
public List<? extends BuildTargetType<?>> getTargetTypes() {
return Arrays.<BuildTargetType<?>>asList(ArtifactBuildTargetType.INSTANCE);
}
}
@@ -0,0 +1,11 @@
package org.jetbrains.plugins.javaFX;
import org.jetbrains.jps.model.artifact.JpsArtifactType;
/**
* User: anna
* Date: 3/13/13
*/
public class JpsJavaFxApplicationArtifactType extends JpsArtifactType<JpsJavaFxArtifactProperties> {
public static final JpsJavaFxApplicationArtifactType INSTANCE = new JpsJavaFxApplicationArtifactType();
}
@@ -0,0 +1,138 @@
package org.jetbrains.plugins.javaFX;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.builders.artifacts.ArtifactBuildTaskProvider;
import org.jetbrains.jps.incremental.BuildTask;
import org.jetbrains.jps.incremental.CompileContext;
import org.jetbrains.jps.incremental.ExternalProcessUtil;
import org.jetbrains.jps.incremental.ProjectBuildException;
import org.jetbrains.jps.incremental.messages.BuildMessage;
import org.jetbrains.jps.incremental.messages.CompilerMessage;
import org.jetbrains.jps.model.JpsElement;
import org.jetbrains.jps.model.artifact.JpsArtifact;
import org.jetbrains.jps.model.java.JpsJavaSdkType;
import org.jetbrains.jps.model.library.sdk.JpsSdk;
import org.jetbrains.jps.model.library.sdk.JpsSdkType;
import org.jetbrains.plugins.javaFX.packaging.AbstractJavaFxPackager;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Set;
/**
* User: anna
* Date: 3/13/13
*/
public class JpsJavaFxArtifactBuildTaskProvider extends ArtifactBuildTaskProvider {
public static final String COMPILER_NAME = "Java FX Packager";
@NotNull
@Override
public List<? extends BuildTask> createArtifactBuildTasks(@NotNull JpsArtifact artifact,
@NotNull ArtifactBuildPhase buildPhase) {
if (buildPhase != ArtifactBuildPhase.POST_PROCESSING) {
return Collections.emptyList();
}
if (!(artifact.getArtifactType() instanceof JpsJavaFxApplicationArtifactType)) {
return Collections.emptyList();
}
final JpsElement props = artifact.getProperties();
if (!(props instanceof JpsJavaFxArtifactProperties)) {
return Collections.emptyList();
}
return Collections.singletonList(new JavaFxJarDeployTask((JpsJavaFxArtifactProperties)props, artifact));
}
private static class JavaFxJarDeployTask extends BuildTask {
private final JpsJavaFxArtifactProperties myProps;
private final JpsArtifact myArtifact;
public JavaFxJarDeployTask(JpsJavaFxArtifactProperties props, JpsArtifact artifact) {
myProps = props;
myArtifact = artifact;
}
@Override
public void build(CompileContext context) throws ProjectBuildException {
final Set<JpsSdk<?>> sdks = context.getProjectDescriptor().getProjectJavaSdks();
JpsSdk javaSdk = null;
for (JpsSdk<?> sdk : sdks) {
final JpsSdkType<? extends JpsElement> sdkType = sdk.getSdkType();
if (sdkType instanceof JpsJavaSdkType) {
javaSdk = sdk;
break;
}
}
if (javaSdk == null) {
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");
}
}
private static class JpsJavaFxPackager extends AbstractJavaFxPackager {
private final JpsJavaFxArtifactProperties myProperties;
private final CompileContext myCompileContext;
private final JpsArtifact myArtifact;
public JpsJavaFxPackager(JpsJavaFxArtifactProperties properties, CompileContext compileContext, JpsArtifact artifact) {
myArtifact = artifact;
myProperties = properties;
myCompileContext = compileContext;
}
@Override
protected String getArtifactName() {
return myArtifact.getName();
}
@Override
protected String getArtifactOutputPath() {
return myArtifact.getOutputPath();
}
@Override
protected String getArtifactOutputFilePath() {
return myArtifact.getOutputFilePath();
}
@Override
protected String getAppClass() {
return myProperties.myState.getAppClass();
}
@Override
protected String getTitle() {
return myProperties.myState.getTitle();
}
@Override
protected String getVendor() {
return myProperties.myState.getVendor();
}
@Override
protected String getDescription() {
return myProperties.myState.getDescription();
}
@Override
protected void registerJavaFxPackagerError(String message) {
myCompileContext.processMessage(new CompilerMessage(COMPILER_NAME, BuildMessage.Kind.ERROR, message));
}
@Override
protected void addParameter(List<String> commandLine, String param) {
super.addParameter(commandLine, ExternalProcessUtil.prepareCommand(param));
}
}
}
@@ -0,0 +1,76 @@
package org.jetbrains.plugins.javaFX;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.ex.JpsElementBase;
/**
* User: anna
* Date: 3/13/13
*/
public class JpsJavaFxArtifactProperties extends JpsElementBase<JpsJavaFxArtifactProperties> {
protected MyState myState = new MyState();
public JpsJavaFxArtifactProperties() {
}
public JpsJavaFxArtifactProperties(MyState state) {
copyState(state);
}
private void copyState(MyState state) {
myState.setAppClass(state.myAppClass);
myState.setTitle(state.myTitle);
myState.setVendor(state.myVendor);
myState.setDescription(state.myDescription);
}
@NotNull
@Override
public JpsJavaFxArtifactProperties createCopy() {
return new JpsJavaFxArtifactProperties(myState);
}
@Override
public void applyChanges(@NotNull JpsJavaFxArtifactProperties modified) {
copyState(modified.myState);
}
public static class MyState {
private String myTitle;
private String myVendor;
private String myDescription;
private String myAppClass;
public String getTitle() {
return myTitle;
}
public void setTitle(String title) {
myTitle = title;
}
public String getVendor() {
return myVendor;
}
public void setVendor(String vendor) {
myVendor = vendor;
}
public String getDescription() {
return myDescription;
}
public void setDescription(String description) {
myDescription = description;
}
public String getAppClass() {
return myAppClass;
}
public void setAppClass(String appClass) {
myAppClass = appClass;
}
}
}
@@ -0,0 +1,62 @@
package org.jetbrains.plugins.javaFX;
import com.intellij.util.xmlb.XmlSerializer;
import org.jdom.Element;
import org.jetbrains.jps.model.serialization.artifact.ArtifactPropertiesState;
import org.jetbrains.jps.model.serialization.artifact.JpsArtifactPropertiesSerializer;
import java.util.List;
/**
* User: anna
* Date: 3/13/13
*/
public class JpsJavaFxArtifactPropertiesSerializer extends JpsArtifactPropertiesSerializer<JpsJavaFxArtifactProperties> {
public JpsJavaFxArtifactPropertiesSerializer() {
super("javafx", JpsJavaFxApplicationArtifactType.INSTANCE);
}
@Override
public JpsJavaFxArtifactProperties loadProperties(List<ArtifactPropertiesState> stateList) {
final JpsJavaFxArtifactProperties.MyState properties = doLoadProperties(stateList);
return properties != null ? new JpsJavaFxArtifactProperties(properties) : new JpsJavaFxArtifactProperties();
}
private static JpsJavaFxArtifactProperties.MyState doLoadProperties(List<ArtifactPropertiesState> stateList) {
final ArtifactPropertiesState state = findApplicationProperties(stateList);
if (state == null) {
return null;
}
final Element options = state.getOptions();
if (options == null) {
return null;
}
return XmlSerializer.deserialize(options, JpsJavaFxArtifactProperties.MyState.class);
}
@Override
public void saveProperties(JpsJavaFxArtifactProperties properties, List<ArtifactPropertiesState> stateList) {
final ArtifactPropertiesState state = findApplicationProperties(stateList);
if (state == null) {
return;
}
final Element element = XmlSerializer.serialize(properties);
if (element == null) {
return;
}
state.setOptions(element);
}
private static ArtifactPropertiesState findApplicationProperties(List<ArtifactPropertiesState> stateList) {
for (ArtifactPropertiesState state : stateList) {
if ("javafx-properties".equals(state.getId())) {
return state;
}
}
return null;
}
}
@@ -0,0 +1,18 @@
package org.jetbrains.plugins.javaFX;
import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension;
import org.jetbrains.jps.model.serialization.artifact.JpsArtifactPropertiesSerializer;
import java.util.Collections;
import java.util.List;
/**
* User: anna
* Date: 3/13/13
*/
public class JpsJavaFxModelSerializerExtension extends JpsModelSerializerExtension {
@Override
public List<? extends JpsArtifactPropertiesSerializer<?>> getArtifactTypePropertiesSerializers() {
return Collections.singletonList(new JpsJavaFxArtifactPropertiesSerializer());
}
}
+1
View File
@@ -20,6 +20,7 @@
<orderEntry type="module" module-name="openapi" />
<orderEntry type="module" module-name="compiler-openapi" />
<orderEntry type="module" module-name="compiler-impl" />
<orderEntry type="module" module-name="common-javaFX-plugin" />
</component>
</module>
@@ -34,6 +34,7 @@
<getterSetterProvider implementation="org.jetbrains.plugins.javaFX.codeInsight.JavaFxGetterSetterPrototypeProvider"/>
<packaging.artifactPropertiesProvider implementation="org.jetbrains.plugins.javaFX.packaging.JavaFxArtifactPropertiesProvider"/>
<packaging.artifactType implementation="org.jetbrains.plugins.javaFX.packaging.JavaFxApplicationArtifactType"/>
<compileServer.plugin classpath="javaFX-jps-plugin.jar;common-javaFX-plugin.jar"/>
</extensions>
<actions>
@@ -15,6 +15,7 @@
*/
package org.jetbrains.plugins.javaFX.packaging;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.compiler.CompileContext;
import com.intellij.openapi.compiler.CompilerMessageCategory;
@@ -36,6 +37,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Set;
/**
@@ -50,7 +52,7 @@ public class JavaFxArtifactProperties extends ArtifactProperties<JavaFxArtifactP
private String myAppClass;
@Override
public void onBuildFinished(@NotNull final Artifact artifact, @NotNull CompileContext compileContext) {
public void onBuildFinished(@NotNull final Artifact artifact, @NotNull final CompileContext compileContext) {
if (!(artifact.getArtifactType() instanceof JavaFxApplicationArtifactType)) {
return;
}
@@ -91,24 +93,7 @@ public class JavaFxArtifactProperties extends ArtifactProperties<JavaFxArtifactP
return;
}
JavaFxPackagerUtil.createJarAndDeploy(artifact, compileContext, binPath, properties);
}
@Nullable
public String getManifestString() {
final StringBuilder buf = new StringBuilder();
if (!StringUtil.isEmptyOrSpaces(myTitle)) {
buf.append("Implementation-Title=").append(myTitle).append(";");
}
if (!StringUtil.isEmptyOrSpaces(myVendor)) {
buf.append("Implementation-Vendor=").append(myVendor).append(";");
}
final int lastIdx = buf.length() - 1;
if (lastIdx > 0 && buf.charAt(lastIdx) == ';') {
buf.deleteCharAt(lastIdx);
}
return buf.length() == 0 ? null : buf.toString();
new JavaFxPackager(artifact, properties, compileContext).createJarAndDeploy(binPath);
}
@Override
@@ -158,4 +143,61 @@ public class JavaFxArtifactProperties extends ArtifactProperties<JavaFxArtifactP
public void setAppClass(String appClass) {
myAppClass = appClass;
}
private static class JavaFxPackager extends AbstractJavaFxPackager {
private final Artifact myArtifact;
private final JavaFxArtifactProperties myProperties;
private final CompileContext myCompileContext;
public JavaFxPackager(Artifact artifact, JavaFxArtifactProperties properties, CompileContext compileContext) {
myArtifact = artifact;
myProperties = properties;
myCompileContext = compileContext;
}
@Override
protected String getArtifactName() {
return myArtifact.getName();
}
@Override
protected String getArtifactOutputPath() {
return myArtifact.getOutputPath();
}
@Override
protected String getArtifactOutputFilePath() {
return myArtifact.getOutputFilePath();
}
@Override
protected String getAppClass() {
return myProperties.getAppClass();
}
@Override
protected String getTitle() {
return myProperties.getTitle();
}
@Override
protected String getVendor() {
return myProperties.getVendor();
}
@Override
protected String getDescription() {
return myProperties.getDescription();
}
@Override
protected void registerJavaFxPackagerError(String message) {
myCompileContext.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
}
@Override
protected void addParameter(List<String> commandLine, String param) {
super.addParameter(commandLine, GeneralCommandLine.prepareCommand(param));
}
}
}
@@ -1,240 +0,0 @@
/*
* 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.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.process.ProcessAdapter;
import com.intellij.execution.process.ProcessEvent;
import com.intellij.execution.process.ProcessOutputTypes;
import com.intellij.openapi.compiler.CompileContext;
import com.intellij.openapi.compiler.CompilerMessageCategory;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.packaging.artifacts.Artifact;
import com.intellij.util.io.ZipUtil;
import java.io.File;
import java.io.IOException;
/**
* User: anna
* Date: 3/12/13
*/
public class JavaFxPackagerUtil {
private static final Logger LOG = Logger.getInstance("#" + JavaFxArtifactProperties.class.getName());
public static void createJarAndDeploy(final Artifact artifact,
final CompileContext compileContext,
final String binPath,
final JavaFxArtifactProperties properties) {
final String zipPath = artifact.getOutputFilePath();
final File tempUnzippedArtifactOutput;
try {
tempUnzippedArtifactOutput = FileUtil.createTempDirectory("artifact", "unzipped");
ZipUtil.extract(new File(zipPath), tempUnzippedArtifactOutput, null);
}
catch (IOException e) {
registerJavaFxPackagerError(compileContext, e);
return;
}
final GeneralCommandLine commandLine = new GeneralCommandLine();
try {
commandLine.setExePath(binPath + File.separator + "javafxpackager");
commandLine.addParameter("-createJar");
commandLine.addParameter("-appclass");
commandLine.addParameter(properties.getAppClass());
commandLine.addParameter("-srcdir");
commandLine.addParameter(tempUnzippedArtifactOutput.getPath());
commandLine.addParameter("-outdir");
final File tempDirWithJar;
try {
tempDirWithJar = FileUtil.createTempDirectory("javafxpackager", "out");
}
catch (IOException e) {
registerJavaFxPackagerError(compileContext, e);
return;
}
commandLine.addParameter(tempDirWithJar.getPath());
commandLine.addParameter("-outfile");
commandLine.addParameter(artifact.getName());
commandLine.addParameter("-v");
commandLine.addParameter("-nocss2bin");
appendManifestProperties(commandLine, properties);
final MyOnTerminatedProcessAdapter adapter = new MyOnTerminatedProcessAdapter(compileContext) {
@Override
protected void onTerminated() {
deploy(artifact, compileContext, binPath, properties, tempDirWithJar, tempUnzippedArtifactOutput);
}
};
startProcess(commandLine, adapter);
}
catch (ExecutionException ex) {
registerJavaFxPackagerError(compileContext, ex);
}
}
private static void registerJavaFxPackagerError(CompileContext compileContext, Exception ex) {
registerJavaFxPackagerError(compileContext, ex.getMessage());
}
private static void registerJavaFxPackagerError(CompileContext compileContext, final String message) {
compileContext.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
}
private static void deploy(final Artifact artifact,
final CompileContext compileContext,
String binPath,
JavaFxArtifactProperties properties,
final File tempDirWithCreatedJar,
final File tempUnzippedArtifactOutput) {
final GeneralCommandLine commandLine = new GeneralCommandLine();
try {
commandLine.setExePath(binPath + File.separator + "javafxpackager");
commandLine.addParameter("-deploy");
final String title = properties.getTitle();
if (!StringUtil.isEmptyOrSpaces(title)) {
commandLine.addParameter("-title");
commandLine.addParameter(title);
}
final String vendor = properties.getVendor();
if (!StringUtil.isEmptyOrSpaces(vendor)) {
commandLine.addParameter("-vendor");
commandLine.addParameter(vendor);
}
final String description = properties.getDescription();
if (!StringUtil.isEmptyOrSpaces(description)) {
commandLine.addParameter("-description");
commandLine.addParameter(description);
}
commandLine.addParameter("-appclass");
commandLine.addParameter(properties.getAppClass());
commandLine.addParameter("-width");
commandLine.addParameter("600");
commandLine.addParameter("-height");
commandLine.addParameter("400");
commandLine.addParameter("-name");
commandLine.addParameter(artifact.getName());
commandLine.addParameter("-outdir");
final File tempDirectory;
try {
tempDirectory = FileUtil.createTempDirectory("javafxpackager", "out");
}
catch (IOException e) {
registerJavaFxPackagerError(compileContext, e);
return;
}
commandLine.addParameter(tempDirectory.getPath());
commandLine.addParameter("-outfile");
commandLine.addParameter(artifact.getName());
commandLine.addParameter("-srcdir");
commandLine.addParameter(tempDirWithCreatedJar.getPath());
commandLine.addParameter("-v");
final MyOnTerminatedProcessAdapter adapter = new MyOnTerminatedProcessAdapter(compileContext) {
@Override
protected void onTerminated() {
FileUtil.delete(tempUnzippedArtifactOutput);
FileUtil.delete(new File(artifact.getOutputFilePath()));
copyResultsToArtifactsOutput(tempDirectory);
copyResultsToArtifactsOutput(tempDirWithCreatedJar);
}
private void copyResultsToArtifactsOutput(final File tempDirectory) {
try {
final File resultedJar = new File(artifact.getOutputPath());
FileUtil.copyDir(tempDirectory, resultedJar);
}
catch (IOException e) {
LOG.info(e);
}
FileUtil.delete(tempDirectory);
}
};
startProcess(commandLine, adapter);
}
catch (ExecutionException ex) {
registerJavaFxPackagerError(compileContext, ex);
}
}
private static void appendManifestProperties(GeneralCommandLine commandLine, final JavaFxArtifactProperties properties) {
final String manifestString = properties.getManifestString();
if (manifestString != null) {
commandLine.addParameter("-manifestAttrs");
commandLine.addParameter("\"" + manifestString + "\"");
}
}
private static void startProcess(GeneralCommandLine commandLine, MyOnTerminatedProcessAdapter adapter)
throws ExecutionException {
final OSProcessHandler handler = new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString());
adapter.setHandler(handler);
handler.addProcessListener(adapter);
handler.startNotify();
}
private static abstract class MyOnTerminatedProcessAdapter extends ProcessAdapter {
private OSProcessHandler myHandler;
private final CompileContext myCompileContext;
public MyOnTerminatedProcessAdapter(CompileContext compileContext) {
myCompileContext = compileContext;
}
private void setHandler(OSProcessHandler handler) {
myHandler = handler;
}
@Override
public void processTerminated(ProcessEvent event) {
myHandler.removeProcessListener(this);
onTerminated();
}
protected abstract void onTerminated();
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
if (outputType == ProcessOutputTypes.STDERR) {
registerJavaFxPackagerError(myCompileContext, event.getText());
}
}
}
}