-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bug][maven] Fix custom windows classpaths in maven plugin (#7587)
* [maven] Fallback to templates using classpath rather than OS-specific paths Previous checks would cause logic in Windows to return early, for built-in templates only. This reorganizes and simplifies the ordering behavior. * Match classpath check in WorkflowSettings with that in TemplateManager * [maven] Much needed unit/integration tests This follows similar approach used in PMD and other plugins managed by maven. Unit tests simply verify we can load configuration as expected into the Mojo. Integration tests execute actual sample projects bound to the current build's Maven plugin. This uses maven-invoker-plugin, which also allows for specifying the maven options in invoker.properties to execute the test. It also provides a verification framework using groovy files with the required naming convention of "verify.groovy". This allows us to quickly and easily check that certain files are outputted by generation, and we may also spotcheck file contents. templateResourcePath option is skipped on windows. I've tested back to version 3.3.3 and this doesn't seem to have worked consistently with how the property works on non-Windows. * Set groovy 3.0.5 for test harness * Print stacktrace on Maven error in Travis * [maven] Set groovy version in tests to supported in Java 11+ * Puts maven integration tests in separate profile called 'integration'
- Loading branch information
1 parent
34d2e25
commit ee1cbf6
Showing
21 changed files
with
1,518 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
modules/openapi-generator-maven-plugin/examples/templates/README.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# TEST TEST TEST | ||
|
||
# {{artifactId}} | ||
|
||
{{appName}} | ||
|
||
- API version: {{appVersion}} | ||
{{^hideGenerationTimestamp}} | ||
|
||
- Build date: {{generatedDate}} | ||
{{/hideGenerationTimestamp}} | ||
|
||
{{#appDescriptionWithNewLines}}{{{appDescriptionWithNewLines}}}{{/appDescriptionWithNewLines}} | ||
|
||
{{#infoUrl}} | ||
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) | ||
{{/infoUrl}} | ||
|
||
*Automatically generated by the [OpenAPI Generator](https://openapi-generator.tech)* | ||
|
||
… etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
modules/openapi-generator-maven-plugin/src/it/custom-template-resource/invoker.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
invoker.goals = -nsu generate-sources | ||
invoker.name = Test Custom Templates via Resource |
57 changes: 57 additions & 0 deletions
57
modules/openapi-generator-maven-plugin/src/it/custom-template-resource/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2020 OpenAPI-Generator Contributors (https://openapi-generator.tech) | ||
~ | ||
~ 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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.openapitools.maven.its</groupId> | ||
<artifactId>custom-template-resource</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>@project.groupId@</groupId> | ||
<artifactId>@project.artifactId@</artifactId> | ||
<version>@project.version@</version> | ||
<configuration> | ||
<inputSpec>https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml</inputSpec> | ||
<generatorName>kotlin</generatorName> | ||
<output>${basedir}/out</output> | ||
<!-- | ||
HACK: rather than compile our own resource, we'll pull from something that's already available: bash generator's templates | ||
This only works because bash shares only README.mustache template with kotlin | ||
--> | ||
<templateResourcePath>bash</templateResourcePath> | ||
<configOptions> | ||
<serializableModel>true</serializableModel> | ||
</configOptions> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>default</id> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>generate</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
39 changes: 39 additions & 0 deletions
39
modules/openapi-generator-maven-plugin/src/it/custom-template-resource/verify.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2020 OpenAPI-Generator Contributors (https://openapi-generator.tech) | ||
* | ||
* 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. | ||
*/ | ||
|
||
File readme = new File(basedir, "out/README.md") | ||
|
||
assert readme.isFile() | ||
if (File.separator == "/") { | ||
// For whatever reason, resource path templates fail in this test in Windows | ||
assert readme.text.contains("# OpenAPI Petstore Bash client") | ||
} | ||
|
||
File gradle = new File(basedir, "out/build.gradle") | ||
assert gradle.isFile() | ||
|
||
File api = new File(basedir, "out/src/main/kotlin/org/openapitools/client/apis/PetApi.kt") | ||
assert api.isFile() | ||
|
||
File model = new File(basedir, "out/src/main/kotlin/org/openapitools/client/models/Pet.kt") | ||
assert model.isFile() | ||
|
||
// note that in Java 11+, this anything matching this condition could fail due to | ||
// Illegal reflective access by org.codehaus.groovy.reflection.CachedClass | ||
// and cause tests to fail. This is more to document for engineers. | ||
if (GroovySystem.version.tokenize('.')[0].toInteger() < 3) { | ||
throw new IllegalStateException("Found:" + GroovySystem.version + ", need Groovy 3.x or higher for Java 11+, so we require it for all versions") | ||
} |
2 changes: 2 additions & 0 deletions
2
modules/openapi-generator-maven-plugin/src/it/custom-template/invoker.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
invoker.goals = -nsu generate-sources | ||
invoker.name = Test Custom Templates |
53 changes: 53 additions & 0 deletions
53
modules/openapi-generator-maven-plugin/src/it/custom-template/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2020 OpenAPI-Generator Contributors (https://openapi-generator.tech) | ||
~ | ||
~ 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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.openapitools.maven.its</groupId> | ||
<artifactId>custom-template</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>@project.groupId@</groupId> | ||
<artifactId>@project.artifactId@</artifactId> | ||
<version>@project.version@</version> | ||
<configuration> | ||
<inputSpec>https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml</inputSpec> | ||
<generatorName>kotlin</generatorName> | ||
<output>${basedir}/out</output> | ||
<templateDirectory>${project.basedir}/templates</templateDirectory> | ||
<configOptions> | ||
<serializableModel>true</serializableModel> | ||
</configOptions> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>remote</id> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>generate</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
21 changes: 21 additions & 0 deletions
21
modules/openapi-generator-maven-plugin/src/it/custom-template/templates/README.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# TEST TEST TEST | ||
|
||
# {{artifactId}} | ||
|
||
{{appName}} | ||
|
||
- API version: {{appVersion}} | ||
{{^hideGenerationTimestamp}} | ||
|
||
- Build date: {{generatedDate}} | ||
{{/hideGenerationTimestamp}} | ||
|
||
{{#appDescriptionWithNewLines}}{{{appDescriptionWithNewLines}}}{{/appDescriptionWithNewLines}} | ||
|
||
{{#infoUrl}} | ||
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) | ||
{{/infoUrl}} | ||
|
||
*Automatically generated by the [OpenAPI Generator](https://openapi-generator.tech)* | ||
|
||
… etc. |
38 changes: 38 additions & 0 deletions
38
modules/openapi-generator-maven-plugin/src/it/custom-template/verify.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2020 OpenAPI-Generator Contributors (https://openapi-generator.tech) | ||
* | ||
* 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. | ||
*/ | ||
|
||
File readme = new File(basedir, "out/README.md") | ||
|
||
assert readme.isFile() | ||
assert readme.text.contains("# TEST TEST TEST") | ||
assert readme.text.contains("# kotlin-client") | ||
assert readme.text.contains("OpenAPI Petstore") | ||
|
||
File gradle = new File(basedir, "out/build.gradle") | ||
assert gradle.isFile() | ||
|
||
File api = new File(basedir, "out/src/main/kotlin/org/openapitools/client/apis/PetApi.kt") | ||
assert api.isFile() | ||
|
||
File model = new File(basedir, "out/src/main/kotlin/org/openapitools/client/models/Pet.kt") | ||
assert model.isFile() | ||
|
||
// note that in Java 11+, this anything matching this condition could fail due to | ||
// Illegal reflective access by org.codehaus.groovy.reflection.CachedClass | ||
// and cause tests to fail. This is more to document for engineers. | ||
if (GroovySystem.version.tokenize('.')[0].toInteger() < 3) { | ||
throw new IllegalStateException("Found:" + GroovySystem.version + ", need Groovy 3.x or higher for Java 11+, so we require it for all versions") | ||
} |
Oops, something went wrong.