Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
<properties>
<revision>1.28.0-3</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.baseline>2.319</jenkins.baseline>

<jenkins.baseline>2.346</jenkins.baseline>
<jenkins.version>2.346.3</jenkins.version>

<module.name>${project.groupId}.prism</module.name>

Expand Down Expand Up @@ -51,6 +53,7 @@
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>font-awesome-api</artifactId>
<version>6.2.0-3</version>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
Expand Down
46 changes: 29 additions & 17 deletions src/main/java/io/jenkins/plugins/prism/SourcePrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import edu.hm.hafner.util.VisibleForTesting;

import j2html.tags.ContainerTag;
import j2html.tags.DomContent;
import j2html.tags.UnescapedText;

import io.jenkins.plugins.fontawesome.api.SvgTag;
import io.jenkins.plugins.fontawesome.api.SvgTag.FontAwesomeStyle;
import io.jenkins.plugins.util.JenkinsFacade;

import static j2html.TagCreator.*;
Expand All @@ -29,6 +31,7 @@ class SourcePrinter {
private static final ColumnMarker COLUMN_MARKER = new ColumnMarker("-n/a-");
private static final String LINE_NUMBERS = "line-numbers";
private static final String MATCH_BRACES = "match-braces";
private static final String ICON_MD = "icon-md";

private final JenkinsFacade jenkinsFacade;

Expand Down Expand Up @@ -91,44 +94,52 @@ private String createInfoPanel(final Marker marker) {

private ContainerTag createBox(final Marker marker) {
if (StringUtils.isEmpty(marker.getDescription())) {
return createTitle(marker.getTitle(), marker.getIcon(), false);
return createTitle(marker, false);
}
else {
return createTitleAndCollapsedDescription(marker.getTitle(),
marker.getDescription(), marker.getIcon());
return createTitleAndCollapsedDescription(marker, marker.getDescription());
}
}

private ContainerTag createTitle(final String message, final String iconUrl, final boolean isCollapseVisible) {
private DomContent createIcon(final String name) {
if (name.startsWith("symbol")) {
// TODO: replace with Jenkins symbol tag once https://github.com/jenkinsci/jenkins/pull/6659 is merged
return new UnescapedText(
new SvgTag("bookmark", jenkinsFacade, FontAwesomeStyle.REGULAR)
.withClasses(ICON_MD)
.render());
}
return img().withSrc(jenkinsFacade.getImagePath(name)).withClasses(ICON_MD);
}

private ContainerTag createTitle(final Marker marker, final boolean isCollapseVisible) {
return div().with(table().withClass("analysis-title").with(tr().with(
td().with(img().withSrc(iconUrl)),
td().with(createIcon(marker.getIcon())),
td().withClass("analysis-title-column")
.with(div().withClass("analysis-warning-title").with(replaceNewLine(message))),
.with(div().withClass("analysis-warning-title").with(replaceNewLine(marker.getTitle()))),
createCollapseButton(isCollapseVisible)
)));
}

private ContainerTag createCollapseButton(final boolean isCollapseVisible) {
ContainerTag td = td();
if (isCollapseVisible) {
td.with(new UnescapedText(new SvgTag("chevron-circle-down", jenkinsFacade)
td.with(new UnescapedText(new SvgTag("circle-chevron-down", jenkinsFacade)
.withClasses("analysis-collapse-icon").render()));
}
return td;
}

private ContainerTag createTitleAndCollapsedDescription(final String message, final String description,
final String iconUrl) {
private ContainerTag createTitleAndCollapsedDescription(final Marker marker, final String description) {
return div().with(
div().withClass("analysis-collapse-button").with(createTitle(message, iconUrl, true)),
div().withClass("analysis-collapse-button").with(createTitle(marker, true)),
div().withClasses("collapse", "analysis-detail")
.with(unescape(description))
.withId("analysis-description"));
}

private UnescapedText replaceNewLine(final String message) {
String m = message.replace("\n", "<br>");
return unescape(m);
return unescape(message.replace("\n", "<br>"));
}

private UnescapedText unescape(final String message) {
Expand Down Expand Up @@ -208,7 +219,7 @@ private String asMarkedCode(final StringBuilder text, final Marker marker, final
}

String sanitized = SANITIZER.render(StringEscapeUtils.escapeHtml4(marked.toString()));
String markerReplaced = COLUMN_MARKER.replacePlaceHolderWithHtmlTag(sanitized);
String markerReplaced = COLUMN_MARKER.replacePlaceHolderWithHtmlTag(sanitized);
return code().withClasses(classes).with(new UnescapedText(markerReplaced)).render();
}

Expand All @@ -217,8 +228,8 @@ private String asCode(final StringBuilder text, final String... classes) {
}

/**
* Encloses columns between {@code start} and {@code end} with an HTML tag (see {@code openingTag} and {@code
* closingTag}).
* Encloses columns between {@code start} and {@code end} with an HTML tag (see {@code openingTag} and
* {@code closingTag}).
*/
static final class ColumnMarker {
private static final String OPENING_TAG = "<span class='code-mark'>";
Expand All @@ -228,8 +239,9 @@ static final class ColumnMarker {
* Creates a {@link ColumnMarker} that will use {@code placeHolderText} for enclosing.
*
* @param placeHolderText
* Used to construct an opening and closing text that can later be replaced with the HTML tag {@code
* openingTag} {@code closingTag}. It should be a text that is unlikely to appear in any source code.
* Used to construct an opening and closing text that can later be replaced with the HTML tag
* {@code openingTag} {@code closingTag}. It should be a text that is unlikely to appear in any source
* code.
*/
ColumnMarker(final String placeHolderText) {
openingTagPlaceHolder = "OpEn" + placeHolderText;
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/css/custom-prism.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ pre > code.highlight {
background-color: #FFF59D;
}

.analysis-collapse-button svg {
.analysis-collapse-button .analysis-collapse-icon {
transition: .3s transform ease-in-out;
}

.analysis-collapse-button.open svg {
.analysis-collapse-button.open .analysis-collapse-icon {
transform: rotate(180deg);
}

Expand Down
9 changes: 6 additions & 3 deletions src/test/java/io/jenkins/plugins/prism/SourcePrinterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SourcePrinterTest extends ResourceTest {
private static final String MESSAGE = "Hello Message";
private static final String DESCRIPTION = "Hello Description";
private static final String FILE_NAME = "filename.txt";
private static final String ICON = "/plugin/xyz/icon";

@Test
void shouldCreateSourceWithoutLineNumber() {
Expand Down Expand Up @@ -84,15 +85,17 @@ void shouldCreateSourceWithoutDescription() {
@Test
void shouldCreateIcon() {
MarkerBuilder builder = new MarkerBuilder();
Marker issue = builder.withLineStart(7).withTitle("Hello Message").withIcon("icon").build();
Marker issue = builder.withLineStart(7).withTitle("Hello Message").withIcon(ICON).build();

SourcePrinter printer = new SourcePrinter();
JenkinsFacade jenkins = mock(JenkinsFacade.class);
when(jenkins.getImagePath(ICON)).thenReturn("/resolved");
SourcePrinter printer = new SourcePrinter(jenkins);

Document document = Jsoup.parse(printer.render(FILE_NAME, asStream("format-java.txt"), issue));

assertThatCodeIsEqualToSourceText(document);

assertThat(document.getElementsByClass("analysis-title").html()).contains("<td><img src=\"icon\"></td>");
assertThat(document.getElementsByClass("analysis-title").html()).contains("<td><img src=\"/resolved\" class=\"icon-md\"></td>");
}

@Test
Expand Down