diff --git a/README.md b/README.md index c618d03..283dc23 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ See [CreekService.org](https://www.creekservice.org) for info on Creek Service. | 6.4.+ | 6.4 | Supported & tested | | 6.4+ | 6.9.4 | Supported & tested | | 7.+ | 7.6.1 | Supported & tested | -| 8.+ | 8.0.2 | Supported & tested | -| > 8.0.2 | | Not currently tested. Should work... | +| 8.+ | 8.5 | Supported & tested | +| > 8.5 | | Not currently tested. Should work... | ## Usage @@ -32,7 +32,7 @@ See the portal for instructions on how to add the plugin to your build. The JSON Schema plugin adds the following tasks to your project: -### generateJsonSchema - `GenerateJsonSchema`[5] +### generateJsonSchema - [GenerateJsonSchema][5] > ### NOTE > Details of how to annotate classes to control their schema can be found in the [Creek JSON Schema Generator docs][1]. @@ -44,8 +44,8 @@ The JSON Schema plugin adds the following tasks to your project: *Dependants:* `processResources` The `generateJsonSchema` task searches the class and module path for with [`@GeneratesSchema`][2] and write out -JSON schemas for them in YAML. The generated schemas are added to the `main` resource set, meaning they will be included -in any generated jar. +JSON schemas for them in YAML. The generated schema output directory is added to the `main` source set, +as an additional resource directories, meaning the schema will be included in any generated jar. Types can be annotated both with [Jackson][3] and [JsonSchema][4] annotations, allowing control of the generated schema. @@ -71,6 +71,25 @@ For example, the following limits the class & module path scanning to only two m --type-scanning-allowed-module=acme.sales.model ``` +### generateTestJsonSchema - [GenerateJsonSchema][5] + +> ### NOTE +> Details of how to annotate classes to control their schema can be found in the [Creek JSON Schema Generator docs][1]. + +> ### NOTE +> Restricting class & module path scanning by setting allowed modules and allowed packages can increase the speed of your build. + +*Dependencies:* `compileTestJava`, `compileTestKotlin`, `compileTestGroovy` if they exist. +*Dependants:* `processTestResources` + +The `generateTestJsonSchema` works the same as [generateJsonSchema](#generatejsonschema---generatejsonschema5), only +for test code. The generated schema output directory is added to the `test` source set, +as an additional resource directories, meaning the schema will be available during unit testing. + +**NOTE**: due to a [bug](https://github.com/java9-modularity/gradle-modules-plugin/issues/227) in the `org.javamodularity.moduleplugin` Gradle plugin, +generated resources are NOT patched in to the module during unit testing. +This should be fixed once https://github.com/java9-modularity/gradle-modules-plugin/pull/228 is merged and released. + ### clean*TaskName* - `Delete` Deletes the files created by the specified task. For example, `cleanGenerateJsonSchema` will delete the generated JSON schema files. @@ -270,22 +289,28 @@ creek.schema.json { ## JSON Schema Generation The `generateJsonSchema` task generates YAML files containing the JSON schema of each `@GeneratesSchema` annotated type -it encounters. By default, these are written to `$buildDir/generated/resources/schema/schema/json`, with -`$buildDir/generated/resources/schema` being added as a resource root. This means the schema files generated will +it encounters. By default, these are written to `$buildDir/generated/resources/schema/main/schema/json`, with +`$buildDir/generated/resources/schema/main` being added as a resource root. This means the schema files generated will be included in the jar under a `schema/json` directory. +The `generateTestJsonSchema` task outputs to the `$buildDir/generated/resources/schema/test/schema/json`, with +`$buildDir/generated/resources/schema/test` being added as a resource root. + ### Changing schema file location The location where schema files are written can be changed by changing either: -* `creek.schema.json.schemaResourceRoot`: the resource root for schema, defaulting to `$buildDir/generated/resources/schema`, or -* `creek.schema.json.outputDirectoryName`: the name of the subdirectory under `creek.schema.json.schemaResourceRoot` where schemas will be written, - and defining the relative path to the schema files within the resulting jar file. +* `creek.schema.json.schemaResourceRoot`: the resource root for schema, defaulting to `$buildDir/generated/resources/schema/main`, or +* `creek.schema.json.testSchemaResourceRoot`: the resource root for test schema, defaulting to `$buildDir/generated/resources/schema/test`, or +* `creek.schema.json.outputDirectoryName`: the name of the subdirectory under `creek.schema.json.schemaResourceRoot` and + `creek.schema.json.testSchemaResourceRoot` where schemas will be written, + and defining the relative path to the schema files within the resulting jar file. ##### Groovy: Customising schema file output location ```groovy creek.schema.json { schemaResourceRoot = file("$buildDir/custom/build/path") + testSchemaResourceRoot = file("$buildDir/custom/build/path/for/test/schema") outputDirectoryName = "custom/path/within/jar" } ``` @@ -294,6 +319,7 @@ creek.schema.json { ```kotlin creek.schema.json { schemaResourceRoot.set(file("$buildDir/custom/build/path")) + testSchemaResourceRoot.set(file("$buildDir/custom/build/path/for/test/schema")) outputDirectoryName.set("custom/path/within/jar") } ``` @@ -301,7 +327,7 @@ creek.schema.json { ## JVM Language support Currently, the plugin automatically configures tasks to work with the standard Java, Groovy and Kotlin plugins. -Schema generation tasks are configured to read the output of `compileJava`, `compileGroovy` and `compileKotlin` +Schema generation tasks are configured to read the output of `compile[Test]Java`, `compile[Test]Groovy` and `compile[Test]Kotlin` tasks if they are present in the project. Support for other JVM languages may be added later, or you may be able to configure your own instance of `GenerateJsonSchema` diff --git a/src/main/java/org/creekservice/api/json/schema/gradle/plugin/JsonSchemaExtension.java b/src/main/java/org/creekservice/api/json/schema/gradle/plugin/JsonSchemaExtension.java index b8b5a4e..29ca40d 100644 --- a/src/main/java/org/creekservice/api/json/schema/gradle/plugin/JsonSchemaExtension.java +++ b/src/main/java/org/creekservice/api/json/schema/gradle/plugin/JsonSchemaExtension.java @@ -124,8 +124,17 @@ public TypeScanningSpec getSubtypeScanning() { public abstract DirectoryProperty getSchemaResourceRoot(); /** - * Optional name of the directory under the {@link #getSchemaResourceRoot() resource root} where - * the schema will be written. + * Optional resource root where generated test schemas should be stored + * + *

Default: {@code $buildDir/generated/test-resources/schema} + * + * @return the test resource root property. + */ + public abstract DirectoryProperty getTestSchemaResourceRoot(); + + /** + * Optional name of the directory under the {@link #getSchemaResourceRoot() resource root} and + * {@link #getTestSchemaResourceRoot() test resource root} where the schema will be written. * *

This corresponds to the directory under which schema files will be located within the * compiled jar file. diff --git a/src/main/java/org/creekservice/api/json/schema/gradle/plugin/JsonSchemaPlugin.java b/src/main/java/org/creekservice/api/json/schema/gradle/plugin/JsonSchemaPlugin.java index 6bd5625..bbaab69 100644 --- a/src/main/java/org/creekservice/api/json/schema/gradle/plugin/JsonSchemaPlugin.java +++ b/src/main/java/org/creekservice/api/json/schema/gradle/plugin/JsonSchemaPlugin.java @@ -18,18 +18,17 @@ import static org.creekservice.api.json.schema.gradle.plugin.GeneratorVersion.defaultGeneratorVersion; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import java.util.stream.Stream; import org.creekservice.api.json.schema.gradle.plugin.task.GenerateJsonSchema; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.dsl.DependencyHandler; -import org.gradle.api.plugins.BasePlugin; import org.gradle.api.plugins.ExtensionAware; import org.gradle.api.plugins.ExtensionContainer; import org.gradle.api.plugins.JavaPlugin; @@ -54,11 +53,17 @@ public final class JsonSchemaPlugin implements Plugin { /** Generate schema task name. */ public static final String GENERATE_SCHEMA_TASK_NAME = "generateJsonSchema"; + /** Generate test schema task name. */ + public static final String GENERATE_TEST_SCHEMA_TASK_NAME = "generateTestJsonSchema"; + /** Standard Creek group name. */ public static final String GROUP_NAME = "creek"; /** Default resource root */ - public static final String DEFAULT_RESOURCE_ROOT = "generated/resources/schema"; + public static final String DEFAULT_RESOURCE_ROOT = "generated/resources/schema/main"; + + /** Default test resource root */ + public static final String DEFAULT_TEST_RESOURCE_ROOT = "generated/resources/schema/test"; /** Default output folder under the resource root. */ public static final String DEFAULT_OUTPUT_FOLDER = "schema/json"; @@ -74,12 +79,12 @@ public final class JsonSchemaPlugin implements Plugin { @Override public void apply(final Project project) { - project.getPluginManager().apply(BasePlugin.class); + project.getPluginManager().apply(JavaPlugin.class); final JsonSchemaExtension extension = registerExtension(project); registerGenerateSchemaTask(project, extension); + registerGenerateTestSchemaTask(project, extension); registerJsonSchemaConfiguration(project); - project.afterEvaluate(this::afterEvaluate); } private JsonSchemaExtension registerExtension(final Project project) { @@ -97,6 +102,10 @@ private JsonSchemaExtension registerExtension(final Project project) { extension .getSchemaResourceRoot() .convention(project.getLayout().getBuildDirectory().dir(DEFAULT_RESOURCE_ROOT)); + extension + .getTestSchemaResourceRoot() + .convention( + project.getLayout().getBuildDirectory().dir(DEFAULT_TEST_RESOURCE_ROOT)); extension.getOutputDirectoryName().convention(DEFAULT_OUTPUT_FOLDER); extension.getExtraArguments().convention(List.of()); return extension; @@ -107,6 +116,49 @@ private void registerGenerateSchemaTask( final GenerateJsonSchema task = project.getTasks().create(GENERATE_SCHEMA_TASK_NAME, GenerateJsonSchema.class); + task.getSchemaResourceRoot().set(extension.getSchemaResourceRoot()); + + configure(extension, task, SourceSet.MAIN_SOURCE_SET_NAME); + + project.afterEvaluate( + proj -> + afterEvaluate( + proj, + GENERATE_SCHEMA_TASK_NAME, + JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME, + List.of( + JavaPlugin.COMPILE_JAVA_TASK_NAME, + "compileKotlin", + "compileGroovy"), + JavaPlugin.PROCESS_RESOURCES_TASK_NAME)); + } + + private void registerGenerateTestSchemaTask( + final Project project, final JsonSchemaExtension extension) { + final GenerateJsonSchema task = + project.getTasks().create(GENERATE_TEST_SCHEMA_TASK_NAME, GenerateJsonSchema.class); + + task.getSchemaResourceRoot().set(extension.getTestSchemaResourceRoot()); + + configure(extension, task, SourceSet.TEST_SOURCE_SET_NAME); + + project.afterEvaluate( + proj -> + afterEvaluate( + proj, + GENERATE_TEST_SCHEMA_TASK_NAME, + JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME, + List.of( + JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME, + "compileTestKotlin", + "compileTestGroovy"), + JavaPlugin.PROCESS_TEST_RESOURCES_TASK_NAME)); + } + + private static void configure( + final JsonSchemaExtension extension, + final GenerateJsonSchema task, + final String sourceSetName) { task.setGroup(GROUP_NAME); task.getTypeScanningModuleWhiteList().set(extension.getTypeScanning().getModuleWhiteList()); task.getTypeScanningPackageWhiteList() @@ -115,9 +167,17 @@ private void registerGenerateSchemaTask( .set(extension.getSubtypeScanning().getModuleWhiteList()); task.getSubtypeScanningPackageWhiteList() .set(extension.getSubtypeScanning().getPackageWhiteListed()); - task.getSchemaResourceRoot().set(extension.getSchemaResourceRoot()); task.getOutputDirectoryName().set(extension.getOutputDirectoryName()); task.getExtraArguments().set(extension.getExtraArguments()); + + final SourceSetContainer sourceSetContainer = + task.getProject().getExtensions().findByType(SourceSetContainer.class); + if (sourceSetContainer == null) { + throw new IllegalStateException("source set container not registered"); + } + + final SourceSet sourceSet = sourceSetContainer.getByName(sourceSetName); + sourceSet.getOutput().dir(Map.of("buildBy", task.getName()), task.getSchemaResourceRoot()); } private void registerJsonSchemaConfiguration(final Project project) { @@ -142,32 +202,23 @@ private void registerJsonSchemaConfiguration(final Project project) { .configureEach(task -> task.getGeneratorDeps().from(cfg)); } - private void afterEvaluate(final Project project) { + private void afterEvaluate( + final Project project, + final String generateTaskName, + final String compileConfigName, + final List compileTaskNames, + final String resourceTaskName) { final GenerateJsonSchema generateTask = - (GenerateJsonSchema) project.getTasks().getByName(GENERATE_SCHEMA_TASK_NAME); - - final SourceSetContainer sourceSetContainer = - project.getExtensions().findByType(SourceSetContainer.class); - if (sourceSetContainer != null) { - final SourceSet mainSourceSet = - sourceSetContainer.getByName(SourceSet.MAIN_SOURCE_SET_NAME); - - mainSourceSet - .getOutput() - .dir( - Map.of("buildBy", GENERATE_SCHEMA_TASK_NAME), - generateTask.getSchemaResourceRoot()); - } + (GenerateJsonSchema) project.getTasks().getByName(generateTaskName); final Configuration compileClassPathConfig = - project.getConfigurations() - .findByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME); + project.getConfigurations().findByName(compileConfigName); if (compileClassPathConfig != null) { generateTask.getProjectDeps().from(compileClassPathConfig); } - final Set compileTasks = compileTasks(project); + final Set compileTasks = collectTasks(project, compileTaskNames); compileTasks.forEach( compileTask -> { @@ -177,12 +228,12 @@ private void afterEvaluate(final Project project) { generateTask.onlyIf(t -> compileTasks.stream().anyMatch(Task::getDidWork)); - project.getTasksByName(JavaPlugin.PROCESS_RESOURCES_TASK_NAME, false) + project.getTasksByName(resourceTaskName, false) .forEach(processTask -> processTask.dependsOn(generateTask)); } - private Set compileTasks(final Project project) { - return Stream.of(JavaPlugin.COMPILE_JAVA_TASK_NAME, "compileKotlin", "compileGroovy") + private Set collectTasks(final Project project, final Collection taskNames) { + return taskNames.stream() .map(taskName -> project.getTasksByName(taskName, false)) .flatMap(Set::stream) .collect(Collectors.toUnmodifiableSet()); @@ -200,6 +251,7 @@ private ExtensionAware ensureExtension( } /** Simple extendable `creek` extension */ + @SuppressWarnings("NullableProblems") public abstract static class CreekSpec implements ExtensionAware { @Override @@ -207,6 +259,7 @@ public abstract static class CreekSpec implements ExtensionAware { } /** Simple extendable `schema` extension */ + @SuppressWarnings("NullableProblems") public abstract static class SchemaSpec implements ExtensionAware { @Override diff --git a/src/test/java/org/creekservice/api/json/schema/gradle/plugin/task/GenerateJsonSchemaTest.java b/src/test/java/org/creekservice/api/json/schema/gradle/plugin/task/GenerateJsonSchemaTest.java index 399f8f1..921593d 100644 --- a/src/test/java/org/creekservice/api/json/schema/gradle/plugin/task/GenerateJsonSchemaTest.java +++ b/src/test/java/org/creekservice/api/json/schema/gradle/plugin/task/GenerateJsonSchemaTest.java @@ -62,7 +62,9 @@ class GenerateJsonSchemaTest { private static final Path TEST_DIR = PROJECT_DIR.resolve("src/test/resources/projects/functional").toAbsolutePath(); - private static final String TASK_NAME = ":generateJsonSchema"; + private static final String GENERATE_TASK_NAME = ":generateJsonSchema"; + private static final String GENERATE_TEST_TASK_NAME = ":generateTestJsonSchema"; + private static final String TEST_TASK_NAME = ":test"; private static final String INIT_SCRIPT = "--init-script=" + TEST_DIR.resolve("init.gradle"); @TempDir private Path projectDir; @@ -80,10 +82,11 @@ void shouldSkipIfNoMainSourceSet(final String flavour, final String gradleVersio givenProject(flavour + "/no-source-sets"); // When: - final BuildResult result = executeTask(ExpectedOutcome.PASS, gradleVersion); + final BuildResult result = + executeTask(GENERATE_TASK_NAME, ExpectedOutcome.PASS, gradleVersion); // Then: - assertThat(result.task(TASK_NAME).getOutcome(), is(SKIPPED)); + assertThat(result.task(GENERATE_TASK_NAME).getOutcome(), is(SKIPPED)); } @CartesianTest @@ -93,10 +96,11 @@ void shouldSkipIfCompileTasksDidNoWork(final String flavour, final String gradle givenProject(flavour + "/empty"); // When: - final BuildResult result = executeTask(ExpectedOutcome.PASS, gradleVersion); + final BuildResult result = + executeTask(GENERATE_TASK_NAME, ExpectedOutcome.PASS, gradleVersion); // Then: - assertThat(result.task(TASK_NAME).getOutcome(), is(SKIPPED)); + assertThat(result.task(GENERATE_TASK_NAME).getOutcome(), is(SKIPPED)); } @CartesianTest @@ -106,16 +110,17 @@ void shouldExecuteWithDefaults(final String flavour, final String gradleVersion) givenProject(flavour + "/default"); // When: - final BuildResult result = executeTask(ExpectedOutcome.PASS, gradleVersion); + final BuildResult result = + executeTask(GENERATE_TASK_NAME, ExpectedOutcome.PASS, gradleVersion); // Then: - assertThat(result.task(TASK_NAME).getOutcome(), is(SUCCESS)); + assertThat(result.task(GENERATE_TASK_NAME).getOutcome(), is(SUCCESS)); assertThat( result.getOutput(), containsString( "--output-directory=" + projectDir.resolve( - "build/generated/resources/schema/schema/json"))); + "build/generated/resources/schema/main/schema/json"))); assertThat(result.getOutput(), containsString("--type-scanning-allowed-modules=")); assertThat(result.getOutput(), containsString("--type-scanning-allowed-packages=")); assertThat(result.getOutput(), containsString("--subtype-scanning-allowed-modules=")); @@ -147,10 +152,11 @@ void shouldExecuteWithSpecificVersion(final String flavour, final String gradleV givenProject(flavour + "/specific_version"); // When: - final BuildResult result = executeTask(ExpectedOutcome.PASS, gradleVersion); + final BuildResult result = + executeTask(GENERATE_TASK_NAME, ExpectedOutcome.PASS, gradleVersion); // Then: - assertThat(result.task(TASK_NAME).getOutcome(), is(SUCCESS)); + assertThat(result.task(GENERATE_TASK_NAME).getOutcome(), is(SUCCESS)); assertThat(result.getOutput(), containsString("JsonSchemaGenerator: 0.2.0-SNAPSHOT")); } @@ -161,14 +167,56 @@ void shouldExecuteWithCustomProperties(final String flavour, final String gradle givenProject(flavour + "/fully_configured"); // When: - final BuildResult result = executeTask(ExpectedOutcome.PASS, gradleVersion); + final BuildResult result = + executeTask(GENERATE_TASK_NAME, ExpectedOutcome.PASS, gradleVersion); + + // Then: + assertThat(result.task(GENERATE_TASK_NAME).getOutcome(), is(SUCCESS)); + assertThat( + result.getOutput(), + containsString( + "--output-directory=" + projectDir.resolve("build/custom/path/main/bob"))); + assertThat( + result.getOutput(), + containsString("--type-scanning-allowed-modules=[acme.test, acme.models]")); + assertThat( + result.getOutput(), + containsString( + "--type-scanning-allowed-packages=[com.acme.test, com.acme.models]")); + assertThat( + result.getOutput(), + containsString( + "--subtype-scanning-allowed-modules=[acme.test.sub, acme.models.sub]")); + assertThat( + result.getOutput(), + containsString( + "--subtype-scanning-allowed-packages=[com.acme.test.sub," + + " com.acme.models.sub]")); + assertThat( + "Should be running from the module-path", + result.getOutput(), + matchesPattern( + Pattern.compile( + ".*^--module-path=[^\n\r]*creek-json-schema-generator.*", + Pattern.MULTILINE | Pattern.DOTALL))); + } + + @CartesianTest + @MethodFactory("flavoursAndVersions") + void shouldExecuteTestWithCustomProperties(final String flavour, final String gradleVersion) { + // Given: + givenProject(flavour + "/fully_configured"); + + // When: + final BuildResult result = + executeTask(GENERATE_TEST_TASK_NAME, ExpectedOutcome.PASS, gradleVersion); // Then: - assertThat(result.task(TASK_NAME).getOutcome(), is(SUCCESS)); + assertThat(result.task(GENERATE_TEST_TASK_NAME).getOutcome(), is(SUCCESS)); assertThat( result.getOutput(), containsString( - "--output-directory=" + projectDir.resolve("build/custom/path/bob"))); + "--output-directory=" + projectDir.resolve("build/custom/path/test/bob"))); assertThat( result.getOutput(), containsString("--type-scanning-allowed-modules=[acme.test, acme.models]")); @@ -202,10 +250,11 @@ void shouldFailIfSystemTestConfigurationDoesNotContainExecutor( givenProject(flavour + "/missing_generator_dep"); // When: - final BuildResult result = executeTask(ExpectedOutcome.FAIL, gradleVersion); + final BuildResult result = + executeTask(GENERATE_TASK_NAME, ExpectedOutcome.FAIL, gradleVersion); // Then: - assertThat(result.task(TASK_NAME).getOutcome(), is(FAILED)); + assertThat(result.task(GENERATE_TASK_NAME).getOutcome(), is(FAILED)); assertThat( result.getOutput(), containsString( @@ -220,10 +269,11 @@ void shouldFailOnBadConfig(final String flavour, final String gradleVersion) { givenProject(flavour + "/invalid_config"); // When: - final BuildResult result = executeTask(ExpectedOutcome.FAIL, gradleVersion); + final BuildResult result = + executeTask(GENERATE_TASK_NAME, ExpectedOutcome.FAIL, gradleVersion); // Then: - assertThat(result.task(TASK_NAME).getOutcome(), is(FAILED)); + assertThat(result.task(GENERATE_TASK_NAME).getOutcome(), is(FAILED)); assertThat(result.getOutput(), containsString("Unknown option: '--unsupported-arg'")); } @@ -237,6 +287,7 @@ void shouldExecuteWithOptions(final String flavour, final String gradleVersion) // When: final BuildResult result = executeTask( + GENERATE_TASK_NAME, ExpectedOutcome.PASS, gradleVersion, "--extra-argument=--echo-only", @@ -250,7 +301,7 @@ void shouldExecuteWithOptions(final String flavour, final String gradleVersion) "--subtype-scanning-allowed-package=org.test.sub.two"); // Then: - assertThat(result.task(TASK_NAME).getOutcome(), is(SUCCESS)); + assertThat(result.task(GENERATE_TASK_NAME).getOutcome(), is(SUCCESS)); assertThat( result.getOutput(), containsString("--type-scanning-allowed-modules=[acme.test, acme.model]")); @@ -291,7 +342,8 @@ void shouldDeleteOutputDirectoryOnClean(final String flavour, final String gradl // Given: givenProject(flavour + "/default"); final Path resultsDir = - givenDirectory(projectDir.resolve("build/generated/resources/schema/schema/json")); + givenDirectory( + projectDir.resolve("build/generated/resources/schema/main/schema/json")); // When: final BuildResult result = @@ -309,10 +361,11 @@ void shouldPlayNicelyWithOthers(final String flavour, final String gradleVersion givenProject(flavour + "/other_creek_plugin"); // When: - final BuildResult result = executeTask(ExpectedOutcome.PASS, gradleVersion); + final BuildResult result = + executeTask(GENERATE_TASK_NAME, ExpectedOutcome.PASS, gradleVersion); // Then: - assertThat(result.task(TASK_NAME).getOutcome(), is(SUCCESS)); + assertThat(result.task(GENERATE_TASK_NAME).getOutcome(), is(SUCCESS)); } @CartesianTest @@ -325,14 +378,38 @@ void shouldWriteOutSchemaFiles( givenProject(flavour + "/generates_schema/" + language); final Path expectedSchemaDir = givenDirectory(projectDir.resolve("expected")); final Path actualSchemaDir = - givenDirectory(projectDir.resolve("build/generated/resources/schema/schema/json")); + givenDirectory( + projectDir.resolve("build/generated/resources/schema/main/schema/json")); // When: - final BuildResult result = executeTask(ExpectedOutcome.PASS, gradleVersion); + final BuildResult result = executeTask(TEST_TASK_NAME, ExpectedOutcome.PASS, gradleVersion); // Then: - assertThat(result.task(TASK_NAME).getOutcome(), is(SUCCESS)); + assertThat(result.task(GENERATE_TASK_NAME).getOutcome(), is(SUCCESS)); assertSchemas(actualSchemaDir, expectedSchemaDir); + assertThat(result.task(TEST_TASK_NAME).getOutcome(), is(SUCCESS)); + } + + @CartesianTest + @MethodFactory("flavoursVersionsAndLanguage") + void shouldWriteOutTestSchemaFiles( + final String flavour, final String gradleVersion, final String language) { + assumeTrue(supported(gradleVersion, language)); + + // Given: + givenProject(flavour + "/generates_test_schema/" + language); + final Path expectedSchemaDir = givenDirectory(projectDir.resolve("expected")); + final Path actualSchemaDir = + givenDirectory( + projectDir.resolve("build/generated/resources/schema/test/schema/json")); + + // When: + final BuildResult result = executeTask(TEST_TASK_NAME, ExpectedOutcome.PASS, gradleVersion); + + // Then: + assertThat(result.task(GENERATE_TEST_TASK_NAME).getOutcome(), is(SUCCESS)); + assertSchemas(actualSchemaDir, expectedSchemaDir); + assertThat(result.task(TEST_TASK_NAME).getOutcome(), is(SUCCESS)); } @Test @@ -358,13 +435,6 @@ private enum ExpectedOutcome { FAIL } - private BuildResult executeTask( - final ExpectedOutcome expectedOutcome, - final String gradleVersion, - final String... additionalArgs) { - return executeTask(TASK_NAME, expectedOutcome, gradleVersion, additionalArgs); - } - private BuildResult executeTask( final String taskName, final ExpectedOutcome expectedOutcome, @@ -444,7 +514,7 @@ private static String readSchema(final Path path) { private static ArgumentSets flavoursAndVersions() { final Collection flavours = List.of("kotlin", "groovy"); // Note: update root README.md when updating this test dimension: - final Collection gradleVersions = List.of("6.4", "6.9.4", "7.6.1", "8.0.2"); + final Collection gradleVersions = List.of("6.4", "6.9.4", "7.6.1", "8.5"); return ArgumentSets.argumentsForFirstParameter(flavours) .argumentsForNextParameter(gradleVersions); } diff --git a/src/test/resources/projects/functional/groovy/fully_configured/build.gradle b/src/test/resources/projects/functional/groovy/fully_configured/build.gradle index 6f2695b..daac3be 100644 --- a/src/test/resources/projects/functional/groovy/fully_configured/build.gradle +++ b/src/test/resources/projects/functional/groovy/fully_configured/build.gradle @@ -22,7 +22,8 @@ plugins { creek { schema { json { - schemaResourceRoot = file("$buildDir/custom/path") + schemaResourceRoot = file("$buildDir/custom/path/main") + testSchemaResourceRoot = file("$buildDir/custom/path/test") outputDirectoryName = 'bob' extraArguments '--echo-only' diff --git a/src/test/resources/projects/functional/groovy/fully_configured/src/test/java/DemoTest.java b/src/test/resources/projects/functional/groovy/fully_configured/src/test/java/DemoTest.java new file mode 100644 index 0000000..1d8aed0 --- /dev/null +++ b/src/test/resources/projects/functional/groovy/fully_configured/src/test/java/DemoTest.java @@ -0,0 +1 @@ +public class DemoTest {} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_schema/groovy/build.gradle b/src/test/resources/projects/functional/groovy/generates_schema/groovy/build.gradle index f27653e..0a88970 100644 --- a/src/test/resources/projects/functional/groovy/generates_schema/groovy/build.gradle +++ b/src/test/resources/projects/functional/groovy/generates_schema/groovy/build.gradle @@ -23,4 +23,11 @@ plugins { dependencies { implementation 'org.codehaus.groovy:groovy-all:3.0.9' implementation 'org.creekservice:creek-base-annotation:+' + + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1' +} + +tasks.test { + useJUnitPlatform() } \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_schema/groovy/src/test/java/acme/ModelTest.java b/src/test/resources/projects/functional/groovy/generates_schema/groovy/src/test/java/acme/ModelTest.java new file mode 100644 index 0000000..7e05174 --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_schema/groovy/src/test/java/acme/ModelTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.junit.jupiter.api.Test; +import java.io.File; +import java.net.URL; +import java.nio.file.Path; + +class ModelTest { + + @Test + void shouldLoadSchemaAsResource() { + final Path path = Path.of(File.separator, "schema", "json", "acme.model.yml"); + final URL resource = ModelTest.class.getResource(path.toString()); + if (resource == null) { + throw new AssertionError("resource not found: " + path); + } + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_schema/java-module/build.gradle b/src/test/resources/projects/functional/groovy/generates_schema/java-module/build.gradle index e17c3c1..1139679 100644 --- a/src/test/resources/projects/functional/groovy/generates_schema/java-module/build.gradle +++ b/src/test/resources/projects/functional/groovy/generates_schema/java-module/build.gradle @@ -22,6 +22,13 @@ plugins { dependencies { api 'org.creekservice:creek-base-annotation:+' implementation 'com.google.guava:guava:31.1-jre' + + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1' +} + +tasks.test { + useJUnitPlatform() } creek.schema.json { diff --git a/src/test/resources/projects/functional/groovy/generates_schema/java-module/src/test/java/acme/ModelTest.java b/src/test/resources/projects/functional/groovy/generates_schema/java-module/src/test/java/acme/ModelTest.java new file mode 100644 index 0000000..7e05174 --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_schema/java-module/src/test/java/acme/ModelTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.junit.jupiter.api.Test; +import java.io.File; +import java.net.URL; +import java.nio.file.Path; + +class ModelTest { + + @Test + void shouldLoadSchemaAsResource() { + final Path path = Path.of(File.separator, "schema", "json", "acme.model.yml"); + final URL resource = ModelTest.class.getResource(path.toString()); + if (resource == null) { + throw new AssertionError("resource not found: " + path); + } + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_schema/java/build.gradle b/src/test/resources/projects/functional/groovy/generates_schema/java/build.gradle index 9175995..e5be447 100644 --- a/src/test/resources/projects/functional/groovy/generates_schema/java/build.gradle +++ b/src/test/resources/projects/functional/groovy/generates_schema/java/build.gradle @@ -21,4 +21,11 @@ plugins { dependencies { implementation 'org.creekservice:creek-base-annotation:+' + + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1' +} + +tasks.test { + useJUnitPlatform() } \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_schema/java/src/main/java/Model.java b/src/test/resources/projects/functional/groovy/generates_schema/java/src/main/java/acme/Model.java similarity index 100% rename from src/test/resources/projects/functional/groovy/generates_schema/java/src/main/java/Model.java rename to src/test/resources/projects/functional/groovy/generates_schema/java/src/main/java/acme/Model.java diff --git a/src/test/resources/projects/functional/groovy/generates_schema/java/src/test/java/acme/ModelTest.java b/src/test/resources/projects/functional/groovy/generates_schema/java/src/test/java/acme/ModelTest.java new file mode 100644 index 0000000..4ac6955 --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_schema/java/src/test/java/acme/ModelTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.junit.jupiter.api.Test; +import java.io.File; +import java.net.URL; +import java.nio.file.Path; + +class ModelTest { + + @Test + void shouldLoadSchemaAsResource() { + final Path path = Path.of(File.separator, "schema", "json", "acme.model.yml"); + final URL resource = ModelTest.class.getResource(path.toString()); + System.out.println(path + " -> " + resource); + if (resource == null) { + throw new AssertionError("resource not found: " + path); + } + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_schema/kotlin/build.gradle b/src/test/resources/projects/functional/groovy/generates_schema/kotlin/build.gradle index 3cfbb6c..ab862c1 100644 --- a/src/test/resources/projects/functional/groovy/generates_schema/kotlin/build.gradle +++ b/src/test/resources/projects/functional/groovy/generates_schema/kotlin/build.gradle @@ -24,4 +24,11 @@ dependencies { implementation platform('org.jetbrains.kotlin:kotlin-bom') implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' implementation 'org.creekservice:creek-base-annotation:+' + + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1' +} + +tasks.test { + useJUnitPlatform() } \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_schema/kotlin/src/test/java/acme/ModelTest.java b/src/test/resources/projects/functional/groovy/generates_schema/kotlin/src/test/java/acme/ModelTest.java new file mode 100644 index 0000000..7e05174 --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_schema/kotlin/src/test/java/acme/ModelTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.junit.jupiter.api.Test; +import java.io.File; +import java.net.URL; +import java.nio.file.Path; + +class ModelTest { + + @Test + void shouldLoadSchemaAsResource() { + final Path path = Path.of(File.separator, "schema", "json", "acme.model.yml"); + final URL resource = ModelTest.class.getResource(path.toString()); + if (resource == null) { + throw new AssertionError("resource not found: " + path); + } + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_test_schema/groovy/build.gradle b/src/test/resources/projects/functional/groovy/generates_test_schema/groovy/build.gradle new file mode 100644 index 0000000..0a88970 --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_test_schema/groovy/build.gradle @@ -0,0 +1,33 @@ +/* + * Copyright 2022 Creek Contributors (https://github.com/creek-service) + * + * 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. + */ + +plugins { + id 'org.creekservice.schema.json' + id 'groovy' + id 'java-library' +} + +dependencies { + implementation 'org.codehaus.groovy:groovy-all:3.0.9' + implementation 'org.creekservice:creek-base-annotation:+' + + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1' +} + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_test_schema/groovy/expected/acme.model.yml b/src/test/resources/projects/functional/groovy/generates_test_schema/groovy/expected/acme.model.yml new file mode 100644 index 0000000..e0b859a --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_test_schema/groovy/expected/acme.model.yml @@ -0,0 +1,8 @@ +--- +$schema: http://json-schema.org/draft-07/schema# +title: Model +type: object +additionalProperties: false +properties: + someProp: + type: string diff --git a/src/test/resources/projects/functional/groovy/generates_test_schema/groovy/src/test/groovy/acme/Model.groovy b/src/test/resources/projects/functional/groovy/generates_test_schema/groovy/src/test/groovy/acme/Model.groovy new file mode 100644 index 0000000..e52a717 --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_test_schema/groovy/src/test/groovy/acme/Model.groovy @@ -0,0 +1,26 @@ +/* + * Copyright 2022-2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme + +import org.creekservice.api.base.annotation.schema.GeneratesSchema + +@GeneratesSchema +class Model { + String getSomeProp() { + null + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_test_schema/groovy/src/test/java/acme/ModelTest.java b/src/test/resources/projects/functional/groovy/generates_test_schema/groovy/src/test/java/acme/ModelTest.java new file mode 100644 index 0000000..7e05174 --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_test_schema/groovy/src/test/java/acme/ModelTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.junit.jupiter.api.Test; +import java.io.File; +import java.net.URL; +import java.nio.file.Path; + +class ModelTest { + + @Test + void shouldLoadSchemaAsResource() { + final Path path = Path.of(File.separator, "schema", "json", "acme.model.yml"); + final URL resource = ModelTest.class.getResource(path.toString()); + if (resource == null) { + throw new AssertionError("resource not found: " + path); + } + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_test_schema/java-module/build.gradle b/src/test/resources/projects/functional/groovy/generates_test_schema/java-module/build.gradle new file mode 100644 index 0000000..1139679 --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_test_schema/java-module/build.gradle @@ -0,0 +1,36 @@ +/* + * Copyright 2022 Creek Contributors (https://github.com/creek-service) + * + * 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. + */ + +plugins { + id 'org.creekservice.schema.json' + id 'java-library' +} + +dependencies { + api 'org.creekservice:creek-base-annotation:+' + implementation 'com.google.guava:guava:31.1-jre' + + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1' +} + +tasks.test { + useJUnitPlatform() +} + +creek.schema.json { + typeScanning.moduleWhiteList = ['acme.models'] +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_test_schema/java-module/expected/acme.model.yml b/src/test/resources/projects/functional/groovy/generates_test_schema/java-module/expected/acme.model.yml new file mode 100644 index 0000000..e0b859a --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_test_schema/java-module/expected/acme.model.yml @@ -0,0 +1,8 @@ +--- +$schema: http://json-schema.org/draft-07/schema# +title: Model +type: object +additionalProperties: false +properties: + someProp: + type: string diff --git a/src/test/resources/projects/functional/groovy/generates_test_schema/java-module/src/main/java/acme/Other.java b/src/test/resources/projects/functional/groovy/generates_test_schema/java-module/src/main/java/acme/Other.java new file mode 100644 index 0000000..345acdd --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_test_schema/java-module/src/main/java/acme/Other.java @@ -0,0 +1,27 @@ +/* + * Copyright 2022-2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.creekservice.api.base.annotation.schema.GeneratesSchema; + +@GeneratesSchema +public final class Other { + + public long getSomeProp() { + return 1L; + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_test_schema/java-module/src/main/java/module-info.java b/src/test/resources/projects/functional/groovy/generates_test_schema/java-module/src/main/java/module-info.java new file mode 100644 index 0000000..2a6160a --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_test_schema/java-module/src/main/java/module-info.java @@ -0,0 +1,6 @@ +module acme.models { + requires transitive creek.base.annotation; + requires com.google.common; + + exports acme; +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_test_schema/java-module/src/test/java/acme/Model.java b/src/test/resources/projects/functional/groovy/generates_test_schema/java-module/src/test/java/acme/Model.java new file mode 100644 index 0000000..c1118d8 --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_test_schema/java-module/src/test/java/acme/Model.java @@ -0,0 +1,27 @@ +/* + * Copyright 2022-2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.creekservice.api.base.annotation.schema.GeneratesSchema; + +@GeneratesSchema +public final class Model { + + public String getSomeProp() { + return null; + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_test_schema/java-module/src/test/java/acme/ModelTest.java b/src/test/resources/projects/functional/groovy/generates_test_schema/java-module/src/test/java/acme/ModelTest.java new file mode 100644 index 0000000..7e05174 --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_test_schema/java-module/src/test/java/acme/ModelTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.junit.jupiter.api.Test; +import java.io.File; +import java.net.URL; +import java.nio.file.Path; + +class ModelTest { + + @Test + void shouldLoadSchemaAsResource() { + final Path path = Path.of(File.separator, "schema", "json", "acme.model.yml"); + final URL resource = ModelTest.class.getResource(path.toString()); + if (resource == null) { + throw new AssertionError("resource not found: " + path); + } + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_test_schema/java/build.gradle b/src/test/resources/projects/functional/groovy/generates_test_schema/java/build.gradle new file mode 100644 index 0000000..e5be447 --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_test_schema/java/build.gradle @@ -0,0 +1,31 @@ +/* + * Copyright 2022 Creek Contributors (https://github.com/creek-service) + * + * 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. + */ + +plugins { + id 'org.creekservice.schema.json' + id 'java-library' +} + +dependencies { + implementation 'org.creekservice:creek-base-annotation:+' + + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1' +} + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_test_schema/java/expected/acme.model.yml b/src/test/resources/projects/functional/groovy/generates_test_schema/java/expected/acme.model.yml new file mode 100644 index 0000000..e0b859a --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_test_schema/java/expected/acme.model.yml @@ -0,0 +1,8 @@ +--- +$schema: http://json-schema.org/draft-07/schema# +title: Model +type: object +additionalProperties: false +properties: + someProp: + type: string diff --git a/src/test/resources/projects/functional/groovy/generates_test_schema/java/src/test/java/acme/Model.java b/src/test/resources/projects/functional/groovy/generates_test_schema/java/src/test/java/acme/Model.java new file mode 100644 index 0000000..c1118d8 --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_test_schema/java/src/test/java/acme/Model.java @@ -0,0 +1,27 @@ +/* + * Copyright 2022-2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.creekservice.api.base.annotation.schema.GeneratesSchema; + +@GeneratesSchema +public final class Model { + + public String getSomeProp() { + return null; + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_test_schema/java/src/test/java/acme/ModelTest.java b/src/test/resources/projects/functional/groovy/generates_test_schema/java/src/test/java/acme/ModelTest.java new file mode 100644 index 0000000..4ac6955 --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_test_schema/java/src/test/java/acme/ModelTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.junit.jupiter.api.Test; +import java.io.File; +import java.net.URL; +import java.nio.file.Path; + +class ModelTest { + + @Test + void shouldLoadSchemaAsResource() { + final Path path = Path.of(File.separator, "schema", "json", "acme.model.yml"); + final URL resource = ModelTest.class.getResource(path.toString()); + System.out.println(path + " -> " + resource); + if (resource == null) { + throw new AssertionError("resource not found: " + path); + } + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_test_schema/kotlin/build.gradle b/src/test/resources/projects/functional/groovy/generates_test_schema/kotlin/build.gradle new file mode 100644 index 0000000..ab862c1 --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_test_schema/kotlin/build.gradle @@ -0,0 +1,34 @@ +/* + * Copyright 2022 Creek Contributors (https://github.com/creek-service) + * + * 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. + */ + +plugins { + id 'org.creekservice.schema.json' + id 'org.jetbrains.kotlin.jvm' version '1.6.21' + id 'java-library' +} + +dependencies { + implementation platform('org.jetbrains.kotlin:kotlin-bom') + implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' + implementation 'org.creekservice:creek-base-annotation:+' + + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1' +} + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_test_schema/kotlin/expected/acme.model.yml b/src/test/resources/projects/functional/groovy/generates_test_schema/kotlin/expected/acme.model.yml new file mode 100644 index 0000000..e0b859a --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_test_schema/kotlin/expected/acme.model.yml @@ -0,0 +1,8 @@ +--- +$schema: http://json-schema.org/draft-07/schema# +title: Model +type: object +additionalProperties: false +properties: + someProp: + type: string diff --git a/src/test/resources/projects/functional/groovy/generates_test_schema/kotlin/src/test/java/acme/ModelTest.java b/src/test/resources/projects/functional/groovy/generates_test_schema/kotlin/src/test/java/acme/ModelTest.java new file mode 100644 index 0000000..7e05174 --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_test_schema/kotlin/src/test/java/acme/ModelTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.junit.jupiter.api.Test; +import java.io.File; +import java.net.URL; +import java.nio.file.Path; + +class ModelTest { + + @Test + void shouldLoadSchemaAsResource() { + final Path path = Path.of(File.separator, "schema", "json", "acme.model.yml"); + final URL resource = ModelTest.class.getResource(path.toString()); + if (resource == null) { + throw new AssertionError("resource not found: " + path); + } + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_test_schema/kotlin/src/test/kotlin/acme/Model.kt b/src/test/resources/projects/functional/groovy/generates_test_schema/kotlin/src/test/kotlin/acme/Model.kt new file mode 100644 index 0000000..fa4e18f --- /dev/null +++ b/src/test/resources/projects/functional/groovy/generates_test_schema/kotlin/src/test/kotlin/acme/Model.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2023-2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme + +import org.creekservice.api.base.annotation.schema.GeneratesSchema + +@Suppress("unused") +@GeneratesSchema +class Model { + var someProp: String? = null +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/fully_configured/build.gradle.kts b/src/test/resources/projects/functional/kotlin/fully_configured/build.gradle.kts index 477b7d6..041183a 100644 --- a/src/test/resources/projects/functional/kotlin/fully_configured/build.gradle.kts +++ b/src/test/resources/projects/functional/kotlin/fully_configured/build.gradle.kts @@ -22,7 +22,8 @@ plugins { creek { schema { json { - schemaResourceRoot.set(file("$buildDir/custom/path")) + schemaResourceRoot.set(file("$buildDir/custom/path/main")) + testSchemaResourceRoot.set(file("$buildDir/custom/path/test")) outputDirectoryName.set("bob") extraArguments("--echo-only") diff --git a/src/test/resources/projects/functional/kotlin/fully_configured/src/test/java/DemoTest.java b/src/test/resources/projects/functional/kotlin/fully_configured/src/test/java/DemoTest.java new file mode 100644 index 0000000..1d8aed0 --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/fully_configured/src/test/java/DemoTest.java @@ -0,0 +1 @@ +public class DemoTest {} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/generates_schema/groovy/build.gradle.kts b/src/test/resources/projects/functional/kotlin/generates_schema/groovy/build.gradle.kts index 373185d..b4169fc 100644 --- a/src/test/resources/projects/functional/kotlin/generates_schema/groovy/build.gradle.kts +++ b/src/test/resources/projects/functional/kotlin/generates_schema/groovy/build.gradle.kts @@ -23,5 +23,11 @@ plugins { dependencies { implementation("org.codehaus.groovy:groovy-all:3.0.9") implementation("org.creekservice:creek-base-annotation:+") + + testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.1") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.1") } +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/generates_schema/groovy/src/test/java/acme/ModelTest.java b/src/test/resources/projects/functional/kotlin/generates_schema/groovy/src/test/java/acme/ModelTest.java new file mode 100644 index 0000000..4ac6955 --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_schema/groovy/src/test/java/acme/ModelTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.junit.jupiter.api.Test; +import java.io.File; +import java.net.URL; +import java.nio.file.Path; + +class ModelTest { + + @Test + void shouldLoadSchemaAsResource() { + final Path path = Path.of(File.separator, "schema", "json", "acme.model.yml"); + final URL resource = ModelTest.class.getResource(path.toString()); + System.out.println(path + " -> " + resource); + if (resource == null) { + throw new AssertionError("resource not found: " + path); + } + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/generates_schema/java-module/build.gradle.kts b/src/test/resources/projects/functional/kotlin/generates_schema/java-module/build.gradle.kts index 45e1422..ba71128 100644 --- a/src/test/resources/projects/functional/kotlin/generates_schema/java-module/build.gradle.kts +++ b/src/test/resources/projects/functional/kotlin/generates_schema/java-module/build.gradle.kts @@ -22,6 +22,13 @@ plugins { dependencies { api("org.creekservice:creek-base-annotation:+") implementation("com.google.guava:guava:31.1-jre") + + testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.1") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.1") +} + +tasks.test { + useJUnitPlatform() } creek.schema.json { diff --git a/src/test/resources/projects/functional/kotlin/generates_schema/java-module/src/test/java/acme/ModelTest.java b/src/test/resources/projects/functional/kotlin/generates_schema/java-module/src/test/java/acme/ModelTest.java new file mode 100644 index 0000000..4ac6955 --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_schema/java-module/src/test/java/acme/ModelTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.junit.jupiter.api.Test; +import java.io.File; +import java.net.URL; +import java.nio.file.Path; + +class ModelTest { + + @Test + void shouldLoadSchemaAsResource() { + final Path path = Path.of(File.separator, "schema", "json", "acme.model.yml"); + final URL resource = ModelTest.class.getResource(path.toString()); + System.out.println(path + " -> " + resource); + if (resource == null) { + throw new AssertionError("resource not found: " + path); + } + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/generates_schema/java/build.gradle.kts b/src/test/resources/projects/functional/kotlin/generates_schema/java/build.gradle.kts index 99ccf55..40d540d 100644 --- a/src/test/resources/projects/functional/kotlin/generates_schema/java/build.gradle.kts +++ b/src/test/resources/projects/functional/kotlin/generates_schema/java/build.gradle.kts @@ -22,4 +22,11 @@ plugins { dependencies { api("org.creekservice:creek-base-annotation:+") implementation("com.google.guava:guava:31.1-jre") + + testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.1") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.1") } + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/generates_schema/java/src/test/java/acme/ModelTest.java b/src/test/resources/projects/functional/kotlin/generates_schema/java/src/test/java/acme/ModelTest.java new file mode 100644 index 0000000..4ac6955 --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_schema/java/src/test/java/acme/ModelTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.junit.jupiter.api.Test; +import java.io.File; +import java.net.URL; +import java.nio.file.Path; + +class ModelTest { + + @Test + void shouldLoadSchemaAsResource() { + final Path path = Path.of(File.separator, "schema", "json", "acme.model.yml"); + final URL resource = ModelTest.class.getResource(path.toString()); + System.out.println(path + " -> " + resource); + if (resource == null) { + throw new AssertionError("resource not found: " + path); + } + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/generates_schema/kotlin/build.gradle.kts b/src/test/resources/projects/functional/kotlin/generates_schema/kotlin/build.gradle.kts index 9a08188..7b25627 100644 --- a/src/test/resources/projects/functional/kotlin/generates_schema/kotlin/build.gradle.kts +++ b/src/test/resources/projects/functional/kotlin/generates_schema/kotlin/build.gradle.kts @@ -24,4 +24,11 @@ dependencies { implementation(platform("org.jetbrains.kotlin:kotlin-bom")) implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") implementation("org.creekservice:creek-base-annotation:+") + + testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.1") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.1") +} + +tasks.test { + useJUnitPlatform() } diff --git a/src/test/resources/projects/functional/kotlin/generates_schema/kotlin/src/test/java/acme/ModelTest.java b/src/test/resources/projects/functional/kotlin/generates_schema/kotlin/src/test/java/acme/ModelTest.java new file mode 100644 index 0000000..4ac6955 --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_schema/kotlin/src/test/java/acme/ModelTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.junit.jupiter.api.Test; +import java.io.File; +import java.net.URL; +import java.nio.file.Path; + +class ModelTest { + + @Test + void shouldLoadSchemaAsResource() { + final Path path = Path.of(File.separator, "schema", "json", "acme.model.yml"); + final URL resource = ModelTest.class.getResource(path.toString()); + System.out.println(path + " -> " + resource); + if (resource == null) { + throw new AssertionError("resource not found: " + path); + } + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/groovy/generates_schema/groovy/build.gradle.kts b/src/test/resources/projects/functional/kotlin/generates_test_schema/groovy/build.gradle.kts similarity index 83% rename from src/test/resources/projects/functional/groovy/generates_schema/groovy/build.gradle.kts rename to src/test/resources/projects/functional/kotlin/generates_test_schema/groovy/build.gradle.kts index 373185d..b4169fc 100644 --- a/src/test/resources/projects/functional/groovy/generates_schema/groovy/build.gradle.kts +++ b/src/test/resources/projects/functional/kotlin/generates_test_schema/groovy/build.gradle.kts @@ -23,5 +23,11 @@ plugins { dependencies { implementation("org.codehaus.groovy:groovy-all:3.0.9") implementation("org.creekservice:creek-base-annotation:+") + + testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.1") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.1") } +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/generates_test_schema/groovy/expected/acme.model.yml b/src/test/resources/projects/functional/kotlin/generates_test_schema/groovy/expected/acme.model.yml new file mode 100644 index 0000000..e0b859a --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_test_schema/groovy/expected/acme.model.yml @@ -0,0 +1,8 @@ +--- +$schema: http://json-schema.org/draft-07/schema# +title: Model +type: object +additionalProperties: false +properties: + someProp: + type: string diff --git a/src/test/resources/projects/functional/kotlin/generates_test_schema/groovy/src/test/groovy/acme/Model.groovy b/src/test/resources/projects/functional/kotlin/generates_test_schema/groovy/src/test/groovy/acme/Model.groovy new file mode 100644 index 0000000..e52a717 --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_test_schema/groovy/src/test/groovy/acme/Model.groovy @@ -0,0 +1,26 @@ +/* + * Copyright 2022-2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme + +import org.creekservice.api.base.annotation.schema.GeneratesSchema + +@GeneratesSchema +class Model { + String getSomeProp() { + null + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/generates_test_schema/groovy/src/test/java/acme/ModelTest.java b/src/test/resources/projects/functional/kotlin/generates_test_schema/groovy/src/test/java/acme/ModelTest.java new file mode 100644 index 0000000..4ac6955 --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_test_schema/groovy/src/test/java/acme/ModelTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.junit.jupiter.api.Test; +import java.io.File; +import java.net.URL; +import java.nio.file.Path; + +class ModelTest { + + @Test + void shouldLoadSchemaAsResource() { + final Path path = Path.of(File.separator, "schema", "json", "acme.model.yml"); + final URL resource = ModelTest.class.getResource(path.toString()); + System.out.println(path + " -> " + resource); + if (resource == null) { + throw new AssertionError("resource not found: " + path); + } + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/generates_test_schema/java-module/build.gradle.kts b/src/test/resources/projects/functional/kotlin/generates_test_schema/java-module/build.gradle.kts new file mode 100644 index 0000000..6a6592a --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_test_schema/java-module/build.gradle.kts @@ -0,0 +1,35 @@ +/* + * Copyright 2022-2024 Creek Contributors (https://github.com/creek-service) + * + * 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. + */ +plugins { + id("org.creekservice.schema.json") + `java-library` +} + +dependencies { + api("org.creekservice:creek-base-annotation:+") + implementation("com.google.guava:guava:31.1-jre") + + testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.1") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.1") +} + +tasks.test { + useJUnitPlatform() +} + +creek.schema.json { + typeScanning.moduleWhiteList.set(listOf("acme.models")) +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/generates_test_schema/java-module/expected/acme.model.yml b/src/test/resources/projects/functional/kotlin/generates_test_schema/java-module/expected/acme.model.yml new file mode 100644 index 0000000..e0b859a --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_test_schema/java-module/expected/acme.model.yml @@ -0,0 +1,8 @@ +--- +$schema: http://json-schema.org/draft-07/schema# +title: Model +type: object +additionalProperties: false +properties: + someProp: + type: string diff --git a/src/test/resources/projects/functional/kotlin/generates_test_schema/java-module/src/main/java/acme/Other.java b/src/test/resources/projects/functional/kotlin/generates_test_schema/java-module/src/main/java/acme/Other.java new file mode 100644 index 0000000..8dc9caf --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_test_schema/java-module/src/main/java/acme/Other.java @@ -0,0 +1,33 @@ +/* + * Copyright 2022-2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import com.google.common.base.Preconditions; +import org.creekservice.api.base.annotation.schema.GeneratesSchema; + +@GeneratesSchema +public final class Other { + + public Other(final String s) { + // Use dependency so that class would fail to load if dependencies were missing + Preconditions.checkArgument(s != null); + } + + public long getSomeProp() { + return 1L; + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/generates_test_schema/java-module/src/main/java/module-info.java b/src/test/resources/projects/functional/kotlin/generates_test_schema/java-module/src/main/java/module-info.java new file mode 100644 index 0000000..2a6160a --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_test_schema/java-module/src/main/java/module-info.java @@ -0,0 +1,6 @@ +module acme.models { + requires transitive creek.base.annotation; + requires com.google.common; + + exports acme; +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/generates_test_schema/java-module/src/test/java/acme/Model.java b/src/test/resources/projects/functional/kotlin/generates_test_schema/java-module/src/test/java/acme/Model.java new file mode 100644 index 0000000..9a11c24 --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_test_schema/java-module/src/test/java/acme/Model.java @@ -0,0 +1,33 @@ +/* + * Copyright 2022-2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import com.google.common.base.Preconditions; +import org.creekservice.api.base.annotation.schema.GeneratesSchema; + +@GeneratesSchema +public final class Model { + + public Model(final String s) { + // Use dependency so that class would fail to load if dependencies were missing + Preconditions.checkArgument(s != null); + } + + public String getSomeProp() { + return null; + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/generates_test_schema/java-module/src/test/java/acme/ModelTest.java b/src/test/resources/projects/functional/kotlin/generates_test_schema/java-module/src/test/java/acme/ModelTest.java new file mode 100644 index 0000000..4ac6955 --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_test_schema/java-module/src/test/java/acme/ModelTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.junit.jupiter.api.Test; +import java.io.File; +import java.net.URL; +import java.nio.file.Path; + +class ModelTest { + + @Test + void shouldLoadSchemaAsResource() { + final Path path = Path.of(File.separator, "schema", "json", "acme.model.yml"); + final URL resource = ModelTest.class.getResource(path.toString()); + System.out.println(path + " -> " + resource); + if (resource == null) { + throw new AssertionError("resource not found: " + path); + } + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/generates_test_schema/java/build.gradle.kts b/src/test/resources/projects/functional/kotlin/generates_test_schema/java/build.gradle.kts new file mode 100644 index 0000000..40527b5 --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_test_schema/java/build.gradle.kts @@ -0,0 +1,32 @@ +/* + * Copyright 2022-2024 Creek Contributors (https://github.com/creek-service) + * + * 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. + */ + +plugins { + id("org.creekservice.schema.json") + `java-library` +} + +dependencies { + api("org.creekservice:creek-base-annotation:+") + implementation("com.google.guava:guava:31.1-jre") + + testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.1") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.1") +} + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/generates_test_schema/java/expected/acme.model.yml b/src/test/resources/projects/functional/kotlin/generates_test_schema/java/expected/acme.model.yml new file mode 100644 index 0000000..e0b859a --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_test_schema/java/expected/acme.model.yml @@ -0,0 +1,8 @@ +--- +$schema: http://json-schema.org/draft-07/schema# +title: Model +type: object +additionalProperties: false +properties: + someProp: + type: string diff --git a/src/test/resources/projects/functional/kotlin/generates_test_schema/java/src/test/java/acme/Model.java b/src/test/resources/projects/functional/kotlin/generates_test_schema/java/src/test/java/acme/Model.java new file mode 100644 index 0000000..9a11c24 --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_test_schema/java/src/test/java/acme/Model.java @@ -0,0 +1,33 @@ +/* + * Copyright 2022-2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import com.google.common.base.Preconditions; +import org.creekservice.api.base.annotation.schema.GeneratesSchema; + +@GeneratesSchema +public final class Model { + + public Model(final String s) { + // Use dependency so that class would fail to load if dependencies were missing + Preconditions.checkArgument(s != null); + } + + public String getSomeProp() { + return null; + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/generates_test_schema/java/src/test/java/acme/ModelTest.java b/src/test/resources/projects/functional/kotlin/generates_test_schema/java/src/test/java/acme/ModelTest.java new file mode 100644 index 0000000..4ac6955 --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_test_schema/java/src/test/java/acme/ModelTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.junit.jupiter.api.Test; +import java.io.File; +import java.net.URL; +import java.nio.file.Path; + +class ModelTest { + + @Test + void shouldLoadSchemaAsResource() { + final Path path = Path.of(File.separator, "schema", "json", "acme.model.yml"); + final URL resource = ModelTest.class.getResource(path.toString()); + System.out.println(path + " -> " + resource); + if (resource == null) { + throw new AssertionError("resource not found: " + path); + } + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/generates_test_schema/kotlin/build.gradle.kts b/src/test/resources/projects/functional/kotlin/generates_test_schema/kotlin/build.gradle.kts new file mode 100644 index 0000000..7d1a551 --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_test_schema/kotlin/build.gradle.kts @@ -0,0 +1,34 @@ +/* + * Copyright 2022-2024 Creek Contributors (https://github.com/creek-service) + * + * 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. + */ + +plugins { + id("org.creekservice.schema.json") + id("org.jetbrains.kotlin.jvm") version "1.6.21" + `java-library` +} + +dependencies { + implementation(platform("org.jetbrains.kotlin:kotlin-bom")) + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + implementation("org.creekservice:creek-base-annotation:+") + + testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.1") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.1") +} + +tasks.test { + useJUnitPlatform() +} diff --git a/src/test/resources/projects/functional/kotlin/generates_test_schema/kotlin/expected/acme.model.yml b/src/test/resources/projects/functional/kotlin/generates_test_schema/kotlin/expected/acme.model.yml new file mode 100644 index 0000000..e0b859a --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_test_schema/kotlin/expected/acme.model.yml @@ -0,0 +1,8 @@ +--- +$schema: http://json-schema.org/draft-07/schema# +title: Model +type: object +additionalProperties: false +properties: + someProp: + type: string diff --git a/src/test/resources/projects/functional/kotlin/generates_test_schema/kotlin/src/test/java/acme/ModelTest.java b/src/test/resources/projects/functional/kotlin/generates_test_schema/kotlin/src/test/java/acme/ModelTest.java new file mode 100644 index 0000000..4ac6955 --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_test_schema/kotlin/src/test/java/acme/ModelTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme; + +import org.junit.jupiter.api.Test; +import java.io.File; +import java.net.URL; +import java.nio.file.Path; + +class ModelTest { + + @Test + void shouldLoadSchemaAsResource() { + final Path path = Path.of(File.separator, "schema", "json", "acme.model.yml"); + final URL resource = ModelTest.class.getResource(path.toString()); + System.out.println(path + " -> " + resource); + if (resource == null) { + throw new AssertionError("resource not found: " + path); + } + } +} \ No newline at end of file diff --git a/src/test/resources/projects/functional/kotlin/generates_test_schema/kotlin/src/test/kotlin/acme/Model.kt b/src/test/resources/projects/functional/kotlin/generates_test_schema/kotlin/src/test/kotlin/acme/Model.kt new file mode 100644 index 0000000..fa4e18f --- /dev/null +++ b/src/test/resources/projects/functional/kotlin/generates_test_schema/kotlin/src/test/kotlin/acme/Model.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2023-2024 Creek Contributors (https://github.com/creek-service) + * + * 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 acme + +import org.creekservice.api.base.annotation.schema.GeneratesSchema + +@Suppress("unused") +@GeneratesSchema +class Model { + var someProp: String? = null +} \ No newline at end of file