Skip to content

Commit

Permalink
Рефакторинг
Browse files Browse the repository at this point in the history
  • Loading branch information
kozstlink committed Dec 3, 2021
1 parent 713c423 commit c8259bf
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
19 changes: 9 additions & 10 deletions src/ru/pulsar/jenkins/library/steps/Swagger.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
}
Expand Down
19 changes: 19 additions & 0 deletions src/ru/pulsar/jenkins/library/utils/OscriptModules.groovy
Original file line number Diff line number Diff line change
@@ -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;
}
}
3 changes: 1 addition & 2 deletions vars/pipeline1C.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ void call() {
}
steps {
script {
def swagger = new Swagger(config)
swagger.run()
swagger config
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions vars/swagger.groovy
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit c8259bf

Please sign in to comment.