diff --git a/hdc/service_IntelliJ_plugin/resources/META-INF/plugin.xml b/hdc/service_IntelliJ_plugin/resources/META-INF/plugin.xml
new file mode 100644
index 0000000000000000000000000000000000000000..7a9c3a8e0081f50f5ba07e5888675f2dfc506936
--- /dev/null
+++ b/hdc/service_IntelliJ_plugin/resources/META-INF/plugin.xml
@@ -0,0 +1,32 @@
+
+ com.sk.service.ng
+ Service Generator
+ 1.0.0
+ 深圳开鸿数字产业发展有限公司
+
+
+
+
+ com.intellij.modules.lang
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/hdc/service_IntelliJ_plugin/resources/images/openDisk.png b/hdc/service_IntelliJ_plugin/resources/images/openDisk.png
new file mode 100644
index 0000000000000000000000000000000000000000..5956a0e538a400c7deaf41167ae5ea70348b8584
Binary files /dev/null and b/hdc/service_IntelliJ_plugin/resources/images/openDisk.png differ
diff --git a/hdc/service_IntelliJ_plugin/resources/images/text.png b/hdc/service_IntelliJ_plugin/resources/images/text.png
new file mode 100644
index 0000000000000000000000000000000000000000..f42534169aa41dd830a7cb09792fe1428c2f34f7
Binary files /dev/null and b/hdc/service_IntelliJ_plugin/resources/images/text.png differ
diff --git a/hdc/service_IntelliJ_plugin/src/com/sk/service/action/BrowseAction.java b/hdc/service_IntelliJ_plugin/src/com/sk/service/action/BrowseAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..ae423e34203e3af587c08fe270d199426e71e660
--- /dev/null
+++ b/hdc/service_IntelliJ_plugin/src/com/sk/service/action/BrowseAction.java
@@ -0,0 +1,117 @@
+/*
+ * 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.service.action;
+
+import com.intellij.notification.NotificationType;
+import com.intellij.openapi.project.Project;
+import com.sk.service.utils.FileUtil;
+import com.sk.service.utils.GenNotification;
+import org.apache.http.util.TextUtils;
+
+import javax.swing.JButton;
+import javax.swing.JFileChooser;
+import javax.swing.JTextField;
+import javax.swing.filechooser.FileNameExtensionFilter;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.util.prefs.Preferences;
+
+/**
+ * 接口文件选择框。
+ *
+ * @author: zhaoxudong@kaihong.com
+ * @see: select file
+ * @version: v1.0.0
+ * @since 2022-02-21
+ */
+public class BrowseAction implements ActionListener {
+ private final JButton button;
+ private final JTextField textField;
+ private final JTextField textFieldOutPath;
+ private final Project project;
+
+
+ public BrowseAction(Project project, JButton button, JTextField textField, JTextField textFieldOutPath) {
+ this.project = project;
+ this.button = button;
+ this.textField = textField;
+ this.textFieldOutPath = textFieldOutPath;
+ }
+
+ @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("文本文件(*.h)", "h");
+ 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);
+ textField.setText(interFile.substring(0, interFile.length() - 1));
+ textFieldOutPath.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);
+ textFieldOutPath.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);
+ textFieldOutPath.setText("");
+ return "";
+ }
+ return interFile.toString();
+ }
+}
diff --git a/hdc/service_IntelliJ_plugin/src/com/sk/service/action/OutPathSelectAction.java b/hdc/service_IntelliJ_plugin/src/com/sk/service/action/OutPathSelectAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..4cc7a4ad6992322bc49ec8f0977eedeae1dccf60
--- /dev/null
+++ b/hdc/service_IntelliJ_plugin/src/com/sk/service/action/OutPathSelectAction.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.service.action;
+
+import javax.swing.JButton;
+import javax.swing.JFileChooser;
+import javax.swing.JTextField;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+/**
+ * Service生成路径文件夹选择框
+ *
+ * @author: zhaoxudong@kaihong.com
+ * @see: select generator file path
+ * @version: v1.0.0
+ * @since 2022-10-08
+ */
+public class OutPathSelectAction implements ActionListener {
+ private final JButton button;
+ private final JTextField textField;
+
+ public OutPathSelectAction(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/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ConfirmDiagPane.form b/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ConfirmDiagPane.form
new file mode 100644
index 0000000000000000000000000000000000000000..8efbf235e5a2571823db56459a811fbb7a2bcd2d
--- /dev/null
+++ b/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ConfirmDiagPane.form
@@ -0,0 +1,75 @@
+
+
+
diff --git a/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ConfirmDiagPane.java b/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ConfirmDiagPane.java
new file mode 100644
index 0000000000000000000000000000000000000000..e8c30005733baf8fa5f599668606586c86d35932
--- /dev/null
+++ b/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ConfirmDiagPane.java
@@ -0,0 +1,49 @@
+/*
+ * 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.service.dialog;
+
+import javax.swing.JPanel;
+import javax.swing.JLabel;
+import javax.swing.JDialog;
+import javax.swing.ImageIcon;
+
+/**
+ * ConfirmDiagPane自定义确认对话框
+ * 解决ShowConfirmDiag 在Deveco里面会出现界面错位问题。
+ *
+ * @author: zhaoxudong@kaihong.com
+ * @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/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ConfirmDialog.java b/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ConfirmDialog.java
new file mode 100644
index 0000000000000000000000000000000000000000..2e28ee24042d0a72227d72dbaaf3a8a5eb7dfffc
--- /dev/null
+++ b/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ConfirmDialog.java
@@ -0,0 +1,52 @@
+/*
+ * 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.service.dialog;
+
+import com.intellij.openapi.ui.DialogWrapper;
+import org.jetbrains.annotations.Nullable;
+import javax.swing.JComponent;
+
+/**
+ * 自定义确认对话框Wrapper
+ *
+ * @author: zhaoxudong@kaihong.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/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ErrorDialog.form b/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ErrorDialog.form
new file mode 100644
index 0000000000000000000000000000000000000000..0225c79a4dcf3603640bd1194c6058012fcdd29d
--- /dev/null
+++ b/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ErrorDialog.form
@@ -0,0 +1,86 @@
+
+
+
diff --git a/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ErrorDialog.java b/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ErrorDialog.java
new file mode 100644
index 0000000000000000000000000000000000000000..129bcacc3f7ee78277351e8fee67aff9f9e3576e
--- /dev/null
+++ b/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ErrorDialog.java
@@ -0,0 +1,101 @@
+/*
+ * 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.service.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: zhaoxudong@kaihong.com
+ * @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();
+ }
+
+ JPanel getContentPanel() {
+ return contentPane;
+ }
+
+ 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/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ServiceGenerateDialog.java b/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ServiceGenerateDialog.java
new file mode 100644
index 0000000000000000000000000000000000000000..ec22b30235423489f2cb686e04cb90e59d8c3fa1
--- /dev/null
+++ b/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ServiceGenerateDialog.java
@@ -0,0 +1,148 @@
+/*
+ * 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.service.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.Action;
+import javax.swing.JComponent;
+import java.awt.Desktop;
+import java.awt.event.ActionEvent;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+/**
+ * 主界面对话框Wrapper
+ *
+ * @author: zhaoxudong@kaihong.com
+ * @see: tool conversion plug-in
+ * @version: v1.0.0
+ * @since 2022-05-27
+ */
+public class ServiceGenerateDialog extends DialogWrapper {
+ private static final Logger LOG = Logger.getInstance(ServiceGenerateDialog.class);
+ private static final String TITLE = "Generate Service Frame";
+ private static final String URL = "https://gitee.com/openharmony/napi_generator/tree/master/hdc/service-gen";
+
+ private final ServiceGenerateDialogPane genDiag;
+
+ /**
+ * 构造函数
+ *
+ * @param project projectId
+ * @param filePath 目录文件
+ * @param dirPath 文件夹目录
+ */
+ public ServiceGenerateDialog(Project project, String filePath, String dirPath) {
+ super(true);
+ this.setResizable(false);
+ setTitle(TITLE);
+ setModal(true);
+ genDiag = new ServiceGenerateDialogPane(project, filePath, dirPath);
+ 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.runServiceFun()) {
+ 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/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ServiceGenerateDialogPane.form b/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ServiceGenerateDialogPane.form
new file mode 100644
index 0000000000000000000000000000000000000000..987dedf17d45e5e341cafcd2f92f4bffb40377be
--- /dev/null
+++ b/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ServiceGenerateDialogPane.form
@@ -0,0 +1,119 @@
+
+
+
diff --git a/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ServiceGenerateDialogPane.java b/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ServiceGenerateDialogPane.java
new file mode 100644
index 0000000000000000000000000000000000000000..e4b7bd9811a9b0fcb741e13e54d6c37d000f5450
--- /dev/null
+++ b/hdc/service_IntelliJ_plugin/src/com/sk/service/dialog/ServiceGenerateDialogPane.java
@@ -0,0 +1,392 @@
+/*
+ * 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.service.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.service.action.BrowseAction;
+import com.sk.service.action.OutPathSelectAction;
+import com.sk.service.utils.FileUtil;
+import com.sk.service.utils.GenNotification;
+import org.apache.http.util.TextUtils;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JDialog;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+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;
+
+/**
+ * 生成工具主界面
+ *
+ * @author: zhaoxudong@kaihong.com
+ * @see: select generate dialog
+ * @version: v1.0.0
+ * @since 2022-02-21
+ */
+public class ServiceGenerateDialogPane extends JDialog {
+ private static final Logger LOG = Logger.getInstance(ServiceGenerateDialogPane.class);
+
+ private final Project project;
+
+ private JPanel contentPane;
+ private JTextField textFieldH;
+ private JTextField textFieldOutPath;
+ private JButton buttonOutPath;
+ private JButton buttonSelectH;
+ private boolean generateSuccess = true;
+ private String sErrorMessage = "";
+ private String dirPath;
+
+ /**
+ * 构造函数
+ *
+ * @param project projectId
+ * @param filePath .h文件
+ * @param dirPath 生成框架文件路径
+ */
+ public ServiceGenerateDialogPane(Project project, String filePath, String dirPath) {
+ this.project = project;
+ this.dirPath = dirPath;
+ textFieldH.setText(filePath);
+ textFieldOutPath.setText(dirPath);
+ contentPane.registerKeyboardAction(actionEvent -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
+ JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
+ buttonOutPath.addActionListener(new OutPathSelectAction(buttonOutPath, textFieldOutPath));
+ buttonSelectH.addActionListener(new BrowseAction(project, buttonSelectH, textFieldH, textFieldOutPath));
+ }
+
+ @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 fileH = textFieldH.getText();
+ String outDir = textFieldOutPath.getText();
+ boolean isEmptyFile = TextUtils.isEmpty(fileH) || TextUtils.isEmpty(outDir);
+ ValidationInfo validationInfo = null;
+ if (isEmptyFile) {
+ String warnMsg = ".h文件、输出路径不能为空";
+ warningMessage(warnMsg);
+ validationInfo = new ValidationInfo(warnMsg);
+ return validationInfo;
+ }
+
+ File file = new File(textFieldOutPath.getText() + "/examservice");
+ 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 = "请选择.h文件,输出结果路径";
+ GenNotification.notifyMessage(this.project, notiContent, title, NotificationType.WARNING);
+ }
+
+ /**
+ * 执行主程序入口
+ *
+ * @return 执行状态
+ */
+ public boolean runServiceFun() {
+ GenNotification.notifyMessage(this.project, "", "正在生成", NotificationType.INFORMATION);
+ String command;
+ command = genCommandService();
+ copyServiceHeader();
+ try {
+ if (!TextUtils.isEmpty(command) && callExtProcess(command)) {
+ GenNotification.notifyMessage(project, "执行成功", "提示", NotificationType.INFORMATION);
+ return true;
+ }
+ } catch (IOException | InterruptedException ex) {
+ GenNotification.notifyMessage(project, textFieldH.getText(), "Command exec error", NotificationType.ERROR);
+ LOG.error(ex);
+ }
+ return false;
+ }
+
+ /**
+ * 生成命令行指令
+ *
+ * @return 返回命令行执行内容
+ */
+ private String genCommandService() {
+ String sysName = System.getProperties().getProperty("os.name").toUpperCase();
+ String tmpDirFile = System.getProperty("java.io.tmpdir");
+ String execFn;
+ if (sysName.contains("WIN")) {
+ execFn = "cmds/win/service-gen-win.exe";
+ tmpDirFile += "service-gen-win.exe";
+ } else if (sysName.contains("LINUX")) {
+ execFn = "cmds/linux/service-gen-linux";
+ tmpDirFile += "service-gen-linux";
+ } else {
+ execFn = "cmds/mac/service-gen-macos";
+ tmpDirFile += "service-gen-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 hFile = textFieldH.getText();
+ String outPath = textFieldOutPath.getText();
+ command += " -f " + hFile + " -o " + outPath + " -s 9001";
+ return command;
+ }
+
+ /**
+ * 生成命令行指令
+ *
+ * @return 返回命令行执行内容
+ */
+ private void copyServiceHeader() {
+ String sysName = System.getProperties().getProperty("os.name").toUpperCase();
+ String tmpDirFile = System.getProperty("java.io.tmpdir");
+ String execFn;
+ if (sysName.contains("WIN")) {
+ execFn = "cmds/win/header_parser.exe";
+ tmpDirFile += "header_parser.exe";
+ } else if (sysName.contains("LINUX")) {
+ execFn = "cmds/linux/service-gen-linux";
+ tmpDirFile += "service-gen-linux";
+ } else {
+ execFn = "cmds/mac/service-gen-macos";
+ tmpDirFile += "service-gen-macos";
+ }
+ 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);
+ }
+ }
+
+ 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) {
+ GenNotification.notifyMessage(project, "执行成功", "提示", NotificationType.INFORMATION);
+ } else {
+ GenNotification.notifyMessage(project, sErrorMessage, "提示", NotificationType.ERROR);
+ return false;
+ }
+ errConsumer.join();
+ outputConsumer.join();
+ return true;
+ }
+
+ /**
+ * 赋值可执行文件权限。
+ *
+ * @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/hdc/service_IntelliJ_plugin/src/com/sk/service/ng/GenMenuService.java b/hdc/service_IntelliJ_plugin/src/com/sk/service/ng/GenMenuService.java
new file mode 100644
index 0000000000000000000000000000000000000000..9d1fa0e5b760026b75460f8523c9d18959c4c5db
--- /dev/null
+++ b/hdc/service_IntelliJ_plugin/src/com/sk/service/ng/GenMenuService.java
@@ -0,0 +1,43 @@
+/*
+ * 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.service.ng;
+
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.project.Project;
+import com.sk.service.dialog.ServiceGenerateDialog;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * 工具菜单入口
+ *
+ * @author: zhaoxudong@kaihong.com
+ * @see: tool conversion plug-in
+ * @version: v1.0.0
+ * @since 2022-05-27
+ */
+public class GenMenuService extends AnAction {
+
+ @Override
+ public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
+ Project project = anActionEvent.getProject();
+
+ if (project == null) {
+ return;
+ }
+ ServiceGenerateDialog wrapper = new ServiceGenerateDialog(project, "", "");
+ wrapper.showAndGet();
+ }
+}
diff --git a/hdc/service_IntelliJ_plugin/src/com/sk/service/ng/GenService.java b/hdc/service_IntelliJ_plugin/src/com/sk/service/ng/GenService.java
new file mode 100644
index 0000000000000000000000000000000000000000..b5cce8a1c603c4341e83f0c13de4c61a39b4df93
--- /dev/null
+++ b/hdc/service_IntelliJ_plugin/src/com/sk/service/ng/GenService.java
@@ -0,0 +1,66 @@
+/*
+ * 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.service.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.service.dialog.ServiceGenerateDialog;
+import com.sk.service.utils.FileUtil;
+import com.sk.service.utils.GenNotification;
+
+/**
+ * 项目文件入口
+ *
+ * @author: zhaoxudong@kaihong.com
+ * @see: tool conversion plug-in
+ * @version: v1.0.0
+ * @since 2022-02-21
+ */
+public class GenService extends AnAction {
+
+ @Override
+ public void actionPerformed(AnActionEvent anActionEvent) {
+ Project project = anActionEvent.getProject();
+ // 获取需要处理的.h文件绝对路径
+ 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 filePath = file.getPath();
+ String dirPath = file.getParent().getPath();
+ ServiceGenerateDialog wrapper = new ServiceGenerateDialog(project, filePath, dirPath);
+ 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/hdc/service_IntelliJ_plugin/src/com/sk/service/utils/FileUtil.java b/hdc/service_IntelliJ_plugin/src/com/sk/service/utils/FileUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..0ae6ce4c97bd67cc6b964f9fc72d5449a17d1c73
--- /dev/null
+++ b/hdc/service_IntelliJ_plugin/src/com/sk/service/utils/FileUtil.java
@@ -0,0 +1,104 @@
+/*
+ * 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.service.utils;
+
+import com.intellij.notification.NotificationType;
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.project.Project;
+import org.apache.http.util.TextUtils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.regex.Pattern;
+
+/**
+ * 文本文件工具
+ *
+ * @author: zhaoxudong@kaihong.com
+ * @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;
+
+ /**
+ * 获取换行符
+ *
+ * @return 换行符
+ */
+ public static String getNewline() {
+ return System.getProperty("line.separator");
+ }
+
+ /**
+ * 正则匹配所选文件名是否符合规范
+ *
+ * @param fileName 文件名
+ * @return boolean 是否匹配
+ */
+ public static boolean patternFileName(String fileName) {
+ String pattern = "([.a-z_A-Z0-9]+).h";
+ 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/hdc/service_IntelliJ_plugin/src/com/sk/service/utils/GenNotification.java b/hdc/service_IntelliJ_plugin/src/com/sk/service/utils/GenNotification.java
new file mode 100644
index 0000000000000000000000000000000000000000..3f15e4d403e90341b57842a9fc5f540d961c691e
--- /dev/null
+++ b/hdc/service_IntelliJ_plugin/src/com/sk/service/utils/GenNotification.java
@@ -0,0 +1,116 @@
+/*
+ * 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.service.utils;
+
+import com.intellij.ide.actions.OpenFileAction;
+import com.intellij.notification.Notification;
+import com.intellij.notification.NotificationAction;
+import com.intellij.notification.NotificationType;
+import com.intellij.notification.Notifications;
+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: zhaoxudong@kaihong.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) {
+
+ Notification notification = new Notification("Generate.Result.Group", "Notes Message", 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()));
+ }
+ }
+ }
+}