Skip to content

Commit

Permalink
Generate client and models from sechub-openapi-java #3238 (#3305)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
hamidonos authored Jul 15, 2024
1 parent 27bfd05 commit 4833b87
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 72 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!
}
Expand Down
20 changes: 10 additions & 10 deletions gradle/build-versioning.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")

// ------------------------
Expand All @@ -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")

// ------------------------
Expand All @@ -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")

// ------------------------
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
}

Expand Down
59 changes: 23 additions & 36 deletions gradle/projects.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -21,34 +23,35 @@ 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: [
project(':sechub-scan-testframework'), //we use same mockito and junit as in other projects, so a spring boot project...
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 */
Expand All @@ -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'),
Expand Down Expand Up @@ -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: [
Expand All @@ -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)
Expand Down
132 changes: 132 additions & 0 deletions sechub-openapi-java-client/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
7 changes: 7 additions & 0 deletions sechub-openapi-java/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT
/*============================================================================
* Build file for subproject
*
* Root build file: "${rootProject.projectDir}/build.gradle"
* ============================================================================
*/
Loading

0 comments on commit 4833b87

Please sign in to comment.