diff --git a/src/ru/pulsar/jenkins/library/steps/DesignerToEdtFormatTransformation.groovy b/src/ru/pulsar/jenkins/library/steps/DesignerToEdtFormatTransformation.groovy index 320fb609..572f2fa1 100644 --- a/src/ru/pulsar/jenkins/library/steps/DesignerToEdtFormatTransformation.groovy +++ b/src/ru/pulsar/jenkins/library/steps/DesignerToEdtFormatTransformation.groovy @@ -7,6 +7,7 @@ import ru.pulsar.jenkins.library.ioc.ContextRegistry import ru.pulsar.jenkins.library.utils.EDT import ru.pulsar.jenkins.library.utils.FileUtils import ru.pulsar.jenkins.library.utils.Logger +import ru.pulsar.jenkins.library.utils.VersionParser class DesignerToEdtFormatTransformation implements Serializable { @@ -36,15 +37,31 @@ class DesignerToEdtFormatTransformation implements Serializable { def srcDir = config.srcDir def configurationRoot = FileUtils.getFilePath("$env.WORKSPACE/$srcDir") def projectName = configurationRoot.getName() - def edtVersionForRing = EDT.ringModule(config) steps.deleteDir(workspaceDir) Logger.println("Конвертация исходников из формата конфигуратора в формат EDT") - def ringCommand = "ring $edtVersionForRing workspace import --configuration-files \"$configurationRoot\" --project-name $projectName --workspace-location \"$workspaceDir\"" + if (VersionParser.compare(config.edtVersion, "2024") < 0) { - steps.ringCommand(ringCommand) + Logger.println("Версия EDT меньше 2024.1.X, используется ring") + + def edtVersionForRing = EDT.ringModule(config) + def ringCommand = "ring $edtVersionForRing workspace import --configuration-files \"$configurationRoot\" --project-name $projectName --workspace-location \"$workspaceDir\"" + + steps.ringCommand(ringCommand) + + } else { + + Logger.println("Версия EDT больше 2024.1.X, используется 1cedtcli") + + def edtcliCommand = "1cedtcli -data \"$workspaceDir\" -command import --configuration-files \"$configurationRoot\" --project-name $projectName" + + def stdOut = steps.cmd(edtcliCommand, false, true) + + Logger.println(stdOut) + + } steps.zip(WORKSPACE, WORKSPACE_ZIP) steps.stash(WORKSPACE_ZIP_STASH, WORKSPACE_ZIP) diff --git a/src/ru/pulsar/jenkins/library/utils/VersionParser.groovy b/src/ru/pulsar/jenkins/library/utils/VersionParser.groovy index 4914cdf8..925a3c47 100644 --- a/src/ru/pulsar/jenkins/library/utils/VersionParser.groovy +++ b/src/ru/pulsar/jenkins/library/utils/VersionParser.groovy @@ -43,4 +43,22 @@ class VersionParser implements Serializable { return matcher != null && matcher.getCount() == 1 ? matcher[0][1] : "" } + static int compare(String thisVersion, String thatVersion) { + + def thisVersionParts = thisVersion.split("\\.") + def thatVersionParts = thatVersion.split("\\.") + + def minIndex = Math.min(thisVersionParts.length, thatVersionParts.length) + + for (int i = 0;i < minIndex;i++) { + + if (thisVersionParts[i].toInteger() > thatVersionParts[i].toInteger()) { + return 1 + } else if (thisVersionParts[i].toInteger() < thatVersionParts[i].toInteger()) { + return -1 + } + } + + return 0 + } } diff --git a/test/unit/groovy/ru/pulsar/jenkins/library/utils/VersionParserTest.java b/test/unit/groovy/ru/pulsar/jenkins/library/utils/VersionParserTest.java index 3ef626cb..afa03ae5 100644 --- a/test/unit/groovy/ru/pulsar/jenkins/library/utils/VersionParserTest.java +++ b/test/unit/groovy/ru/pulsar/jenkins/library/utils/VersionParserTest.java @@ -85,4 +85,34 @@ void testConfiguration() throws IOException { assertThat(storage).isEqualTo("1.0.0.1"); } + @Test + void testVersionComparisonLessThan() { + + // given + String thisVersion = "2023.2.4"; + String thatVersion = "2023.3.1"; + + // when + int result = VersionParser.compare(thisVersion, thatVersion); + + // then + assertThat(result).isEqualTo(-1); + + } + + @Test + void testVersionComparisonEqualShort() { + + // given + String thisVersion = "2024.2.4"; + String thatVersion = "2024.2"; + + // when + int result = VersionParser.compare(thisVersion, thatVersion); + + // then + assertThat(result).isEqualTo(0); + + } + } \ No newline at end of file