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..edea6552 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.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 81d4e13b..c6287fe3 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.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 { @@ -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.shaded.org.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.shaded.org.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.shaded.org.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.shaded.org.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.shaded.org.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.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 1ab47f5a..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.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.IntStream; -import org.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 f88521a9..aa23fe10 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.shaded.org.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"