The Unified and Autonomous Development Platform
fix issue #153 - Publish a markdown file as build artifact and render the content in a separate build tab
Robin Shen8f91636aa710
diff --git a/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/BuildDetailPage.java b/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/BuildDetailPage.javaindex f30449b9b1..0b0bf951af 100644--- a/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/BuildDetailPage.java+++ b/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/BuildDetailPage.java@@ -434,6 +434,7 @@ public abstract class BuildDetailPage extends ProjectPagepublic void renderHead(IHeaderResponse response) {super.renderHead(response);response.render(JavaScriptHeaderItem.forReference(new BuildDetailResourceReference()));+ response.render(OnDomReadyHeaderItem.forScript("onedev.server.buildDetail.onDomReady();"));}@Overridediff --git a/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/build-detail.css b/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/build-detail.cssindex 497054e971..a94c9de880 100644--- a/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/build-detail.css+++ b/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/build-detail.css@@ -1,3 +1,11 @@+body.BuildDetailPage #layout>.body {+ padding: 50px 0 0 0;+}+#build-detail>.main {+ overflow: auto;+ position: relative;+ padding: 20px;+}#build-detail>.main>div {margin-bottom: 20px;}@@ -51,7 +59,7 @@}@media(min-width: 1150px) {#build-detail>.main {- padding-right: 360px;+ margin-right: 360px;}#build-detail .side-info {box-shadow: none;diff --git a/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/build-detail.js b/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/build-detail.jsindex accbc7cb2d..2cf80eb0d7 100644--- a/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/build-detail.js+++ b/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/build-detail.js@@ -5,8 +5,19 @@ onedev.server.buildDetail = {ps.update();});},+ onDomReady: function() {+ $("body").css("overflow", "hidden");+ var $main = $("#build-detail>.main");+ function adjustHeight() {+ $main.outerHeight($(window).height() - $main.offset().top);+ }+ adjustHeight();+ $main.addClass("resize-aware").on("resized", adjustHeight);+ },onLogDomReady: function() {- var $log = $("#build-detail>.main>div>.build-log");+ var $main = $("#build-detail>.main");+ $main.css("overflow", "hidden");+ var $log = $main.find(">div>.build-log");function setLogHeight() {$log.height($(window).height() - $log.offset().top - 40);}diff --git a/server-plugin/pom.xml b/server-plugin/pom.xmlindex 7a213f0567..40c5b3537e 100644--- a/server-plugin/pom.xml+++ b/server-plugin/pom.xml@@ -25,5 +25,6 @@<module>server-plugin-buildspec-node</module><module>server-plugin-authenticator-ldap</module><module>server-plugin-sso-openid</module>+ <module>server-plugin-report-markdown</module></modules></project>\ No newline at end of filediff --git a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportPage.java b/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportPage.javaindex 73f4bd7a7f..0565ecf2f1 100644--- a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportPage.java+++ b/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/HtmlReportPage.java@@ -67,7 +67,7 @@ public class HtmlReportPage extends BuildDetailPage {}.add(AttributeAppender.append("src", startPageUrl.toString())));} else {- add(new Label("htmlReport", "No html report published: " + reportName) {+ add(new Label("htmlReport", "No html report published") {@Overrideprotected void onComponentTag(ComponentTag tag) {diff --git a/server-plugin/server-plugin-report-markdown/pom.xml b/server-plugin/server-plugin-report-markdown/pom.xmlnew file mode 100644index 0000000000..6c28f2a2b5--- /dev/null+++ b/server-plugin/server-plugin-report-markdown/pom.xml@@ -0,0 +1,13 @@+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">+ <modelVersion>4.0.0</modelVersion>+ <artifactId>server-plugin-report-markdown</artifactId>+ <parent>+ <groupId>io.onedev</groupId>+ <artifactId>server-plugin</artifactId>+ <version>3.2.0</version>+ </parent>+ <properties>+ <moduleClass>io.onedev.server.plugin.report.markdown.MarkdownReportModule</moduleClass>+ </properties>+</project>diff --git a/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/JobMarkdownReport.java b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/JobMarkdownReport.javanew file mode 100644index 0000000000..a1df5fd357--- /dev/null+++ b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/JobMarkdownReport.java@@ -0,0 +1,95 @@+package io.onedev.server.plugin.report.markdown;++import java.io.File;+import java.io.IOException;+import java.util.List;+import java.util.concurrent.Callable;++import org.hibernate.validator.constraints.NotEmpty;++import io.onedev.commons.codeassist.InputSuggestion;+import io.onedev.commons.utils.FileUtils;+import io.onedev.commons.utils.LockUtils;+import io.onedev.server.buildspec.job.Job;+import io.onedev.server.buildspec.job.JobReport;+import io.onedev.server.model.Build;+import io.onedev.server.util.JobLogger;+import io.onedev.server.util.validation.annotation.PathSegment;+import io.onedev.server.web.editable.annotation.Editable;+import io.onedev.server.web.editable.annotation.Interpolative;++@Editable(name="Markdown Report")+public class JobMarkdownReport extends JobReport {++ private static final long serialVersionUID = 1L;++ public static final String DIR = "markdown-reports";++ public static final String START_PAGE = "$onedev-markdownreport-startpage$";++ private String reportName;++ private String startPage;++ @Editable(order=1000, description="Specify report name. "+ + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")+ @Interpolative(variableSuggester="suggestVariables")+ @PathSegment+ @NotEmpty+ public String getReportName() {+ return reportName;+ }++ public void setReportName(String reportName) {+ this.reportName = reportName;+ }++ @Editable(order=1100, description="Specify start page of the report relative to <a href='$docRoot/pages/concepts.md#job-workspace' target='_blank'>job workspace</a>, for instance: manual/index.md. "+ + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")+ @Interpolative(variableSuggester="suggestVariables")+ @NotEmpty+ public String getStartPage() {+ return startPage;+ }++ public void setStartPage(String startPage) {+ this.startPage = startPage;+ }++ @SuppressWarnings("unused")+ private static List<InputSuggestion> suggestVariables(String matchWith) {+ return Job.suggestVariables(matchWith);+ }++ @Override+ public void process(Build build, File workspace, JobLogger logger) {+ File reportDir = new File(build.getReportDir(DIR), getReportName());+ FileUtils.createDir(reportDir);++ LockUtils.write(build.getReportLockKey(DIR), new Callable<Void>() {++ @Override+ public Void call() throws Exception {+ File startPage = new File(workspace, getStartPage());+ if (startPage.exists()) {+ File startPageFile = new File(reportDir, START_PAGE);+ FileUtils.writeFile(startPageFile, getStartPage());++ int baseLen = workspace.getAbsolutePath().length() + 1;+ for (File file: getPatternSet().listFiles(workspace)) {+ try {+ FileUtils.copyFile(file, new File(reportDir, file.getAbsolutePath().substring(baseLen)));+ } catch (IOException e) {+ throw new RuntimeException(e);+ }+ }+ } else {+ logger.log("WARNING: Markdown report start page not found: " + startPage.getAbsolutePath());+ }+ return null;+ }++ });+ }++}diff --git a/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportCssResourceReference.java b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportCssResourceReference.javanew file mode 100644index 0000000000..0b73908385--- /dev/null+++ b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportCssResourceReference.java@@ -0,0 +1,13 @@+package io.onedev.server.plugin.report.markdown;++import io.onedev.server.web.page.base.BaseDependentCssResourceReference;++public class MarkdownReportCssResourceReference extends BaseDependentCssResourceReference {++ private static final long serialVersionUID = 1L;++ public MarkdownReportCssResourceReference() {+ super(MarkdownReportCssResourceReference.class, "markdown-report.css");+ }++}diff --git a/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportDownloadResource.java b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportDownloadResource.javanew file mode 100644index 0000000000..37f45d2dae--- /dev/null+++ b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportDownloadResource.java@@ -0,0 +1,151 @@+package io.onedev.server.plugin.report.markdown;++import java.io.File;+import java.io.FileInputStream;+import java.io.IOException;+import java.io.InputStream;+import java.io.UnsupportedEncodingException;+import java.net.URLEncoder;+import java.nio.charset.StandardCharsets;+import java.nio.file.Files;+import java.util.ArrayList;+import java.util.List;+import java.util.concurrent.Callable;++import javax.persistence.EntityNotFoundException;++import org.apache.commons.lang3.StringUtils;+import org.apache.shiro.authz.UnauthorizedException;+import org.apache.tika.io.IOUtils;+import org.apache.wicket.request.mapper.parameter.PageParameters;+import org.apache.wicket.request.resource.AbstractResource;++import com.google.common.base.Joiner;++import io.onedev.commons.utils.LockUtils;+import io.onedev.server.OneDev;+import io.onedev.server.OneException;+import io.onedev.server.entitymanager.BuildManager;+import io.onedev.server.entitymanager.ProjectManager;+import io.onedev.server.model.Build;+import io.onedev.server.model.Project;+import io.onedev.server.security.SecurityUtils;+import io.onedev.server.storage.StorageManager;++public class MarkdownReportDownloadResource extends AbstractResource {++ private static final long serialVersionUID = 1L;++ private static final String PARAM_PROJECT = "project";++ private static final String PARAM_BUILD = "build";++ private static final String PARAM_REPORT = "report";++ private static final String PARAM_PATH = "path";++ @Override+ protected ResourceResponse newResourceResponse(Attributes attributes) {+ PageParameters params = attributes.getParameters();++ String projectName = params.get(PARAM_PROJECT).toString();+ if (StringUtils.isBlank(projectName))+ throw new IllegalArgumentException("project name has to be specified");++ Project project = OneDev.getInstance(ProjectManager.class).find(projectName);++ if (project == null)+ throw new EntityNotFoundException("Unable to find project: " + projectName);++ Long buildNumber = params.get(PARAM_BUILD).toOptionalLong();++ if (buildNumber == null)+ throw new IllegalArgumentException("build number has to be specified");++ Build build = OneDev.getInstance(BuildManager.class).find(project, buildNumber);++ if (build == null) {+ String message = String.format("Unable to find build (project: %s, build number: %d)",+ project.getName(), buildNumber);+ throw new EntityNotFoundException(message);+ }++ String reportName = params.get(PARAM_REPORT).toOptionalString();++ if (reportName == null)+ throw new IllegalArgumentException("Markdown report name has to be specified");++ if (!SecurityUtils.canAccessReport(build, reportName))+ throw new UnauthorizedException();++ List<String> pathSegments = new ArrayList<>();+ String pathSegment = params.get(PARAM_PATH).toString();+ if (pathSegment.length() != 0)+ pathSegments.add(pathSegment);+ else+ throw new OneException("Markdown report path has to be specified");++ for (int i = 0; i < params.getIndexedCount(); i++) {+ pathSegment = params.get(i).toString();+ if (pathSegment.length() != 0)+ pathSegments.add(pathSegment);+ }++ String markdownPath = Joiner.on("/").join(pathSegments);++ File buildDir = OneDev.getInstance(StorageManager.class).getBuildDir(project.getId(), build.getNumber());+ File reportDir = new File(buildDir, JobMarkdownReport.DIR + "/" + reportName);++ File markdownFile = new File(reportDir, markdownPath);+ if (!markdownFile.exists() || markdownFile.isDirectory()) {+ String message = String.format("Specified markdown path does not exist or is a directory (project: %s, build number: %d, path: %s)",+ project.getName(), build.getNumber(), markdownPath);+ throw new OneException(message);+ }++ ResourceResponse response = new ResourceResponse();+ try {+ response.setContentType(Files.probeContentType(markdownFile.toPath()));+ } catch (IOException e) {+ throw new RuntimeException(e);+ }++ response.disableCaching();++ try {+ response.setFileName(URLEncoder.encode(markdownFile.getName(), StandardCharsets.UTF_8.name()));+ } catch (UnsupportedEncodingException e) {+ throw new RuntimeException(e);+ }+ response.setWriteCallback(new WriteCallback() {++ @Override+ public void writeData(Attributes attributes) throws IOException {+ LockUtils.read(build.getReportLockKey(JobMarkdownReport.DIR), new Callable<Void>() {++ @Override+ public Void call() throws Exception {+ try (InputStream is = new FileInputStream(markdownFile)) {+ IOUtils.copy(is, attributes.getResponse().getOutputStream());+ }+ return null;+ }++ });+ }++ });++ return response;+ }++ public static PageParameters paramsOf(Project project, Long buildNumber, String reportName, String path) {+ PageParameters params = new PageParameters();+ params.set(PARAM_PROJECT, project.getName());+ params.set(PARAM_BUILD, buildNumber);+ params.set(PARAM_REPORT, reportName);+ params.set(PARAM_PATH, path);+ return params;+ }++}diff --git a/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportDownloadResourceReference.java b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportDownloadResourceReference.javanew file mode 100644index 0000000000..3afd31c34e--- /dev/null+++ b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportDownloadResourceReference.java@@ -0,0 +1,19 @@+package io.onedev.server.plugin.report.markdown;++import org.apache.wicket.request.resource.IResource;+import org.apache.wicket.request.resource.ResourceReference;++public class MarkdownReportDownloadResourceReference extends ResourceReference {++ private static final long serialVersionUID = 1L;++ public MarkdownReportDownloadResourceReference() {+ super("markdown-report");+ }++ @Override+ public IResource getResource() {+ return new MarkdownReportDownloadResource();+ }++}diff --git a/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportModule.java b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportModule.javanew file mode 100644index 0000000000..d71114b077--- /dev/null+++ b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportModule.java@@ -0,0 +1,88 @@+package io.onedev.server.plugin.report.markdown;++import java.io.File;+import java.util.ArrayList;+import java.util.Collection;+import java.util.List;+import java.util.concurrent.Callable;++import org.apache.wicket.protocol.http.WebApplication;++import com.google.common.collect.Sets;++import io.onedev.commons.launcher.loader.AbstractPluginModule;+import io.onedev.commons.launcher.loader.ImplementationProvider;+import io.onedev.commons.utils.LockUtils;+import io.onedev.server.buildspec.job.JobReport;+import io.onedev.server.model.Build;+import io.onedev.server.security.SecurityUtils;+import io.onedev.server.web.WebApplicationConfigurator;+import io.onedev.server.web.mapper.OnePageMapper;+import io.onedev.server.web.page.project.builds.detail.BuildTab;+import io.onedev.server.web.page.project.builds.detail.BuildTabContribution;++/**+ * NOTE: Do not forget to rename moduleClass property defined in the pom if you've renamed this class.+ *+ */+public class MarkdownReportModule extends AbstractPluginModule {++ @Override+ protected void configure() {+ super.configure();++ contribute(ImplementationProvider.class, new ImplementationProvider() {++ @Override+ public Class<?> getAbstractClass() {+ return JobReport.class;+ }++ @Override+ public Collection<Class<?>> getImplementations() {+ return Sets.newHashSet(JobMarkdownReport.class);+ }++ });++ contribute(BuildTabContribution.class, new BuildTabContribution() {++ @Override+ public List<BuildTab> getTabs(Build build) {+ List<BuildTab> tabs = new ArrayList<>();+ LockUtils.read(build.getReportLockKey(JobMarkdownReport.DIR), new Callable<Void>() {++ @Override+ public Void call() throws Exception {+ if (build.getReportDir(JobMarkdownReport.DIR).exists()) {+ for (File reportDir: build.getReportDir(JobMarkdownReport.DIR).listFiles()) {+ if (SecurityUtils.canAccessReport(build, reportDir.getName()))+ tabs.add(new MarkdownReportTab(reportDir.getName()));+ }+ }+ return null;+ }++ });+ return tabs;+ }++ @Override+ public int getOrder() {+ return 300;+ }++ });++ contribute(WebApplicationConfigurator.class, new WebApplicationConfigurator() {++ @Override+ public void configure(WebApplication application) {+ application.mount(new OnePageMapper("projects/${project}/builds/${build}/markdown-reports/${report}/#{path}", MarkdownReportPage.class));+ }++ });++ }++}diff --git a/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportPage.html b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportPage.htmlnew file mode 100644index 0000000000..83d874b729--- /dev/null+++ b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportPage.html@@ -0,0 +1,3 @@+<wicket:extend>+ <div wicket:id="markdownReport" class="markdown-report"></div>+</wicket:extend>\ No newline at end of filediff --git a/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportPage.java b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportPage.javanew file mode 100644index 0000000000..62cb523c1a--- /dev/null+++ b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportPage.java@@ -0,0 +1,115 @@+package io.onedev.server.plugin.report.markdown;++import java.io.File;+import java.io.IOException;+import java.nio.charset.StandardCharsets;+import java.util.ArrayList;+import java.util.List;++import javax.annotation.Nullable;++import org.apache.wicket.behavior.AttributeAppender;+import org.apache.wicket.markup.ComponentTag;+import org.apache.wicket.markup.head.CssHeaderItem;+import org.apache.wicket.markup.head.IHeaderResponse;+import org.apache.wicket.markup.html.basic.Label;+import org.apache.wicket.model.Model;+import org.apache.wicket.request.cycle.RequestCycle;+import org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler;+import org.apache.wicket.request.mapper.parameter.PageParameters;++import io.onedev.commons.utils.FileUtils;+import io.onedev.commons.utils.StringUtils;+import io.onedev.server.model.Build;+import io.onedev.server.security.SecurityUtils;+import io.onedev.server.web.component.markdown.MarkdownViewer;+import io.onedev.server.web.page.project.builds.detail.BuildDetailPage;++@SuppressWarnings("serial")+public class MarkdownReportPage extends BuildDetailPage {++ private static final String PARAM_REPORT = "report";++ private static final String PARAM_PATH = "path";++ private final String reportName;++ private final String filePath;++ public MarkdownReportPage(PageParameters params) {+ super(params);++ reportName = params.get(PARAM_REPORT).toString();++ List<String> pathSegments = new ArrayList<>();+ String segment = params.get(PARAM_PATH).toString();+ if (segment != null && segment.length() != 0)+ pathSegments.add(segment);++ for (int i=0; i<params.getIndexedCount(); i++) {+ segment = params.get(i).toString();+ if (segment.length() != 0)+ pathSegments.add(segment);+ }++ if (!pathSegments.isEmpty()) {+ filePath = StringUtils.join(pathSegments, "/");+ if (!filePath.endsWith(".md")) {+ RequestCycle.get().scheduleRequestHandlerAfterCurrent(+ new ResourceReferenceRequestHandler(new MarkdownReportDownloadResourceReference(), getPageParameters()));+ }+ } else {+ filePath = null;+ }++ }++ @Override+ protected void onInitialize() {+ super.onInitialize();++ if (filePath != null) {+ File file = new File(getBuild().getReportDir(JobMarkdownReport.DIR),+ reportName + "/" + filePath);+ try {+ String markdown = FileUtils.readFileToString(file, StandardCharsets.UTF_8);+ add(new MarkdownViewer("markdownReport", Model.of(markdown), null));+ } catch (IOException e) {+ throw new RuntimeException(e);+ }+ } else {+ add(new Label("markdownReport", "No markdown report published") {++ @Override+ protected void onComponentTag(ComponentTag tag) {+ super.onComponentTag(tag);+ tag.setName("div");+ }++ }.add(AttributeAppender.append("class", "alert alert-warning")));+ }+ }++ @Override+ protected boolean isPermitted() {+ return SecurityUtils.canAccessReport(getBuild(), reportName);+ }++ public String getReportName() {+ return reportName;+ }++ @Override+ public void renderHead(IHeaderResponse response) {+ super.renderHead(response);+ response.render(CssHeaderItem.forReference(new MarkdownReportCssResourceReference()));+ }++ public static PageParameters paramsOf(Build build, String reportName, @Nullable String filePath) {+ PageParameters params = paramsOf(build);+ params.add(PARAM_REPORT, reportName);+ if (filePath != null)+ params.add(PARAM_PATH, filePath);+ return params;+ }+}diff --git a/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportTab.java b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportTab.javanew file mode 100644index 0000000000..739f2ec4ec--- /dev/null+++ b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/MarkdownReportTab.java@@ -0,0 +1,64 @@+package io.onedev.server.plugin.report.markdown;++import java.io.File;+import java.nio.charset.StandardCharsets;+import java.util.concurrent.Callable;++import org.apache.wicket.Component;+import org.apache.wicket.Page;+import org.apache.wicket.markup.html.link.Link;+import org.apache.wicket.request.mapper.parameter.PageParameters;++import io.onedev.commons.utils.FileUtils;+import io.onedev.commons.utils.LockUtils;+import io.onedev.server.web.component.link.ViewStateAwarePageLink;+import io.onedev.server.web.component.tabbable.PageTabLink;+import io.onedev.server.web.page.project.builds.detail.BuildDetailPage;+import io.onedev.server.web.page.project.builds.detail.BuildTab;++@SuppressWarnings("serial")+public class MarkdownReportTab extends BuildTab {++ public MarkdownReportTab(String reportName) {+ super(reportName, MarkdownReportPage.class);+ }++ @Override+ public Component render(String componentId) {+ return new PageTabLink(componentId, this) {++ @Override+ protected Link<?> newLink(String linkId, Class<? extends Page> pageClass) {+ BuildDetailPage page = (BuildDetailPage) getPage();+ String startPage = LockUtils.read(page.getBuild().getReportLockKey(JobMarkdownReport.DIR), new Callable<String>() {++ @Override+ public String call() throws Exception {+ File startPageFile = new File(page.getBuild().getReportDir(JobMarkdownReport.DIR),+ getTitle() + "/" + JobMarkdownReport.START_PAGE);+ if (startPageFile.exists())+ return FileUtils.readFileToString(startPageFile, StandardCharsets.UTF_8);+ else+ return null;+ }++ });++ PageParameters params = MarkdownReportPage.paramsOf(page.getBuild(), getTitle(), startPage);+ return new ViewStateAwarePageLink<Void>(linkId, pageClass, params);+ }++ };+ }++ @Override+ public boolean isActive(Page currentPage) {+ if (super.isActive(currentPage)) {+ MarkdownReportPage markdownReportPage = (MarkdownReportPage) currentPage;+ return getTitle().equals(markdownReportPage.getReportName());+ } else {+ return false;+ }+ }++}diff --git a/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/markdown-report.css b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/markdown-report.cssnew file mode 100644index 0000000000..e9c57ff3a8--- /dev/null+++ b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/markdown-report.css@@ -0,0 +1,6 @@+.markdown-report>.markdown-viewer {+ padding: 0 20px;+ max-width: 900px;+ margin-left: auto;+ margin-right: auto;+}diff --git a/server-product/pom.xml b/server-product/pom.xmlindex f27d32866c..5f8d781cb3 100644--- a/server-product/pom.xml+++ b/server-product/pom.xml@@ -55,6 +55,11 @@<artifactId>server-plugin-sso-openid</artifactId><version>${project.version}</version></dependency>+ <dependency>+ <groupId>io.onedev</groupId>+ <artifactId>server-plugin-report-markdown</artifactId>+ <version>${project.version}</version>+ </dependency></dependencies><properties><executables>bin/*.sh, boot/wrapper-*</executables>