Skip to content
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

Relocate antlr-runtime #54

Merged
merged 2 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ allprojects {
}
}

from(components.findByName("java"))
if (project.name != "generated-antlr") {
from(components.findByName("java"))
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/projectnessie/cel/parser/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
48 changes: 26 additions & 22 deletions core/src/main/java/org/projectnessie/cel/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
28 changes: 27 additions & 1 deletion generated-antlr/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand All @@ -32,3 +35,26 @@ dependencies {
tasks.named<Jar>("sourcesJar") {
dependsOn(tasks.named("generateGrammarSource"))
}

tasks.named<Jar>("jar") {
archiveClassifier.set("raw")
}

tasks.named<ShadowJar>("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")
Copy link
Contributor

@omarsmak omarsmak Nov 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense if we keep the shaded package name as it is and add shaded prefix (something similar to Iceberg)? e.g: org.projectnessie.cel.shaded.org.antlr.v4.runtime. In order to distinguish that is shaded from org.antlr.v4.runtime

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup - updated the package name

archiveClassifier.set("")
}

publishing {
publications {
getByName<MavenPublication>("maven") {
project.shadow.component(this)
}
}
}
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down