From cd71f183bbcb91ffe996890ca4e3675bab81baa4 Mon Sep 17 00:00:00 2001 From: z15lross Date: Thu, 5 May 2022 10:20:58 +0200 Subject: [PATCH] fix : thread block on some unix system when creating demo project --- .../ara/loader/DemoExecutionLoader.java | 75 ++++++++++--------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/code/api/api/src/main/java/com/decathlon/ara/loader/DemoExecutionLoader.java b/code/api/api/src/main/java/com/decathlon/ara/loader/DemoExecutionLoader.java index 3e3e47d43..3e3b919fc 100644 --- a/code/api/api/src/main/java/com/decathlon/ara/loader/DemoExecutionLoader.java +++ b/code/api/api/src/main/java/com/decathlon/ara/loader/DemoExecutionLoader.java @@ -17,31 +17,12 @@ package com.decathlon.ara.loader; -import com.decathlon.ara.ci.bean.Build; -import com.decathlon.ara.ci.bean.CycleDef; -import com.decathlon.ara.ci.bean.PlatformRule; -import com.decathlon.ara.ci.bean.QualityThreshold; -import com.decathlon.ara.common.NotGonnaHappenException; -import com.decathlon.ara.domain.CycleDefinition; -import com.decathlon.ara.domain.enumeration.Result; -import com.decathlon.ara.repository.CycleDefinitionRepository; -import com.decathlon.ara.service.ExecutionService; -import com.decathlon.ara.service.SettingService; -import com.decathlon.ara.service.dto.cycledefinition.CycleDefinitionDTO; -import com.decathlon.ara.service.support.Settings; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.collections4.map.HashedMap; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; +import static com.decathlon.ara.loader.DemoLoaderConstants.BRANCH_DEVELOP; +import static com.decathlon.ara.loader.DemoLoaderConstants.BRANCH_MASTER; +import static com.decathlon.ara.loader.DemoLoaderConstants.CYCLE_DAY; +import static com.decathlon.ara.loader.DemoLoaderConstants.CYCLE_NIGHT; +import static com.decathlon.ara.loader.DemoLoaderConstants.PROJECT_CODE_DEMO; -import javax.persistence.EntityManager; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -50,20 +31,48 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.ZoneOffset; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiPredicate; import java.util.function.Function; import java.util.regex.Pattern; import java.util.stream.Stream; -import static com.decathlon.ara.loader.DemoLoaderConstants.*; +import javax.persistence.EntityManager; + +import org.apache.commons.collections4.map.HashedMap; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.decathlon.ara.ci.bean.Build; +import com.decathlon.ara.ci.bean.CycleDef; +import com.decathlon.ara.ci.bean.PlatformRule; +import com.decathlon.ara.ci.bean.QualityThreshold; +import com.decathlon.ara.common.NotGonnaHappenException; +import com.decathlon.ara.domain.CycleDefinition; +import com.decathlon.ara.domain.enumeration.Result; +import com.decathlon.ara.repository.CycleDefinitionRepository; +import com.decathlon.ara.service.ExecutionService; +import com.decathlon.ara.service.SettingService; +import com.decathlon.ara.service.dto.cycledefinition.CycleDefinitionDTO; +import com.decathlon.ara.service.support.Settings; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; /** * Service for loading executions into the Demo project. @@ -82,6 +91,8 @@ public class DemoExecutionLoader { private static final Pattern POSTMAN_ECHO_HOST_PATTERN = Pattern.compile("postman-echo.com"); + private static final Random RANDOM = new Random(); + private static final BiPredicate JSON_FILE_FILTER = (path, attributes) -> attributes.isRegularFile() && path.getFileName().toString().endsWith(".json"); private final SettingService settingService; @@ -306,15 +317,9 @@ private void copyStreamToFile(InputStream stream, File destinationFile) throws I } private String randomGitCommitId() { - Random random; - try { - random = SecureRandom.getInstanceStrong(); - } catch (NoSuchAlgorithmException e) { - random = new SecureRandom(); - } char[] id = new char[40]; for (int i = 0; i < id.length; i++) { - id[i] = Integer.toHexString(random.nextInt(16)).charAt(0); + id[i] = Integer.toHexString(RANDOM.nextInt(16)).charAt(0); } return new String(id); }