From c8259bf49ef8c4bee8177222d2fd102189aeaa53 Mon Sep 17 00:00:00 2001 From: Sergey Kozinskiy Date: Fri, 3 Dec 2021 16:21:35 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jenkins/library/steps/Swagger.groovy | 19 +++++++++---------- .../library/utils/OscriptModules.groovy | 19 +++++++++++++++++++ vars/pipeline1C.groovy | 3 +-- vars/swagger.groovy | 11 +++++++++++ 4 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 src/ru/pulsar/jenkins/library/utils/OscriptModules.groovy create mode 100644 vars/swagger.groovy diff --git a/src/ru/pulsar/jenkins/library/steps/Swagger.groovy b/src/ru/pulsar/jenkins/library/steps/Swagger.groovy index 551caca3..0aeda16d 100644 --- a/src/ru/pulsar/jenkins/library/steps/Swagger.groovy +++ b/src/ru/pulsar/jenkins/library/steps/Swagger.groovy @@ -4,11 +4,10 @@ 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.Logger - -import java.nio.file.Paths +import ru.pulsar.jenkins.library.utils.OscriptModules class Swagger { - public static final String OUT = 'build/out/' + public static final String OUT = 'build/out/swagger' private final JobConfiguration config; @@ -17,22 +16,22 @@ class Swagger { } def run() { + if (!config.stageFlags.swagger) { + Logger.println("Swagger documentation is disabled") + return + } + IStepExecutor steps = ContextRegistry.getContext().getStepExecutor() Logger.printLocation() def env = steps.env(); - if (!config.stageFlags.swagger) { - Logger.println("Swagger documentation is disabled") - return - } - steps.installLocalDependencies() - String SRC_PATH = new File("$env.WORKSPACE/$config.srcDir").getCanonicalPath() + String swaggerPath = OscriptModules.getModulePath("swagger"); - steps.cmd("oscript_modules/bin/swagger generate --src-path $SRC_PATH --out $OUT") + steps.cmd(swaggerPath + "generate --src-path $config.srcDir --out $OUT") steps.archiveArtifacts(OUT) } diff --git a/src/ru/pulsar/jenkins/library/utils/OscriptModules.groovy b/src/ru/pulsar/jenkins/library/utils/OscriptModules.groovy new file mode 100644 index 00000000..03411c2b --- /dev/null +++ b/src/ru/pulsar/jenkins/library/utils/OscriptModules.groovy @@ -0,0 +1,19 @@ +package ru.pulsar.jenkins.library.utils + +import ru.pulsar.jenkins.library.IStepExecutor +import ru.pulsar.jenkins.library.ioc.ContextRegistry + +class OscriptModules { + static String getModulePath(String moduleName) { + + IStepExecutor steps = ContextRegistry.getContext().getStepExecutor() + + String moduleBinary = steps.isUnix() ? moduleName : "$moduleName"".bat"; + String modulePath = "oscript_modules/bin/$moduleBinary"; + if (!steps.fileExists(modulePath)) { + modulePath = moduleBinary; + } + + return modulePath; + } +} \ No newline at end of file diff --git a/vars/pipeline1C.groovy b/vars/pipeline1C.groovy index 485e4b34..7e7e044b 100644 --- a/vars/pipeline1C.groovy +++ b/vars/pipeline1C.groovy @@ -211,8 +211,7 @@ void call() { } steps { script { - def swagger = new Swagger(config) - swagger.run() + swagger config } } } diff --git a/vars/swagger.groovy b/vars/swagger.groovy new file mode 100644 index 00000000..8bd14061 --- /dev/null +++ b/vars/swagger.groovy @@ -0,0 +1,11 @@ +import ru.pulsar.jenkins.library.configuration.JobConfiguration +import ru.pulsar.jenkins.library.ioc.ContextRegistry +import ru.pulsar.jenkins.library.steps.Swagger + +def call(JobConfiguration config) { + ContextRegistry.registerDefaultContext(this) + + def swagger = new Swagger(config) + swagger.run() +} +