Skip to content
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.netflix.nebula:nebula-publishing-plugin:14.1.1'
classpath 'com.palantir.gradle.consistentversions:gradle-consistent-versions:1.13.1'
classpath 'com.palantir.baseline:gradle-baseline-java:2.39.0'
classpath 'com.palantir.baseline:gradle-baseline-java:2.42.0'
classpath 'com.palantir.gradle.conjure:gradle-conjure:4.14.0'
classpath 'com.palantir.gradle.gitversion:gradle-git-version:0.12.2'
classpath 'gradle.plugin.org.inferred:gradle-processors:3.1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ public final void action() throws IOException {
File output = getOutputFile().getAsFile().get();
getProject().mkdir(output.getParent());

writer.writeValue(output, getSource().getFiles().stream()
.map(CompileMetricSchemaTask::readFile)
.collect(ImmutableSet.toImmutableSet()));
writer.writeValue(
output,
getSource().getFiles().stream()
.map(CompileMetricSchemaTask::readFile)
.collect(ImmutableSet.toImmutableSet()));
}

private static MetricSchema readFile(File file) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ public final void createManifest() throws IOException {

private Map<String, List<MetricSchema>> getLocalMetrics() throws IOException {
if (getMetricsFile().getAsFile().isPresent()) {
return ImmutableMap.of(getProjectCoordinates(getProject()), mapper.readValue(
getMetricsFile().getAsFile().get(), new TypeReference<List<MetricSchema>>() {}));
return ImmutableMap.of(
getProjectCoordinates(getProject()),
mapper.readValue(getMetricsFile().getAsFile().get(), new TypeReference<List<MetricSchema>>() {}));
}
return Collections.emptyMap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,18 @@ private static void validateNamespace(String namespace, MetricNamespace namespac
// Provide enough data to figure out which schema is missing a namespace
SafeArg.of("namespaceValue", namespaceValue));
Preconditions.checkArgument(
NAME_PREDICATE.matcher(namespace).matches(), "Namespace must match pattern", SafeArg.of(
"pattern", NAME_PATTERN));
NAME_PREDICATE.matcher(namespace).matches(),
"Namespace must match pattern",
SafeArg.of("pattern", NAME_PATTERN));
validateShortName(namespaceValue);
validateDocumentation(namespaceValue.getDocs());
namespaceValue.getMetrics().forEach((name, definition) -> {
Preconditions.checkArgument(
!name.isEmpty(), "MetricDefinition names must not be empty", SafeArg.of("namespace", namespace));
Preconditions.checkArgument(
NAME_PREDICATE.matcher(name).matches(), "MetricDefinition names must match pattern", SafeArg.of(
"pattern", NAME_PATTERN));
NAME_PREDICATE.matcher(name).matches(),
"MetricDefinition names must match pattern",
SafeArg.of("pattern", NAME_PATTERN));
Preconditions.checkArgument(
MetricType.Value.UNKNOWN != definition.getType().get(),
"Unknown metric type",
Expand All @@ -64,16 +66,18 @@ private static void validateNamespace(String namespace, MetricNamespace namespac
SafeArg.of("namespace", namespace),
SafeArg.of("definition", definition));
Preconditions.checkArgument(
NAME_PREDICATE.matcher(tag).matches(), "MetricDefinition tags must match pattern", SafeArg.of(
"pattern", NAME_PATTERN));
NAME_PREDICATE.matcher(tag).matches(),
"MetricDefinition tags must match pattern",
SafeArg.of("pattern", NAME_PATTERN));
});
});
}

private static void validateShortName(MetricNamespace namespace) {
namespace.getShortName().ifPresent(shortName -> Preconditions.checkArgument(
SHORT_NAME_PREDICATE.matcher(shortName).matches(), "ShortName must match pattern", SafeArg.of(
"pattern", SHORT_NAME_PATTERN)));
SHORT_NAME_PREDICATE.matcher(shortName).matches(),
"ShortName must match pattern",
SafeArg.of("pattern", SHORT_NAME_PATTERN)));
}

private static void validateDocumentation(Documentation documentation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ public class GoetheTest {

@Test
public void testFormatAndEmit() {
JavaFile javaFile = JavaFile.builder("com.palantir.foo", TypeSpec.classBuilder("Foo")
.addStaticBlock(CodeBlock.builder().addStatement("type oops name = bar").build())
.build())
JavaFile javaFile = JavaFile.builder(
"com.palantir.foo",
TypeSpec.classBuilder("Foo")
.addStaticBlock(CodeBlock.builder().addStatement("type oops name = bar").build())
.build())
.build();
assertThatThrownBy(() -> Goethe.format(javaFile))
.hasMessageContaining("Failed to format 'com.palantir.foo.Foo'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
public class JavaGeneratorTest {
private static final String REFERENCE_FILES_FOLDER = "src/integrationInput/java";

@TempDir public Path tempDir;
@TempDir
public Path tempDir;

@Test
void generates_code() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,17 @@ void testValidateNamespace_newline() {
@Test
void testEmptyMetricName() {
assertThatThrownBy(() -> Validator.validate(MetricSchema.builder()
.namespaces("test", MetricNamespace.builder()
.docs(DOCS)
.metrics("", MetricDefinition.builder().docs(DOCS).type(MetricType.COUNTER).build())
.build())
.namespaces(
"test",
MetricNamespace.builder()
.docs(DOCS)
.metrics(
"",
MetricDefinition.builder()
.docs(DOCS)
.type(MetricType.COUNTER)
.build())
.build())
.build()))
.isInstanceOf(SafeIllegalArgumentException.class)
.hasMessageContaining("MetricDefinition names must not be empty");
Expand All @@ -74,14 +81,18 @@ void testEmptyMetricName() {
@Test
void testUnknownType() {
assertThatThrownBy(() -> Validator.validate(MetricSchema.builder()
.namespaces("test", MetricNamespace.builder()
.docs(DOCS)
.metrics("name", MetricDefinition.builder()
.namespaces(
"test",
MetricNamespace.builder()
.docs(DOCS)
.type(MetricType.valueOf("other"))
.tags("")
.metrics(
"name",
MetricDefinition.builder()
.docs(DOCS)
.type(MetricType.valueOf("other"))
.tags("")
.build())
.build())
.build())
.build()))
.isInstanceOf(SafeIllegalArgumentException.class)
.hasMessageContaining("Unknown metric type");
Expand All @@ -90,14 +101,18 @@ void testUnknownType() {
@Test
void testEmptyTag() {
assertThatThrownBy(() -> Validator.validate(MetricSchema.builder()
.namespaces("test", MetricNamespace.builder()
.docs(DOCS)
.metrics("name", MetricDefinition.builder()
.namespaces(
"test",
MetricNamespace.builder()
.docs(DOCS)
.type(MetricType.COUNTER)
.tags("")
.metrics(
"name",
MetricDefinition.builder()
.docs(DOCS)
.type(MetricType.COUNTER)
.tags("")
.build())
.build())
.build())
.build()))
.isInstanceOf(SafeIllegalArgumentException.class)
.hasMessageContaining("MetricDefinition tags must not be empty");
Expand All @@ -115,13 +130,17 @@ void testBlankTopLevelDocs() {
@Test
void testBlankMetricDocs() {
assertThatThrownBy(() -> Validator.validate(MetricSchema.builder()
.namespaces("test", MetricNamespace.builder()
.docs(DOCS)
.metrics("test", MetricDefinition.builder()
.type(MetricType.METER)
.docs(Documentation.of("\t \n"))
.namespaces(
"test",
MetricNamespace.builder()
.docs(DOCS)
.metrics(
"test",
MetricDefinition.builder()
.type(MetricType.METER)
.docs(Documentation.of("\t \n"))
.build())
.build())
.build())
.build()))
.isInstanceOf(SafeIllegalArgumentException.class)
.hasMessageContaining("Documentation must not be blank");
Expand Down
Loading