Skip to content

Commit 3965166

Browse files
chohanbingermanattanasio
authored andcommitted
feat(docs): Add support for APIDiff (watson-developer-cloud#928)
* :crystall_ball: Enable generating API diff between the latest java-sdk release and the java-sdk in the current directory by invoking apidiff.sh * Remove printing out current jar by default. Only print on failure * Update the API Diff report filename prefix * Stop generating txt version of API Diff report. HTML version alone is sufficient. * 🔮 Upload API diffs to WDC Java SDK webpage * 🎨 Rename apidiff.sh to generate-api-diff.sh to clarify its function. * 🎨 Move generate-api-diff.sh under .utility folder that houses other documentation generation scripts * 😒 Replace a tab character with four spaces to be consistent with other indented lines. * 😒 Update places where apidiff.sh used to be invoked to call generate-api-diff.sh instead. * 📝 Remove steps no longer needed in generate-api-diff.sh, and add a high-level description of the script.
1 parent 2a1f307 commit 3965166

5 files changed

Lines changed: 126 additions & 2 deletions

File tree

‎.utility/generate-api-diff.sh‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
# Author: Hanbin Cho (mraerok@gmail.com)
3+
# Description: This script 1) downloads the latest java-sdk jar published in Maven Repo 2) builds the jar of current java-sdk version, then 3) generate an API diff report of the two versions.
4+
# Assumptions
5+
# 1. This script is placed in the project root of java-sdk.
6+
# 2. Version format is [0-9].[0-9].[0-9]
7+
8+
# Step 1: Download the latest release of java-sdk published in Maven Repository.
9+
mvn dependency:get \
10+
-DgroupId=com.ibm.watson.developer_cloud \
11+
-DartifactId=java-sdk \
12+
-Dversion=LATEST \
13+
-Dpackaging=jar \
14+
-Dclassifier=jar-with-dependencies \
15+
-Dtransitive=false
16+
17+
# Step 2: Construct the filepath to the latest release of java-sdk.
18+
LOCAL_MAVEN_REPO_PATH="${HOME}/.m2/repository"
19+
RELEASE_JAR_BASEPATH="${LOCAL_MAVEN_REPO_PATH}/com/ibm/watson/developer_cloud/java-sdk"
20+
pushd $RELEASE_JAR_BASEPATH
21+
LATEST_RELEASE_VERSION=`ls | grep -d read "[0-9]\.[0-9]\.[0-9]" | sort | tail -n 1`
22+
LATEST_RELEASE_JAR_FILENAME="java-sdk-${LATEST_RELEASE_VERSION}-jar-with-dependencies.jar"
23+
LATEST_RELEASE_JAR_PATH="${RELEASE_JAR_BASEPATH}/${LATEST_RELEASE_VERSION}/${LATEST_RELEASE_JAR_FILENAME}"
24+
25+
# Step 3: Validate the filepath to the latest release of java-sdk.
26+
if [ ! -f $LATEST_RELEASE_JAR_PATH ]; then
27+
echo "apidiff.sh: Latest release jar was not at its expected location at: $LATEST_RELEASE_JAR_PATH"
28+
popd
29+
exit 1
30+
fi
31+
popd
32+
33+
# Step 4: Generate a stand-alone jar of the current version of java-sdk.
34+
./gradlew shadowJar
35+
36+
# Step 5: Construct the filepath to the current version of java-sdk.
37+
CURRENT_VERSION=`cat gradle.properties | grep "version=[0-9]\.[0-9]\.[0-9]" | cut -d '=' -f 2`
38+
CURRENT_JAR_FILENAME="java-sdk-${CURRENT_VERSION}-jar-with-dependencies.jar"
39+
CURRENT_JAR_BASEPATH="java-sdk/build/libs"
40+
CURRENT_JAR_PATH="${CURRENT_JAR_BASEPATH}/${CURRENT_JAR_FILENAME}"
41+
42+
# Step 6: Validate the filepath to the current version of java-sdk.
43+
if [ ! -f $CURRENT_JAR_PATH ]; then
44+
echo "apidiff.sh: Current jar was not at its expected location at: $CURRENT_JAR_PATH"
45+
exit 1
46+
fi
47+
48+
# Step 7: Produce an API diff between the latest release and the current version using japicmp module.
49+
# TODO: Figure out how to set japicmp task's properties (oldClasspath and newClasspath) through command-line invocation.
50+
./gradlew japicmp -PoldJarPath="${LATEST_RELEASE_JAR_PATH}" -PnewJarPath="${CURRENT_JAR_PATH}" -PoldJarVersion="${LATEST_RELEASE_VERSION}" -PnewJarVersion="${CURRENT_VERSION}"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
3+
# based on https://odoepner.wordpress.com/2012/02/17/shell-script-to-generate-simple-index-html/
4+
5+
echo '<!DOCTYPE html>
6+
<html>
7+
<head>
8+
<meta charset="utf-8">
9+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
10+
<meta name="viewport" content="width=device-width, initial-scale=1">
11+
<title>IBM Watson Developer Cloud</title>
12+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
13+
</head>
14+
<body>
15+
<div class="container">
16+
<div class="page-header">
17+
<h1>IBM Watson Developer Cloud Java SDK API Diff</h1>
18+
</div>
19+
<p><a href="https://www.ibm.com/watson/developer/">Info</a>
20+
| <a href="https://console.bluemix.net/developer/watson/documentation">Documentation</a>
21+
| API Diff
22+
| <a href="https://github.com/watson-developer-cloud/java-sdk">GitHub</a>
23+
| <a href="http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.ibm.watson.developer_cloud%22%20a%3A%22java-sdk%22">Maven</a>
24+
</p>
25+
<p>API Diff by version</p>
26+
<ul>'
27+
ls apidiff/ | grep --invert-match index.html | sed 's/^.*/<li><a href="&">&<\/a><\/li>/'
28+
echo ' </ul>
29+
</div>
30+
<script>
31+
(function(i,s,o,g,r,a,m){i["GoogleAnalyticsObject"]=r;i[r]=i[r]||function(){
32+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
33+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
34+
})(window,document,"script","//www.google-analytics.com/analytics.js","ga");
35+
ga("create", "UA-59827755-4", "auto");
36+
ga("send", "pageview");
37+
</script>
38+
</body>
39+
</html>'

‎.utility/generate_index_html.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ echo '<!DOCTYPE html>
1919
2020
<p><a href="https://www.ibm.com/watson/developer/">Info</a>
2121
| <a href="https://console.bluemix.net/developer/watson/documentation">Documentation</a>
22+
| <a href="http://watson-developer-cloud.github.io/java-sdk/apidiff">API Diff</a>
2223
| <a href="https://github.com/watson-developer-cloud/java-sdk">GitHub</a>
2324
| <a href="http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.ibm.watson.developer_cloud%22%20a%3A%22java-sdk%22">Maven</a>
2425
</p>

‎.utility/push-javadoc-to-gh-pages.sh‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" ]; then
1010
# on tagged builds, $TRAVIS_BRANCH is the tag (e.g. v1.2.3), otherwise it's the branch name (e.g. master)
1111
rm -rf docs/$TRAVIS_BRANCH
1212
mkdir -p docs/$TRAVIS_BRANCH
13-
1413
cp -rf ../build/docs/all/* docs/$TRAVIS_BRANCH
1514
../.utility/generate_index_html.sh > index.html
1615

17-
# update the latest/ symlink
16+
# produce API diff of the current version and the latest release
17+
../.utility/generate-api-diff.sh
18+
rm -rf apidiff/
19+
mkdir apidiff/
20+
cp -f ../build/reports/java-sdk-api-diff* apidiff/
21+
../.utility/generate_apidiff_index_html.sh > apidiff/index.html
22+
23+
# update the latest/ symlink
1824
# on tagged builds, $TRAVIS_TAG is set to the tag, but it's blank on regular builds, unlike $TRAVIS_BRANCH
1925
if [ $TRAVIS_TAG ]; then
2026
rm latest

‎build.gradle‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id 'net.researchgate.release' version '2.4.0'
3+
id 'me.champeau.gradle.japicmp' version '0.2.6'
34
}
45

56
apply from: 'utils.gradle'
@@ -138,5 +139,32 @@ task printversion {
138139
}
139140
}
140141

142+
task japicmp(type: me.champeau.gradle.japicmp.JapicmpTask) {
143+
ext.oldJarVersion =
144+
project.hasProperty('oldJarVersion')
145+
? project.getProperty('oldJarVersion')
146+
: "pass-in-older-jar-version"
147+
ext.newJarVersion =
148+
project.hasProperty('newJarVersion')
149+
? project.getProperty('newJarVersion')
150+
: "pass-in-newer-jar-version"
151+
ext.oldJarPath =
152+
project.hasProperty('oldJarPath')
153+
? project.getProperty('oldJarPath')
154+
: "pass/in/path/to/older/version.jar"
155+
ext.newJarPath =
156+
project.hasProperty('newJarPath')
157+
? project.getProperty('newJarPath')
158+
: "pass/in/path/to/newer/version.jar"
159+
160+
oldClasspath = files(oldJarPath)
161+
newClasspath = files(newJarPath)
162+
163+
onlyModified = true
164+
failOnModification = true
165+
166+
htmlOutputFile = file("$buildDir/reports/java-sdk-api-diff-" + oldJarVersion + "-to-" + newJarVersion + ".html")
167+
}
168+
141169
beforeReleaseBuild.dependsOn startmessage
142170
afterReleaseBuild.dependsOn printversion

0 commit comments

Comments
 (0)