diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java index ecf7999e17..b4cc54fc85 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java @@ -644,7 +644,7 @@ public class ElementUtil { if (arguments != null) { for (int i = 0; i < arguments.getArguments().size(); ++i) { String argValue = arguments.getArgument(i).getValue(); - script.append("vars.put(\"" + arguments.getArgument(i).getName() + "\",\"" + argValue + "\");").append("\n"); + script.append("vars.put(\"" + arguments.getArgument(i).getName() + "\",\"" + argValue + "\");").append(StringUtils.LF); } processor.setProperty("script", script.toString()); } diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java index 60d0d2f0b3..f74dbc6d07 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/controller/MsLoopController.java @@ -195,7 +195,7 @@ public class MsLoopController extends MsTestElement { } private String script() { - String script = "\n" + "import java.util.*;\n" + "import java.text.SimpleDateFormat;\n" + "import org.apache.jmeter.threads.JMeterContextService;\n" + "\n" + "// 循环控制器超时后结束循环\n" + "try{\n" + "\tString ms_current_timer = vars.get(\"" + ms_current_timer + "\");\n" + "\tlong _nowTime = System.currentTimeMillis(); \n" + "\tif(ms_current_timer == null ){\n" + "\t\tvars.put(\"" + ms_current_timer + "\",_nowTime.toString());\n" + "\t}\n" + "\tlong time = Long.parseLong(vars.get(\"" + ms_current_timer + "\"));\n" + "\t if((_nowTime - time) > " + this.whileController.getTimeout() + " ){\n" + "\t \tvars.put(\"" + ms_current_timer + "\", \"stop\");\n" + "\t \tlog.info( \"结束循环\");\n" + "\t }\n" + "}catch (Exception e){\n" + "\tlog.info( e.getMessage());\n" + "\tvars.put(\"" + ms_current_timer + "\", \"stop\");\n" + "}\n"; + String script = StringUtils.LF + "import java.util.*;\n" + "import java.text.SimpleDateFormat;\n" + "import org.apache.jmeter.threads.JMeterContextService;\n" + "\n" + "// 循环控制器超时后结束循环\n" + "try{\n" + "\tString ms_current_timer = vars.get(\"" + ms_current_timer + "\");\n" + "\tlong _nowTime = System.currentTimeMillis(); \n" + "\tif(ms_current_timer == null ){\n" + "\t\tvars.put(\"" + ms_current_timer + "\",_nowTime.toString());\n" + "\t}\n" + "\tlong time = Long.parseLong(vars.get(\"" + ms_current_timer + "\"));\n" + "\t if((_nowTime - time) > " + this.whileController.getTimeout() + " ){\n" + "\t \tvars.put(\"" + ms_current_timer + "\", \"stop\");\n" + "\t \tlog.info( \"结束循环\");\n" + "\t }\n" + "}catch (Exception e){\n" + "\tlog.info( e.getMessage());\n" + "\tvars.put(\"" + ms_current_timer + "\", \"stop\");\n" + "}\n"; return script; } diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/engine/EngineSourceParserFactory.java b/api-test/backend/src/main/java/io/metersphere/api/exec/engine/EngineSourceParserFactory.java index 09fa40b39e..62ab84255f 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/engine/EngineSourceParserFactory.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/engine/EngineSourceParserFactory.java @@ -47,7 +47,7 @@ public class EngineSourceParserFactory { // 删除空白的行 List nodes = document.selectNodes("//text()[normalize-space(.)='']"); nodes.forEach(node -> { - if (node.getText().contains("\n")) { + if (node.getText().contains(StringUtils.LF)) { node.setText(""); } }); diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/engine/KubernetesTestEngine.java b/api-test/backend/src/main/java/io/metersphere/api/exec/engine/KubernetesTestEngine.java index 84c753d963..fc736ce8d6 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/engine/KubernetesTestEngine.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/engine/KubernetesTestEngine.java @@ -51,8 +51,8 @@ public class KubernetesTestEngine extends AbstractEngine { Pod pod = KubernetesApiExec.getExecPod(clientCredential, client); StringBuffer logMsg = new StringBuffer("当前报告:【" + runRequest.getReportId() + "】资源:【" + runRequest.getTestId() + "】") - .append("\n").append("namespace:").append(clientCredential.getNamespace()) - .append("\n").append("Pod信息:【 ") + .append(StringUtils.LF).append("namespace:").append(clientCredential.getNamespace()) + .append(StringUtils.LF).append("Pod信息:【 ") .append(JSON.toJSONString(pod.getMetadata())).append(" 】"); LoggerUtil.info(logMsg); // 拼接CURL执行命令 diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/queue/ExecThreadPoolExecutor.java b/api-test/backend/src/main/java/io/metersphere/api/exec/queue/ExecThreadPoolExecutor.java index 1fd5a4164d..ec1e85f1dc 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/queue/ExecThreadPoolExecutor.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/queue/ExecThreadPoolExecutor.java @@ -83,15 +83,15 @@ public class ExecThreadPoolExecutor { public void outApiThreadPoolExecutorLogger(String message) { ArrayBlockingQueue queue = (ArrayBlockingQueue) threadPool.getQueue(); - StringBuffer buffer = new StringBuffer("\n" + message); - buffer.append("\n").append("线程池详情:").append("\n"); - buffer.append(" 核心线程数:" + threadPool.getCorePoolSize()).append("\n"); - buffer.append(" 活动线程数:" + threadPool.getActiveCount()).append(" (略有波动非精确数据)").append("\n"); - buffer.append(" 最大线程数:" + threadPool.getMaximumPoolSize()).append("\n"); - buffer.append(" 线程池活跃度:" + divide(threadPool.getActiveCount(), threadPool.getMaximumPoolSize())).append("\n"); - buffer.append(" 最大队列数:" + (queue.size() + queue.remainingCapacity())).append("\n"); - buffer.append(" 当前排队线程数:" + (msRejectedExecutionHandler.getBufferQueue().size() + queue.size())).append("\n"); - buffer.append(" 执行中队列大小:" + PoolExecBlockingQueueUtil.queue.size()).append("\n"); + StringBuffer buffer = new StringBuffer(org.apache.commons.lang3.StringUtils.LF + message); + buffer.append("\n").append("线程池详情:").append(org.apache.commons.lang3.StringUtils.LF); + buffer.append(" 核心线程数:" + threadPool.getCorePoolSize()).append(org.apache.commons.lang3.StringUtils.LF); + buffer.append(" 活动线程数:" + threadPool.getActiveCount()).append(" (略有波动非精确数据)").append(org.apache.commons.lang3.StringUtils.LF); + buffer.append(" 最大线程数:" + threadPool.getMaximumPoolSize()).append(org.apache.commons.lang3.StringUtils.LF); + buffer.append(" 线程池活跃度:" + divide(threadPool.getActiveCount(), threadPool.getMaximumPoolSize())).append(org.apache.commons.lang3.StringUtils.LF); + buffer.append(" 最大队列数:" + (queue.size() + queue.remainingCapacity())).append(org.apache.commons.lang3.StringUtils.LF); + buffer.append(" 当前排队线程数:" + (msRejectedExecutionHandler.getBufferQueue().size() + queue.size())).append(org.apache.commons.lang3.StringUtils.LF); + buffer.append(" 执行中队列大小:" + PoolExecBlockingQueueUtil.queue.size()).append(org.apache.commons.lang3.StringUtils.LF); buffer.append(" 队列使用度:" + divide(queue.size(), queue.size() + queue.remainingCapacity())); LoggerUtil.info(buffer.toString()); @@ -172,7 +172,7 @@ public class ExecThreadPoolExecutor { workerQueue.forEach(item -> { ExecTask task = (ExecTask) item; if (task.getRequest() != null) { - buffer.append("等待队列报告:【 " + task.getRequest().getReportId() + "】资源:【 " + task.getRequest().getTestId() + "】").append("\n"); + buffer.append("等待队列报告:【 " + task.getRequest().getReportId() + "】资源:【 " + task.getRequest().getTestId() + "】").append(org.apache.commons.lang3.StringUtils.LF); } }); diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiEnvironmentRunningParamService.java b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiEnvironmentRunningParamService.java index 771ecff3e5..e824684e5c 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiEnvironmentRunningParamService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiEnvironmentRunningParamService.java @@ -108,7 +108,7 @@ public class ApiEnvironmentRunningParamService { } public void parseEvn(String envStr) { - String[] envStringArr = envStr.split("\n"); + String[] envStringArr = envStr.split(StringUtils.LF); Map> envVarsMap = new HashMap<>(); for (String env : envStringArr) { if (StringUtils.contains(env, "=")) { diff --git a/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterLoggerAppender.java b/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterLoggerAppender.java index 1e1ae6d012..96a4c8e4c7 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterLoggerAppender.java +++ b/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterLoggerAppender.java @@ -17,14 +17,14 @@ public class JMeterLoggerAppender extends UnsynchronizedAppenderBase entry : variables.entrySet()) { - builder.append(entry.getKey()).append(":").append(entry.getValue()).append("\n"); + builder.append(entry.getKey()).append(":").append(entry.getValue()).append(StringUtils.LF); } if (StringUtils.isNotEmpty(builder)) { result.setExtVars(builder.toString()); diff --git a/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java b/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java index 2137664f64..269a36bddc 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java +++ b/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsKafkaListener.java @@ -6,6 +6,7 @@ import io.metersphere.commons.utils.NamedThreadFactory; import io.metersphere.service.ApiExecutionQueueService; import io.metersphere.service.TestResultService; import io.metersphere.utils.LoggerUtil; +import org.apache.commons.lang3.StringUtils; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.springframework.context.annotation.Configuration; import org.springframework.kafka.annotation.KafkaListener; @@ -65,19 +66,19 @@ public class MsKafkaListener { public void outKafkaPoolLogger() { StringBuffer buffer = new StringBuffer() - .append("\n") + .append(StringUtils.LF) .append("KAFKA Consume 线程池详情:") - .append("\n") + .append(StringUtils.LF) .append(" KAFKA Consume 核心线程数:" + threadPool.getCorePoolSize()) - .append("\n") + .append(StringUtils.LF) .append(" KAFKA Consume 活动线程数:" + threadPool.getActiveCount()) - .append("\n") + .append(StringUtils.LF) .append(" KAFKA Consume 最大线程数:" + threadPool.getMaximumPoolSize()) - .append("\n") + .append(StringUtils.LF) .append(" KAFKA Consume 最大队列数:" + (threadPool.getQueue().size() + threadPool.getQueue().remainingCapacity())) - .append("\n") + .append(StringUtils.LF) .append(" KAFKA Consume 当前排队线程数:" + (threadPool.getQueue().size())) - .append("\n"); + .append(StringUtils.LF); LoggerUtil.info(buffer.toString()); } diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/HarScenarioAbstractParser.java b/api-test/backend/src/main/java/io/metersphere/api/parse/HarScenarioAbstractParser.java index 6dc42f0b38..795ae505ab 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/HarScenarioAbstractParser.java +++ b/api-test/backend/src/main/java/io/metersphere/api/parse/HarScenarioAbstractParser.java @@ -163,7 +163,7 @@ public abstract class HarScenarioAbstractParser extends ApiImportAbstractPars if (CollectionUtils.isNotEmpty(exec)) { exec.forEach(col -> { if (StringUtils.isNotEmpty(col)) { - scriptStr.append(col + "\n"); + scriptStr.append(col + StringUtils.LF); } }); } diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/JmeterDocumentParser.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/JmeterDocumentParser.java index b3a4588338..d84e6c4d8f 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/JmeterDocumentParser.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/JmeterDocumentParser.java @@ -255,7 +255,7 @@ public class JmeterDocumentParser implements EngineSourceParser { if (content == null) { return; } - StringTokenizer tokenizer = new StringTokenizer(new String(content), "\n"); + StringTokenizer tokenizer = new StringTokenizer(new String(content), StringUtils.LF); if (!tokenizer.hasMoreTokens()) { return; } @@ -268,7 +268,7 @@ public class JmeterDocumentParser implements EngineSourceParser { boolean csvHasHeader = ((JSONObject) (config)).getBoolean("csvHasHeader"); if (csvHasHeader) { String header = tokenizer.nextToken(); - csv.append(header).append("\n"); + csv.append(header).append(StringUtils.LF); } int count = tokenizer.countTokens(); @@ -289,7 +289,7 @@ public class JmeterDocumentParser implements EngineSourceParser { while (tokenizer.hasMoreTokens()) { if (current == 0) { // 节点一个都没有分到,把所有的数据都给这个节点(极端情况) String line = tokenizer.nextToken(); - csv.append(line).append("\n"); + csv.append(line).append(StringUtils.LF); } else { if (index <= offset) { tokenizer.nextToken(); @@ -300,7 +300,7 @@ public class JmeterDocumentParser implements EngineSourceParser { break; } String line = tokenizer.nextToken(); - csv.append(line).append("\n"); + csv.append(line).append(StringUtils.LF); } index++; } diff --git a/api-test/backend/src/main/java/io/metersphere/listener/ApiAppStartListener.java b/api-test/backend/src/main/java/io/metersphere/listener/ApiAppStartListener.java index 4b498b55b5..e6ce8e66b2 100644 --- a/api-test/backend/src/main/java/io/metersphere/listener/ApiAppStartListener.java +++ b/api-test/backend/src/main/java/io/metersphere/listener/ApiAppStartListener.java @@ -77,13 +77,13 @@ public class ApiAppStartListener implements ApplicationRunner { LogUtil.info("starting quartz"); StringBuffer buffer = new StringBuffer("定时任务相关设置:"); buffer.append("quartz.acquireTriggersWithinLock :") - .append(acquireTriggersWithinLock).append("\n") + .append(acquireTriggersWithinLock).append(StringUtils.LF) .append("quartz.enabled ") - .append(quartzEnable).append("\n") + .append(quartzEnable).append(StringUtils.LF) .append("quartz.scheduler-name ") - .append(quartzScheduleName).append("\n") + .append(quartzScheduleName).append(StringUtils.LF) .append("quartz.thread-count ") - .append(quartzThreadCount).append("\n"); + .append(quartzThreadCount).append(StringUtils.LF); LogUtil.info(buffer.toString()); scheduleService.startEnableSchedules(ScheduleGroup.API_SCENARIO_TEST); diff --git a/api-test/backend/src/main/java/io/metersphere/service/RemakeReportService.java b/api-test/backend/src/main/java/io/metersphere/service/RemakeReportService.java index 318e02ff94..03cc54bb27 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/RemakeReportService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/RemakeReportService.java @@ -184,7 +184,7 @@ public class RemakeReportService { // 全局并发队列 PoolExecBlockingQueueUtil.offer(dto.getReportId()); String consoleMsg = FixedCapacityUtil.getJmeterLogger(dto.getReportId(), true); - dto.setConsole(consoleMsg + "\n" + errorMsg); + dto.setConsole(consoleMsg + StringUtils.LF + errorMsg); // 整体执行结束更新资源状态 CommonBeanFactory.getBean(TestResultService.class).testEnded(dto); diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/EnumPropertyUtil.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/EnumPropertyUtil.java index 0272fa7021..68cc57bd85 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/EnumPropertyUtil.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/EnumPropertyUtil.java @@ -4,6 +4,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.metersphere.commons.json.BasicConstant; +import org.apache.commons.lang3.StringUtils; import java.util.LinkedList; import java.util.List; @@ -22,7 +23,7 @@ public class EnumPropertyUtil { jsonStr = object.get(BasicConstant.ENUM).getAsString(); } if (jsonStr != null && list.isEmpty()) { - String[] arrays = jsonStr.split("\n"); + String[] arrays = jsonStr.split(StringUtils.LF); for (String str : arrays) { list.add(str); } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/LogUtil.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/LogUtil.java index 3b2fba94a6..1b209e974a 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/LogUtil.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/LogUtil.java @@ -1,5 +1,6 @@ package io.metersphere.commons.utils; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -260,9 +261,9 @@ public class LogUtil { StackTraceElement[] stackElements = e.getStackTrace(); for (StackTraceElement stackTraceElement : stackElements) { sb.append(stackTraceElement.toString()); - sb.append("\n"); + sb.append(StringUtils.LF); } - sb.append("\n"); + sb.append(StringUtils.LF); return sb.toString(); } } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/log/utils/diff/json/Leaf.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/log/utils/diff/json/Leaf.java index 97429a764e..48a2e05785 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/log/utils/diff/json/Leaf.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/log/utils/diff/json/Leaf.java @@ -4,6 +4,7 @@ import io.metersphere.log.utils.diff.json.jsonwrap.JzonArray; import io.metersphere.log.utils.diff.json.jsonwrap.JzonElement; import io.metersphere.log.utils.diff.json.jsonwrap.JzonObject; import io.metersphere.log.utils.diff.json.jsonwrap.Wrapper; +import org.apache.commons.lang3.StringUtils; import java.util.*; import java.util.logging.Level; @@ -378,7 +379,7 @@ class Leaf implements Comparable { bld.append("_ORPHAN"); } bld.append(">"); - bld.append("\n"); + bld.append(StringUtils.LF); return bld.toString(); diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseUserService.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseUserService.java index 4026be346b..d1b80e3997 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseUserService.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseUserService.java @@ -561,7 +561,7 @@ public class BaseUserService { List names = users.stream().map(User::getName).collect(Collectors.toList()); StringBuilder nameBuilder = new StringBuilder(); - nameBuilder.append(String.join(",", names)).append("\n"); + nameBuilder.append(String.join(",", names)).append(StringUtils.LF); for (String userId : ids) { UserGroupExample userGroupExample = new UserGroupExample(); userGroupExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(id); diff --git a/performance-test/backend/src/main/java/io/metersphere/engine/EngineFactory.java b/performance-test/backend/src/main/java/io/metersphere/engine/EngineFactory.java index a84fcab0a4..05833af0e1 100644 --- a/performance-test/backend/src/main/java/io/metersphere/engine/EngineFactory.java +++ b/performance-test/backend/src/main/java/io/metersphere/engine/EngineFactory.java @@ -221,7 +221,7 @@ public class EngineFactory { if (!(Boolean) prop.get("enable")) { continue; } - dns.append(prop.get("ip")).append(StringUtils.SPACE).append(prop.get("domain")).append("\n"); + dns.append(prop.get("ip")).append(StringUtils.SPACE).append(prop.get("domain")).append(StringUtils.LF); } } } @@ -240,7 +240,7 @@ public class EngineFactory { if (!(Boolean) prop.get("enable")) { continue; } - props.append(prop.get("name")).append("=").append(prop.get("value")).append("\n"); + props.append(prop.get("name")).append("=").append(prop.get("value")).append(StringUtils.LF); } } } @@ -259,7 +259,7 @@ public class EngineFactory { if (!(Boolean) prop.get("enable")) { continue; } - props.append(prop.get("name")).append("=").append(prop.get("value")).append("\n"); + props.append(prop.get("name")).append("=").append(prop.get("value")).append(StringUtils.LF); } } } diff --git a/performance-test/backend/src/main/java/io/metersphere/parse/EngineSourceParserFactory.java b/performance-test/backend/src/main/java/io/metersphere/parse/EngineSourceParserFactory.java index 64ed296a9d..5d4659b0b3 100644 --- a/performance-test/backend/src/main/java/io/metersphere/parse/EngineSourceParserFactory.java +++ b/performance-test/backend/src/main/java/io/metersphere/parse/EngineSourceParserFactory.java @@ -60,7 +60,7 @@ public class EngineSourceParserFactory { // 删除空白的行 List nodes = document.selectNodes("//text()[normalize-space(.)='']"); nodes.forEach(node -> { - if (node.getText().contains("\n")) { + if (node.getText().contains(StringUtils.LF)) { node.setText(StringUtils.EMPTY); } }); diff --git a/performance-test/backend/src/main/java/io/metersphere/parse/xml/reader/JmeterDocumentParser.java b/performance-test/backend/src/main/java/io/metersphere/parse/xml/reader/JmeterDocumentParser.java index 84403b5b07..4f21eb43de 100644 --- a/performance-test/backend/src/main/java/io/metersphere/parse/xml/reader/JmeterDocumentParser.java +++ b/performance-test/backend/src/main/java/io/metersphere/parse/xml/reader/JmeterDocumentParser.java @@ -253,7 +253,7 @@ public class JmeterDocumentParser implements EngineSourceParser { if (content == null) { return; } - StringTokenizer tokenizer = new StringTokenizer(new String(content), "\n"); + StringTokenizer tokenizer = new StringTokenizer(new String(content), StringUtils.LF); if (!tokenizer.hasMoreTokens()) { return; } @@ -266,7 +266,7 @@ public class JmeterDocumentParser implements EngineSourceParser { boolean csvHasHeader = (Boolean) ((Map) (config)).get("csvHasHeader"); if (csvHasHeader) { String header = tokenizer.nextToken(); - csv.append(header).append("\n"); + csv.append(header).append(StringUtils.LF); } int count = tokenizer.countTokens(); @@ -287,7 +287,7 @@ public class JmeterDocumentParser implements EngineSourceParser { while (tokenizer.hasMoreTokens()) { if (current == 0) { // 节点一个都没有分到,把所有的数据都给这个节点(极端情况) String line = tokenizer.nextToken(); - csv.append(line).append("\n"); + csv.append(line).append(StringUtils.LF); } else { if (index <= offset) { tokenizer.nextToken(); @@ -298,7 +298,7 @@ public class JmeterDocumentParser implements EngineSourceParser { break; } String line = tokenizer.nextToken(); - csv.append(line).append("\n"); + csv.append(line).append(StringUtils.LF); } index++; } diff --git a/performance-test/backend/src/main/java/io/metersphere/service/PerformanceTestService.java b/performance-test/backend/src/main/java/io/metersphere/service/PerformanceTestService.java index 65f061d488..14045a6c59 100644 --- a/performance-test/backend/src/main/java/io/metersphere/service/PerformanceTestService.java +++ b/performance-test/backend/src/main/java/io/metersphere/service/PerformanceTestService.java @@ -453,7 +453,7 @@ public class PerformanceTestService { reportDetail.setPart(1L); loadTestReportDetailMapper.insertSelective(reportDetail); // append \n - extLoadTestReportDetailMapper.appendLine(testReport.getId(), "\n"); + extLoadTestReportDetailMapper.appendLine(testReport.getId(), StringUtils.LF); // 保存一个 reportStatus LoadTestReportResult reportResult = new LoadTestReportResult(); reportResult.setId(UUID.randomUUID().toString()); @@ -1008,7 +1008,7 @@ public class PerformanceTestService { example.createCriteria().andIdIn(testIds); List loadTests = loadTestMapper.selectByExample(example); errorMessage += Translator.get("load_test") + ": " + StringUtils.join(loadTests.stream().map(LoadTest::getName).toArray(), ","); - errorMessage += "\n"; + errorMessage += StringUtils.LF; } if (StringUtils.isNotBlank(errorMessage)) { MSException.throwException(errorMessage + Translator.get("project_file_in_use")); diff --git a/project-management/backend/src/main/java/io/metersphere/code/snippet/JMeterLoggerAppender.java b/project-management/backend/src/main/java/io/metersphere/code/snippet/JMeterLoggerAppender.java index 0327f0b435..35a7483b01 100644 --- a/project-management/backend/src/main/java/io/metersphere/code/snippet/JMeterLoggerAppender.java +++ b/project-management/backend/src/main/java/io/metersphere/code/snippet/JMeterLoggerAppender.java @@ -18,14 +18,14 @@ public class JMeterLoggerAppender extends UnsynchronizedAppenderBase entry : variables.entrySet()) { - builder.append(entry.getKey()).append(":").append(entry.getValue()).append("\n"); + builder.append(entry.getKey()).append(":").append(entry.getValue()).append(StringUtils.LF); } if (StringUtils.isNotEmpty(builder)) { result.setExtVars(builder.toString()); diff --git a/report-stat/backend/src/main/java/io/metersphere/reportstatistics/service/EnterpriseTestReportService.java b/report-stat/backend/src/main/java/io/metersphere/reportstatistics/service/EnterpriseTestReportService.java index 956d18564a..b3f36b6ab8 100644 --- a/report-stat/backend/src/main/java/io/metersphere/reportstatistics/service/EnterpriseTestReportService.java +++ b/report-stat/backend/src/main/java/io/metersphere/reportstatistics/service/EnterpriseTestReportService.java @@ -354,7 +354,7 @@ public class EnterpriseTestReportService { for (EnterpriseReportContentStep step : stepList) { String title = "
\n" + - "" + step.getName() + "\n" + + "" + step.getName() + StringUtils.LF + "\n" + "
"; returnReportContentBuffer.append(title); diff --git a/system-setting/backend/src/main/java/io/metersphere/excel/listener/UserDataListener.java b/system-setting/backend/src/main/java/io/metersphere/excel/listener/UserDataListener.java index 0179bedc40..0aa3f9c88e 100644 --- a/system-setting/backend/src/main/java/io/metersphere/excel/listener/UserDataListener.java +++ b/system-setting/backend/src/main/java/io/metersphere/excel/listener/UserDataListener.java @@ -126,7 +126,7 @@ public class UserDataListener extends EasyExcelListener { private String checkWorkSpace(String userRoleInExcel, String workspaceInfoInExcel) { String result = null; if (StringUtils.equalsIgnoreCase(Translator.get("options_yes"), userRoleInExcel)) { - String[] workspaceArr = workspaceInfoInExcel.split("\n"); + String[] workspaceArr = workspaceInfoInExcel.split(StringUtils.LF); for (String workspace : workspaceArr) { if (!workspaceNameMap.containsKey(workspace)) { @@ -151,7 +151,7 @@ public class UserDataListener extends EasyExcelListener { private String checkProject(String userGroupInExcel, String projectInfoInExcel) { String result = null; if (StringUtils.equalsAnyIgnoreCase(Translator.get("options_yes"), userGroupInExcel)) { - String[] projectNameArr = projectInfoInExcel.split("\n"); + String[] projectNameArr = projectInfoInExcel.split(StringUtils.LF); for (String projectName : projectNameArr) { if (!projectNameMap.containsKey(projectName)) { if (result == null) { @@ -176,7 +176,7 @@ public class UserDataListener extends EasyExcelListener { private List getIdByExcelInfoAndIdDic(String userRoleInExcel, String nameStringInExce, Map idDic) { List resultList = new ArrayList<>(); if (StringUtils.equalsIgnoreCase(Translator.get("options_yes"), userRoleInExcel)) { - String[] nameArr = nameStringInExce.split("\n"); + String[] nameArr = nameStringInExce.split(StringUtils.LF); for (String name : nameArr) { if (idDic.containsKey(name)) { resultList.add(idDic.get(name)); diff --git a/system-setting/backend/src/main/java/io/metersphere/service/UserService.java b/system-setting/backend/src/main/java/io/metersphere/service/UserService.java index 1785d667f1..f8a248cb7b 100644 --- a/system-setting/backend/src/main/java/io/metersphere/service/UserService.java +++ b/system-setting/backend/src/main/java/io/metersphere/service/UserService.java @@ -950,7 +950,7 @@ public class UserService { List names = users.stream().map(User::getName).collect(Collectors.toList()); StringBuilder nameBuilder = new StringBuilder(); - nameBuilder.append(String.join(",", names)).append("\n"); + nameBuilder.append(String.join(",", names)).append(StringUtils.LF); for (String userId : ids) { UserGroupExample userGroupExample = new UserGroupExample(); userGroupExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(id); @@ -1019,7 +1019,7 @@ public class UserService { List users = userMapper.selectByExample(example); if (users != null) { List names = users.stream().map(User::getName).collect(Collectors.toList()); - String roles = "\n" + "成员角色:\n" + this.getRoles(users.get(0).getId()); + String roles = StringUtils.LF + "成员角色:\n" + this.getRoles(users.get(0).getId()); OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(userIdList), null, String.join(",", names) + roles, null, new LinkedList<>()); return JSON.toJSONString(details); } diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java index 0bd551c185..7ff68b89d7 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -1311,7 +1311,7 @@ public class TestPlanService { if (line.contains("\"#report\"")) { line = line.replace("\"#report\"", new Gson().toJson(report)); } - line += "\n"; + line += StringUtils.LF; byte[] lineBytes = line.getBytes(StandardCharsets.UTF_8); int start = 0; while (start < lineBytes.length) { diff --git a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java index 0c8903d411..f6e21e6775 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java @@ -2341,21 +2341,21 @@ public class TestCaseService { List testCases = relevanceApiCaseService.getApiCaseByIds(testCaseIds); List caseNames = testCases.stream().map(ApiTestCase::getName).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(caseNames)) { - nameBuilder.append("接口用例:").append("\n").append(caseNames).append("\n"); + nameBuilder.append("接口用例:").append(StringUtils.LF).append(caseNames).append(StringUtils.LF); } } if (CollectionUtils.isNotEmpty(performanceIds)) { List loadTests = relevanceLoadCaseService.getLoadCaseByIds(performanceIds); List caseNames = loadTests.stream().map(LoadTest::getName).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(caseNames)) { - nameBuilder.append("性能用例:").append("\n").append(caseNames).append("\n"); + nameBuilder.append("性能用例:").append(StringUtils.LF).append(caseNames).append(StringUtils.LF); } } if (CollectionUtils.isNotEmpty(automationIds)) { List scenarios = relevanceApiCaseService.getScenarioCaseByIds(automationIds); List caseNames = scenarios.stream().map(ApiScenario::getName).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(caseNames)) { - nameBuilder.append("自动化用例:").append("\n").append(caseNames).append("\n"); + nameBuilder.append("自动化用例:").append(StringUtils.LF).append(caseNames).append(StringUtils.LF); } } } @@ -2393,7 +2393,7 @@ public class TestCaseService { if (CollectionUtils.isNotEmpty(dtos)) { names = dtos.stream().map(TestCaseCommentDTO::getDescription).collect(Collectors.toList()); } - DetailColumn detailColumn = new DetailColumn("评论", "comment", String.join("\n", names), null); + DetailColumn detailColumn = new DetailColumn("评论", "comment", String.join(StringUtils.LF, names), null); columns.add(detailColumn); OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(id), bloBs.getProjectId(), bloBs.getName(), bloBs.getCreateUser(), columns); @@ -2412,7 +2412,7 @@ public class TestCaseService { List dtos = testCaseCommentService.getCaseComments(id); if (CollectionUtils.isNotEmpty(dtos)) { List names = dtos.stream().map(TestCaseCommentDTO::getDescription).collect(Collectors.toList()); - DetailColumn detailColumn = new DetailColumn("评论", "comment", String.join("\n", names), null); + DetailColumn detailColumn = new DetailColumn("评论", "comment", String.join(StringUtils.LF, names), null); columns.add(detailColumn); } OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(testCaseWithBLOBs.getId()), testCaseWithBLOBs.getProjectId(), testCaseWithBLOBs.getName(), testCaseWithBLOBs.getCreateUser(), columns); diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/platform/AbstractIssuePlatform.java b/test-track/backend/src/main/java/io/metersphere/service/issue/platform/AbstractIssuePlatform.java index a42990d75f..40d0678d5d 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/platform/AbstractIssuePlatform.java +++ b/test-track/backend/src/main/java/io/metersphere/service/issue/platform/AbstractIssuePlatform.java @@ -240,7 +240,7 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform { document.outputSettings(new Document.OutputSettings().prettyPrint(false)); document.select("br").append("\\n"); document.select("p").prepend("\\n\\n"); - desc = document.html().replaceAll("\\\\n", "\n"); + desc = document.html().replaceAll("\\\\n", StringUtils.LF); desc = Jsoup.clean(desc, "", Safelist.none(), new Document.OutputSettings().prettyPrint(false)); return desc.replace(" ", ""); } diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/platform/JiraPlatform.java b/test-track/backend/src/main/java/io/metersphere/service/issue/platform/JiraPlatform.java index 51646b63a7..b34e6b88bc 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/platform/JiraPlatform.java +++ b/test-track/backend/src/main/java/io/metersphere/service/issue/platform/JiraPlatform.java @@ -158,7 +158,7 @@ public class JiraPlatform extends AbstractIssuePlatform { private String appendMoreImage(String description, Map fileContentMap) { for (String key: fileContentMap.keySet()) { // 同步jira上传的附件 - description += "\n" + fileContentMap.get(key); + description += StringUtils.LF + fileContentMap.get(key); } return description; } diff --git a/test-track/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java b/test-track/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java index f1cd4d1a07..090eb29180 100644 --- a/test-track/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java +++ b/test-track/backend/src/main/java/io/metersphere/xmind/XmindCaseParser.java @@ -392,7 +392,7 @@ public class XmindCaseParser { testCase.setPrerequisite(replace(item.getTitle(), PC_REGEX)); } else if (isAvailable(item.getTitle(), RC_REGEX)) { rc.append(replace(item.getTitle(), RC_REGEX)); - rc.append("\n"); + rc.append(StringUtils.LF); } else if (isAvailable(item.getTitle(), TAG_REGEX)) { String tag = replace(item.getTitle(), TAG_REGEX); if (StringUtils.isNotEmpty(tag)) {