From 4833b876ca670b349daaa388d3ff314288b53e67 Mon Sep 17 00:00:00 2001 From: Hamid <94196804+hamidonos@users.noreply.github.com> Date: Mon, 15 Jul 2024 13:42:25 +0200 Subject: [PATCH] Generate client and models from sechub-openapi-java #3238 (#3305) - Create client and models from sechub-openapi-java in sechub-openapi-java-client - Remove gradle build stage and add remaining gradle submodules to project build - Fix error in build-versioning.gradle where file path was not resolved correctly --- build.gradle | 4 +- gradle/build-versioning.gradle | 20 ++-- gradle/projects.gradle | 59 +++++------ sechub-openapi-java-client/build.gradle | 132 ++++++++++++++++++++++++ sechub-openapi-java/build.gradle | 7 ++ settings.gradle | 37 +++---- 6 files changed, 187 insertions(+), 72 deletions(-) create mode 100644 sechub-openapi-java-client/build.gradle create mode 100644 sechub-openapi-java/build.gradle diff --git a/build.gradle b/build.gradle index 5cadc78fee..e346a2e368 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ plugins { id 'org.asciidoctor.jvm.pdf' version '3.3.2' // open api - id 'org.openapi.generator' version '6.5.0' + id 'org.openapi.generator' version '7.7.0' // spring id 'org.springframework.boot' version '3.2.2' apply false @@ -83,7 +83,7 @@ task internalCleanRootBuildFolder(type: Delete){ doFirst { def rootBuildFolder = file("${project.projectDir}/build") if (! rootBuildFolder.exists()){ - rootBuildFolder.mkdirs(); + rootBuildFolder.mkdirs() } delete rootBuildFolder.listFiles() // so we do NOT clear buildSrc/build here! } diff --git a/gradle/build-versioning.gradle b/gradle/build-versioning.gradle index 82048a5efc..4aaafad08a 100644 --- a/gradle/build-versioning.gradle +++ b/gradle/build-versioning.gradle @@ -82,9 +82,9 @@ def buildVersionFiles(){ def clientVersionInfo = versionData.defineVersion("Client",buildVersionString(clientVersionCommitTag, hasChanged,buildNumber),latestClientVersion) // write version code for go client - String clientGoVersionTemplate = new File('./sechub-cli/src/mercedes-benz.com/sechub/cli/version.go.template').getText('UTF-8') + String clientGoVersionTemplate = new File(project.rootDir, '/sechub-cli/src/mercedes-benz.com/sechub/cli/version.go.template').getText('UTF-8') String clientGoVersionCode = clientGoVersionTemplate.replaceAll("__version__",clientVersionInfo.getFullVersion()) - def clientVersionFile = new File('./sechub-cli/src/mercedes-benz.com/sechub/cli/version.go') + def clientVersionFile = new File(project.rootDir, './sechub-cli/src/mercedes-benz.com/sechub/cli/version.go') clientVersionFile.write(clientGoVersionCode) // Latest tagged client version as asciidoc file (#2285) @@ -93,7 +93,7 @@ def buildVersionFiles(){ if (latestClientVersion != clientVersionInfo.getShortVersion()) { latestClientVersionText = latestClientVersion + " modified (commit " + currentGitCommit + ")" } - def clientVersionAsciiDocFile = new File('./sechub-doc/src/docs/asciidoc/documents/gen/client-version.adoc') + def clientVersionAsciiDocFile = new File(project.rootDir, './sechub-doc/src/docs/asciidoc/documents/gen/client-version.adoc') clientVersionAsciiDocFile.write("// SPDX-License-Identifier: MIT\n:revnumber: Client "+latestClientVersionText+"\n:longrevnumber: Client "+latestClientVersionText+" - Build date: "+docsTimeStamp+"\n") // ------------------------ @@ -118,7 +118,7 @@ def buildVersionFiles(){ if (latestServerVersion != serverVersionInfo.getShortVersion()) { latestServerVersionText = latestServerVersion + " modified (commit " + currentGitCommit + ")" } - def serverVersionAsciiDocFile = new File('./sechub-doc/src/docs/asciidoc/documents/gen/server-version.adoc') + def serverVersionAsciiDocFile = new File(project.rootDir, './sechub-doc/src/docs/asciidoc/documents/gen/server-version.adoc') serverVersionAsciiDocFile.write("// SPDX-License-Identifier: MIT\n:revnumber: Server "+latestServerVersionText+"\n:longrevnumber: Server "+latestServerVersionText+" - Build date: "+docsTimeStamp+"\n") // ------------------------ @@ -143,7 +143,7 @@ def buildVersionFiles(){ if (latestPDSVersion != pdsVersionInfo.getShortVersion()) { latestPDSVersionText = latestPDSVersion + " modified (commit " + currentGitCommit + ")" } - def pdsVersionAsciiDocFile = new File('./sechub-doc/src/docs/asciidoc/documents/gen/pds-version.adoc') + def pdsVersionAsciiDocFile = new File(project.rootDir, './sechub-doc/src/docs/asciidoc/documents/gen/pds-version.adoc') pdsVersionAsciiDocFile.write("// SPDX-License-Identifier: MIT\n:revnumber: PDS "+latestPDSVersionText+"\n:longrevnumber: PDS "+latestPDSVersionText+" - Build date: "+docsTimeStamp+"\n") // ------------------------ @@ -261,9 +261,9 @@ def buildVersionFiles(){ def stop = new Date() - println(clientVersionInfo.describe()); - println(serverVersionInfo.describe()); - println(webuiVersionInfo.describe()); + println(clientVersionInfo.describe()) + println(serverVersionInfo.describe()) + println(webuiVersionInfo.describe()) println(pdsVersionInfo.describe()) println(pdsToolsVersionInfo.describe()) println(librariesVersionInfo.describe()) @@ -327,9 +327,9 @@ def buildVersionString(commitTag, boolean hasChanged, buildNumber){ calcversion = calcversion - 'v' } if (hasChanged){ - calcversion = "${calcversion}-dirty"; + calcversion = "${calcversion}-dirty" } - calcversion = "${calcversion}-${buildNumber}"; + calcversion = "${calcversion}-${buildNumber}" return calcversion } diff --git a/gradle/projects.gradle b/gradle/projects.gradle index 8a47d4fdad..940b217fa8 100644 --- a/gradle/projects.gradle +++ b/gradle/projects.gradle @@ -10,6 +10,8 @@ projectType = [ ], javaProjects: [ project(':sechub-openapi-java'), + project(':sechub-openapi-java-client'), + project(':sechub-api-java'), project(':sechub-testframework'), project(':sechub-analyzer-cli'), project(':sechub-commons-core'), @@ -21,13 +23,16 @@ projectType = [ project(':sechub-wrapper-owasp-zap'), project(':sechub-pds-commons-core'), project(':sechub-wrapper-xray'), + project(':sechub-systemtest'), + project(':sechub-pds-tools'), + project(':sechub-examples:example-sechub-api-java'), ], - + publishedLibraries: [ project(':sechub-commons-core'), project(':sechub-commons-model'), ], - + /* any project using spring parts but not already in other spring boot group must be defined here */ springBootProjects: [ @@ -35,20 +40,18 @@ projectType = [ project(':sechub-integrationtest'), project(':sechub-developertools'), project(':sechub-test'), - + project(':sechub-storage-sharedvolume-spring'), - + /* next projects added as spring boot projects only, because otherwise we get the (older) dependencies from aws as compiled projects in IDEs: */ project(':sechub-storage-s3-aws'), project(':sechub-storage-s3-aws-test'), - + /* special wrapper applications which are also spring boot applications to have dependency injection and access to some other spring boot parts */ project(':sechub-wrapper-checkmarx'), - project(':sechub-wrapper-prepare'), - - + project(':sechub-wrapper-prepare') ], /* adapter projects - have simple spring dependencies, but know only sechub-adapter as base */ @@ -59,7 +62,7 @@ projectType = [ project(':deprecated-sechub-adapter-netsparker'), project(':deprecated-sechub-adapter-nessus'), ], - + /* PDS projects, all contained inside product delegation server */ springBootPDSProjects: [ project(':sechub-pds'), @@ -87,15 +90,18 @@ projectType = [ project(':sechub-statistic'), ], - + bootableSpringApplicationProjects:[ project(':sechub-server'), project(':sechub-pds'), project(':sechub-wrapper-checkmarx'), project(':sechub-wrapper-prepare'), + project(':sechub-webui') + ], + + springBootWebUIProjects:[ + project('sechub-webui') ], - - springBootWebUIProjects:[], // is filled later programmatically /* documentation projects */ springDocProjects: [ @@ -118,38 +124,19 @@ projectType = [ asciiDoctorProjects: [ project(':sechub-doc'), ], - + noSpotless : [ - + project('sechub-examples:example-sechub-api-java'), + project('sechub-openapi-java-client') ], - + integrationTestProjects: [ project(':sechub-integrationtest'), + project(':sechub-systemtest'), ], ] } -if (secHubBuildStage.providesGeneratedOpenApiFile()){ - /* add the java projects which need an open api file / compiled java api */ - projectType.javaProjects.add(project(':sechub-api-java')) - - projectType.javaProjects.add(project(':sechub-systemtest')) - projectType.javaProjects.add(project(':sechub-pds-tools')) - - projectType.javaProjects.add(project(':sechub-examples:example-sechub-api-java')) - - /* avoid spotless duplication problem in gradle build */ - projectType.noSpotless.add(project(':sechub-examples:example-sechub-api-java')) - - /* make it possible to use integration test parts for systemtest (unit tests) as well */ - projectType.integrationTestProjects.add(project(':sechub-systemtest')) - - /* webui */ - projectType.bootableSpringApplicationProjects.add(project(':sechub-webui')) - projectType.springBootWebUIProjects.add(project(':sechub-webui')) -} - - /* dynamically define java projects */ projectType.springBootProjects.addAll(projectType.springBootSecHubServerProjects) projectType.springBootProjects.addAll(projectType.springBootPDSProjects) diff --git a/sechub-openapi-java-client/build.gradle b/sechub-openapi-java-client/build.gradle new file mode 100644 index 0000000000..a10031ad77 --- /dev/null +++ b/sechub-openapi-java-client/build.gradle @@ -0,0 +1,132 @@ +import org.openapitools.generator.gradle.plugin.tasks.GenerateTask + +// SPDX-License-Identifier: MIT +/*============================================================================ +* Build file for subproject +* +* Root build file: "${rootProject.projectDir}/build.gradle" +* ============================================================================ +*/ + +plugins { + id 'org.openapi.generator' +} + +dependencies { + implementation 'com.fasterxml.jackson.core:jackson-annotations:2.17.2' + implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.4.1' + implementation 'javax.annotation:javax.annotation-api:1.3.2' + implementation 'com.google.code.findbugs:jsr305:3.0.2' + implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.2' + implementation 'org.openapitools:jackson-databind-nullable:0.2.6' +} + +clean.doFirst { + delete 'gen' +} + +def openApiSpecPath = "${project.rootDir}/sechub-api-java/src/main/resources/openapi.yaml" + +openApiGenerate { + generatorName = 'java' + inputSpec = openApiSpecPath + outputDir = "${projectDir}/gen" + apiPackage = 'com.mercedesbenz.sechub.api.internal.gen' + invokerPackage = 'com.mercedesbenz.sechub.api.internal.gen.invoker' + modelPackage = 'com.mercedesbenz.sechub.api.internal.gen.model' + packageName = 'com.mercedesbenz.sechub.api.internal.gen' + generateModelTests = false + generateApiTests = false + + globalProperties = [ + validateSpec : 'true', + modelDocs : 'false', + models : '', // generate all + apis : '', // generate all + supportingFiles: '', // generate all + ] + // java generator: https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/java.md + configOptions = [ + groupId : 'com.mercedesbenz.sechub', + version : "${project.version}", + performBeanValidation : 'false', + useBeanValidation : 'false', + dateLibrary : 'java8', + serializableModel : 'true', + serializationLibrary : 'jackson', + artifactId : 'sechub-openapi-java-client', + artifactDescription : 'The SecHub API Java client', + artifactUrl : 'https://github.com/mercedes-benz/sechub', + legacyDiscriminatorBehavior: 'false', + library : 'native', // Uses the Java HTTP Client (available in Java 11+) + licenseName : 'MIT', + licenseUrl : 'https://github.com/mercedes-benz/sechub/blob/develop/LICENSE', + developerEmail : '', + developerName : '', + developerOrganization : 'Mercedes-Benz Tech Innovation', + developerOrganizationUrl : 'https://www.mercedes-benz-techinnovation.com/', + scmConnection : '', + scmDeveloperConnection : '', + scmUrl : 'https://github.com/mercedes-benz/sechub', + useJakartaEe : 'false' + ] +} + +tasks.named('openApiGenerate').configure { + doFirst { + delete 'gen' + } +} + +tasks.withType(GenerateTask).configureEach { + outputs.upToDateWhen { false } + outputs.cacheIf { false } +} + +ext.apiPublishNecessary = "${project.version}" != '0.0.0' + +/* + * The assemble task will normally be called from IDE integrations (eclipse buildship, intellij) to setup parts + */ +tasks.named('assemble') { + dependsOn tasks.named('openApiGenerate') // an assemble shall always generate all parts +} + +tasks.named('compileJava') { + dependsOn tasks.named('openApiGenerate') +} + +/* +* If the gradle task eclipse is used, the assemble task shall be used as well +* to avoid compile errors. +* +* Direct IDE integrations (eclipse buildship, intellij) normally directly use +* the assemble task before importing projects/modules, so it should work there always. +*/ +tasks.named('eclipse') { + dependsOn('assemble') +} + +/** + * Custom gradle task to build a 'fatJar'. + */ +tasks.register('buildJavaApiAll', Jar) { + group 'sechub' + description 'Builds the java api library as standalone library.' + archivesBaseName = 'sechub-java-api-all' + from { + configurations.runtimeClasspath.collect { + it.isDirectory() ? it : zipTree(it) + } + } + duplicatesStrategy = DuplicatesStrategy.INCLUDE + with jar +} + +sourceSets { + main { + java { + srcDir "$rootDir/sechub-openapi-java-client/gen/src/main/java" + } + } +} \ No newline at end of file diff --git a/sechub-openapi-java/build.gradle b/sechub-openapi-java/build.gradle new file mode 100644 index 0000000000..0cf7824982 --- /dev/null +++ b/sechub-openapi-java/build.gradle @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: MIT + /*============================================================================ + * Build file for subproject + * + * Root build file: "${rootProject.projectDir}/build.gradle" + * ============================================================================ + */ diff --git a/settings.gradle b/settings.gradle index bc71eea6b1..05fc2b0697 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,6 +6,8 @@ include 'sechub-cli', /* openapi */ 'sechub-openapi-java', +'sechub-openapi-java-client', +'sechub-api-java', // DEPRECATED /* commons */ 'sechub-commons-core', @@ -84,37 +86,24 @@ include 'sechub-cli', // Wrapper checkmarx 'sechub-wrapper-checkmarx', -// Wrapper Xray -'sechub-wrapper-xray', - // Wrapper prepare 'sechub-wrapper-prepare', -/* webui */ -'sechub-webui-solution' - -String buildStage = System.getProperty("sechub.build.stage") - -if (buildStage!=null) { - - /* build stage properrty is set */ - if (buildStage.equals("api-necessary") || buildStage.equals("all") ){ - - include 'sechub-api-java', /* needs open api file to generate */ +// Wrapper Xray +'sechub-wrapper-xray', - /* system test - needs java api*/ - 'sechub-systemtest', +/* System Test */ +'sechub-systemtest', - /* pds tools - needs java api */ - 'sechub-pds-tools', +/* PDS tools */ +'sechub-pds-tools', - // Examples (are below 'sechub-examples' folder) - 'sechub-examples:example-sechub-api-java', +// Examples (are below 'sechub-examples' folder) +'sechub-examples:example-sechub-api-java', - /* WebUI - needs the Java API */ - 'sechub-webui' - } -} +/* WebUI */ +'sechub-webui', +'sechub-webui-solution' buildCache { def useTempCache = System.getenv('SECHUB_BUILD_USE_TMP_CACHE')