diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/DbeCommonUtils.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/DbeCommonUtils.java index 3543434012d35e64092d21decf351e65e3d4ce08..167b6545b0210ae0769d16e21583095e77f13186 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/DbeCommonUtils.java +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/DbeCommonUtils.java @@ -27,6 +27,7 @@ import java.util.stream.Collectors; import org.apache.commons.lang.StringUtils; import org.opengauss.mppdbide.debuger.service.DbeDebugService; +import org.opengauss.mppdbide.debuger.service.SourceCodeService; import org.opengauss.mppdbide.debuger.vo.dbe.InfoCodeVo; import org.opengauss.mppdbide.utils.IMessagesConstants; import org.opengauss.mppdbide.utils.loader.MessageConfigLoader; @@ -53,6 +54,10 @@ public final class DbeCommonUtils { */ public static final String END = "END"; + private static final String REPLACE_FUNCTION = "$function$"; + + private static final String REPLACED = "$$"; + private DbeCommonUtils() { } @@ -72,7 +77,10 @@ public final class DbeCommonUtils { List canBreaks = infos.stream().filter(item -> item.canbreak).collect(Collectors.toList()); for (int i = 0; i < indexs.size(); i++) { String selectCode = sourceCodes.get(Integer.parseInt(indexs.get(i))); - long count = canBreaks.stream().filter(item -> item.query.equalsIgnoreCase(selectCode)).count(); + long count = canBreaks.stream().filter(item -> { + String str = item.query.replaceAll(REPLACE_FUNCTION, REPLACED); + return str.equalsIgnoreCase(selectCode); + }).count(); if (count == 0) { throw new SQLException(MessageConfigLoader.getProperty(IMessagesConstants.NOT_SUPPORT_BREAK)); } @@ -99,6 +107,14 @@ public final class DbeCommonUtils { map.put(END, i); } } + Integer begin = map.get(BEGIN); + Integer end = map.get(END); + if (begin == null) { + map.put(BEGIN, getBeginIndex(sourceCodes, BEGIN)); + } + if (end == null) { + map.put(END, getEndIndex(sourceCodes, END)); + } return map; } @@ -113,6 +129,49 @@ public final class DbeCommonUtils { return firstCode.toUpperCase(Locale.ENGLISH).trim().startsWith(endCode); } + /** + * getBeginIndex + * + * @param codes codes + * @param match match + * @return int int + */ + public static int getBeginIndex(List codes, String match) { + for(int i =0; i codes, String match) { + for(int i =codes.size()-1; i sourceCodes, String match) { + return sourceCodes.stream().filter(item -> checkStrEquals(item ,END)).count(); + } + /** * getCanBreakLinesByInfo * @@ -122,7 +181,7 @@ public final class DbeCommonUtils { * @return List string */ public static List getCanBreakLinesByInfo(IConnection conn, List inputsParams, - List sourceCodes) { + List sourceCodes) { List infos = null; try { infos = DbeDebugService.getInfoCodes(conn, inputsParams); @@ -145,6 +204,9 @@ public final class DbeCommonUtils { List linse = new ArrayList(); for (int i = map.get(BEGIN); i < sourceCodes.size(); i++) { if (i >= map.get(END)) { + if (checkIsEqualLine(sourceCodes, END) == 0) { + linse.add(String.valueOf(i)); + } return linse; } if (i < infos.size() && infos.get(i).canbreak) { diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DbeSourceCodeService.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DbeSourceCodeService.java index 16a430449df1ac77405d415edb14e76f89275c83..a026eb0af85f7a5577201b61f9d7b8750dae86c4 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DbeSourceCodeService.java +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DbeSourceCodeService.java @@ -16,6 +16,7 @@ package org.opengauss.mppdbide.debuger.service; import java.util.List; +import java.util.Locale; import org.opengauss.mppdbide.common.DbeCommonUtils; import org.opengauss.mppdbide.debuger.exception.DebugPositionNotFoundException; @@ -37,4 +38,56 @@ public class DbeSourceCodeService extends SourceCodeService { List terminalCodes = super.totalCodeDesc.getCodeList(); return DbeCommonUtils.compluteIndex(DbeCommonUtils.infoCodes, terminalCodes); } -} + + /** + * set base code + * + * @param the base code + * @return void + */ + @Override + public void setBaseCode(String code) { + this.baseCodeDesc = new DbeCodeDescription(code); + } + + /** + * set total code + * + * @param the total code + * @return void + */ + @Override + public void setTotalCode(String code) { + this.totalCodeDesc = new DbeCodeDescription(code); + } + + /** + * Title: CodeDescription class + */ + public static class DbeCodeDescription extends CodeDescription{ + /** + * DbeCodeDescription + * + * @param code + */ + public DbeCodeDescription(String code) { + super(code); + } + + /** + * get BeginFromCode + * + * @param lines line + * @return int linse item + */ + @Override + public int getBeginFromCode(List lines) { + for (int i = 0; i < lines.size(); i++) { + if (lines.get(i).toUpperCase(Locale.ENGLISH).trim().startsWith(DbeCommonUtils.BEGIN)) { + return i; + } + } + return DbeCommonUtils.getBeginIndex(lines, DbeCommonUtils.BEGIN); + } + } +} \ No newline at end of file diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/utils/ExportUtil.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/utils/ExportUtil.java index 64625203f596136ec0960d52ecc01671a7540874..3735cd6f667090091de128cad3bc135b9547efc9 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/utils/ExportUtil.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/utils/ExportUtil.java @@ -43,6 +43,9 @@ import org.opengauss.mppdbide.utils.logger.MPPDBIDELoggerUtility; * @since 3.0.0 */ public final class ExportUtil { + private static final String USER_DIR = "user.dir"; + private static final String FILE_SEP = "file.separator"; + private static final String LINE_SEP = "line.separator"; private static String outpath; private static File file; @@ -127,10 +130,15 @@ public final class ExportUtil { if (html == null) { String path = FileLocator.toFileURL(url).getPath().substring(1); file = new File(path); - String workDir = System.getProperty("user.dir"); - String fileSepa = System.getProperty("file.separator"); - outpath = String.format(Locale.ENGLISH, "%s%s%s_%s_%s.html", - workDir, fileSepa, oid, sqlName, System.currentTimeMillis()); + String workDir = System.getProperty(USER_DIR); + String fileSepa = System.getProperty(FILE_SEP); + String dir = String.format(Locale.ENGLISH, "%s%shis_coverage%s", workDir, fileSepa, fileSepa); + File outFile = new File(dir); + if (!outFile.exists()) { + outFile.mkdir(); + } + outpath = String.format(Locale.ENGLISH, "%s%s_%s_%s.html", dir, oid, sqlName, + System.currentTimeMillis()); parse = Jsoup.parse(file, "gbk"); convertZhCn(parse); } else { @@ -180,7 +188,7 @@ public final class ExportUtil { BufferedWriter bw = new BufferedWriter(new FileWriter(new File(path))); String[] split = text.split(" "); for (String str : split) { - bw.write(str + System.getProperty("line.separator")); + bw.write(str + System.getProperty(LINE_SEP)); } if (bw != null) { bw.close();