├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ ├── config.yml
│ └── feature_request.md
├── dependabot.yml
├── issue_template.md
└── workflows
│ ├── codeql-analysis.yml
│ ├── release_on_pr.yml
│ └── tests.yml
├── .gitignore
├── .gitmodules
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE.txt
├── README.md
├── build
└── make.go
├── checkstyle.xml
├── gauge-java.go
├── genproto.sh
├── go.mod
├── java.json
├── notice.md
├── pom.xml
└── src
├── META-INF
└── MANIFEST.MF
├── main
└── java
│ ├── com
│ └── thoughtworks
│ │ └── gauge
│ │ ├── AfterClassSteps.java
│ │ ├── AfterScenario.java
│ │ ├── AfterSpec.java
│ │ ├── AfterStep.java
│ │ ├── AfterSuite.java
│ │ ├── BeforeClassSteps.java
│ │ ├── BeforeScenario.java
│ │ ├── BeforeSpec.java
│ │ ├── BeforeStep.java
│ │ ├── BeforeSuite.java
│ │ ├── ClassInitializer.java
│ │ ├── ClassInstanceManager.java
│ │ ├── ClasspathHelper.java
│ │ ├── ContinueOnFailure.java
│ │ ├── DefaultClassInitializer.java
│ │ ├── ExecutionContext.java
│ │ ├── FileHelper.java
│ │ ├── Gauge.java
│ │ ├── GaugeConstant.java
│ │ ├── GaugeRuntime.java
│ │ ├── Logger.java
│ │ ├── MessageCollector.java
│ │ ├── Operator.java
│ │ ├── RowSizeMismatchException.java
│ │ ├── RunnerServiceHandler.java
│ │ ├── Scenario.java
│ │ ├── ScreenshotCollector.java
│ │ ├── SkipScenarioException.java
│ │ ├── Specification.java
│ │ ├── Step.java
│ │ ├── StepDetails.java
│ │ ├── StepRegistryEntry.java
│ │ ├── StepValue.java
│ │ ├── Table.java
│ │ ├── TableCell.java
│ │ ├── TableRow.java
│ │ ├── Util.java
│ │ ├── command
│ │ ├── GaugeCommandFactory.java
│ │ ├── GaugeJavaCommand.java
│ │ ├── SetupCommand.java
│ │ └── StartCommand.java
│ │ ├── connection
│ │ ├── MessageProcessorFactory.java
│ │ └── StubImplementationCodeProcessor.java
│ │ ├── datastore
│ │ ├── DataStore.java
│ │ ├── DataStoreFactory.java
│ │ ├── DataStoreInitializer.java
│ │ ├── ScenarioDataStore.java
│ │ ├── SpecDataStore.java
│ │ └── SuiteDataStore.java
│ │ ├── execution
│ │ ├── AbstractExecutionStage.java
│ │ ├── ExecutionInfoMapper.java
│ │ ├── ExecutionPipeline.java
│ │ ├── ExecutionStage.java
│ │ ├── ExecutorPool.java
│ │ ├── HookExecutionStage.java
│ │ ├── HooksExecutor.java
│ │ ├── MethodExecutor.java
│ │ ├── StepExecutionStage.java
│ │ └── parameters
│ │ │ ├── DynamicParametersReplacer.java
│ │ │ ├── ParametersExtractor.java
│ │ │ ├── ParsingException.java
│ │ │ └── parsers
│ │ │ ├── base
│ │ │ ├── CustomParameterParser.java
│ │ │ ├── ParameterParser.java
│ │ │ └── ParameterParsingChain.java
│ │ │ ├── converters
│ │ │ ├── StringToPrimitiveConverter.java
│ │ │ └── TableConverter.java
│ │ │ └── types
│ │ │ ├── EnumParameterParser.java
│ │ │ ├── PrimitiveParameterParser.java
│ │ │ ├── PrimitivesConverter.java
│ │ │ └── TableParameterParser.java
│ │ ├── hook
│ │ └── Hook.java
│ │ ├── processor
│ │ ├── CacheFileRequestProcessor.java
│ │ ├── ClearObjectCache.java
│ │ ├── DefaultMessageProcessor.java
│ │ ├── ExecuteStepProcessor.java
│ │ ├── IMessageProcessor.java
│ │ ├── KillProcessProcessor.java
│ │ ├── MethodExecutionMessageProcessor.java
│ │ ├── RefactorRequestProcessor.java
│ │ ├── ScenarioExecutionEndingProcessor.java
│ │ ├── ScenarioExecutionStartingProcessor.java
│ │ ├── SpecExecutionEndingProcessor.java
│ │ ├── SpecExecutionStartingProcessor.java
│ │ ├── StepExecutionEndingProcessor.java
│ │ ├── StepExecutionStartingProcessor.java
│ │ ├── StepNameRequestProcessor.java
│ │ ├── StepNamesRequestProcessor.java
│ │ ├── StepPositionsRequestProcessor.java
│ │ ├── SuiteExecutionEndingProcessor.java
│ │ ├── SuiteExecutionStartingProcessor.java
│ │ └── ValidateStepProcessor.java
│ │ ├── refactor
│ │ ├── Diff.java
│ │ ├── FileModifier.java
│ │ ├── JavaParseWorker.java
│ │ ├── JavaRefactoring.java
│ │ ├── JavaRefactoringElement.java
│ │ ├── RefactoringException.java
│ │ ├── RefactoringMethodVisitor.java
│ │ └── RefactoringResult.java
│ │ ├── registry
│ │ ├── ClassInitializerRegistry.java
│ │ ├── HooksRegistry.java
│ │ └── StepRegistry.java
│ │ ├── scan
│ │ ├── ClasspathScanner.java
│ │ ├── CustomClassInitializerScanner.java
│ │ ├── HooksScanner.java
│ │ ├── IScanner.java
│ │ ├── RegistryMethodVisitor.java
│ │ ├── StaticScanner.java
│ │ ├── StepsScanner.java
│ │ └── StepsUtil.java
│ │ ├── screenshot
│ │ ├── CustomScreenshot.java
│ │ ├── CustomScreenshotScanner.java
│ │ ├── CustomScreenshotWriter.java
│ │ ├── ICustomScreenshotGrabber.java
│ │ └── ScreenshotFactory.java
│ │ └── tag
│ │ ├── AndMatcher.java
│ │ ├── OrMatcher.java
│ │ ├── SimpleTagMatcher.java
│ │ └── TagMatcher.java
│ └── gauge
│ └── messages
│ ├── Messages.java
│ ├── RunnerGrpc.java
│ ├── Services.java
│ └── Spec.java
└── test
├── java
└── com
│ └── thoughtworks
│ └── gauge
│ ├── ClassInstanceManagerTest.java
│ ├── ExecutionContextTest.java
│ ├── FileHelperTest.java
│ ├── MessageCollectorTest.java
│ ├── ScreenshotCollectorTest.java
│ ├── TableRowTest.java
│ ├── TableTest.java
│ ├── TestStepImplClass.java
│ ├── UtilTest.java
│ ├── execution
│ ├── AbstractExecutionStageTest.java
│ ├── ExecutionInfoMapperTest.java
│ ├── ExecutionPipelineTest.java
│ ├── HooksExecutorTest.java
│ ├── ParameterTestHelpers.java
│ ├── StepExecutionStageTest.java
│ └── parameters
│ │ ├── DynamicParametersReplacerTest.java
│ │ ├── ParametersExtractorTest.java
│ │ └── parsers
│ │ └── types
│ │ ├── EnumParameterParserTest.java
│ │ ├── PrimitiveParameterParserTest.java
│ │ └── TableParameterParserTest.java
│ ├── hook
│ └── HookTest.java
│ ├── processor
│ ├── CacheFileRequestProcessorTest.java
│ ├── DefaultMessageProcessorTest.java
│ ├── StepNameRequestProcessorTest.java
│ ├── StepPositionsRequestProcessorTest.java
│ ├── StubImplementationCodeProcessorTest.java
│ └── ValidateStepProcessorTest.java
│ ├── refactor
│ └── JavaRefactoringTest.java
│ ├── registry
│ ├── HooksRegistryTest.java
│ └── StepRegistryTest.java
│ ├── scan
│ ├── StaticScannerTest.java
│ └── StepsScannerTest.java
│ ├── tag
│ ├── AndMatcherTest.java
│ └── OrMatcherTest.java
│ └── test
│ ├── AnEnum.java
│ └── TestValues.java
└── resources
└── test
└── files
├── Empty.java
├── foo.java
├── fooAliases.java
├── formatted
├── StepImpl.java
└── StepImplWithComments.java
└── unformatted
└── UnFormattedStepImpl.java
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps (or project) to reproduce the behavior:
15 | 1. Initialise a gauge project
16 | 2. Use the following piece of code
17 | 3. Run the gauge command
18 | 5. See error
19 |
20 | ```
21 | $ gauge init java
22 | $ gauge run specs
23 | ```
24 |
25 | **Logs**
26 |
27 | ```
28 | Paste any log or error messages here
29 | ```
30 |
31 | **Expected behavior**
32 | A clear and concise description of what you expected to happen.
33 |
34 | **Screenshots**
35 | If applicable, add screenshots to help explain your problem.
36 |
37 |
38 | **Versions:**
39 | - OS [e.g. 10.15.6 (19G2021) please be specific ]
40 | - Java version
41 | - Maven/Gradle version
42 |
43 |
44 |
45 | ```
46 | gauge -v
47 | ```
48 |
49 |
50 | **Additional context**
51 | Add any other context about the problem here.
52 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: false
2 | contact_links:
3 | - name: Gauge Community Support
4 | url: https://spectrum.chat/gauge
5 | about: Please ask and answer questions here.
6 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: gomod
4 | directory: "/"
5 | schedule:
6 | interval: monthly
7 | allow:
8 | - dependency-type: all
9 | groups:
10 | go:
11 | patterns:
12 | - "*"
13 | - package-ecosystem: "github-actions"
14 | directory: "/"
15 | schedule:
16 | interval: monthly
17 | groups:
18 | github-actions:
19 | patterns:
20 | - "*"
21 | - package-ecosystem: maven
22 | directory: "/"
23 | schedule:
24 | interval: monthly
25 | groups:
26 | maven-dependencies:
27 | patterns:
28 | - "*"
29 |
--------------------------------------------------------------------------------
/.github/issue_template.md:
--------------------------------------------------------------------------------
1 |
10 |
11 | ### Expected behavior
12 | Tell us what should happen
13 |
14 | ### Actual behavior
15 | Tell us what happens instead
16 |
17 | ### Steps to reproduce
18 | 1.
19 | 2.
20 | 3.
21 |
22 | ### Gauge version
23 | ```
24 | Run gauge -v on your system and paste the results here.
25 | ```
26 |
--------------------------------------------------------------------------------
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | # For most projects, this workflow file will not need changing; you simply need
2 | # to commit it to your repository.
3 | #
4 | # You may wish to alter this file to override the set of languages analyzed,
5 | # or to provide custom queries or build logic.
6 | #
7 | # ******** NOTE ********
8 | # We have attempted to detect the languages in your repository. Please check
9 | # the `language` matrix defined below to confirm you have the correct set of
10 | # supported CodeQL languages.
11 | #
12 | name: "CodeQL"
13 |
14 | on:
15 | push:
16 | branches: [ master ]
17 | pull_request:
18 | # The branches below must be a subset of the branches above
19 | branches: [ master ]
20 | schedule:
21 | - cron: '16 22 * * 2'
22 |
23 | jobs:
24 | analyze:
25 | name: Analyze
26 | runs-on: ubuntu-latest
27 | permissions:
28 | actions: read
29 | contents: read
30 | security-events: write
31 |
32 | strategy:
33 | fail-fast: false
34 | matrix:
35 | language: [ 'go', 'java' ]
36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37 | # Learn more about CodeQL language support at https://git.io/codeql-language-support
38 |
39 | steps:
40 | - name: Checkout repository
41 | uses: actions/checkout@v4
42 |
43 | - name: Set up Go
44 | uses: actions/setup-go@v5
45 | if: matrix.language == 'go'
46 | with:
47 | check-latest: true
48 | go-version-file: 'go.mod'
49 |
50 | # Initializes the CodeQL tools for scanning.
51 | - name: Initialize CodeQL
52 | uses: github/codeql-action/init@v3
53 | with:
54 | languages: ${{ matrix.language }}
55 | # If you wish to specify custom queries, you can do so here or in a config file.
56 | # By default, queries listed here will override any specified in a config file.
57 | # Prefix the list here with "+" to use these queries and those in the config file.
58 | # queries: ./path/to/local/query, your-org/your-repo/queries@main
59 |
60 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
61 | # If this step fails, then you should remove it and run the build manually (see below)
62 | - name: Autobuild
63 | uses: github/codeql-action/autobuild@v3
64 |
65 | # ℹ️ Command-line programs to run using the OS shell.
66 | # 📚 https://git.io/JvXDl
67 |
68 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
69 | # and modify them (or add more) to build your code if your project
70 | # uses a compiled language
71 |
72 | #- run: |
73 | # make bootstrap
74 | # make release
75 |
76 | - name: Perform CodeQL Analysis
77 | uses: github/codeql-action/analyze@v3
78 |
--------------------------------------------------------------------------------
/.github/workflows/release_on_pr.yml:
--------------------------------------------------------------------------------
1 | name: Release on PR Merge
2 |
3 | on: deployment
4 |
5 | jobs:
6 | deploy:
7 | if: github.event.deployment.environment == 'production'
8 | runs-on: ubuntu-latest
9 | env:
10 | MAVEN_GPG_SIGN_KEY: '${{ secrets.MAVEN_GPG_SIGN_KEY }}'
11 | username: '${{ secrets.maven_deploy_username }}'
12 | password: '${{ secrets.maven_deploy_password }}'
13 | passphrase: '${{ secrets.gpg_passphrase }}'
14 | GITHUB_TOKEN: '${{ secrets.GAUGEBOT_GITHUB_TOKEN }}'
15 | CI: true
16 |
17 | steps:
18 | - uses: actions/checkout@v4
19 | - name: Set up JDK
20 | uses: actions/setup-java@v4
21 | with:
22 | distribution: 'temurin'
23 | java-version: '21'
24 |
25 | - name: Set up Maven
26 | uses: stCarolas/setup-maven@v5
27 | with:
28 | maven-version: 3.9.9
29 |
30 | - name: Setup maven
31 | run: |
32 | echo -e "$MAVEN_GPG_SIGN_KEY" | gpg --import --batch -
33 | gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys $gpgkey
34 | rm -rf $HOME/.m2
35 | mkdir -p $HOME/.m2
36 | echo -e "\n\n\ncentral\n$username\n$password\n\n\n" > $HOME/.m2/settings.xml
37 |
38 | - name: Setup git
39 | run: |
40 | git config --global user.name "$(git --no-pager log --format=format:'%an' -n 1)"
41 | git config --global user.email "$(git --no-pager log --format=format:'%ae' -n 1)"
42 |
43 | - name: Set up Go
44 | uses: actions/setup-go@v5
45 | with:
46 | check-latest: true
47 | go-version-file: 'go.mod'
48 |
49 | - name: Build artifacts
50 | run: go run build/make.go --all-platforms && go run build/make.go --all-platforms --distro
51 | shell: bash
52 |
53 | - name: Deploy on github
54 | run: |
55 | if [ -z "$version" ]; then
56 | version=$(cd deploy && ls gauge-java* | head -1 | sed "s/\.[^\.]*$//" | sed "s/gauge-java-//" | sed "s/-[a-z]*\.[a-z0-9_]*$//")
57 | fi
58 | echo "VERSION=$version" >> $GITHUB_ENV
59 |
60 | echo "---------------------------"
61 | echo "Updating release v$version"
62 | echo "---------------------------"
63 | echo -e "Gauge Java v$version\n\n" >desc.txt
64 | release_description=$(ruby -e "$(curl -sSfL https://github.com/getgauge/gauge/raw/master/build/create_release_text.rb)" getgauge gauge-java)
65 | echo "$release_description" >> desc.txt
66 | gh release create --title "Gauge Java v${version}" --notes-file ./desc.txt "v${version}" deploy/gauge-java*
67 |
68 | - name: Deploy on maven central
69 | run: |
70 | mvn -q clean deploy -Dgpg.passphrase=$passphrase
71 |
72 |
73 | - name: Update metadata in gauge-repository
74 | run: |
75 | git clone https://github.com/getgauge/gauge-repository.git
76 | cd gauge-repository
77 | python update_metadata.py java $VERSION
78 | commit_message=$(echo -e "Update java to v$VERSION")
79 | git commit -am "$commit_message"
80 | git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/getgauge/gauge-repository.git" master
81 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | # Package Files #
4 | *.jar
5 | *.war
6 | *.ear
7 |
8 | libs
9 | .idea/workspace.xml
10 |
11 | gauge-java
12 | tags
13 | src/src
14 | *.exe
15 | target
16 | out
17 | .idea/
18 |
19 | #go deps
20 | src/github.com
21 | tmp
22 | deploy
23 | artifacts
24 | *.iml
25 |
26 | bin
27 |
28 | .DS_Store
29 | .classpath
30 | .project
31 | .settings/
32 | .vscode/
33 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "gauge-proto"]
2 | path = gauge-proto
3 | url = https://github.com/getgauge/gauge-proto
4 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | ## Contributing to Gauge
2 |
3 | Contributions to Gauge are welcome and appreciated. Please read this document to understand the process for contributing.
4 |
5 | ## Gauge Core v/s Plugins
6 |
7 | Gauge Core is a project that has features that would reflect across all Gauge use cases. These features are typically agnostic of the user's choice of implementation language.
8 |
9 | Plugins are meant to do something specific. These could be adding support for a new language, or have a new report etc.
10 |
11 | So, depending on where you see your contribution fit, please focus on the respective repository.
12 |
13 | ## Contribution process
14 |
15 | Please read about the Contribution Process [here](https://github.com/getgauge/gauge/blob/master/CONTRIBUTING.md), if you are happy please sign the [Contributor's License Agreement](https://gauge-bot.herokuapp.com/cla/).
16 |
17 | ## How can I contribute
18 |
19 | Contributions can be of many forms:
20 |
21 | - Open an issue, or participate in an existing one.
22 | - Write some code, and send us a pull request.
23 | - Enhance the documentation
24 | - Participate in design discussions on Google Groups
25 |
26 | If you need help in getting started with contribution, feel free to reach out on the [Google Groups](https://groups.google.com/forum/#!forum/getgauge) or [Gitter](https://gitter.im/getgauge/chat).
27 |
28 |
29 | ## Bump up gauge-java version
30 |
31 | * Update the version in `java.json` file.
32 |
33 | Ex:
34 | ```diff
35 | "id": "java",
36 | - "version": "0.7.5",
37 | + "version": "0.7.6",
38 | ```
39 |
40 | * Update the productVersion property in `pom.xml`.
41 |
42 | Ex:
43 |
44 |
45 | * Update the version in `pom.xml`.
46 |
47 | Ex:
48 |
49 | ```diff
50 | gauge-java
51 | - 0.11.3
52 | + 0.11.4
53 | Java plugin for Gauge
54 | ```
55 |
--------------------------------------------------------------------------------
/genproto.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # *----------------------------------------------------------------
4 | # * Copyright (c) ThoughtWorks, Inc.
5 | # * Licensed under the Apache License, Version 2.0
6 | # * See LICENSE.txt in the project root for license information.
7 | # *----------------------------------------------------------------*/
8 |
9 | #Using protoc version 2.6.1
10 | for filename in gauge-proto/*.proto; do
11 | newName="$filename-bkp"
12 | sed 's/option java_package = "com.thoughtworks.gauge";/option java_package = "gauge.messages";/' "$filename" > "$newName"
13 | rm "$filename"
14 | cp "$newName" "$filename"
15 | rm "$newName"
16 | done
17 | mvn protobuf:compile-custom protobuf:compile
18 |
19 |
20 | cp target/generated-sources/protobuf/java/gauge/messages/Messages.java src/main/java/gauge/messages
21 | cp target/generated-sources/protobuf/java/gauge/messages/Spec.java src/main/java/gauge/messages
22 | cp target/generated-sources/protobuf/java/gauge/messages/Services.java src/main/java/gauge/messages
23 |
24 | cp target/generated-sources/protobuf/grpc-java/gauge/messages/RunnerGrpc.java src/main/java/gauge/messages
25 |
26 | cd gauge-proto && git checkout . && cd ..
27 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/getgauge/gauge-java
2 |
3 | go 1.24
4 |
--------------------------------------------------------------------------------
/java.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": "java",
3 | "version": "0.12.0",
4 | "description": "Java support for gauge",
5 | "install": {
6 | "windows": [],
7 | "linux": [],
8 | "darwin": []
9 | },
10 | "run": {
11 | "windows": [
12 | "gauge-java",
13 | "--start"
14 | ],
15 | "linux": [
16 | "gauge-java",
17 | "--start"
18 | ],
19 | "darwin": [
20 | "gauge-java",
21 | "--start"
22 | ]
23 | },
24 | "init": {
25 | "windows": [
26 | "gauge-java",
27 | "--init"
28 | ],
29 | "linux": [
30 | "gauge-java",
31 | "--init"
32 | ],
33 | "darwin": [
34 | "gauge-java",
35 | "--init"
36 | ]
37 | },
38 | "lib": "libs",
39 | "multithreaded": true,
40 | "gaugeVersionSupport": {
41 | "minimum": "1.6.7",
42 | "maximum": ""
43 | },
44 | "lspLangId": "java",
45 | "gRPCSupport": true
46 | }
47 |
--------------------------------------------------------------------------------
/notice.md:
--------------------------------------------------------------------------------
1 |
2 | | Dependency Name | Copyright Information | Description | Repo URL | License Type | License URL |
3 | |-----------------|-----------------------|-------------|----------|--------------|-------------|
4 | |guava|Copyright (C) 2012 The Guava Authors|"Google Core Libraries for Java 6+|https://code.google.com/p/guava-libraries/|Apache 2.0|http://www.apache.org/licenses/LICENSE-2.0|
5 | |javassist|Copyright (C) 1999-2015 Shigeru Chiba.|Java bytecode engineering toolkit|http://www.javassist.org/ |Triple License: MPL 1.1, LGPL 2.1, Apache 2.0||
6 | |reflections|Copyright (C) 2004 Sam Hocevar|Java runtime metadata analysis|https://github.com/ronmamo/reflections|wtfpl version 2 |https://code.google.com/p/reflections/source/browse/trunk/COPYING.txt|
7 | |protobuf-java| Copyright 2008 Google Inc.|Java Protocol Buffers runtime library|https://github.com/google/protobuf/tree/master/java|BSD 2 clause license|http://www.opensource.org/licenses/bsd-license.php|
8 |
--------------------------------------------------------------------------------
/src/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 |
3 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/AfterClassSteps.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.lang.annotation.ElementType;
9 | import java.lang.annotation.Retention;
10 | import java.lang.annotation.RetentionPolicy;
11 | import java.lang.annotation.Target;
12 |
13 | /**
14 | * Methods annotated with this hook, will be executed after every step in that particular class.
15 | *
16 | * If there is more than one method annotated with @AfterClassSteps the order of execution is as follows:
17 | *
18 | *
Hooks which are not filtered by tags.
19 | *
Hooks filtered by tags.
20 | *
21 | * If there is more than one hook of these categories, they are executed in reverse alphabetical order based on method names.
22 | *
23 | */
24 | @Target(ElementType.METHOD)
25 | @Deprecated
26 | @Retention(RetentionPolicy.RUNTIME)
27 | public @interface AfterClassSteps {
28 |
29 | /**
30 | * @return Array of tags to filter which steps the hook executes after based on the tags in the current scenario and spec.
31 | */
32 | String[] tags() default {};
33 |
34 | /**
35 | * @return OR: if hook should execute for the current execution context (spec and scenario) containing any of the tags provided
36 | * AND: if hook should execute for the current execution context (spec and scenario) containing all of the tags provided
37 | * Default is AND
38 | */
39 | Operator tagAggregation() default Operator.AND;
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/AfterScenario.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.lang.annotation.ElementType;
9 | import java.lang.annotation.Retention;
10 | import java.lang.annotation.RetentionPolicy;
11 | import java.lang.annotation.Target;
12 |
13 | /**
14 | * Methods annotated with this hook, execute after every scenario execution completes.
15 | * The scenario can be filtered by passing additional attributes.
16 | *
17 | * If there is more than one method annotated with @AfterScenario, the order of execution is as follows:
18 | *
19 | *
Hooks which are not filtered by tags.
20 | *
Hooks filtered by tags.
21 | *
22 | * If there is more than one hook of these categories, they are executed in reverse alphabetical order based on method names.
23 | */
24 | @Target(ElementType.METHOD)
25 | @Retention(RetentionPolicy.RUNTIME)
26 | public @interface AfterScenario {
27 |
28 | /**
29 | * @return Array of tags to filter which scenarios the hook runs after.
30 | */
31 | String[] tags() default {};
32 |
33 | /**
34 | * @return OR: if hook should run for a scenario containing any of the tags provided
35 | * AND: if hook should run for a scenario containing all of the tags provided
36 | * Default is AND
37 | */
38 | Operator tagAggregation() default Operator.AND;
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/AfterSpec.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.lang.annotation.ElementType;
9 | import java.lang.annotation.Retention;
10 | import java.lang.annotation.RetentionPolicy;
11 | import java.lang.annotation.Target;
12 |
13 | /**
14 | * Methods annotated with this hook, execute after every Specification execution completes.
15 | * The specification can be filtered by passing additional attributes.
16 | *
17 | * If there is more than one method annotated with @AfterSpec, the order of execution is as follows:
18 | *
19 | *
Hooks which are not filtered by tags.
20 | *
Hooks filtered by tags.
21 | *
22 | * If there is more than one hook of these categories, they are executed in reverse alphabetical order based on method names.
23 | *
24 | */
25 | @Target(ElementType.METHOD)
26 | @Retention(RetentionPolicy.RUNTIME)
27 | public @interface AfterSpec {
28 |
29 | /**
30 | * @return Array of tags to filter which specifications the hook runs after.
31 | */
32 | String[] tags() default {};
33 |
34 | /**
35 | * @return OR: if hook should run for a specification containing any of the tags provided
36 | * AND: if hook should run for a specification containing all of the tags provided
37 | * Default is AND
38 | */
39 | Operator tagAggregation() default Operator.AND;
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/AfterStep.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.lang.annotation.ElementType;
9 | import java.lang.annotation.Retention;
10 | import java.lang.annotation.RetentionPolicy;
11 | import java.lang.annotation.Target;
12 |
13 | /**
14 | * Methods annotated with this hook, execute after every Step execution completes.
15 | * The steps for which the hook executes can be filtered by passing additional attributes.
16 | *
17 | * If there is more than one method annotated with @AfterStep, the order of execution is as follows:
18 | *
19 | *
Hooks which are not filtered by tags.
20 | *
Hooks filtered by tags.
21 | *
22 | * If there is more than one hook of these categories, they are executed in reverse alphabetical order based on method names.
23 | *
24 | */
25 | @Target(ElementType.METHOD)
26 | @Retention(RetentionPolicy.RUNTIME)
27 | public @interface AfterStep {
28 |
29 | /**
30 | * @return Array of tags to filter which steps the hook runs after.
31 | */
32 | String[] tags() default {};
33 |
34 | /**
35 | * @return OR: if hook should execute for the current execution context (spec and scenario) containing any of the tags provided
36 | * AND: if hook should execute for the current execution context (spec and scenario) containing all of the tags provided
37 | * Default is AND
38 | */
39 | Operator tagAggregation() default Operator.AND;
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/AfterSuite.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.lang.annotation.ElementType;
9 | import java.lang.annotation.Retention;
10 | import java.lang.annotation.RetentionPolicy;
11 | import java.lang.annotation.Target;
12 |
13 | /**
14 | * Methods annotated with this hook, execute after the entire suite (all specs) execution completes.
15 |
If there is more than one method annotated with @AfterSuite, they are executed in reverse alphabetical order of their method names.
16 | */
17 | @Target(ElementType.METHOD)
18 | @Retention(RetentionPolicy.RUNTIME)
19 | public @interface AfterSuite {
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/BeforeClassSteps.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.lang.annotation.ElementType;
9 | import java.lang.annotation.Retention;
10 | import java.lang.annotation.RetentionPolicy;
11 | import java.lang.annotation.Target;
12 |
13 | /**
14 | * Methods annotated with this hook, will execute before every step in that particular class.
15 | *
16 | * If there is more than one method annotated with @BeforeClassSteps the order of execution is as follows:
17 | *
18 | *
Hooks which are not filtered by tags.
19 | *
Hooks filtered by tags.
20 | *
21 | * If there is more than one hook of these categories, they are alphabetically sorted based on method names.
22 | *
23 | */
24 | @Target(ElementType.METHOD)
25 | @Deprecated
26 | @Retention(RetentionPolicy.RUNTIME)
27 | public @interface BeforeClassSteps {
28 |
29 | /**
30 | * @return Array of tags to filter which steps the hook executes before based on the tags in the current scenario and spec.
31 | */
32 | String[] tags() default {};
33 |
34 | /**
35 | * @return OR: if hook should execute for the current execution context (spec and scenario) containing any of the tags provided
36 | * AND: if hook should execute for the current execution context (spec and scenario) containing all of the tags provided
37 | * Default is AND
38 | */
39 | Operator tagAggregation() default Operator.AND;
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/BeforeScenario.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.lang.annotation.ElementType;
9 | import java.lang.annotation.Retention;
10 | import java.lang.annotation.RetentionPolicy;
11 | import java.lang.annotation.Target;
12 |
13 | /**
14 | * Methods annotated with this hook, execute before every scenario execution completes.
15 | * The scenario can be filtered by passing additional attributes.
16 | *
17 | * If there is more than one method annotated with @BeforeScenario, the order of execution is as follows:
18 | *
19 | *
Hooks which are not filtered by tags.
20 | *
Hooks filtered by tags.
21 | *
22 | * If there is more than one hook of these categories, they are executed in alphabetical order based on method names.
23 | *
24 | */
25 | @Target(ElementType.METHOD)
26 | @Retention(RetentionPolicy.RUNTIME)
27 | public @interface BeforeScenario {
28 |
29 | /**
30 | * @return Array of tags to filter which scenarios the hook runs before.
31 | */
32 | String[] tags() default {};
33 |
34 | /**
35 | * @return OR: if hook should run for a scenario containing any of the tags provided
36 | * AND: if hook should run for a scenario containing all of the tags provided
37 | * Default is AND
38 | */
39 | Operator tagAggregation() default Operator.AND;
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/BeforeSpec.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.lang.annotation.ElementType;
9 | import java.lang.annotation.Retention;
10 | import java.lang.annotation.RetentionPolicy;
11 | import java.lang.annotation.Target;
12 |
13 | /**
14 | * Methods annotated with this hook, execute before every Specification execution completes.
15 | * The specification can be filtered by passing additional attributes.
16 | *
If there is more than one method annotated with @BeforeSpec, the order of execution is as follows:
17 | *
18 | *
Hooks which are not filtered by tags.
19 | *
Hooks filtered by tags.
20 | *
21 | * If there is more than one hook of these categories, they are executed in alphabetical order based on method names.
22 | *
23 | */
24 | @Target(ElementType.METHOD)
25 | @Retention(RetentionPolicy.RUNTIME)
26 | public @interface BeforeSpec {
27 |
28 | /**
29 | * @return Array of tags to filter which specifications the hook runs before.
30 | */
31 | String[] tags() default {};
32 |
33 | /**
34 | * @return OR: if hook should run for a specification containing any of the tags provided
35 | * AND: if hook should run for a specification containing all of the tags provided
36 | * Default is AND
37 | */
38 | Operator tagAggregation() default Operator.AND;
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/BeforeStep.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.lang.annotation.ElementType;
9 | import java.lang.annotation.Retention;
10 | import java.lang.annotation.RetentionPolicy;
11 | import java.lang.annotation.Target;
12 |
13 | /**
14 | * Methods annotated with this hook, execute before every Step execution completes.
15 | * The steps for which the hook executes can be filtered by passing additional attributes
16 | *
17 | * If there is more than one method annotated with @BeforeStep, the order of execution is as follows:
18 | *
19 | *
Hooks which are not filtered by tags.
20 | *
Hooks filtered by tags.
21 | *
22 | * If there is more than one hook of these categories, they are executed in alphabetical order based on method names.
23 | *
24 | */
25 | @Target(ElementType.METHOD)
26 | @Retention(RetentionPolicy.RUNTIME)
27 | public @interface BeforeStep {
28 |
29 | /**
30 | * @return Array of tags to filter which steps the hook runs before.
31 | */
32 | String[] tags() default {};
33 |
34 | /**
35 | * @return OR: if hook should execute for the current execution context (spec and scenario) containing any of the tags provided
36 | * AND: if hook should execute for the current execution context (spec and scenario) containing all of the tags provided
37 | * Default is AND
38 | */
39 | Operator tagAggregation() default Operator.AND;
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/BeforeSuite.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.lang.annotation.ElementType;
9 | import java.lang.annotation.Retention;
10 | import java.lang.annotation.RetentionPolicy;
11 | import java.lang.annotation.Target;
12 |
13 | /**
14 | * Methods annotated with this hook, execute before the entire suite (all specs) execution completes.
15 | * If there is more than one method annotated with @BeforeSuite, they are executed in alphabetical order based on method names.
16 | */
17 | @Target(ElementType.METHOD)
18 | @Retention(RetentionPolicy.RUNTIME)
19 | public @interface BeforeSuite {
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/ClassInitializer.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | /**
9 | * Interface to provide a Custom Class Initializer for managing Class Objects.
10 | */
11 | public interface ClassInitializer {
12 | Object initialize(Class> classToInitialize) throws Exception;
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/ClassInstanceManager.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.util.HashMap;
9 | import java.util.Map;
10 |
11 | /**
12 | * Manages class instance creation, lifetime and caching.
13 | */
14 | public class ClassInstanceManager {
15 | private final Map, Object> classInstanceMap = new HashMap<>();
16 | private static final ThreadLocal INITIALIZER = new InheritableThreadLocal<>();
17 |
18 | public ClassInstanceManager() {
19 | INITIALIZER.set(new DefaultClassInitializer());
20 | }
21 |
22 | public ClassInstanceManager(ClassInitializer classInitializer) {
23 | INITIALIZER.set(classInitializer);
24 | }
25 |
26 | public Object get(Class> declaringClass) throws Exception {
27 | Object classInstance = classInstanceMap.get(declaringClass);
28 | if (classInstance == null) {
29 | classInstance = getInitializer().initialize(declaringClass);
30 | classInstanceMap.put(declaringClass, classInstance);
31 | }
32 | return classInstance;
33 | }
34 |
35 | public static void setClassInitializer(ClassInitializer classInitializer) {
36 | INITIALIZER.set(classInitializer);
37 | }
38 |
39 | public void clearCache() {
40 | this.classInstanceMap.clear();
41 | }
42 |
43 | private static ClassInitializer getInitializer() {
44 | return INITIALIZER.get();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/ClasspathHelper.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.net.URL;
9 | import java.util.ArrayList;
10 | import java.util.Collection;
11 |
12 | public class ClasspathHelper {
13 |
14 | public static Collection getUrls() {
15 | final String packagesToScan = System.getenv(GaugeConstant.PACKAGE_TO_SCAN);
16 | if (packagesToScan != null) {
17 | Collection urls = new ArrayList<>();
18 | for (String packageToScan : packagesToScan.split(",")) {
19 | urls.addAll(org.reflections.util.ClasspathHelper.forPackage(packageToScan.trim()));
20 | }
21 | return urls;
22 | }
23 | return org.reflections.util.ClasspathHelper.forJavaClassPath();
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/ContinueOnFailure.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.lang.annotation.ElementType;
9 | import java.lang.annotation.Retention;
10 | import java.lang.annotation.RetentionPolicy;
11 | import java.lang.annotation.Target;
12 |
13 | /**
14 | * Annotation added to methods which are Gauge Step implementations.
15 | */
16 | @Target(ElementType.METHOD)
17 | @Retention(RetentionPolicy.RUNTIME)
18 | public @interface ContinueOnFailure {
19 | Class[] value() default Throwable.class;
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/DefaultClassInitializer.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | public class DefaultClassInitializer implements ClassInitializer {
9 |
10 | @Override
11 | public Object initialize(Class> classToInitialize) throws Exception {
12 | return Class.forName(classToInitialize.getName()).newInstance();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/ExecutionContext.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.util.ArrayList;
9 | import java.util.HashSet;
10 | import java.util.List;
11 |
12 | /**
13 | * Gives the information about the current execution at runtime - spec, scenario, step that is running.
14 | */
15 | public class ExecutionContext {
16 | private final Specification currentSpecification;
17 | private final Scenario currentScenario;
18 | private final StepDetails currentStep;
19 |
20 | public ExecutionContext(Specification specification, Scenario scenario, StepDetails stepDetails) {
21 | this.currentSpecification = specification;
22 | this.currentScenario = scenario;
23 | this.currentStep = stepDetails;
24 | }
25 |
26 | public ExecutionContext() {
27 | this.currentSpecification = new Specification();
28 | this.currentScenario = new Scenario();
29 | this.currentStep = new StepDetails();
30 | }
31 |
32 | /**
33 | * @return - The Current Specification that is executing.
34 | * Returns null in BeforeSuite and AfterSuite levels as no spec is executing then.
35 | */
36 | public Specification getCurrentSpecification() {
37 | return currentSpecification;
38 | }
39 |
40 | /**
41 | * @return - The Current Scenario that is executing.
42 | * Returns null in BeforeSuite, AfterSuite, BeforeSpec levels as no scenario is executing then.
43 | */
44 | public Scenario getCurrentScenario() {
45 | return currentScenario;
46 | }
47 |
48 | /**
49 | * @return - The Current Step that is executing.
50 | * Returns null in BeforeSuite, AfterSuite, BeforeSpec, AfterSpec, BeforeScenario levels as no step is executing then.
51 | */
52 | public StepDetails getCurrentStep() {
53 | return currentStep;
54 | }
55 |
56 | /**
57 | * @return - All the valid tags (including scenario and spec tags) at the execution level.
58 | */
59 | public List getAllTags() {
60 | HashSet specTags = new HashSet<>(currentSpecification.getTags());
61 | specTags.addAll(currentScenario.getTags());
62 | return new ArrayList<>(specTags);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/Gauge.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import com.thoughtworks.gauge.screenshot.ScreenshotFactory;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | public class Gauge {
14 |
15 | private static final ThreadLocal> MESSAGES = new InheritableThreadLocal<>() {
16 | @Override
17 | protected List initialValue() {
18 | return new ArrayList<>();
19 | }
20 | };
21 | private static ClassInstanceManager instanceManager;
22 | private static final ThreadLocal> SCREENSHOTS = new InheritableThreadLocal<>() {
23 | @Override
24 | protected List initialValue() {
25 | return new ArrayList<>();
26 | }
27 | };
28 |
29 | public static void setInstanceManager(ClassInstanceManager instanceManager) {
30 | Gauge.instanceManager = instanceManager;
31 | }
32 |
33 | /**
34 | * @param message - Custom message that can be added at runtime that will be visible in reports.
35 | */
36 | public static void writeMessage(String message) {
37 | getMessages().add(message);
38 | }
39 |
40 | /**
41 | * @param format - Custom messages that can be added at runtime that will be visible in reports.
42 | * Format of the string message
43 | * @param args - Arguments for the format string as passed into String.format()
44 | */
45 | public static void writeMessage(String format, String... args) {
46 | getMessages().add(String.format(format, args));
47 | }
48 |
49 | static List getMessages() {
50 | return MESSAGES.get();
51 | }
52 |
53 | public static void captureScreenshot() {
54 | String screenshotFileName = new ScreenshotFactory(instanceManager).getScreenshotBytes();
55 | getScreenshots().add(screenshotFileName);
56 | }
57 |
58 | static List getScreenshots() {
59 | return SCREENSHOTS.get();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/GaugeConstant.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | public class GaugeConstant {
9 | public static final String SCREENSHOT_ON_FAILURE_ENABLED = "screenshot_on_failure";
10 | public static final String PACKAGE_TO_SCAN = "package_to_scan";
11 | public static final String GAUGE_PROJECT_ROOT = "GAUGE_PROJECT_ROOT";
12 | public static final String GAUGE_CUSTOM_COMPILE_DIR = "gauge_custom_compile_dir";
13 | public static final String DEFAULT_SRC_DIR = "src/test/java";
14 | public static final String[] DEFAULT_SRC_DIRS = {"src/main/java", DEFAULT_SRC_DIR};
15 | public static final String SCREENSHOTS_DIR_ENV = "gauge_screenshots_dir";
16 | public static final String STREAMS_COUNT_ENV = "GAUGE_PARALLEL_STREAMS_COUNT";
17 | public static final String ENABLE_MULTITHREADING_ENV = "enable_multithreading";
18 | public static final String SCAN_EXTERNAL_LIBS = "scan_external_dependencies";
19 | public static final String LOCALHOST = "127.0.0.1";
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/GaugeRuntime.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import com.thoughtworks.gauge.command.GaugeCommandFactory;
9 |
10 | /**
11 | * Holds Main for starting Gauge-java 1. Makes connections to gauge 2. Scans
12 | * Classpath 3. Dispatched all message responses
13 | */
14 | public class GaugeRuntime {
15 | public static void main(String[] args) throws Exception {
16 | Thread.setDefaultUncaughtExceptionHandler((t, e) -> Logger.fatal("Error in thread " + t.getId(), e));
17 | if (args.length == 0) {
18 | System.out.println("usage: GaugeJava --");
19 | System.exit(1);
20 | }
21 | String phase = args[0];
22 | GaugeCommandFactory gaugeCommandFactory = new GaugeCommandFactory();
23 | gaugeCommandFactory.getExecutor(phase).execute();
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/Logger.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import org.assertj.core.util.Throwables;
9 | import org.json.JSONObject;
10 |
11 | public class Logger {
12 | public static void info(String message) {
13 | logToStdout("info", message);
14 | }
15 |
16 | public static void error(String message) {
17 | logToStdErr("error", message);
18 | }
19 |
20 | public static void error(String message, Throwable t) {
21 | error(String.format("%s\n%s\n%s", message, t.getMessage(), Throwables.getStackTrace(t)));
22 | }
23 |
24 | public static void warning(String message) {
25 | logToStdout("warning", message);
26 | }
27 |
28 | public static void warning(String message, Throwable t) {
29 | warning(String.format("%s\n%s\n%s", message, t.getMessage(), Throwables.getStackTrace(t)));
30 | }
31 |
32 | public static void debug(String message) {
33 | logToStdout("debug", message);
34 | }
35 |
36 | public static void fatal(String message) {
37 | logToStdErr("fatal", message);
38 | System.exit(1);
39 | }
40 |
41 | public static void fatal(String message, Throwable t) {
42 | fatal(String.format("%s\n%s\n%s", message, t.getMessage(), Throwables.getStackTrace(t)));
43 |
44 | }
45 |
46 | private static void logToStdout(String level, String message) {
47 | System.out.println(getJsonObject(level, message));
48 | }
49 |
50 | private static JSONObject getJsonObject(String level, String message) {
51 | JSONObject jsonObj = new JSONObject();
52 | jsonObj.put("logLevel", level);
53 | jsonObj.put("message", message);
54 | return jsonObj;
55 | }
56 |
57 | private static void logToStdErr(String level, String message) {
58 | System.err.println(getJsonObject(level, message));
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/MessageCollector.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import gauge.messages.Spec;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | import java.util.Objects;
13 |
14 | import static com.thoughtworks.gauge.Gauge.getMessages;
15 |
16 | public class MessageCollector {
17 | public Spec.ProtoExecutionResult addPendingMessagesTo(Spec.ProtoExecutionResult result) {
18 | List messages = getPendingMessages();
19 | return addPendingMessages(result, messages);
20 | }
21 |
22 | Spec.ProtoExecutionResult addPendingMessages(Spec.ProtoExecutionResult result, List messages) {
23 | Spec.ProtoExecutionResult.Builder builder = Spec.ProtoExecutionResult.newBuilder(result);
24 | messages.stream().filter(Objects::nonNull).forEach(builder::addMessage);
25 | return builder.build();
26 | }
27 |
28 | private static List getPendingMessages() {
29 | List pendingMessages = new ArrayList<>(getMessages());
30 | clear();
31 | return pendingMessages;
32 | }
33 |
34 | private static void clear() {
35 | getMessages().clear();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/Operator.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | /**
9 | * Operator for performing Tag aggregation mechanism in Execution Hooks.
10 | */
11 | public enum Operator {
12 | AND, OR
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/RowSizeMismatchException.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | public class RowSizeMismatchException extends RuntimeException {
9 | public RowSizeMismatchException(String error) {
10 | super(error);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/Scenario.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | /**
12 | * Holds the information about the current Scenario executing at Runtime.
13 | */
14 | public class Scenario {
15 | private String name = "";
16 | private Boolean isFailing = false;
17 | private List tags = new ArrayList<>();
18 |
19 | public Scenario(String name, boolean isFailing, List tags) {
20 | this.name = name;
21 | this.isFailing = isFailing;
22 | this.tags = tags;
23 | }
24 |
25 | public Scenario() {
26 | }
27 |
28 | /**
29 | * @return List of all tags in just the scenario
30 | */
31 | public List getTags() {
32 | return tags;
33 | }
34 |
35 | /**
36 | * @return True if the scenario or spec is failing
37 | */
38 | public Boolean getIsFailing() {
39 | return isFailing;
40 | }
41 |
42 | /**
43 | * @return Name of the Scenario as mentioned in the scenario heading
44 | */
45 | public String getName() {
46 | return name;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/ScreenshotCollector.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import gauge.messages.Spec;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | import static com.thoughtworks.gauge.Gauge.getScreenshots;
14 |
15 | public class ScreenshotCollector {
16 | public Spec.ProtoExecutionResult addPendingScreenshotTo(Spec.ProtoExecutionResult result) {
17 | ArrayList screenshots = getAllPendingScreenshots();
18 | return addPendingScreenshot(result, screenshots);
19 | }
20 |
21 | Spec.ProtoExecutionResult addPendingScreenshot(Spec.ProtoExecutionResult result, List screenshotsFileName) {
22 | Spec.ProtoExecutionResult.Builder builder = Spec.ProtoExecutionResult.newBuilder(result);
23 | builder.addAllScreenshotFiles(screenshotsFileName);
24 | return builder.build();
25 | }
26 |
27 | private ArrayList getAllPendingScreenshots() {
28 | ArrayList pendingScreenshots = new ArrayList<>(getScreenshots());
29 | clear();
30 | return pendingScreenshots;
31 | }
32 |
33 | private void clear() {
34 | getScreenshots().clear();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/SkipScenarioException.java:
--------------------------------------------------------------------------------
1 | package com.thoughtworks.gauge;
2 |
3 | public class SkipScenarioException extends RuntimeException {
4 | public SkipScenarioException(String message) {
5 | super(message);
6 | }
7 |
8 | @SuppressWarnings("unused")
9 | public SkipScenarioException(String message, Throwable cause) {
10 | super(message, cause);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/Specification.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | /**
12 | * Holds the information about the current Specification executing at runtime.
13 | */
14 | public class Specification {
15 | private String name = "";
16 | private String fileName = "";
17 | private Boolean isFailing = false;
18 | private List tags = new ArrayList<>();
19 |
20 | public Specification(String name, String fileName, boolean isFailing, List tags) {
21 | this.name = name;
22 | this.fileName = fileName;
23 | this.isFailing = isFailing;
24 | this.tags = tags;
25 | }
26 |
27 | public Specification() {
28 | }
29 |
30 | /**
31 | * @return List of all the tags in the Spec
32 | */
33 | public List getTags() {
34 | return tags;
35 | }
36 |
37 | /**
38 | * @return True if the current spec is failing.
39 | */
40 | public Boolean getIsFailing() {
41 | return isFailing;
42 | }
43 |
44 | /**
45 | * @return Full path to the Spec
46 | */
47 | public String getFileName() {
48 | return fileName;
49 | }
50 |
51 | /**
52 | * @return The name of the Specification as mentioned in the Spec heading
53 | */
54 | public String getName() {
55 | return name;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/Step.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.lang.annotation.ElementType;
9 | import java.lang.annotation.Retention;
10 | import java.lang.annotation.RetentionPolicy;
11 | import java.lang.annotation.Target;
12 |
13 | /**
14 | * Annotation added to methods which are Gauge Step implementations.
15 | */
16 | @Target(ElementType.METHOD)
17 | @Retention(RetentionPolicy.RUNTIME)
18 | public @interface Step {
19 | String[] value();
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/StepDetails.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | /**
9 | * Holds the information about the current step executing at runtime.
10 | */
11 | public class StepDetails {
12 | private String text = "";
13 | private String dynamicText = "";
14 | private String stackTrace = "";
15 | private String errorMessage = "";
16 | private Boolean isFailing = false;
17 |
18 | public StepDetails(String text, boolean isFailing, String stackTrace, String errorMessage) {
19 | this(text, text, isFailing, stackTrace, errorMessage);
20 | }
21 |
22 | public StepDetails(String text, String dynamicText, boolean isFailing, String stackTrace, String errorMessage) {
23 | this.text = text;
24 | this.dynamicText = dynamicText;
25 | this.isFailing = isFailing;
26 | this.stackTrace = stackTrace;
27 | this.errorMessage = errorMessage;
28 | }
29 |
30 | public StepDetails() {
31 | }
32 |
33 | /**
34 | * @return True if the current spec or scenario or step is failing due to error.
35 | */
36 | public Boolean getIsFailing() {
37 | return isFailing;
38 | }
39 |
40 | /**
41 | * @return The name of the step as given in the spec file.
42 | */
43 | public String getText() {
44 | return text;
45 | }
46 |
47 | /**
48 | * @return The step text with values of dynamic parameters instead of placeholders.
49 | * Return the same value as {@link #text} in case of static parameters.
50 | */
51 | public String getDynamicText() {
52 | return dynamicText;
53 | }
54 |
55 | public String getStackTrace() {
56 | return stackTrace;
57 | }
58 |
59 | public String getErrorMessage() {
60 | return errorMessage;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/StepValue.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import gauge.messages.Spec;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | import java.util.Objects;
13 |
14 | public class StepValue {
15 | private final String stepText;
16 | private final String parameterizedStepText;
17 | private final List parameters;
18 |
19 | public StepValue(String stepText, String parameterizedStepText, List parameters) {
20 | this.stepText = stepText;
21 | this.parameterizedStepText = parameterizedStepText;
22 | this.parameters = parameters;
23 | }
24 |
25 | public StepValue(String stepTemplateText, String parameterizedStepText) {
26 | this.stepText = stepTemplateText;
27 | this.parameterizedStepText = parameterizedStepText;
28 | this.parameters = new ArrayList<>();
29 | }
30 |
31 | public static StepValue from(Spec.ProtoStepValue protoStepValue) {
32 | return new StepValue(protoStepValue.getStepValue(), protoStepValue.getParameterizedStepValue(), protoStepValue.getParametersList());
33 | }
34 |
35 | public String getStepText() {
36 | return stepText;
37 | }
38 |
39 | public List getParameters() {
40 | return parameters;
41 | }
42 |
43 | public String getStepAnnotationText() {
44 | return parameterizedStepText;
45 | }
46 |
47 | @Override
48 | public boolean equals(Object o) {
49 | if (this == o) {
50 | return true;
51 | }
52 |
53 | if (!(o instanceof StepValue)) {
54 | return false;
55 | }
56 |
57 | StepValue stepValue = (StepValue) o;
58 | return Objects.equals(parameterizedStepText, stepValue.parameterizedStepText)
59 | && Objects.equals(parameters, stepValue.parameters)
60 | && Objects.equals(stepText, stepValue.stepText);
61 | }
62 |
63 | @Override
64 | public int hashCode() {
65 | int result = stepText != null ? stepText.hashCode() : 0;
66 | result = 31 * result + (parameterizedStepText != null ? parameterizedStepText.hashCode() : 0); // SUPPRESS CHECKSTYLE
67 | result = 31 * result + (parameters != null ? parameters.hashCode() : 0); // SUPPRESS CHECKSTYLE
68 | return result;
69 | }
70 |
71 | @Override
72 | public String toString() {
73 | return "StepValue{"
74 | + "stepText='" + stepText + '\''
75 | + ", parameterizedStepText='" + parameterizedStepText + '\''
76 | + ", parameters=" + parameters
77 | + '}';
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/TableCell.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | /**
9 | * This class represents a single table cell object containing
10 | * the cell's column name and its associated value.
11 | */
12 | public class TableCell {
13 | private final String columnName;
14 | private final String value;
15 |
16 | public TableCell(String columnName, String value) {
17 | this.columnName = columnName;
18 | this.value = value;
19 | }
20 |
21 | public String getColumnName() {
22 | return columnName;
23 | }
24 |
25 | public String getValue() {
26 | return value;
27 | }
28 |
29 | @Override
30 | public String toString() {
31 | return "TableCell{"
32 | + "columnName=" + columnName
33 | + ", "
34 | + "value=" + value
35 | + '}';
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/TableRow.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.util.*;
9 |
10 | /**
11 | * Represents a Row of Data in a Table.
12 | */
13 | public class TableRow {
14 | private final Map cells = new LinkedHashMap<>();
15 |
16 | /**
17 | * Get the value of cell corresponding to a column name.
18 | *
19 | * @param columnName
20 | * - The column name of TableRow.
21 | * @return The value of cell corresponding to a column name.
22 | */
23 | public String getCell(String columnName) {
24 | if (!cells.containsKey(columnName)) {
25 | return "";
26 | }
27 | return cells.get(columnName);
28 | }
29 |
30 | /**
31 | * Add a cell to the TableRow.
32 | *
33 | * @param columnName
34 | * The column name against which the cell is added.
35 | * @param value
36 | * The value to be stored in the cell.
37 | */
38 | public void addCell(String columnName, String value) {
39 | cells.put(columnName, value);
40 | }
41 |
42 | /**
43 | * Get the number of cells in TableRow.
44 | *
45 | * @return The number of cells in TableRow.
46 | */
47 | public int size() {
48 | return cells.size();
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return "TableRow{" + "cells=" + cells + '}';
54 | }
55 |
56 | /**
57 | * Returns a list containing the values of each cell in the table row.
58 | *
59 | * @return a list of the values of each cell in the table row.
60 | */
61 | public List getCellValues() {
62 | // Since we have a LinkedHashMap, the order of values() is guaranteed.
63 | return new ArrayList<>(cells.values());
64 | }
65 |
66 | /**
67 | * Returns a list of TableCells representing each cell in the table row.
68 | *
69 | * @return a list of TableCells.
70 | */
71 | public List getTableCells() {
72 | List listOfCells = new ArrayList<>();
73 |
74 | // Since we have a LinkedHashMap, the order of entrySet() is guaranteed.
75 | for (Map.Entry mapEntry : cells.entrySet()) {
76 | TableCell cell = new TableCell(mapEntry.getKey(), mapEntry.getValue());
77 | listOfCells.add(cell);
78 | }
79 |
80 | return listOfCells;
81 | }
82 |
83 | @Override
84 | public int hashCode() {
85 | final int prime = 31;
86 | int result = 1;
87 | result = prime * result + cells.hashCode();
88 | return result;
89 | }
90 |
91 | @Override
92 | public boolean equals(Object obj) {
93 | if (this == obj) {
94 | return true;
95 | }
96 | if (obj == null) {
97 | return false;
98 | }
99 | if (getClass() != obj.getClass()) {
100 | return false;
101 | }
102 | TableRow other = (TableRow) obj;
103 | return Objects.equals(cells, other.cells);
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/Util.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge;
7 |
8 | import java.io.File;
9 |
10 | public class Util {
11 | public static File workingDir() {
12 | String wd = System.getenv(GaugeConstant.GAUGE_PROJECT_ROOT);
13 | if (wd != null && !wd.isEmpty()) {
14 | return new File(wd);
15 | }
16 | return new File(System.getProperty("user.dir"));
17 | }
18 |
19 | public static String convertToCamelCase(String s) {
20 | String[] words = s.trim().split(" ");
21 | String text = words[0].toLowerCase();
22 | for (int i = 1, wordsLength = words.length; i < wordsLength; i++) {
23 | String word = words[i].trim();
24 | if (!word.isEmpty()) {
25 | text += words[i].substring(0, 1).toUpperCase() + words[i].substring(1).toLowerCase();
26 | }
27 | }
28 | return text;
29 | }
30 |
31 | public static String getValidJavaIdentifier(String s) {
32 | StringBuilder builder = new StringBuilder();
33 | for (int i = 0; i < s.length(); i++) {
34 | if (Character.isJavaIdentifierPart(s.charAt(i))) {
35 | builder.append(s.charAt(i));
36 | }
37 | }
38 | return builder.toString();
39 | }
40 |
41 | public static String trimQuotes(String text) {
42 | return text == null ? null : text.replaceFirst("^\"", "").replaceFirst("\"$", "");
43 | }
44 |
45 | public static boolean shouldTakeFailureScreenshot() {
46 | String screenshotOnFailureEnabled = System.getenv(GaugeConstant.SCREENSHOT_ON_FAILURE_ENABLED);
47 | return !(screenshotOnFailureEnabled == null || screenshotOnFailureEnabled.equalsIgnoreCase("false"));
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/command/GaugeCommandFactory.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge.command;
7 |
8 | public class GaugeCommandFactory {
9 | public GaugeJavaCommand getExecutor(String phase) {
10 | if ("--init".equals(phase)) {
11 | return new SetupCommand();
12 | }
13 | return new StartCommand();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/command/GaugeJavaCommand.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge.command;
7 |
8 | public interface GaugeJavaCommand {
9 | void execute() throws Exception;
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/command/StartCommand.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge.command;
7 |
8 | import com.thoughtworks.gauge.Logger;
9 | import com.thoughtworks.gauge.RunnerServiceHandler;
10 | import com.thoughtworks.gauge.connection.MessageProcessorFactory;
11 | import com.thoughtworks.gauge.scan.StaticScanner;
12 | import io.grpc.Server;
13 | import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder;
14 |
15 | import java.net.InetSocketAddress;
16 |
17 | import static com.thoughtworks.gauge.GaugeConstant.*;
18 |
19 | public class StartCommand implements GaugeJavaCommand {
20 |
21 | @Override
22 | public void execute() throws Exception {
23 | boolean multithreading = Boolean.parseBoolean(System.getenv(ENABLE_MULTITHREADING_ENV));
24 | Logger.debug("multithreading is set to " + multithreading);
25 | int numberOfStreams = 1;
26 |
27 | if (multithreading) {
28 | String streamsCount = System.getenv(STREAMS_COUNT_ENV);
29 | try {
30 | numberOfStreams = Integer.parseInt(streamsCount);
31 | Logger.debug("multithreading enabled, number of threads=" + numberOfStreams);
32 | } catch (NumberFormatException e) {
33 | Logger.debug("multithreading enabled, but could not read " + STREAMS_COUNT_ENV + " as int. Got " + STREAMS_COUNT_ENV + "=" + streamsCount);
34 | Logger.debug("using numberOfStreams=1, err: " + e.getMessage());
35 | }
36 | }
37 |
38 | long start = System.currentTimeMillis();
39 | StaticScanner staticScanner = new StaticScanner();
40 | staticScanner.addStepsToRegistry();
41 | Server server;
42 | MessageProcessorFactory messageProcessorFactory = new MessageProcessorFactory(staticScanner);
43 | RunnerServiceHandler runnerServiceHandler = new RunnerServiceHandler(messageProcessorFactory, multithreading, numberOfStreams);
44 | server = NettyServerBuilder
45 | .forAddress(new InetSocketAddress(LOCALHOST, 0))
46 | .addService(runnerServiceHandler)
47 | .executor(Runnable::run)
48 | .build();
49 | runnerServiceHandler.addServer(server);
50 | long elapsed = System.currentTimeMillis() - start;
51 | Logger.debug("gauge-java took " + elapsed + "milliseconds to load and scan. This should be less than 'runner_connection_timeout' config value.");
52 | Logger.debug("run 'gauge config runner_connection_timeout' and verify that it is < " + elapsed);
53 | Logger.debug("starting gRPC server...");
54 | server.start();
55 | int port = server.getPort();
56 | Logger.debug("started gRPC server on port " + port);
57 | Logger.info("Listening on port:" + port);
58 | server.awaitTermination();
59 | Logger.debug("Runner killed gracefully.");
60 | System.exit(0);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/thoughtworks/gauge/datastore/DataStore.java:
--------------------------------------------------------------------------------
1 | /*----------------------------------------------------------------
2 | * Copyright (c) ThoughtWorks, Inc.
3 | * Licensed under the Apache License, Version 2.0
4 | * See LICENSE.txt in the project root for license information.
5 | *----------------------------------------------------------------*/
6 | package com.thoughtworks.gauge.datastore;
7 |
8 | import java.util.HashMap;
9 | import java.util.Map;
10 | import java.util.Set;
11 | /**
12 | * @deprecated DataStore is no longer valid. The usage together with DataStoreFactory API will throw an Exception in multithreaded execution.
13 | *