-
-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[allure-adaptor] Add ability to configure report layout #5423
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
vividus-allure-adaptor/src/main/java/org/vividus/report/allure/plugin/DynamicPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2019-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.vividus.report.allure.plugin; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.attribute.PosixFilePermission; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Stream; | ||
|
||
import org.apache.commons.lang3.SystemUtils; | ||
import org.vividus.util.ResourceUtils; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import io.qameta.allure.PluginConfiguration; | ||
import io.qameta.allure.plugin.DefaultPlugin; | ||
|
||
public class DynamicPlugin extends DefaultPlugin | ||
{ | ||
private static final String INDEX_JS = "index.js"; | ||
|
||
private final Map<String, Path> pluginFiles = new HashMap<>(); | ||
|
||
@SuppressFBWarnings("CT_CONSTRUCTOR_THROW") | ||
public DynamicPlugin(String pluginId, Supplier<List<String>> jsFileLinesSupplier) throws IOException | ||
{ | ||
super(new PluginConfiguration() | ||
.setId(pluginId) | ||
.setJsFiles(List.of()), | ||
List.of(), null); | ||
|
||
List<String> jsFileLines = jsFileLinesSupplier.get(); | ||
|
||
if (!jsFileLines.isEmpty()) | ||
{ | ||
Path indexJs = ResourceUtils.createTempFile("index", ".js"); | ||
Files.write(indexJs, Stream.of(List.of("'use strict';"), jsFileLines).flatMap(List::stream).toList()); | ||
|
||
/* | ||
For UNIX like operating systems default access for temp files is 600, whereas for regular files the | ||
default access is 644, so the following fix is used to align access bits across all files being created | ||
during test execution and avoid potential access related issues. | ||
*/ | ||
if (SystemUtils.IS_OS_UNIX) | ||
{ | ||
Files.setPosixFilePermissions(indexJs, | ||
Set.of(PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_READ, | ||
PosixFilePermission.GROUP_READ, PosixFilePermission.OTHERS_READ)); | ||
} | ||
|
||
pluginFiles.put(INDEX_JS, Path.of(indexJs.toUri())); | ||
getConfig().setJsFiles(List.of(INDEX_JS)); | ||
} | ||
} | ||
|
||
@Override | ||
public Map<String, Path> getPluginFiles() | ||
{ | ||
return pluginFiles; | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...llure-adaptor/src/main/java/org/vividus/report/allure/plugin/LayoutConfiguringPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright 2019-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.vividus.report.allure.plugin; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map.Entry; | ||
import java.util.stream.Collectors; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
import org.vividus.util.property.PropertyMappedCollection; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
|
||
public class LayoutConfiguringPlugin extends DynamicPlugin | ||
{ | ||
@SuppressFBWarnings("CT_CONSTRUCTOR_THROW") | ||
public LayoutConfiguringPlugin(PropertyMappedCollection<Component> tabs, | ||
PropertyMappedCollection<Component> widgets, PropertyMappedCollection<Component> charts) throws IOException | ||
{ | ||
super("layout-configuration", () -> { | ||
List<String> jsFileLines = new ArrayList<>(); | ||
|
||
String tabsToExclude = tabs.getData().entrySet().stream() | ||
.filter(e -> e.getValue().isDisabled()) | ||
.map(Entry::getKey) | ||
.map("'%s'"::formatted) | ||
.collect(Collectors.joining(",")); | ||
if (!tabsToExclude.isEmpty()) | ||
{ | ||
jsFileLines.add("allure.api.tabs = allure.api.tabs.filter(t => ![%s].includes(t.tabName));".formatted( | ||
tabsToExclude)); | ||
} | ||
|
||
addJsLinesDisablingComponents(widgets, "delete allure.api.widgets.widgets['%s'];", jsFileLines); | ||
addJsLinesDisablingComponents(charts, "delete allure.api.widgets.graph['%s'];", jsFileLines); | ||
|
||
return jsFileLines; | ||
}); | ||
} | ||
|
||
private static void addJsLinesDisablingComponents(PropertyMappedCollection<Component> components, | ||
String jsLineFormat, List<String> jsFileLines) | ||
{ | ||
components.getData().entrySet().stream() | ||
.filter(e -> e.getValue().isDisabled()) | ||
.map(Entry::getKey) | ||
.map(jsLineFormat::formatted) | ||
.forEach(jsFileLines::add); | ||
} | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public static final class Component | ||
{ | ||
private Boolean enabled; | ||
|
||
public Boolean isEnabled() | ||
{ | ||
return enabled; | ||
} | ||
|
||
public void setEnabled(Boolean enabled) | ||
{ | ||
this.enabled = enabled; | ||
} | ||
|
||
public boolean isDisabled() | ||
{ | ||
return Boolean.FALSE.equals(isEnabled()); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this expected format of messages (I about '[]') ?
Shouldn't we add spaces after the colon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it is, rendering is not correct without square brackets and no space is expected after colon: https://docs.asciidoctor.org/asciidoc/latest/macros/ui-macros/