Skip to content

Commit 5e42868

Browse files
committed
[breaking] Rename system properties to global properties
1 parent 0f5fd3a commit 5e42868

File tree

14 files changed

+60
-125
lines changed

14 files changed

+60
-125
lines changed

modules/openapi-generator-cli/src/main/java/org/openapitools/codegen/cmd/Generate.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ public class Generate extends OpenApiGeneratorCommand {
7171
+ "Pass in a URL-encoded string of name:header with a comma separating multiple values")
7272
private String auth;
7373

74-
// TODO: Remove -D short option in 5.0
7574
@Option(
76-
name = {"-D", "--global-property"},
75+
name = {"--global-property"},
7776
title = "global properties",
7877
description = "sets specified global properties (previously called 'system properties') in "
7978
+ "the format of name=value,name=value (or multiple options, each with name=value)")

modules/openapi-generator-core/src/main/java/org/openapitools/codegen/config/WorkflowSettings.java

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class WorkflowSettings {
4747
public static final boolean DEFAULT_ENABLE_MINIMAL_UPDATE = false;
4848
public static final boolean DEFAULT_STRICT_SPEC_BEHAVIOR = true;
4949
public static final String DEFAULT_TEMPLATING_ENGINE_NAME = "mustache";
50-
public static final ImmutableMap<String, String> DEFAULT_SYSTEM_PROPERTIES = ImmutableMap.of();
50+
public static final ImmutableMap<String, String> DEFAULT_GLOBAL_PROPERTIES = ImmutableMap.of();
5151

5252
private String inputSpec;
5353
private String outputDir = DEFAULT_OUTPUT_DIR;
@@ -62,7 +62,7 @@ public class WorkflowSettings {
6262
private String templateDir;
6363
private String templatingEngineName = DEFAULT_TEMPLATING_ENGINE_NAME;
6464
private String ignoreFileOverride;
65-
private ImmutableMap<String, String> systemProperties = DEFAULT_SYSTEM_PROPERTIES;
65+
private ImmutableMap<String, String> globalProperties = DEFAULT_GLOBAL_PROPERTIES;
6666

6767
private WorkflowSettings(Builder builder) {
6868
this.inputSpec = builder.inputSpec;
@@ -78,15 +78,7 @@ private WorkflowSettings(Builder builder) {
7878
this.templateDir = builder.templateDir;
7979
this.templatingEngineName = builder.templatingEngineName;
8080
this.ignoreFileOverride = builder.ignoreFileOverride;
81-
// TODO: rename to globalProperties for 5.0
82-
this.systemProperties = ImmutableMap.copyOf(builder.systemProperties);
83-
if (this.systemProperties.size() > 0) {
84-
// write no more than every 5s. This is temporary until version 5.0 as once(Logger) is not accessible here.
85-
// thread contention may cause this to write more than once, but this is just an attempt to reduce noise
86-
if (System.currentTimeMillis() - lastWarning.getAndUpdate(x -> System.currentTimeMillis()) > 5000) {
87-
LOGGER.warn("systemProperties will be renamed to globalProperties in version 5.0");
88-
}
89-
}
81+
this.globalProperties = ImmutableMap.copyOf(builder.globalProperties);
9082
}
9183

9284
/**
@@ -117,7 +109,7 @@ public static Builder newBuilder(WorkflowSettings copy) {
117109
builder.ignoreFileOverride = copy.getIgnoreFileOverride();
118110

119111
// this, and any other collections, must be mutable in the builder.
120-
builder.systemProperties = new HashMap<>(copy.getSystemProperties());
112+
builder.globalProperties = new HashMap<>(copy.getGlobalProperties());
121113

122114
// force builder "with" methods to invoke side effects
123115
builder.withTemplateDir(copy.getTemplateDir());
@@ -264,8 +256,8 @@ public String getIgnoreFileOverride() {
264256
*
265257
* @return the system properties
266258
*/
267-
public Map<String, String> getSystemProperties() {
268-
return systemProperties;
259+
public Map<String, String> getGlobalProperties() {
260+
return globalProperties;
269261
}
270262

271263
/**
@@ -288,7 +280,7 @@ public static final class Builder {
288280
private String ignoreFileOverride;
289281

290282
// NOTE: All collections must be mutable in the builder, and copied to a new immutable collection in .build()
291-
private Map<String, String> systemProperties = new HashMap<>();;
283+
private Map<String, String> globalProperties = new HashMap<>();;
292284

293285
private Builder() {
294286
}
@@ -469,30 +461,30 @@ public Builder withIgnoreFileOverride(String ignoreFileOverride) {
469461
}
470462

471463
/**
472-
* Sets the {@code systemProperties} and returns a reference to this Builder so that the methods can be chained together.
464+
* Sets the {@code globalProperties} and returns a reference to this Builder so that the methods can be chained together.
473465
*
474-
* @param systemProperties the {@code systemProperties} to set
466+
* @param globalProperties the {@code globalProperties} to set
475467
* @return a reference to this Builder
476468
*/
477-
public Builder withSystemProperties(Map<String, String> systemProperties) {
478-
if (systemProperties != null) {
479-
this.systemProperties = systemProperties;
469+
public Builder withGlobalProperties(Map<String, String> globalProperties) {
470+
if (globalProperties != null) {
471+
this.globalProperties = globalProperties;
480472
}
481473
return this;
482474
}
483475

484476
/**
485-
* Sets the {@code systemProperties} and returns a reference to this Builder so that the methods can be chained together.
477+
* Sets the {@code globalProperties} and returns a reference to this Builder so that the methods can be chained together.
486478
*
487479
* @param key The key of a system (global) property to set
488480
* @param value The value of a system (global) property to set
489481
* @return a reference to this Builder
490482
*/
491-
public Builder withSystemProperty(String key, String value) {
492-
if (this.systemProperties == null) {
493-
this.systemProperties = new HashMap<>();
483+
public Builder withGlobalProperty(String key, String value) {
484+
if (this.globalProperties == null) {
485+
this.globalProperties = new HashMap<>();
494486
}
495-
this.systemProperties.put(key, value);
487+
this.globalProperties.put(key, value);
496488
return this;
497489
}
498490

@@ -526,7 +518,7 @@ public String toString() {
526518
", templateDir='" + templateDir + '\'' +
527519
", templatingEngineName='" + templatingEngineName + '\'' +
528520
", ignoreFileOverride='" + ignoreFileOverride + '\'' +
529-
", systemProperties=" + systemProperties +
521+
", globalProperties=" + globalProperties +
530522
'}';
531523
}
532524

@@ -548,7 +540,7 @@ public boolean equals(Object o) {
548540
Objects.equals(getTemplateDir(), that.getTemplateDir()) &&
549541
Objects.equals(getTemplatingEngineName(), that.getTemplatingEngineName()) &&
550542
Objects.equals(getIgnoreFileOverride(), that.getIgnoreFileOverride()) &&
551-
Objects.equals(getSystemProperties(), that.getSystemProperties());
543+
Objects.equals(getGlobalProperties(), that.getGlobalProperties());
552544
}
553545

554546
@Override
@@ -567,7 +559,7 @@ public int hashCode() {
567559
getTemplateDir(),
568560
getTemplatingEngineName(),
569561
getIgnoreFileOverride(),
570-
getSystemProperties()
562+
getGlobalProperties()
571563
);
572564
}
573565
}

modules/openapi-generator-core/src/test/java/org/openapitools/codegen/config/WorkflowSettingsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ public void defaultValuesNotOverriddenByNulls(){
5050
}
5151

5252
@Test
53-
public void newBuilderFromCopyShouldMutateSystemProperties(){
53+
public void newBuilderFromCopyShouldMutateGlobalProperties(){
5454
WorkflowSettings original = WorkflowSettings.newBuilder()
5555
.withOutputDir("output")
5656
.withVerbose(true)
5757
.withSkipOverwrite(false)
58-
.withSystemProperty("first", "1st")
58+
.withGlobalProperty("first", "1st")
5959
.build();
6060

6161
WorkflowSettings modified = WorkflowSettings.newBuilder(original)
62-
.withSystemProperty("second", "2nd")
62+
.withGlobalProperty("second", "2nd")
6363
.build();
6464

65-
Map<String, String> properties = modified.getSystemProperties();
65+
Map<String, String> properties = modified.getGlobalProperties();
6666
assertEquals(properties.size(), 2, "System Properties map should allow mutation when invoked via copy constructor");
6767
assertEquals(properties.getOrDefault("first", ""), "1st");
6868
assertEquals(properties.getOrDefault("second", ""), "2nd");

modules/openapi-generator-gradle-plugin/README.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ apply plugin: 'org.openapi.generator'
135135
|None
136136
|Adds authorization headers when fetching the OpenAPI definitions remotely. Pass in a URL-encoded string of name:header with a comma separating multiple values.
137137

138-
|systemProperties
138+
|globalProperties
139139
|Map(String,String)
140140
|None
141-
|Sets specified system properties.
141+
|Sets specified global properties.
142142

143143
|configFile
144144
|String
@@ -346,12 +346,12 @@ For more control over generation of individual files, configure an ignore file a
346346

347347
[NOTE]
348348
====
349-
When configuring `systemProperties` in order to perform selective generation you can disable generation of some parts by providing `"false"` value:
349+
When configuring `globalProperties` in order to perform selective generation you can disable generation of some parts by providing `"false"` value:
350350
[source,groovy]
351351
----
352352
openApiGenerate {
353353
// other settings omitted
354-
systemProperties = [
354+
globalProperties = [
355355
modelDocs: "false",
356356
apis: "false"
357357
]
@@ -362,7 +362,7 @@ When enabling generation of only specific parts you either have to provide CSV l
362362
----
363363
openApiGenerate {
364364
// other settings omitted
365-
systemProperties = [
365+
globalProperties = [
366366
apis: "",
367367
models: "User,Pet"
368368
]
@@ -609,7 +609,7 @@ task buildKotlinClient(type: org.openapitools.generator.gradle.plugin.tasks.Gene
609609
configOptions = [
610610
dateLibrary: "java8"
611611
]
612-
systemProperties = [
612+
globalProperties = [
613613
modelDocs: "false"
614614
]
615615
}

modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ openApiGenerate {
4242
configOptions = [
4343
dateLibrary: "java8"
4444
]
45-
systemProperties = [
45+
globalProperties = [
4646
modelDocs: "false"
4747
]
4848
skipValidateSpec = true
@@ -74,7 +74,7 @@ task buildDotnetSdk(type: org.openapitools.generator.gradle.plugin.tasks.Generat
7474
useCompareNetObjects: "true"
7575
]
7676
outputDir = "$buildDir/csharp-netcore".toString()
77-
systemProperties = [
77+
globalProperties = [
7878
models: "",
7979
apis : "",
8080
]

modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/OpenApiGeneratorPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
9898
inputSpec.set(generate.inputSpec)
9999
templateDir.set(generate.templateDir)
100100
auth.set(generate.auth)
101-
systemProperties.set(generate.systemProperties)
101+
globalProperties.set(generate.globalProperties)
102102
configFile.set(generate.configFile)
103103
skipOverwrite.set(generate.skipOverwrite)
104104
packageName.set(generate.packageName)

modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorGenerateExtension.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
6565
val auth = project.objects.property<String>()
6666

6767
/**
68-
* Sets specified system properties.
68+
* Sets specified global properties.
6969
*/
70-
val systemProperties = project.objects.mapProperty<String, String>()
70+
val globalProperties = project.objects.mapProperty<String, String>()
7171

7272
/**
7373
* Path to json configuration file.

modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ open class GenerateTask : DefaultTask() {
9797
val auth = project.objects.property<String>()
9898

9999
/**
100-
* Sets specified system properties.
100+
* Sets specified global properties.
101101
*/
102102
@get:Internal
103-
val systemProperties = project.objects.mapProperty<String, String>()
103+
val globalProperties = project.objects.mapProperty<String, String>()
104104

105105
/**
106106
* Path to json configuration file.
@@ -415,9 +415,9 @@ open class GenerateTask : DefaultTask() {
415415
} else CodegenConfigurator()
416416

417417
try {
418-
if (systemProperties.isPresent) {
419-
systemProperties.get().forEach { (key, value) ->
420-
configurator.addSystemProperty(key, value)
418+
if (globalProperties.isPresent) {
419+
globalProperties.get().forEach { (key, value) ->
420+
configurator.addGlobalProperty(key, value)
421421
}
422422
}
423423

@@ -582,10 +582,9 @@ open class GenerateTask : DefaultTask() {
582582
}
583583
}
584584

585-
if (systemProperties.isPresent) {
586-
// TODO: rename to globalProperties in 5.0
587-
systemProperties.get().forEach { entry ->
588-
configurator.addSystemProperty(entry.key, entry.value)
585+
if (globalProperties.isPresent) {
586+
globalProperties.get().forEach { entry ->
587+
configurator.addGlobalProperty(entry.key, entry.value)
589588
}
590589
}
591590

modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,6 @@ public class CodeGenMojo extends AbstractMojo {
8585
@Parameter(name = "verbose", defaultValue = "false")
8686
private boolean verbose;
8787

88-
// TODO: 5.0 Remove `language` option.
89-
/**
90-
* Client language to generate.
91-
*/
92-
@Parameter(name = "language")
93-
private String language;
94-
95-
9688
/**
9789
* The name of the generator to use.
9890
*/
@@ -538,20 +530,8 @@ public void execute() throws MojoExecutionException {
538530
configurator.setGenerateAliasAsModel(generateAliasAsModel);
539531
}
540532

541-
// TODO: After 3.0.0 release (maybe for 3.1.0): Fully deprecate lang.
542533
if (isNotEmpty(generatorName)) {
543534
configurator.setGeneratorName(generatorName);
544-
545-
// check if generatorName & language are set together, inform user this needs to be updated to prevent future issues.
546-
if (isNotEmpty(language)) {
547-
LOGGER.warn("The 'language' option is deprecated and was replaced by 'generatorName'. Both can not be set together");
548-
throw new MojoExecutionException(
549-
"Illegal configuration: 'language' and 'generatorName' can not be set both, remove 'language' from your configuration");
550-
}
551-
} else if (isNotEmpty(language)) {
552-
LOGGER.warn(
553-
"The 'language' option is deprecated and may reference language names only in the next major release (4.0). Please use 'generatorName' instead.");
554-
configurator.setGeneratorName(language);
555535
} else {
556536
LOGGER.error("A generator name (generatorName) is required.");
557537
throw new MojoExecutionException("The generator requires 'generatorName'. Refer to documentation for a list of options.");
@@ -724,7 +704,7 @@ public void execute() throws MojoExecutionException {
724704
originalEnvironmentVariables.put(key, GlobalSettings.getProperty(key));
725705
String value = environmentVariables.get(key);
726706
if (value != null) {
727-
configurator.addSystemProperty(key, value);
707+
configurator.addGlobalProperty(key, value);
728708
}
729709
}
730710
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfigurator.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class CodegenConfigurator {
6161
private String generatorName;
6262
private String inputSpec;
6363
private String templatingEngineName;
64-
private Map<String, String> systemProperties = new HashMap<>();
64+
private Map<String, String> globalProperties = new HashMap<>();
6565
private Map<String, String> instantiationTypes = new HashMap<>();
6666
private Map<String, String> typeMappings = new HashMap<>();
6767
private Map<String, Object> additionalProperties = new HashMap<>();
@@ -91,8 +91,8 @@ public static CodegenConfigurator fromFile(String configFile, Module... modules)
9191
configurator.generatorName = generatorSettings.getGeneratorName();
9292
configurator.inputSpec = workflowSettings.getInputSpec();
9393
configurator.templatingEngineName = workflowSettings.getTemplatingEngineName();
94-
if (workflowSettings.getSystemProperties() != null) {
95-
configurator.systemProperties.putAll(workflowSettings.getSystemProperties());
94+
if (workflowSettings.getGlobalProperties() != null) {
95+
configurator.globalProperties.putAll(workflowSettings.getGlobalProperties());
9696
}
9797
if(generatorSettings.getInstantiationTypes() != null) {
9898
configurator.instantiationTypes.putAll(generatorSettings.getInstantiationTypes());
@@ -183,10 +183,9 @@ public CodegenConfigurator addLanguageSpecificPrimitive(String value) {
183183
return this;
184184
}
185185

186-
// TODO: rename this and other references to "global property" rather than "system property"
187-
public CodegenConfigurator addSystemProperty(String key, String value) {
188-
this.systemProperties.put(key, value);
189-
workflowSettingsBuilder.withSystemProperty(key, value);
186+
public CodegenConfigurator addGlobalProperty(String key, String value) {
187+
this.globalProperties.put(key, value);
188+
workflowSettingsBuilder.withGlobalProperty(key, value);
190189
return this;
191190
}
192191

@@ -385,9 +384,9 @@ public CodegenConfigurator setStrictSpecBehavior(boolean strictSpecBehavior) {
385384
return this;
386385
}
387386

388-
public CodegenConfigurator setSystemProperties(Map<String, String> systemProperties) {
389-
this.systemProperties = systemProperties;
390-
workflowSettingsBuilder.withSystemProperties(systemProperties);
387+
public CodegenConfigurator setGlobalProperties(Map<String, String> globalProperties) {
388+
this.globalProperties = globalProperties;
389+
workflowSettingsBuilder.withGlobalProperties(globalProperties);
391390
return this;
392391
}
393392

@@ -450,7 +449,7 @@ public Context<?> toContext() {
450449
GlobalSettings.setProperty("verbose", "false");
451450
}
452451

453-
for (Map.Entry<String, String> entry : workflowSettings.getSystemProperties().entrySet()) {
452+
for (Map.Entry<String, String> entry : workflowSettings.getGlobalProperties().entrySet()) {
454453
GlobalSettings.setProperty(entry.getKey(), entry.getValue());
455454
}
456455

0 commit comments

Comments
 (0)