Skip to content

improve heaer of generated source files #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ repositories {
}
}

sourceSets {
main {
java {
srcDirs "${buildDir}/version"
}
}
}

compileKotlin.dependsOn "generateVersion"


test {
useJUnitPlatform()
}
Expand Down Expand Up @@ -156,4 +167,5 @@ dokka {
outputDirectory = "$buildDir/docs/kotlin"
}

apply plugin: VersionPlugin
apply from: "${rootProject.rootDir}/gradle/publishing.gradle"
44 changes: 44 additions & 0 deletions buildSrc/src/main/groovy/VersionPlugin.groovy
Original file line number Diff line number Diff line change
@@ -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:
*
* <pre>{@code
* package io.openapiprocessor.spring;
*
* public class Version {
* public static final String version = "${project.version}";
* }
* }</pre>
*
*
* 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<Project> {

void apply(Project project) {
project.afterEvaluate (new Action<Project> () {

@Override
void execute (Project prj) {
prj.tasks.register ('generateVersion', VersionTask , new Action<VersionTask>() {

@Override
void execute (VersionTask task) {
task.targetDir = prj.buildDir
task.version = prj.version
}

})
}

})
}

}
52 changes: 52 additions & 0 deletions buildSrc/src/main/groovy/VersionTask.groovy
Original file line number Diff line number Diff line change
@@ -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}";
}

"""
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
*/

"""
Expand Down
Original file line number Diff line number Diff line change
@@ -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
*/

"""
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,7 +27,7 @@ import org.junit.runners.Parameterized
* using Junit so IDEA adds a "<Click to see difference>" when using assertEquals().
*/
@RunWith(Parameterized)
class ProcessorEndToEndTest extends ProcessorTestBase {
class ProcessorEndToEndTest extends EndToEndBase {

@Parameterized.Parameters(name = "{0}")
static Collection<TestSet> sources () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.junit.runners.Parameterized
* using Junit so IDEA adds a "<Click to see difference>" when using assertEquals().
*/
@RunWith(Parameterized)
class ProcessorJimsFileSystemTest extends ProcessorTestBase {
class ProcessorJimsFileSystemTest extends EndToEndBase {

@Parameterized.Parameters(name = "{0}")
static Collection<TestSet> sources () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestSet> sources () {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down