diff --git a/OAT.xml b/OAT.xml
index df2e5ab5e353031e7fc3315cd8e84242bbd16fd2..e190b51e8e4dd5c05034970c1624f8efca80b2bf 100644
--- a/OAT.xml
+++ b/OAT.xml
@@ -64,9 +64,10 @@ Note:If the text contains special characters, please escape them according to th
+
-
+
diff --git a/napi_IntelliJ_plugin/generator/README_zh.md b/napi_IntelliJ_plugin/generator/README_zh.md
new file mode 100644
index 0000000000000000000000000000000000000000..a3202496d6206cb58831fbbf27fd1c3ba90d90f9
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/README_zh.md
@@ -0,0 +1,42 @@
+# IDEA插件开发环境配置
+
+基础环境要求:
+JDK 11 ,IDEA Community 2021.3.3
+
+1.下载IDEA Community 与 JDK11 配置好环境
+点击 https://www.jetbrains.com/idea/download/ 下载Community版本,并完成安装。
+
+
+2.打开IDEA Community 应用程序。
+依次点击项目File>Open 选择napi_generator/src/generator项目文件夹。
+
+
+3.项目配置
+项目打开完成,点击File>Project Structure
+
+
+
+4.配置Modules.
+Project Settings > Modules 新建Modules.点击上方“-”删除原有的Modules,“+”选择 New Modules。
+
+
+
+5.配置Module SDK.
+在New Modules对话框中,选择IntelliJ Platform Plugin。若为首次环境配置,请在Module SDK 下拉框中点击 Add IntelliJ Platform Plugin SDK 选择IDEA Community安装目录,点击OK,在Select Internal Java Platform 选择 JAVA SDK 11(213版本只支持 11)
+
+
+6.配置Root Content.
+在上图界面点击Next,选择Content root:为napi_generator/src/generator文件夹,module name会自动变为generator,若出现提示已存在是否覆盖的提示,请点“是”完成配置。
+
+
+
+7.配置完成Modules后,若在SDKs中无相应JDK和Plugin SDK,请点击+号分别添加 Add Java JDK和Add Intellij PlantForm Plugin SDK,Java JDK为java11的安装目录,Plugin SDK为 IDEA Community 2021.3.3的安装目录。
+
+
+8.若完成步骤7配置,点击OK完成配置。Rebuild项目,若IDEA依然不能点击右上角的运行。请重新配置一次Modules。
+
+9.项目运行成功后,会另起一个IDEA应用程序。插件运行在IDEA中,只需要新建一个Grandle Project,添加相应的TS文件到项目文件夹里面,就可以右击文件,选择Generate napi Frame出现插件主界面进行相应操作。
+
+10.在Deveco stdio中安装插件。
+请在IDEA Community中依次点击Build>Prepare Plugin Module " " for development"生成jar包(jar一般生成在generator目录下)。打开DevEco Studio 工具,点击File>settings>plugin。点击右方齿轮选择install plugin from disk选择jar包,点击确定完成。重新IDE完成安装
+
\ No newline at end of file
diff --git a/napi_IntelliJ_plugin/generator/resources/META-INF/plugin.xml b/napi_IntelliJ_plugin/generator/resources/META-INF/plugin.xml
new file mode 100644
index 0000000000000000000000000000000000000000..031258e0ec10abc1f4610b7b6eb04d34ab57a65f
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/resources/META-INF/plugin.xml
@@ -0,0 +1,59 @@
+
+ com.sk.ng
+ Napi Generator
+ 1.0
+ YourCompany
+
+ Introduction
+ One-click generation of NAPI framework code, business code framework, GN file, etc. according to the ts (typescript) interface file in the user-specified path.
+ When developing the interface between JS applications and NAPI, the developers of the underlying framework do not need to pay attention to the upper-level application conversion logic such as Nodejs syntax, data type conversion between C++ and JS, and only focus on the underlying business logic. Professional people do professional things. Thus, the development efficiency can be greatly improved
+
+ Sources on Gitee
+
+
+
+
+
+
+
+
+ ]]>
+
+
+ Features
+ ]]>
+
+
+
+
+
+
+ com.intellij.modules.platform
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/napi_IntelliJ_plugin/generator/resources/cmds/linux/INTELLIJ_README_LINUX_zh.md b/napi_IntelliJ_plugin/generator/resources/cmds/linux/INTELLIJ_README_LINUX_zh.md
new file mode 100644
index 0000000000000000000000000000000000000000..fbc3760dc4a556f8f7b72a9864d9335ec38b8200
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/resources/cmds/linux/INTELLIJ_README_LINUX_zh.md
@@ -0,0 +1,4 @@
+# 目录说明
+ 此目录用于存放napi_generator-linux可执行文件
+
+[可执行文件下载](http://ftpkaihongdigi.i234.me:5000/fsdownload/PPVcNMgVv/2022-06-13)
\ No newline at end of file
diff --git a/napi_IntelliJ_plugin/generator/resources/cmds/mac/INTELLIJ_README_MAC_zh.md b/napi_IntelliJ_plugin/generator/resources/cmds/mac/INTELLIJ_README_MAC_zh.md
new file mode 100644
index 0000000000000000000000000000000000000000..387afad4bd104ee81ce2e0d52cf2364a24067a26
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/resources/cmds/mac/INTELLIJ_README_MAC_zh.md
@@ -0,0 +1,4 @@
+# 目录说明
+ 此目录用于存放napi_generator-macos可执行文件
+
+[可执行文件下载](http://ftpkaihongdigi.i234.me:5000/fsdownload/PPVcNMgVv/2022-06-13)
\ No newline at end of file
diff --git a/napi_IntelliJ_plugin/generator/resources/cmds/win/INTELLIJ_README_WIN_zh.md b/napi_IntelliJ_plugin/generator/resources/cmds/win/INTELLIJ_README_WIN_zh.md
new file mode 100644
index 0000000000000000000000000000000000000000..6985f40f10bb7495db98132499a85f578e1f11eb
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/resources/cmds/win/INTELLIJ_README_WIN_zh.md
@@ -0,0 +1,4 @@
+# 目录说明
+ 此目录用于存放napi_generator-win.exe可执行文件
+
+[可执行文件下载](http://ftpkaihongdigi.i234.me:5000/fsdownload/PPVcNMgVv/2022-06-13)
\ No newline at end of file
diff --git a/napi_IntelliJ_plugin/generator/resources/images/openDisk.png b/napi_IntelliJ_plugin/generator/resources/images/openDisk.png
new file mode 100644
index 0000000000000000000000000000000000000000..5e66baa62e361484a32069b4277e269bcdce722f
Binary files /dev/null and b/napi_IntelliJ_plugin/generator/resources/images/openDisk.png differ
diff --git a/napi_IntelliJ_plugin/generator/resources/images/text.png b/napi_IntelliJ_plugin/generator/resources/images/text.png
new file mode 100644
index 0000000000000000000000000000000000000000..e2442e2b179f2069f6345e8bbff808c3e6b0bb05
Binary files /dev/null and b/napi_IntelliJ_plugin/generator/resources/images/text.png differ
diff --git a/napi_IntelliJ_plugin/generator/src/com/sk/action/BrowseAction.java b/napi_IntelliJ_plugin/generator/src/com/sk/action/BrowseAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..b8fca5f242d5246001aaca3c57676f10e2a662ae
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/src/com/sk/action/BrowseAction.java
@@ -0,0 +1,132 @@
+/*
+ * 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 com.intellij.notification.NotificationType;
+import com.intellij.openapi.project.Project;
+import com.sk.utils.FileUtil;
+import com.sk.utils.GenNotification;
+import org.apache.http.util.TextUtils;
+
+import javax.swing.JButton;
+import javax.swing.JTextField;
+import javax.swing.JFileChooser;
+import javax.swing.filechooser.FileNameExtensionFilter;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.util.prefs.Preferences;
+
+/**
+ * 接口文件选择框。
+ *
+ * @author: xudong
+ * @see: select file
+ * @version: v1.0.0
+ * @since 2022-02-21
+ */
+public class BrowseAction implements ActionListener {
+ private final JButton button;
+ private final JTextField interField;
+ private final JTextField genField;
+ private final JTextField scriptField;
+ private final Project project;
+
+
+ public BrowseAction(Project project, JButton button, JTextField interField,
+ JTextField geField, JTextField scriptField) {
+ this.project = project;
+ this.button = button;
+ this.interField = interField;
+ this.genField = geField;
+ this.scriptField = scriptField;
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent actionEvent) {
+ if (actionEvent.getSource().equals(button)) {
+ Preferences preferences = Preferences.userRoot();
+ JFileChooser fcDlg = new JFileChooser();
+
+ // 获取上次打开文件的路径。
+
+ String pathRecord = preferences.get("interPathRecord", "");
+ if (!pathRecord.equals("")) {
+ fcDlg = new JFileChooser(pathRecord);
+ }
+ fcDlg.setDialogTitle("请选择接口文件...");
+ fcDlg.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
+ FileNameExtensionFilter filter = new FileNameExtensionFilter("文本文件(*.ts)", "ts");
+ fcDlg.setMultiSelectionEnabled(true);
+ fcDlg.setFileFilter(filter);
+ int returnVal = fcDlg.showOpenDialog(null);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ String upPath = fcDlg.getSelectedFile().getParent();
+ File[] files = fcDlg.getSelectedFiles();
+ String interFile = setSelectFile(files);
+ if (TextUtils.isBlank(interFile)) {
+ return;
+ }
+
+ // 设置默认打开路径;
+
+ preferences.put("interPathRecord", upPath);
+ interField.setText(interFile.substring(0, interFile.length() - 1));
+ genField.setText(upPath);
+ scriptField.setText(upPath);
+ }
+ }
+ }
+
+ private String setSelectFile(File[] files) {
+ StringBuilder interFile = new StringBuilder();
+ boolean existFile = false;
+ boolean existDir = false;
+ for (File file : files) {
+ if (file.isDirectory()) {
+ if (!existDir) {
+ existDir = true;
+ interFile.append(file.getPath()).append(",");
+ } else {
+ GenNotification.notifyMessage(project,
+ "目前只支持单个文件夹转换",
+ "选择不符合要求",
+ NotificationType.WARNING);
+ interField.setText("");
+ return "";
+ }
+ } else {
+ if (!FileUtil.patternFileName(file.getName())) {
+ GenNotification.notifyMessage(project,
+ file.getPath(),
+ file.getName() + "文件名不符合",
+ NotificationType.WARNING);
+ return "";
+ }
+ existFile = true;
+ interFile.append(file.getPath()).append(",");
+ }
+ }
+ if (existDir && existFile) {
+ GenNotification.notifyMessage(project,
+ "不能同时转换文件和文件夹",
+ "选择不符合要求",
+ NotificationType.WARNING);
+ interField.setText("");
+ return "";
+ }
+ return interFile.toString();
+ }
+}
diff --git a/napi_IntelliJ_plugin/generator/src/com/sk/action/GenAction.java b/napi_IntelliJ_plugin/generator/src/com/sk/action/GenAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..bd6122f30d3d9fc78ef965894c2ebf84738d2538
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/src/com/sk/action/GenAction.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: xudong
+ * @see: select generator file path
+ * @version: v1.0.0
+ * @since 2022-02-21
+ */
+public class GenAction implements ActionListener {
+ private final JButton button;
+ private final JTextField textField;
+
+ public GenAction(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/generator/src/com/sk/action/ScriptAction.java b/napi_IntelliJ_plugin/generator/src/com/sk/action/ScriptAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..c2a172fb93003d7c2870666c4268f980a1372926
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/src/com/sk/action/ScriptAction.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: xudong
+ * @see: select compile script
+ * @version: v1.0.0
+ * @since 2022-02-21
+ */
+public class ScriptAction implements ActionListener {
+ private final JButton button;
+ private final JTextField textField;
+
+ public ScriptAction(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);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/napi_IntelliJ_plugin/generator/src/com/sk/dialog/ConfirmDiagPane.form b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/ConfirmDiagPane.form
new file mode 100644
index 0000000000000000000000000000000000000000..8ac1467b5c8fe9c2b089aa1f1f986568d15d63a3
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/ConfirmDiagPane.form
@@ -0,0 +1,61 @@
+
+
diff --git a/napi_IntelliJ_plugin/generator/src/com/sk/dialog/ConfirmDiagPane.java b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/ConfirmDiagPane.java
new file mode 100644
index 0000000000000000000000000000000000000000..62cc25feca56d0fd733efc19c436fdce7ca665e2
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/ConfirmDiagPane.java
@@ -0,0 +1,50 @@
+/*
+ * 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.dialog;
+
+import javax.swing.JPanel;
+import javax.swing.JLabel;
+import javax.swing.JDialog;
+import javax.swing.ImageIcon;
+
+/**
+ * ConfirmDiagPane自定义确认对话框
+ * 解决ShowConfirmDiag 在Deveco里面会出现界面错位问题。
+ *
+ * @author: xudong
+ * @see: generator error dialog
+ * @version: v1.0.0
+ * @since 2022-02-21
+ */
+public class ConfirmDiagPane extends JDialog {
+ private JPanel contentPane;
+ private JLabel msgLabel;
+ private JLabel iconLabel;
+
+ /**
+ * 构造函数
+ *
+ * @param sErrorMessage 错误信息
+ */
+ public ConfirmDiagPane(String sErrorMessage) {
+ msgLabel.setText(sErrorMessage);
+ iconLabel.setIcon(new ImageIcon(""));
+ }
+
+
+ JPanel getContentPanel() {
+ return contentPane;
+ }
+}
diff --git a/napi_IntelliJ_plugin/generator/src/com/sk/dialog/ConfirmDialog.java b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/ConfirmDialog.java
new file mode 100644
index 0000000000000000000000000000000000000000..7bcf2479d57018d721bd90978f09892362c3ddf4
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/ConfirmDialog.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2022 Guangzhou Digitalchina Information Technology Co., Ltd.
+ * All rights reserved.
+ * 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.dialog;
+
+import com.intellij.openapi.ui.DialogWrapper;
+import org.jetbrains.annotations.Nullable;
+import javax.swing.JComponent;
+
+/**
+ * 自定义确认对话框Wrapper
+ *
+ * @author: liulongc digitalchina.com
+ * @see: tool conversion plug-in
+ * @version: v1.0.0
+ * @since 2022-02-21
+ */
+public class ConfirmDialog extends DialogWrapper {
+ private final ConfirmDiagPane confirmDiagPane;
+
+ /**
+ * 构造函数
+ * @param message 弹出框信息内容
+ */
+ public ConfirmDialog(String message) {
+ super(true);
+ confirmDiagPane = new ConfirmDiagPane(message);
+ setOKButtonText("Yes");
+ setCancelButtonText("No");
+ setUndecorated(true);
+ setResizable(false);
+ init();
+ }
+
+ @Override
+ @Nullable
+ protected JComponent createCenterPanel() {
+ return confirmDiagPane.getContentPanel();
+ }
+
+}
diff --git a/napi_IntelliJ_plugin/generator/src/com/sk/dialog/ErrorDialog.form b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/ErrorDialog.form
new file mode 100644
index 0000000000000000000000000000000000000000..ae897a574268d86b0a299d3c6d3d649a924d28ff
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/ErrorDialog.form
@@ -0,0 +1,72 @@
+
+
diff --git a/napi_IntelliJ_plugin/generator/src/com/sk/dialog/ErrorDialog.java b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/ErrorDialog.java
new file mode 100644
index 0000000000000000000000000000000000000000..263cc10fd50cde3a547fd85b773c00e93a5fc2d5
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/ErrorDialog.java
@@ -0,0 +1,97 @@
+/*
+ * 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.dialog;
+
+import com.intellij.openapi.diagnostic.Logger;
+
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JDialog;
+import javax.swing.JPanel;
+import javax.swing.JTextArea;
+import javax.swing.KeyStroke;
+import java.awt.event.KeyEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.IOException;
+
+/**
+ * ErrorDialog错误对话框
+ *
+ * @author: xudong
+ * @see: generator error dialog
+ * @version: v1.0.0
+ * @since 2022-02-21
+ */
+public class ErrorDialog extends JDialog {
+ private static final Logger LOG = Logger.getInstance(ErrorDialog.class);
+ private static final String URL =
+ "rundll32 url.dll,FileProtocolHandler" + " https://gitee" + ".com/openharmony" + "-sig/napi_generator";
+
+ private JPanel contentPane;
+ private JButton buttonOK;
+ private JButton buttonHelp;
+ private JTextArea textAreaError;
+ private String errorMessage;
+
+ public ErrorDialog(String sErrorMessage) {
+ errorMessage = sErrorMessage;
+ }
+
+ /**
+ * 初始化
+ */
+ public void initDialog() {
+ setContentPane(contentPane);
+ setModal(true);
+ getRootPane().setDefaultButton(buttonOK);
+ setTitle("执行失败");
+ textAreaError.setText(errorMessage);
+ buttonOK.addActionListener(actionEvent -> onOK());
+
+ buttonHelp.addActionListener(actionEvent -> onCancel());
+
+ // call onCancel() when cross is clicked
+ setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
+ addWindowListener(new WindowAdapter() {
+ /**
+ * close dialog
+ * @param windowEvent WindowEvent
+ */
+ @Override
+ public void windowClosing(WindowEvent windowEvent) {
+ onCancel();
+ }
+ });
+
+ // call onCancel() on ESCAPE
+ contentPane.registerKeyboardAction(actionEvent -> onCancel(),
+ KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
+ JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
+ }
+
+ private void onOK() {
+ dispose();
+ }
+
+ private void onCancel() {
+ try {
+ Runtime.getRuntime().exec(URL);
+ } catch (IOException ioException) {
+ LOG.error("exec command help error" + ioException);
+ }
+ dispose();
+ }
+}
\ No newline at end of file
diff --git a/napi_IntelliJ_plugin/generator/src/com/sk/dialog/GenResultDialog.form b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/GenResultDialog.form
new file mode 100644
index 0000000000000000000000000000000000000000..b6e02973f844d7ac60601fc98e8393c098ddb9e8
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/GenResultDialog.form
@@ -0,0 +1,64 @@
+
+
diff --git a/napi_IntelliJ_plugin/generator/src/com/sk/dialog/GenResultDialog.java b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/GenResultDialog.java
new file mode 100644
index 0000000000000000000000000000000000000000..bb0b1617ea67edf10d48b86a65acb41e864885be
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/GenResultDialog.java
@@ -0,0 +1,82 @@
+/*
+ * 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.dialog;
+
+import com.intellij.openapi.diagnostic.Logger;
+
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * GenResultDialog结果生成框
+ *
+ * @author: xudong
+ * @see: generate success dialog
+ * @version: v1.0.0
+ * @since 2022-02-21
+ */
+public class GenResultDialog extends JDialog {
+ private static final Logger LOG = Logger.getInstance(GenResultDialog.class);
+
+ private JPanel contentPane;
+ private JButton buttonOK;
+ private JList resultList;
+ private String path;
+
+ public GenResultDialog(String directoryPath) {
+ path = directoryPath;
+ }
+
+ /**
+ * 初始化
+ */
+ public void initResultDialog() {
+ setContentPane(contentPane);
+ setModal(true);
+ getRootPane().setDefaultButton(buttonOK);
+ setTitle("执行成功");
+ buttonOK.addActionListener(actionEvent -> onOK());
+ List fileList = getDirFileName(path);
+ resultList.setListData(fileList.toArray(new String[fileList.size()]));
+ }
+
+ private void onOK() {
+ dispose();
+ }
+
+ private List getDirFileName(String path) {
+ List files = new ArrayList<>();
+ File file = new File(path);
+ if (!file.exists()) {
+ LOG.info("getDirFileName f not exist");
+ return files;
+ }
+ File[] fileArray = file.listFiles();
+ for (int i = 0; i < fileArray.length; i++) {
+ File fs = fileArray[i];
+ if (!fs.isDirectory()) {
+ files.add(fs.getPath());
+ } else {
+ LOG.info("getDirFileName this file is dir");
+ }
+ }
+ return files;
+ }
+}
diff --git a/napi_IntelliJ_plugin/generator/src/com/sk/dialog/GenerateDialog.java b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/GenerateDialog.java
new file mode 100644
index 0000000000000000000000000000000000000000..0a3cfdd54cde729cae22023eccdd62f3a53ca7ed
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/GenerateDialog.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2022 Guangzhou Digitalchina Information Technology Co., Ltd.
+ * All rights reserved.
+ * 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.dialog;
+
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.project.Project;
+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 java.awt.Desktop;
+import java.awt.event.ActionEvent;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+/**
+ * 主界面对话框Wrapper
+ *
+ * @author: liulongc digitalchina.com
+ * @see: tool conversion plug-in
+ * @version: v1.0.0
+ * @since 2022-05-27
+ */
+public class GenerateDialog extends DialogWrapper {
+ private static final Logger LOG = Logger.getInstance(GenerateDialog.class);
+ private static final String TITLE = "Generate Napi Frame";
+ private static final String URL = "https://gitee.com/openharmony/napi_generator";
+
+ private final GenerateDialogPane genDiag;
+
+ /**
+ * 构造函数
+ *
+ * @param project projectid
+ * @param destPath 目录文件
+ * @param directoryPath 文件夹目录
+ * @param fileName 文件名
+ */
+ public GenerateDialog(Project project, String destPath, String directoryPath, String fileName) {
+ super(true);
+ this.setResizable(false);
+ setTitle(TITLE);
+ setModal(true);
+ genDiag = new GenerateDialogPane(project, destPath, directoryPath, fileName);
+ init();
+ }
+
+ /**
+ * 创建视图
+ *
+ * @return 组件内容
+ */
+ @Nullable
+ @Override
+ protected JComponent createCenterPanel() {
+ return genDiag.getContentPanel();
+ }
+
+
+ /**
+ * 校验数据
+ *
+ * @return 检测文本框架是否有目录。
+ */
+ @Nullable
+ @Override
+ protected ValidationInfo doValidate() {
+ return genDiag.validationInfo();
+ }
+
+ /**
+ * ok/cancel按钮
+ *
+ * @return Action[] buttos list
+ */
+ @NotNull
+ @Override
+ protected Action[] createActions() {
+ DialogWrapperExitAction exitAction = new DialogWrapperExitAction("Cancel", CANCEL_EXIT_CODE);
+ CustomOKAction okAction = new CustomOKAction();
+
+ // 设置默认的焦点按钮
+ okAction.putValue(DialogWrapper.DEFAULT_ACTION, true);
+ return new Action[]{exitAction, okAction};
+ }
+
+ @NotNull
+ @Override
+ protected Action[] createLeftSideActions() {
+ CustomHelpAction helpAction = new CustomHelpAction();
+ return new Action[]{helpAction};
+ }
+
+ /**
+ * 自定义 ok Action
+ */
+ protected class CustomOKAction extends DialogWrapperAction {
+
+ protected CustomOKAction() {
+ super("OK");
+ }
+
+ @Override
+ protected void doAction(ActionEvent actionEvent) {
+
+
+ ValidationInfo validationInfo = doValidate();
+ if (validationInfo != null) {
+ LOG.info(validationInfo.message);
+ } else {
+ if (genDiag.runFun()) {
+ close(CANCEL_EXIT_CODE);
+ }
+ }
+ }
+ }
+
+ /**
+ * 自定义 help Action
+ */
+ protected class CustomHelpAction extends DialogWrapperAction {
+
+ protected CustomHelpAction() {
+ super("Help");
+ }
+
+ @Override
+ protected void doAction(ActionEvent actionEvent) {
+ try {
+ Desktop.getDesktop().browse(new URI(URL));
+ } catch (URISyntaxException | IOException e) {
+ LOG.error("Open help error:" + e);
+ }
+ }
+ }
+}
diff --git a/napi_IntelliJ_plugin/generator/src/com/sk/dialog/GenerateDialogPane.form b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/GenerateDialogPane.form
new file mode 100644
index 0000000000000000000000000000000000000000..f846b03becbc326490a985d9599b23fcd96e745b
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/GenerateDialogPane.form
@@ -0,0 +1,160 @@
+
+
diff --git a/napi_IntelliJ_plugin/generator/src/com/sk/dialog/GenerateDialogPane.java b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/GenerateDialogPane.java
new file mode 100644
index 0000000000000000000000000000000000000000..08ec063df0e78372872760dc83566286702430a4
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/src/com/sk/dialog/GenerateDialogPane.java
@@ -0,0 +1,447 @@
+/*
+ * 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.dialog;
+
+import com.intellij.notification.NotificationType;
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.ValidationInfo;
+import com.sk.action.BrowseAction;
+import com.sk.action.GenAction;
+import com.sk.action.ScriptAction;
+import com.sk.utils.FileUtil;
+import com.sk.utils.GenNotification;
+import org.apache.http.util.TextUtils;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.JComponent;
+import javax.swing.JDialog;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.JLabel;
+import javax.swing.JButton;
+import javax.swing.KeyStroke;
+import java.awt.event.KeyEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowListener;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * GenerateDialogPane生成工具主界面
+ *
+ * @author: xudong
+ * @see: select generate 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 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 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 boolean generateSuccess = true;
+ private String sErrorMessage = "";
+ private String interFileOrDir;
+ private String genOutDir;
+ private String scriptOutDir;
+ private final Project project;
+
+
+ /**
+ * 构造函数
+ *
+ * @param project projectid
+ * @param interFilePath 接口文件路径
+ * @param genDir 生成框架文件路径
+ * @param scriptDir 脚本目录
+ */
+ public GenerateDialogPane(Project project, String interFilePath, String genDir, String scriptDir) {
+ 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);
+
+ // 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));
+ }
+
+ @Override
+ public synchronized void addWindowListener(WindowListener windowListener) {
+ super.addWindowListener(windowListener);
+ new WindowAdapter() {
+ /**
+ * close dialog
+ *
+ * @param windowEvent WindowEvent
+ */
+ @Override
+ public void windowClosing(WindowEvent windowEvent) {
+ onCancel();
+ }
+ };
+ }
+
+ /**
+ * 验证文本选择框是否空。是否替换已存在的内容
+ *
+ * @return ValidationInfo 返回不符要求的信息。
+ */
+ @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));
+ return validationInfo;
+ }
+ }
+ return validationInfo;
+ }
+
+ private void onCancel() {
+ dispose();
+ }
+
+ private void warningMessage(String title) {
+ String notiContent = "请选择接口文件或文件夹,生成框架路径,编译脚本路径";
+ GenNotification.notifyMessage(this.project, notiContent, title, NotificationType.WARNING);
+ }
+
+ /**
+ * 执行主程序入口
+ *
+ * @return 执行状态
+ */
+ public boolean runFun() {
+ GenNotification.notifyMessage(this.project, "", "正在生成", NotificationType.INFORMATION);
+ interFileOrDir = interPath.getText();
+ genOutDir = genPath.getText();
+ scriptOutDir = scriptPath.getText();
+
+ String command;
+ command = genCommand();
+
+ try {
+ if (!TextUtils.isEmpty(command) && callExtProcess(command)) {
+ GenNotification.notifyMessage(project, genPath.getText(), "提示", NotificationType.INFORMATION, true);
+ return true;
+ }
+ } catch (IOException | InterruptedException ex) {
+ GenNotification.notifyMessage(project, genPath.getText(), "Command exec error", NotificationType.ERROR);
+ LOG.error(ex);
+ }
+ return false;
+ }
+
+ /**
+ * 生成命令行指令
+ *
+ * @return 返回命令行执行内容
+ */
+ 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";
+ tmpDirFile += "napi_generator-win.exe";
+ } else if (sysName.contains("LINUX")) {
+ execFn = "cmds/linux/napi_generator-linux";
+ tmpDirFile += "napi_generator-linux";
+ } else {
+ execFn = "cmds/mac/napi_generator-macos";
+ tmpDirFile += "napi_generator-macos";
+ }
+ File file = new File(tmpDirFile);
+ if (!file.exists()) {
+ try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(execFn)) {
+ if (inputStream == null) {
+ throw new IOException("exec File InputStream is Null");
+ }
+ byte[] bs = inputStream.readAllBytes();
+ writeTmpFile(tmpDirFile, bs);
+ if (sysName.contains("LINUX") || sysName.contains("MAC OS")) {
+ executable(tmpDirFile);
+ }
+ } catch (IOException | InterruptedException e) {
+ 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;
+ return command;
+ }
+
+ /**
+ * 生成 -f -d 输入参数。
+ *
+ * @return 生成后的值-f -d的值
+ */
+ private String genInArgs() {
+
+ String[] interArr = interFileOrDir.split(",");
+ StringBuilder tsParam = new StringBuilder(" -f ");
+ StringBuilder dirParam = new StringBuilder(" -d ");
+ String inputCommand = "";
+ if (interArr.length > 0) {
+ for (String interStr : interArr) {
+ File interFile = new File(interStr);
+ if (interFile.isDirectory()) {
+ dirParam.append(interStr).append(" ");
+ } else {
+ tsParam.append(interStr).append(",");
+ }
+ }
+ 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", ""))) {
+ inputCommand += dirParam.substring(0, dirParam.length() - 1);
+ }
+ }
+ return inputCommand;
+ }
+
+ private boolean callExtProcess(String command) throws IOException, InterruptedException {
+
+ if (TextUtils.isEmpty(command)) {
+ GenNotification.notifyMessage(this.project, "执行命令文件为空", "空命令行提示", NotificationType.ERROR);
+ return false;
+ }
+ Process process = Runtime.getRuntime().exec(command);
+ genResultLog(process);
+ StreamConsumer errConsumer = new StreamConsumer(process.getErrorStream());
+ StreamConsumer outputConsumer = new StreamConsumer(process.getInputStream());
+ errConsumer.start();
+ outputConsumer.start();
+
+ if (generateSuccess) {
+ writeCommand();
+ } else {
+ GenNotification.notifyMessage(project, sErrorMessage, "提示", NotificationType.ERROR);
+ return false;
+ }
+ errConsumer.join();
+ outputConsumer.join();
+ return true;
+ }
+
+ /**
+ * 写makeFile.txt文件
+ */
+ private void writeCommand() {
+ FileUtil fileUtil = new FileUtil();
+ String filePath = fileUtil.makeFile(genOutDir + "/makeFile.txt");
+ if (TextUtils.isEmpty(filePath)) {
+ LOG.info("makeFile is fail");
+ return;
+ }
+ Matcher matcher = LF_PATTERN.matcher(COMMAND_STATEMENT);
+ String statement = matcher.replaceAll(scriptOutDir);
+ try {
+ if (!fileUtil.findStringInFile(filePath, statement)) {
+ fileUtil.writeErrorToTxt(filePath, statement);
+ }
+ } catch (IOException ioException) {
+ LOG.error("writeCommand io error" + ioException);
+ }
+ }
+
+ /**
+ * 赋值可执行文件权限。
+ *
+ * @param execFn 可执行命令
+ * @throws IOException 打开文件异常
+ * @throws InterruptedException 中断异常
+ */
+ private void executable(String execFn) throws IOException, InterruptedException {
+ callExtProcess("chmod a+x " + execFn);
+ }
+
+ /**
+ * 拷贝可执行文件到临时文件夹
+ *
+ * @param path 目标文件路径
+ * @param bs 字节内容
+ * @throws IOException exception
+ */
+ private void writeTmpFile(String path, byte[] bs) throws IOException {
+ File file = new File(path);
+ if (!file.exists()) {
+ boolean isNewFile = file.createNewFile();
+ if (!isNewFile) {
+ LOG.info("writeTmpFile createNewFile error");
+ }
+ }
+ FileOutputStream fw = new FileOutputStream(file);
+ fw.write(bs, 0, bs.length);
+ fw.close();
+ }
+
+ /**
+ * 获取生成成功结果文件。
+ *
+ * @param process 进程ID
+ */
+ private void genResultLog(Process process) {
+ BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+ String sErr;
+ String sOut;
+ sErr = getErrorResult(stdError);
+ if (TextUtils.isEmpty(sErr)) {
+ sOut = genInputLog(stdInput);
+ if (!generateIsSuccess(sOut)) {
+ sErrorMessage = sOut;
+ }
+ return;
+ }
+ generateSuccess = false;
+ sErrorMessage = sErr;
+ }
+
+ /**
+ * 获取生成失败结果文件。
+ *
+ * @param stdError error buff
+ * @return ErrorResult
+ */
+ private String getErrorResult(BufferedReader stdError) {
+ StringBuilder sErr = new StringBuilder();
+ while (true) {
+ String sTmp;
+ try {
+ if ((sTmp = stdError.readLine()) == null) {
+ break;
+ }
+ sErr.append(sTmp).append(FileUtil.getNewline());
+ } catch (IOException ioException) {
+ LOG.error(" genResultLog stdInput error" + ioException);
+ }
+ }
+ return sErr.toString();
+ }
+
+ private boolean generateIsSuccess(String sOut) {
+ generateSuccess = sOut.contains("success") || TextUtils.isEmpty(sOut);
+ return generateSuccess;
+ }
+
+ /**
+ * 获取生成文本内容。
+ *
+ * @param stdInput input buff
+ * @return 返回当前输入框内容
+ */
+ private String genInputLog(BufferedReader stdInput) {
+ StringBuilder sOut = new StringBuilder();
+ while (true) {
+ String sTmp;
+ try {
+ if ((sTmp = stdInput.readLine()) == null) {
+ break;
+ }
+ sOut.append(sTmp).append(FileUtil.getNewline());
+ } catch (IOException ioException) {
+ LOG.error(" genResultLog stdInput error" + ioException);
+ }
+ }
+ return sOut.toString();
+ }
+
+ static class StreamConsumer extends Thread {
+ InputStream is;
+
+ StreamConsumer(InputStream is) {
+ super.setName("StreamConsumer");
+ this.is = is;
+ }
+
+ @Override
+ public void run() {
+ try {
+ InputStreamReader isr = new InputStreamReader(is);
+ BufferedReader br = new BufferedReader(isr);
+ String line;
+ while ((line = br.readLine()) != null) {
+ LOG.error("StreamConsumer" + line);
+ }
+ } catch (IOException ioException) {
+ LOG.error("StreamConsumer io error" + ioException);
+ }
+ }
+ }
+
+ JPanel getContentPanel() {
+ return contentPane;
+ }
+}
diff --git a/napi_IntelliJ_plugin/generator/src/com/sk/ng/GenDTS.java b/napi_IntelliJ_plugin/generator/src/com/sk/ng/GenDTS.java
new file mode 100644
index 0000000000000000000000000000000000000000..020bc614d318c25b005e9922fe35d72d6b3a0a15
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/src/com/sk/ng/GenDTS.java
@@ -0,0 +1,73 @@
+/*
+ * 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.ng;
+
+import com.intellij.notification.NotificationType;
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.PlatformDataKeys;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.sk.dialog.GenerateDialog;
+import com.sk.utils.FileUtil;
+import com.sk.utils.GenNotification;
+
+/**
+ * 项目文件入口
+ *
+ * @author: xudong
+ * @see: tool conversion plug-in
+ * @version: v1.0.0
+ * @since 2022-02-21
+ */
+public class GenDTS extends AnAction {
+
+ @Override
+ public void actionPerformed(AnActionEvent anActionEvent) {
+ Project project = anActionEvent.getProject();
+ // 获取需要处理的.d.ts文件绝对路径
+ VirtualFile file = anActionEvent.getData(PlatformDataKeys.VIRTUAL_FILE);
+ if (file == null) {
+ GenNotification.notifyMessage(project, "", "file is not exist", NotificationType.ERROR);
+ return;
+ }
+ if (project == null) {
+ return;
+ }
+ String baseFile = project.getBasePath();
+
+ if (FileUtil.checkProjectSDK(project, baseFile)) {
+ return;
+ }
+
+ String destPath = file.getPath();
+ String directoryPath = file.getParent().getPath();
+ String fileName = file.getName();
+ GenerateDialog wrapper = new GenerateDialog(project, destPath, directoryPath, fileName);
+ wrapper.showAndGet();
+ }
+
+
+ @Override
+ public void update(AnActionEvent event) {
+ // 根据所选文件名,判断是否显示生成菜单项
+ VirtualFile file = event.getData(PlatformDataKeys.VIRTUAL_FILE);
+ if (file == null) {
+ event.getPresentation().setEnabledAndVisible(false);
+ } else {
+ event.getPresentation().setEnabledAndVisible(FileUtil.patternFileName(file.getName()));
+ }
+ }
+}
diff --git a/napi_IntelliJ_plugin/generator/src/com/sk/ng/GenMenuDTS.java b/napi_IntelliJ_plugin/generator/src/com/sk/ng/GenMenuDTS.java
new file mode 100644
index 0000000000000000000000000000000000000000..f69f004996d4a6364a71a7d14a07d9f43f3f3286
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/src/com/sk/ng/GenMenuDTS.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2022 Guangzhou Digitalchina Information Technology 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.ng;
+
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.project.Project;
+import com.sk.dialog.GenerateDialog;
+import com.sk.utils.FileUtil;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * 工具菜单入口
+ *
+ * @author: liulongc digitalchina.com
+ * @see: tool conversion plug-in
+ * @version: v1.0.0
+ * @since 2022-05-27
+ */
+public class GenMenuDTS extends AnAction {
+
+ @Override
+ public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
+ Project project = anActionEvent.getProject();
+
+ if (project == null) {
+ return;
+ }
+ String baseFile = project.getBasePath();
+
+ if (FileUtil.checkProjectSDK(project, baseFile)) {
+ return;
+ }
+
+ GenerateDialog wrapper = new GenerateDialog(project, "", "", "");
+ wrapper.showAndGet();
+ }
+
+}
diff --git a/napi_IntelliJ_plugin/generator/src/com/sk/utils/FileUtil.java b/napi_IntelliJ_plugin/generator/src/com/sk/utils/FileUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..7500b0eac5a8d30653643085a997f3b5719076ba
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/src/com/sk/utils/FileUtil.java
@@ -0,0 +1,187 @@
+/*
+ * 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.utils;
+
+import com.intellij.notification.NotificationType;
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.project.Project;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.util.TextUtils;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.InputStreamReader;
+import java.io.FileInputStream;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.FileNotFoundException;
+import java.nio.charset.StandardCharsets;
+import java.util.Properties;
+import java.util.regex.Pattern;
+
+/**
+ * 文本文件工具
+ *
+ * @author: xudong
+ * @see: file utils
+ * @version: v1.0.0
+ * @since 2022-02-21
+ */
+public class FileUtil {
+ private static final Logger LOG = Logger.getInstance(FileUtil.class);
+
+ private static final int COMPILE_SDK_VERSION = 5;
+
+ /**
+ * 将错误信息输入到txt中
+ *
+ * @param path 路径
+ * @param content 内容
+ */
+ public void writeErrorToTxt(String path, String content) {
+ File file = new File(path);
+ try (FileWriter fw = new FileWriter(file, true)) {
+ fw.write(content + FileUtil.getNewline());
+ } catch (IOException ioException) {
+ LOG.error("writeErrorToTxt io error" + ioException);
+ }
+ }
+
+ /**
+ * 创建文件
+ *
+ * @param path 文件路径
+ * @return 文件路径
+ */
+ public String makeFile(String path) {
+ File file = new File(path);
+ if (!file.exists()) {
+ try {
+ boolean isCreateFile = file.createNewFile();
+ if (isCreateFile) {
+ LOG.info(String.format("makeFile %s success", path));
+ }
+ } catch (IOException ioException) {
+ LOG.error(String.format("makeFile %s error:%s", path, ioException));
+ return "";
+ }
+ }
+ return file.getPath();
+ }
+
+ /**
+ * 判断文件是否包含指定字符串
+ *
+ * @param path 文件路径
+ * @param content 指定内容
+ * @return 是否包含指定字符串
+ * @throws IOException 异常信息
+ */
+ public boolean findStringInFile(String path, String content) throws IOException {
+ File file = new File(path);
+ String[] command = content.split(StringUtils.LF);
+
+ try (InputStreamReader read = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
+ BufferedReader bufferedReader = new BufferedReader(read)) {
+ return isContainString(bufferedReader, command);
+ } catch (FileNotFoundException foundException) {
+ LOG.error("file not found" + foundException);
+ return false;
+ }
+ }
+
+ private boolean isContainString(BufferedReader bufferedReader, String[] command) {
+ String line = null;
+ while (true) {
+ try {
+ if ((line = bufferedReader.readLine()) == null) {
+ return false;
+ }
+ } catch (IOException ioException) {
+ LOG.error("findStringInFile IOException" + ioException);
+ }
+ line += line;
+ if (line.contains(command[0])) {
+ return true;
+ }
+ }
+ }
+
+ /**
+ * 获取换行符
+ *
+ * @return 换行符
+ */
+ public static String getNewline() {
+ return System.getProperty("line.separator");
+ }
+
+ /**
+ * 正则匹配所选文件名是否符合规范
+ *
+ * @param fileName 文件名
+ * @return boolean 是否匹配
+ */
+ public static boolean patternFileName(String fileName) {
+ String pattern = "@ohos.([.a-z_A-Z0-9]+).d.ts";
+ return Pattern.matches(pattern, fileName);
+ }
+
+ /**
+ * check project SDK
+ *
+ * @param project projectid
+ * @param baseFile project root file
+ * @return boolean
+ */
+ public static boolean checkProjectSDK(Project project, String baseFile) {
+
+ String gradlePath = "";
+ File baseDir = new File(baseFile);
+ if (baseDir.isDirectory()) {
+ File[] childFile = baseDir.listFiles();
+ assert childFile != null;
+ for (File file : childFile) {
+ if (file.getName().equals("build.gradle") || file.getName().equals("build-profile.json5")) {
+ gradlePath = file.getPath();
+ }
+ }
+ }
+
+ Properties properties = new Properties();
+ if (TextUtils.isBlank(gradlePath)) {
+ GenNotification.notifyMessage(project, "项目结构中没有grandle配置文件。",
+ "当前项目结构不支持",
+ NotificationType.WARNING);
+ return true;
+ }
+ try {
+ properties.load(new FileInputStream(gradlePath));
+ } catch (IOException e) {
+ GenNotification.notifyMessage(project, e.getMessage(), "提示", NotificationType.ERROR);
+ LOG.error(String.format("Can not load file :%s . %s", gradlePath, e));
+ return true;
+ }
+ String ohosSDK = properties.getProperty("compileSdkVersion");
+
+ if (ohosSDK != null && Integer.parseInt(ohosSDK) < COMPILE_SDK_VERSION) {
+ GenNotification.notifyMessage(project, "SKD版本过低,NAPI仅支持5.0及以上版本",
+ "提示",
+ NotificationType.WARNING);
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/napi_IntelliJ_plugin/generator/src/com/sk/utils/GenNotification.java b/napi_IntelliJ_plugin/generator/src/com/sk/utils/GenNotification.java
new file mode 100644
index 0000000000000000000000000000000000000000..68dc43744ce4e11ae2752f53c608c6eac74bf440
--- /dev/null
+++ b/napi_IntelliJ_plugin/generator/src/com/sk/utils/GenNotification.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2022 Guangzhou Digitalchina Information Technology 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.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.Notifications;
+import com.intellij.notification.NotificationDisplayType;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.project.Project;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.File;
+
+/**
+ * 通知框
+ *
+ * @author: liulongc digitalchina.com
+ * @see: tool conversion plug-in
+ * @version: v1.0.0
+ * @since 2022-05-27
+ */
+public class GenNotification {
+
+ private static final Logger LOG = Logger.getInstance(FileUtil.class);
+
+ private GenNotification() {
+ }
+
+ /**
+ * 无action 通知
+ *
+ * @param project projectid
+ * @param content 提示内容
+ * @param title 提示栏内容
+ * @param type 提示类型 Error,Waring,info
+ */
+ public static void notifyMessage(@javax.annotation.Nullable Project project,
+ String content,
+ String title,
+ NotificationType type) {
+ notifyMessage(project, content, title, type, false);
+ }
+
+ /**
+ * 消息通知
+ *
+ * @param project projectid
+ * @param content 提示内容
+ * @param title 提示栏内容
+ * @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) {
+
+ NotificationGroup notificationGroup = new NotificationGroup("Generate.Result.Group",
+ NotificationDisplayType.STICKY_BALLOON);
+ Notification notification = notificationGroup.createNotification(content, type);
+ notification.setTitle(title);
+ notification.setContent(content);
+
+ if (NotificationType.ERROR.equals(type)) {
+ LOG.error(content);
+ } else if (NotificationType.WARNING.equals(type)) {
+ LOG.warn(content);
+ } else {
+ LOG.info(content);
+ }
+
+ if (addAct) {
+ notification.setContent(null);
+ addAction(project, content, notification);
+ }
+ Notifications.Bus.notify(notification, project);
+
+ }
+
+ private static void addAction(Project project, String dirPath, Notification notification) {
+ File genResultPath = new File(dirPath);
+ if (!genResultPath.exists()) {
+ LOG.info(String.format("%s not exist", genResultPath.getPath()));
+ }
+ LOG.info("generated file list log:");
+
+ File[] fa = genResultPath.listFiles();
+ for (int i = 0; i < fa.length; i++) {
+ File fs = fa[i];
+ String fileName = fs.getName();
+ boolean dissFile = !fileName.endsWith(".log") || !fileName.endsWith(".txt") || !fileName.endsWith(".ts");
+ if (!fs.isDirectory() && dissFile) {
+ String filePath = fs.getPath();
+ NotificationAction action = new NotificationAction(filePath) {
+ @Override
+ public void actionPerformed(@NotNull AnActionEvent anActionEvent,
+ @NotNull Notification notification) {
+ OpenFileAction.openFile(filePath, project);
+ }
+ };
+ notification.addAction(action);
+ } else {
+ LOG.info(String.format("%s is Directory", fs.getPath()));
+ }
+ }
+ }
+}