-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from ColdWaterLW/issue-1746
Issue 1746
- Loading branch information
Showing
6 changed files
with
71 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 57 additions & 16 deletions
73
src/main/java/com/actiontech/sqle/action/AuditMyBatis.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,77 @@ | ||
package com.actiontech.sqle.action; | ||
|
||
import com.actiontech.sqle.util.HttpClientUtil; | ||
import com.intellij.notification.Notification; | ||
import com.intellij.notification.NotificationType; | ||
import com.intellij.notification.Notifications; | ||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.CommonDataKeys; | ||
import com.intellij.openapi.actionSystem.*; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.intellij.psi.PsiFile; | ||
import org.apache.commons.io.FileUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.Objects; | ||
|
||
import com.intellij.ide.highlighter.XmlFileType; | ||
|
||
public class AuditMyBatis extends AnAction { | ||
private PsiFile file; | ||
private String fileName; | ||
private ArrayList<String> filePaths; | ||
|
||
@Override | ||
public void update(@NotNull AnActionEvent e) { | ||
this.file = e.getData(CommonDataKeys.PSI_FILE); | ||
this.fileName = this.file.getOriginalFile().getName(); | ||
|
||
if (!this.fileName.endsWith(".xml")) { | ||
filePaths = new ArrayList<>(); | ||
VirtualFile vFile = e.getData(PlatformDataKeys.VIRTUAL_FILE); | ||
if (vFile == null) { | ||
return; | ||
} | ||
System.out.println("test log"); | ||
String path = vFile.getPath(); | ||
if (vFile.isDirectory()) { | ||
gatherFilesFromDir(path); | ||
} else if (vFile.getFileType().getClass() == XmlFileType.class) { | ||
addFilePath(path); | ||
} else { | ||
e.getPresentation().setEnabled(false); | ||
} | ||
} | ||
|
||
private void addFilePath(String path) { | ||
if (filePaths.contains(path)) { | ||
return; | ||
} | ||
filePaths.add(path); | ||
} | ||
|
||
private void gatherFilesFromDir(String path) { | ||
File file = new File(path); | ||
if (file.isDirectory()) { | ||
File dir = new File(path); | ||
File[] files = dir.listFiles(); | ||
if (files == null) { | ||
return; | ||
} | ||
for (File f : files) { | ||
if (f.isDirectory()) { | ||
gatherFilesFromDir(f.getPath()); | ||
} else if (f.getName().endsWith(".xml")) { | ||
addFilePath(f.getPath()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void actionPerformed(AnActionEvent e) { | ||
String text = Objects.requireNonNull(file.getViewProvider().getDocument()).getText(); | ||
Audit.Audit(e, text, HttpClientUtil.AuditType.MyBatis); | ||
public void actionPerformed(@NotNull AnActionEvent event) { | ||
ArrayList<String> texts = new ArrayList<>(); | ||
for (String filePath : filePaths) { | ||
try { | ||
String text = Files.readString(Path.of(filePath)); | ||
texts.add(text); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
Audit.Audit(event, texts.toArray(new String[0]), HttpClientUtil.AuditType.MyBatis); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters