Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

搜索结果新增idea表达式 #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ private void searchObject(String filed_name,Object filed_object,String log_chain
// 搜索
if(!is_search_all){
if(MatchUtil.matchClassType(clazz.getName(),this.keys)){
write2log(result_file,new_log_chain + "\n\n\n");
write2log(result_file,new_log_chain + "\n");
write2log(result_file, "idea_express: " + genExpress(new_log_chain) + "\n\n\n");
if(is_debug) {
write2log(all_chain_file, new_log_chain + "\n\n\n");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import me.gv7.tools.josearcher.utils.CheckUtil;
import me.gv7.tools.josearcher.utils.LogUtil;
import me.gv7.tools.josearcher.utils.MatchUtil;

import java.lang.reflect.Field;
import java.util.*;

import static me.gv7.tools.josearcher.utils.CommonUtil.*;
import static me.gv7.tools.josearcher.utils.CommonUtil.write2log;
import static me.gv7.tools.josearcher.utils.CheckUtil.isList;
Expand All @@ -35,22 +37,22 @@ public class SearchRequstByBFS {
private String err_log_file;


public SearchRequstByBFS(Object target, List<Keyword> keys){
public SearchRequstByBFS(Object target, List<Keyword> keys) {
this.target = target;
this.keys = keys;
//把当前的元素加入到队列尾
q.offer(new NodeT.Builder().setChain("").setField_name("TargetObject").setField_object(target).build());
}

public void initSavePath(){
if(report_save_path == null){
this.result_file = String.format("%s_result_%s.txt",model_name,getCurrentDate());
this.all_chain_file = String.format("%s_log_%s.txt",model_name,getCurrentDate());
this.err_log_file = String.format("%s_error_%s.txt",model_name,getCurrentDate());
}else{
this.result_file = String.format("%s/%s_result_%s.txt",report_save_path,model_name,getCurrentDate());
this.all_chain_file = String.format("%s/%s_log_%s.txt",report_save_path,model_name,getCurrentDate());
this.err_log_file = String.format("%s_error_%s.txt",report_save_path,model_name,getCurrentDate());
public void initSavePath() {
if (report_save_path == null) {
this.result_file = String.format("%s_result_%s.txt", model_name, getCurrentDate());
this.all_chain_file = String.format("%s_log_%s.txt", model_name, getCurrentDate());
this.err_log_file = String.format("%s_error_%s.txt", model_name, getCurrentDate());
} else {
this.result_file = String.format("%s/%s_result_%s.txt", report_save_path, model_name, getCurrentDate());
this.all_chain_file = String.format("%s/%s_log_%s.txt", report_save_path, model_name, getCurrentDate());
this.err_log_file = String.format("%s_error_%s.txt", report_save_path, model_name, getCurrentDate());
}
}

Expand All @@ -75,9 +77,9 @@ public void setErrLogFile(String err_log_file) {
this.err_log_file = err_log_file;
}

public void searchObject(){
public void searchObject() {
this.initSavePath();
while(!q.isEmpty()){
while (!q.isEmpty()) {
NodeT node = q.poll();
String filed_name = node.getField_name();
Object filed_object = node.getField_object();
Expand All @@ -86,11 +88,11 @@ public void searchObject(){
int current_depth = node.getCurrent_depth();

//最多挖多深
if(current_depth > max_search_depth){
if (current_depth > max_search_depth) {
continue;
}

if (filed_object == null || CheckUtil.isSysType(filed_object) || MatchUtil.isInBlacklist(filed_name,filed_object,this.blacklists)){
if (filed_object == null || CheckUtil.isSysType(filed_object) || MatchUtil.isInBlacklist(filed_name, filed_object, this.blacklists)) {
//如果object是null/基本数据类型/包装类/日期类型,则不需要在递归调用
continue;
}
Expand All @@ -110,7 +112,8 @@ public void searchObject(){

// 搜索操作
if (MatchUtil.matchObject(filed_name, filed_object, keys)) {
write2log(result_file, new_log_chain + "\n\n\n");
write2log(result_file, new_log_chain + "\n");
write2log(result_file, "idea_express: " + genExpress(new_log_chain) + "\n\n\n");
}
if (is_debug) {
write2log(all_chain_file, new_log_chain + "\n\n\n");
Expand Down Expand Up @@ -263,8 +266,8 @@ public void searchObject(){
}
}
}
}catch (Throwable e){
LogUtil.saveThrowableInfo(e,this.err_log_file);
} catch (Throwable e) {
LogUtil.saveThrowableInfo(e, this.err_log_file);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ private void searchObject(String filed_name,Object filed_object,String log_chain
}

if(MatchUtil.matchObject(filed_name,filed_object,keys)){
write2log(result_file,new_log_chain + "\n\n\n");
write2log(result_file,new_log_chain + "\n");
write2log(result_file, "idea_express: " + genExpress(new_log_chain) + "\n\n\n");
}

if(is_debug) {
Expand Down
47 changes: 36 additions & 11 deletions src/main/java/me/gv7/tools/josearcher/utils/CommonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,70 @@
import java.util.Date;

public class CommonUtil {
public static String getBanner(){
public static String getBanner() {
String banner = "#############################################################\n" +
" Java Object Searcher v0.01\n" +
" author: c0ny1<[email protected]>\n" +
" github: http://github.com/c0ny1/java-object-searcher\n" +
"#############################################################\n\n\n";
" Java Object Searcher v0.01\n" +
" author: c0ny1<[email protected]>\n" +
" github: http://github.com/c0ny1/java-object-searcher\n" +
"#############################################################\n\n\n";
return banner;
}

public static void write2log(String filename,String content){
public static String genExpress(String log) {
String[] logs = log.split("--->");

String idea_express = null;
for (int i = 0; i < logs.length; i++) {
if (i == 0) {
idea_express = new Express(logs[i]).getField();
continue;
}
String express;
Express currentExpress = new Express(logs[i]);
Express previousExpress = new Express(logs[i - 1]);
express = String.format("%s.%s", idea_express, currentExpress.getField());
if (previousExpress.getClassName().contains("[Ljava")) {
express = String.format("%s%s", idea_express, currentExpress.getField());
}
if (previousExpress.getClassName().contains("Map")) {
express = String.format("%s.get(\"%s\")", idea_express, currentExpress.getField().replace("[", "").replace("]", ""));
}
idea_express = express;
}
return idea_express;
}


public static void write2log(String filename, String content) {
try {
File file = new File(filename);
String new_content;
if (!file.exists()) {
file.createNewFile();
new_content = getBanner() + content;
}else{
} else {
new_content = content;
}

//使用true,即进行append file
FileWriter fileWritter = new FileWriter(file, true);
fileWritter.write(new_content);
fileWritter.close();
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
}
}


public static String getBlank(int n){
public static String getBlank(int n) {
String strTab = "";
for(int i=0;i<n;i++){
for (int i = 0; i < n; i++) {
strTab += " ";
}
return strTab;
}

public static String getCurrentDate(){
public static String getCurrentDate() {
Date date = new Date();
String str = "yyyMMddHHmmss";
SimpleDateFormat sdf = new SimpleDateFormat(str);
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/me/gv7/tools/josearcher/utils/Express.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package me.gv7.tools.josearcher.utils;

class Express {
private String field;

public String getField() {
return field;
}

public String getClassName() {
return className;
}

private String className;

public Express(String data) {
String[] datas = data.split(" = ");
this.field = datas[0].trim();
this.className = datas[1].trim();
}
}