-
-
Notifications
You must be signed in to change notification settings - Fork 687
Gherkin-Utils - Java - Address issue #1662 - add a Java pretty print gherkin module #1725
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
Changes from all commits
b0501c1
3e85f37
7cdbe75
ef4f7c5
9a73928
ad5887f
c36c37d
f9e6ca2
1242fc1
d13d33e
97d5a6c
fb9be45
da7aa10
a527c67
c588f2b
85b4f9e
992cf4f
5201f42
cd76a13
2ed7730
c356fe3
a9a30cb
ed00d2a
4f627cc
30d9b53
4bcc2bd
19fe741
15f7e70
f992a61
95f59ef
26417cd
4b89272
c804fa1
2e3d3b2
3ed72e1
6625780
330371d
b90afc0
cb68862
e85f043
c5e73bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
PLEASE DO NOT CREATE ISSUES IN THIS REPO. | ||
THIS REPO IS A READ-ONLY MIRROR. | ||
|
||
Create your issue in the Cucumber monorepo instead: | ||
https://github.com/cucumber/cucumber/issues |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
PLEASE DO NOT CREATE PULL REAUESTS IN THIS REPO. | ||
THIS REPO IS A READ-ONLY MIRROR. | ||
|
||
Create your pull request in the Cucumber monorepo instead: | ||
https://github.com/cucumber/cucumber/pulls |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.idea/ | ||
*.iml | ||
target/ | ||
release.properties | ||
pom.xml.releaseBackup | ||
pom.xml.versionsBackup | ||
dependency-reduced-pom.xml | ||
.classpath | ||
.deps | ||
.project | ||
.settings/ | ||
.tested* | ||
.compared | ||
.built | ||
.codegen | ||
# Approval tests | ||
acceptance/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
../LICENSE LICENSE | ||
../../.templates/github/ .github/ | ||
../../.templates/java/ . | ||
../testdata/ testdata/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Please read [CONTRIBUTING](https://github.com/cucumber/common/blob/main/CONTRIBUTING.md) first. You should clone | ||
the [cucumber/cucumber](https://github.com/cucumber/cucumber) repo if you want to contribute. | ||
|
||
## Run tests | ||
|
||
### Using make | ||
|
||
Just run `make` from this directory. | ||
|
||
### Using just Maven | ||
|
||
Just run `mvn clean test` from this directory. | ||
|
||
Keep in mind that this will only run unit tests. The acceptance tests are only run when you build with `make`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) Cucumber Ltd, Nicholas DiPiazza | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include default.mk |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Gherkin Utilties for Java | ||
|
||
This contains a Java library with some common Utilties | ||
|
||
See [GherkinTest](src/test/java/io/cucumber/gherkin/utils/PrettyPrintGherkinDocumentTest.java) for sample usage. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Please update /.templates/java/default.mk and sync: | ||
# | ||
# source scripts/functions.sh && rsync_files | ||
# | ||
SHELL := /usr/bin/env bash | ||
JAVA_SOURCE_FILES = $(shell find . -name "*.java") | ||
IS_TESTDATA = $(findstring -testdata,${CURDIR}) | ||
|
||
# https://stackoverflow.com/questions/2483182/recursive-wildcards-in-gnu-make | ||
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d)) | ||
|
||
default: .tested | ||
.PHONY: default | ||
|
||
.codegen: | ||
touch $@ | ||
|
||
.tested: .tested-jar-check | ||
|
||
.tested-jar-check: .deps .built | ||
./scripts/check-jar.sh $(JAR) | ||
touch $@ | ||
|
||
.built: pom.xml $(JAVA_SOURCE_FILES) .codegen | ||
mvn install | ||
touch $@ | ||
|
||
.deps: | ||
touch $@ | ||
|
||
update-dependencies: | ||
mvn versions:force-releases | ||
mvn versions:use-latest-versions -Dmaven.version.rules=file://$(shell pwd)/maven-versions-rules.xml | ||
ruby scripts/set_version_ranges.rb | ||
.PHONY: update-dependencies | ||
|
||
pre-release: update-version update-dependencies clean default | ||
.PHONY: pre-release | ||
|
||
update-version: | ||
ifdef NEW_VERSION | ||
mvn versions:set -DnewVersion=$(NEW_VERSION) -DgenerateBackupPoms=false | ||
else | ||
@echo -e "\033[0;31mNEW_VERSION is not defined. Can't update version :-(\033[0m" | ||
exit 1 | ||
endif | ||
.PHONY: update-version | ||
|
||
publish: .deps | ||
ifeq ($(IS_TESTDATA),-testdata) | ||
# no-op | ||
else | ||
mvn deploy -Psign-source-javadoc -DskipTests=true | ||
endif | ||
.PHONY: publish | ||
|
||
post-release: | ||
scripts/post-release.sh | ||
.PHONY: post-release | ||
|
||
clean: clean-java | ||
.PHONY: clean | ||
|
||
clean-java: | ||
rm -rf target .deps .tested* .built acceptance .codegen | ||
mvn clean | ||
.PHONY: clean-java | ||
|
||
### COMMON stuff for all platforms | ||
|
||
BERP_VERSION = 1.3.0 | ||
BERP_GRAMMAR = gherkin.berp | ||
|
||
define berp-generate-parser = | ||
-! dotnet tool list --tool-path /usr/bin | grep "berp\s*$(BERP_VERSION)" && dotnet tool update Berp --version $(BERP_VERSION) --tool-path /usr/bin | ||
berp -g $(BERP_GRAMMAR) -t $< -o $@ --noBOM | ||
endef |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<ruleset comparisonMethod="maven" | ||
xmlns="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0 http://mojo.codehaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd"> | ||
<ignoreVersions> | ||
<ignoreVersion type="regex">.*pr.*</ignoreVersion> | ||
<ignoreVersion type="regex">.*-rc.*</ignoreVersion> | ||
<ignoreVersion type="regex">.*-M\d+</ignoreVersion> | ||
</ignoreVersions> | ||
</ruleset> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?xml version="1.0"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>io.cucumber</groupId> | ||
<artifactId>gherkin-utils</artifactId> | ||
<version>22.0.0</version> | ||
<packaging>jar</packaging> | ||
<name>Gherkin Utils</name> | ||
<description>Gherkin utils for doing things such as walking a Gherkin tree or pretty printing Gherkin files. | ||
</description> | ||
<url>https://github.com/cucumber/common</url> | ||
|
||
<properties> | ||
<project.Automatic-Module-Name>io.cucumber.gherkin-utils</project.Automatic-Module-Name> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
</properties> | ||
|
||
<scm> | ||
<connection>scm:git:git://github.com/cucumber/common.git</connection> | ||
<developerConnection>scm:git:[email protected]:cucumber/common.git</developerConnection> | ||
<url>git://github.com/cucumber/common.git</url> | ||
<tag>HEAD</tag> | ||
</scm> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.cucumber</groupId> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be Please add a runtime dependency on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i could not make this change, it caused project not to compile due to missing dependencies during compile time. |
||
<artifactId>gherkin</artifactId> | ||
<version>21.0.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>5.5.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.2.0</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.2</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Verifies that the jar doesn't have any non-"io.cucumber" classes. This might happen | ||
# if some dependencies are shaded, but some are forgotten. | ||
# | ||
set -uf -o pipefail | ||
|
||
check_jar() { | ||
jar="$1" | ||
module_name=$(xmlstarlet sel -N pom="http://maven.apache.org/POM/4.0.0" -t -m "//pom:project.Automatic-Module-Name" -v . pom.xml) | ||
module_path=$(echo $module_name | sed "s/\./\\\\\//g" | sed "s/-/\\\\\//g") | ||
echo "Checking contents of ${jar} to see if it matches pattern: ${module_path}" | ||
unshaded_classes=$(unzip -l ${jar} | grep -e "\.class" | rev | cut -d' ' -f1 | rev | grep -v "^$module_path") | ||
if [[ "${unshaded_classes}" != "" ]]; then | ||
echo "Some classes in ${jar} are not in the expected package matching pattern ${module_path}. Rename the classes or change the maven-shade-plugin configuration." | ||
echo | ||
echo "${unshaded_classes}" | ||
exit 1 | ||
fi | ||
} | ||
|
||
find . -name "*.jar" | while read jar; do | ||
check_jar "${jar}" | ||
done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Bumps the patch version and appends -SNAPSHOT | ||
# | ||
set -uf -o pipefail | ||
|
||
# Finding current version in Changelog is way simpler, as there may be multiple <version> nodes in pom.xml | ||
# Also extracting version with maven itself is a bit tedious | ||
if [[ $(cat "../CHANGELOG.md") =~ \[([0-9]+).([0-9]+).([0-9]+)\] ]]; then | ||
MAJOR="${BASH_REMATCH[1]}" | ||
MINOR="${BASH_REMATCH[2]}" | ||
PATCH="${BASH_REMATCH[3]}" | ||
|
||
NEW_VERSION="$MAJOR.$MINOR.$(( PATCH + 1))-SNAPSHOT" | ||
mvn versions:set -DnewVersion=$NEW_VERSION -DgenerateBackupPoms=false | ||
echo "Updated version in pom.xml to $NEW_VERSION" | ||
else | ||
echo "Unable to find current version in CHANGELOG, please update pom.xml manually" | ||
echo "Bump the patch version in the `pom.xml` and append `-SNAPSHOT` to it." | ||
exit 1 | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'nokogiri' | ||
|
||
pom = File.open("pom.xml") { |f| Nokogiri::XML(f) } | ||
|
||
versions = pom.xpath("//xmlns:dependency/xmlns:version[../xmlns:groupId/text() = 'io.cucumber']") | ||
versions.each do |version| | ||
return version unless version.content =~ /^\d+\.\d+\.\d+$/ | ||
major, minor, patch = version.content.split('.').map {|i| i.to_i} | ||
version.content = "[#{major}.#{minor}.#{patch},#{major+1}.0.0)" | ||
end | ||
|
||
File.open("pom.xml", "w:UTF-8") { |f| f.write(pom.to_xml) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain those changes here?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I added the new module, I noticed that the message was misleading. It mentioned "io.cucumber" needs to be the package, but it's actually checking for io.cucumber + {sub-module}. After spinning my tires on that, I updated the message to make it clear.
And sub-modules with
-
in them need to be replaced with/
just like you are already doing with.
that waygherkin-utils
becomesio/cucumber/gherkin/utils