Skip to content

Commit

Permalink
#362: htmlTitle is used as title for maven report
Browse files Browse the repository at this point in the history
  • Loading branch information
siom79 committed Sep 22, 2023
1 parent 2997889 commit 90ae1eb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ protected void executeReport(Locale locale) throws MavenReportException {
htmlString = htmlString.replaceAll("<title>[^<]*</title>", "");
htmlString = htmlString.replaceAll("<META[^>]*>", "");
Sink sink = getSink();
String htmlTitle = getHtmlTitle();
if (htmlTitle != null) {
sink.head();
sink.title();
sink.text(pluginParameters.getParameterParam().getHtmlTitle());
sink.title_();
sink.head_();
}
sink.rawText(htmlString);
sink.close();
}
Expand Down Expand Up @@ -119,6 +127,13 @@ private Options getOptions() {
}
}

private String getHtmlTitle() {
if (pluginParameters.getParameterParam() != null && pluginParameters.getParameterParam().getHtmlTitle() != null) {
return pluginParameters.getParameterParam().getHtmlTitle();
}
return null;
}

@Override
public String getOutputName() {
if (this.parameter != null && this.parameter.getReportLinkName() != null) {
Expand Down Expand Up @@ -150,6 +165,6 @@ public String getDescription(Locale locale) {

private boolean isPomModuleNeedingSkip() {
return this.pluginParameters.getParameterParam().getSkipPomModules()
&& "pom".equalsIgnoreCase(this.mavenProject.getArtifact().getType());
&& "pom".equalsIgnoreCase(this.mavenProject.getArtifact().getType());
}
}
1 change: 1 addition & 0 deletions japicmp-testbase/japicmp-test-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@
<ignoreNonResolvableArtifacts>true</ignoreNonResolvableArtifacts>
<onlyModified>true</onlyModified>
<reportOnlyFilename>true</reportOnlyFilename>
<htmlTitle>Test-Title for Site-Report</htmlTitle>
</parameter>
</configuration>
<reportSets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,36 @@
import org.junit.Test;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class ITHtmlTitle {

@Test
public void testHtmlTitle() throws IOException {
Path htmlPath = Paths.get(System.getProperty("user.dir"), "target", "japicmp", "single-version.html");
assertThat(Files.exists(htmlPath), is(true));
Document document = Jsoup.parse(htmlPath.toFile(), Charset.forName("UTF-8").toString());
Document document = Jsoup.parse(htmlPath.toFile(), StandardCharsets.UTF_8.toString());
Elements title = document.select("title");
assertThat(title.isEmpty(), is(false));
assertThat(title.text(), is("Test-Title"));
Elements span = document.select("span.title");
assertThat(span.isEmpty(), is(false));
assertThat(span.text(), is("Test-Title"));
}

@Test
public void testHtmlTitleInSiteReport() throws IOException {
Path htmlPath = Paths.get(System.getProperty("user.dir"), "target", "site", "japicmp-test-v1_japicmp-test-v2.html");
assertThat(Files.exists(htmlPath), is(true));
Document document = Jsoup.parse(htmlPath.toFile(), StandardCharsets.UTF_8.toString());
Elements title = document.select("title");
assertThat(title.isEmpty(), is(false));
assertThat(title.text(), is("japicmp-test-maven-plugin – Test-Title for Site-Report"));
}
}

0 comments on commit 90ae1eb

Please sign in to comment.