Skip to content

Commit

Permalink
Allow URL(s) as source in jsonschema2pojo-gradle-plugin
Browse files Browse the repository at this point in the history
Closes #1010
  • Loading branch information
unkish committed Sep 18, 2023
1 parent 72050f6 commit a68742e
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 30 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions jsonschema2pojo-gradle-plugin/example/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
38 changes: 35 additions & 3 deletions jsonschema2pojo-gradle-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
</dependency>
</dependencies>

<properties>
<integrationTestSourceDirectory>src/integrationTest/groovy</integrationTestSourceDirectory>
</properties>

<build>
<sourceDirectory>${project.basedir}/src/main/groovy</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/groovy</testSourceDirectory>
Expand Down Expand Up @@ -75,6 +79,18 @@
</sources>
</configuration>
</execution>
<execution>
<id>add-integration-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${integrationTestSourceDirectory}</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down Expand Up @@ -116,11 +132,27 @@
<include>**/*Spec.*</include>
</includes>
</configuration>
</plugin>
<plugin>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<useFile>false</useFile>
<testSourceDirectory>${integrationTestSourceDirectory}</testSourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>codenarc-maven-plugin</artifactId>
</plugin>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -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()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> ignoredProperties = new HashSet<String>() {{
add("sourceFiles");
Expand All @@ -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()
}
}
}

0 comments on commit a68742e

Please sign in to comment.