mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Javafx: Write output of the packager to the build log (IDEA-183393)
This commit is contained in:
+66
-8
@@ -16,8 +16,13 @@
|
||||
package org.jetbrains.plugins.javaFX.packaging;
|
||||
|
||||
import com.intellij.execution.CommandLineUtil;
|
||||
import com.intellij.execution.process.BaseOSProcessHandler;
|
||||
import com.intellij.execution.process.ProcessAdapter;
|
||||
import com.intellij.execution.process.ProcessEvent;
|
||||
import com.intellij.execution.process.ProcessOutputTypes;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
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.openapi.vfs.CharsetToolkit;
|
||||
@@ -25,12 +30,14 @@ import com.intellij.util.ArrayUtilRt;
|
||||
import com.intellij.util.Base64;
|
||||
import com.intellij.util.PathUtilRt;
|
||||
import com.intellij.util.io.ZipUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public abstract class AbstractJavaFxPackager {
|
||||
private static final Logger LOG = Logger.getInstance(AbstractJavaFxPackager.class);
|
||||
@@ -77,8 +84,12 @@ public abstract class AbstractJavaFxPackager {
|
||||
|
||||
protected abstract void registerJavaFxPackagerError(final String message);
|
||||
|
||||
protected abstract void registerJavaFxPackagerInfo(final String message);
|
||||
|
||||
protected abstract JavaFxApplicationIcons getIcons();
|
||||
|
||||
protected abstract JavaFxPackagerConstants.MsgOutputLevel getMsgOutputLevel();
|
||||
|
||||
public void buildJavaFxArtifact(final String homePath) {
|
||||
if (!checkNotEmpty(getAppClass(), "Application class")) return;
|
||||
if (!checkNotEmpty(getWidth(), "Width")) return;
|
||||
@@ -246,16 +257,59 @@ public abstract class AbstractJavaFxPackager {
|
||||
|
||||
private int startProcess(List<String> commands) {
|
||||
try {
|
||||
final AtomicInteger exitCode = new AtomicInteger();
|
||||
final StringBuilder errorOutput = new StringBuilder();
|
||||
final List<String> delayedInfoOutput = new ArrayList<>();
|
||||
boolean isVerbose = getMsgOutputLevel() != null && getMsgOutputLevel().isVerbose();
|
||||
|
||||
final Process process = new ProcessBuilder(CommandLineUtil.toCommandLine(commands)).start();
|
||||
final String message = new String(FileUtil.loadBytes(process.getErrorStream()));
|
||||
if (!StringUtil.isEmptyOrSpaces(message)) {
|
||||
registerJavaFxPackagerError(message);
|
||||
}
|
||||
final int result = process.waitFor();
|
||||
BaseOSProcessHandler handler = new BaseOSProcessHandler(process, commands.toString(), null);
|
||||
handler.addProcessListener(new ProcessAdapter() {
|
||||
@Override
|
||||
public void startNotified(@NotNull ProcessEvent event) {
|
||||
if (isVerbose) {
|
||||
LOG.info("Started " + commands);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processTerminated(@NotNull ProcessEvent event) {
|
||||
if (isVerbose) {
|
||||
LOG.info("Terminated " + commands + ", exit code: " + event.getExitCode());
|
||||
}
|
||||
exitCode.set(event.getExitCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType) {
|
||||
String message = StringUtil.trimTrailing(event.getText());
|
||||
if (outputType == ProcessOutputTypes.STDERR) {
|
||||
LOG.error(message, (Throwable)null);
|
||||
errorOutput.append(event.getText());
|
||||
}
|
||||
else {
|
||||
LOG.info(message);
|
||||
if (isVerbose) {
|
||||
registerJavaFxPackagerInfo(message);
|
||||
}
|
||||
else {
|
||||
delayedInfoOutput.add(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
handler.startNotify();
|
||||
handler.waitFor();
|
||||
|
||||
int result = exitCode.get();
|
||||
if (result != 0) {
|
||||
final String explanationMessage = new String(FileUtil.loadBytes(process.getInputStream()));
|
||||
if (!StringUtil.isEmptyOrSpaces(explanationMessage)) {
|
||||
registerJavaFxPackagerError(explanationMessage);
|
||||
final String message = errorOutput.toString();
|
||||
if (!StringUtil.isEmptyOrSpaces(message)) {
|
||||
registerJavaFxPackagerError(message);
|
||||
}
|
||||
for (String info : delayedInfoOutput) {
|
||||
registerJavaFxPackagerInfo(info);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -283,6 +337,10 @@ public abstract class AbstractJavaFxPackager {
|
||||
javaHome + "/lib/ant-javafx.jar" + File.pathSeparator +
|
||||
javaHome + "/jre/lib/jfxrt.jar");
|
||||
commands.add("org.apache.tools.ant.launch.Launcher");
|
||||
String cmdLineParam = getMsgOutputLevel() != null ? getMsgOutputLevel().getCmdLineParam() : "";
|
||||
if (!cmdLineParam.isEmpty()) {
|
||||
commands.add(cmdLineParam);
|
||||
}
|
||||
commands.add("-f");
|
||||
try {
|
||||
File tempFile = FileUtil.createTempFile("build", ".xml");
|
||||
|
||||
+9
@@ -99,6 +99,7 @@ public class JavaFxAntGenerator {
|
||||
//create jar task
|
||||
final SimpleTag createJarTag = new SimpleTag("fx:jar",
|
||||
Couple.of("destfile", tempDirPath + "/" + artifactFileName));
|
||||
addVerboseAttribute(createJarTag, packager);
|
||||
createJarTag.add(new SimpleTag("fx:application", Couple.of("refid", appId)));
|
||||
|
||||
final List<Pair> fileset2Jar = new ArrayList<>();
|
||||
@@ -137,6 +138,7 @@ public class JavaFxAntGenerator {
|
||||
if (!StringUtil.isEmpty(packager.getHtmlPlaceholderId())) {
|
||||
deployTag.addAttribute(Couple.of("placeholderId", packager.getHtmlPlaceholderId()));
|
||||
}
|
||||
addVerboseAttribute(deployTag, packager);
|
||||
|
||||
if (packager.isEnabledSigning()) {
|
||||
deployTag.add(new SimpleTag("fx:permissions", Couple.of("elevated", "true")));
|
||||
@@ -161,6 +163,13 @@ public class JavaFxAntGenerator {
|
||||
return topLevelTagsCollector;
|
||||
}
|
||||
|
||||
private static void addVerboseAttribute(SimpleTag tag, @NotNull AbstractJavaFxPackager packager) {
|
||||
JavaFxPackagerConstants.MsgOutputLevel msgOutputLevel = packager.getMsgOutputLevel();
|
||||
if (msgOutputLevel != null && msgOutputLevel.isVerbose()) {
|
||||
tag.addAttribute(Couple.of("verbose", "true"));
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<JavaFxManifestAttribute> getManifestAttributes(@NotNull AbstractJavaFxPackager packager) {
|
||||
final List<JavaFxManifestAttribute> manifestAttributes = new ArrayList<>();
|
||||
|
||||
+22
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.plugins.javaFX.packaging;
|
||||
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class JavaFxPackagerConstants {
|
||||
@NonNls public static final String UPDATE_MODE_BACKGROUND = "background";
|
||||
@@ -38,4 +39,25 @@ public class JavaFxPackagerConstants {
|
||||
return this == all || this == exe || this == msi;
|
||||
}
|
||||
}
|
||||
|
||||
public enum MsgOutputLevel {
|
||||
Quiet("-quiet", false), Default("", false), Verbose("-verbose", true), Debug("-debug", true);
|
||||
|
||||
private final String myCmdLineParam;
|
||||
private final boolean myIsVerbose;
|
||||
|
||||
MsgOutputLevel(String cmdLineParam, boolean isVerbose) {
|
||||
myCmdLineParam = cmdLineParam;
|
||||
myIsVerbose = isVerbose;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getCmdLineParam() {
|
||||
return myCmdLineParam;
|
||||
}
|
||||
|
||||
public boolean isVerbose() {
|
||||
return myIsVerbose;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+48
@@ -36,6 +36,7 @@ public class JavaFxAntTaskTest extends TestCase {
|
||||
private static final String PLACEHOLDER = "placeholder";
|
||||
private static final String PRELOADER_JAR = "preloaderJar";
|
||||
private static final String SIGNED = "signed";
|
||||
private static final String VERBOSE = "verbose";
|
||||
|
||||
public void testJarDeployNoInfo() {
|
||||
doTest("<fx:fileset id=\"all_but_jarDeployNoInfo\" dir=\"temp\" includes=\"**/*.jar\">\n" +
|
||||
@@ -348,6 +349,35 @@ public class JavaFxAntTaskTest extends TestCase {
|
||||
"</fx:deploy>\n", options);
|
||||
}
|
||||
|
||||
public void testJarDeployVerbose() {
|
||||
doTest("<fx:fileset id=\"all_but_jarDeployVerbose\" dir=\"temp\" includes=\"**/*.jar\">\n" +
|
||||
"<exclude name=\"jarDeployVerbose.jar\">\n" +
|
||||
"</exclude>\n" +
|
||||
"</fx:fileset>\n" +
|
||||
"<fx:fileset id=\"all_jarDeployVerbose\" dir=\"temp\" includes=\"**/*.jar\">\n" +
|
||||
"</fx:fileset>\n" +
|
||||
"<fx:application id=\"jarDeployVerbose_id\" name=\"jarDeployVerbose\" mainClass=\"Main\">\n" +
|
||||
"</fx:application>\n" +
|
||||
"<fx:jar destfile=\"temp/jarDeployVerbose.jar\" verbose=\"true\">\n" +
|
||||
"<fx:application refid=\"jarDeployVerbose_id\">\n" +
|
||||
"</fx:application>\n" +
|
||||
"<fileset dir=\"temp\" excludes=\"**/*.jar\">\n" +
|
||||
"</fileset>\n" +
|
||||
"<fx:resources>\n" +
|
||||
"<fx:fileset refid=\"all_but_jarDeployVerbose\">\n" +
|
||||
"</fx:fileset>\n" +
|
||||
"</fx:resources>\n" +
|
||||
"</fx:jar>\n" +
|
||||
"<fx:deploy width=\"800\" height=\"400\" updatemode=\"background\" outdir=\"temp/deploy\" outfile=\"jarDeployVerbose\" verbose=\"true\">\n" +
|
||||
"<fx:application refid=\"jarDeployVerbose_id\">\n" +
|
||||
"</fx:application>\n" +
|
||||
"<fx:resources>\n" +
|
||||
"<fx:fileset refid=\"all_jarDeployVerbose\">\n" +
|
||||
"</fx:fileset>\n" +
|
||||
"</fx:resources>\n" +
|
||||
"</fx:deploy>\n", Collections.singletonMap(VERBOSE, "true"));
|
||||
}
|
||||
|
||||
private void doTest(final String expected, Map<String, String> options) {
|
||||
final String artifactName = UsefulTestCase.getTestName(getName(), true);
|
||||
final String artifactFileName = artifactName + ".jar";
|
||||
@@ -398,6 +428,10 @@ public class JavaFxAntTaskTest extends TestCase {
|
||||
packager.setSigned(true);
|
||||
}
|
||||
|
||||
if (options.containsKey(VERBOSE)) {
|
||||
packager.setMsgOutputLevel(JavaFxPackagerConstants.MsgOutputLevel.Verbose);
|
||||
}
|
||||
|
||||
final List<JavaFxAntGenerator.SimpleTag> temp = JavaFxAntGenerator
|
||||
.createJarAndDeployTasks(packager, artifactFileName, artifactName, "temp", "temp" + "/" + "deploy", relativeToBaseDirPath);
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
@@ -425,6 +459,7 @@ public class JavaFxAntTaskTest extends TestCase {
|
||||
private List<JavaFxManifestAttribute> myCustomManifestAttributes;
|
||||
private JavaFxApplicationIcons myIcons;
|
||||
private JavaFxPackagerConstants.NativeBundles myNativeBundle = JavaFxPackagerConstants.NativeBundles.none;
|
||||
private JavaFxPackagerConstants.MsgOutputLevel myMsgOutputLevel = JavaFxPackagerConstants.MsgOutputLevel.Default;
|
||||
|
||||
private MockJavaFxPackager(String outputPath) {
|
||||
myOutputPath = outputPath;
|
||||
@@ -482,6 +517,10 @@ public class JavaFxAntTaskTest extends TestCase {
|
||||
myNativeBundle = nativeBundle;
|
||||
}
|
||||
|
||||
public void setMsgOutputLevel(JavaFxPackagerConstants.MsgOutputLevel msgOutputLevel) {
|
||||
myMsgOutputLevel = msgOutputLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getArtifactName() {
|
||||
return getArtifactRootName();
|
||||
@@ -566,6 +605,10 @@ public class JavaFxAntTaskTest extends TestCase {
|
||||
protected void registerJavaFxPackagerError(String message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerJavaFxPackagerInfo(String message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKeypass() {
|
||||
return null;
|
||||
@@ -620,5 +663,10 @@ public class JavaFxAntTaskTest extends TestCase {
|
||||
public JavaFxApplicationIcons getIcons() {
|
||||
return myIcons;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaFxPackagerConstants.MsgOutputLevel getMsgOutputLevel() {
|
||||
return myMsgOutputLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
@@ -171,6 +171,11 @@ public class JpsJavaFxArtifactBuildTaskProvider extends ArtifactBuildTaskProvide
|
||||
myCompileContext.processMessage(new CompilerMessage(COMPILER_NAME, BuildMessage.Kind.ERROR, message));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerJavaFxPackagerInfo(String message) {
|
||||
myCompileContext.processMessage(new CompilerMessage(COMPILER_NAME, BuildMessage.Kind.INFO, message));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getHtmlTemplateFile() {
|
||||
return myProperties.myState.getHtmlTemplateFile();
|
||||
@@ -260,6 +265,11 @@ public class JpsJavaFxArtifactBuildTaskProvider extends ArtifactBuildTaskProvide
|
||||
return myProperties.myState.getCustomManifestAttributes();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JavaFxPackagerConstants.MsgOutputLevel getMsgOutputLevel() {
|
||||
return myProperties.myState.getMsgOutputLevel();
|
||||
}
|
||||
|
||||
private JpsArtifact getPreloaderArtifact() {
|
||||
for (JpsPackagingElement element : myArtifact.getRootElement().getChildren()) {
|
||||
if (element instanceof JpsArtifactOutputPackagingElement) {
|
||||
|
||||
+10
@@ -42,6 +42,7 @@ public class JpsJavaFxArtifactProperties extends JpsElementBase<JpsJavaFxArtifac
|
||||
myState.setNativeBundle(state.myNativeBundle);
|
||||
myState.setCustomManifestAttributes(state.myCustomManifestAttributes);
|
||||
myState.setIcons(state.myIcons);
|
||||
myState.setMsgOutputLevel(state.myMsgOutputLevel);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -78,6 +79,7 @@ public class JpsJavaFxArtifactProperties extends JpsElementBase<JpsJavaFxArtifac
|
||||
public JavaFxPackagerConstants.NativeBundles myNativeBundle = JavaFxPackagerConstants.NativeBundles.none;
|
||||
private List<JavaFxManifestAttribute> myCustomManifestAttributes = new ArrayList<>();
|
||||
private JavaFxApplicationIcons myIcons = new JavaFxApplicationIcons();
|
||||
private JavaFxPackagerConstants.MsgOutputLevel myMsgOutputLevel = JavaFxPackagerConstants.MsgOutputLevel.Default;
|
||||
|
||||
public String getTitle() {
|
||||
return myTitle;
|
||||
@@ -254,5 +256,13 @@ public class JpsJavaFxArtifactProperties extends JpsElementBase<JpsJavaFxArtifac
|
||||
public void setCustomManifestAttributes(List<JavaFxManifestAttribute> customManifestAttributes) {
|
||||
myCustomManifestAttributes = customManifestAttributes;
|
||||
}
|
||||
|
||||
public JavaFxPackagerConstants.MsgOutputLevel getMsgOutputLevel() {
|
||||
return myMsgOutputLevel;
|
||||
}
|
||||
|
||||
public void setMsgOutputLevel(JavaFxPackagerConstants.MsgOutputLevel msgOutputLevel) {
|
||||
myMsgOutputLevel = msgOutputLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+19
@@ -71,6 +71,7 @@ public class JavaFxArtifactProperties extends ArtifactProperties<JavaFxArtifactP
|
||||
private String myNativeBundle = JavaFxPackagerConstants.NativeBundles.none.name();
|
||||
private List<JavaFxManifestAttribute> myCustomManifestAttributes = new ArrayList<>();
|
||||
private JavaFxApplicationIcons myIcons = new JavaFxApplicationIcons();
|
||||
private String myMsgOutputLevel = JavaFxPackagerConstants.MsgOutputLevel.Default.name();
|
||||
|
||||
@Override
|
||||
public void onBuildFinished(@NotNull final Artifact artifact, @NotNull final CompileContext compileContext) {
|
||||
@@ -107,6 +108,11 @@ public class JavaFxArtifactProperties extends ArtifactProperties<JavaFxArtifactP
|
||||
protected void registerJavaFxPackagerError(String message) {
|
||||
compileContext.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerJavaFxPackagerInfo(String message) {
|
||||
compileContext.addMessage(CompilerMessageCategory.INFORMATION, message, null, -1, -1);
|
||||
}
|
||||
};
|
||||
javaFxPackager.buildJavaFxArtifact(fxCompatibleSdk.getHomePath());
|
||||
}
|
||||
@@ -335,6 +341,14 @@ public class JavaFxArtifactProperties extends ArtifactProperties<JavaFxArtifactP
|
||||
myIcons = icons;
|
||||
}
|
||||
|
||||
public String getMsgOutputLevel() {
|
||||
return myMsgOutputLevel;
|
||||
}
|
||||
|
||||
public void setMsgOutputLevel(String msgOutputLevel) {
|
||||
myMsgOutputLevel = msgOutputLevel;
|
||||
}
|
||||
|
||||
public static abstract class JavaFxPackager extends AbstractJavaFxPackager {
|
||||
private final Artifact myArtifact;
|
||||
private final JavaFxArtifactProperties myProperties;
|
||||
@@ -485,5 +499,10 @@ public class JavaFxArtifactProperties extends ArtifactProperties<JavaFxArtifactP
|
||||
public List<JavaFxManifestAttribute> getCustomManifestAttributes() {
|
||||
return myProperties.getCustomManifestAttributes();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JavaFxPackagerConstants.MsgOutputLevel getMsgOutputLevel() {
|
||||
return JavaFxPackagerConstants.MsgOutputLevel.valueOf(myProperties.getMsgOutputLevel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -141,6 +141,8 @@ public class JavaFxChunkBuildExtension extends ChunkBuildExtension {
|
||||
new JavaFxArtifactProperties.JavaFxPackager(artifact, properties, context.getProject()) {
|
||||
@Override
|
||||
protected void registerJavaFxPackagerError(String message) {}
|
||||
@Override
|
||||
protected void registerJavaFxPackagerInfo(String message) {}
|
||||
};
|
||||
final String tempDirDeployPath = tempDirPath + "/deploy";
|
||||
final List<JavaFxAntGenerator.SimpleTag> tags =
|
||||
|
||||
Reference in New Issue
Block a user