javafx: allow to configure custom manifest attributes (IDEA-115252)

This commit is contained in:
anna
2013-12-03 10:56:11 +01:00
parent e0222e9c3c
commit 4076692232
9 changed files with 278 additions and 6 deletions
@@ -18,6 +18,7 @@ package org.jetbrains.plugins.javaFX.packaging;
import com.intellij.execution.CommandLineUtil;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ArrayUtilRt;
@@ -358,4 +359,6 @@ public abstract class AbstractJavaFxPackager {
public abstract String getPreloaderJar();
public abstract boolean convertCss2Bin();
public abstract List<JavaFxManifestAttribute> getCustomManifestAttributes();
}
@@ -106,7 +106,18 @@ public class JavaFxAntGenerator {
createJarTag.add(new SimpleTag("fileset", fileset2Jar.toArray(new Pair[fileset2Jar.size()])));
createJarTag.add(createResourcesTag(preloaderFiles, false, allButPreloader, allButSelf, all));
List<JavaFxManifestAttribute> manifestAttributes = packager.getCustomManifestAttributes();
if (manifestAttributes != null) {
final SimpleTag manifestTag = new SimpleTag("manifest");
for (JavaFxManifestAttribute pair : manifestAttributes) {
manifestTag.add(new SimpleTag("attribute",
new Pair<String, String>("name", pair.getName()),
new Pair<String, String>("value", pair.getValue())));
}
createJarTag.add(manifestTag);
}
topLevelTagsCollector.add(createJarTag);
//deploy task
@@ -0,0 +1,50 @@
package org.jetbrains.plugins.javaFX.packaging;
public class JavaFxManifestAttribute {
private String myName;
private String myValue;
public JavaFxManifestAttribute() {
}
public JavaFxManifestAttribute(String name, String value) {
myName = name;
myValue = value;
}
public String getName() {
return myName;
}
public void setName(String name) {
myName = name;
}
public String getValue() {
return myValue;
}
public void setValue(String value) {
myValue = value;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
JavaFxManifestAttribute attribute = (JavaFxManifestAttribute)o;
if (!myName.equals(attribute.myName)) return false;
if (!myValue.equals(attribute.myValue)) return false;
return true;
}
@Override
public int hashCode() {
int result = myName.hashCode();
result = 31 * result + myValue.hashCode();
return result;
}
}
@@ -15,6 +15,7 @@
*/
package org.jetbrains.plugins.javaFX.packaging;
import com.intellij.openapi.util.Pair;
import com.intellij.testFramework.UsefulTestCase;
import java.io.File;
@@ -215,6 +216,7 @@ public class JavaFxAntTaskTest extends UsefulTestCase{
private String myPreloaderJar;
private boolean myConvertCss2Bin;
private boolean mySigned;
private List<JavaFxManifestAttribute> myCustomManifestAttributes;
private MockJavaFxPackager(String outputPath) {
myOutputPath = outputPath;
@@ -365,5 +367,10 @@ public class JavaFxAntTaskTest extends UsefulTestCase{
public boolean convertCss2Bin() {
return myConvertCss2Bin;
}
@Override
public List<JavaFxManifestAttribute> getCustomManifestAttributes() {
return myCustomManifestAttributes;
}
}
}
@@ -31,6 +31,7 @@ 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 org.jetbrains.plugins.javaFX.packaging.JavaFxManifestAttribute;
import org.jetbrains.plugins.javaFX.packaging.JavaFxPackagerConstants;
import org.jetbrains.plugins.javaFX.preloader.JpsJavaFxPreloaderArtifactProperties;
import org.jetbrains.plugins.javaFX.preloader.JpsJavaFxPreloaderArtifactType;
@@ -237,6 +238,11 @@ public class JpsJavaFxArtifactBuildTaskProvider extends ArtifactBuildTaskProvide
return myProperties.myState.isConvertCss2Bin();
}
@Override
public List<JavaFxManifestAttribute> getCustomManifestAttributes() {
return myProperties.myState.getCustomManifestAttributes();
}
private JpsArtifact getPreloaderArtifact() {
for (JpsPackagingElement element : myArtifact.getRootElement().getChildren()) {
if (element instanceof JpsArtifactOutputPackagingElement) {
@@ -2,8 +2,12 @@ package org.jetbrains.plugins.javaFX;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.ex.JpsElementBase;
import org.jetbrains.plugins.javaFX.packaging.JavaFxManifestAttribute;
import org.jetbrains.plugins.javaFX.packaging.JavaFxPackagerConstants;
import java.util.ArrayList;
import java.util.List;
/**
* User: anna
* Date: 3/13/13
@@ -36,6 +40,7 @@ public class JpsJavaFxArtifactProperties extends JpsElementBase<JpsJavaFxArtifac
myState.setAlias(state.myAlias);
myState.setConvertCss2Bin(state.myConvertCss2Bin);
myState.setNativeBundle(state.myNativeBundle);
myState.setCustomManifestAttributes(state.myCustomManifestAttributes);
}
@NotNull
@@ -67,6 +72,7 @@ public class JpsJavaFxArtifactProperties extends JpsElementBase<JpsJavaFxArtifac
private String myKeypass;
private boolean myConvertCss2Bin;
public JavaFxPackagerConstants.NativeBundles myNativeBundle = JavaFxPackagerConstants.NativeBundles.none;
private List<JavaFxManifestAttribute> myCustomManifestAttributes = new ArrayList<JavaFxManifestAttribute>();
public String getTitle() {
return myTitle;
@@ -203,5 +209,13 @@ public class JpsJavaFxArtifactProperties extends JpsElementBase<JpsJavaFxArtifac
public void setNativeBundle(JavaFxPackagerConstants.NativeBundles nativeBundle) {
myNativeBundle = nativeBundle;
}
public List<JavaFxManifestAttribute> getCustomManifestAttributes() {
return myCustomManifestAttributes;
}
public void setCustomManifestAttributes(List<JavaFxManifestAttribute> customManifestAttributes) {
myCustomManifestAttributes = customManifestAttributes;
}
}
}
@@ -25,6 +25,7 @@ import com.intellij.openapi.projectRoots.JavaSdkVersion;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Pair;
import com.intellij.packaging.artifacts.Artifact;
import com.intellij.packaging.artifacts.ArtifactManager;
import com.intellij.packaging.artifacts.ArtifactProperties;
@@ -35,6 +36,7 @@ import com.intellij.packaging.impl.elements.ArtifactPackagingElement;
import com.intellij.packaging.ui.ArtifactEditorContext;
import com.intellij.packaging.ui.ArtifactPropertiesEditor;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.intellij.util.xmlb.annotations.Tag;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.javaFX.packaging.preloader.JavaFxPreloaderArtifactProperties;
@@ -42,7 +44,9 @@ import org.jetbrains.plugins.javaFX.packaging.preloader.JavaFxPreloaderArtifactP
import org.jetbrains.plugins.javaFX.packaging.preloader.JavaFxPreloaderArtifactType;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
/**
@@ -69,6 +73,7 @@ public class JavaFxArtifactProperties extends ArtifactProperties<JavaFxArtifactP
private String myKeypass;
private boolean myConvertCss2Bin;
private String myNativeBundle = JavaFxPackagerConstants.NativeBundles.none.name();
private List<JavaFxManifestAttribute> myCustomManifestAttributes = new ArrayList<JavaFxManifestAttribute>();
@Override
public void onBuildFinished(@NotNull final Artifact artifact, @NotNull final CompileContext compileContext) {
@@ -298,6 +303,14 @@ public class JavaFxArtifactProperties extends ArtifactProperties<JavaFxArtifactP
myNativeBundle = nativeBundle;
}
public List<JavaFxManifestAttribute> getCustomManifestAttributes() {
return myCustomManifestAttributes;
}
public void setCustomManifestAttributes(List<JavaFxManifestAttribute> customManifestAttributes) {
myCustomManifestAttributes = customManifestAttributes;
}
public static abstract class JavaFxPackager extends AbstractJavaFxPackager {
private final Artifact myArtifact;
private final JavaFxArtifactProperties myProperties;
@@ -423,5 +436,10 @@ public class JavaFxArtifactProperties extends ArtifactProperties<JavaFxArtifactP
public boolean isEnabledSigning() {
return myProperties.isEnabledSigning();
}
@Override
public List<JavaFxManifestAttribute> getCustomManifestAttributes() {
return myProperties.getCustomManifestAttributes();
}
}
}
@@ -3,12 +3,12 @@
<grid id="27dc6" binding="myWholePanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
<xy x="20" y="20" width="500" height="422"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="ca833" layout-manager="GridLayoutManager" row-count="12" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="ca833" layout-manager="GridLayoutManager" row-count="13" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -215,6 +215,37 @@
</constraints>
<properties/>
</component>
<component id="7d6a7" class="javax.swing.JLabel">
<constraints>
<grid row="12" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Custom manifest attributes"/>
</properties>
</component>
<grid id="cd6c2" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="12" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="bacf3" class="javax.swing.JButton" binding="myEditAttributesButton" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Edit Attributes"/>
</properties>
</component>
<hspacer id="20f71">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
</children>
</grid>
<vspacer id="1a12e">
@@ -15,21 +15,27 @@
*/
package org.jetbrains.plugins.javaFX.packaging;
import com.intellij.execution.util.ListTableWithButtons;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.packaging.artifacts.Artifact;
import com.intellij.packaging.ui.ArtifactPropertiesEditor;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Base64Converter;
import com.intellij.util.ui.ColumnInfo;
import com.intellij.util.ui.ListTableModel;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.text.JTextComponent;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
@@ -56,7 +62,10 @@ public class JavaFxArtifactPropertiesEditor extends ArtifactPropertiesEditor {
private JButton myEditSignCertificateButton;
private JCheckBox myConvertCssToBinCheckBox;
private JComboBox myNativeBundleCB;
private JButton myEditAttributesButton;
private JavaFxEditCertificatesDialog myDialog;
private CustomManifestAttributesDialog myManifestAttributesDialog;
private List<JavaFxManifestAttribute> myCustomManifestAttributes;
public JavaFxArtifactPropertiesEditor(JavaFxArtifactProperties properties, final Project project, Artifact artifact) {
super();
@@ -79,6 +88,17 @@ public class JavaFxArtifactPropertiesEditor extends ArtifactPropertiesEditor {
}
});
myEditAttributesButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
myManifestAttributesDialog = new CustomManifestAttributesDialog(myWholePanel, myCustomManifestAttributes);
myManifestAttributesDialog.show();
if (myManifestAttributesDialog.isOK()) {
myCustomManifestAttributes = myManifestAttributesDialog.getAttrs();
}
}
});
final List<String> bundleNames = new ArrayList<String>();
for (JavaFxPackagerConstants.NativeBundles bundle : JavaFxPackagerConstants.NativeBundles.values()) {
bundleNames.add(bundle.name());
@@ -121,13 +141,17 @@ public class JavaFxArtifactPropertiesEditor extends ArtifactPropertiesEditor {
if (isModified(storepass != null ? Base64Converter.decode(storepass) : "", myDialog.myPanel.myStorePassTF)) return true;
if (myProperties.isSelfSigning() != myDialog.myPanel.mySelfSignedRadioButton.isSelected()) return true;
}
if (myManifestAttributesDialog != null) {
if (!Comparing.equal(myManifestAttributesDialog.getAttrs(), myProperties.getCustomManifestAttributes())) return true;
}
return false;
}
private static boolean isModified(final String title, JTextComponent tf) {
return !Comparing.strEqual(title, tf.getText().trim());
}
private static boolean isModified(final String title, TextFieldWithBrowseButton tf) {
return !Comparing.strEqual(title, tf.getText().trim());
}
@@ -142,7 +166,7 @@ public class JavaFxArtifactPropertiesEditor extends ArtifactPropertiesEditor {
myProperties.setHeight(myHeightTF.getText());
myProperties.setHtmlParamFile(myHtmlParams.getText());
myProperties.setParamFile(myParams.getText());
myProperties.setUpdateMode(myUpdateInBackgroundCB.isSelected() ? JavaFxPackagerConstants.UPDATE_MODE_BACKGROUND
myProperties.setUpdateMode(myUpdateInBackgroundCB.isSelected() ? JavaFxPackagerConstants.UPDATE_MODE_BACKGROUND
: JavaFxPackagerConstants.UPDATE_MODE_ALWAYS);
myProperties.setEnabledSigning(myEnableSigningCB.isSelected());
myProperties.setConvertCss2Bin(myConvertCssToBinCheckBox.isSelected());
@@ -156,6 +180,10 @@ public class JavaFxArtifactPropertiesEditor extends ArtifactPropertiesEditor {
final String storePass = String.valueOf(myDialog.myPanel.myStorePassTF.getPassword());
myProperties.setStorepass(!StringUtil.isEmptyOrSpaces(storePass) ? Base64Converter.encode(storePass) : null);
}
if (myManifestAttributesDialog != null) {
myProperties.setCustomManifestAttributes(myManifestAttributesDialog.getAttrs());
}
}
@Nullable
@@ -179,6 +207,7 @@ public class JavaFxArtifactPropertiesEditor extends ArtifactPropertiesEditor {
myEnableSigningCB.setSelected(myProperties.isEnabledSigning());
myConvertCssToBinCheckBox.setSelected(myProperties.isConvertCss2Bin());
myEditSignCertificateButton.setEnabled(myProperties.isEnabledSigning());
myCustomManifestAttributes = myProperties.getCustomManifestAttributes();
}
private static void setText(TextFieldWithBrowseButton tf, final String title) {
@@ -199,4 +228,107 @@ public class JavaFxArtifactPropertiesEditor extends ArtifactPropertiesEditor {
myDialog.myPanel = null;
}
}
}
private static class CustomManifestAttributesDialog extends DialogWrapper {
private final JPanel myWholePanel = new JPanel(new BorderLayout());
private final AttributesTable myTable;
protected CustomManifestAttributesDialog(JPanel panel, List<JavaFxManifestAttribute> attrs) {
super(panel, true);
myTable = new AttributesTable();
myTable.setValues(attrs);
myWholePanel.add(myTable.getComponent(), BorderLayout.CENTER);
setTitle("Edit Custom Manifest Attributes");
init();
}
@Override
@Nullable
protected JComponent createCenterPanel() {
return myWholePanel;
}
@Override
protected void doOKAction() {
myTable.stopEditing();
super.doOKAction();
}
List<JavaFxManifestAttribute> getAttrs() {
return myTable.getAttrs();
}
private static class AttributesTable extends ListTableWithButtons<JavaFxManifestAttribute> {
@Override
protected ListTableModel createListModel() {
final ColumnInfo name = new ElementsColumnInfoBase<JavaFxManifestAttribute>("Name") {
@Nullable
@Override
public String valueOf(JavaFxManifestAttribute attribute) {
return attribute.getName();
}
@Override
public boolean isCellEditable(JavaFxManifestAttribute attr) {
return true;
}
@Override
public void setValue(JavaFxManifestAttribute attr, String value) {
attr.setName(value);
}
@Nullable
@Override
protected String getDescription(JavaFxManifestAttribute element) {
return element.getName();
}
};
final ColumnInfo value = new ElementsColumnInfoBase<JavaFxManifestAttribute>("Value") {
@Override
public String valueOf(JavaFxManifestAttribute attr) {
return attr.getValue();
}
@Override
public boolean isCellEditable(JavaFxManifestAttribute attr) {
return true;
}
@Override
public void setValue(JavaFxManifestAttribute attr, String s) {
attr.setValue(s);
}
@Nullable
@Override
protected String getDescription(JavaFxManifestAttribute attr) {
return attr.getValue();
}
};
return new ListTableModel((new ColumnInfo[]{name, value}));
}
@Override
protected JavaFxManifestAttribute createElement() {
return new JavaFxManifestAttribute("", "");
}
@Override
protected JavaFxManifestAttribute cloneElement(JavaFxManifestAttribute attribute) {
return new JavaFxManifestAttribute(attribute.getName(), attribute.getValue());
}
@Override
protected boolean canDeleteElement(JavaFxManifestAttribute selection) {
return true;
}
public List<JavaFxManifestAttribute> getAttrs() {
return getElements();
}
}
}
}