Skip to content

Commit 1476474

Browse files
authoredSep 22, 2024··
Allow URL(s) as source in jsonschema2pojo-gradle-plugin (#1554)
Closes #1010
1 parent a8881a3 commit 1476474

File tree

6 files changed

+94
-30
lines changed

6 files changed

+94
-30
lines changed
 

‎.github/workflows/ci.yml

+4
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ jobs:
2828
maven-version: 3.8.7
2929
- name: Verify with Maven
3030
run: mvn verify -B
31+
- name: Verify jsonschema2pojo-gradle-plugin integration tests
32+
run: |
33+
mvn -U -B install -DskipTests -Dmaven.javadoc.skip -Dmaven.site.skip -pl jsonschema2pojo-gradle-plugin -am
34+
mvn -U -B install -pl jsonschema2pojo-gradle-plugin

‎jsonschema2pojo-gradle-plugin/example/java/build.gradle

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ dependencies {
2929
}
3030

3131
jsonSchema2Pojo {
32+
// omitting 'source' will force plugin to look for sources under ${project.sourceSets.main.output.resourcesDir}/json
33+
source = [
34+
'https://raw.githubusercontent.com/joelittlejohn/jsonschema2pojo/master/jsonschema2pojo-integration-tests/src/test/resources/schema/ref/recursiveTreeNode.json',
35+
file("src/main/resources/json")
36+
]
3237
targetPackage = 'example'
3338
includeJsr303Annotations = true
3439
propertyWordDelimiters = ['_'] as char[]

‎jsonschema2pojo-gradle-plugin/pom.xml

+35-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
</dependency>
4444
</dependencies>
4545

46+
<properties>
47+
<integrationTestSourceDirectory>src/integrationTest/groovy</integrationTestSourceDirectory>
48+
</properties>
49+
4650
<build>
4751
<sourceDirectory>${project.basedir}/src/main/groovy</sourceDirectory>
4852
<testSourceDirectory>${project.basedir}/src/test/groovy</testSourceDirectory>
@@ -75,6 +79,18 @@
7579
</sources>
7680
</configuration>
7781
</execution>
82+
<execution>
83+
<id>add-integration-test-sources</id>
84+
<phase>generate-test-sources</phase>
85+
<goals>
86+
<goal>add-test-source</goal>
87+
</goals>
88+
<configuration>
89+
<sources>
90+
<source>${integrationTestSourceDirectory}</source>
91+
</sources>
92+
</configuration>
93+
</execution>
7894
</executions>
7995
</plugin>
8096
<plugin>
@@ -116,11 +132,27 @@
116132
<include>**/*Spec.*</include>
117133
</includes>
118134
</configuration>
119-
</plugin>
120-
<plugin>
135+
</plugin>
136+
<plugin>
137+
<artifactId>maven-failsafe-plugin</artifactId>
138+
<executions>
139+
<execution>
140+
<phase>install</phase>
141+
<goals>
142+
<goal>integration-test</goal>
143+
<goal>verify</goal>
144+
</goals>
145+
</execution>
146+
</executions>
147+
<configuration>
148+
<useFile>false</useFile>
149+
<testSourceDirectory>${integrationTestSourceDirectory}</testSourceDirectory>
150+
</configuration>
151+
</plugin>
152+
<plugin>
121153
<groupId>org.codehaus.mojo</groupId>
122154
<artifactId>codenarc-maven-plugin</artifactId>
123-
</plugin>
155+
</plugin>
124156
</plugins>
125157
</build>
126158
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright © 2010-2014 Nokia
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.jsonschema2pojo.gradle
17+
18+
import org.gradle.tooling.BuildLauncher
19+
import org.gradle.tooling.GradleConnector
20+
import org.gradle.tooling.ProjectConnection
21+
import org.junit.Test
22+
23+
class GradleBuildIT {
24+
25+
@Test
26+
void java() {
27+
build("example/java");
28+
}
29+
30+
void build(String projectDir) {
31+
GradleConnector connector = GradleConnector.newConnector()
32+
connector.useGradleVersion("5.6")
33+
connector.forProjectDirectory(new File(projectDir))
34+
ProjectConnection connection = connector.connect()
35+
try {
36+
BuildLauncher launcher = connection.newBuild()
37+
launcher.setStandardOutput(System.out);
38+
launcher.setStandardError(System.err);
39+
launcher.forTasks("build")
40+
launcher.addArguments("--stacktrace")
41+
launcher.run()
42+
} finally {
43+
connection.close()
44+
}
45+
}
46+
47+
}

‎jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/GenerateJsonSchemaJavaTask.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class GenerateJsonSchemaJavaTask extends DefaultTask {
5656
setTargetVersion configuration
5757

5858
inputs.property("configuration", configuration.toString())
59-
inputs.files project.files(configuration.sourceFiles)
59+
inputs.files project.files(configuration.source.findAll { 'file'.equals(it.protocol) })
6060
}
6161
}
6262

‎jsonschema2pojo-gradle-plugin/src/test/groovy/org/jsonschema2pojo/gradle/JsonSchemaPluginSpec.groovy

+2-26
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,18 @@
1616
package org.jsonschema2pojo.gradle
1717

1818
import static org.hamcrest.MatcherAssert.*;
19-
import static org.hamcrest.Matchers.*;
2019

2120
import java.lang.reflect.Field
21+
import java.nio.charset.StandardCharsets
2222

2323
import org.apache.commons.io.FileUtils
24-
import org.gradle.tooling.BuildLauncher
25-
import org.gradle.tooling.GradleConnector
26-
import org.gradle.tooling.ProjectConnection
27-
import org.jsonschema2pojo.gradle.JsonSchemaExtension
2824
import org.junit.Test
2925

3026
class JsonSchemaPluginSpec {
3127

3228
@Test
3329
void documentationIncludesAllProperties() {
34-
String documentation = FileUtils.readFileToString(new File("README.md"));
30+
String documentation = FileUtils.readFileToString(new File("README.md"), StandardCharsets.UTF_8);
3531

3632
Set<String> ignoredProperties = new HashSet<String>() {{
3733
add("sourceFiles");
@@ -52,24 +48,4 @@ class JsonSchemaPluginSpec {
5248
assertThat(missingProperties.toString(), missingProperties.isEmpty())
5349
}
5450

55-
@Test
56-
void java() {
57-
build("example/java");
58-
}
59-
60-
void build(String projectDir) {
61-
GradleConnector connector = GradleConnector.newConnector()
62-
connector.useGradleVersion("5.6")
63-
connector.forProjectDirectory(new File(projectDir))
64-
ProjectConnection connection = connector.connect()
65-
try {
66-
BuildLauncher launcher = connection.newBuild()
67-
launcher.setStandardOutput(System.out);
68-
launcher.setStandardError(System.err);
69-
launcher.forTasks("build")
70-
launcher.run()
71-
} finally {
72-
connection.close()
73-
}
74-
}
7551
}

0 commit comments

Comments
 (0)