Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New option to generate reports in Markdown format --markdown #405

Merged
merged 15 commits into from
Aug 20, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ in less than one second and therewith can be easily integrated in each build.

* Comparison of two jar archives without the need to add all of their dependencies to the classpath.
* Differences are printed on the command line in a simple diff format.
* Differences can optionally be printed as XML or HTML file.
* Differences can optionally be printed as [Markdown](https://www.markdownguide.org/), XML or HTML file.
* Per default private and package protected classes and class members are not compared. If necessary, the access modifier of the classes and class members to be
compared can be set to public, protected, package or private.
* Per default all classes are tracked. If necessary, certain packages, classes, methods or fields can be excluded or explicitly included. Inclusion and exclusion is also possible based on annotations.
Expand Down
3,177 changes: 3,177 additions & 0 deletions doc/japicmp_guava.md

Large diffs are not rendered by default.

Binary file added doc/japicmp_guava_markdown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions japicmp-ant-task/src/main/java/japicmp/ant/JApiCmpTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import japicmp.output.html.HtmlOutputGenerator;
import japicmp.output.html.HtmlOutputGeneratorOptions;
import japicmp.output.incompatible.IncompatibleErrorOutput;
import japicmp.output.markdown.MarkdownOutputGenerator;
import japicmp.output.semver.SemverOut;
import japicmp.output.stdout.StdoutOutputGenerator;
import japicmp.output.xml.XmlOutput;
Expand Down Expand Up @@ -38,6 +39,7 @@ public class JApiCmpTask extends Task {
private boolean includeSynthetic = false;
private boolean noAnnotations = false;
private boolean semanticVersioning = false;
private boolean markdown = false;
private boolean reportOnlyFilename = false;
private boolean reportOnlySummary = false;
private boolean ignoreMissingClasses = false;
Expand All @@ -46,6 +48,7 @@ public class JApiCmpTask extends Task {
private final List<String> ignoreMissingClassesByRegularExpressions = new ArrayList<>();
private String accessModifier = "protected";
private String semanticVersionProperty;
private String markdownProperty;
private String oldJar;
private String newJar;
private Path oldClassPath;
Expand Down Expand Up @@ -88,6 +91,15 @@ public void setSemVerProperty(String semverProperty) {
semanticVersionProperty = semverProperty;
}

public void setMarkdown(String markdown) {
this.markdown = Project.toBoolean(markdown);
}

public void setMarkdownProperty(String mdProperty) {
markdown = Boolean.TRUE;
markdownProperty = mdProperty;
}

public void setReportOnlyFilename(String reportOnlyFilename) {
this.reportOnlyFilename = Project.toBoolean(reportOnlyFilename);
}
Expand Down Expand Up @@ -284,6 +296,14 @@ private void generateOutput(Options options, List<JApiClass> jApiClasses, JarArc
}
log(semver);
return;
} else if (markdown) {
MarkdownOutputGenerator markdownOutputGenerator = new MarkdownOutputGenerator(options, jApiClasses);
String md = markdownOutputGenerator.generate();
if (markdownProperty != null) {
getProject().setProperty(markdownProperty, md);
}
log(md);
return;
}

if (!options.getXmlOutputFile().isPresent() && !options.getHtmlOutputFile().isPresent()) {
Expand Down
27 changes: 27 additions & 0 deletions japicmp-maven-plugin/src/main/java/japicmp/maven/JApiCmpMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import japicmp.output.html.HtmlOutputGenerator;
import japicmp.output.html.HtmlOutputGeneratorOptions;
import japicmp.output.incompatible.IncompatibleErrorOutput;
import japicmp.output.markdown.MarkdownOutputGenerator;
import japicmp.output.markdown.config.MarkdownOptions;
import japicmp.output.semver.SemverOut;
import japicmp.output.stdout.StdoutOutputGenerator;
import japicmp.output.xml.XmlOutput;
Expand Down Expand Up @@ -77,6 +79,8 @@ public class JApiCmpMojo extends AbstractMojo {
private boolean skip;
@org.apache.maven.plugins.annotations.Parameter(property = "japicmp.skip", defaultValue = "false")
private boolean skipExec;
@org.apache.maven.plugins.annotations.Parameter(property = "japicmp.skipMarkdownReport", required = false)
private boolean skipMarkdownReport;
@org.apache.maven.plugins.annotations.Parameter(property = "japicmp.skipXmlReport", required = false)
private boolean skipXmlReport;
@org.apache.maven.plugins.annotations.Parameter(property = "japicmp.skipHtmlReport", required = false)
Expand Down Expand Up @@ -148,6 +152,9 @@ Optional<HtmlOutput> executeWithParameters(PluginParameters pluginParameters, Ma
SemverOut semverOut = new SemverOut(options, jApiClasses);
String semanticVersioningInformation = semverOut.generate();
generateDiffOutput(mavenParameters, pluginParameters, options, jApiClasses, jApiCmpBuildDir, semanticVersioningInformation);
if (!skipMarkdownReport(pluginParameters)) {
generateMarkdownOutput(mavenParameters, pluginParameters, options, jApiClasses, jApiCmpBuildDir);
}
if (!skipXmlReport(pluginParameters)) {
XmlOutput xmlOutput = generateXmlOutput(jApiClasses, jApiCmpBuildDir, options, mavenParameters, pluginParameters, semanticVersioningInformation);
if (pluginParameters.isWriteToFiles()) {
Expand Down Expand Up @@ -576,6 +583,18 @@ private void generateDiffOutput(MavenParameters mavenParameters, PluginParameter
}
}

private void generateMarkdownOutput(MavenParameters mavenParameters, PluginParameters pluginParameters, Options options,
List<JApiClass> jApiClasses, File jApiCmpBuildDir) throws IOException, MojoFailureException {
MarkdownOptions mdOptions = MarkdownOptions.newDefault(options);
if (pluginParameters.getParameterParam() != null && pluginParameters.getParameterParam().getMarkdownTitle() != null) {
mdOptions.title.report = pluginParameters.getParameterParam().getMarkdownTitle();
}
MarkdownOutputGenerator mdOut = new MarkdownOutputGenerator(mdOptions, jApiClasses);
String markdown = mdOut.generate();
File output = new File(jApiCmpBuildDir.getCanonicalPath() + File.separator + createFilename(mavenParameters) + ".md");
writeToFile(markdown, output);
}

private XmlOutput generateXmlOutput(List<JApiClass> jApiClasses, File jApiCmpBuildDir, Options options, MavenParameters mavenParameters,
PluginParameters pluginParameters, String semanticVersioningInformation) throws IOException {
String filename = createFilename(mavenParameters);
Expand Down Expand Up @@ -621,6 +640,14 @@ private boolean skipXmlReport(PluginParameters pluginParameters) {
return skipReport || this.skipXmlReport;
}

private boolean skipMarkdownReport(PluginParameters pluginParameters) {
boolean skipReport = false;
if (pluginParameters.getParameterParam() != null) {
skipReport = pluginParameters.getParameterParam().getSkipMarkdownReport();
}
return skipReport || this.skipMarkdownReport;
}

private String createFilename(MavenParameters mavenParameters) {
String filename = "japicmp";
String executionId = mavenParameters.getMojoExecution().getExecutionId();
Expand Down
20 changes: 20 additions & 0 deletions japicmp-maven-plugin/src/main/java/japicmp/maven/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class Parameter {
@org.apache.maven.plugins.annotations.Parameter(required = false)
private String htmlTitle;
@org.apache.maven.plugins.annotations.Parameter(required = false)
private String markdownTitle;
@org.apache.maven.plugins.annotations.Parameter(required = false)
private boolean noAnnotations;
@org.apache.maven.plugins.annotations.Parameter(required = false)
private String ignoreNonResolvableArtifacts;
Expand All @@ -35,6 +37,8 @@ public class Parameter {
@org.apache.maven.plugins.annotations.Parameter(required = false)
private boolean skipXmlReport;
@org.apache.maven.plugins.annotations.Parameter(required = false)
private boolean skipMarkdownReport;
@org.apache.maven.plugins.annotations.Parameter(required = false)
private boolean skipDiffReport;
@org.apache.maven.plugins.annotations.Parameter(required = false)
private boolean ignoreMissingOldVersion;
Expand Down Expand Up @@ -221,6 +225,14 @@ public void setHtmlTitle(String htmlTitle) {
this.htmlTitle = htmlTitle;
}

public String getMarkdownTitle() {
return markdownTitle;
}

public void setMarkdownTitle(String markdownTitle) {
this.markdownTitle = markdownTitle;
}

public String getIgnoreNonResolvableArtifacts() {
return ignoreNonResolvableArtifacts;
}
Expand Down Expand Up @@ -277,6 +289,14 @@ public void setSkipXmlReport(boolean skipXmlReport) {
this.skipXmlReport = skipXmlReport;
}

public boolean getSkipMarkdownReport() {
return skipMarkdownReport;
}

public void setSkipMarkdownReport(boolean skipMarkdownReport) {
this.skipMarkdownReport = skipMarkdownReport;
}

public boolean isSkipDiffReport() {
return skipDiffReport;
}
Expand Down
2 changes: 2 additions & 0 deletions japicmp-testbase/japicmp-test-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<includeSynthetic>true</includeSynthetic>
<htmlStylesheet>${project.basedir}/src/main/resources/css/stylesheet.css</htmlStylesheet>
<htmlTitle>Test-Title</htmlTitle>
<markdownTitle>Test-Markdown-Title</markdownTitle>
</parameter>
<dependencies>
<dependency>
Expand Down Expand Up @@ -190,6 +191,7 @@
<onlyModified>true</onlyModified>
<skipXmlReport>true</skipXmlReport>
<skipHtmlReport>true</skipHtmlReport>
<skipMarkdownReport>true</skipMarkdownReport>
</parameter>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ public void testClassFileFormatVersionIsPresent() throws IOException {
}
}

@Test
public void testMarkdownReportDiffClassFileFormatVersionIsPresent() throws IOException {
Path path = Paths.get(System.getProperty("user.dir"), "target", "japicmp", "class-file-format-version.md");
if (!Files.exists(path)) {
return; //in JDK 1.7 case
}
assertThat(Files.exists(path), is(true));
List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);
boolean found = false;
for (String line : lines) {
if (line.contains("~~JDK 6~~ &rarr; **JDK 8**")) {
found = true;
break;
}
}
assertThat(found, is(true));
}

@Test
public void testStoutDiffClassFileFormatVersionIsPresent() throws IOException {
Path path = Paths.get(System.getProperty("user.dir"), "target", "japicmp", "class-file-format-version.diff");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package japicmp.test;

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

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import org.junit.Test;

public class ITMarkdownTitle {

@Test
public void testMarkdownTitle() throws IOException {
Path markdownPath = Paths.get(System.getProperty("user.dir"), "target", "japicmp", "single-version.md");
assertThat(Files.exists(markdownPath), is(true));
List<String> lines = Files.readAllLines(markdownPath, StandardCharsets.UTF_8);
boolean found = false;
for (String line : lines) {
if (line.equals("# Test-Markdown-Title")) {
found = true;
break;
}
}
assertThat(found, is(true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public void testHtmlReportNotGenerated() throws IOException {
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "ignore-module.xml")), is(false));
}

@Test
public void testMarkdownReportGenerated() throws IOException {
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "ignore-module.md")), is(false));
}

@Test
public void testDiffReportGenerated() throws IOException {
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "ignore-module.diff")), is(false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ public class ITMultipleExecutions {
public void testThatXmlAndHtmlFilesAreWritten() {
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "multiple-versions.html")), is(true));
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "multiple-versions.xml")), is(true));
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "multiple-versions.md")), is(true));
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "multiple-versions.diff")), is(true));
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "single-version.html")), is(true));
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "single-version.xml")), is(true));
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "single-version.md")), is(true));
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "single-version.diff")), is(true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public void testHtmlReportNotGenerated() throws IOException {
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "no-reports.xml")), is(false));
}

@Test
public void testMarkdownReportNotGenerated() throws IOException {
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "no-reports.md")), is(false));
}

@Test
public void testDiffReportGenerated() throws IOException {
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "no-reports.diff")), is(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public void testHtmlReportNotGenerated() throws IOException {
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "skip.xml")), is(false));
}

@Test
public void testMarkdownReportGenerated() throws IOException {
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "skip.md")), is(false));
}

@Test
public void testDiffReportGenerated() throws IOException {
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "skip.diff")), is(false));
Expand Down
6 changes: 6 additions & 0 deletions japicmp/src/main/java/japicmp/cli/CliParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public Options parse(String[] args) throws IllegalArgumentException {
options.setHtmlOutputFile(Optional.fromNullable(pathToHtmlOutputFile));
} else if ("-s".equals(arg) || "--semantic-versioning".equals(arg)) {
options.setSemanticVersioning(true);
} else if ("--markdown".equals(arg)) {
options.setMarkdown(true);
} else if ("--include-synthetic".equals(arg)) {
options.setIncludeSynthetic(true);
} else if (IGNORE_MISSING_CLASSES.equals(arg)) {
Expand Down Expand Up @@ -128,6 +130,7 @@ public static void printHelp() {
" [--old-classpath <oldClassPath>]\n" +
" [--report-only-filename] [--report-only-summary]\n" +
" [(-s | --semantic-versioning)]\n" +
" [--markdown]\n" +
" [(-x <pathToXmlOutputFile> | --xml-file <pathToXmlOutputFile>)]\n" +
" [--error-on-binary-incompatibility]\n" +
" [--error-on-source-incompatibility]\n" +
Expand Down Expand Up @@ -215,6 +218,9 @@ public static void printHelp() {
" -s, --semantic-versioning\n" +
" Tells you which part of the version to increment.\n" +
"\n" +
" --markdown\n" +
" Generates output in Markdown format.\n" +
"\n" +
" -x <pathToXmlOutputFile>, --xml-file <pathToXmlOutputFile>\n" +
" Provides the path to the xml output file.\n" +
"\n" +
Expand Down
7 changes: 7 additions & 0 deletions japicmp/src/main/java/japicmp/cli/JApiCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import japicmp.output.html.HtmlOutputGenerator;
import japicmp.output.html.HtmlOutputGeneratorOptions;
import japicmp.output.incompatible.IncompatibleErrorOutput;
import japicmp.output.markdown.MarkdownOutputGenerator;
import japicmp.output.semver.SemverOut;
import japicmp.output.stdout.StdoutOutputGenerator;
import japicmp.output.xml.XmlOutput;
Expand Down Expand Up @@ -69,6 +70,12 @@ private void generateOutput(Options options, List<JApiClass> jApiClasses, JarArc
throw new JApiCmpException(JApiCmpException.Reason.IoException, "Could not write HTML file: " + e.getMessage(), e);
}
}
if (options.isMarkdown()) {
MarkdownOutputGenerator markdownOutputGenerator = new MarkdownOutputGenerator(options, jApiClasses);
String output = markdownOutputGenerator.generate();
System.out.println(output);
return;
guillermocalvo marked this conversation as resolved.
Show resolved Hide resolved
}
StdoutOutputGenerator stdoutOutputGenerator = new StdoutOutputGenerator(options, jApiClasses);
String output = stdoutOutputGenerator.generate();
System.out.println(output);
Expand Down
9 changes: 9 additions & 0 deletions japicmp/src/main/java/japicmp/config/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class Options {
private boolean reportOnlyFilename;
private boolean reportOnlySummary;
private boolean semanticVersioning;
private boolean markdown;
private boolean errorOnBinaryIncompatibility;
private boolean errorOnSourceIncompatibility;
private boolean errorOnExclusionIncompatibility = true;
Expand Down Expand Up @@ -398,6 +399,14 @@ public boolean isSemanticVersioning() {
return semanticVersioning;
}

public void setMarkdown(boolean markdown) {
this.markdown = markdown;
}

public boolean isMarkdown() {
return markdown;
}

public boolean isErrorOnBinaryIncompatibility() {
return errorOnBinaryIncompatibility;
}
Expand Down
Loading
Loading