|
| 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}" |
0 commit comments