diff --git a/napi_IntelliJ_plugin/resources/images/openDisk.png b/napi_IntelliJ_plugin/resources/images/openDisk.png index 5e66baa62e361484a32069b4277e269bcdce722f..5956a0e538a400c7deaf41167ae5ea70348b8584 100644 Binary files a/napi_IntelliJ_plugin/resources/images/openDisk.png and b/napi_IntelliJ_plugin/resources/images/openDisk.png differ diff --git a/napi_IntelliJ_plugin/resources/images/text.png b/napi_IntelliJ_plugin/resources/images/text.png index e2442e2b179f2069f6345e8bbff808c3e6b0bb05..f42534169aa41dd830a7cb09792fe1428c2f34f7 100644 Binary files a/napi_IntelliJ_plugin/resources/images/text.png and b/napi_IntelliJ_plugin/resources/images/text.png differ diff --git a/napi_IntelliJ_plugin/src/com/sk/action/BrowseAction.java b/napi_IntelliJ_plugin/src/com/sk/action/BrowseAction.java index b8fca5f242d5246001aaca3c57676f10e2a662ae..1e1b3a3a9d2f5270e21e72cdabf71b4500ea41ae 100644 --- a/napi_IntelliJ_plugin/src/com/sk/action/BrowseAction.java +++ b/napi_IntelliJ_plugin/src/com/sk/action/BrowseAction.java @@ -32,7 +32,7 @@ import java.util.prefs.Preferences; /** * 接口文件选择框。 * - * @author: xudong + * @author: zhaoxudong@kaihong.com * @see: select file * @version: v1.0.0 * @since 2022-02-21 diff --git a/napi_IntelliJ_plugin/src/com/sk/action/GenAction.java b/napi_IntelliJ_plugin/src/com/sk/action/GenAction.java index bd6122f30d3d9fc78ef965894c2ebf84738d2538..7d31aa563a3ebf7ede9d08a014197beefeb95966 100644 --- a/napi_IntelliJ_plugin/src/com/sk/action/GenAction.java +++ b/napi_IntelliJ_plugin/src/com/sk/action/GenAction.java @@ -23,7 +23,7 @@ import java.awt.event.ActionListener; /** * 编译文件夹选择框 * - * @author: xudong + * @author: zhaoxudong@kaihong.com * @see: select generator file path * @version: v1.0.0 * @since 2022-02-21 diff --git a/napi_IntelliJ_plugin/src/com/sk/action/ScriptAction.java b/napi_IntelliJ_plugin/src/com/sk/action/ScriptAction.java index c2a172fb93003d7c2870666c4268f980a1372926..5f2c49c8a4631305cdc82bdc15b37e6edebecac1 100644 --- a/napi_IntelliJ_plugin/src/com/sk/action/ScriptAction.java +++ b/napi_IntelliJ_plugin/src/com/sk/action/ScriptAction.java @@ -23,7 +23,7 @@ import java.awt.event.ActionListener; /** * 脚本选择对话框 * - * @author: xudong + * @author: zhaoxudong@kaihong.com * @see: select compile script * @version: v1.0.0 * @since 2022-02-21 diff --git a/napi_IntelliJ_plugin/src/com/sk/action/SelectHAction.java b/napi_IntelliJ_plugin/src/com/sk/action/SelectHAction.java new file mode 100644 index 0000000000000000000000000000000000000000..2f13588eeb7b7d640a73ad9e7d15104628542671 --- /dev/null +++ b/napi_IntelliJ_plugin/src/com/sk/action/SelectHAction.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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 com.sk.action; + +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JTextField; +import javax.swing.filechooser.FileNameExtensionFilter; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * 编译文件夹选择框 + * + * @author: zhaoxudong@kaihong.com + * @see: select generator file path + * @version: v1.0.0 + * @since 2022-02-21 + */ +public class SelectHAction implements ActionListener { + private final JButton button; + private final JTextField textField; + + public SelectHAction(JButton button, JTextField textField) { + this.button = button; + this.textField = textField; + } + + @Override + public void actionPerformed(ActionEvent actionEvent) { + if (actionEvent.getSource().equals(button)) { + JFileChooser fcDlg = new JFileChooser(); + fcDlg.setDialogTitle("请选择.h文件路径..."); + fcDlg.setFileSelectionMode(JFileChooser.FILES_ONLY); + FileNameExtensionFilter filter = new FileNameExtensionFilter("文本文件(*.h)", "h"); + fcDlg.setMultiSelectionEnabled(true); + fcDlg.setFileFilter(filter); + int returnVal = fcDlg.showOpenDialog(null); + if (returnVal == JFileChooser.APPROVE_OPTION) { + String filepath = fcDlg.getSelectedFile().getPath(); + textField.setText(filepath); + } + } + } +} diff --git a/napi_IntelliJ_plugin/src/com/sk/action/SelectOutPathAction.java b/napi_IntelliJ_plugin/src/com/sk/action/SelectOutPathAction.java new file mode 100644 index 0000000000000000000000000000000000000000..dc7a6991307c6a667fce0fbb42762a85d2fc93da --- /dev/null +++ b/napi_IntelliJ_plugin/src/com/sk/action/SelectOutPathAction.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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 com.sk.action; + +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JTextField; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * 编译文件夹选择框 + * + * @author: zhaoxudong@kaihong.com + * @see: select generator file path + * @version: v1.0.0 + * @since 2022-02-21 + */ +public class SelectOutPathAction implements ActionListener { + private final JButton button; + private final JTextField textField; + + public SelectOutPathAction(JButton button, JTextField textField) { + this.button = button; + this.textField = textField; + } + + @Override + public void actionPerformed(ActionEvent actionEvent) { + if (actionEvent.getSource().equals(button)) { + JFileChooser fcDlg = new JFileChooser(); + fcDlg.setDialogTitle("请选择输出目录路径..."); + fcDlg.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + int returnVal = fcDlg.showOpenDialog(null); + if (returnVal == JFileChooser.APPROVE_OPTION) { + String filepath = fcDlg.getSelectedFile().getPath(); + textField.setText(filepath); + } + } + } +} diff --git a/napi_IntelliJ_plugin/src/com/sk/dialog/ConfirmDiagPane.java b/napi_IntelliJ_plugin/src/com/sk/dialog/ConfirmDiagPane.java index 62cc25feca56d0fd733efc19c436fdce7ca665e2..0711d7f895e43452e327ccdc0c6d58543c9d75d8 100644 --- a/napi_IntelliJ_plugin/src/com/sk/dialog/ConfirmDiagPane.java +++ b/napi_IntelliJ_plugin/src/com/sk/dialog/ConfirmDiagPane.java @@ -23,7 +23,7 @@ import javax.swing.ImageIcon; * ConfirmDiagPane自定义确认对话框 * 解决ShowConfirmDiag 在Deveco里面会出现界面错位问题。 * - * @author: xudong + * @author: zhaoxudong@kaihong.com * @see: generator error dialog * @version: v1.0.0 * @since 2022-02-21 diff --git a/napi_IntelliJ_plugin/src/com/sk/dialog/ErrorDialog.java b/napi_IntelliJ_plugin/src/com/sk/dialog/ErrorDialog.java index 263cc10fd50cde3a547fd85b773c00e93a5fc2d5..517768d6aed51e834351d5d4c11fba8953975f09 100644 --- a/napi_IntelliJ_plugin/src/com/sk/dialog/ErrorDialog.java +++ b/napi_IntelliJ_plugin/src/com/sk/dialog/ErrorDialog.java @@ -30,7 +30,7 @@ import java.io.IOException; /** * ErrorDialog错误对话框 * - * @author: xudong + * @author: zhaoxudong@kaihong.com * @see: generator error dialog * @version: v1.0.0 * @since 2022-02-21 diff --git a/napi_IntelliJ_plugin/src/com/sk/dialog/GenResultDialog.java b/napi_IntelliJ_plugin/src/com/sk/dialog/GenResultDialog.java index bb0b1617ea67edf10d48b86a65acb41e864885be..2f531c753d8d128480388239ad493661e86a0e17 100644 --- a/napi_IntelliJ_plugin/src/com/sk/dialog/GenResultDialog.java +++ b/napi_IntelliJ_plugin/src/com/sk/dialog/GenResultDialog.java @@ -27,7 +27,7 @@ import java.util.List; /** * GenResultDialog结果生成框 * - * @author: xudong + * @author: zhaoxudong@kaihong.com * @see: generate success dialog * @version: v1.0.0 * @since 2022-02-21 diff --git a/napi_IntelliJ_plugin/src/com/sk/dialog/GenerateDialog.java b/napi_IntelliJ_plugin/src/com/sk/dialog/GenerateDialog.java index 0a3cfdd54cde729cae22023eccdd62f3a53ca7ed..2bd25c1ced8b51d6c2f8c23302c56476d528e116 100644 --- a/napi_IntelliJ_plugin/src/com/sk/dialog/GenerateDialog.java +++ b/napi_IntelliJ_plugin/src/com/sk/dialog/GenerateDialog.java @@ -21,8 +21,9 @@ import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.ValidationInfo; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import javax.swing.JComponent; + import javax.swing.Action; +import javax.swing.JComponent; import java.awt.Desktop; import java.awt.event.ActionEvent; import java.io.IOException; @@ -32,7 +33,7 @@ import java.net.URISyntaxException; /** * 主界面对话框Wrapper * - * @author: liulongc digitalchina.com + * @author: zhaoxudong@kaihong.com * @see: tool conversion plug-in * @version: v1.0.0 * @since 2022-05-27 @@ -47,10 +48,10 @@ public class GenerateDialog extends DialogWrapper { /** * 构造函数 * - * @param project projectid - * @param destPath 目录文件 + * @param project projectId + * @param destPath 目录文件 * @param directoryPath 文件夹目录 - * @param fileName 文件名 + * @param fileName 文件名 */ public GenerateDialog(Project project, String destPath, String directoryPath, String fileName) { super(true); @@ -124,8 +125,14 @@ public class GenerateDialog extends DialogWrapper { if (validationInfo != null) { LOG.info(validationInfo.message); } else { - if (genDiag.runFun()) { - close(CANCEL_EXIT_CODE); + if (genDiag.getSelectedIndex() == 0) { + if (genDiag.runFun()) { + close(CANCEL_EXIT_CODE); + } + } else { + if (genDiag.runFunH2ts()) { + close(CANCEL_EXIT_CODE); + } } } } diff --git a/napi_IntelliJ_plugin/src/com/sk/dialog/GenerateDialogPane.form b/napi_IntelliJ_plugin/src/com/sk/dialog/GenerateDialogPane.form index 5ca7577ae1e2f16f8a3dd61c1ad7245cffbdff22..0893f9fabfcd4a3d21215edcb5c48b10da0fd71d 100644 --- a/napi_IntelliJ_plugin/src/com/sk/dialog/GenerateDialogPane.form +++ b/napi_IntelliJ_plugin/src/com/sk/dialog/GenerateDialogPane.form @@ -14,190 +14,282 @@ limitations under the License. -->
- - + + - + - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - - - - - - - - + - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/napi_IntelliJ_plugin/src/com/sk/dialog/GenerateDialogPane.java b/napi_IntelliJ_plugin/src/com/sk/dialog/GenerateDialogPane.java index dd51d711cf7c7299f663ef8e9575f436307bade2..afe5e86fdfa63545589e68ab7abbe04be8f5ee36 100644 --- a/napi_IntelliJ_plugin/src/com/sk/dialog/GenerateDialogPane.java +++ b/napi_IntelliJ_plugin/src/com/sk/dialog/GenerateDialogPane.java @@ -21,6 +21,8 @@ import com.intellij.openapi.ui.ValidationInfo; import com.sk.action.BrowseAction; import com.sk.action.GenAction; import com.sk.action.ScriptAction; +import com.sk.action.SelectHAction; +import com.sk.action.SelectOutPathAction; import com.sk.utils.FileUtil; import com.sk.utils.GenNotification; import org.apache.http.util.TextUtils; @@ -29,11 +31,13 @@ import org.jetbrains.annotations.Nullable; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JDialog; -import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; +import javax.swing.JTabbedPane; import javax.swing.JTextField; import javax.swing.KeyStroke; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; @@ -48,38 +52,39 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * GenerateDialogPane生成工具主界面 + * 配置对话框 * - * @author: xudong - * @see: select generate dialog + * @author: zhaoxudong@kaihong.com + * @see: generator dialog * @version: v1.0.0 * @since 2022-02-21 */ public class GenerateDialogPane extends JDialog { private static final Logger LOG = Logger.getInstance(GenerateDialogPane.class); - private static final String COMMAND_STATEMENT = "add_library(napitest SHARED tool_utility.cpp napitest.cpp " - + "napitest_middle.cpp)" + FileUtil.getNewline() + "target_link_libraries(napitest libace_napi.z.so)"; + private static final String COMMAND_STATEMENT = "add_library(napitest SHARED x_napi_tool.cpp napitest.cpp " + + "napitest_middle.cpp)" + FileUtil.getNewline() + "target_link_libraries(napitest libace_napi.z.so)"; private static final String REGEX = "napitest"; private static final Pattern LF_PATTERN = Pattern.compile(REGEX, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); - + private final Project project; private JPanel contentPane; - private JTextField interPath; - private JTextField genPath; - private JTextField scriptPath; - private JButton selectInter; - private JButton selectGenPath; - private JButton selectScriptPath; - private JLabel interText; - private JLabel genText; - private JLabel scriptText; + private JTabbedPane tabbedPane; + private JTextField textFieldSelectH; + private JTextField textFieldSelectOutPath; + private JTextField textFieldInterPath; + private JTextField textFieldGenPath; + private JTextField textFieldScriptPath; private JRadioButton radioButton; + private JButton buttonSelectInter; + private JButton buttonSelectGenPath; + private JButton buttonSelectScriptPath; + private JButton buttonSelectH; + private JButton buttonSelectOutPath; private boolean generateSuccess = true; private String sErrorMessage = ""; private String interFileOrDir; private String genOutDir; private String scriptOutDir; - private final Project project; - + private int selectedIndex; /** * 构造函数 @@ -90,27 +95,46 @@ public class GenerateDialogPane extends JDialog { * @param scriptDir 脚本目录 */ public GenerateDialogPane(Project project, String interFilePath, String genDir, String scriptDir) { + setContentPane(contentPane); + setModal(true); + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent windowEvent) { + onCancel(); + } + }); this.project = project; this.interFileOrDir = interFilePath; this.genOutDir = genDir; this.scriptOutDir = scriptDir; - - interText.setText("接口文件:"); - genText.setText("生成框架路径:"); - scriptText.setText("编译脚本路径:"); - - interPath.setText(interFileOrDir); - genPath.setText(genOutDir); - scriptPath.setText(genOutDir); - + if (FileUtil.patternFileNameH(scriptDir)) { + textFieldSelectH.setText(interFileOrDir); + textFieldSelectOutPath.setText(genOutDir); + tabbedPane.setSelectedIndex(1); + selectedIndex = 1; + } else { + textFieldInterPath.setText(interFileOrDir); + textFieldGenPath.setText(genOutDir); + textFieldScriptPath.setText(genOutDir); + } // call onCancel() on ESCAPE contentPane.registerKeyboardAction(actionEvent -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - BrowseAction browseAction = new BrowseAction(project, selectInter, interPath, genPath, scriptPath); - selectInter.addActionListener(browseAction); - selectGenPath.addActionListener(new GenAction(selectGenPath, genPath)); - selectScriptPath.addActionListener(new ScriptAction(selectScriptPath, scriptPath)); + BrowseAction browseAction = new BrowseAction(project, buttonSelectInter, textFieldInterPath, textFieldGenPath, + textFieldScriptPath); + buttonSelectInter.addActionListener(browseAction); + buttonSelectGenPath.addActionListener(new GenAction(buttonSelectGenPath, textFieldGenPath)); + buttonSelectScriptPath.addActionListener(new ScriptAction(buttonSelectScriptPath, textFieldScriptPath)); + buttonSelectH.addActionListener(new SelectHAction(buttonSelectH, textFieldSelectH)); + buttonSelectOutPath.addActionListener(new SelectOutPathAction(buttonSelectOutPath, textFieldSelectOutPath)); + tabbedPane.addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent changeEvent) { + JTabbedPane tabbedPane = (JTabbedPane) changeEvent.getSource(); + selectedIndex = tabbedPane.getSelectedIndex(); + } + }); } @Override @@ -136,26 +160,35 @@ public class GenerateDialogPane extends JDialog { */ @Nullable public ValidationInfo validationInfo() { - String fileInter = interPath.getText(); - String scriptDir = scriptPath.getText(); - String filegypDir = genPath.getText(); - boolean isEmptyFile = TextUtils.isEmpty(fileInter) - || TextUtils.isEmpty(scriptDir) - || TextUtils.isEmpty(filegypDir); - ValidationInfo validationInfo = null; - if (isEmptyFile) { - String warnMsg = "接口文件、框架、编译脚本路径不能为空"; - warningMessage(warnMsg); - validationInfo = new ValidationInfo(warnMsg); - return validationInfo; - } - - File file = new File(filegypDir + "/binding.gyp"); - if (file.exists()) { - ConfirmDialog confirmDialog = new ConfirmDialog("是否替换已存在的编译脚本?"); - if (!confirmDialog.showAndGet()) { - validationInfo = new ValidationInfo(String.format("不替换现有编译脚本:%s", file)); + if (selectedIndex == 0) { + String fileInter = textFieldInterPath.getText(); + String scriptDir = textFieldScriptPath.getText(); + String filegypDir = textFieldGenPath.getText(); + boolean isEmptyFile = + TextUtils.isEmpty(fileInter) || TextUtils.isEmpty(scriptDir) || TextUtils.isEmpty(filegypDir); + if (isEmptyFile) { + String warnMsg = "接口文件、框架、编译脚本路径不能为空"; + warningMessage(warnMsg); + validationInfo = new ValidationInfo(warnMsg); + return validationInfo; + } + File file = new File(filegypDir + "/binding.gyp"); + if (file.exists()) { + ConfirmDialog confirmDialog = new ConfirmDialog("是否替换已存在的编译脚本?"); + if (!confirmDialog.showAndGet()) { + validationInfo = new ValidationInfo(String.format("不替换现有编译脚本:%s", file)); + return validationInfo; + } + } + } else { + String hFile = textFieldSelectH.getText(); + String outPutDir = textFieldSelectOutPath.getText(); + boolean isEmptyFile = TextUtils.isEmpty(hFile) || TextUtils.isEmpty(outPutDir); + if (isEmptyFile) { + String warnMsg = "文件路径、输出路径不能为空"; + warningMessage(warnMsg); + validationInfo = new ValidationInfo(warnMsg); return validationInfo; } } @@ -167,8 +200,8 @@ public class GenerateDialogPane extends JDialog { } private void warningMessage(String title) { - String notiContent = "请选择接口文件或文件夹,生成框架路径,编译脚本路径"; - GenNotification.notifyMessage(this.project, notiContent, title, NotificationType.WARNING); + String notifyContent = "请选择接口文件或文件夹,生成框架路径,编译脚本路径"; + GenNotification.notifyMessage(this.project, notifyContent, title, NotificationType.WARNING); } /** @@ -178,20 +211,22 @@ public class GenerateDialogPane extends JDialog { */ public boolean runFun() { GenNotification.notifyMessage(this.project, "", "正在生成", NotificationType.INFORMATION); - interFileOrDir = interPath.getText(); - genOutDir = genPath.getText(); - scriptOutDir = scriptPath.getText(); - + interFileOrDir = textFieldInterPath.getText(); + genOutDir = textFieldGenPath.getText(); + scriptOutDir = textFieldScriptPath.getText(); + copyFileToLocalPath("header_parser"); String command; command = genCommand(); try { if (!TextUtils.isEmpty(command) && callExtProcess(command)) { - GenNotification.notifyMessage(project, genPath.getText(), "提示", NotificationType.INFORMATION, true); + GenNotification.notifyMessage(project, textFieldGenPath.getText(), "提示", + NotificationType.INFORMATION, true); return true; } } catch (IOException | InterruptedException ex) { - GenNotification.notifyMessage(project, genPath.getText(), "Command exec error", NotificationType.ERROR); + GenNotification.notifyMessage(project, textFieldGenPath.getText(), "Command exec error", + NotificationType.ERROR); LOG.error(ex); } return false; @@ -205,18 +240,42 @@ public class GenerateDialogPane extends JDialog { private String genCommand() { String sysName = System.getProperties().getProperty("os.name").toUpperCase(); String tmpDirFile = System.getProperty("java.io.tmpdir"); - String execFn; if (sysName.contains("WIN")) { - execFn = "cmds/win/napi_generator-win.exe"; + copyFileToLocalPath("napi_generator-win"); tmpDirFile += "napi_generator-win.exe"; } else if (sysName.contains("LINUX")) { - execFn = "cmds/linux/napi_generator-linux"; + copyFileToLocalPath("napi_generator-linux"); tmpDirFile += "napi_generator-linux"; } else { - execFn = "cmds/mac/napi_generator-macos"; + copyFileToLocalPath("napi_generator-macos"); tmpDirFile += "napi_generator-macos"; } File file = new File(tmpDirFile); + String command = file.toString(); + String inArgs = genInArgs(); + command += inArgs + " -o " + genOutDir + " -i " + radioButton.isSelected(); + return command; + } + + /** + * 拷贝文件到本地临时目录 + * + * @param fileName 文件名 + */ + private void copyFileToLocalPath(String fileName) { + String sysName = System.getProperties().getProperty("os.name").toUpperCase(); + String tmpDirFile = System.getProperty("java.io.tmpdir"); + String execFn; + if (sysName.contains("WIN")) { + execFn = "cmds/win/" + fileName + ".exe"; + tmpDirFile += fileName + ".exe"; + } else if (sysName.contains("LINUX")) { + execFn = "cmds/linux/" + fileName; + tmpDirFile += fileName; + } else { + execFn = "cmds/mac/" + fileName; + tmpDirFile += fileName; + } try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(execFn)) { if (inputStream == null) { throw new IOException("exec File InputStream is Null"); @@ -230,13 +289,7 @@ public class GenerateDialogPane extends JDialog { GenNotification.notifyMessage(this.project, e.getMessage(), "Can not Find File:" + execFn, NotificationType.ERROR); LOG.error(e); - - return ""; } - String command = file.toString(); - String inArgs = genInArgs(); - command += inArgs + " -o " + genOutDir + " -i " + radioButton.isSelected(); - return command; } /** @@ -245,7 +298,6 @@ public class GenerateDialogPane extends JDialog { * @return 生成后的值-f -d的值 */ private String genInArgs() { - String[] interArr = interFileOrDir.split(","); StringBuilder tsParam = new StringBuilder(" -f "); StringBuilder dirParam = new StringBuilder(" -d "); @@ -259,12 +311,12 @@ public class GenerateDialogPane extends JDialog { tsParam.append(interStr).append(","); } } - if (!TextUtils.isEmpty(tsParam.toString().replaceAll("-f", "")) - && !TextUtils.isBlank(tsParam.toString().replaceAll("-f", ""))) { + if (!TextUtils.isEmpty(tsParam.toString().replaceAll("-f", "")) && + !TextUtils.isBlank(tsParam.toString().replaceAll("-f", ""))) { inputCommand += tsParam.substring(0, tsParam.length() - 1); } - if (!TextUtils.isEmpty(dirParam.toString().replace("-d", "")) - && !TextUtils.isBlank(dirParam.toString().replace("-d", ""))) { + if (!TextUtils.isEmpty(dirParam.toString().replace("-d", "")) && + !TextUtils.isBlank(dirParam.toString().replace("-d", ""))) { inputCommand += dirParam.substring(0, dirParam.length() - 1); } } @@ -441,7 +493,59 @@ public class GenerateDialogPane extends JDialog { } } + /** + * 执行主程序入口 + * + * @return 执行状态 + */ + public boolean runFunH2ts() { + GenNotification.notifyMessage(this.project, "", "正在生成", NotificationType.INFORMATION); + copyFileToLocalPath("header_parser"); + String command; + command = genCommandH2ts(); + try { + if (!TextUtils.isEmpty(command) && callExtProcess(command)) { + GenNotification.notifyMessage(project, textFieldSelectOutPath.getText(), "提示", + NotificationType.INFORMATION, true); + return true; + } + } catch (IOException | InterruptedException ex) { + GenNotification.notifyMessage(project, textFieldSelectOutPath.getText(), "Command exec error", + NotificationType.ERROR); + LOG.error(ex); + } + return false; + } + + /** + * 生成命令行指令 + * + * @return 返回命令行执行内容 + */ + private String genCommandH2ts() { + String sysName = System.getProperties().getProperty("os.name").toUpperCase(); + String tmpDirFile = System.getProperty("java.io.tmpdir"); + if (sysName.contains("WIN")) { + copyFileToLocalPath("napi_generator-win"); + tmpDirFile += "napi_generator-win.exe"; + } else if (sysName.contains("LINUX")) { + copyFileToLocalPath("napi_generator-linux"); + tmpDirFile += "napi_generator-linux"; + } else { + copyFileToLocalPath("napi_generator-macos"); + tmpDirFile += "napi_generator-macos"; + } + File file = new File(tmpDirFile); + String command = file.toString(); + command += " -f " + textFieldSelectH.getText() + " -o " + textFieldSelectOutPath.getText(); + return command; + } + JPanel getContentPanel() { return contentPane; } + + public int getSelectedIndex() { + return selectedIndex; + } } diff --git a/napi_IntelliJ_plugin/src/com/sk/ng/GenDTS.java b/napi_IntelliJ_plugin/src/com/sk/ng/GenDTS.java index ac8f52ae36fa0057d9a29c157612b9c062ad94cd..5fa7b3f70564c866ee5d6c6926540028d75d1016 100644 --- a/napi_IntelliJ_plugin/src/com/sk/ng/GenDTS.java +++ b/napi_IntelliJ_plugin/src/com/sk/ng/GenDTS.java @@ -27,7 +27,7 @@ import com.sk.utils.GenNotification; /** * 项目文件入口 * - * @author: xudong + * @author: zhaoxudong@kaihong.com * @see: tool conversion plug-in * @version: v1.0.0 * @since 2022-02-21 diff --git a/napi_IntelliJ_plugin/src/com/sk/utils/FileUtil.java b/napi_IntelliJ_plugin/src/com/sk/utils/FileUtil.java index 7500b0eac5a8d30653643085a997f3b5719076ba..4ced0505bfc754816ce0958d7737d4fb41a2a9ac 100644 --- a/napi_IntelliJ_plugin/src/com/sk/utils/FileUtil.java +++ b/napi_IntelliJ_plugin/src/com/sk/utils/FileUtil.java @@ -34,7 +34,7 @@ import java.util.regex.Pattern; /** * 文本文件工具 * - * @author: xudong + * @author: zhaoxudong@kaihong.com * @see: file utils * @version: v1.0.0 * @since 2022-02-21 @@ -135,7 +135,18 @@ public class FileUtil { * @return boolean 是否匹配 */ public static boolean patternFileName(String fileName) { - String pattern = "@ohos.([.a-z_A-Z0-9]+).d.ts"; + String pattern = "(@ohos.([.a-z_A-Z0-9]+).d.ts|([.a-z_A-Z0-9]+).h)"; + return Pattern.matches(pattern, fileName); + } + + /** + * 正则匹配所选文件名是否符合规范 + * + * @param fileName 文件名 + * @return boolean 是否匹配 + */ + public static boolean patternFileNameH(String fileName) { + String pattern = "([.a-z_A-Z0-9]+).h"; return Pattern.matches(pattern, fileName); } diff --git a/napi_IntelliJ_plugin/src/com/sk/utils/GenNotification.java b/napi_IntelliJ_plugin/src/com/sk/utils/GenNotification.java index 68dc43744ce4e11ae2752f53c608c6eac74bf440..89aa908e42cd23fe65b9e95cafbc9bba3f0be4da 100644 --- a/napi_IntelliJ_plugin/src/com/sk/utils/GenNotification.java +++ b/napi_IntelliJ_plugin/src/com/sk/utils/GenNotification.java @@ -15,12 +15,10 @@ package com.sk.utils; import com.intellij.ide.actions.OpenFileAction; -import com.intellij.notification.NotificationType; import com.intellij.notification.Notification; -import com.intellij.notification.NotificationGroup; import com.intellij.notification.NotificationAction; +import com.intellij.notification.NotificationType; import com.intellij.notification.Notifications; -import com.intellij.notification.NotificationDisplayType; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; @@ -51,10 +49,8 @@ public class GenNotification { * @param title 提示栏内容 * @param type 提示类型 Error,Waring,info */ - public static void notifyMessage(@javax.annotation.Nullable Project project, - String content, - String title, - NotificationType type) { + public static void notifyMessage(@javax.annotation.Nullable Project project, String content, String title, + NotificationType type) { notifyMessage(project, content, title, type, false); } @@ -67,15 +63,10 @@ public class GenNotification { * @param type 提示类型 Error,Waring,info * @param addAct 是否添加action */ - public static void notifyMessage(@javax.annotation.Nullable Project project, - String content, - String title, - NotificationType type, - boolean addAct) { + public static void notifyMessage(@javax.annotation.Nullable Project project, String content, String title, + NotificationType type, boolean addAct) { - NotificationGroup notificationGroup = new NotificationGroup("Generate.Result.Group", - NotificationDisplayType.STICKY_BALLOON); - Notification notification = notificationGroup.createNotification(content, type); + Notification notification = new Notification("Generate.Result.Group", "Notes Message", content, type); notification.setTitle(title); notification.setContent(content);