From b7613301a2440f3cede05c0c64a0815cfcd343a6 Mon Sep 17 00:00:00 2001 From: Joao Duarte Date: Wed, 8 Apr 2020 10:25:23 +0100 Subject: [PATCH 1/2] remove google java formatter dependency --- logstash-core/build.gradle | 6 ---- .../ir/compiler/ComputeStepSyntaxElement.java | 35 ++++++------------- 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/logstash-core/build.gradle b/logstash-core/build.gradle index 2084a3e7861..e952462b5c2 100644 --- a/logstash-core/build.gradle +++ b/logstash-core/build.gradle @@ -168,12 +168,6 @@ dependencies { api files(customJRubyDir + "/maven/jruby-complete/target/jruby-complete-${customJRubyVersion}.jar") } implementation group: 'com.google.guava', name: 'guava', version: '22.0' - // WARNING: DO NOT UPGRADE "google-java-format" - // later versions require GPL licensed code in javac-shaded that is - // Apache2 incompatible - implementation('com.google.googlejavaformat:google-java-format:1.1') { - exclude group: 'com.google.guava', module: 'guava' - } implementation 'org.javassist:javassist:3.26.0-GA' testImplementation 'org.apache.logging.log4j:log4j-core:2.12.1:tests' testImplementation 'junit:junit:4.12' diff --git a/logstash-core/src/main/java/org/logstash/config/ir/compiler/ComputeStepSyntaxElement.java b/logstash-core/src/main/java/org/logstash/config/ir/compiler/ComputeStepSyntaxElement.java index 0381435bd28..009903d31c9 100644 --- a/logstash-core/src/main/java/org/logstash/config/ir/compiler/ComputeStepSyntaxElement.java +++ b/logstash-core/src/main/java/org/logstash/config/ir/compiler/ComputeStepSyntaxElement.java @@ -20,8 +20,6 @@ package org.logstash.config.ir.compiler; -import com.google.googlejavaformat.java.Formatter; -import com.google.googlejavaformat.java.FormatterException; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.nio.charset.StandardCharsets; @@ -58,12 +56,6 @@ public final class ComputeStepSyntaxElement { private static final Map, Class> CLASS_CACHE = new HashMap<>(5000); - /** - * Pattern to remove redundant {@code ;} from formatted code since {@link Formatter} does not - * remove those. - */ - private static final Pattern REDUNDANT_SEMICOLON = Pattern.compile("\n[ ]*;\n"); - private static final String CLASS_NAME_PLACEHOLDER = "CLASS_NAME_PLACEHOLDER"; private static final Pattern CLASS_NAME_PLACEHOLDER_REGEX = Pattern.compile(CLASS_NAME_PLACEHOLDER); @@ -155,24 +147,17 @@ public boolean equals(final Object other) { } private String generateCode(final String name) { - try { - return REDUNDANT_SEMICOLON.matcher(new Formatter().formatSource( - String.format( - "package org.logstash.generated;\npublic final class %s extends org.logstash.config.ir.compiler.BaseDataset implements %s { %s }", - name, - type.getName(), - SyntaxFactory.join( - fields.inlineAssigned().generateCode(), fieldsAndCtor(name), - combine( - StreamSupport.stream(methods.spliterator(), false) - .toArray(SyntaxElement[]::new) - ) + return String.format( + "package org.logstash.generated;\npublic final class %s extends org.logstash.config.ir.compiler.BaseDataset implements %s { %s }", + name, + type.getName(), + SyntaxFactory.join( + fields.inlineAssigned().generateCode(), fieldsAndCtor(name), + combine( + StreamSupport.stream(methods.spliterator(), false) + .toArray(SyntaxElement[]::new) ) - ) - )).replaceAll("\n"); - } catch (final FormatterException ex) { - throw new IllegalStateException(ex); - } + )).replaceAll("\n"); } private static Path debugDir() { From 7e867c3615470496cb336594e715f17c28331f11 Mon Sep 17 00:00:00 2001 From: Joao Duarte Date: Wed, 8 Apr 2020 11:25:28 +0100 Subject: [PATCH 2/2] remove google java formatter dependency --- .../logstash/config/ir/compiler/ComputeStepSyntaxElement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logstash-core/src/main/java/org/logstash/config/ir/compiler/ComputeStepSyntaxElement.java b/logstash-core/src/main/java/org/logstash/config/ir/compiler/ComputeStepSyntaxElement.java index 009903d31c9..e853c4a49ab 100644 --- a/logstash-core/src/main/java/org/logstash/config/ir/compiler/ComputeStepSyntaxElement.java +++ b/logstash-core/src/main/java/org/logstash/config/ir/compiler/ComputeStepSyntaxElement.java @@ -157,7 +157,7 @@ private String generateCode(final String name) { StreamSupport.stream(methods.spliterator(), false) .toArray(SyntaxElement[]::new) ) - )).replaceAll("\n"); + )); } private static Path debugDir() {