Skip to content

Commit cbd89b0

Browse files
committed
Merge branch 'guillermocalvo-markdown'
2 parents 87926c1 + b1613cb commit cbd89b0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+5335
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ in less than one second and therewith can be easily integrated in each build.
105105

106106
* Comparison of two jar archives without the need to add all of their dependencies to the classpath.
107107
* Differences are printed on the command line in a simple diff format.
108-
* Differences can optionally be printed as XML or HTML file.
108+
* Differences can optionally be printed as [Markdown](https://www.markdownguide.org/), XML or HTML file.
109109
* 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
110110
compared can be set to public, protected, package or private.
111111
* 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.

doc/japicmp_guava.md

Lines changed: 3177 additions & 0 deletions
Large diffs are not rendered by default.

doc/japicmp_guava_markdown.png

214 KB
Loading

japicmp-ant-task/src/main/java/japicmp/ant/JApiCmpTask.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import japicmp.output.html.HtmlOutputGenerator;
1010
import japicmp.output.html.HtmlOutputGeneratorOptions;
1111
import japicmp.output.incompatible.IncompatibleErrorOutput;
12+
import japicmp.output.markdown.MarkdownOutputGenerator;
1213
import japicmp.output.semver.SemverOut;
1314
import japicmp.output.stdout.StdoutOutputGenerator;
1415
import japicmp.output.xml.XmlOutput;
@@ -38,6 +39,7 @@ public class JApiCmpTask extends Task {
3839
private boolean includeSynthetic = false;
3940
private boolean noAnnotations = false;
4041
private boolean semanticVersioning = false;
42+
private boolean markdown = false;
4143
private boolean reportOnlyFilename = false;
4244
private boolean reportOnlySummary = false;
4345
private boolean ignoreMissingClasses = false;
@@ -46,6 +48,7 @@ public class JApiCmpTask extends Task {
4648
private final List<String> ignoreMissingClassesByRegularExpressions = new ArrayList<>();
4749
private String accessModifier = "protected";
4850
private String semanticVersionProperty;
51+
private String markdownProperty;
4952
private String oldJar;
5053
private String newJar;
5154
private Path oldClassPath;
@@ -88,6 +91,15 @@ public void setSemVerProperty(String semverProperty) {
8891
semanticVersionProperty = semverProperty;
8992
}
9093

94+
public void setMarkdown(String markdown) {
95+
this.markdown = Project.toBoolean(markdown);
96+
}
97+
98+
public void setMarkdownProperty(String mdProperty) {
99+
markdown = Boolean.TRUE;
100+
markdownProperty = mdProperty;
101+
}
102+
91103
public void setReportOnlyFilename(String reportOnlyFilename) {
92104
this.reportOnlyFilename = Project.toBoolean(reportOnlyFilename);
93105
}
@@ -284,6 +296,14 @@ private void generateOutput(Options options, List<JApiClass> jApiClasses, JarArc
284296
}
285297
log(semver);
286298
return;
299+
} else if (markdown) {
300+
MarkdownOutputGenerator markdownOutputGenerator = new MarkdownOutputGenerator(options, jApiClasses);
301+
String md = markdownOutputGenerator.generate();
302+
if (markdownProperty != null) {
303+
getProject().setProperty(markdownProperty, md);
304+
}
305+
log(md);
306+
return;
287307
}
288308

289309
if (!options.getXmlOutputFile().isPresent() && !options.getHtmlOutputFile().isPresent()) {

japicmp-maven-plugin/src/main/java/japicmp/maven/JApiCmpMojo.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import japicmp.output.html.HtmlOutputGenerator;
1616
import japicmp.output.html.HtmlOutputGeneratorOptions;
1717
import japicmp.output.incompatible.IncompatibleErrorOutput;
18+
import japicmp.output.markdown.MarkdownOutputGenerator;
19+
import japicmp.output.markdown.config.MarkdownOptions;
1820
import japicmp.output.semver.SemverOut;
1921
import japicmp.output.stdout.StdoutOutputGenerator;
2022
import japicmp.output.xml.XmlOutput;
@@ -77,6 +79,8 @@ public class JApiCmpMojo extends AbstractMojo {
7779
private boolean skip;
7880
@org.apache.maven.plugins.annotations.Parameter(property = "japicmp.skip", defaultValue = "false")
7981
private boolean skipExec;
82+
@org.apache.maven.plugins.annotations.Parameter(property = "japicmp.skipMarkdownReport", required = false)
83+
private boolean skipMarkdownReport;
8084
@org.apache.maven.plugins.annotations.Parameter(property = "japicmp.skipXmlReport", required = false)
8185
private boolean skipXmlReport;
8286
@org.apache.maven.plugins.annotations.Parameter(property = "japicmp.skipHtmlReport", required = false)
@@ -148,6 +152,9 @@ Optional<HtmlOutput> executeWithParameters(PluginParameters pluginParameters, Ma
148152
SemverOut semverOut = new SemverOut(options, jApiClasses);
149153
String semanticVersioningInformation = semverOut.generate();
150154
generateDiffOutput(mavenParameters, pluginParameters, options, jApiClasses, jApiCmpBuildDir, semanticVersioningInformation);
155+
if (!skipMarkdownReport(pluginParameters)) {
156+
generateMarkdownOutput(mavenParameters, pluginParameters, options, jApiClasses, jApiCmpBuildDir);
157+
}
151158
if (!skipXmlReport(pluginParameters)) {
152159
XmlOutput xmlOutput = generateXmlOutput(jApiClasses, jApiCmpBuildDir, options, mavenParameters, pluginParameters, semanticVersioningInformation);
153160
if (pluginParameters.isWriteToFiles()) {
@@ -576,6 +583,18 @@ private void generateDiffOutput(MavenParameters mavenParameters, PluginParameter
576583
}
577584
}
578585

586+
private void generateMarkdownOutput(MavenParameters mavenParameters, PluginParameters pluginParameters, Options options,
587+
List<JApiClass> jApiClasses, File jApiCmpBuildDir) throws IOException, MojoFailureException {
588+
MarkdownOptions mdOptions = MarkdownOptions.newDefault(options);
589+
if (pluginParameters.getParameterParam() != null && pluginParameters.getParameterParam().getMarkdownTitle() != null) {
590+
mdOptions.title.report = pluginParameters.getParameterParam().getMarkdownTitle();
591+
}
592+
MarkdownOutputGenerator mdOut = new MarkdownOutputGenerator(mdOptions, jApiClasses);
593+
String markdown = mdOut.generate();
594+
File output = new File(jApiCmpBuildDir.getCanonicalPath() + File.separator + createFilename(mavenParameters) + ".md");
595+
writeToFile(markdown, output);
596+
}
597+
579598
private XmlOutput generateXmlOutput(List<JApiClass> jApiClasses, File jApiCmpBuildDir, Options options, MavenParameters mavenParameters,
580599
PluginParameters pluginParameters, String semanticVersioningInformation) throws IOException {
581600
String filename = createFilename(mavenParameters);
@@ -621,6 +640,14 @@ private boolean skipXmlReport(PluginParameters pluginParameters) {
621640
return skipReport || this.skipXmlReport;
622641
}
623642

643+
private boolean skipMarkdownReport(PluginParameters pluginParameters) {
644+
boolean skipReport = false;
645+
if (pluginParameters.getParameterParam() != null) {
646+
skipReport = pluginParameters.getParameterParam().getSkipMarkdownReport();
647+
}
648+
return skipReport || this.skipMarkdownReport;
649+
}
650+
624651
private String createFilename(MavenParameters mavenParameters) {
625652
String filename = "japicmp";
626653
String executionId = mavenParameters.getMojoExecution().getExecutionId();

japicmp-maven-plugin/src/main/java/japicmp/maven/Parameter.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public class Parameter {
2323
@org.apache.maven.plugins.annotations.Parameter(required = false)
2424
private String htmlTitle;
2525
@org.apache.maven.plugins.annotations.Parameter(required = false)
26+
private String markdownTitle;
27+
@org.apache.maven.plugins.annotations.Parameter(required = false)
2628
private boolean noAnnotations;
2729
@org.apache.maven.plugins.annotations.Parameter(required = false)
2830
private String ignoreNonResolvableArtifacts;
@@ -35,6 +37,8 @@ public class Parameter {
3537
@org.apache.maven.plugins.annotations.Parameter(required = false)
3638
private boolean skipXmlReport;
3739
@org.apache.maven.plugins.annotations.Parameter(required = false)
40+
private boolean skipMarkdownReport;
41+
@org.apache.maven.plugins.annotations.Parameter(required = false)
3842
private boolean skipDiffReport;
3943
@org.apache.maven.plugins.annotations.Parameter(required = false)
4044
private boolean ignoreMissingOldVersion;
@@ -221,6 +225,14 @@ public void setHtmlTitle(String htmlTitle) {
221225
this.htmlTitle = htmlTitle;
222226
}
223227

228+
public String getMarkdownTitle() {
229+
return markdownTitle;
230+
}
231+
232+
public void setMarkdownTitle(String markdownTitle) {
233+
this.markdownTitle = markdownTitle;
234+
}
235+
224236
public String getIgnoreNonResolvableArtifacts() {
225237
return ignoreNonResolvableArtifacts;
226238
}
@@ -277,6 +289,14 @@ public void setSkipXmlReport(boolean skipXmlReport) {
277289
this.skipXmlReport = skipXmlReport;
278290
}
279291

292+
public boolean getSkipMarkdownReport() {
293+
return skipMarkdownReport;
294+
}
295+
296+
public void setSkipMarkdownReport(boolean skipMarkdownReport) {
297+
this.skipMarkdownReport = skipMarkdownReport;
298+
}
299+
280300
public boolean isSkipDiffReport() {
281301
return skipDiffReport;
282302
}

japicmp-testbase/japicmp-test-maven-plugin/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
<includeSynthetic>true</includeSynthetic>
109109
<htmlStylesheet>${project.basedir}/src/main/resources/css/stylesheet.css</htmlStylesheet>
110110
<htmlTitle>Test-Title</htmlTitle>
111+
<markdownTitle>Test-Markdown-Title</markdownTitle>
111112
</parameter>
112113
<dependencies>
113114
<dependency>
@@ -190,6 +191,7 @@
190191
<onlyModified>true</onlyModified>
191192
<skipXmlReport>true</skipXmlReport>
192193
<skipHtmlReport>true</skipHtmlReport>
194+
<skipMarkdownReport>true</skipMarkdownReport>
193195
</parameter>
194196
<dependencies>
195197
<dependency>

japicmp-testbase/japicmp-test-maven-plugin/src/test/java/japicmp/test/ITClassFileFormatVersion.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ public void testClassFileFormatVersionIsPresent() throws IOException {
3838
}
3939
}
4040

41+
@Test
42+
public void testMarkdownReportDiffClassFileFormatVersionIsPresent() throws IOException {
43+
Path path = Paths.get(System.getProperty("user.dir"), "target", "japicmp", "class-file-format-version.md");
44+
if (!Files.exists(path)) {
45+
return; //in JDK 1.7 case
46+
}
47+
assertThat(Files.exists(path), is(true));
48+
List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);
49+
boolean found = false;
50+
for (String line : lines) {
51+
if (line.contains("~~JDK 6~~ &rarr; **JDK 8**")) {
52+
found = true;
53+
break;
54+
}
55+
}
56+
assertThat(found, is(true));
57+
}
58+
4159
@Test
4260
public void testStoutDiffClassFileFormatVersionIsPresent() throws IOException {
4361
Path path = Paths.get(System.getProperty("user.dir"), "target", "japicmp", "class-file-format-version.diff");
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package japicmp.test;
2+
3+
import static org.hamcrest.MatcherAssert.assertThat;
4+
import static org.hamcrest.core.Is.is;
5+
6+
import java.io.IOException;
7+
import java.nio.charset.StandardCharsets;
8+
import java.nio.file.Files;
9+
import java.nio.file.Path;
10+
import java.nio.file.Paths;
11+
import java.util.List;
12+
import org.junit.Test;
13+
14+
public class ITMarkdownTitle {
15+
16+
@Test
17+
public void testMarkdownTitle() throws IOException {
18+
Path markdownPath = Paths.get(System.getProperty("user.dir"), "target", "japicmp", "single-version.md");
19+
assertThat(Files.exists(markdownPath), is(true));
20+
List<String> lines = Files.readAllLines(markdownPath, StandardCharsets.UTF_8);
21+
boolean found = false;
22+
for (String line : lines) {
23+
if (line.equals("# Test-Markdown-Title")) {
24+
found = true;
25+
break;
26+
}
27+
}
28+
assertThat(found, is(true));
29+
}
30+
}

japicmp-testbase/japicmp-test-maven-plugin/src/test/java/japicmp/test/ITModuleExcluded.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public void testHtmlReportNotGenerated() throws IOException {
2121
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "ignore-module.xml")), is(false));
2222
}
2323

24+
@Test
25+
public void testMarkdownReportGenerated() throws IOException {
26+
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "ignore-module.md")), is(false));
27+
}
28+
2429
@Test
2530
public void testDiffReportGenerated() throws IOException {
2631
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "japicmp", "ignore-module.diff")), is(false));

0 commit comments

Comments
 (0)