From 21e59aed4855fddf1c3d01b3ea5518c0eb570a48 Mon Sep 17 00:00:00 2001 From: Dima Date: Sun, 10 Nov 2024 17:45:07 +0300 Subject: [PATCH] refactoring --- .../library/edt/EdtCliEngineFactory.groovy | 18 ++++ .../jenkins/library/edt/IEdtCliEngine.java | 11 ++ .../library/edt/NativeEdtCliConverter.groovy | 92 ++++++++++++++++ .../jenkins/library/edt/RingConverter.groovy | 101 ++++++++++++++++++ .../DesignerToEdtFormatTransformation.groovy | 38 +------ .../EdtToDesignerFormatTransformation.groovy | 81 +------------- .../jenkins/library/steps/EdtValidate.groovy | 28 +---- .../library/utils/VersionParser.groovy | 18 ---- .../library/utils/VersionParserTest.java | 30 ------ 9 files changed, 233 insertions(+), 184 deletions(-) create mode 100644 src/ru/pulsar/jenkins/library/edt/EdtCliEngineFactory.groovy create mode 100644 src/ru/pulsar/jenkins/library/edt/IEdtCliEngine.java create mode 100644 src/ru/pulsar/jenkins/library/edt/NativeEdtCliConverter.groovy create mode 100644 src/ru/pulsar/jenkins/library/edt/RingConverter.groovy diff --git a/src/ru/pulsar/jenkins/library/edt/EdtCliEngineFactory.groovy b/src/ru/pulsar/jenkins/library/edt/EdtCliEngineFactory.groovy new file mode 100644 index 00000000..767638ab --- /dev/null +++ b/src/ru/pulsar/jenkins/library/edt/EdtCliEngineFactory.groovy @@ -0,0 +1,18 @@ +package ru.pulsar.jenkins.library.edt + +import java.lang.module.ModuleDescriptor + +class EdtCliEngineFactory { + + static IEdtCliEngine getEngine(String edtVersion) { + + def currentVersion = ModuleDescriptor.Version.parse(edtVersion) + def version2024 = ModuleDescriptor.Version.parse("2024") + + if (currentVersion < version2024) { + return new RingConverter() + } else { + return new NativeEdtCliConverter() + } + } +} diff --git a/src/ru/pulsar/jenkins/library/edt/IEdtCliEngine.java b/src/ru/pulsar/jenkins/library/edt/IEdtCliEngine.java new file mode 100644 index 00000000..ef498d75 --- /dev/null +++ b/src/ru/pulsar/jenkins/library/edt/IEdtCliEngine.java @@ -0,0 +1,11 @@ +package ru.pulsar.jenkins.library.edt; + +import ru.pulsar.jenkins.library.IStepExecutor; +import ru.pulsar.jenkins.library.configuration.JobConfiguration; + +public interface IEdtCliEngine { + void edtToDesignerTransformConfiguration(IStepExecutor steps, JobConfiguration config); + void edtToDesignerTransformExtensions(IStepExecutor steps, JobConfiguration config); + void designerToEdtTransform(IStepExecutor steps, JobConfiguration config); + void edtValidate(IStepExecutor steps, JobConfiguration config, String projectList); +} diff --git a/src/ru/pulsar/jenkins/library/edt/NativeEdtCliConverter.groovy b/src/ru/pulsar/jenkins/library/edt/NativeEdtCliConverter.groovy new file mode 100644 index 00000000..10869a80 --- /dev/null +++ b/src/ru/pulsar/jenkins/library/edt/NativeEdtCliConverter.groovy @@ -0,0 +1,92 @@ +package ru.pulsar.jenkins.library.edt + +import ru.pulsar.jenkins.library.IStepExecutor +import ru.pulsar.jenkins.library.configuration.InitExtensionMethod +import ru.pulsar.jenkins.library.configuration.JobConfiguration +import ru.pulsar.jenkins.library.steps.DesignerToEdtFormatTransformation +import ru.pulsar.jenkins.library.steps.EdtToDesignerFormatTransformation +import ru.pulsar.jenkins.library.steps.EdtValidate +import ru.pulsar.jenkins.library.utils.FileUtils +import ru.pulsar.jenkins.library.utils.Logger + +class NativeEdtCliConverter implements IEdtCliEngine { + + @Override + void edtToDesignerTransformConfiguration(IStepExecutor steps, JobConfiguration config) { + + String workspaceDir = FileUtils.getFilePath("$env.WORKSPACE/$WORKSPACE").getRemote() + String projectWorkspaceDir = FileUtils.getFilePath("$workspaceDir/cf").getRemote() + String configurationRoot = FileUtils.getFilePath("$env.WORKSPACE/$EdtToDesignerFormatTransformation.CONFIGURATION_DIR").getRemote() + + Logger.println("Конвертация исходников конфигурации из формата EDT в формат Конфигуратора с помощью ring") + + steps.deleteDir(configurationRoot) + + def projectName = configurationRoot.getName() + def edtcliCommand = "1cedtcli -data \"$projectWorkspaceDir\" -command export --configuration-files \"$configurationRoot\" --project-name $projectName" + + steps.cmd(edtcliCommand) + + } + + @Override + void edtToDesignerTransformExtensions(IStepExecutor steps, JobConfiguration config) { + + def env = steps.env() + + String workspaceDir = FileUtils.getFilePath("$env.WORKSPACE/$WORKSPACE").getRemote() + String extensionRoot = FileUtils.getFilePath("$env.WORKSPACE/$EdtToDesignerFormatTransformation.EXTENSION_DIR").getRemote() + + config.initInfoBaseOptions.extensions.each { + + if (it.initMethod != InitExtensionMethod.SOURCE) { + return + } + + Logger.println("Конвертация исходников расширения ${it.name} из формата EDT в формат Конфигуратора с помощью 1cedtcli") + def currentExtensionWorkspaceDir = FileUtils.getFilePath("$workspaceDir/cfe/${it.name}") + + def edtcliCommand = "1cedtcli -data \"$currentExtensionWorkspaceDir\" -command export --configuration-files \"$extensionRoot/${it.name}\" --project-name ${it.name}" + + steps.cmd(edtcliCommand) + + } + + } + + @Override + void designerToEdtTransform(IStepExecutor steps, JobConfiguration config) { + + def env = steps.env() + + def workspaceDir = FileUtils.getFilePath("$env.WORKSPACE/$WORKSPACE") + def srcDir = config.srcDir + def configurationRoot = FileUtils.getFilePath("$env.WORKSPACE/$srcDir") + def projectName = configurationRoot.getName() + + steps.deleteDir(workspaceDir) + steps.deleteDir(configurationRoot) + + Logger.println("Конвертация исходников из формата конфигуратора в формат EDT с помощью 1cedtcli") + + def edtcliCommand = "1cedtcli -data \"$workspaceDir\" -command import --configuration-files \"$configurationRoot\" --project-name $projectName" + + steps.cmd(edtcliCommand) + + } + + @Override + void edtValidate(IStepExecutor steps, JobConfiguration config, String projectList) { + + def env = steps.env() + + String workspaceLocation = "$env.WORKSPACE/$DesignerToEdtFormatTransformation.WORKSPACE" + def resultFile = "$env.WORKSPACE/$EdtValidate.RESULT_FILE" + + def edtcliCommand = "1cedtcli -data \"$workspaceLocation\" -command validate --file \"$resultFile\" $projectList" + steps.catchError { + steps.cmd(edtcliCommand) + } + + } +} diff --git a/src/ru/pulsar/jenkins/library/edt/RingConverter.groovy b/src/ru/pulsar/jenkins/library/edt/RingConverter.groovy new file mode 100644 index 00000000..967a567a --- /dev/null +++ b/src/ru/pulsar/jenkins/library/edt/RingConverter.groovy @@ -0,0 +1,101 @@ +package ru.pulsar.jenkins.library.edt + +import ru.pulsar.jenkins.library.IStepExecutor +import ru.pulsar.jenkins.library.configuration.InitExtensionMethod +import ru.pulsar.jenkins.library.configuration.JobConfiguration +import ru.pulsar.jenkins.library.steps.DesignerToEdtFormatTransformation +import ru.pulsar.jenkins.library.steps.EdtToDesignerFormatTransformation +import ru.pulsar.jenkins.library.steps.EdtValidate +import ru.pulsar.jenkins.library.utils.EDT +import ru.pulsar.jenkins.library.utils.FileUtils +import ru.pulsar.jenkins.library.utils.Logger + +class RingConverter implements IEdtCliEngine { + + @Override + void edtToDesignerTransformConfiguration(IStepExecutor steps, JobConfiguration config) { + + def env = steps.env() + def edtVersionForRing = EDT.ringModule(config) + def srcDir = config.srcDir + + String workspaceDir = FileUtils.getFilePath("$env.WORKSPACE/$WORKSPACE").getRemote() + String projectWorkspaceDir = FileUtils.getFilePath("$workspaceDir/cf").getRemote() + String projectDir = FileUtils.getFilePath("$env.WORKSPACE/$srcDir").getRemote() + String configurationRoot = FileUtils.getFilePath("$env.WORKSPACE/$EdtToDesignerFormatTransformation.CONFIGURATION_DIR").getRemote() + + Logger.println("Конвертация исходников конфигурации из формата EDT в формат Конфигуратора с помощью ring") + + steps.deleteDir(configurationRoot) + + def ringCommand = "ring $edtVersionForRing workspace export --workspace-location \"$projectWorkspaceDir\" --project \"$projectDir\" --configuration-files \"$configurationRoot\"" + steps.ringCommand(ringCommand) + + } + + @Override + void edtToDesignerTransformExtensions(IStepExecutor steps, JobConfiguration config) { + + def env = steps.env() + + String workspaceDir = FileUtils.getFilePath("$env.WORKSPACE/$WORKSPACE").getRemote() + def edtVersionForRing = EDT.ringModule(config) + String extensionRoot = FileUtils.getFilePath("$env.WORKSPACE/$EdtToDesignerFormatTransformation.EXTENSION_DIR").getRemote() + + config.initInfoBaseOptions.extensions.each { + + if (it.initMethod != InitExtensionMethod.SOURCE) { + return + } + + Logger.println("Конвертация исходников расширения ${it.name} из формата EDT в формат Конфигуратора с помощью ring") + + + def projectDir = FileUtils.getFilePath("$env.WORKSPACE/${it.path}") + def currentExtensionWorkspaceDir = FileUtils.getFilePath("$workspaceDir/cfe/${it.name}") + def ringCommand = "ring $edtVersionForRing workspace export --workspace-location \"$currentExtensionWorkspaceDir\" --project \"$projectDir\" --configuration-files \"$extensionRoot/${it.name}\"" + steps.ringCommand(ringCommand) + } + } + + @Override + void designerToEdtTransform(IStepExecutor steps, JobConfiguration config) { + + def env = steps.env() + + def workspaceDir = FileUtils.getFilePath("$env.WORKSPACE/$WORKSPACE") + def srcDir = config.srcDir + def configurationRoot = FileUtils.getFilePath("$env.WORKSPACE/$srcDir") + def projectName = configurationRoot.getName() + + steps.deleteDir(workspaceDir) + steps.deleteDir(configurationRoot) + + Logger.println("Конвертация исходников из формата конфигуратора в формат EDT с помощью ring") + + String edtVersionForRing = EDT.ringModule(config) + String ringCommand = "ring $edtVersionForRing workspace import --configuration-files \"$configurationRoot\" --project-name $projectName --workspace-location \"$workspaceDir\"" + + steps.ringCommand(ringCommand) + + } + + @Override + void edtValidate(IStepExecutor steps, JobConfiguration config, String projectList) { + + def env = steps.env() + + def edtVersionForRing = EDT.ringModule(config) + String workspaceLocation = "$env.WORKSPACE/$DesignerToEdtFormatTransformation.WORKSPACE" + + def resultFile = "$env.WORKSPACE/$EdtValidate.RESULT_FILE" + + Logger.println("Версия EDT меньше 2024.1.X, для валидации используется ring") + + def ringCommand = "ring $edtVersionForRing workspace validate --workspace-location \"$workspaceLocation\" --file \"$resultFile\" $projectList" + steps.catchError { + steps.ringCommand(ringCommand) + } + + } +} diff --git a/src/ru/pulsar/jenkins/library/steps/DesignerToEdtFormatTransformation.groovy b/src/ru/pulsar/jenkins/library/steps/DesignerToEdtFormatTransformation.groovy index 7a19feaf..e9aa06f8 100644 --- a/src/ru/pulsar/jenkins/library/steps/DesignerToEdtFormatTransformation.groovy +++ b/src/ru/pulsar/jenkins/library/steps/DesignerToEdtFormatTransformation.groovy @@ -1,13 +1,10 @@ package ru.pulsar.jenkins.library.steps - +import ru.pulsar.jenkins.library.edt.EdtCliEngineFactory import ru.pulsar.jenkins.library.IStepExecutor import ru.pulsar.jenkins.library.configuration.JobConfiguration 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 { @@ -31,37 +28,8 @@ class DesignerToEdtFormatTransformation implements Serializable { return } - def env = steps.env() - - def workspaceDir = FileUtils.getFilePath("$env.WORKSPACE/$WORKSPACE") - def srcDir = config.srcDir - def configurationRoot = FileUtils.getFilePath("$env.WORKSPACE/$srcDir") - - steps.deleteDir(workspaceDir) - - Logger.println("Конвертация исходников из формата конфигуратора в формат EDT") - - if (VersionParser.compare(config.edtVersion, "2024") < 0) { - - 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 projectName = configurationRoot.getName() - def edtcliCommand = "1cedtcli -data \"$workspaceDir\" -command import --configuration-files \"$configurationRoot\" --project-name $projectName" - - def stdOut = steps.cmd(edtcliCommand, false, true) - - Logger.println(stdOut) - - } + def engine = EdtCliEngineFactory.getEngine(config.edtVersion) + engine.designerToEdtTransform(steps, config) steps.zip(WORKSPACE, WORKSPACE_ZIP) steps.stash(WORKSPACE_ZIP_STASH, WORKSPACE_ZIP) diff --git a/src/ru/pulsar/jenkins/library/steps/EdtToDesignerFormatTransformation.groovy b/src/ru/pulsar/jenkins/library/steps/EdtToDesignerFormatTransformation.groovy index d7ae5b88..13f5af05 100644 --- a/src/ru/pulsar/jenkins/library/steps/EdtToDesignerFormatTransformation.groovy +++ b/src/ru/pulsar/jenkins/library/steps/EdtToDesignerFormatTransformation.groovy @@ -1,15 +1,12 @@ package ru.pulsar.jenkins.library.steps - +import ru.pulsar.jenkins.library.edt.EdtCliEngineFactory import ru.pulsar.jenkins.library.IStepExecutor import ru.pulsar.jenkins.library.configuration.JobConfiguration import ru.pulsar.jenkins.library.configuration.SourceFormat -import ru.pulsar.jenkins.library.configuration.InitExtensionMethod 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 EdtToDesignerFormatTransformation implements Serializable { @@ -39,87 +36,19 @@ class EdtToDesignerFormatTransformation implements Serializable { def env = steps.env(); - String srcDir = config.srcDir String workspaceDir = FileUtils.getFilePath("$env.WORKSPACE/$WORKSPACE").getRemote() - - String projectWorkspaceDir = FileUtils.getFilePath("$workspaceDir/cf").getRemote() - String projectDir = FileUtils.getFilePath("$env.WORKSPACE/$srcDir").getRemote() - String configurationRoot = FileUtils.getFilePath("$env.WORKSPACE/$CONFIGURATION_DIR").getRemote() - - - String extensionRoot = FileUtils.getFilePath("$env.WORKSPACE/$EXTENSION_DIR").getRemote() - def edtVersionForRing = EDT.ringModule(config) - steps.deleteDir(workspaceDir) - transformConfiguration(steps, projectDir, projectWorkspaceDir, configurationRoot, edtVersionForRing) - transformExtensions(steps, workspaceDir, extensionRoot, edtVersionForRing) - } - - private void transformConfiguration(IStepExecutor steps, String projectDir, String projectWorkspaceDir, String configurationRoot, String edtVersionForRing) { - - Logger.println("Конвертация исходников конфигурации из формата EDT в формат Конфигуратора") - steps.deleteDir(configurationRoot) - - if (VersionParser.compare(config.edtVersion, "2024") < 0) { - - Logger.println("Версия EDT меньше 2024.1.X, используется ring") - - def ringCommand = "ring $edtVersionForRing workspace export --workspace-location \"$projectWorkspaceDir\" --project \"$projectDir\" --configuration-files \"$configurationRoot\"" - steps.ringCommand(ringCommand) - - } else { - - Logger.println("Версия EDT больше 2024.1.X, используется 1cedtcli") - - def projectName = configurationRoot.getName() - def edtcliCommand = "1cedtcli -data \"$projectWorkspaceDir\" -command export --configuration-files \"$configurationRoot\" --project-name $projectName" - - def stdOut = steps.cmd(edtcliCommand, false, true) - - Logger.println(stdOut) - } + def engine = EdtCliEngineFactory.getEngine(config.edtVersion) + engine.edtToDesignerTransformConfiguration(steps, config) steps.zip(CONFIGURATION_DIR, CONFIGURATION_ZIP) steps.stash(CONFIGURATION_ZIP_STASH, CONFIGURATION_ZIP) - } - - private void transformExtensions(IStepExecutor steps, String workspaceDir, String extensionRoot, String edtVersionForRing) { - steps.deleteDir(extensionRoot) - - config.initInfoBaseOptions.extensions.each { - - if (it.initMethod != InitExtensionMethod.SOURCE) { - return - } - - Logger.println("Конвертация исходников расширения ${it.name} из формата EDT в формат Конфигуратора") - - def env = steps.env(); - def projectDir = FileUtils.getFilePath("$env.WORKSPACE/${it.path}") - def currentExtensionWorkspaceDir = FileUtils.getFilePath("$workspaceDir/cfe/${it.name}") - - if (VersionParser.compare(config.edtVersion, "2024") < 0) { - - Logger.println("Версия EDT меньше 2024.1.X, для конвертации исходников расширения используется ring") - def ringCommand = "ring $edtVersionForRing workspace export --workspace-location \"$currentExtensionWorkspaceDir\" --project \"$projectDir\" --configuration-files \"$extensionRoot/${it.name}\"" - steps.ringCommand(ringCommand) - - } else { - - Logger.println("Версия EDT больше 2024.1.X, для конвертации исходников расширения используется 1cedtcli") - - def edtcliCommand = "1cedtcli -data \"$currentExtensionWorkspaceDir\" -command export --configuration-files \"$extensionRoot/${it.name}\" --project-name ${it.name}" - - def stdOut = steps.cmd(edtcliCommand, false, true) - - Logger.println(stdOut) - - } - } + engine.edtToDesignerTransformExtensions(steps, config) steps.zip(EXTENSION_DIR, EXTENSION_ZIP) steps.stash(EXTENSION_ZIP_STASH, EXTENSION_ZIP) + } } diff --git a/src/ru/pulsar/jenkins/library/steps/EdtValidate.groovy b/src/ru/pulsar/jenkins/library/steps/EdtValidate.groovy index c94710bc..bb4f7886 100644 --- a/src/ru/pulsar/jenkins/library/steps/EdtValidate.groovy +++ b/src/ru/pulsar/jenkins/library/steps/EdtValidate.groovy @@ -1,13 +1,12 @@ package ru.pulsar.jenkins.library.steps +import ru.pulsar.jenkins.library.edt.EdtCliEngineFactory import ru.pulsar.jenkins.library.IStepExecutor import ru.pulsar.jenkins.library.configuration.JobConfiguration import ru.pulsar.jenkins.library.configuration.SourceFormat 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 EdtValidate implements Serializable { @@ -32,7 +31,6 @@ class EdtValidate implements Serializable { def env = steps.env() - String workspaceLocation = "$env.WORKSPACE/$DesignerToEdtFormatTransformation.WORKSPACE" String projectList if (config.sourceFormat == SourceFormat.DESIGNER) { @@ -51,31 +49,11 @@ class EdtValidate implements Serializable { projectList = "--project-list \"$projectDir\"" } - def resultFile = "$env.WORKSPACE/$RESULT_FILE" - def edtVersionForRing = EDT.ringModule(config) - Logger.println("Выполнение валидации EDT") - if (VersionParser.compare(config.edtVersion, "2024") < 0) { - - Logger.println("Версия EDT меньше 2024.1.X, для валидации используется ring") - - def ringCommand = "ring $edtVersionForRing workspace validate --workspace-location \"$workspaceLocation\" --file \"$resultFile\" $projectList" - steps.catchError { - steps.ringCommand(ringCommand) - } - - } else { - - Logger.println("Версия EDT больше 2024.1.X, для валидации используется 1cedtcli") + def engine = EdtCliEngineFactory.getEngine(config.edtVersion) - def edtcliCommand = "1cedtcli -data \"$workspaceLocation\" -command validate --file \"$resultFile\" $projectList" - steps.catchError { - def stdOut = steps.cmd(edtcliCommand, false, true) - Logger.println(stdOut) - } - - } + engine.edtValidate(steps, config, projectList) steps.archiveArtifacts("$DesignerToEdtFormatTransformation.WORKSPACE/.metadata/.log") steps.archiveArtifacts(RESULT_FILE) diff --git a/src/ru/pulsar/jenkins/library/utils/VersionParser.groovy b/src/ru/pulsar/jenkins/library/utils/VersionParser.groovy index 925a3c47..4914cdf8 100644 --- a/src/ru/pulsar/jenkins/library/utils/VersionParser.groovy +++ b/src/ru/pulsar/jenkins/library/utils/VersionParser.groovy @@ -43,22 +43,4 @@ 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 afa03ae5..3ef626cb 100644 --- a/test/unit/groovy/ru/pulsar/jenkins/library/utils/VersionParserTest.java +++ b/test/unit/groovy/ru/pulsar/jenkins/library/utils/VersionParserTest.java @@ -85,34 +85,4 @@ 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