mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
javafx packaging: artifact type; works with old compile only
(cherry picked from commit f16e080cecdf41ebd98c809799dc6d8b0b965e5d)
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
<orderEntry type="module" module-name="java-impl" />
|
||||
<orderEntry type="module" module-name="java-indexing-api" />
|
||||
<orderEntry type="module" module-name="openapi" />
|
||||
<orderEntry type="module" module-name="compiler-openapi" />
|
||||
<orderEntry type="module" module-name="compiler-impl" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
<lang.importOptimizer language="XML" implementationClass="org.jetbrains.plugins.javaFX.fxml.codeInsight.JavaFxImportsOptimizer" order="before XML"/>
|
||||
<psi.referenceContributor implementation="org.jetbrains.plugins.javaFX.fxml.refs.JavaFxReferencesContributor"/>
|
||||
<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"/>
|
||||
</extensions>
|
||||
|
||||
<actions>
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.icons.AllIcons;
|
||||
import com.intellij.packaging.artifacts.ArtifactType;
|
||||
import com.intellij.packaging.elements.CompositePackagingElement;
|
||||
import com.intellij.packaging.elements.PackagingElementFactory;
|
||||
import com.intellij.packaging.elements.PackagingElementOutputKind;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 3/12/13
|
||||
*/
|
||||
public class JavaFxApplicationArtifactType extends ArtifactType {
|
||||
protected JavaFxApplicationArtifactType() {
|
||||
super("javafx", "JavaFx Application");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return AllIcons.Nodes.Artifact;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getDefaultPathFor(@NotNull PackagingElementOutputKind kind) {
|
||||
return "/";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CompositePackagingElement<?> createRootElement(@NotNull String artifactName) {
|
||||
return PackagingElementFactory.getInstance().createArchive(artifactName + ".jar");
|
||||
}
|
||||
}
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* 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.application.ApplicationManager;
|
||||
import com.intellij.openapi.compiler.CompileContext;
|
||||
import com.intellij.openapi.compiler.CompilerMessageCategory;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
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.text.StringUtil;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.packaging.artifacts.ArtifactProperties;
|
||||
import com.intellij.packaging.impl.artifacts.ArtifactUtil;
|
||||
import com.intellij.packaging.ui.ArtifactEditorContext;
|
||||
import com.intellij.packaging.ui.ArtifactPropertiesEditor;
|
||||
import com.intellij.util.xmlb.XmlSerializerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 3/12/13
|
||||
*/
|
||||
public class JavaFxArtifactProperties extends ArtifactProperties<JavaFxArtifactProperties> {
|
||||
|
||||
private String myTitle;
|
||||
private String myVendor;
|
||||
private String myDescription;
|
||||
private String myAppClass;
|
||||
|
||||
@Override
|
||||
public void onBuildFinished(@NotNull final Artifact artifact, @NotNull CompileContext compileContext) {
|
||||
if (!(artifact.getArtifactType() instanceof JavaFxApplicationArtifactType)) {
|
||||
return;
|
||||
}
|
||||
final Project project = compileContext.getProject();
|
||||
final Set<Module> modules = ApplicationManager.getApplication().runReadAction(new Computable<Set<Module>>() {
|
||||
@Override
|
||||
public Set<Module> compute() {
|
||||
return ArtifactUtil.getModulesIncludedInArtifacts(Collections.singletonList(artifact), project);
|
||||
}
|
||||
});
|
||||
if (modules.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Sdk fxCompatibleSdk = null;
|
||||
for (Module module : modules) {
|
||||
final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
|
||||
if (sdk != null && sdk.getSdkType() instanceof JavaSdk) {
|
||||
if (((JavaSdk)sdk.getSdkType()).isOfVersionOrHigher(sdk, JavaSdkVersion.JDK_1_7)) {
|
||||
fxCompatibleSdk = sdk;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fxCompatibleSdk == null) {
|
||||
compileContext.addMessage(CompilerMessageCategory.ERROR, "Java version 7 or higher is required to build JavaFX package", null, -1, -1);
|
||||
return;
|
||||
}
|
||||
|
||||
final String binPath = ((JavaSdk)fxCompatibleSdk.getSdkType()).getBinPath(fxCompatibleSdk);
|
||||
|
||||
final JavaFxArtifactProperties properties =
|
||||
(JavaFxArtifactProperties)artifact.getProperties(JavaFxArtifactPropertiesProvider.getInstance());
|
||||
|
||||
if (StringUtil.isEmptyOrSpaces(properties.getAppClass())) {
|
||||
compileContext.addMessage(CompilerMessageCategory.ERROR, "No application class specified for JavaFX package", null, -1, -1);
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArtifactPropertiesEditor createEditor(@NotNull ArtifactEditorContext context) {
|
||||
return new JavaFxArtifactPropertiesEditor(this, context.getProject(), context.getArtifact());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JavaFxArtifactProperties getState() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(JavaFxArtifactProperties state) {
|
||||
XmlSerializerUtil.copyBean(state, this);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.plugins.javaFX.packaging.JavaFxArtifactPropertiesEditor">
|
||||
<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"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="ca833" layout-manager="GridLayoutManager" row-count="4" column-count="3" 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"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="e6b9f" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="1" 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>
|
||||
<labelFor value="7bfab"/>
|
||||
<text value="&Title:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="5bdb3">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="7bfab" class="javax.swing.JTextField" binding="myTitleTF">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="b0dab" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="2" 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>
|
||||
<labelFor value="ad1f3"/>
|
||||
<text value="&Vendor:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ad1f3" class="javax.swing.JTextField" binding="myVendorTF">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<scrollpane id="c7b69" class="com.intellij.ui.components.JBScrollPane">
|
||||
<constraints>
|
||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="-1" height="100"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="a51e8" class="javax.swing.JEditorPane" binding="myDescriptionEditorPane" default-binding="true">
|
||||
<constraints/>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
<component id="3ada" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="a51e8"/>
|
||||
<text value="&Description:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="a1cdd" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" 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>
|
||||
<labelFor value="e5f9c"/>
|
||||
<text value="A&pplication class:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e5f9c" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myAppClass">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<vspacer id="1a12e">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* 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.JavaExecutionUtil;
|
||||
import com.intellij.execution.ui.ClassBrowser;
|
||||
import com.intellij.ide.util.ClassFilter;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.packaging.impl.artifacts.ArtifactUtil;
|
||||
import com.intellij.packaging.ui.ArtifactPropertiesEditor;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.JTextComponent;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 3/12/13
|
||||
*/
|
||||
public class JavaFxArtifactPropertiesEditor extends ArtifactPropertiesEditor {
|
||||
private final JavaFxArtifactProperties myProperties;
|
||||
|
||||
private JPanel myWholePanel;
|
||||
private JTextField myTitleTF;
|
||||
private JTextField myVendorTF;
|
||||
private JEditorPane myDescriptionEditorPane;
|
||||
private TextFieldWithBrowseButton myAppClass;
|
||||
|
||||
public JavaFxArtifactPropertiesEditor(JavaFxArtifactProperties properties, Project project, Artifact artifact) {
|
||||
super();
|
||||
myProperties = properties;
|
||||
new JavaFxApplicationClassBrowser(project, artifact).setField(myAppClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTabName() {
|
||||
return "Java FX";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
return myWholePanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
if (isModified(myProperties.getTitle(), myTitleTF)) return true;
|
||||
if (isModified(myProperties.getVendor(), myVendorTF)) return true;
|
||||
if (isModified(myProperties.getDescription(), myDescriptionEditorPane)) return true;
|
||||
if (!Comparing.strEqual(myProperties.getAppClass(), myAppClass.getText().trim())) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isModified(final String title, JTextComponent tf) {
|
||||
return !Comparing.strEqual(title, tf.getText().trim());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
myProperties.setTitle(myTitleTF.getText());
|
||||
myProperties.setVendor(myVendorTF.getText());
|
||||
myProperties.setDescription(myDescriptionEditorPane.getText());
|
||||
myProperties.setAppClass(myAppClass.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
setText(myTitleTF, myProperties.getTitle());
|
||||
setText(myVendorTF, myProperties.getVendor());
|
||||
setText(myDescriptionEditorPane, myProperties.getDescription());
|
||||
final String appClass = myProperties.getAppClass();
|
||||
if (appClass != null) {
|
||||
myAppClass.setText(appClass.trim());
|
||||
}
|
||||
}
|
||||
|
||||
private static void setText(JTextComponent tf, final String title) {
|
||||
if (title != null) {
|
||||
tf.setText(title.trim());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeUIResources() {}
|
||||
|
||||
private static class JavaFxApplicationClassBrowser extends ClassBrowser {
|
||||
|
||||
private final Artifact myArtifact;
|
||||
|
||||
public JavaFxApplicationClassBrowser(Project project, Artifact artifact) {
|
||||
super(project, "Choose Application Class");
|
||||
myArtifact = artifact;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ClassFilter.ClassFilterWithScope getFilter() throws NoFilterException {
|
||||
return new ClassFilter.ClassFilterWithScope() {
|
||||
@Override
|
||||
public GlobalSearchScope getScope() {
|
||||
return GlobalSearchScope.projectScope(getProject());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccepted(PsiClass aClass) {
|
||||
return InheritanceUtil.isInheritor(aClass, "javafx.application.Application");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PsiClass findClass(String className) {
|
||||
final Set<Module> modules = ApplicationManager.getApplication().runReadAction(new Computable<Set<Module>>() {
|
||||
@Override
|
||||
public Set<Module> compute() {
|
||||
return ArtifactUtil.getModulesIncludedInArtifacts(Collections.singletonList(myArtifact), getProject());
|
||||
}
|
||||
});
|
||||
for (Module module : modules) {
|
||||
final PsiClass aClass = JavaExecutionUtil.findMainClass(getProject(), className, GlobalSearchScope.moduleScope(module));
|
||||
if (aClass != null) {
|
||||
return aClass;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.packaging.artifacts.ArtifactProperties;
|
||||
import com.intellij.packaging.artifacts.ArtifactPropertiesProvider;
|
||||
import com.intellij.packaging.artifacts.ArtifactType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 3/12/13
|
||||
*/
|
||||
public class JavaFxArtifactPropertiesProvider extends ArtifactPropertiesProvider {
|
||||
protected JavaFxArtifactPropertiesProvider() {
|
||||
super("javafx-properties");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailableFor(@NotNull ArtifactType type) {
|
||||
return type instanceof JavaFxApplicationArtifactType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ArtifactProperties<?> createProperties(@NotNull ArtifactType artifactType) {
|
||||
return new JavaFxArtifactProperties();
|
||||
}
|
||||
|
||||
public static JavaFxArtifactPropertiesProvider getInstance() {
|
||||
return EP_NAME.findExtension(JavaFxArtifactPropertiesProvider.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
* 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user