Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release #200

Merged
merged 7 commits into from Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Expand Up @@ -52,7 +52,7 @@ jobs:
version-file-extraction-pattern: ${{ env.VERSION_EXTRACT_PATTERN }}

- name: Setup git credentials
uses: oleksiyrudenko/gha-git-credentials@v2.1
uses: oleksiyrudenko/gha-git-credentials@v2.1.1
with:
name: 'reportportal.io'
email: 'support@reportportal.io'
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
@@ -1,10 +1,13 @@
# Changelog

## [Unreleased]
### Added
- `class` and `classRef` keywords for `@Step` templating, by @HardNorth
- `PropertiesLoader.getPropertyFilePath`method, by @HardNorth

## [5.1.14]
### Added
- Issue [#198](https://github.com/reportportal/client-java/issues/198) Property file customization, by @HardNorth
- Issue [#198](https://github.com/reportportal/client-java/issues/198) Property file customization with `rp.properties.path` property, by @HardNorth
### Changed
- `jackson-databind` dependency was forcibly updated to address vulnerabilities, by @HardNorth

Expand Down
3 changes: 1 addition & 2 deletions build.gradle
Expand Up @@ -35,7 +35,6 @@ targetCompatibility = JavaVersion.VERSION_1_8

repositories {
mavenCentral()
maven { url "https://jitpack.io" }
}

dependencies {
Expand Down Expand Up @@ -74,7 +73,7 @@ dependencies {
exclude group: 'org.hamcrest'
}
testImplementation 'org.apache.commons:commons-io:1.3.2'
testImplementation 'com.github.reportportal:agent-java-test-utils:2d652c6'
testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.1'
}

test {
Expand Down
Expand Up @@ -34,6 +34,10 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface TemplateConfig {

String classNameTemplate() default TemplateConfiguration.CLASS_SIMPLE_NAME_TEMPLATE;

String classRefTemplate() default TemplateConfiguration.CLASS_FULL_NAME_TEMPLATE;

String methodNameTemplate() default TemplateConfiguration.METHOD_NAME_TEMPLATE;

String selfNameTemplate() default TemplateConfiguration.SELF_NAME_TEMPLATE;
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/com/epam/reportportal/aspect/StepNameUtils.java
Expand Up @@ -23,7 +23,6 @@
import org.aspectj.lang.reflect.MethodSignature;

import javax.annotation.Nonnull;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -47,7 +46,8 @@ private StepNameUtils() {
* @return step name
*/
@Nonnull
public static String getStepName(@Nonnull Step step, @Nonnull MethodSignature signature, @Nonnull JoinPoint joinPoint) {
public static String getStepName(@Nonnull Step step, @Nonnull MethodSignature signature,
@Nonnull JoinPoint joinPoint) {
String nameTemplate = step.value();
if (nameTemplate.trim().isEmpty()) {
return signature.getMethod().getName();
Expand Down Expand Up @@ -82,13 +82,21 @@ public static String getStepName(@Nonnull String nameTemplate, @Nonnull Template
}

@Nonnull
static Map<String, Object> createParamsMapping(@Nonnull TemplateConfiguration templateConfig, @Nonnull MethodSignature signature,
@Nonnull JoinPoint joinPoint) {
static Map<String, Object> createParamsMapping(@Nonnull TemplateConfiguration templateConfig,
@Nonnull MethodSignature signature, @Nonnull JoinPoint joinPoint) {
Object[] args = joinPoint.getArgs();
String[] parameterNames = signature.getParameterNames();
int paramsCount = Math.min(ofNullable(parameterNames).map(p -> p.length).orElse(0), ofNullable(args).map(a -> a.length).orElse(0));
int paramsCount = Math.min(
ofNullable(parameterNames).map(p -> p.length).orElse(0),
ofNullable(args).map(a -> a.length).orElse(0)
);
Map<String, Object> paramsMapping = new HashMap<>();
ofNullable(signature.getMethod()).map(Method::getName).ifPresent(name -> paramsMapping.put(templateConfig.getMethodName(), name));
ofNullable(signature.getMethod()).ifPresent(method -> {
paramsMapping.put(templateConfig.getMethodName(), method.getName());
Class<?> clazz = method.getDeclaringClass();
paramsMapping.put(templateConfig.getClassName(), clazz.getSimpleName());
paramsMapping.put(templateConfig.getClassRef(), clazz.getName());
});
ofNullable(joinPoint.getThis()).ifPresent(current -> paramsMapping.put(templateConfig.getSelfName(), current));
for (int i = 0; i < paramsCount; i++) {
paramsMapping.put(parameterNames[i], args[i]);
Expand Down
Expand Up @@ -42,7 +42,7 @@
import static java.util.Optional.ofNullable;

/**
* Report portal listeners parameters
* Report portal client parameters. The class is a placeholder for client and agent parameters.
*/
public class ListenerParameters implements Cloneable {

Expand Down Expand Up @@ -153,6 +153,9 @@ private static Duration getDurationProperty(@Nonnull PropertiesLoader properties
)).orElse(null);
}

/**
* Create class instance with default parameters
*/
public ListenerParameters() {

this.isSkippedAnIssue = DEFAULT_SKIP_ISSUE;
Expand Down Expand Up @@ -188,6 +191,11 @@ public ListenerParameters() {
this.attributeLengthLimit = DEFAULT_TRUNCATE_ATTRIBUTE_LIMIT;
}

/**
* Create class instance with parameters from property source
*
* @param properties property source
*/
public ListenerParameters(PropertiesLoader properties) {
this.description = properties.getProperty(DESCRIPTION);
this.apiKey = ofNullable(properties.getProperty(API_KEY, properties.getProperty(UUID))).map(String::trim)
Expand Down Expand Up @@ -576,6 +584,7 @@ public void setRxBufferSize(int size) {
}

/**
* @return to truncate or not truncate
* @deprecated use {@link #isTruncateFields} instead
*/
@Deprecated
Expand All @@ -584,6 +593,7 @@ public boolean isTruncateItemNames() {
}

/**
* @param truncate to truncate or not truncate
* @deprecated use {@link #setTruncateFields} instead
*/
@Deprecated
Expand All @@ -608,6 +618,7 @@ public void setTruncateItemNamesLimit(int limit) {
}

/**
* @return truncation replacement
* @deprecated Use {@link #getTruncateReplacement} instead
*/
@Deprecated
Expand All @@ -616,6 +627,7 @@ public String getTruncateItemNamesReplacement() {
}

/**
* @param replacement truncation replacement
* @deprecated Use {@link #setTruncateReplacement} instead
*/
@Deprecated
Expand Down
Expand Up @@ -85,18 +85,25 @@ public static PropertiesLoader load(final String resource) {
});
}

/**
* Get path to Report Portal configuration file according to Environment Variables and System Properties.
*
* @return path to Report Portal configuration file
*/
public static String getPropertyFilePath() {
return ofNullable(normalizeOverrides(System.getProperties()).get(PROPERTIES_PATH_PROPERTY)).filter(StringUtils::isNotBlank)
.orElseGet(() -> ofNullable(normalizeOverrides(System.getenv()).get(PROPERTIES_PATH_PROPERTY)).filter(
StringUtils::isNotBlank).orElse(INNER_PATH));
}

/**
* Loads properties from default location
*
* @return PropertiesLoader instance
* @see #INNER_PATH
*/
public static PropertiesLoader load() {
String propertyFilePath = ofNullable(normalizeOverrides(System.getProperties()).get(PROPERTIES_PATH_PROPERTY)).filter(
StringUtils::isNotBlank)
.orElseGet(() -> ofNullable(normalizeOverrides(System.getenv()).get(PROPERTIES_PATH_PROPERTY)).filter(
StringUtils::isNotBlank).orElse(INNER_PATH));
return load(propertyFilePath);
return load(getPropertyFilePath());
}

private PropertiesLoader(final Supplier<Properties> propertiesSupplier) {
Expand Down
Expand Up @@ -21,7 +21,13 @@

import java.util.Objects;

/**
* Template configuration holder class. With the help of {@link TemplateConfig} annotation one can configure every
* aspect of template keywords and special characters.
*/
public class TemplateConfiguration {
public static final String CLASS_SIMPLE_NAME_TEMPLATE = "class";
public static final String CLASS_FULL_NAME_TEMPLATE = "classRef";
public static final String METHOD_NAME_TEMPLATE = "method";
public static final String SELF_NAME_TEMPLATE = "this";
public static final String FIELD_REFERENCE_DELIMITER = ".";
Expand All @@ -32,6 +38,8 @@ public class TemplateConfiguration {
public static final String ARRAY_END_PATTERN = "}";
public static final String ARRAY_ELEMENT_DELIMITER = ", ";

private String className;
private String classRef;
private String methodName;
private String selfName;
private String fieldDelimiter;
Expand All @@ -43,6 +51,8 @@ public class TemplateConfiguration {
private String arrayDelimiter;

public TemplateConfiguration() {
className = CLASS_SIMPLE_NAME_TEMPLATE;
classRef = CLASS_FULL_NAME_TEMPLATE;
methodName = METHOD_NAME_TEMPLATE;
selfName = SELF_NAME_TEMPLATE;
fieldDelimiter = FIELD_REFERENCE_DELIMITER;
Expand All @@ -63,15 +73,19 @@ public boolean equals(Object o) {
return false;
}
TemplateConfiguration that = (TemplateConfiguration) o;
return methodName.equals(that.methodName) && selfName.equals(that.selfName) && fieldDelimiter.equals(that.fieldDelimiter)
&& iterableStart.equals(that.iterableStart) && iterableEnd.equals(that.iterableEnd)
&& iterableDelimiter.equals(that.iterableDelimiter) && arrayStart.equals(that.arrayStart) && arrayEnd.equals(that.arrayEnd)
&& arrayDelimiter.equals(that.arrayDelimiter);
return className.equals(that.className) && classRef.equals(that.classRef) && methodName.equals(that.methodName)
&& selfName.equals(that.selfName) && fieldDelimiter.equals(that.fieldDelimiter) && iterableStart.equals(
that.iterableStart) && iterableEnd.equals(that.iterableEnd)
&& iterableDelimiter.equals(that.iterableDelimiter) && arrayStart.equals(that.arrayStart)
&& arrayEnd.equals(that.arrayEnd) && arrayDelimiter.equals(that.arrayDelimiter);
}

@Override
public int hashCode() {
return Objects.hash(methodName,
return Objects.hash(
className,
classRef,
methodName,
selfName,
fieldDelimiter,
iterableStart,
Expand All @@ -95,6 +109,8 @@ public TemplateConfiguration(StepTemplateConfig config) {
}

public TemplateConfiguration(TemplateConfig config) {
className = config.classNameTemplate();
classRef = config.classRefTemplate();
methodName = config.methodNameTemplate();
selfName = config.selfNameTemplate();
fieldDelimiter = config.fieldDelimiter();
Expand All @@ -106,6 +122,24 @@ public TemplateConfiguration(TemplateConfig config) {
arrayDelimiter = config.arrayElementDelimiter();
}

public String getClassName() {
return className;
}

public TemplateConfiguration setClassName(String className) {
this.className = className;
return this;
}

public String getClassRef() {
return classRef;
}

public TemplateConfiguration setClassRef(String classRef) {
this.classRef = classRef;
return this;
}

public String getMethodName() {
return methodName;
}
Expand Down