diff --git a/java.json b/java.json
index c0b14892..6c6028cd 100644
--- a/java.json
+++ b/java.json
@@ -1,6 +1,6 @@
{
"id": "java",
- "version": "1.0.0",
+ "version": "1.0.1",
"description": "Java support for gauge",
"install": {
"windows": [],
diff --git a/notice.md b/notice.md
index 9df64904..3d5486d4 100644
--- a/notice.md
+++ b/notice.md
@@ -6,7 +6,7 @@
| 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 |
| javassist | Copyright (C) 1999-2015 Shigeru Chiba. | Java bytecode engineering toolkit | https://www.javassist.org/ | Triple License: MPL 1.1, LGPL 2.1, Apache 2.0 | https://www.apache.org/licenses/LICENSE-2.0 |
| javaparser | | Java 1-21 Parser and Abstract Syntax Tree for Java with advanced analysis functionalities. | https://github.com/javaparser/javaparser | Dual License: LGPL 3.0, Apache 2.0 | https://www.apache.org/licenses/LICENSE-2.0 |
-| JSON-java | | A reference implementation of a JSON package in Java. | https://github.com/stleary/JSON-java | Public Domain | https://github.com/stleary/JSON-java/blob/master/LICENSE |
| guava | Copyright (C) 2012 The Guava Authors | Google Core Libraries for Java | https://github.com/google/guava | Apache 2.0 | https://www.apache.org/licenses/LICENSE-2.0 |
+| gson | | A Java serialization/deserialization library to convert Java Objects into JSON and back | https://github.com/google/gson | Apache 2.0 | https://www.apache.org/licenses/LICENSE-2.0 |
| protobuf-java | | Java Protocol Buffers runtime library | https://github.com/protocolbuffers/protobuf | BSD 2 clause license | https://www.opensource.org/licenses/bsd-license.php |
| grpc-java | | Google Core Libraries for Java | https://github.com/grpc/grpc-java | Apache 2.0 | https://www.apache.org/licenses/LICENSE-2.0 |
diff --git a/pom.xml b/pom.xml
index 30f791cd..3b261b46 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
gauge-javacom.thoughtworks.gaugegauge-java
- 1.0.0
+ 1.0.1Java plugin for Gaugehttps://github.com/getgauge/gauge-java
@@ -55,9 +55,15 @@
3.27.1
- org.json
- json
- 20250517
+ com.google.code.gson
+ gson
+ 2.13.2
+
+
+ com.google.errorprone
+ error_prone_annotations
+
+ com.google.protobuf
@@ -137,6 +143,10 @@
com.google.errorproneerror_prone_annotations
+
+ org.codehaus.mojo
+ animal-sniffer-annotations
+
@@ -340,8 +350,8 @@
Gauge Teamgetgauge@googlegroups.com
- ThoughtWorks
- https://thoughtworks.com/
+ Gauge Team
+ https://gauge.org/
diff --git a/src/main/java/com/thoughtworks/gauge/AfterClassSteps.java b/src/main/java/com/thoughtworks/gauge/AfterClassSteps.java
deleted file mode 100644
index 88bf86c4..00000000
--- a/src/main/java/com/thoughtworks/gauge/AfterClassSteps.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*----------------------------------------------------------------
- * Copyright (c) ThoughtWorks, Inc.
- * Licensed under the Apache License, Version 2.0
- * See LICENSE.txt in the project root for license information.
- *----------------------------------------------------------------*/
-package com.thoughtworks.gauge;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Methods annotated with this hook, will be executed after every step in that particular class.
- *
- * If there is more than one method annotated with @AfterClassSteps the order of execution is as follows:
- *
- *
Hooks which are not filtered by tags.
- *
Hooks filtered by tags.
- *
- * If there is more than one hook of these categories, they are executed in reverse alphabetical order based on method names.
- *
- */
-@Target(ElementType.METHOD)
-@Deprecated
-@Retention(RetentionPolicy.RUNTIME)
-public @interface AfterClassSteps {
-
- /**
- * @return Array of tags to filter which steps the hook executes after based on the tags in the current scenario and spec.
- */
- String[] tags() default {};
-
- /**
- * @return OR: if hook should execute for the current execution context (spec and scenario) containing any of the tags provided
- * AND: if hook should execute for the current execution context (spec and scenario) containing all of the tags provided
- * Default is AND
- */
- Operator tagAggregation() default Operator.AND;
-}
diff --git a/src/main/java/com/thoughtworks/gauge/BeforeClassSteps.java b/src/main/java/com/thoughtworks/gauge/BeforeClassSteps.java
deleted file mode 100644
index 5dcc7b1e..00000000
--- a/src/main/java/com/thoughtworks/gauge/BeforeClassSteps.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*----------------------------------------------------------------
- * Copyright (c) ThoughtWorks, Inc.
- * Licensed under the Apache License, Version 2.0
- * See LICENSE.txt in the project root for license information.
- *----------------------------------------------------------------*/
-package com.thoughtworks.gauge;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Methods annotated with this hook, will execute before every step in that particular class.
- *
- * If there is more than one method annotated with @BeforeClassSteps the order of execution is as follows:
- *
- *
Hooks which are not filtered by tags.
- *
Hooks filtered by tags.
- *
- * If there is more than one hook of these categories, they are alphabetically sorted based on method names.
- *
- */
-@Target(ElementType.METHOD)
-@Deprecated
-@Retention(RetentionPolicy.RUNTIME)
-public @interface BeforeClassSteps {
-
- /**
- * @return Array of tags to filter which steps the hook executes before based on the tags in the current scenario and spec.
- */
- String[] tags() default {};
-
- /**
- * @return OR: if hook should execute for the current execution context (spec and scenario) containing any of the tags provided
- * AND: if hook should execute for the current execution context (spec and scenario) containing all of the tags provided
- * Default is AND
- */
- Operator tagAggregation() default Operator.AND;
-}
diff --git a/src/main/java/com/thoughtworks/gauge/Logger.java b/src/main/java/com/thoughtworks/gauge/Logger.java
index 27c11e32..e1bfc91d 100644
--- a/src/main/java/com/thoughtworks/gauge/Logger.java
+++ b/src/main/java/com/thoughtworks/gauge/Logger.java
@@ -5,8 +5,10 @@
*----------------------------------------------------------------*/
package com.thoughtworks.gauge;
-import org.assertj.core.util.Throwables;
-import org.json.JSONObject;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
public class Logger {
public static void info(String message) {
@@ -18,7 +20,7 @@ public static void error(String message) {
}
public static void error(String message, Throwable t) {
- error(String.format("%s\n%s\n%s", message, t.getMessage(), Throwables.getStackTrace(t)));
+ error(String.format("%s\n%s\n%s", message, t.getMessage(), Util.stacktraceFrom(t)));
}
public static void warning(String message) {
@@ -26,7 +28,7 @@ public static void warning(String message) {
}
public static void warning(String message, Throwable t) {
- warning(String.format("%s\n%s\n%s", message, t.getMessage(), Throwables.getStackTrace(t)));
+ warning(String.format("%s\n%s\n%s", message, t.getMessage(), Util.stacktraceFrom(t)));
}
public static void debug(String message) {
@@ -39,22 +41,27 @@ public static void fatal(String message) {
}
public static void fatal(String message, Throwable t) {
- fatal(String.format("%s\n%s\n%s", message, t.getMessage(), Throwables.getStackTrace(t)));
-
+ fatal(String.format("%s\n%s\n%s", message, t.getMessage(), Util.stacktraceFrom(t)));
}
private static void logToStdout(String level, String message) {
- System.out.println(getJsonObject(level, message));
+ System.out.println(LogMessage.of(level, message));
}
- private static JSONObject getJsonObject(String level, String message) {
- JSONObject jsonObj = new JSONObject();
- jsonObj.put("logLevel", level);
- jsonObj.put("message", message);
- return jsonObj;
+ private static void logToStdErr(String level, String message) {
+ System.err.println(LogMessage.of(level, message));
}
- private static void logToStdErr(String level, String message) {
- System.err.println(getJsonObject(level, message));
+ private record LogMessage(@Expose @SerializedName("logLevel") String level, @Expose @SerializedName("message") String message) {
+ private static final Gson GSON = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
+
+ public static LogMessage of(String level, String message) {
+ return new LogMessage(level, message);
+ }
+
+ @Override
+ public String toString() {
+ return GSON.toJson(this);
+ }
}
}
diff --git a/src/main/java/com/thoughtworks/gauge/Table.java b/src/main/java/com/thoughtworks/gauge/Table.java
index ac81b1b9..85b4ec56 100644
--- a/src/main/java/com/thoughtworks/gauge/Table.java
+++ b/src/main/java/com/thoughtworks/gauge/Table.java
@@ -5,10 +5,8 @@
*----------------------------------------------------------------*/
package com.thoughtworks.gauge;
-import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
-import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.Collections;
@@ -25,14 +23,13 @@ public class Table {
private static final String DASH = "-";
private static final String PIPE = "|";
private static final char SPACE_AS_CHAR = ' ';
+
private final List headers;
- private final List> rows;
- private final List tableRows;
+ private final List> rows = new ArrayList<>();
+ private final List tableRows = new ArrayList<>();
public Table(List headers) {
this.headers = headers;
- rows = new ArrayList<>();
- tableRows = new ArrayList<>();
}
public void addRow(List row) {
@@ -57,7 +54,7 @@ public List getColumnNames() {
/**
* Gets a Column name by index.
*
- * @param columnIndex
+ * @param columnIndex 0-indexed column ordinal within the table
* @return a single column name by given column index.
*/
public String getColumnName(int columnIndex) {
@@ -74,16 +71,6 @@ public List getTableRows() {
return tableRows;
}
- /**
- * @return List of TableRows in the table. Each Row is represented by a List
- * of String values according to the order of column names
- * @deprecated Use getTableRows() method instead of this.
- */
- @Deprecated
- public List> getRows() {
- return rows;
- }
-
/**
* Get all the values of a column in Table.
*
@@ -144,14 +131,10 @@ private void addValues(int maxStringLength, List formattedHeaderAndRows)
}
private String formattedRow(List strings, int maxStringLength) {
- List formattedStrings = Lists.transform(strings, format(maxStringLength));
+ List formattedStrings = strings.stream().map(s -> Strings.padEnd(s, maxStringLength, SPACE_AS_CHAR)).toList();
return PIPE + Joiner.on(PIPE).join(formattedStrings) + PIPE;
}
- private Function format(final int maxStringLength) {
- return input -> Strings.padEnd(input, maxStringLength, SPACE_AS_CHAR);
- }
-
private Integer getMaxStringLength() {
List maxs = new ArrayList<>();
maxs.add(getMaxStringSize(headers));
@@ -177,8 +160,8 @@ public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (headers == null ? 0 : headers.hashCode());
- result = prime * result + (rows == null ? 0 : rows.hashCode());
- result = prime * result + (tableRows == null ? 0 : tableRows.hashCode());
+ result = prime * result + rows.hashCode();
+ result = prime * result + tableRows.hashCode();
return result;
}
diff --git a/src/main/java/com/thoughtworks/gauge/Util.java b/src/main/java/com/thoughtworks/gauge/Util.java
index 60040097..b5da09c6 100644
--- a/src/main/java/com/thoughtworks/gauge/Util.java
+++ b/src/main/java/com/thoughtworks/gauge/Util.java
@@ -8,6 +8,8 @@
import com.google.common.base.Splitter;
import java.io.File;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@@ -60,4 +62,12 @@ public static boolean shouldTakeFailureScreenshot() {
return !(screenshotOnFailureEnabled == null || "false".equalsIgnoreCase(screenshotOnFailureEnabled));
}
+ public static String stacktraceFrom(Throwable throwable) {
+ StringWriter sw = new StringWriter();
+ try (PrintWriter pw = new PrintWriter(sw, true)) {
+ throwable.printStackTrace(pw);
+ return sw.getBuffer().toString();
+ }
+ }
+
}
diff --git a/src/main/java/com/thoughtworks/gauge/datastore/DataStore.java b/src/main/java/com/thoughtworks/gauge/datastore/DataStore.java
deleted file mode 100644
index b9c870fa..00000000
--- a/src/main/java/com/thoughtworks/gauge/datastore/DataStore.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*----------------------------------------------------------------
- * Copyright (c) ThoughtWorks, Inc.
- * Licensed under the Apache License, Version 2.0
- * See LICENSE.txt in the project root for license information.
- *----------------------------------------------------------------*/
-package com.thoughtworks.gauge.datastore;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-/**
- * @deprecated DataStore is no longer valid. The usage together with DataStoreFactory API will throw an Exception in multithreaded execution.
- *