diff --git a/README_zh.md b/README_zh.md
index ba6a971617816311d233e263e0b6041305be90a2..38ecd7ee22a5c340021d99afcac7c651662a3b91 100755
--- a/README_zh.md
+++ b/README_zh.md
@@ -47,7 +47,7 @@
工具有三种类型,分别是可执行文件、VS Code插件、IntelliJ插件。其中的可执行文件可根据工具使用者的开发环境选择,支持Windows,Linux和Mac。可执行文件、IntelliJ插件、VS Code插件下载路径如下,选择napi_generator_outputs.zip下载。
-[下载链接](http://ftpkaihongdigi.i234.me:5000/fsdownload/PPVcNMgVv/2022-06-13)
+[下载链接](http://ftpkaihongdigi.i234.me:5000/fsdownload/GGsW3B68u/generator_outputs)
具体的工具使用步骤,可以左键单击以下链接了解:
diff --git a/docs/DEVELOP_ZH.md b/docs/DEVELOP_ZH.md
index 467eb5fcad168c64e7085507ebeb269cc13a9eeb..38fef839e111b22ad6ef86f6dc52aed69ebcb6ee 100755
--- a/docs/DEVELOP_ZH.md
+++ b/docs/DEVELOP_ZH.md
@@ -169,7 +169,7 @@
3.基础环境配置按照IDEA插件开发环境配置操作,确保项目可运行,且.d.ts文件可正常生成框架代码。
-[IDEA插件开发环境配置](https://gitee.com/openharmony/napi_generator/blob/master/src/generator/README_zh.md)
+[IDEA插件开发环境配置](https://gitee.com/openharmony/napi_generator/blob/master/napi_IntelliJ_plugin/README_zh.md)
4.点击Intellij IDEA工具右上角Built Project按钮,等待工程built完成。
diff --git a/docs/INSTRUCTION_ZH.md b/docs/INSTRUCTION_ZH.md
index b6d337aa61089b5705bb479adeea4c4c6658b9f5..db6b10d2c2476840e967a5b36bff735434e58e73 100755
--- a/docs/INSTRUCTION_ZH.md
+++ b/docs/INSTRUCTION_ZH.md
@@ -3,7 +3,7 @@
NAPI框架生成工具支持三种入口,分别是可执行程序、VS Code插件、IntelliJ插件,使用者可以根据自己的需要选择合适的工具。可执行文件、IntelliJ插件、VS Code插件下载路径如下,选择napi_generator_outputs.zip下载。
-[下载链接](http://ftpkaihongdigi.i234.me:5000/fsdownload/PPVcNMgVv/2022-06-13)
+[下载链接](http://ftpkaihongdigi.i234.me:5000/fsdownload/GGsW3B68u/generator_outputs)
下载文件说明如下:
diff --git a/src/generator/README_zh.md b/src/generator/README_zh.md
deleted file mode 100644
index 7f5e8f8317ecb808e78bdb6726942b8141599da9..0000000000000000000000000000000000000000
--- a/src/generator/README_zh.md
+++ /dev/null
@@ -1,65 +0,0 @@
-# IDEA插件开发环境配置
-
-## 基础环境准备
-
-### 约束
-JDK 11 ,IDEA Community 2021.3.3
-
-### 步骤
-
-1.将napi_generator目录下的可执行文件分别放置在napi_generator\src\generator\resources\cmds目录下对应系统的文件夹下。
-
-2.下载IDEA Community 与 JDK11 配置好环境。
-点击 https://www.jetbrains.com/idea/download/ 下载Community版本,并完成安装。
-
-3.打开IDEA Community 应用程序。
-依次点击项目File>Open 选择napi_generator/src/generator项目文件夹。
-
-
-4.项目配置
-项目打开完成,点击File>Project Structure。
-
-
-5.配置Modules
-Project Settings > Modules 新建Modules。点击上方“-”删除原有的Modules,然后点击“+”选择 New Module。
-
-
-6.配置Module SDK.
-在New Module对话框中,选择IntelliJ Platform Plugin。若为首次环境配置,请在Module SDK 下拉框中点击 Add IntelliJ Platform Plugin SDK 选择IDEA Community安装目录,点击OK,在Select Internal Java Platform 选择 JAVA SDK 11(213版本只支持 11),点击New Module对话框中Next。
-
-
-7.配置Content root.
-
-Content root选择napi_generator/src/generator文件夹,module name会自动变为generator。点击Finish,若出现提示已存在是否覆盖的提示,请点“Yes”完成配置。
-
-
-8.Modules配置完成后,若在SDKs中无相应JDK和Plugin SDK,请点击+号分别添加 Add Java JDK和Add Intellij PlantForm Plugin SDK,Java JDK为java11的安装目录,Plugin SDK为 IDEA Community 2021.3.3的安装目录。
-
-
-9.若完成步骤7配置,点击OK完成配置。Rebuild项目,若IDEA不能点击右上角的运行,点击Plugin后下三角选择Edit Configurations...选项,Run/Debug Configurations框中Use classpath of moudle选择generator,点击ok,等待安装完成,即可点击运行按钮。若IDEA依然不能点击右上角的运行,请重复以上全部操作。
-
-
-
-
-
-## 配置开发调试环境
-
-1.IntelliJ IDEA工具进入上述generator项目页面,执行右上角的run。
-
-
-
-2.IntelliJ IDEA会自动拉起一个应用程序,首次运行若没有项目,可选择Welcome to IntelliJ IDEA框中点击New Project新建项目。然后在New Project框中左侧选择Gradle,右侧Project SDK选择11,点击next;根据需要修改Location,最后点击Finish,完成配置。
-
-
-
-
-
-3.在新打开项目中,将.d.ts文件放入untitled\src\main\resources路径下。并且检查需要转换的d.ts文件中是否声明了import的d.ts文件,如果存在需要将import的d.ts文件也放入到untitled\src\main\resources路径下。选择.d.ts文件,右键选择generate Napi Frame选项,工具打开generate Napi Frame弹窗。接口文件路径默认填写,此处不修改;生成框架路径默认填写,此处修改为新增out文件夹下;编译脚本路径默认填写,不修改。点击ok,生成文件。
-
-
-
-
-
-4.执行结束后会在目录下生成对应的文件。
-
-
\ No newline at end of file
diff --git a/src/generator/resources/META-INF/plugin.xml b/src/generator/resources/META-INF/plugin.xml
deleted file mode 100644
index 94fa46a5110774904f5adab4bd9666c61087b818..0000000000000000000000000000000000000000
--- a/src/generator/resources/META-INF/plugin.xml
+++ /dev/null
@@ -1,60 +0,0 @@
-
- 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
-
-
-
-
-
-
-
-
- ]]>
-
-
-
- most HTML tags may be used
- ]]>
-
-
-
-
-
-
- com.intellij.modules.platform
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/generator/resources/cmds/linux/INTELLIJ_README_LINUX_zh.md b/src/generator/resources/cmds/linux/INTELLIJ_README_LINUX_zh.md
deleted file mode 100644
index 1b8c11eee30ca1ee7fc8c3f4b872158faca40bbf..0000000000000000000000000000000000000000
--- a/src/generator/resources/cmds/linux/INTELLIJ_README_LINUX_zh.md
+++ /dev/null
@@ -1,4 +0,0 @@
-# 目录说明
- 此目录用于存放napi_generator-linux可执行文件
-
-[可执行文件下载](https://repo.huaweicloud.com/harmonyos/develop_tools/napi_generator/napi_generator_20220319.tart.gz)
\ No newline at end of file
diff --git a/src/generator/resources/cmds/mac/INTELLIJ_README_MAC_zh.md b/src/generator/resources/cmds/mac/INTELLIJ_README_MAC_zh.md
deleted file mode 100644
index 75f137f8d0975e5fae73239aa7faca703f234f8a..0000000000000000000000000000000000000000
--- a/src/generator/resources/cmds/mac/INTELLIJ_README_MAC_zh.md
+++ /dev/null
@@ -1,4 +0,0 @@
-# 目录说明
- 此目录用于存放napi_generator-macos可执行文件
-
-[可执行文件下载](https://repo.huaweicloud.com/harmonyos/develop_tools/napi_generator/napi_generator_20220319.tart.gz)
\ No newline at end of file
diff --git a/src/generator/resources/cmds/win/INTELLIJ_README_WIN_zh.md b/src/generator/resources/cmds/win/INTELLIJ_README_WIN_zh.md
deleted file mode 100644
index 41cc6fa6943aad0cd5059db686af0637d61da6a8..0000000000000000000000000000000000000000
--- a/src/generator/resources/cmds/win/INTELLIJ_README_WIN_zh.md
+++ /dev/null
@@ -1,4 +0,0 @@
-# 目录说明
- 此目录用于存放napi_generator-win.exe可执行文件
-
-[可执行文件下载](https://repo.huaweicloud.com/harmonyos/develop_tools/napi_generator/napi_generator_20220319.tart.gz)
\ No newline at end of file
diff --git a/src/generator/resources/images/openDisk.png b/src/generator/resources/images/openDisk.png
deleted file mode 100644
index 5e66baa62e361484a32069b4277e269bcdce722f..0000000000000000000000000000000000000000
Binary files a/src/generator/resources/images/openDisk.png and /dev/null differ
diff --git a/src/generator/resources/images/text.png b/src/generator/resources/images/text.png
deleted file mode 100644
index e2442e2b179f2069f6345e8bbff808c3e6b0bb05..0000000000000000000000000000000000000000
Binary files a/src/generator/resources/images/text.png and /dev/null differ
diff --git a/src/generator/src/com/sk/action/BrowseAction.java b/src/generator/src/com/sk/action/BrowseAction.java
deleted file mode 100644
index b8fca5f242d5246001aaca3c57676f10e2a662ae..0000000000000000000000000000000000000000
--- a/src/generator/src/com/sk/action/BrowseAction.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * 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/src/generator/src/com/sk/action/GenAction.java b/src/generator/src/com/sk/action/GenAction.java
deleted file mode 100644
index bd6122f30d3d9fc78ef965894c2ebf84738d2538..0000000000000000000000000000000000000000
--- a/src/generator/src/com/sk/action/GenAction.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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/src/generator/src/com/sk/action/ScriptAction.java b/src/generator/src/com/sk/action/ScriptAction.java
deleted file mode 100644
index c2a172fb93003d7c2870666c4268f980a1372926..0000000000000000000000000000000000000000
--- a/src/generator/src/com/sk/action/ScriptAction.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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/src/generator/src/com/sk/dialog/ConfirmDiagPane.form b/src/generator/src/com/sk/dialog/ConfirmDiagPane.form
deleted file mode 100644
index 8ac1467b5c8fe9c2b089aa1f1f986568d15d63a3..0000000000000000000000000000000000000000
--- a/src/generator/src/com/sk/dialog/ConfirmDiagPane.form
+++ /dev/null
@@ -1,61 +0,0 @@
-
-
diff --git a/src/generator/src/com/sk/dialog/ConfirmDiagPane.java b/src/generator/src/com/sk/dialog/ConfirmDiagPane.java
deleted file mode 100644
index 62cc25feca56d0fd733efc19c436fdce7ca665e2..0000000000000000000000000000000000000000
--- a/src/generator/src/com/sk/dialog/ConfirmDiagPane.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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/src/generator/src/com/sk/dialog/ConfirmDialog.java b/src/generator/src/com/sk/dialog/ConfirmDialog.java
deleted file mode 100644
index 7bcf2479d57018d721bd90978f09892362c3ddf4..0000000000000000000000000000000000000000
--- a/src/generator/src/com/sk/dialog/ConfirmDialog.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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/src/generator/src/com/sk/dialog/ErrorDialog.form b/src/generator/src/com/sk/dialog/ErrorDialog.form
deleted file mode 100644
index ae897a574268d86b0a299d3c6d3d649a924d28ff..0000000000000000000000000000000000000000
--- a/src/generator/src/com/sk/dialog/ErrorDialog.form
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
diff --git a/src/generator/src/com/sk/dialog/ErrorDialog.java b/src/generator/src/com/sk/dialog/ErrorDialog.java
deleted file mode 100644
index 263cc10fd50cde3a547fd85b773c00e93a5fc2d5..0000000000000000000000000000000000000000
--- a/src/generator/src/com/sk/dialog/ErrorDialog.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * 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/src/generator/src/com/sk/dialog/GenResultDialog.form b/src/generator/src/com/sk/dialog/GenResultDialog.form
deleted file mode 100644
index b6e02973f844d7ac60601fc98e8393c098ddb9e8..0000000000000000000000000000000000000000
--- a/src/generator/src/com/sk/dialog/GenResultDialog.form
+++ /dev/null
@@ -1,64 +0,0 @@
-
-
diff --git a/src/generator/src/com/sk/dialog/GenResultDialog.java b/src/generator/src/com/sk/dialog/GenResultDialog.java
deleted file mode 100644
index bb0b1617ea67edf10d48b86a65acb41e864885be..0000000000000000000000000000000000000000
--- a/src/generator/src/com/sk/dialog/GenResultDialog.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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/src/generator/src/com/sk/dialog/GenerateDialog.java b/src/generator/src/com/sk/dialog/GenerateDialog.java
deleted file mode 100644
index 0a3cfdd54cde729cae22023eccdd62f3a53ca7ed..0000000000000000000000000000000000000000
--- a/src/generator/src/com/sk/dialog/GenerateDialog.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * 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/src/generator/src/com/sk/dialog/GenerateDialogPane.form b/src/generator/src/com/sk/dialog/GenerateDialogPane.form
deleted file mode 100644
index f846b03becbc326490a985d9599b23fcd96e745b..0000000000000000000000000000000000000000
--- a/src/generator/src/com/sk/dialog/GenerateDialogPane.form
+++ /dev/null
@@ -1,160 +0,0 @@
-
-
diff --git a/src/generator/src/com/sk/dialog/GenerateDialogPane.java b/src/generator/src/com/sk/dialog/GenerateDialogPane.java
deleted file mode 100644
index 08ec063df0e78372872760dc83566286702430a4..0000000000000000000000000000000000000000
--- a/src/generator/src/com/sk/dialog/GenerateDialogPane.java
+++ /dev/null
@@ -1,447 +0,0 @@
-/*
- * 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/src/generator/src/com/sk/ng/GenDTS.java b/src/generator/src/com/sk/ng/GenDTS.java
deleted file mode 100644
index 020bc614d318c25b005e9922fe35d72d6b3a0a15..0000000000000000000000000000000000000000
--- a/src/generator/src/com/sk/ng/GenDTS.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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/src/generator/src/com/sk/ng/GenMenuDTS.java b/src/generator/src/com/sk/ng/GenMenuDTS.java
deleted file mode 100644
index f69f004996d4a6364a71a7d14a07d9f43f3f3286..0000000000000000000000000000000000000000
--- a/src/generator/src/com/sk/ng/GenMenuDTS.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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/src/generator/src/com/sk/utils/FileUtil.java b/src/generator/src/com/sk/utils/FileUtil.java
deleted file mode 100644
index 184aad3f80f5f57c4d06a568adafb8720a72770c..0000000000000000000000000000000000000000
--- a/src/generator/src/com/sk/utils/FileUtil.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * 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-zA-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/src/generator/src/com/sk/utils/GenNotification.java b/src/generator/src/com/sk/utils/GenNotification.java
deleted file mode 100644
index 68dc43744ce4e11ae2752f53c608c6eac74bf440..0000000000000000000000000000000000000000
--- a/src/generator/src/com/sk/utils/GenNotification.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * 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()));
- }
- }
- }
-}