From e4ded4ab2bc8ca0bcb541c6f41d93919aa3e2bff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Clengege=E2=80=9D?= Date: Mon, 23 May 2022 14:50:04 +0800 Subject: [PATCH] feat: modified notification mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #I51B1C Signed-off-by: “lengege” --- .gitignore | 7 + OAT.xml | 1 + src/generator/resources/META-INF/plugin.xml | 30 +- src/generator/resources/images/openDisk.png | Bin 0 -> 176 bytes src/generator/resources/images/text.png | Bin 0 -> 122 bytes .../src/com/sk/action/BrowseAction.java | 48 +- .../src/com/sk/action/GenAction.java | 4 +- .../src/com/sk/action/ScriptAction.java | 4 +- .../src/com/sk/dialog/ConfirmDiagPane.form | 61 +++ .../src/com/sk/dialog/ConfirmDiagPane.java | 50 +++ .../src/com/sk/dialog/ConfirmDialog.java | 53 +++ .../src/com/sk/dialog/ErrorDialog.java | 6 +- .../src/com/sk/dialog/GenResultDialog.java | 4 +- .../src/com/sk/dialog/GenerateDialog.form | 141 ------ .../src/com/sk/dialog/GenerateDialog.java | 407 ++++------------- .../src/com/sk/dialog/GenerateDialogPane.form | 157 +++++++ .../src/com/sk/dialog/GenerateDialogPane.java | 418 ++++++++++++++++++ src/generator/src/com/sk/ng/GenDTS.java | 38 +- src/generator/src/com/sk/ng/GenMenuDTS.java | 50 +++ src/generator/src/com/sk/utils/FileUtil.java | 62 ++- .../src/com/sk/utils/GenNotification.java | 125 ++++++ 21 files changed, 1175 insertions(+), 491 deletions(-) create mode 100644 src/generator/resources/images/openDisk.png create mode 100644 src/generator/resources/images/text.png create mode 100644 src/generator/src/com/sk/dialog/ConfirmDiagPane.form create mode 100644 src/generator/src/com/sk/dialog/ConfirmDiagPane.java create mode 100644 src/generator/src/com/sk/dialog/ConfirmDialog.java delete mode 100644 src/generator/src/com/sk/dialog/GenerateDialog.form create mode 100644 src/generator/src/com/sk/dialog/GenerateDialogPane.form create mode 100644 src/generator/src/com/sk/dialog/GenerateDialogPane.java create mode 100644 src/generator/src/com/sk/ng/GenMenuDTS.java create mode 100644 src/generator/src/com/sk/utils/GenNotification.java diff --git a/.gitignore b/.gitignore index 5c000a24..472f234f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.iml +.gitignore .gradle /local.properties /.idea/caches @@ -16,3 +17,9 @@ /node_modules /src/node_modules /src/gen/ttt.js +/src/generator/generator.jar +/src/generator/out/ +/src/generator/resources/cmds/linux/napi_generator-linux +/src/generator/resources/cmds/mac/napi_generator-macos +/src/generator/resources/cmds/win/napi_generator-win.exe +/src/generator/.idea/ \ No newline at end of file diff --git a/OAT.xml b/OAT.xml index c7c37ad0..df2e5ab5 100644 --- a/OAT.xml +++ b/OAT.xml @@ -57,6 +57,7 @@ Note:If the text contains special characters, please escape them according to th + diff --git a/src/generator/resources/META-INF/plugin.xml b/src/generator/resources/META-INF/plugin.xml index 55a23a9e..94fa46a5 100644 --- a/src/generator/resources/META-INF/plugin.xml +++ b/src/generator/resources/META-INF/plugin.xml @@ -5,9 +5,21 @@ YourCompany - most HTML tags may be used - ]]> +

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

+ + + + + + + + + ]]> + @@ -24,6 +36,8 @@ + + @@ -31,6 +45,16 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/generator/resources/images/openDisk.png b/src/generator/resources/images/openDisk.png new file mode 100644 index 0000000000000000000000000000000000000000..5e66baa62e361484a32069b4277e269bcdce722f GIT binary patch literal 176 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`<(@8%Ar-fh6C~soEUZpqW_$NO ze8HK9b)KA4BpnzoA8Yt^Pc!QYd(!zMTiWKyO>CRzS?aQzMa=I)KzP=RnKBNO!V?Tb z@0)6_Te#l8L+AEEy%#ey!tdKEc4eGZ=-#!=OM!>Ms#Rq<^WHA04u|IxQmilRZdR9P aWO&}dG-q+zo@+oSFnGH9xvX +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/generator/src/com/sk/dialog/ConfirmDiagPane.java b/src/generator/src/com/sk/dialog/ConfirmDiagPane.java new file mode 100644 index 00000000..62cc25fe --- /dev/null +++ b/src/generator/src/com/sk/dialog/ConfirmDiagPane.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.sk.dialog; + +import javax.swing.JPanel; +import javax.swing.JLabel; +import javax.swing.JDialog; +import javax.swing.ImageIcon; + +/** + * ConfirmDiagPane自定义确认对话框 + * 解决ShowConfirmDiag 在Deveco里面会出现界面错位问题。 + * + * @author: xudong + * @see: generator error dialog + * @version: v1.0.0 + * @since 2022-02-21 + */ +public class ConfirmDiagPane extends JDialog { + private JPanel contentPane; + private JLabel msgLabel; + private JLabel iconLabel; + + /** + * 构造函数 + * + * @param sErrorMessage 错误信息 + */ + public ConfirmDiagPane(String sErrorMessage) { + msgLabel.setText(sErrorMessage); + iconLabel.setIcon(new ImageIcon("")); + } + + + JPanel getContentPanel() { + return contentPane; + } +} diff --git a/src/generator/src/com/sk/dialog/ConfirmDialog.java b/src/generator/src/com/sk/dialog/ConfirmDialog.java new file mode 100644 index 00000000..f610471d --- /dev/null +++ b/src/generator/src/com/sk/dialog/ConfirmDialog.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 Guangzhou Digitalchina Information Technology Co., Ltd. + * All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.sk.dialog; + +import com.intellij.openapi.ui.DialogWrapper; +import org.jetbrains.annotations.Nullable; +import javax.swing.JComponent; + +/** + * 自定义确认对话框Wrapper + * + * @author: liulongc digitalchina.com + * @see: tool conversion plug-in + * @version: v1.0.0 + * @since 2022-02-21 + */ +public class ConfirmDialog extends DialogWrapper { + private 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.java b/src/generator/src/com/sk/dialog/ErrorDialog.java index ef6071b1..263cc10f 100644 --- a/src/generator/src/com/sk/dialog/ErrorDialog.java +++ b/src/generator/src/com/sk/dialog/ErrorDialog.java @@ -28,10 +28,12 @@ import java.awt.event.WindowEvent; import java.io.IOException; /** + * ErrorDialog错误对话框 + * * @author: xudong * @see: generator error dialog * @version: v1.0.0 - * @since 2022/02/21 + * @since 2022-02-21 */ public class ErrorDialog extends JDialog { private static final Logger LOG = Logger.getInstance(ErrorDialog.class); @@ -92,4 +94,4 @@ public class ErrorDialog extends JDialog { } dispose(); } -} +} \ No newline at end of file diff --git a/src/generator/src/com/sk/dialog/GenResultDialog.java b/src/generator/src/com/sk/dialog/GenResultDialog.java index 488e7b90..bb0b1617 100644 --- a/src/generator/src/com/sk/dialog/GenResultDialog.java +++ b/src/generator/src/com/sk/dialog/GenResultDialog.java @@ -25,10 +25,12 @@ import java.util.ArrayList; import java.util.List; /** + * GenResultDialog结果生成框 + * * @author: xudong * @see: generate success dialog * @version: v1.0.0 - * @since 2022/02/21 + * @since 2022-02-21 */ public class GenResultDialog extends JDialog { private static final Logger LOG = Logger.getInstance(GenResultDialog.class); diff --git a/src/generator/src/com/sk/dialog/GenerateDialog.form b/src/generator/src/com/sk/dialog/GenerateDialog.form deleted file mode 100644 index c9e858b7..00000000 --- a/src/generator/src/com/sk/dialog/GenerateDialog.form +++ /dev/null @@ -1,141 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/generator/src/com/sk/dialog/GenerateDialog.java b/src/generator/src/com/sk/dialog/GenerateDialog.java index 1fabf99a..8bd9db76 100644 --- a/src/generator/src/com/sk/dialog/GenerateDialog.java +++ b/src/generator/src/com/sk/dialog/GenerateDialog.java @@ -1,10 +1,11 @@ /* - * Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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 + * 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, @@ -15,362 +16,140 @@ package com.sk.dialog; import com.intellij.openapi.diagnostic.Logger; -import com.sk.action.BrowseAction; -import com.sk.action.GenAction; -import com.sk.action.ScriptAction; -import com.sk.utils.FileUtil; -import org.apache.http.util.TextUtils; - -import javax.swing.JButton; +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.JDialog; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.KeyStroke; -import java.awt.event.ComponentAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; +import javax.swing.Action; +import java.awt.Desktop; +import java.awt.event.ActionEvent; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import java.net.URI; +import java.net.URISyntaxException; /** - * @author: xudong - * @see: select generate dialog + * 主界面对话框Wrapper + * + * @author: liulongc digitalchina.com + * @see: tool conversion plug-in * @version: v1.0.0 - * @since 2022/02/21 + * @since 2022-05-27 */ -public class GenerateDialog extends JDialog { +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 = - "rundll32 url.dll,FileProtocolHandler" + " https://gitee" + ".com/openharmony" + "-sig/napi_generator"; - 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 static final String URL = "https://gitee.com/openharmony/napi_generator"; - private JPanel contentPane; - private JButton buttonOK; - private JButton buttonCancel; - private JButton btnGenPath; - private JButton btnSelectScript; - private JTextField textField1; - private JTextField textField2; - private JTextField textField3; - private JButton btnSelectInter; - private JButton selectInter; - private JButton selectGenPath; - private JButton select; - private JButton buttonHelp; - private boolean generateSuccess = true; - private String sErrorMessage = ""; - private String destPath; - private String directoryPath; - private String fileName; + private GenerateDialogPane genDiag; + private DialogWrapperExitAction exitAction; + private CustomOKAction okAction; + private CustomHelpAction helpAction; /** * 构造函数 * - * @param destPath 接口文件路径 - * @param directoryPath 生成框架文件路径 - * @param fileName 文件名 + * @param project projectid + * @param destPath 目录文件 + * @param directoryPath 文件夹目录 + * @param fileName 文件名 */ - public GenerateDialog(String destPath, String directoryPath, String fileName) { - this.destPath = destPath; - this.directoryPath = directoryPath; - this.fileName = 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 组件内容 */ - public void initDialog() { - initData(); - setContentPane(contentPane); - setModal(true); - setTitle(TITLE); - getRootPane().setDefaultButton(buttonOK); - btnGenPath.setText("生成框架路径:"); - btnSelectScript.setText("编译脚本路径:"); - btnSelectInter.setText("接口文件:"); - buttonOK.addActionListener(actionEvent -> onOK()); - - buttonCancel.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); - - selectInter.addActionListener(new BrowseAction(selectInter, textField1)); - selectGenPath.addActionListener(new GenAction(selectGenPath, textField2)); - select.addActionListener(new ScriptAction(select, textField3)); - buttonHelp.addComponentListener(new ComponentAdapter() { - }); - buttonHelp.addActionListener(actionEvent -> onHelp()); - } - - private void onHelp() { - try { - Runtime.getRuntime().exec(URL); - } catch (IOException ioException) { - LOG.error("exec command help error" + ioException); - } - dispose(); - } - - private void initData() { - textField1.setText(destPath); - textField2.setText(directoryPath); - textField3.setText(directoryPath); - } - - private void onOK() { - if (TextUtils.isEmpty(textField1.getText())) { - warningMessage("请选择接口文件"); - return; - } - if (TextUtils.isEmpty(textField2.getText())) { - warningMessage("请选择保存框架路径"); - return; - } - if (TextUtils.isEmpty(textField3.getText())) { - warningMessage("请选择编译脚本路径"); - return; - } - runFun(textField1.getText(), textField2.getText()); - dispose(); - } - - private void onCancel() { - dispose(); - } - - private void warningMessage(String message) { - JOptionPane.showMessageDialog(null, message, "提示", JOptionPane.WARNING_MESSAGE); - } - - private void runFun(String destPath, String parentPath) { - String sysName = System.getProperties().getProperty("os.name").toUpperCase(); - String executeProgram; - if (sysName.indexOf("WIN") >= 0) { - executeProgram = "cmds/win/napi_generator-win.exe"; - } else if (sysName.indexOf("LINUX") >= 0) { - executeProgram = "cmds/linux/napi_generator-linux"; - } else { - executeProgram = "cmds/linux/napi_generator-mac"; - } - try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(executeProgram)) { - String command = genCommand(inputStream, destPath, parentPath); - callExtProcess(command); - } catch (IOException ioException) { - LOG.error("exec command error" + ioException); - } catch (InterruptedException exception) { - LOG.warn("exec command Interrupted" + exception); - Thread.currentThread().interrupt(); - } - } - - private String genCommand(InputStream inputStream, String destPath, String parentPath) { - String sysName = System.getProperties().getProperty("os.name").toUpperCase(); - String tmpDir = System.getProperty("java.io.tmpdir"); - String execFn = tmpDir + "/napi_generator.exe"; - if (sysName.indexOf("LINUX") >= 0) { - executable(execFn); - } - - File file = new File(execFn); - if (!file.exists()) { - try { - byte[] bs = inputStream.readAllBytes(); - writeTmpFile(execFn, bs); - } catch (IOException ioException) { - LOG.error("runFun WIN write_tmp_file io error" + ioException); - } - } - return file + " " + "-f" + " " + destPath + " " + "-o" + " " + parentPath; + @Nullable + @Override + protected JComponent createCenterPanel() { + return genDiag.getContentPanel(); } - private void callExtProcess(String command) throws IOException, InterruptedException { - 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) { - LOG.error(" callExtProcess process.waitFor() != 0"); - promptDialog(); - } else { - promptDialog(); - writeCommand(); - } - errConsumer.join(); - outputConsumer.join(); - } + /** + * 校验数据 + * + * @return 检测文本框架是否有目录。 + */ + @Nullable + @Override + protected ValidationInfo doValidate() { - private void writeCommand() { - FileUtil fileUtil = new FileUtil(); - String filePath = fileUtil.makeFile(directoryPath + "/makeFile.txt"); - if (TextUtils.isEmpty(filePath)) { - LOG.error("makeFile is error"); - return; - } - Matcher matcher = LF_PATTERN.matcher(COMMAND_STATEMENT); - String statement = matcher.replaceAll(fileName); - try { - if (!fileUtil.findStringInFile(filePath, statement)) { - fileUtil.writeErrorToTxt(filePath, statement); - } - } catch (IOException ioException) { - LOG.error("writeCommand io error" + ioException); - } + return genDiag.validationInfo(); } - private void executable(String execFn) { - try { - callExtProcess("chmod a+x " + execFn); - } catch (IOException ioException) { - LOG.warn("LINUX IOException error" + ioException); - } catch (InterruptedException exception) { - LOG.warn("exec chmod command Interrupted" + exception); - Thread.currentThread().interrupt(); - } - } + /** + * ok/cancel按钮 + * + * @return Action[] buttos list + */ + @NotNull + @Override + protected Action[] createActions() { + exitAction = new DialogWrapperExitAction("Cancel", CANCEL_EXIT_CODE); + okAction = new CustomOKAction(); - 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"); - } - } - try (FileOutputStream fw = new FileOutputStream(file)) { - fw.write(bs, 0, bs.length); - } catch (IOException ioException) { - LOG.error("writeTmpFile io error" + ioException); - } + // 设置默认的焦点按钮 + okAction.putValue(DialogWrapper.DEFAULT_ACTION, true); + return new Action[]{exitAction, okAction}; } - private void promptDialog() { - if (generateSuccess) { - GenResultDialog genResultDialog = new GenResultDialog(directoryPath); - genResultDialog.initResultDialog(); - setMethod(genResultDialog); - } else { - ErrorDialog errorDialog = new ErrorDialog(sErrorMessage); - errorDialog.initDialog(); - setMethod(errorDialog); - } + @NotNull + @Override + protected Action[] createLeftSideActions() { + helpAction = new CustomHelpAction(); + return new Action[]{helpAction}; } - private void setMethod(JDialog dialog) { - dialog.setLocationRelativeTo(dialog); - dialog.pack(); - dialog.setVisible(true); - } + /** + * 自定义 ok Action + */ + protected class CustomOKAction extends DialogWrapperAction { - 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; + protected CustomOKAction() { + super("OK"); } - generateSuccess = false; - sErrorMessage = sErr; - } - private String getErrorResult(BufferedReader stdError) { - String sErr = ""; - while (true) { - String sTmp; - try { - if ((sTmp = stdError.readLine()) == null) { - break; - } - sErr += sTmp + FileUtil.getNewline(); - } catch (IOException ioException) { - LOG.error(" genResultLog stdInput error" + ioException); - } - } - return sErr; - } + @Override + protected void doAction(ActionEvent actionEvent) { - private boolean generateIsSuccess(String sOut) { - if (!TextUtils.isEmpty(sOut) && sOut.indexOf("success") >= 0) { - generateSuccess = true; - } else { - generateSuccess = false; - } - return generateSuccess; - } - private String genInputLog(BufferedReader stdInput) { - String sOut = ""; - while (true) { - String sTmp; - try { - if ((sTmp = stdInput.readLine()) == null) { - break; + ValidationInfo validationInfo = doValidate(); + if (validationInfo != null) { + LOG.info(validationInfo.message); + } else { + if (genDiag.runFun()) { + close(CANCEL_EXIT_CODE); } - sOut += sTmp + FileUtil.getNewline(); - } catch (IOException ioException) { - LOG.error(" genResultLog stdInput error" + ioException); } } - return sOut; } - class StreamConsumer extends Thread { - InputStream is; + /** + * 自定义 help Action + */ + protected class CustomHelpAction extends DialogWrapperAction { - StreamConsumer(InputStream is) { - super.setName("StreamConsumer"); - this.is = is; + protected CustomHelpAction() { + super("Help"); } @Override - public void run() { + protected void doAction(ActionEvent actionEvent) { 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); + 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 new file mode 100644 index 00000000..8c23604d --- /dev/null +++ b/src/generator/src/com/sk/dialog/GenerateDialogPane.form @@ -0,0 +1,157 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/generator/src/com/sk/dialog/GenerateDialogPane.java b/src/generator/src/com/sk/dialog/GenerateDialogPane.java new file mode 100644 index 00000000..a498af34 --- /dev/null +++ b/src/generator/src/com/sk/dialog/GenerateDialogPane.java @@ -0,0 +1,418 @@ +/* + * 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 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 genText; + private JLabel scriptText; + private JLabel interText; + private boolean generateSuccess = true; + private String sErrorMessage = ""; + private String destPath; + private String directoryPath; + private String fileName; + private 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.destPath = interFilePath; + this.directoryPath = genDir; + this.fileName = scriptDir; + + interText.setText("接口文件:"); + genText.setText("生成框架路径:"); + scriptText.setText("编译脚本路径:"); + + interPath.setText(destPath); + genPath.setText(directoryPath); + scriptPath.setText(directoryPath); + + // call onCancel() on ESCAPE + contentPane.registerKeyboardAction(actionEvent -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), + JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + + selectInter.addActionListener(new BrowseAction(project, selectInter, interPath, genPath, scriptPath)); + 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 返回不符要求的信息。 + */ + 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 = new ValidationInfo(null); + if (isEmptyFile) { + String warnMsg = "接口文件、框架、编译脚本路径不能为空"; + warningMessage("Please input interface,gen and gyp file directory", 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 message, String title) { + GenNotification.notifyMessage(this.project, message, title, NotificationType.WARNING); + } + + /** + * 执行主程序入口 + * + * @return 执行状态 + * @throws IOException 文件打开 + */ + public boolean runFun() { + GenNotification.notifyMessage(this.project, "", "正在生成", NotificationType.INFORMATION); + destPath = interPath.getText(); + String parentPath = genPath.getText(); + + String command; + command = genCommand(destPath, parentPath); + + try { + if (!TextUtils.isEmpty(command) && callExtProcess(command)) { + GenNotification.notifyMessage(project, directoryPath, "提示", NotificationType.INFORMATION, true); + return true; + } + } catch (IOException | InterruptedException ex) { + GenNotification.notifyMessage(project, directoryPath, "Command exec error", NotificationType.ERROR); + LOG.error(ex); + } + return false; + } + + /** + * 生成命令行指令 + * + * @param destPath 目标文件 + * @param parentPath 父目录文件 + * @return 返回命令行执行内容 + */ + private String genCommand(String destPath, String parentPath) { + String sysName = System.getProperties().getProperty("os.name").toUpperCase(); + String tmpDirFile = System.getProperty("java.io.tmpdir"); + String execFn; + + + if (sysName.indexOf("WIN") >= 0) { + execFn = "cmds/win/napi_generator-win.exe"; + tmpDirFile += "napi_generator-win.exe"; + } else if (sysName.indexOf("LINUX") >= 0) { + 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) { + return ""; + } + byte[] bs = inputStream.readAllBytes(); + writeTmpFile(tmpDirFile, bs); + if (sysName.indexOf("LINUX") >= 0 || sysName.indexOf("MAC OS") >= 0) { + executable(tmpDirFile); + } + } catch (IOException | InterruptedException e) { + GenNotification.notifyMessage(this.project, e.getMessage(), "Can not Find File:" + execFn, + NotificationType.ERROR); + LOG.error(e); + return ""; + } + } + return file + " " + "-f" + " " + destPath + " " + "-o" + " " + parentPath; + } + + 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文件 + * + * @throws IOException 文件异常 + */ + private void writeCommand() { + FileUtil fileUtil = new FileUtil(); + String filePath = fileUtil.makeFile(directoryPath + "/makeFile.txt"); + if (TextUtils.isEmpty(filePath)) { + LOG.error("makeFile is error"); + return; + } + Matcher matcher = LF_PATTERN.matcher(COMMAND_STATEMENT); + String statement = matcher.replaceAll(fileName); + 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) { + String sErr = ""; + while (true) { + String sTmp; + try { + if ((sTmp = stdError.readLine()) == null) { + break; + } + sErr += sTmp + FileUtil.getNewline(); + } catch (IOException ioException) { + LOG.error(" genResultLog stdInput error" + ioException); + } + } + return sErr; + } + + private boolean generateIsSuccess(String sOut) { + if (sOut.indexOf("success") >= 0 || TextUtils.isEmpty(sOut)) { + generateSuccess = true; + } else { + generateSuccess = false; + } + return generateSuccess; + } + + /** + * 获取生成文本内容。 + * + * @param stdInput input buff + * @return 返回当前输入框内容 + */ + private String genInputLog(BufferedReader stdInput) { + String sOut = ""; + while (true) { + String sTmp; + try { + if ((sTmp = stdInput.readLine()) == null) { + break; + } + sOut += sTmp + FileUtil.getNewline(); + } catch (IOException ioException) { + LOG.error(" genResultLog stdInput error" + ioException); + } + } + return sOut; + } + + 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 index 99d78a91..10dc4021 100644 --- a/src/generator/src/com/sk/ng/GenDTS.java +++ b/src/generator/src/com/sk/ng/GenDTS.java @@ -14,52 +14,51 @@ */ 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.diagnostic.Logger; -import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.sk.dialog.GenerateDialog; - -import java.util.regex.Pattern; +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 + * @since 2022-02-21 */ public class GenDTS extends AnAction { - private static final Logger LOG = Logger.getInstance(GenDTS.class); @Override public void actionPerformed(AnActionEvent anActionEvent) { + Project project = anActionEvent.getProject(); // 获取需要处理的.d.ts文件绝对路径 VirtualFile file = anActionEvent.getData(PlatformDataKeys.VIRTUAL_FILE); if (file == null) { - LOG.error("file is not exit"); + GenNotification.notifyMessage(project, "", "file is not exist", NotificationType.ERROR); return; } - // 正则匹配所选文件名是否符合规范 - if (!Pattern.matches("@ohos.[a-zA-Z0-9]+.d.ts", file.getName())) { - Messages.showErrorDialog("选择@ohos.xxx.d.ts文件生成", "错误"); + String baseFile = project.getBasePath(); + + if (!FileUtil.checkProjectSDK(project, baseFile)) { return; } + String destPath = file.getPath(); String directoryPath = file.getParent().getPath(); String fileName = file.getName(); - showDialog(destPath, directoryPath, fileName); + GenerateDialog wrapper = new GenerateDialog(project, destPath, directoryPath, fileName); + if (wrapper.showAndGet()) { + return; + } } - private void showDialog(String destPath, String directoryPath, String fileName) { - GenerateDialog dialog = new GenerateDialog(destPath, directoryPath, fileName); - dialog.initDialog(); - dialog.setLocationRelativeTo(dialog); - dialog.pack(); - dialog.setVisible(true); - } @Override public void update(AnActionEvent event) { @@ -68,8 +67,7 @@ public class GenDTS extends AnAction { if (file == null) { event.getPresentation().setEnabledAndVisible(false); } else { - String extension = file.getExtension(); - if (extension != null && "ts".equals(extension)) { + if (FileUtil.patternFileName(file.getName())) { event.getPresentation().setEnabledAndVisible(true); } else { event.getPresentation().setEnabledAndVisible(false); diff --git a/src/generator/src/com/sk/ng/GenMenuDTS.java b/src/generator/src/com/sk/ng/GenMenuDTS.java new file mode 100644 index 00000000..58b9ed34 --- /dev/null +++ b/src/generator/src/com/sk/ng/GenMenuDTS.java @@ -0,0 +1,50 @@ +/* + * 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(); + + String baseFile = project.getBasePath(); + + if (!FileUtil.checkProjectSDK(project, baseFile)) { + return; + } + + GenerateDialog wrapper = new GenerateDialog(project, "", "", ""); + if (wrapper.showAndGet()) { + return; + } + } + +} diff --git a/src/generator/src/com/sk/utils/FileUtil.java b/src/generator/src/com/sk/utils/FileUtil.java index 63ff8130..e3ff8bc7 100644 --- a/src/generator/src/com/sk/utils/FileUtil.java +++ b/src/generator/src/com/sk/utils/FileUtil.java @@ -14,7 +14,9 @@ */ 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 java.io.BufferedReader; @@ -23,16 +25,22 @@ import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; +import java.util.Properties; +import java.util.regex.Pattern; /** + * 文本文件工具 + * * @author: xudong * @see: file utils * @version: v1.0.0 - * @since 2022/02/21 + * @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中 * @@ -85,7 +93,7 @@ public class FileUtil { File file = new File(path); String[] command = content.split(StringUtils.LF); try (InputStreamReader read = new InputStreamReader(new FileInputStream(file), "UTF-8"); - BufferedReader bufferedReader = new BufferedReader(read)) { + BufferedReader bufferedReader = new BufferedReader(read)) { return isContainString(bufferedReader, command); } } @@ -121,4 +129,54 @@ public class FileUtil { 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(); + for (File file : childFile) { + if (file.getName().equals("build.gradle")) { + gradlePath = file.getPath(); + } + } + } + + Properties properties = new Properties(); + 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 false; + } + String ohosSDK = properties.getProperty("compileSdkVersion"); + + if (ohosSDK != null && Integer.parseInt(ohosSDK) < COMPILE_SDK_VERSION) { + GenNotification.notifyMessage(project, "SKD版本过低,NAPI仅支持5.0及以上版本", + "提示", + NotificationType.WARNING); + return false; + } + return true; + } } diff --git a/src/generator/src/com/sk/utils/GenNotification.java b/src/generator/src/com/sk/utils/GenNotification.java new file mode 100644 index 00000000..68dc4374 --- /dev/null +++ b/src/generator/src/com/sk/utils/GenNotification.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2022 Guangzhou Digitalchina Information Technology Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.sk.utils; + +import com.intellij.ide.actions.OpenFileAction; +import com.intellij.notification.NotificationType; +import com.intellij.notification.Notification; +import com.intellij.notification.NotificationGroup; +import com.intellij.notification.NotificationAction; +import com.intellij.notification.Notifications; +import com.intellij.notification.NotificationDisplayType; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; + +import java.io.File; + +/** + * 通知框 + * + * @author: liulongc digitalchina.com + * @see: tool conversion plug-in + * @version: v1.0.0 + * @since 2022-05-27 + */ +public class GenNotification { + + private static final Logger LOG = Logger.getInstance(FileUtil.class); + + private GenNotification() { + } + + /** + * 无action 通知 + * + * @param project projectid + * @param content 提示内容 + * @param title 提示栏内容 + * @param type 提示类型 Error,Waring,info + */ + public static void notifyMessage(@javax.annotation.Nullable Project project, + String content, + String title, + NotificationType type) { + notifyMessage(project, content, title, type, false); + } + + /** + * 消息通知 + * + * @param project projectid + * @param content 提示内容 + * @param title 提示栏内容 + * @param type 提示类型 Error,Waring,info + * @param addAct 是否添加action + */ + public static void notifyMessage(@javax.annotation.Nullable Project project, + String content, + String title, + NotificationType type, + boolean addAct) { + + NotificationGroup notificationGroup = new NotificationGroup("Generate.Result.Group", + NotificationDisplayType.STICKY_BALLOON); + Notification notification = notificationGroup.createNotification(content, type); + notification.setTitle(title); + notification.setContent(content); + + if (NotificationType.ERROR.equals(type)) { + LOG.error(content); + } else if (NotificationType.WARNING.equals(type)) { + LOG.warn(content); + } else { + LOG.info(content); + } + + if (addAct) { + notification.setContent(null); + addAction(project, content, notification); + } + Notifications.Bus.notify(notification, project); + + } + + private static void addAction(Project project, String dirPath, Notification notification) { + File genResultPath = new File(dirPath); + if (!genResultPath.exists()) { + LOG.info(String.format("%s not exist", genResultPath.getPath())); + } + LOG.info("generated file list log:"); + + File[] fa = genResultPath.listFiles(); + for (int i = 0; i < fa.length; i++) { + File fs = fa[i]; + String fileName = fs.getName(); + boolean dissFile = !fileName.endsWith(".log") || !fileName.endsWith(".txt") || !fileName.endsWith(".ts"); + if (!fs.isDirectory() && dissFile) { + String filePath = fs.getPath(); + NotificationAction action = new NotificationAction(filePath) { + @Override + public void actionPerformed(@NotNull AnActionEvent anActionEvent, + @NotNull Notification notification) { + OpenFileAction.openFile(filePath, project); + } + }; + notification.addAction(action); + } else { + LOG.info(String.format("%s is Directory", fs.getPath())); + } + } + } +} -- Gitee