Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement config priorities #12433

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,20 @@ public static void main(String[] args) {

public static List<CodegenConfig> getExtensions() {
ServiceLoader<CodegenConfig> loader = ServiceLoader.load(CodegenConfig.class);
List<CodegenConfig> output = new ArrayList<CodegenConfig>();
for (CodegenConfig aLoader : loader) {
output.add(aLoader);
Map<String, CodegenConfig> output = new HashMap<>();

for (CodegenConfig config : loader) {
if (output.get(config.getName()) == null) {
output.put(config.getName(), config);
} else if (config.isPrivileged() && !output.get(config.getName()).isPrivileged()) {
output.put(config.getName(), config);
} else if (output.get(config.getName()).isPrivileged() && !config.isPrivileged()) {
// skip
} else if (config.getPriority() > output.get(config.getName()).getPriority()) {
output.put(config.getName(), config);
}
}
return output;
return new ArrayList<>(output.values());
}

static void usage(Options options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,16 @@ public interface CodegenConfig {
boolean defaultIgnoreImportMappingOption();

boolean isUsingFlattenSpec();

default boolean isPrivileged() {
return false;
}

default int getPriority() {
return Integer.MIN_VALUE;
}

default String getCodeName() {
return getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,25 @@ public static CodegenConfig forName(String name) {
ServiceLoader<CodegenConfig> loader = load(CodegenConfig.class);

StringBuilder availableConfigs = new StringBuilder();

CodegenConfig current = null;
for (CodegenConfig config : loader) {

if (config.getName().equals(name)) {
return config;
if (current == null) {
current = config;
} else if (config.isPrivileged() && !current.isPrivileged()) {
current = config;
} else if (current.isPrivileged() && !config.isPrivileged()) {
// skip
} else if (config.getPriority() > current.getPriority()) {
current = config;
}
}

availableConfigs.append(config.getName()).append("\n");
}
if (current != null) {
return current;
}

// else try to load directly
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,20 @@ public static void main(String[] args) {

public static List<CodegenConfig> getExtensions() {
ServiceLoader<CodegenConfig> loader = ServiceLoader.load(CodegenConfig.class);
List<CodegenConfig> output = new ArrayList<CodegenConfig>();
Map<String, CodegenConfig> output = new HashMap<>();

for (CodegenConfig config : loader) {
output.add(config);
if (output.get(config.getName()) == null) {
output.put(config.getName(), config);
} else if (config.isPrivileged() && !output.get(config.getName()).isPrivileged()) {
output.put(config.getName(), config);
} else if (output.get(config.getName()).isPrivileged() && !config.isPrivileged()) {
// skip
} else if (config.getPriority() > output.get(config.getName()).getPriority()) {
output.put(config.getName(), config);
}
}
return output;
return new ArrayList<>(output.values());
}

static void usage(Options options) {
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@
</repositories>
<properties>
<maven.compiler.release>8</maven.compiler.release>
<swagger-parser-version>1.0.70</swagger-parser-version>
<swagger-parser-version>1.0.71</swagger-parser-version>
<scala-version>2.11.1</scala-version>
<felix-version>3.3.0</felix-version>
<swagger-core-version>1.6.14</swagger-core-version>
Expand All @@ -1075,7 +1075,7 @@
Codegen support of Java 8 should be removed if updating to 1.16+
-->
<jmustache-version>1.15</jmustache-version>
<testng-version>7.10.1</testng-version>
<testng-version>7.10.2</testng-version>
<surefire-version>3.0.0</surefire-version>
<jmockit-version>1.49</jmockit-version>
<mockito-version>5.11.0</mockito-version>
Expand Down
Loading