diff --git a/build.gradle b/build.gradle index 0ff3a259..8fe7a368 100644 --- a/build.gradle +++ b/build.gradle @@ -55,6 +55,17 @@ repositories { } } +sourceSets { + main { + java { + srcDirs "${buildDir}/version" + } + } +} + +compileKotlin.dependsOn "generateVersion" + + test { useJUnitPlatform() } @@ -156,4 +167,5 @@ dokka { outputDirectory = "$buildDir/docs/kotlin" } +apply plugin: VersionPlugin apply from: "${rootProject.rootDir}/gradle/publishing.gradle" diff --git a/buildSrc/src/main/groovy/VersionPlugin.groovy b/buildSrc/src/main/groovy/VersionPlugin.groovy new file mode 100644 index 00000000..e277404d --- /dev/null +++ b/buildSrc/src/main/groovy/VersionPlugin.groovy @@ -0,0 +1,44 @@ +import org.gradle.api.Action +import org.gradle.api.Plugin +import org.gradle.api.Project + +/** + * provides a "generateVersion" task to a create a simple Version.java class: + * + *
{@code
+ * package io.openapiprocessor.spring;
+ *
+ * public class Version {
+ *     public static final String version = "${project.version}";
+ * }
+ * }
+ * + * + * The io/openapiprocessor/spring/Version.java file is generated to: + * + * $(project.buildDir}/main/java + * + * Add it as a source directory to include it in compilation. + */ +class VersionPlugin implements Plugin { + + void apply(Project project) { + project.afterEvaluate (new Action () { + + @Override + void execute (Project prj) { + prj.tasks.register ('generateVersion', VersionTask , new Action() { + + @Override + void execute (VersionTask task) { + task.targetDir = prj.buildDir + task.version = prj.version + } + + }) + } + + }) + } + +} diff --git a/buildSrc/src/main/groovy/VersionTask.groovy b/buildSrc/src/main/groovy/VersionTask.groovy new file mode 100644 index 00000000..e12d7f74 --- /dev/null +++ b/buildSrc/src/main/groovy/VersionTask.groovy @@ -0,0 +1,52 @@ +import org.gradle.api.DefaultTask +import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.TaskAction + +import java.nio.file.Files +import java.nio.file.Path +import java.time.Instant + +/** + * simple task to create a Version class. + */ +class VersionTask extends DefaultTask { + + /** + * Target directory for the generated version class. + * + * Used by gradle for the up-to-date check. + */ + @OutputDirectory + String targetDir + + @Internal + String version + + /** + * generate the version class. + */ + @TaskAction + void generateVersion () { + def path = Path.of (targetDir, "version", "io", "openapiprocessor", "spring") + Files.createDirectories(path) + + def target = path.resolve ("Version.java") + + target.text = """\ +/* + * DO NOT MODIFY - this file was auto generated by buildSrc/src/main/groovy/VersionPlugin.groovy + * + * ${Instant.now ().toString ()} + */ + +package io.openapiprocessor.spring; + +public class Version { + public static final String version = "${version}"; +} + +""" + } + +} diff --git a/src/main/groovy/com/github/hauner/openapi/spring/writer/java/HeaderWriter.groovy b/src/main/groovy/com/github/hauner/openapi/spring/writer/java/HeaderWriter.groovy index 72764086..8a9df5b2 100644 --- a/src/main/groovy/com/github/hauner/openapi/spring/writer/java/HeaderWriter.groovy +++ b/src/main/groovy/com/github/hauner/openapi/spring/writer/java/HeaderWriter.groovy @@ -17,6 +17,9 @@ package com.github.hauner.openapi.spring.writer.java import com.github.hauner.openapi.core.writer.java.SimpleWriter +import io.openapiprocessor.spring.Version + +import java.time.Instant /** * Writer for a simple header of the generated interfaces & classes. @@ -27,8 +30,11 @@ class HeaderWriter implements SimpleWriter { static String HEADER = """\ /* - * This class is auto generated by https://github.com/hauner/openapi-processor-spring. - * DO NOT EDIT. + * DO NOT MODIFY - this class was auto generated by openapi-processor-spring + * + * ${Version.version} + * ${Instant.now().toString()} + * https://docs.openapiprocessor.io/spring */ """ diff --git a/src/testInt/groovy/com/github/hauner/openapi/processor/spring/EndToEndBase.groovy b/src/testInt/groovy/com/github/hauner/openapi/processor/spring/EndToEndBase.groovy new file mode 100644 index 00000000..0eab06e0 --- /dev/null +++ b/src/testInt/groovy/com/github/hauner/openapi/processor/spring/EndToEndBase.groovy @@ -0,0 +1,46 @@ +/* + * Copyright 2020 the original authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.github.hauner.openapi.processor.spring + +import com.github.hauner.openapi.spring.writer.java.HeaderWriter +import com.github.hauner.openapi.test.ProcessorTestBase +import com.github.hauner.openapi.test.TestSet +import org.junit.BeforeClass + +class EndToEndBase extends ProcessorTestBase { + + EndToEndBase (TestSet testSet) { + super (testSet) + } + + @BeforeClass + static void setConstantHeaderWriterText () { + // set a "fixed" header, we don't want moving version/date/time parts + + HeaderWriter.HEADER = """\ +/* + * DO NOT MODIFY - this class was auto generated by openapi-processor-spring + * + * test + * time + * https://docs.openapiprocessor.io/spring + */ + +""" + } + +} diff --git a/src/testInt/groovy/com/github/hauner/openapi/processor/spring/ProcessorEndToEndTest.groovy b/src/testInt/groovy/com/github/hauner/openapi/processor/spring/ProcessorEndToEndTest.groovy index 82e09c63..c3300bfa 100644 --- a/src/testInt/groovy/com/github/hauner/openapi/processor/spring/ProcessorEndToEndTest.groovy +++ b/src/testInt/groovy/com/github/hauner/openapi/processor/spring/ProcessorEndToEndTest.groovy @@ -18,7 +18,6 @@ package com.github.hauner.openapi.processor.spring import com.github.hauner.openapi.core.parser.ParserType import com.github.hauner.openapi.spring.processor.SpringProcessor -import com.github.hauner.openapi.test.ProcessorTestBase import com.github.hauner.openapi.test.TestSet import org.junit.Test import org.junit.runner.RunWith @@ -28,7 +27,7 @@ import org.junit.runners.Parameterized * using Junit so IDEA adds a "" when using assertEquals(). */ @RunWith(Parameterized) -class ProcessorEndToEndTest extends ProcessorTestBase { +class ProcessorEndToEndTest extends EndToEndBase { @Parameterized.Parameters(name = "{0}") static Collection sources () { diff --git a/src/testInt/groovy/com/github/hauner/openapi/processor/spring/ProcessorJimsFileSystemTest.groovy b/src/testInt/groovy/com/github/hauner/openapi/processor/spring/ProcessorJimsFileSystemTest.groovy index 53b2754a..b1c7672b 100644 --- a/src/testInt/groovy/com/github/hauner/openapi/processor/spring/ProcessorJimsFileSystemTest.groovy +++ b/src/testInt/groovy/com/github/hauner/openapi/processor/spring/ProcessorJimsFileSystemTest.groovy @@ -30,7 +30,7 @@ import org.junit.runners.Parameterized * using Junit so IDEA adds a "" when using assertEquals(). */ @RunWith(Parameterized) -class ProcessorJimsFileSystemTest extends ProcessorTestBase { +class ProcessorJimsFileSystemTest extends EndToEndBase { @Parameterized.Parameters(name = "{0}") static Collection sources () { diff --git a/src/testInt/groovy/com/github/hauner/openapi/processor/spring/ProcessorPendingTest.groovy b/src/testInt/groovy/com/github/hauner/openapi/processor/spring/ProcessorPendingTest.groovy index c159a5b8..be8d0ad4 100644 --- a/src/testInt/groovy/com/github/hauner/openapi/processor/spring/ProcessorPendingTest.groovy +++ b/src/testInt/groovy/com/github/hauner/openapi/processor/spring/ProcessorPendingTest.groovy @@ -27,7 +27,7 @@ import org.junit.runners.Parameterized //@Ignore @RunWith(Parameterized) -class ProcessorPendingTest extends ProcessorTestBase { +class ProcessorPendingTest extends EndToEndBase { @Parameterized.Parameters(name = "{0}") static Collection sources () { diff --git a/src/testInt/resources/tests/endpoint-http-mapping/generated/api/EndpointApi.java b/src/testInt/resources/tests/endpoint-http-mapping/generated/api/EndpointApi.java index 94572252..bbf27e74 100644 --- a/src/testInt/resources/tests/endpoint-http-mapping/generated/api/EndpointApi.java +++ b/src/testInt/resources/tests/endpoint-http-mapping/generated/api/EndpointApi.java @@ -1,6 +1,9 @@ /* - * This class is auto generated by https://github.com/hauner/openapi-processor-spring. - * DO NOT EDIT. + * DO NOT MODIFY - this class was auto generated by openapi-processor-spring + * + * test + * time + * https://docs.openapiprocessor.io/spring */ package generated.api; diff --git a/src/testInt/resources/tests/params-complex-data-types/generated/api/Api.java b/src/testInt/resources/tests/params-complex-data-types/generated/api/Api.java index 1c4ab69b..c169b38d 100644 --- a/src/testInt/resources/tests/params-complex-data-types/generated/api/Api.java +++ b/src/testInt/resources/tests/params-complex-data-types/generated/api/Api.java @@ -1,6 +1,9 @@ /* - * This class is auto generated by https://github.com/hauner/openapi-processor-spring. - * DO NOT EDIT. + * DO NOT MODIFY - this class was auto generated by openapi-processor-spring + * + * test + * time + * https://docs.openapiprocessor.io/spring */ package generated.api; diff --git a/src/testInt/resources/tests/params-complex-data-types/generated/model/Props.java b/src/testInt/resources/tests/params-complex-data-types/generated/model/Props.java index 9e1fe07c..6aeeb62e 100644 --- a/src/testInt/resources/tests/params-complex-data-types/generated/model/Props.java +++ b/src/testInt/resources/tests/params-complex-data-types/generated/model/Props.java @@ -1,6 +1,9 @@ /* - * This class is auto generated by https://github.com/hauner/openapi-processor-spring. - * DO NOT EDIT. + * DO NOT MODIFY - this class was auto generated by openapi-processor-spring + * + * test + * time + * https://docs.openapiprocessor.io/spring */ package generated.model; diff --git a/src/testInt/resources/tests/params-pageable-mapping/generated/api/Api.java b/src/testInt/resources/tests/params-pageable-mapping/generated/api/Api.java index 0308f12d..1ef975ce 100644 --- a/src/testInt/resources/tests/params-pageable-mapping/generated/api/Api.java +++ b/src/testInt/resources/tests/params-pageable-mapping/generated/api/Api.java @@ -1,6 +1,9 @@ /* - * This class is auto generated by https://github.com/hauner/openapi-processor-spring. - * DO NOT EDIT. + * DO NOT MODIFY - this class was auto generated by openapi-processor-spring + * + * test + * time + * https://docs.openapiprocessor.io/spring */ package generated.api; diff --git a/src/testInt/resources/tests/params-path-simple-data-types/generated/api/EndpointApi.java b/src/testInt/resources/tests/params-path-simple-data-types/generated/api/EndpointApi.java index 7c9cc548..d2134fc0 100644 --- a/src/testInt/resources/tests/params-path-simple-data-types/generated/api/EndpointApi.java +++ b/src/testInt/resources/tests/params-path-simple-data-types/generated/api/EndpointApi.java @@ -1,6 +1,9 @@ /* - * This class is auto generated by https://github.com/hauner/openapi-processor-spring. - * DO NOT EDIT. + * DO NOT MODIFY - this class was auto generated by openapi-processor-spring + * + * test + * time + * https://docs.openapiprocessor.io/spring */ package generated.api; diff --git a/src/testInt/resources/tests/params-request-body-multipart-mapping/generated/api/Api.java b/src/testInt/resources/tests/params-request-body-multipart-mapping/generated/api/Api.java index 4f054c2e..27134725 100644 --- a/src/testInt/resources/tests/params-request-body-multipart-mapping/generated/api/Api.java +++ b/src/testInt/resources/tests/params-request-body-multipart-mapping/generated/api/Api.java @@ -1,6 +1,9 @@ /* - * This class is auto generated by https://github.com/hauner/openapi-processor-spring. - * DO NOT EDIT. + * DO NOT MODIFY - this class was auto generated by openapi-processor-spring + * + * test + * time + * https://docs.openapiprocessor.io/spring */ package generated.api; diff --git a/src/testInt/resources/tests/params-request-body/generated/api/Api.java b/src/testInt/resources/tests/params-request-body/generated/api/Api.java index 148c89bd..dc8771be 100644 --- a/src/testInt/resources/tests/params-request-body/generated/api/Api.java +++ b/src/testInt/resources/tests/params-request-body/generated/api/Api.java @@ -1,6 +1,9 @@ /* - * This class is auto generated by https://github.com/hauner/openapi-processor-spring. - * DO NOT EDIT. + * DO NOT MODIFY - this class was auto generated by openapi-processor-spring + * + * test + * time + * https://docs.openapiprocessor.io/spring */ package generated.api; diff --git a/src/testInt/resources/tests/params-request-body/generated/model/Book.java b/src/testInt/resources/tests/params-request-body/generated/model/Book.java index b0590499..9289aafd 100644 --- a/src/testInt/resources/tests/params-request-body/generated/model/Book.java +++ b/src/testInt/resources/tests/params-request-body/generated/model/Book.java @@ -1,6 +1,9 @@ /* - * This class is auto generated by https://github.com/hauner/openapi-processor-spring. - * DO NOT EDIT. + * DO NOT MODIFY - this class was auto generated by openapi-processor-spring + * + * test + * time + * https://docs.openapiprocessor.io/spring */ package generated.model; diff --git a/src/testInt/resources/tests/params-simple-data-types/generated/api/EndpointApi.java b/src/testInt/resources/tests/params-simple-data-types/generated/api/EndpointApi.java index 72f79542..8fda2639 100644 --- a/src/testInt/resources/tests/params-simple-data-types/generated/api/EndpointApi.java +++ b/src/testInt/resources/tests/params-simple-data-types/generated/api/EndpointApi.java @@ -1,6 +1,9 @@ /* - * This class is auto generated by https://github.com/hauner/openapi-processor-spring. - * DO NOT EDIT. + * DO NOT MODIFY - this class was auto generated by openapi-processor-spring + * + * test + * time + * https://docs.openapiprocessor.io/spring */ package generated.api;