From 3b5b0c601c5b71b55d09f8c48f1ce79a1772cb40 Mon Sep 17 00:00:00 2001 From: Artem Eroshenko Date: Sat, 15 Feb 2020 00:28:42 +0300 Subject: [PATCH 1/4] add hotspot plugin --- allure-generator/package-lock.json | 34 ++---- .../qameta/allure/ConfigurationBuilder.java | 4 +- .../io/qameta/allure/hotspot/Element.java | 42 +++++++ .../qameta/allure/hotspot/HotspotPlugin.java | 114 ++++++++++++++++++ .../qameta/allure/hotspot/LocatorAction.java | 19 +++ hotspot.sh | 2 + 6 files changed, 189 insertions(+), 26 deletions(-) create mode 100644 allure-generator/src/main/java/io/qameta/allure/hotspot/Element.java create mode 100644 allure-generator/src/main/java/io/qameta/allure/hotspot/HotspotPlugin.java create mode 100644 allure-generator/src/main/java/io/qameta/allure/hotspot/LocatorAction.java create mode 100644 hotspot.sh diff --git a/allure-generator/package-lock.json b/allure-generator/package-lock.json index a656fef6d..93925ae8b 100644 --- a/allure-generator/package-lock.json +++ b/allure-generator/package-lock.json @@ -4917,8 +4917,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -4939,14 +4938,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -4959,20 +4956,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -5087,8 +5081,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -5100,7 +5093,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -5115,7 +5107,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -5226,8 +5217,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -5239,7 +5229,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -5360,7 +5349,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -5380,7 +5368,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -5409,8 +5396,7 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.2", @@ -8086,7 +8072,6 @@ "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.3.5.tgz", "integrity": "sha512-Gi1W4k059gyRbyVUZQ4mEqLm0YIUiGYfvxhF6SIlk3ui1WVxMTGfGdQ2SInh3PDrRTVvPKgULkpJtT4RH10+VA==", "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -8096,8 +8081,7 @@ "version": "3.0.3", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz", "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==", - "dev": true, - "optional": true + "dev": true } } }, diff --git a/allure-generator/src/main/java/io/qameta/allure/ConfigurationBuilder.java b/allure-generator/src/main/java/io/qameta/allure/ConfigurationBuilder.java index 8d2a4413b..174eb89f7 100644 --- a/allure-generator/src/main/java/io/qameta/allure/ConfigurationBuilder.java +++ b/allure-generator/src/main/java/io/qameta/allure/ConfigurationBuilder.java @@ -36,6 +36,7 @@ import io.qameta.allure.ga.GaPlugin; import io.qameta.allure.history.HistoryPlugin; import io.qameta.allure.history.HistoryTrendPlugin; +import io.qameta.allure.hotspot.HotspotPlugin; import io.qameta.allure.idea.IdeaLinksPlugin; import io.qameta.allure.influxdb.InfluxDbExportPlugin; import io.qameta.allure.launch.LaunchPlugin; @@ -107,7 +108,8 @@ public ConfigurationBuilder useDefault() { new Allure1Plugin(), new Allure1EnvironmentPlugin(), new Allure2Plugin(), - new GaPlugin() + new GaPlugin(), + new HotspotPlugin() )); return this; } diff --git a/allure-generator/src/main/java/io/qameta/allure/hotspot/Element.java b/allure-generator/src/main/java/io/qameta/allure/hotspot/Element.java new file mode 100644 index 000000000..858924efb --- /dev/null +++ b/allure-generator/src/main/java/io/qameta/allure/hotspot/Element.java @@ -0,0 +1,42 @@ +package io.qameta.allure.hotspot; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * @author eroshenkoam (Artem Eroshenko). + */ +@Data +@Accessors(chain = true) +public class Element { + + private String fullPath; + private Set urls = new HashSet<>(); + private List tests = new ArrayList<>(); + + public Element addUrls(final Set url) { + urls.addAll(url); + return this; + } + + + /** + * @author eroshenkoam (Artem Eroshenko). + */ + @Data + @Accessors(chain = true) + public static class Test { + + private String name; + private String url; + private String status; + private Long duration; + + } + +} diff --git a/allure-generator/src/main/java/io/qameta/allure/hotspot/HotspotPlugin.java b/allure-generator/src/main/java/io/qameta/allure/hotspot/HotspotPlugin.java new file mode 100644 index 000000000..61a9c19f6 --- /dev/null +++ b/allure-generator/src/main/java/io/qameta/allure/hotspot/HotspotPlugin.java @@ -0,0 +1,114 @@ +package io.qameta.allure.hotspot; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.qameta.allure.Aggregator; +import io.qameta.allure.context.JacksonContext; +import io.qameta.allure.core.Configuration; +import io.qameta.allure.core.LaunchResults; +import io.qameta.allure.entity.Attachment; +import io.qameta.allure.entity.ExecutorInfo; +import io.qameta.allure.entity.StageResult; +import io.qameta.allure.entity.Step; +import io.qameta.allure.executor.ExecutorPlugin; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * @author eroshenkoam (Artem Eroshenko). + */ +@SuppressWarnings({"PMD.SystemPrintln", "PMD.AvoidInstantiatingObjectsInLoops", "PMD.AvoidThrowingRawExceptionTypes"}) +public class HotspotPlugin implements Aggregator { + + @Override + public void aggregate(final Configuration configuration, + final List launchesResults, + final Path outputDirectory) throws IOException { + final ObjectMapper mapper = configuration.requireContext(JacksonContext.class).getValue(); + final Map elements = new HashMap<>(); + launchesResults.forEach(launch -> { + final ExecutorInfo executor = launch.getExtra( + ExecutorPlugin.EXECUTORS_BLOCK_NAME, + ExecutorInfo::new + ); + launch.getAllResults().forEach(result -> { + final List attachments = new ArrayList<>(); + result.getBeforeStages().stream() + .filter(Objects::nonNull) + .map(this::getAttachments) + .forEach(attachments::addAll); + result.getAfterStages().stream() + .filter(Objects::nonNull) + .map(this::getAttachments) + .forEach(attachments::addAll); + Optional.ofNullable(result.getTestStage()) + .map(this::getAttachments) + .ifPresent(attachments::addAll); + + final List locators = attachments.stream() + .filter(attachment -> attachment.getName().endsWith("locators")) + .collect(Collectors.toList()); + + for (final Attachment attachment : locators) { + try { + final Path path = outputDirectory.resolve("data").resolve("attachments") + .resolve(attachment.getSource()); + final List actions = mapper + .readValue(Files.readAllBytes(path), new TypeReference>() { + }); + System.out.println(actions.size()); + actions.forEach(action -> { + final Element element = elements.getOrDefault(action.getFullPath(), new Element()); + element.setFullPath(action.getFullPath()); + element.addUrls(action.getUrls()); + + final Element.Test test = new Element.Test() + .setName(result.getName()) + .setDuration(result.getTime().getDuration()) + .setStatus(result.getStatus().value()); + Optional.ofNullable(executor) + .map(ExecutorInfo::getReportUrl) + .map(url -> this.createReportUrl(url, result.getUid())) + .ifPresent(test::setUrl); + element.getTests().add(test); + elements.put(element.getFullPath(), element); + }); + } catch (IOException e) { + e.printStackTrace(System.out); +// throw new RuntimeException(e); + } + } + }); + }); + final Path hotspot = outputDirectory.resolve("export").resolve("hotspot.json"); + Files.write(hotspot, mapper.writeValueAsBytes(elements.values())); + } + + private List getAttachments(final StageResult stage) { + final List attachments = new ArrayList<>(); + Optional.ofNullable(stage.getAttachments()).ifPresent(attachments::addAll); + stage.getSteps().forEach(step -> attachments.addAll(getAttachments(step))); + return attachments; + } + + private List getAttachments(final Step steps) { + final List attachments = new ArrayList<>(); + Optional.ofNullable(steps.getAttachments()).ifPresent(attachments::addAll); + steps.getSteps().forEach(step -> attachments.addAll(getAttachments(step))); + return attachments; + } + + private String createReportUrl(final String reportUrl, final String uuid) { + final String pattern = reportUrl.endsWith("index.html") ? "%s#testresult/%s" : "%s/#testresult/%s"; + return String.format(pattern, reportUrl, uuid); + } +} diff --git a/allure-generator/src/main/java/io/qameta/allure/hotspot/LocatorAction.java b/allure-generator/src/main/java/io/qameta/allure/hotspot/LocatorAction.java new file mode 100644 index 000000000..3c2894b26 --- /dev/null +++ b/allure-generator/src/main/java/io/qameta/allure/hotspot/LocatorAction.java @@ -0,0 +1,19 @@ +package io.qameta.allure.hotspot; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.HashSet; +import java.util.Set; + +/** + * @author eroshenkoam (Artem Eroshenko). + */ +@Data +@Accessors(chain = true) +public class LocatorAction { + + private String fullPath; + private Set urls = new HashSet<>(); + +} diff --git a/hotspot.sh b/hotspot.sh new file mode 100644 index 000000000..0c1812ace --- /dev/null +++ b/hotspot.sh @@ -0,0 +1,2 @@ +./allure-commandline/build/install/allure-commandline/bin/allure serve \ + /Users/eroshenkoam/Developer/kurau/atlas-locator-watcher/target/allure-results From af21adcd15d0d163c5343dec948e8a211192ecfb Mon Sep 17 00:00:00 2001 From: Artem Eroshenko Date: Fri, 17 Apr 2020 14:29:19 +0300 Subject: [PATCH 2/4] little improvements --- .../io/qameta/allure/hotspot/Element.java | 1 + .../qameta/allure/hotspot/HotspotPlugin.java | 35 +++++++++++-------- .../java/io/qameta/allure/HotspotPLugin.java | 26 ++++++++++++++ hotspot.sh | 4 +-- 4 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 allure-generator/src/test/java/io/qameta/allure/HotspotPLugin.java mode change 100644 => 100755 hotspot.sh diff --git a/allure-generator/src/main/java/io/qameta/allure/hotspot/Element.java b/allure-generator/src/main/java/io/qameta/allure/hotspot/Element.java index 858924efb..011161f6a 100644 --- a/allure-generator/src/main/java/io/qameta/allure/hotspot/Element.java +++ b/allure-generator/src/main/java/io/qameta/allure/hotspot/Element.java @@ -32,6 +32,7 @@ public Element addUrls(final Set url) { @Accessors(chain = true) public static class Test { + private String uid; private String name; private String url; private String status; diff --git a/allure-generator/src/main/java/io/qameta/allure/hotspot/HotspotPlugin.java b/allure-generator/src/main/java/io/qameta/allure/hotspot/HotspotPlugin.java index 61a9c19f6..342427532 100644 --- a/allure-generator/src/main/java/io/qameta/allure/hotspot/HotspotPlugin.java +++ b/allure-generator/src/main/java/io/qameta/allure/hotspot/HotspotPlugin.java @@ -1,9 +1,9 @@ package io.qameta.allure.hotspot; import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import io.qameta.allure.Aggregator; -import io.qameta.allure.context.JacksonContext; import io.qameta.allure.core.Configuration; import io.qameta.allure.core.LaunchResults; import io.qameta.allure.entity.Attachment; @@ -33,7 +33,8 @@ public class HotspotPlugin implements Aggregator { public void aggregate(final Configuration configuration, final List launchesResults, final Path outputDirectory) throws IOException { - final ObjectMapper mapper = configuration.requireContext(JacksonContext.class).getValue(); + final ObjectMapper mapper = new ObjectMapper() + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); final Map elements = new HashMap<>(); launchesResults.forEach(launch -> { final ExecutorInfo executor = launch.getExtra( @@ -55,7 +56,7 @@ public void aggregate(final Configuration configuration, .ifPresent(attachments::addAll); final List locators = attachments.stream() - .filter(attachment -> attachment.getName().endsWith("locators")) + .filter(attachment -> attachment.getName().endsWith("locators2")) .collect(Collectors.toList()); for (final Attachment attachment : locators) { @@ -63,23 +64,29 @@ public void aggregate(final Configuration configuration, final Path path = outputDirectory.resolve("data").resolve("attachments") .resolve(attachment.getSource()); final List actions = mapper - .readValue(Files.readAllBytes(path), new TypeReference>() { + .readValue(path.toFile(), new TypeReference>() { }); - System.out.println(actions.size()); actions.forEach(action -> { final Element element = elements.getOrDefault(action.getFullPath(), new Element()); element.setFullPath(action.getFullPath()); element.addUrls(action.getUrls()); - final Element.Test test = new Element.Test() - .setName(result.getName()) - .setDuration(result.getTime().getDuration()) - .setStatus(result.getStatus().value()); - Optional.ofNullable(executor) - .map(ExecutorInfo::getReportUrl) - .map(url -> this.createReportUrl(url, result.getUid())) - .ifPresent(test::setUrl); - element.getTests().add(test); + final String uuid = result.getUid(); + final boolean exists = element.getTests().stream() + .map(Element.Test::getUid) + .anyMatch(uuid::equals); + if (!exists) { + final Element.Test test = new Element.Test() + .setUid(result.getUid()) + .setName(result.getName()) + .setDuration(result.getTime().getDuration()) + .setStatus(result.getStatus().value()); + Optional.ofNullable(executor) + .map(ExecutorInfo::getReportUrl) + .map(url -> this.createReportUrl(url, result.getUid())) + .ifPresent(test::setUrl); + element.getTests().add(test); + } elements.put(element.getFullPath(), element); }); } catch (IOException e) { diff --git a/allure-generator/src/test/java/io/qameta/allure/HotspotPLugin.java b/allure-generator/src/test/java/io/qameta/allure/HotspotPLugin.java new file mode 100644 index 000000000..39aee632d --- /dev/null +++ b/allure-generator/src/test/java/io/qameta/allure/HotspotPLugin.java @@ -0,0 +1,26 @@ +package io.qameta.allure; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.qameta.allure.hotspot.LocatorAction; +import org.junit.jupiter.api.Test; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + +public class HotspotPLugin { + + @Test + public void testOutput() throws Exception { + final ObjectMapper mapper = new ObjectMapper() + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final Path path = Paths.get("/Users/eroshenkoam/Downloads/realty/realty-web-tests/target/one/553d09ac-7872-4d5a-a10e-5ba1fad52ea4-attachment.locators2"); + final List actions = mapper + .readValue(path.toFile(), new TypeReference>() { + }); + + } + +} diff --git a/hotspot.sh b/hotspot.sh old mode 100644 new mode 100755 index 0c1812ace..7f022ba0f --- a/hotspot.sh +++ b/hotspot.sh @@ -1,2 +1,2 @@ -./allure-commandline/build/install/allure-commandline/bin/allure serve \ - /Users/eroshenkoam/Developer/kurau/atlas-locator-watcher/target/allure-results +./allure-commandline/build/install/allure-commandline/bin/allure serve --port 3333 \ + /Users/eroshenkoam/Downloads/realty/realty-web-tests/target/allure-results From 80f5d1bff86d85e6c9ae24fb990c4cf08e53692e Mon Sep 17 00:00:00 2001 From: Artem Eroshenko Date: Wed, 17 Jun 2020 14:49:25 +0300 Subject: [PATCH 3/4] little fixes --- .../io/qameta/allure/hotspot/Element.java | 1 + .../qameta/allure/hotspot/HotspotPlugin.java | 12 ++++++++- .../java/io/qameta/allure/HotspotPLugin.java | 26 ------------------- 3 files changed, 12 insertions(+), 27 deletions(-) delete mode 100644 allure-generator/src/test/java/io/qameta/allure/HotspotPLugin.java diff --git a/allure-generator/src/main/java/io/qameta/allure/hotspot/Element.java b/allure-generator/src/main/java/io/qameta/allure/hotspot/Element.java index 011161f6a..76111161f 100644 --- a/allure-generator/src/main/java/io/qameta/allure/hotspot/Element.java +++ b/allure-generator/src/main/java/io/qameta/allure/hotspot/Element.java @@ -16,6 +16,7 @@ public class Element { private String fullPath; + private int count; private Set urls = new HashSet<>(); private List tests = new ArrayList<>(); diff --git a/allure-generator/src/main/java/io/qameta/allure/hotspot/HotspotPlugin.java b/allure-generator/src/main/java/io/qameta/allure/hotspot/HotspotPlugin.java index 342427532..2ca1c76b7 100644 --- a/allure-generator/src/main/java/io/qameta/allure/hotspot/HotspotPlugin.java +++ b/allure-generator/src/main/java/io/qameta/allure/hotspot/HotspotPlugin.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import freemarker.template.utility.StringUtil; import io.qameta.allure.Aggregator; import io.qameta.allure.core.Configuration; import io.qameta.allure.core.LaunchResults; @@ -26,7 +27,12 @@ /** * @author eroshenkoam (Artem Eroshenko). */ -@SuppressWarnings({"PMD.SystemPrintln", "PMD.AvoidInstantiatingObjectsInLoops", "PMD.AvoidThrowingRawExceptionTypes"}) +@SuppressWarnings({ + "PMD.SystemPrintln", + "PMD.AvoidInstantiatingObjectsInLoops", + "PMD.AvoidThrowingRawExceptionTypes", + "ExecutableStatementCount" +}) public class HotspotPlugin implements Aggregator { @Override @@ -67,6 +73,9 @@ public void aggregate(final Configuration configuration, .readValue(path.toFile(), new TypeReference>() { }); actions.forEach(action -> { + if (StringUtil.isTrimmableToEmpty(action.getFullPath().toCharArray())) { + return; + } final Element element = elements.getOrDefault(action.getFullPath(), new Element()); element.setFullPath(action.getFullPath()); element.addUrls(action.getUrls()); @@ -87,6 +96,7 @@ public void aggregate(final Configuration configuration, .ifPresent(test::setUrl); element.getTests().add(test); } + element.setCount(element.getTests().size()); elements.put(element.getFullPath(), element); }); } catch (IOException e) { diff --git a/allure-generator/src/test/java/io/qameta/allure/HotspotPLugin.java b/allure-generator/src/test/java/io/qameta/allure/HotspotPLugin.java deleted file mode 100644 index 39aee632d..000000000 --- a/allure-generator/src/test/java/io/qameta/allure/HotspotPLugin.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.qameta.allure; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.qameta.allure.hotspot.LocatorAction; -import org.junit.jupiter.api.Test; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; - -public class HotspotPLugin { - - @Test - public void testOutput() throws Exception { - final ObjectMapper mapper = new ObjectMapper() - .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - final Path path = Paths.get("/Users/eroshenkoam/Downloads/realty/realty-web-tests/target/one/553d09ac-7872-4d5a-a10e-5ba1fad52ea4-attachment.locators2"); - final List actions = mapper - .readValue(path.toFile(), new TypeReference>() { - }); - - } - -} From 8a1121af335242fb8701a5fb3ef78cd6881680cd Mon Sep 17 00:00:00 2001 From: Artem Eroshenko Date: Mon, 2 Nov 2020 21:22:04 +0300 Subject: [PATCH 4/4] skip retries --- .../src/main/java/io/qameta/allure/hotspot/HotspotPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/allure-generator/src/main/java/io/qameta/allure/hotspot/HotspotPlugin.java b/allure-generator/src/main/java/io/qameta/allure/hotspot/HotspotPlugin.java index 2ca1c76b7..b0987c7e1 100644 --- a/allure-generator/src/main/java/io/qameta/allure/hotspot/HotspotPlugin.java +++ b/allure-generator/src/main/java/io/qameta/allure/hotspot/HotspotPlugin.java @@ -47,7 +47,7 @@ public void aggregate(final Configuration configuration, ExecutorPlugin.EXECUTORS_BLOCK_NAME, ExecutorInfo::new ); - launch.getAllResults().forEach(result -> { + launch.getAllResults().stream().filter(s -> !s.isHidden()).forEach(result -> { final List attachments = new ArrayList<>(); result.getBeforeStages().stream() .filter(Objects::nonNull)