This is an automated email from the ASF dual-hosted git repository. ctubbsii pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/accumulo-access.git
The following commit(s) were added to refs/heads/main by this push: new 009246e Convert antlr4-example into an integration test (#53) 009246e is described below commit 009246e93aaa91dc4ce0b2a35ae8f14ddf04e210 Author: Christopher Tubbs <ctubb...@apache.org> AuthorDate: Wed Feb 14 02:45:49 2024 -0500 Convert antlr4-example into an integration test (#53) * Update README to point to the antlr-example integration test's README for an ANTLR example. * Move the contrib/antlr4 project into an integration test invoked by the maven-invoker-plugin, that depends on this project, so it doesn't have to be kept up-to-date * Fix LICENSE to include mention that Abnf.g4 is under the BSD-3-Clause license * Get a fresh unaltered copy of Abnf.g4 from upstream, use POM config to specify package, rather than modify it * Remove unnecessary build stuff from example POM * Move the ABNF spec to src/main/resources and add a test to ensure it matches the contents of the SPECIFICATION.md file * Clean up unused checks in checkstyle config for dependencies or code that doesn't exist in this project * Fix link in README to getting started section This fixes #43 --- .gitignore | 31 ++--- LICENSE | 9 ++ README.md | 10 +- SPECIFICATION.md | 2 +- contrib/antlr4/README.md | 31 ----- pom.xml | 40 ++++--- src/it/antlr4-example/README.md | 53 +++++++++ .../it/antlr4-example/invoker.properties | 19 +--- {contrib/antlr4 => src/it/antlr4-example}/pom.xml | 94 +++------------- .../it/antlr4-example}/src/main/antlr4/Abnf.g4 | 125 ++++++++++----------- .../src/main/antlr4/AccessExpression.g4 | 6 +- .../accumulo/access/antlr/TestDataLoader.java | 6 +- .../accumulo/access/grammar/SpecificationTest.java | 8 +- .../antlr/AccessExpressionAntlrBenchmark.java | 0 .../antlr/AccessExpressionAntlrEvaluator.java | 0 .../grammar/antlr/AccessExpressionAntlrParser.java | 0 .../accumulo/access/grammar/antlr/Antlr4Tests.java | 0 src/it/settings.xml | 55 +++++++++ .../access/specification/AccessExpression.abnf | 0 .../accumulo/access/AccessExpressionTest.java | 35 ++++++ 20 files changed, 283 insertions(+), 241 deletions(-) diff --git a/.gitignore b/.gitignore index 7b0fced..35f9301 100644 --- a/.gitignore +++ b/.gitignore @@ -18,19 +18,22 @@ # # Maven ignores -target/ +/target/ # IDE ignores -.settings/ -.project -.classpath -.pydevproject -.idea -*.iml -*.ipr -*.iws -nbproject/ -nbactions.xml -nb-configuration.xml -.vscode/ -.factorypath +/.settings/ +/.project +/.classpath +/.pydevproject +/.idea +/*.iml +/*.ipr +/*.iws +/nbproject/ +/nbactions.xml +/nb-configuration.xml +/.vscode/ +/.factorypath + +# MacOS ignores +.DS_Store diff --git a/LICENSE b/LICENSE index d645695..dcc7fa1 100644 --- a/LICENSE +++ b/LICENSE @@ -200,3 +200,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + +***** + +This project also includes portions that are made available under other licenses: + +* Abnf.g4 is copied in whole from + https://github.com/antlr/grammars-v4/blob/753536777d827ccc0c9b108531ea67375c2039ac/abnf/Abnf.g4 + and is included under the terms of the BSD-3-Clause license found at the top of that file. + diff --git a/README.md b/README.md index af51287..db008ae 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,8 @@ This functionality is provided in a standalone java library that has no dependencies (for example no Hadoop, Zookeeper, Thrift, etc dependencies). For a conceptual overview of what an access expression is, see the -[specification](SPECIFICATION.md) document. See the [getting started -guide](contrib/getting-started/README.md) for an example of how to use -this java library. +[specification](SPECIFICATION.md) document. See the [Getting Started +section](#getting-started) for an example of how to use this java library. ## Public API @@ -50,7 +49,7 @@ Add the library to your CLASSPATH. For Maven, use: <dependency> <groupId>org.apache.accumulo</groupId> <artifactId>accumulo-access</artifactId> - <version>$version</version> + <version>${version.accumulo-access}</version> </dependency> </dependencies> ``` @@ -66,6 +65,9 @@ CLASSPATH=$(ls target/accumulo-access-*.jar) java src/test/java/example/AccessEx Note that `data6` is always returned, because it has no access expression. And remember, authorizations are case-sensitive. +For an ANTLRv4 example, see antlr-example integration test's +[README](src/it/antlr4-example/README.md). + ## Running the Benchmark This project includes a JMH Benchmark. To run it: diff --git a/SPECIFICATION.md b/SPECIFICATION.md index f4b484d..eae4e08 100644 --- a/SPECIFICATION.md +++ b/SPECIFICATION.md @@ -37,7 +37,7 @@ entity's Authorizations and the object's AccessExpression. The formal definition of the AccessExpression UTF-8 string representation is provided by the following [ABNF][1]: -``` +```ABNF access-expression = [expression] ; empty string is a valid access expression expression = (access-token / paren-expression) [and-expression / or-expression] diff --git a/contrib/antlr4/README.md b/contrib/antlr4/README.md deleted file mode 100644 index 8dbf3f3..0000000 --- a/contrib/antlr4/README.md +++ /dev/null @@ -1,31 +0,0 @@ -<!-- - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - https://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. ---> -# ANTLR Example - -This contrib example contains an [ANTLRv4](https://www.antlr.org/) grammar file (see [AccessExpression.g4](src/main/antlr4/AccessExpression.g4)) that can be used to create AccessExpression parsers in languages supported by ANTLRv4. For example, a project could use this to validate that AccessExpression's are valid before sending them to Accumulo in the ColumnVisibility field of the Key. - -An example [parser](src/test/java/org/apache/accumulo/access/grammar/antlr/AccessExpressionAntlrParser.java) and [evaluator](src/test/java/org/apache/accumulo/access/grammar/antlr/AccessExpressionAntlrEvaluator.java) are used when building this project to confirm that the parsing and evaluation are consistent with the reference Java implementation. - -## Running the Benchmark - -ANTLR was evaluated as a replacement for the existing custom Java parser, but it doesn't parse as fast as the custom implementation. You can view the performance differences by running the JMH benchmark in this contrib project and the one in the main project. - -To run the benchmark in this project: -``` -mvn clean package -mvn exec:exec -Dexec.executable="java" -Dexec.classpathScope=test -Dexec.args="-classpath %classpath org.apache.accumulo.access.grammar.antlr.AccessExpressionAntlrBenchmark" -``` diff --git a/pom.xml b/pom.xml index bf4cf5d..2e22b9a 100644 --- a/pom.xml +++ b/pom.xml @@ -105,7 +105,9 @@ <rat.consoleOutput>true</rat.consoleOutput> <sourceReleaseAssemblyDescriptor>source-release-tar</sourceReleaseAssemblyDescriptor> <version.errorprone>2.24.1</version.errorprone> + <version.gson>2.10.1</version.gson> <version.jmh>1.37</version.jmh> + <version.junit>5.10.2</version.junit> </properties> <dependencies> <dependency> @@ -117,13 +119,13 @@ <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> - <version>2.10.1</version> + <version>${version.gson}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> - <version>5.10.2</version> + <version>${version.junit}</version> <scope>test</scope> </dependency> <dependency> @@ -150,7 +152,7 @@ <licenseSet> <header>src/build/license-header.txt</header> <excludes> - <exclude>contrib/antlr4/src/main/antlr4/Abnf.g4</exclude> + <exclude>src/it/antlr4-example/src/main/antlr4/Abnf.g4</exclude> <exclude>**/DEPENDENCIES</exclude> <exclude>**/LICENSE</exclude> <exclude>**/NOTICE</exclude> @@ -349,18 +351,6 @@ <property name="format" value="[@]see\s+[{][@]link" /> <property name="message" value="Javadoc @see does not need @link: pick one or the other." /> </module> - <module name="RegexpSinglelineJava"> - <property name="format" value="jline[.]internal[.]Preconditions" /> - <property name="message" value="Please use Guava Preconditions not JLine" /> - </module> - <module name="RegexpSinglelineJava"> - <property name="format" value="org[.]apache[.]commons[.]math[.]" /> - <property name="message" value="Use commons-math3 (org.apache.commons.math3.*)" /> - </module> - <module name="RegexpSinglelineJava"> - <property name="format" value="import org[.]apache[.]accumulo[.]core[.]util[.]LazySingletons;" /> - <property name="message" value="Use static imports for LazySingletons for consistency" /> - </module> <module name="RegexpSinglelineJava"> <property name="format" value="org[.]junit[.]jupiter[.]api[.]Assertions;" /> <property name="message" value="Use static imports for Assertions.* methods for consistency" /> @@ -474,6 +464,24 @@ <legacyMode>true</legacyMode> </configuration> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-invoker-plugin</artifactId> + <executions> + <execution> + <id>invoked-integration-tests</id> + <goals> + <goal>install</goal> + <goal>run</goal> + </goals> + <configuration> + <cloneProjectsTo>${project.build.directory}/its</cloneProjectsTo> + <localRepositoryPath>${project.build.directory}/it-repo</localRepositoryPath> + <settingsFile>src/it/settings.xml</settingsFile> + </configuration> + </execution> + </executions> + </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> @@ -494,7 +502,7 @@ <artifactId>apache-rat-plugin</artifactId> <configuration> <excludes> - <exclude>contrib/antlr4/src/main/antlr4/Abnf.g4</exclude> + <exclude>src/it/antlr4-example/src/main/antlr4/Abnf.g4</exclude> <exclude>src/test/resources/testdata.json</exclude> </excludes> </configuration> diff --git a/src/it/antlr4-example/README.md b/src/it/antlr4-example/README.md new file mode 100644 index 0000000..3e32539 --- /dev/null +++ b/src/it/antlr4-example/README.md @@ -0,0 +1,53 @@ +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + https://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +# ANTLR Example + +This example project contains an [ANTLRv4][1] grammar file (see +[AccessExpression.g4][2]) that can be used to create AccessExpression parsers +in languages supported by ANTLRv4. For example, a project could use this to +validate that AccessExpression's are valid before sending them to Accumulo in +the ColumnVisibility field of the Key. + +An example [parser][3] and [evaluator][4] are used when building this project +to confirm that the parsing and evaluation are consistent with the reference +Java implementation. + +## Running the Benchmark + +ANTLR was evaluated as a replacement for the existing custom Java parser, but +it doesn't parse as fast as the custom implementation. You can view the +performance differences by running the JMH benchmark in this contrib project +and the one in the main project. + +To run the benchmark in this project, first build the main project using: + +``` +mvn clean install +``` + +Then, switch to the cloned directory for this example, and run the benchmark +command: + +``` +cd target/its/antlr4-example/ +mvn exec:exec -Dexec.executable="java" -Dexec.classpathScope=test -Dexec.args="-classpath %classpath org.apache.accumulo.access.grammar.antlr.AccessExpressionAntlrBenchmark" +``` + +[1]: https://www.antlr.org +[2]: src/main/antlr4/AccessExpression.g4 +[3]: src/test/java/org/apache/accumulo/access/grammar/antlr/AccessExpressionAntlrParser.java +[4]: src/test/java/org/apache/accumulo/access/grammar/antlr/AccessExpressionAntlrEvaluator.java diff --git a/.gitignore b/src/it/antlr4-example/invoker.properties similarity index 81% copy from .gitignore copy to src/it/antlr4-example/invoker.properties index 7b0fced..8b360bf 100644 --- a/.gitignore +++ b/src/it/antlr4-example/invoker.properties @@ -17,20 +17,7 @@ # under the License. # -# Maven ignores -target/ +invoker.goals = clean verify -# IDE ignores -.settings/ -.project -.classpath -.pydevproject -.idea -*.iml -*.ipr -*.iws -nbproject/ -nbactions.xml -nb-configuration.xml -.vscode/ -.factorypath +# The expected result of the build, possible values are "success" (default) and "failure" +invoker.buildResult = success diff --git a/contrib/antlr4/pom.xml b/src/it/antlr4-example/pom.xml similarity index 50% rename from contrib/antlr4/pom.xml rename to src/it/antlr4-example/pom.xml index 143042e..e14db9b 100644 --- a/contrib/antlr4/pom.xml +++ b/src/it/antlr4-example/pom.xml @@ -24,18 +24,18 @@ <parent> <groupId>org.apache</groupId> <artifactId>apache</artifactId> - <version>30</version> + <version>31</version> </parent> <groupId>org.apache.accumulo</groupId> - <artifactId>accumulo-access-antlr4</artifactId> - <version>1.0.0-SNAPSHOT</version> + <artifactId>accumulo-access-antlr4-example</artifactId> + <version>@project.version@</version> <name>Apache Accumulo Access Antlr4 Example</name> <properties> + <maven.compiler.release>11</maven.compiler.release> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> <maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <version.jmh>1.36</version.jmh> </properties> <dependencies> <dependency> @@ -47,67 +47,35 @@ <dependency> <groupId>org.apache.accumulo</groupId> <artifactId>accumulo-access</artifactId> - <version>1.0.0-beta-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>com.github.spotbugs</groupId> - <artifactId>spotbugs-annotations</artifactId> - <version>4.7.3</version> - <scope>test</scope> + <version>@project.version@</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> - <version>2.10.1</version> + <version>@version.gson@</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> - <version>5.9.2</version> + <version>@version.junit@</version> <scope>test</scope> </dependency> <dependency> <groupId>org.openjdk.jmh</groupId> <artifactId>jmh-core</artifactId> - <version>${version.jmh}</version> + <version>@version.jmh@</version> <scope>test</scope> </dependency> <dependency> <groupId>org.openjdk.jmh</groupId> <artifactId>jmh-generator-annprocess</artifactId> - <version>${version.jmh}</version> + <version>@version.jmh@</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> - <plugin> - <groupId>com.github.ekryd.sortpom</groupId> - <artifactId>sortpom-maven-plugin</artifactId> - <version>3.3.0</version> - <configuration> - <createBackupFile>false</createBackupFile> - <expandEmptyElements>false</expandEmptyElements> - <keepBlankLines>false</keepBlankLines> - <lineSeparator>\n</lineSeparator> - <nrOfIndentSpace>2</nrOfIndentSpace> - <predefinedSortOrder>recommended_2008_06</predefinedSortOrder> - <sortDependencies>scope,groupId,artifactId</sortDependencies> - <sortProperties>true</sortProperties> - <spaceBeforeCloseEmptyElement>true</spaceBeforeCloseEmptyElement> - <verifyFail>Stop</verifyFail> - </configuration> - <executions> - <execution> - <id>sort-pom</id> - <goals> - <goal>sort</goal> - </goals> - <phase>process-sources</phase> - </execution> - </executions> - </plugin> <plugin> <groupId>org.antlr</groupId> <artifactId>antlr4-maven-plugin</artifactId> @@ -119,52 +87,16 @@ </goals> <phase>generate-sources</phase> <configuration> - <outputDirectory>target/generated-sources/antlr4/org/apache/accumulo/access/grammars</outputDirectory> + <arguments> + <arg>-package</arg> + <arg>org.apache.accumulo.access.grammars</arg> + </arguments> <listener>false</listener> <visitor>false</visitor> </configuration> </execution> </executions> </plugin> - <plugin> - <groupId>net.revelc.code</groupId> - <artifactId>impsort-maven-plugin</artifactId> - <version>1.9.0</version> - <configuration> - <removeUnused>true</removeUnused> - <groups>java.,javax.,jakarta.,org.,com.</groups> - </configuration> - <executions> - <execution> - <id>sort-imports</id> - <goals> - <goal>sort</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>net.revelc.code.formatter</groupId> - <artifactId>formatter-maven-plugin</artifactId> - <version>2.23.0</version> - <configuration> - <configFile>../../src/build/eclipse-codestyle.xml</configFile> - <lineEnding>LF</lineEnding> - <skipCssFormatting>true</skipCssFormatting> - <skipHtmlFormatting>true</skipHtmlFormatting> - <skipJsFormatting>true</skipJsFormatting> - <skipJsonFormatting>true</skipJsonFormatting> - <skipXmlFormatting>true</skipXmlFormatting> - </configuration> - <executions> - <execution> - <id>format-java-source</id> - <goals> - <goal>format</goal> - </goals> - </execution> - </executions> - </plugin> </plugins> </build> </project> diff --git a/contrib/antlr4/src/main/antlr4/Abnf.g4 b/src/it/antlr4-example/src/main/antlr4/Abnf.g4 similarity index 65% rename from contrib/antlr4/src/main/antlr4/Abnf.g4 rename to src/it/antlr4-example/src/main/antlr4/Abnf.g4 index 0eb9088..eecd109 100644 --- a/contrib/antlr4/src/main/antlr4/Abnf.g4 +++ b/src/it/antlr4-example/src/main/antlr4/Abnf.g4 @@ -44,120 +44,117 @@ ABNF grammar derived from: Terminal rules mainly created by ANTLRWorks 1.5 sample code. */ -/* - * This is a copy of https://github.com/antlr/grammars-v4/blob/master/abnf/Abnf.g4 that - * has been modified to specify the package name for the generated java code - */ -grammar Abnf; - - @header { - package org.apache.accumulo.access.grammars; - } +// $antlr-format alignTrailingComments true, columnLimit 150, minEmptyLines 1, maxEmptyLinesToKeep 1, reflowComments false, useTab false +// $antlr-format allowShortRulesOnASingleLine false, allowShortBlocksOnASingleLine true, alignSemicolons hanging, alignColons hanging +grammar Abnf; // Note: Whitespace handling not as strict as in the specification. rulelist - : rule_* EOF - ; + : rule_* EOF + ; rule_ - : ID '=' '/'? elements - ; + : ID '=' '/'? elements + ; elements - : alternation - ; + : alternation + ; alternation - : concatenation ( '/' concatenation )* - ; + : concatenation ('/' concatenation)* + ; concatenation - : repetition + - ; + : repetition+ + ; repetition - : repeat_? element - ; + : repeat_? element + ; repeat_ - : INT | INT? '*' INT? - ; + : INT + | INT? '*' INT? + ; element - : ID | group | option | STRING | NumberValue | ProseValue - ; + : ID + | group + | option + | STRING + | NumberValue + | ProseValue + ; group - : '(' alternation ')' - ; + : '(' alternation ')' + ; option - : '[' alternation ']' - ; - + : '[' alternation ']' + ; NumberValue - : '%' ( BinaryValue | DecimalValue | HexValue ) - ; - + : '%' (BinaryValue | DecimalValue | HexValue) + ; fragment BinaryValue - : 'b' BIT+ ( ( '.' BIT+ )+ | '-' BIT+ )? - ; - + : 'b' BIT+ (( '.' BIT+)+ | '-' BIT+)? + ; fragment DecimalValue - : 'd' DIGIT+ ( ( '.' DIGIT+ )+ | '-' DIGIT+ )? - ; - + : 'd' DIGIT+ (( '.' DIGIT+)+ | '-' DIGIT+)? + ; fragment HexValue - : 'x' HEX_DIGIT+ ( ( '.' HEX_DIGIT+ )+ | '-' HEX_DIGIT+ )? - ; - + : 'x' HEX_DIGIT+ (( '.' HEX_DIGIT+)+ | '-' HEX_DIGIT+)? + ; ProseValue - : '<' ~'>'* '>' - ; + : '<' ~'>'* '>' + ; ID - : LETTER ( LETTER | DIGIT | '-' )* - ; + : LETTER (LETTER | DIGIT | '-')* + ; INT - : '0' .. '9'+ - ; + : '0' .. '9'+ + ; COMMENT - : ';' ~ ( '\n' | '\r' )* '\r'? '\n' -> channel ( HIDDEN ) - ; + : ';' ~ ('\n' | '\r')* '\r'? '\n' -> channel ( HIDDEN ) + ; WS - : ( ' ' | '\t' | '\r' | '\n' ) -> channel ( HIDDEN ) - ; - + : (' ' | '\t' | '\r' | '\n') -> channel ( HIDDEN ) + ; STRING - : ( '%s' | '%i' )? '"' ~'"'* '"' - ; + : ('%s' | '%i')? '"' ~'"'* '"' + ; -fragment LETTER : 'a' .. 'z' | 'A' .. 'Z'; +fragment LETTER + : 'a' .. 'z' + | 'A' .. 'Z' + ; fragment BIT - : '0' .. '1' - ; - + : '0' .. '1' + ; fragment DIGIT - : '0' .. '9' - ; - + : '0' .. '9' + ; // Note: from the RFC errata (http://www.rfc-editor.org/errata_search.php?rfc=5234&eid=4040): // > ABNF strings are case insensitive and the character set for these strings is US-ASCII. // > So the definition of HEXDIG already allows for both upper and lower case (or a mixture). fragment HEX_DIGIT - : '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' - ; + : '0' .. '9' + | 'a' .. 'f' + | 'A' .. 'F' + ; diff --git a/contrib/antlr4/src/main/antlr4/AccessExpression.g4 b/src/it/antlr4-example/src/main/antlr4/AccessExpression.g4 similarity index 94% rename from contrib/antlr4/src/main/antlr4/AccessExpression.g4 rename to src/it/antlr4-example/src/main/antlr4/AccessExpression.g4 index 4ab5f6f..46f2286 100644 --- a/contrib/antlr4/src/main/antlr4/AccessExpression.g4 +++ b/src/it/antlr4-example/src/main/antlr4/AccessExpression.g4 @@ -18,10 +18,6 @@ */ grammar AccessExpression; -@header { - package org.apache.accumulo.access.grammars; -} - access_expression : EOF | expression EOF; expression : ( and_expression | or_expression | '(' expression ')' | access_token); and_expression : ( access_token | '(' expression ')' ) (and_operator ( access_token | '(' expression ')' ) )+; @@ -33,4 +29,4 @@ or_operator : '|'; ACCESS_TOKEN : ( [A-Za-z] | [0-9] | '_' | '-' | '.' | ':' | '/' )+ | '"' ( [\u0020-\u0021] | [\u0023-\u005B] | [\u005D-\u007E] | [\u0080-\uD7FF] | [\uE000-\u{10FFFF}] | ( '\\"' | '\\\\' ) )+ '"' ; -WS : [\r\t\b\u000C]+ -> skip; \ No newline at end of file +WS : [\r\t\b\u000C]+ -> skip; diff --git a/contrib/antlr4/src/test/java/org/apache/accumulo/access/antlr/TestDataLoader.java b/src/it/antlr4-example/src/test/java/org/apache/accumulo/access/antlr/TestDataLoader.java similarity index 94% rename from contrib/antlr4/src/test/java/org/apache/accumulo/access/antlr/TestDataLoader.java rename to src/it/antlr4-example/src/test/java/org/apache/accumulo/access/antlr/TestDataLoader.java index 0fcc76e..173155f 100644 --- a/contrib/antlr4/src/test/java/org/apache/accumulo/access/antlr/TestDataLoader.java +++ b/src/it/antlr4-example/src/test/java/org/apache/accumulo/access/antlr/TestDataLoader.java @@ -46,9 +46,7 @@ public class TestDataLoader { public static class TestDataSet { public String description; - public String[][] auths; - public List<TestExpressions> tests; } @@ -56,8 +54,8 @@ public class TestDataLoader { URL url = TestDataLoader.class.getClassLoader().getResource("."); File testClassesDir = new File(url.toURI()); - File accumuloAccessParentDir = - testClassesDir.getParentFile().getParentFile().getParentFile().getParentFile(); + File accumuloAccessParentDir = testClassesDir.getParentFile().getParentFile().getParentFile() + .getParentFile().getParentFile(); File accumuloAccessSourceDir = new File(accumuloAccessParentDir, "src"); assertTrue(accumuloAccessSourceDir.exists()); File accumuloAccessTestDir = new File(accumuloAccessSourceDir, "test"); diff --git a/contrib/antlr4/src/test/java/org/apache/accumulo/access/grammar/SpecificationTest.java b/src/it/antlr4-example/src/test/java/org/apache/accumulo/access/grammar/SpecificationTest.java similarity index 92% rename from contrib/antlr4/src/test/java/org/apache/accumulo/access/grammar/SpecificationTest.java rename to src/it/antlr4-example/src/test/java/org/apache/accumulo/access/grammar/SpecificationTest.java index 500036b..b990775 100644 --- a/contrib/antlr4/src/test/java/org/apache/accumulo/access/grammar/SpecificationTest.java +++ b/src/it/antlr4-example/src/test/java/org/apache/accumulo/access/grammar/SpecificationTest.java @@ -30,23 +30,21 @@ import org.antlr.v4.runtime.ConsoleErrorListener; import org.antlr.v4.runtime.LexerNoViableAltException; import org.antlr.v4.runtime.RecognitionException; import org.antlr.v4.runtime.Recognizer; +import org.apache.accumulo.access.AccessExpression; import org.apache.accumulo.access.grammar.antlr.Antlr4Tests; import org.apache.accumulo.access.grammars.AbnfLexer; import org.apache.accumulo.access.grammars.AbnfParser; import org.junit.jupiter.api.Test; // This test uses the ANTLR ABNF grammar to parse the -// accumulo-access ANBF specification to validate that +// AccessExpression ANBF specification to validate that // it is proper ANBF. public class SpecificationTest { @Test public void testAbnfSpecificationParses() throws Exception { - // The test resource specification.abnf is a copy of the ABNF - // from SPECIFICATION.md - - InputStream is = Antlr4Tests.class.getResourceAsStream("/specification.abnf"); + var is = AccessExpression.class.getResourceAsStream("specification/AccessExpression.abnf"); assertNotNull(is); final AtomicLong errors = new AtomicLong(0); diff --git a/contrib/antlr4/src/test/java/org/apache/accumulo/access/grammar/antlr/AccessExpressionAntlrBenchmark.java b/src/it/antlr4-example/src/test/java/org/apache/accumulo/access/grammar/antlr/AccessExpressionAntlrBenchmark.java similarity index 100% rename from contrib/antlr4/src/test/java/org/apache/accumulo/access/grammar/antlr/AccessExpressionAntlrBenchmark.java rename to src/it/antlr4-example/src/test/java/org/apache/accumulo/access/grammar/antlr/AccessExpressionAntlrBenchmark.java diff --git a/contrib/antlr4/src/test/java/org/apache/accumulo/access/grammar/antlr/AccessExpressionAntlrEvaluator.java b/src/it/antlr4-example/src/test/java/org/apache/accumulo/access/grammar/antlr/AccessExpressionAntlrEvaluator.java similarity index 100% rename from contrib/antlr4/src/test/java/org/apache/accumulo/access/grammar/antlr/AccessExpressionAntlrEvaluator.java rename to src/it/antlr4-example/src/test/java/org/apache/accumulo/access/grammar/antlr/AccessExpressionAntlrEvaluator.java diff --git a/contrib/antlr4/src/test/java/org/apache/accumulo/access/grammar/antlr/AccessExpressionAntlrParser.java b/src/it/antlr4-example/src/test/java/org/apache/accumulo/access/grammar/antlr/AccessExpressionAntlrParser.java similarity index 100% rename from contrib/antlr4/src/test/java/org/apache/accumulo/access/grammar/antlr/AccessExpressionAntlrParser.java rename to src/it/antlr4-example/src/test/java/org/apache/accumulo/access/grammar/antlr/AccessExpressionAntlrParser.java diff --git a/contrib/antlr4/src/test/java/org/apache/accumulo/access/grammar/antlr/Antlr4Tests.java b/src/it/antlr4-example/src/test/java/org/apache/accumulo/access/grammar/antlr/Antlr4Tests.java similarity index 100% rename from contrib/antlr4/src/test/java/org/apache/accumulo/access/grammar/antlr/Antlr4Tests.java rename to src/it/antlr4-example/src/test/java/org/apache/accumulo/access/grammar/antlr/Antlr4Tests.java diff --git a/src/it/settings.xml b/src/it/settings.xml new file mode 100644 index 0000000..0b3a97b --- /dev/null +++ b/src/it/settings.xml @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +--> +<settings> + <profiles> + <profile> + <id>it-repo</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <repositories> + <repository> + <id>local.central</id> + <url>@localRepositoryUrl@</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </repository> + </repositories> + <pluginRepositories> + <pluginRepository> + <id>local.central</id> + <url>@localRepositoryUrl@</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </pluginRepository> + </pluginRepositories> + </profile> + </profiles> +</settings> diff --git a/contrib/antlr4/src/test/resources/specification.abnf b/src/main/resources/org/apache/accumulo/access/specification/AccessExpression.abnf similarity index 100% rename from contrib/antlr4/src/test/resources/specification.abnf rename to src/main/resources/org/apache/accumulo/access/specification/AccessExpression.abnf diff --git a/src/test/java/org/apache/accumulo/access/AccessExpressionTest.java b/src/test/java/org/apache/accumulo/access/AccessExpressionTest.java index 266be77..c41fdd8 100644 --- a/src/test/java/org/apache/accumulo/access/AccessExpressionTest.java +++ b/src/test/java/org/apache/accumulo/access/AccessExpressionTest.java @@ -19,13 +19,22 @@ package org.apache.accumulo.access; import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.stream.Collectors.toList; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import java.util.function.Predicate; import java.util.stream.Collectors; import org.junit.jupiter.api.Test; @@ -189,4 +198,30 @@ public class AccessExpressionTest { assertEquals(ae1.hashCode(), ae3.hashCode()); assertNotEquals(ae1.hashCode(), ae2.hashCode()); } + + @Test + public void testSpecificationDocumentation() throws IOException, URISyntaxException { + // verify AccessExpression.abnf matches what is documented in SPECIFICATION.md + + // read the abnf spec, ignoring the header + List<String> specLinesFromAbnfFile; + try ( + var abnfFileStream = + AccessExpression.class.getResourceAsStream("specification/AccessExpression.abnf"); + var inputStreamReader = new InputStreamReader(abnfFileStream, UTF_8); + var bufferedReader = new BufferedReader(inputStreamReader)) { + + Predicate<String> abnfComment = line -> line.startsWith(";"); + Predicate<String> beforeFirstLine = abnfComment.or(String::isBlank); + specLinesFromAbnfFile = bufferedReader.lines().dropWhile(beforeFirstLine).collect(toList()); + } + + // grab from the markdown, but make sure to skip the markdown triple ticks + List<String> specLinesFromMarkdownFile = Files.readAllLines(Path.of("SPECIFICATION.md")) + .stream().dropWhile(line -> !line.startsWith("```ABNF")).skip(1) + .takeWhile(line -> !line.startsWith("```")).collect(toList()); + + assertFalse(specLinesFromAbnfFile.isEmpty()); // make sure we didn't just compare nothing + assertEquals(specLinesFromAbnfFile, specLinesFromMarkdownFile); + } }