diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e66182b1..97ec12e66 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,3 +28,7 @@ jobs: maven-version: 3.8.7 - name: Verify with Maven run: mvn verify -B + - name: Verify jsonschema2pojo-gradle-plugin integration tests + run: | + mvn -U -B install -DskipTests -Dmaven.javadoc.skip -Dmaven.site.skip -pl jsonschema2pojo-gradle-plugin -am + mvn -U -B install -pl jsonschema2pojo-gradle-plugin diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/BuilderRule.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/BuilderRule.java index d64234b15..5695ed2e4 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/BuilderRule.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/BuilderRule.java @@ -110,7 +110,7 @@ public JDefinedClass apply(String nodeName, JsonNode node, JsonNode parent, JDef generateNoArgsBuilderConstructors(instanceClass, builderClass, concreteBuilderClass); } - JMethod builderMethod = instanceClass.method(JMod.PUBLIC + JMod.STATIC, builderClass, "builder"); + JMethod builderMethod = instanceClass.method(JMod.PUBLIC + JMod.STATIC, builderClass.narrow(instanceClass.wildcard()), "builder"); JBlock builderBody = builderMethod.body(); builderBody._return(JExpr._new(concreteBuilderClass)); diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/PropertyRule.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/PropertyRule.java index 9bb0ecb72..79a70b99b 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/PropertyRule.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/PropertyRule.java @@ -290,7 +290,7 @@ private JMethod addLegacyBuilder(JDefinedClass c, JFieldVar field, String jsonPr private JMethod addInnerBuilderMethod(JDefinedClass c, JFieldVar field, String jsonPropertyName, JsonNode node) { JDefinedClass builderClass = ruleFactory.getReflectionHelper().getBaseBuilderClass(c); - JMethod builderMethod = builderClass.method(JMod.PUBLIC, builderClass, getBuilderName(jsonPropertyName, node)); + JMethod builderMethod = builderClass.method(JMod.PUBLIC, builderClass.narrow(builderClass.typeParams()), getBuilderName(jsonPropertyName, node)); JVar param = builderMethod.param(field.type(), field.name()); JBlock body = builderMethod.body(); diff --git a/jsonschema2pojo-gradle-plugin/example/java/build.gradle b/jsonschema2pojo-gradle-plugin/example/java/build.gradle index 8f1bf4031..ae8644dca 100644 --- a/jsonschema2pojo-gradle-plugin/example/java/build.gradle +++ b/jsonschema2pojo-gradle-plugin/example/java/build.gradle @@ -29,6 +29,11 @@ dependencies { } jsonSchema2Pojo { + // omitting 'source' will force plugin to look for sources under ${project.sourceSets.main.output.resourcesDir}/json + source = [ + 'https://raw.githubusercontent.com/joelittlejohn/jsonschema2pojo/master/jsonschema2pojo-integration-tests/src/test/resources/schema/ref/recursiveTreeNode.json', + file("src/main/resources/json") + ] targetPackage = 'example' includeJsr303Annotations = true propertyWordDelimiters = ['_'] as char[] diff --git a/jsonschema2pojo-gradle-plugin/pom.xml b/jsonschema2pojo-gradle-plugin/pom.xml index 40c97af40..9ed215eaf 100644 --- a/jsonschema2pojo-gradle-plugin/pom.xml +++ b/jsonschema2pojo-gradle-plugin/pom.xml @@ -43,6 +43,10 @@ + + src/integrationTest/groovy + + ${project.basedir}/src/main/groovy ${project.basedir}/src/test/groovy @@ -75,6 +79,18 @@ + + add-integration-test-sources + generate-test-sources + + add-test-source + + + + ${integrationTestSourceDirectory} + + + @@ -116,11 +132,27 @@ **/*Spec.* - - + + + maven-failsafe-plugin + + + install + + integration-test + verify + + + + + false + ${integrationTestSourceDirectory} + + + org.codehaus.mojo codenarc-maven-plugin - + diff --git a/jsonschema2pojo-gradle-plugin/src/integrationTest/groovy/org/jsonschema2pojo/gradle/GradleBuildIT.groovy b/jsonschema2pojo-gradle-plugin/src/integrationTest/groovy/org/jsonschema2pojo/gradle/GradleBuildIT.groovy new file mode 100644 index 000000000..9a2a2c361 --- /dev/null +++ b/jsonschema2pojo-gradle-plugin/src/integrationTest/groovy/org/jsonschema2pojo/gradle/GradleBuildIT.groovy @@ -0,0 +1,47 @@ +/** + * Copyright © 2010-2014 Nokia + * + * 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 org.jsonschema2pojo.gradle + +import org.gradle.tooling.BuildLauncher +import org.gradle.tooling.GradleConnector +import org.gradle.tooling.ProjectConnection +import org.junit.Test + +class GradleBuildIT { + + @Test + void java() { + build("example/java"); + } + + void build(String projectDir) { + GradleConnector connector = GradleConnector.newConnector() + connector.useGradleVersion("5.6") + connector.forProjectDirectory(new File(projectDir)) + ProjectConnection connection = connector.connect() + try { + BuildLauncher launcher = connection.newBuild() + launcher.setStandardOutput(System.out); + launcher.setStandardError(System.err); + launcher.forTasks("build") + launcher.addArguments("--stacktrace") + launcher.run() + } finally { + connection.close() + } + } + +} diff --git a/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/GenerateJsonSchemaJavaTask.groovy b/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/GenerateJsonSchemaJavaTask.groovy index 12997fbc0..e7f0f937e 100644 --- a/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/GenerateJsonSchemaJavaTask.groovy +++ b/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/GenerateJsonSchemaJavaTask.groovy @@ -56,7 +56,7 @@ class GenerateJsonSchemaJavaTask extends DefaultTask { setTargetVersion configuration inputs.property("configuration", configuration.toString()) - inputs.files project.files(configuration.sourceFiles) + inputs.files project.files(configuration.source.findAll { 'file'.equals(it.protocol) }) } } diff --git a/jsonschema2pojo-gradle-plugin/src/test/groovy/org/jsonschema2pojo/gradle/JsonSchemaPluginSpec.groovy b/jsonschema2pojo-gradle-plugin/src/test/groovy/org/jsonschema2pojo/gradle/JsonSchemaPluginSpec.groovy index 5878a7137..699252d5d 100644 --- a/jsonschema2pojo-gradle-plugin/src/test/groovy/org/jsonschema2pojo/gradle/JsonSchemaPluginSpec.groovy +++ b/jsonschema2pojo-gradle-plugin/src/test/groovy/org/jsonschema2pojo/gradle/JsonSchemaPluginSpec.groovy @@ -16,22 +16,18 @@ package org.jsonschema2pojo.gradle import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.Matchers.*; import java.lang.reflect.Field +import java.nio.charset.StandardCharsets import org.apache.commons.io.FileUtils -import org.gradle.tooling.BuildLauncher -import org.gradle.tooling.GradleConnector -import org.gradle.tooling.ProjectConnection -import org.jsonschema2pojo.gradle.JsonSchemaExtension import org.junit.Test class JsonSchemaPluginSpec { @Test void documentationIncludesAllProperties() { - String documentation = FileUtils.readFileToString(new File("README.md")); + String documentation = FileUtils.readFileToString(new File("README.md"), StandardCharsets.UTF_8); Set ignoredProperties = new HashSet() {{ add("sourceFiles"); @@ -52,24 +48,4 @@ class JsonSchemaPluginSpec { assertThat(missingProperties.toString(), missingProperties.isEmpty()) } - @Test - void java() { - build("example/java"); - } - - void build(String projectDir) { - GradleConnector connector = GradleConnector.newConnector() - connector.useGradleVersion("5.6") - connector.forProjectDirectory(new File(projectDir)) - ProjectConnection connection = connector.connect() - try { - BuildLauncher launcher = connection.newBuild() - launcher.setStandardOutput(System.out); - launcher.setStandardError(System.err); - launcher.forTasks("build") - launcher.run() - } finally { - connection.close() - } - } }