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() +} +