-
Notifications
You must be signed in to change notification settings - Fork 312
Implement Config Inversion with Default Strictness of Warning
#9181
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
base: master
Are you sure you want to change the base?
Changes from 43 commits
fd62009
a756eb2
96e2546
6a87970
b062c96
6769bda
06ed2fd
8dd50e0
9660b1a
f8d2a8c
b68f0b2
dc5d83b
fe2eeb9
229c38d
77ddecd
eb6908a
972eef4
81c12f4
98c57b5
990c0ce
5bdd8cf
52c05b4
5192a8a
f128de8
734f9c7
e9ce233
90f536d
7a1517e
5ca61c0
abc0b64
97db41f
04bde01
9a764c9
e10e0a9
340eeef
ea83e25
4b602c1
4bdb960
962490d
c7aa94d
8068724
47a8f6a
94f392c
6c2a551
fe697ff
1aefa7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
plugins { | ||
`java-library` | ||
id("com.gradleup.shadow") | ||
} | ||
|
||
sourceSets { | ||
create("generator") { | ||
java.srcDir("src/generator/java") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❔ question: There are some maven conventions about |
||
val main by getting { | ||
java { | ||
srcDir("build/generated/sources/supported") | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
"generatorImplementation"("com.fasterxml.jackson.core:jackson-databind:2.15.2") | ||
"generatorImplementation"("org.slf4j:slf4j-api:1.7.36") | ||
implementation(project(":dd-trace-api")) | ||
} | ||
|
||
apply(from = "$rootDir/gradle/java.gradle") | ||
|
||
val compileGeneratorJava = tasks.named("compileGeneratorJava") | ||
|
||
val generateSupportedConfigurations by tasks.registering(JavaExec::class) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔨 issue: Input and output task defintions are missing. Isn't breaking the build / task cache? |
||
// We can run the generator with the main sourceSet runtimeClasspath | ||
dependsOn(compileGeneratorJava) | ||
mainClass.set("datadog.generator.ParseSupportedConfigurations") | ||
classpath = sourceSets["generator"].runtimeClasspath | ||
|
||
val outputFile = layout.buildDirectory.file("generated/sources/supported/GeneratedSupportedConfigurations.java") | ||
args("supported-configurations.json", outputFile.get().asFile.absolutePath) | ||
|
||
doFirst { | ||
outputFile.get().asFile.parentFile.mkdirs() | ||
} | ||
} | ||
// Ensure Java compilation depends on the generated sources | ||
sourceSets["main"].java.srcDir(layout.buildDirectory.dir("generated/sources/supported")) | ||
|
||
tasks.named("compileJava") { | ||
dependsOn(generateSupportedConfigurations) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package datadog.generator; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.PrintWriter; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class ParseSupportedConfigurations { | ||
|
||
public static void main(String[] args) { | ||
String supportedConfigurationsFilename = | ||
args[0]; // e.g., "resources/supported-configurations.json" | ||
String generatedMappingPath = args[1]; // e.g., | ||
// "build/generated-sources/datadog/environment/GeneratedSupportedConfigurations.java" | ||
|
||
String jsonString; | ||
try { | ||
|
||
InputStream in = | ||
ParseSupportedConfigurations.class | ||
.getClassLoader() | ||
.getResourceAsStream(supportedConfigurationsFilename); | ||
if (in == null) { | ||
throw new IllegalArgumentException( | ||
"Resource not found: " + supportedConfigurationsFilename); | ||
} | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
Map<String, Object> fileData = mapper.readValue(in, Map.class); | ||
|
||
Map<String, List<String>> supported = | ||
(Map<String, List<String>>) fileData.get("supportedConfigurations"); | ||
Map<String, List<String>> aliases = (Map<String, List<String>>) fileData.get("aliases"); | ||
Map<String, String> deprecated = (Map<String, String>) fileData.get("deprecations"); | ||
|
||
Map<String, String> aliasMapping = new HashMap<>(); | ||
for (Map.Entry<String, List<String>> entry : aliases.entrySet()) { | ||
for (String alias : entry.getValue()) { | ||
aliasMapping.put(alias, entry.getKey()); | ||
} | ||
} | ||
generateJavaFile(generatedMappingPath, supported.keySet(), aliases, aliasMapping, deprecated); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to read " + supportedConfigurationsFilename, e); | ||
} | ||
} | ||
|
||
private static void generateJavaFile( | ||
String outputPath, | ||
Set<String> supported, | ||
Map<String, List<String>> aliases, | ||
Map<String, String> aliasMapping, | ||
Map<String, String> deprecated) | ||
throws IOException { | ||
try (PrintWriter out = new PrintWriter(Files.newBufferedWriter(Paths.get(outputPath)))) { | ||
out.println("package datadog.generator;"); | ||
out.println(); | ||
out.println("import java.util.*;"); | ||
out.println(); | ||
out.println("public final class GeneratedSupportedConfigurations {"); | ||
|
||
// Supported set using Arrays.asList and HashSet | ||
out.println(" public static final Set<String> SUPPORTED;"); | ||
out.println(); | ||
|
||
// ALIASES map | ||
out.println(" public static final Map<String, List<String>> ALIASES;"); | ||
out.println(); | ||
|
||
// ALIAS_MAPPING map | ||
out.println(" public static final Map<String, String> ALIAS_MAPPING;"); | ||
out.println(); | ||
|
||
// DEPRECATED map | ||
out.println(" public static final Map<String, String> DEPRECATED;"); | ||
out.println(); | ||
|
||
// Static initializer block | ||
out.println(" static {"); | ||
|
||
// Initialize SUPPORTED | ||
out.print(" Set<String> supportedSet = new HashSet<>(Arrays.asList("); | ||
Iterator<String> supportedIter = supported.iterator(); | ||
while (supportedIter.hasNext()) { | ||
String key = supportedIter.next(); | ||
out.print("\"" + key + "\""); | ||
if (supportedIter.hasNext()) { | ||
out.print(", "); | ||
} | ||
} | ||
out.println("));"); | ||
out.println(" SUPPORTED = Collections.unmodifiableSet(supportedSet);"); | ||
out.println(); | ||
|
||
// Initialize ALIASES | ||
out.println(" Map<String, List<String>> aliasesMap = new HashMap<>();"); | ||
for (Map.Entry<String, List<String>> entry : aliases.entrySet()) { | ||
out.printf( | ||
" aliasesMap.put(\"%s\", Collections.unmodifiableList(Arrays.asList(%s)));\n", | ||
entry.getKey(), quoteList(entry.getValue())); | ||
} | ||
out.println(" ALIASES = Collections.unmodifiableMap(aliasesMap);"); | ||
out.println(); | ||
|
||
// Initialize ALIAS_MAPPING | ||
out.println(" Map<String, String> aliasMappingMap = new HashMap<>();"); | ||
for (Map.Entry<String, String> entry : aliasMapping.entrySet()) { | ||
out.printf(" aliasMappingMap.put(\"%s\", \"%s\");\n", entry.getKey(), entry.getValue()); | ||
} | ||
out.println(" ALIAS_MAPPING = Collections.unmodifiableMap(aliasMappingMap);"); | ||
out.println(); | ||
|
||
// Initialize DEPRECATED | ||
out.println(" Map<String, String> deprecatedMap = new HashMap<>();"); | ||
for (Map.Entry<String, String> entry : deprecated.entrySet()) { | ||
out.printf(" deprecatedMap.put(\"%s\", \"%s\");\n", entry.getKey(), entry.getValue()); | ||
} | ||
out.println(" DEPRECATED = Collections.unmodifiableMap(deprecatedMap);"); | ||
|
||
out.println(" }"); // end static block | ||
out.println("}"); // end class | ||
} | ||
} | ||
|
||
private static String quoteList(List<String> list) { | ||
StringBuilder sb = new StringBuilder(); | ||
for (int i = 0; i < list.size(); i++) { | ||
sb.append("\"").append(list.get(i)).append("\""); | ||
if (i < list.size() - 1) { | ||
sb.append(", "); | ||
} | ||
} | ||
return sb.toString(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❔ question: What the shadow plugin is used for?