diff --git a/prebuilt/End User License Agreement.md b/prebuilt/End User License Agreement.md
index 99a818f3bcad713c1350736d62cc71f5e47ea211..91325dd76199005dbe1a75cbf2c8c472d9e2af20 100644
--- a/prebuilt/End User License Agreement.md
+++ b/prebuilt/End User License Agreement.md
@@ -1,3 +1,18 @@
+/*
+* 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.
+*/
+
## End User License Agreement
THIS END USER LICENSE AGREEMENT (“AGREEMENT”) IS A LEGAL AGREEMENT BETWEEN YOU (EITHER A SINGLE INDIVIDUAL, OR SINGLE LEGAL ENTITY) AND【 深圳开鸿数字产业发展有限公司 】 (HERE AFTER REFERRED TO AS"【 深开鸿】") FOR THE USE OF THE SOFTWARE ACCOMPANYING THIS AGREEMENT. 【 深开鸿】 IS ONLY WILLING TO LICENSE THE SOFTWARE TO YOU ON CONDITION THAT YOU ACCEPT ALL OF THE TERMS IN THIS AGREEMENT. BY DOWNDOADING OR BY INSTALLING OR OTHERWISE USING OR COPYING THE SOFTWARE YOU INDICATE THAT YOU AGREE TO BE BOUND BY ALL OF THE TERMS OF THIS AGREEMENT. IF YOU DO NOT AGREE TO THE TERMS OF THIS AGREEMENT,【深开鸿 】 WILL NOT LICENSE THE SOFTWARE TO YOU AND YOU MAY NOT INSTALL, USE OR COPY THE SOFTWARE, AND YOU SHALL PROMPTLY DESTROY, DELETE, OR RETURN THE SOFTWARE TO YOUR SUPPLIER.
diff --git a/src/generator/generator.iml b/src/generator/generator.iml
deleted file mode 100644
index 0fbaa11135b1b5d5a3dd4ca920048f02bb255493..0000000000000000000000000000000000000000
--- a/src/generator/generator.iml
+++ /dev/null
@@ -1,28 +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.
- */
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/generator/resources/META-INF/plugin.xml b/src/generator/resources/META-INF/plugin.xml
index 7847f2c7c13445aa0c48068ba64977b345a380ba..55a23a9e33bf0bbd816b0199141ef52067d7d0a5 100644
--- a/src/generator/resources/META-INF/plugin.xml
+++ b/src/generator/resources/META-INF/plugin.xml
@@ -1,20 +1,6 @@
-/*
- * 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.
- */
com.sk.ng
- napi_generator
+ Napi Generator
1.0
YourCompany
@@ -42,7 +28,7 @@
-
+
diff --git a/src/generator/src/com/sk/action/BrowseAction.java b/src/generator/src/com/sk/action/BrowseAction.java
index cc49278744c7716bd453a07f09437108aaed2698..be8002c11446b196894ffa9ab2287399f37f151c 100644
--- a/src/generator/src/com/sk/action/BrowseAction.java
+++ b/src/generator/src/com/sk/action/BrowseAction.java
@@ -14,15 +14,18 @@
*/
package com.sk.action;
-import javax.swing.*;
+import javax.swing.JButton;
+import javax.swing.JFileChooser;
+import javax.swing.JTextField;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* @author: xudong
- * @see: 选择文件
- * @version: 2022/02/21/v1.0.0
+ * @see: select file
+ * @version: v1.0.0
+ * @since 2022/02/21
*/
public class BrowseAction implements ActionListener {
private JButton button;
@@ -34,8 +37,8 @@ public class BrowseAction implements ActionListener {
}
@Override
- public void actionPerformed(ActionEvent e) {
- if (e.getSource().equals(button)) {
+ public void actionPerformed(ActionEvent actionEvent) {
+ if (actionEvent.getSource().equals(button)) {
JFileChooser fcDlg = new JFileChooser();
fcDlg.setDialogTitle("请选择接口文件...");
fcDlg.setFileSelectionMode(JFileChooser.FILES_ONLY);
diff --git a/src/generator/src/com/sk/action/GenAction.java b/src/generator/src/com/sk/action/GenAction.java
index 980679c682fbb1b007098c6c9cac8982854404d0..768a4bc672254bdaa3561fc676db092e03ec1a80 100644
--- a/src/generator/src/com/sk/action/GenAction.java
+++ b/src/generator/src/com/sk/action/GenAction.java
@@ -14,14 +14,17 @@
*/
package com.sk.action;
-import javax.swing.*;
+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: 选择生成框架路径
- * @version: 2022/02/21/v1.0.0
+ * @see: select generator file path
+ * @version: v1.0.0
+ * @since 2022/02/21
*/
public class GenAction implements ActionListener {
private JButton button;
@@ -33,8 +36,8 @@ public class GenAction implements ActionListener {
}
@Override
- public void actionPerformed(ActionEvent e) {
- if (e.getSource().equals(button)) {
+ public void actionPerformed(ActionEvent actionEvent) {
+ if (actionEvent.getSource().equals(button)) {
JFileChooser fcDlg = new JFileChooser();
fcDlg.setDialogTitle("请选择生成框架路径...");
fcDlg.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
@@ -46,4 +49,3 @@ public class GenAction implements ActionListener {
}
}
}
-
diff --git a/src/generator/src/com/sk/action/ScriptAction.java b/src/generator/src/com/sk/action/ScriptAction.java
index 6637e48e297e08a5e3dfba3df76f49860f04dfc5..602f06642541e035bdde1032cbea7d352bd2d779 100644
--- a/src/generator/src/com/sk/action/ScriptAction.java
+++ b/src/generator/src/com/sk/action/ScriptAction.java
@@ -14,14 +14,17 @@
*/
package com.sk.action;
-import javax.swing.*;
+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: 选择编译脚本
- * @version: 2022/02/21/v1.0.0
+ * @see: select compile script
+ * @version: v1.0.0
+ * @since 2022/02/21
*/
public class ScriptAction implements ActionListener {
private JButton button;
@@ -33,8 +36,8 @@ public class ScriptAction implements ActionListener {
}
@Override
- public void actionPerformed(ActionEvent e) {
- if (e.getSource().equals(button)) {
+ public void actionPerformed(ActionEvent actionEvent) {
+ if (actionEvent.getSource().equals(button)) {
JFileChooser fcDlg = new JFileChooser();
fcDlg.setDialogTitle("请选择编译脚本路径...");
fcDlg.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
diff --git a/src/generator/src/com/sk/dialog/ErrorDialog.java b/src/generator/src/com/sk/dialog/ErrorDialog.java
index dedec284f5cb36a198031f81d9a7bd49aa718eb0..ef6071b1c6da33ebc134696a84b6eab88cea9e04 100644
--- a/src/generator/src/com/sk/dialog/ErrorDialog.java
+++ b/src/generator/src/com/sk/dialog/ErrorDialog.java
@@ -16,54 +16,68 @@ package com.sk.dialog;
import com.intellij.openapi.diagnostic.Logger;
-import javax.swing.*;
-import java.awt.event.*;
+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;
/**
* @author: xudong
- * @see: 生成文件错误弹窗
- * @version: 2022/02/21/v1.0.0
+ * @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(sErrorMessage);
- buttonOK.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- onOK();
- }
- });
+ textAreaError.setText(errorMessage);
+ buttonOK.addActionListener(actionEvent -> onOK());
- buttonHelp.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- onCancel();
- }
- });
+ buttonHelp.addActionListener(actionEvent -> onCancel());
// call onCancel() when cross is clicked
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
+ /**
+ * close dialog
+ * @param windowEvent WindowEvent
+ */
+ @Override
+ public void windowClosing(WindowEvent windowEvent) {
onCancel();
}
});
// call onCancel() on ESCAPE
- contentPane.registerKeyboardAction(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- onCancel();
- }
- }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
+ contentPane.registerKeyboardAction(actionEvent -> onCancel(),
+ KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
+ JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
}
private void onOK() {
@@ -72,10 +86,9 @@ public class ErrorDialog extends JDialog {
private void onCancel() {
try {
- Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler" +
- " https://gitee.com/openharmony-sig/napi_generator");
- } catch (IOException e) {
- LOG.error("exec command help error");
+ Runtime.getRuntime().exec(URL);
+ } catch (IOException ioException) {
+ LOG.error("exec command help error" + ioException);
}
dispose();
}
diff --git a/src/generator/src/com/sk/dialog/GenResultDialog.java b/src/generator/src/com/sk/dialog/GenResultDialog.java
index f2b51410c8e73414f33a3eba48054e264e316a8c..3f2be9aafeb614416a5edca9965a055022e6a0e2 100644
--- a/src/generator/src/com/sk/dialog/GenResultDialog.java
+++ b/src/generator/src/com/sk/dialog/GenResultDialog.java
@@ -16,35 +16,41 @@ package com.sk.dialog;
import com.intellij.openapi.diagnostic.Logger;
-import javax.swing.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
+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;
/**
* @author: xudong
- * @see: 成功弹窗
- * @version: 2022/02/21/v1.0.0
+ * @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(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- onOK();
- }
- });
- List fileList = getDirFileName(directoryPath);
+ buttonOK.addActionListener(actionEvent -> onOK());
+ List fileList = getDirFileName(path);
resultList.setListData(fileList.toArray(new String[fileList.size()]));
}
@@ -54,14 +60,14 @@ public class GenResultDialog extends JDialog {
private List getDirFileName(String path) {
List files = new ArrayList<>();
- File f = new File(path);
- if (!f.exists()) {
+ File file = new File(path);
+ if (!file.exists()) {
LOG.info("getDirFileName f not exist");
return files;
}
- File fa[] = f.listFiles();
- for (int i = 0; i < fa.length; i++) {
- File fs = fa[i];
+ File[] fileArray = file.listFiles();
+ for (int i = 0; i < fileArray.length; i++) {
+ File fs = fileArray[i];
if (!fs.isDirectory()) {
files.add(fs.getPath());
} else {
diff --git a/src/generator/src/com/sk/dialog/GenerateDialog.java b/src/generator/src/com/sk/dialog/GenerateDialog.java
index e33eb4876efc39fc578a617b05e34496933309d6..71266d90188d36f7ed1072b26ef0641fee0a1c3c 100644
--- a/src/generator/src/com/sk/dialog/GenerateDialog.java
+++ b/src/generator/src/com/sk/dialog/GenerateDialog.java
@@ -21,18 +21,42 @@ import com.sk.action.ScriptAction;
import com.sk.utils.FileUtil;
import org.apache.http.util.TextUtils;
-import javax.swing.*;
-import java.awt.event.*;
-import java.io.*;
+import javax.swing.JButton;
+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 java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* @author: xudong
- * @see: 选择路径弹窗
- * @version: 2022/02/21/v1.0.0
+ * @see: select generate dialog
+ * @version: v1.0.0
+ * @since 2022/02/21
*/
public class GenerateDialog extends JDialog {
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 JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
@@ -48,61 +72,69 @@ public class GenerateDialog extends JDialog {
private JButton buttonHelp;
private boolean generateSuccess = true;
private String sErrorMessage = "";
- private String destPath, directoryPath, fileName;
-
+ private String destPath;
+ private String directoryPath;
+ private String fileName;
+
+ /**
+ * 构造函数
+ *
+ * @param destPath 接口文件路径
+ * @param directoryPath 生成框架文件路径
+ * @param fileName 文件名
+ */
public GenerateDialog(String destPath, String directoryPath, String fileName) {
this.destPath = destPath;
this.directoryPath = directoryPath;
this.fileName = fileName;
+ }
+
+ /**
+ * 初始化对话框
+ */
+ public void initDialog() {
initData();
setContentPane(contentPane);
setModal(true);
setTitle(TITLE);
getRootPane().setDefaultButton(buttonOK);
- buttonOK.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- onOK();
- }
- });
+ btnGenPath.setText("生成框架路径:");
+ btnSelectScript.setText("编译脚本路径:");
+ btnSelectInter.setText("接口文件:");
+ buttonOK.addActionListener(actionEvent -> onOK());
- buttonCancel.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- onCancel();
- }
- });
+ buttonCancel.addActionListener(actionEvent -> onCancel());
// call onCancel() when cross is clicked
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
+ /**
+ * close dialog
+ * @param windowEvent WindowEvent
+ */
+ @Override
+ public void windowClosing(WindowEvent windowEvent) {
onCancel();
}
});
// call onCancel() on ESCAPE
- contentPane.registerKeyboardAction(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- onCancel();
- }
- }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
+ 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(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- onHelp();
- }
- });
+ buttonHelp.addActionListener(actionEvent -> onHelp());
}
private void onHelp() {
try {
- Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler" + " https://gitee.com/openharmony-sig/napi_generator");
- } catch (IOException e) {
- LOG.error("exec command help error");
+ Runtime.getRuntime().exec(URL);
+ } catch (IOException ioException) {
+ LOG.error("exec command help error" + ioException);
}
dispose();
}
@@ -139,7 +171,6 @@ public class GenerateDialog extends JDialog {
}
private void runFun(String destPath, String parentPath) {
- String command;
InputStream inputStream;
String sysName = System.getProperties().getProperty("os.name").toUpperCase();
@@ -150,17 +181,14 @@ public class GenerateDialog extends JDialog {
} else {
inputStream = getClass().getClassLoader().getResourceAsStream("cmds/linux/napi_generator-mac");
}
- command = genCommand(inputStream, destPath, parentPath);
-
+ String command = genCommand(inputStream, destPath, parentPath);
try {
- try {
- callExtProcess(command);
- } catch (InterruptedException e) {
- LOG.warn("exec command Interrupted");
- Thread.currentThread().interrupt();
- }
- } catch (IOException ex) {
- LOG.debug("exec command error");
+ callExtProcess(command);
+ } catch (IOException ioException) {
+ LOG.error("exec command error" + ioException);
+ } catch (InterruptedException exception) {
+ LOG.warn("exec command Interrupted" + exception);
+ Thread.currentThread().interrupt();
}
}
@@ -177,8 +205,8 @@ public class GenerateDialog extends JDialog {
try {
byte[] bs = inputStream.readAllBytes();
writeTmpFile(execFn, bs);
- } catch (IOException e) {
- LOG.error("runFun WIN write_tmp_file io error");
+ } catch (IOException ioException) {
+ LOG.error("runFun WIN write_tmp_file io error" + ioException);
}
}
return file + " " + "-f" + " " + destPath + " " + "-o" + " " + parentPath;
@@ -206,25 +234,30 @@ public class GenerateDialog extends JDialog {
}
private void writeCommand() {
- String command = "add_library(napitest SHARED x_napi_tool.cpp napitest.cpp napitest_middle.cpp)".replaceAll("napitest", fileName) + "\n" + "target_link_libraries(napitest libace_napi.z.so)".replaceAll("napitest", fileName);
FileUtil fileUtil = new FileUtil();
String filePath = fileUtil.makeFile(directoryPath + "/makeFile.txt");
if (TextUtils.isEmpty(filePath)) {
LOG.error("makeFile is error");
return;
}
- if (!fileUtil.findStringInFile(filePath, command)) {
- fileUtil.writeErrorToTxt(filePath, command);
+ 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);
}
}
private void executable(String execFn) {
try {
callExtProcess("chmod a+x " + execFn);
- } catch (IOException e) {
- LOG.warn("LINUX IOException error");
- } catch (InterruptedException e) {
- LOG.warn("exec chmod command Interrupted");
+ } catch (IOException ioException) {
+ LOG.warn("LINUX IOException error" + ioException);
+ } catch (InterruptedException exception) {
+ LOG.warn("exec chmod command Interrupted" + exception);
Thread.currentThread().interrupt();
}
}
@@ -237,26 +270,26 @@ public class GenerateDialog extends JDialog {
LOG.info("writeTmpFile createNewFile error");
}
}
- FileOutputStream fw = null;
- try {
- fw = new FileOutputStream(file);
+ try (FileOutputStream fw = new FileOutputStream(file)) {
fw.write(bs, 0, bs.length);
- } catch (IOException e) {
- LOG.error("writeTmpFile io error");
- } finally {
- if (fw != null) {
- fw.close();
- }
+ } catch (IOException ioException) {
+ LOG.error("writeTmpFile io error" + ioException);
}
}
private void promptDialog() {
- JDialog dialog;
if (generateSuccess) {
- dialog = new GenResultDialog(directoryPath);
+ GenResultDialog genResultDialog = new GenResultDialog(directoryPath);
+ genResultDialog.initResultDialog();
+ setMethod(genResultDialog);
} else {
- dialog = new ErrorDialog(sErrorMessage);
+ ErrorDialog errorDialog = new ErrorDialog(sErrorMessage);
+ errorDialog.initDialog();
+ setMethod(errorDialog);
}
+ }
+
+ private void setMethod(JDialog dialog) {
dialog.setLocationRelativeTo(dialog);
dialog.pack();
dialog.setVisible(true);
@@ -286,9 +319,9 @@ public class GenerateDialog extends JDialog {
if ((sTmp = stdError.readLine()) == null) {
break;
}
- sErr += sTmp + "\n";
- } catch (IOException e) {
- LOG.error(" genResultLog stdInput error");
+ sErr += sTmp + FileUtil.getNewline();
+ } catch (IOException ioException) {
+ LOG.error(" genResultLog stdInput error" + ioException);
}
}
return sErr;
@@ -311,9 +344,9 @@ public class GenerateDialog extends JDialog {
if ((sTmp = stdInput.readLine()) == null) {
break;
}
- sOut += sTmp + "\n";
- } catch (IOException e) {
- LOG.error(" genResultLog stdInput error");
+ sOut += sTmp + FileUtil.getNewline();
+ } catch (IOException ioException) {
+ LOG.error(" genResultLog stdInput error" + ioException);
}
}
return sOut;
@@ -336,8 +369,8 @@ public class GenerateDialog extends JDialog {
while ((line = br.readLine()) != null) {
LOG.error("StreamConsumer" + line);
}
- } catch (IOException ex) {
- LOG.error("StreamConsumer io error");
+ } catch (IOException ioException) {
+ LOG.error("StreamConsumer io error" + ioException);
}
}
}
diff --git a/src/generator/src/com/sk/ng/GenDTS.java b/src/generator/src/com/sk/ng/GenDTS.java
index 85563fbd20e9139785858d762dac24917be61db8..99d78a911260d1c2f12aa1cbb8b0a79a7ead45e3 100644
--- a/src/generator/src/com/sk/ng/GenDTS.java
+++ b/src/generator/src/com/sk/ng/GenDTS.java
@@ -26,8 +26,9 @@ import java.util.regex.Pattern;
/**
* @author: xudong
- * @see: 工具转换插件
- * @version: 2022/02/21/v1.0.0
+ * @see: tool conversion plug-in
+ * @version: v1.0.0
+ * @since 2022/02/21
*/
public class GenDTS extends AnAction {
private static final Logger LOG = Logger.getInstance(GenDTS.class);
@@ -54,6 +55,7 @@ public class GenDTS extends AnAction {
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);
diff --git a/src/generator/src/com/sk/utils/FileUtil.java b/src/generator/src/com/sk/utils/FileUtil.java
index d43d7de35f3949a8c48b0a777791a40e428694f9..63ff813036cf22765b423e1a7b3b45d1849e3f54 100644
--- a/src/generator/src/com/sk/utils/FileUtil.java
+++ b/src/generator/src/com/sk/utils/FileUtil.java
@@ -15,13 +15,20 @@
package com.sk.utils;
import com.intellij.openapi.diagnostic.Logger;
+import org.apache.commons.lang3.StringUtils;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
/**
* @author: xudong
- * @see: 文件相关操作工具
- * @version: 2022/02/21/v1.0.0
+ * @see: file utils
+ * @version: v1.0.0
+ * @since 2022/02/21
*/
public class FileUtil {
private static final Logger LOG = Logger.getInstance(FileUtil.class);
@@ -29,27 +36,16 @@ public class FileUtil {
/**
* 将错误信息输入到txt中
*
- * @param path
- * @param content
- * @throws IOException
+ * @param path 路径
+ * @param content 内容
+ * @throws IOException 异常
*/
public void writeErrorToTxt(String path, String content) {
File file = new File(path);
- FileWriter fw = null;
- try {
- //设置为:True,表示写入的时候追加数据
- fw = new FileWriter(file, true);
- fw.write(content + "\r\n");
- } catch (IOException e) {
- LOG.error("writeErrorToTxt io error");
- } finally {
- if (fw != null) {
- try {
- fw.close();
- } catch (IOException e) {
- LOG.error("writeErrorToTxt io error");
- }
- }
+ try (FileWriter fw = new FileWriter(file, true)) {
+ fw.write(content + FileUtil.getNewline());
+ } catch (IOException ioException) {
+ LOG.error("writeErrorToTxt io error" + ioException);
}
}
@@ -64,9 +60,13 @@ public class FileUtil {
if (!file.exists()) {
try {
boolean isCreateFile = file.createNewFile();
- LOG.info("makeFile result isCreateFile = " + isCreateFile);
- } catch (IOException e) {
- LOG.error("writeErrorToTxt io error");
+ if (isCreateFile) {
+ LOG.info("makeFile result success");
+ } else {
+ LOG.info("makeFile result error");
+ }
+ } catch (IOException ioException) {
+ LOG.error("makeFile io error" + ioException);
return "";
}
}
@@ -79,21 +79,15 @@ public class FileUtil {
* @param path 文件路径
* @param content 指定内容
* @return 是否包含指定字符串
+ * @throws IOException 异常信息
*/
- public boolean findStringInFile(String path, String content) {
+ public boolean findStringInFile(String path, String content) throws IOException {
File file = new File(path);
- String[] command = content.split("\n");
- InputStreamReader read = null;
- try {
- read = new InputStreamReader(new FileInputStream(file), "UTF-8");
- } catch (UnsupportedEncodingException e) {
- LOG.error("findStringInFile encodingException");
- } catch (FileNotFoundException e) {
- LOG.error("findStringInFile FileNotFoundException");
+ String[] command = content.split(StringUtils.LF);
+ try (InputStreamReader read = new InputStreamReader(new FileInputStream(file), "UTF-8");
+ BufferedReader bufferedReader = new BufferedReader(read)) {
+ return isContainString(bufferedReader, command);
}
- //考虑到编码格式
- BufferedReader bufferedReader = new BufferedReader(read);
- return isContainString(bufferedReader, command);
}
private boolean isContainString(BufferedReader bufferedReader, String[] command) {
@@ -103,13 +97,13 @@ public class FileUtil {
if (!((line = bufferedReader.readLine()) != null)) {
return false;
}
- } catch (IOException e) {
- LOG.error("findStringInFile IOException");
+ } catch (IOException ioException) {
+ LOG.error("findStringInFile IOException" + ioException);
} finally {
try {
bufferedReader.close();
- } catch (IOException e) {
- LOG.error("findStringInFile io error");
+ } catch (IOException ioException) {
+ LOG.error("findStringInFile io error" + ioException);
}
}
line += line;
@@ -118,4 +112,13 @@ public class FileUtil {
}
}
}
+
+ /**
+ * 获取换行符
+ *
+ * @return 换行符
+ */
+ public static String getNewline() {
+ return System.getProperty("line.separator");
+ }
}