From 898b4ab9805bfa70faa1d518e256a6004a45ce96 Mon Sep 17 00:00:00 2001 From: Robert Stupp Date: Fri, 29 Oct 2021 18:48:19 +0200 Subject: [PATCH 1/2] Relocate antlr-runtime --- build.gradle.kts | 4 +- core/build.gradle.kts | 2 +- .../org/projectnessie/cel/parser/Helper.java | 4 +- .../org/projectnessie/cel/parser/Parser.java | 48 ++++++++++--------- .../cel/parser/StringCharStream.java | 6 +-- generated-antlr/build.gradle.kts | 28 ++++++++++- settings.gradle.kts | 2 +- 7 files changed, 63 insertions(+), 31 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index bf1321e4..e0ec2a89 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -133,7 +133,9 @@ allprojects { } } - from(components.findByName("java")) + if (project.name != "generated-antlr") { + from(components.findByName("java")) + } } } } diff --git a/core/build.gradle.kts b/core/build.gradle.kts index ae5502ac..5bcb0d23 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -32,7 +32,7 @@ val versionJmh = "1.33" val versionJunit = "5.8.1" dependencies { - implementation(project(":generated-antlr")) + implementation(project(":generated-antlr", "shadow")) api(project(":generated-pb")) implementation("org.agrona:agrona:$versionAgrona") diff --git a/core/src/main/java/org/projectnessie/cel/parser/Helper.java b/core/src/main/java/org/projectnessie/cel/parser/Helper.java index b24567fb..8a29d9e4 100644 --- a/core/src/main/java/org/projectnessie/cel/parser/Helper.java +++ b/core/src/main/java/org/projectnessie/cel/parser/Helper.java @@ -33,10 +33,10 @@ import java.util.List; import java.util.Map; import org.agrona.collections.LongArrayList; -import org.antlr.v4.runtime.ParserRuleContext; -import org.antlr.v4.runtime.Token; import org.projectnessie.cel.common.Location; import org.projectnessie.cel.common.Source; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.ParserRuleContext; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.Token; final class Helper { private final Source source; diff --git a/core/src/main/java/org/projectnessie/cel/parser/Parser.java b/core/src/main/java/org/projectnessie/cel/parser/Parser.java index 81d4e13b..8613cebd 100644 --- a/core/src/main/java/org/projectnessie/cel/parser/Parser.java +++ b/core/src/main/java/org/projectnessie/cel/parser/Parser.java @@ -32,22 +32,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.antlr.v4.runtime.ANTLRErrorListener; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.DefaultErrorStrategy; -import org.antlr.v4.runtime.IntStream; -import org.antlr.v4.runtime.ParserRuleContext; -import org.antlr.v4.runtime.RecognitionException; -import org.antlr.v4.runtime.Recognizer; -import org.antlr.v4.runtime.RuleContext; -import org.antlr.v4.runtime.Token; -import org.antlr.v4.runtime.atn.ATNConfigSet; -import org.antlr.v4.runtime.dfa.DFA; -import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; -import org.antlr.v4.runtime.tree.ErrorNode; -import org.antlr.v4.runtime.tree.ParseTree; -import org.antlr.v4.runtime.tree.ParseTreeListener; -import org.antlr.v4.runtime.tree.TerminalNode; import org.projectnessie.cel.common.ErrorWithLocation; import org.projectnessie.cel.common.Errors; import org.projectnessie.cel.common.Location; @@ -86,6 +70,22 @@ import org.projectnessie.cel.parser.gen.CELParser.StringContext; import org.projectnessie.cel.parser.gen.CELParser.UintContext; import org.projectnessie.cel.parser.gen.CELParser.UnaryContext; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.ANTLRErrorListener; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.CommonTokenStream; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.DefaultErrorStrategy; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.IntStream; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.ParserRuleContext; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.RecognitionException; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.Recognizer; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.RuleContext; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.Token; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.atn.ATNConfigSet; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.dfa.DFA; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.tree.AbstractParseTreeVisitor; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.tree.ErrorNode; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.tree.ParseTree; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.tree.ParseTreeListener; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.tree.TerminalNode; public final class Parser { @@ -258,18 +258,22 @@ private RecoveryLimitErrorStrategy(int maxAttempts) { } @Override - public void recover(org.antlr.v4.runtime.Parser recognizer, RecognitionException e) { + public void recover( + org.projectnessie.cel.parser.gen.antlr.v4.runtime.Parser recognizer, + RecognitionException e) { checkAttempts(recognizer); super.recover(recognizer, e); } @Override - public Token recoverInline(org.antlr.v4.runtime.Parser recognizer) throws RecognitionException { + public Token recoverInline(org.projectnessie.cel.parser.gen.antlr.v4.runtime.Parser recognizer) + throws RecognitionException { checkAttempts(recognizer); return super.recoverInline(recognizer); } - void checkAttempts(org.antlr.v4.runtime.Parser recognizer) throws RecognitionException { + void checkAttempts(org.projectnessie.cel.parser.gen.antlr.v4.runtime.Parser recognizer) + throws RecognitionException { if (attempts >= maxAttempts) { attempts++; String msg = String.format("error recovery attempt limit exceeded: %d", maxAttempts); @@ -303,7 +307,7 @@ public void syntaxError( @Override public void reportAmbiguity( - org.antlr.v4.runtime.Parser recognizer, + org.projectnessie.cel.parser.gen.antlr.v4.runtime.Parser recognizer, DFA dfa, int startIndex, int stopIndex, @@ -315,7 +319,7 @@ public void reportAmbiguity( @Override public void reportAttemptingFullContext( - org.antlr.v4.runtime.Parser recognizer, + org.projectnessie.cel.parser.gen.antlr.v4.runtime.Parser recognizer, DFA dfa, int startIndex, int stopIndex, @@ -326,7 +330,7 @@ public void reportAttemptingFullContext( @Override public void reportContextSensitivity( - org.antlr.v4.runtime.Parser recognizer, + org.projectnessie.cel.parser.gen.antlr.v4.runtime.Parser recognizer, DFA dfa, int startIndex, int stopIndex, diff --git a/core/src/main/java/org/projectnessie/cel/parser/StringCharStream.java b/core/src/main/java/org/projectnessie/cel/parser/StringCharStream.java index 1ab47f5a..a98bfc42 100644 --- a/core/src/main/java/org/projectnessie/cel/parser/StringCharStream.java +++ b/core/src/main/java/org/projectnessie/cel/parser/StringCharStream.java @@ -15,9 +15,9 @@ */ package org.projectnessie.cel.parser; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.IntStream; -import org.antlr.v4.runtime.misc.Interval; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.CharStream; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.IntStream; +import org.projectnessie.cel.parser.gen.antlr.v4.runtime.misc.Interval; public final class StringCharStream implements CharStream { diff --git a/generated-antlr/build.gradle.kts b/generated-antlr/build.gradle.kts index f88521a9..10ad289b 100644 --- a/generated-antlr/build.gradle.kts +++ b/generated-antlr/build.gradle.kts @@ -14,14 +14,17 @@ * limitations under the License. */ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + plugins { `java-library` antlr `maven-publish` signing + id("com.github.johnrengelman.shadow") } -val versionAntlr = "4.8" +val versionAntlr = "4.9.2" dependencies { antlr("org.antlr:antlr4:$versionAntlr") // TODO remove from runtime-classpath *sigh* @@ -32,3 +35,26 @@ dependencies { tasks.named("sourcesJar") { dependsOn(tasks.named("generateGrammarSource")) } + +tasks.named("jar") { + archiveClassifier.set("raw") +} + +tasks.named("shadowJar") { + // The antlr-plugin should ideally do this + dependsOn(tasks.named("generateGrammarSource")) + + dependencies { + include(dependency("org.antlr:antlr4-runtime")) + } + relocate("org.antlr.v4.runtime", "org.projectnessie.cel.parser.gen.antlr.v4.runtime") + archiveClassifier.set("") +} + +publishing { + publications { + getByName("maven") { + project.shadow.component(this) + } + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 4f871b21..d32eab63 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -25,7 +25,7 @@ pluginManagement { id("org.jetbrains.gradle.plugin.idea-ext") version "1.0" id("com.google.protobuf") version "0.8.16" id("me.champeau.jmh") version "0.6.5" - id("com.github.johnrengelman.shadow") version "7.0.0" + id("com.github.johnrengelman.shadow") version "7.1.0" id("org.caffinitas.gradle.aggregatetestresults") version "0.1" id("org.caffinitas.gradle.testsummary") version "0.1.1" id("org.caffinitas.gradle.testrerun") version "0.1" From 53411122acdcb304423c29ce538bf2c779b2a98a Mon Sep 17 00:00:00 2001 From: Robert Stupp Date: Tue, 2 Nov 2021 12:45:19 +0100 Subject: [PATCH 2/2] Update shaded package name --- .../org/projectnessie/cel/parser/Helper.java | 4 +- .../org/projectnessie/cel/parser/Parser.java | 44 +++++++++---------- .../cel/parser/StringCharStream.java | 6 +-- generated-antlr/build.gradle.kts | 2 +- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/core/src/main/java/org/projectnessie/cel/parser/Helper.java b/core/src/main/java/org/projectnessie/cel/parser/Helper.java index 8a29d9e4..edea6552 100644 --- a/core/src/main/java/org/projectnessie/cel/parser/Helper.java +++ b/core/src/main/java/org/projectnessie/cel/parser/Helper.java @@ -35,8 +35,8 @@ import org.agrona.collections.LongArrayList; import org.projectnessie.cel.common.Location; import org.projectnessie.cel.common.Source; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.ParserRuleContext; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.Token; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.ParserRuleContext; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.Token; final class Helper { private final Source source; diff --git a/core/src/main/java/org/projectnessie/cel/parser/Parser.java b/core/src/main/java/org/projectnessie/cel/parser/Parser.java index 8613cebd..c6287fe3 100644 --- a/core/src/main/java/org/projectnessie/cel/parser/Parser.java +++ b/core/src/main/java/org/projectnessie/cel/parser/Parser.java @@ -70,22 +70,22 @@ import org.projectnessie.cel.parser.gen.CELParser.StringContext; import org.projectnessie.cel.parser.gen.CELParser.UintContext; import org.projectnessie.cel.parser.gen.CELParser.UnaryContext; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.ANTLRErrorListener; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.CommonTokenStream; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.DefaultErrorStrategy; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.IntStream; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.ParserRuleContext; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.RecognitionException; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.Recognizer; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.RuleContext; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.Token; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.atn.ATNConfigSet; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.dfa.DFA; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.tree.AbstractParseTreeVisitor; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.tree.ErrorNode; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.tree.ParseTree; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.tree.ParseTreeListener; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.tree.TerminalNode; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.ANTLRErrorListener; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.CommonTokenStream; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.DefaultErrorStrategy; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.IntStream; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.ParserRuleContext; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.RecognitionException; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.Recognizer; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.RuleContext; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.Token; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.atn.ATNConfigSet; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.dfa.DFA; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.tree.ErrorNode; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.tree.ParseTree; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.tree.ParseTreeListener; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.tree.TerminalNode; public final class Parser { @@ -259,20 +259,20 @@ private RecoveryLimitErrorStrategy(int maxAttempts) { @Override public void recover( - org.projectnessie.cel.parser.gen.antlr.v4.runtime.Parser recognizer, + org.projectnessie.cel.shaded.org.antlr.v4.runtime.Parser recognizer, RecognitionException e) { checkAttempts(recognizer); super.recover(recognizer, e); } @Override - public Token recoverInline(org.projectnessie.cel.parser.gen.antlr.v4.runtime.Parser recognizer) + public Token recoverInline(org.projectnessie.cel.shaded.org.antlr.v4.runtime.Parser recognizer) throws RecognitionException { checkAttempts(recognizer); return super.recoverInline(recognizer); } - void checkAttempts(org.projectnessie.cel.parser.gen.antlr.v4.runtime.Parser recognizer) + void checkAttempts(org.projectnessie.cel.shaded.org.antlr.v4.runtime.Parser recognizer) throws RecognitionException { if (attempts >= maxAttempts) { attempts++; @@ -307,7 +307,7 @@ public void syntaxError( @Override public void reportAmbiguity( - org.projectnessie.cel.parser.gen.antlr.v4.runtime.Parser recognizer, + org.projectnessie.cel.shaded.org.antlr.v4.runtime.Parser recognizer, DFA dfa, int startIndex, int stopIndex, @@ -319,7 +319,7 @@ public void reportAmbiguity( @Override public void reportAttemptingFullContext( - org.projectnessie.cel.parser.gen.antlr.v4.runtime.Parser recognizer, + org.projectnessie.cel.shaded.org.antlr.v4.runtime.Parser recognizer, DFA dfa, int startIndex, int stopIndex, @@ -330,7 +330,7 @@ public void reportAttemptingFullContext( @Override public void reportContextSensitivity( - org.projectnessie.cel.parser.gen.antlr.v4.runtime.Parser recognizer, + org.projectnessie.cel.shaded.org.antlr.v4.runtime.Parser recognizer, DFA dfa, int startIndex, int stopIndex, diff --git a/core/src/main/java/org/projectnessie/cel/parser/StringCharStream.java b/core/src/main/java/org/projectnessie/cel/parser/StringCharStream.java index a98bfc42..bc29ec06 100644 --- a/core/src/main/java/org/projectnessie/cel/parser/StringCharStream.java +++ b/core/src/main/java/org/projectnessie/cel/parser/StringCharStream.java @@ -15,9 +15,9 @@ */ package org.projectnessie.cel.parser; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.CharStream; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.IntStream; -import org.projectnessie.cel.parser.gen.antlr.v4.runtime.misc.Interval; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.CharStream; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.IntStream; +import org.projectnessie.cel.shaded.org.antlr.v4.runtime.misc.Interval; public final class StringCharStream implements CharStream { diff --git a/generated-antlr/build.gradle.kts b/generated-antlr/build.gradle.kts index 10ad289b..aa23fe10 100644 --- a/generated-antlr/build.gradle.kts +++ b/generated-antlr/build.gradle.kts @@ -47,7 +47,7 @@ tasks.named("shadowJar") { dependencies { include(dependency("org.antlr:antlr4-runtime")) } - relocate("org.antlr.v4.runtime", "org.projectnessie.cel.parser.gen.antlr.v4.runtime") + relocate("org.antlr.v4.runtime", "org.projectnessie.cel.shaded.org.antlr.v4.runtime") archiveClassifier.set("") }