diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000000..a057c1b1fa --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,5 @@ +# Code owners file. +# This file controls who is tagged for review for any given pull request. + + # For anything not explicitly taken by someone else: +* @bogdandrutu @carlosalberto @SergeyKanzhelev @yurishkuro \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..3e0746f040 --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +# Gradle +build +gradle.properties +.gradle +local.properties +out/ + +# Maven (proto) +target + +# IntelliJ IDEA +.idea +*.iml +.editorconfig + +# Eclipse +.classpath +.project +.settings +bin + +# NetBeans +/.nb-gradle +/.nb-gradle-properties + +# VS Code +.vscode + +# OS X +.DS_Store + +# Emacs +*~ +\#*\# + +# Vim +.swp + +# Other +TAGS \ No newline at end of file diff --git a/api/README.md b/api/README.md new file mode 100644 index 0000000000..cebac7e758 --- /dev/null +++ b/api/README.md @@ -0,0 +1,6 @@ +OpenConsensus API +====================================================== + +* Java 7 and Android 14 compatible. +* The abstract classes in this directory can be subclassed to create alternative + implementations of the OpenCensus library. diff --git a/api/build.gradle b/api/build.gradle new file mode 100644 index 0000000000..1fe72ca08b --- /dev/null +++ b/api/build.gradle @@ -0,0 +1,10 @@ +description = 'OpenConsensus API' + +dependencies { + compile project(':openconsensus-context') + + compileOnly libraries.auto_value + + signature "org.codehaus.mojo.signature:java17:1.0@signature" + signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature" +} diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..eb8d7ec52c --- /dev/null +++ b/build.gradle @@ -0,0 +1,259 @@ +buildscript { + repositories { + mavenCentral() + mavenLocal() + maven { + url "https://plugins.gradle.org/m2/" + } + } + dependencies { + classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.4.6' + classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.16' + classpath "net.ltgt.gradle:gradle-apt-plugin:0.18" + classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0' + classpath "gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.8" + classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.8" + classpath "gradle.plugin.io.morethan.jmhreport:gradle-jmh-report:0.9.0" + } +} + +// Display the version report using: ./gradlew dependencyUpdates +// Also see https://github.com/ben-manes/gradle-versions-plugin. +apply plugin: 'com.github.ben-manes.versions' + +subprojects { + apply plugin: "checkstyle" + apply plugin: 'maven' + apply plugin: 'idea' + apply plugin: 'eclipse' + apply plugin: 'java' + apply plugin: "signing" + apply plugin: "jacoco" + // The plugin only has an effect if a signature is specified + apply plugin: 'ru.vyarus.animalsniffer' + apply plugin: 'findbugs' + apply plugin: 'net.ltgt.apt' + apply plugin: 'net.ltgt.apt-idea' + apply plugin: "me.champeau.gradle.jmh" + apply plugin: "io.morethan.jmhreport" + apply plugin: 'com.github.sherter.google-java-format' + apply plugin: "net.ltgt.errorprone" + + group = "io.openconsensus" + version = "0.1.0-SNAPSHOT" // CURRENT_VERSION + + sourceCompatibility = 1.7 + targetCompatibility = 1.7 + + repositories { + mavenCentral() + mavenLocal() + } + + [compileJava, compileTestJava, compileJmhJava].each() { + // We suppress the "try" warning because it disallows managing an auto-closeable with + // try-with-resources without referencing the auto-closeable within the try block. + // We suppress the "processing" warning as suggested in + // https://groups.google.com/forum/#!topic/bazel-discuss/_R3A9TJSoPM + it.options.compilerArgs += ["-Xlint:all", "-Xlint:-try", "-Xlint:-processing"] + it.options.compilerArgs += ["-XepAllDisabledChecksAsWarnings", "-XepDisableWarningsInGeneratedCode"] + + // MutableMethodReturnType can suggest returning Guava types from + // API methods (https://github.com/google/error-prone/issues/982). + it.options.compilerArgs += ["-Xep:MutableMethodReturnType:OFF"] + + // Doesn't currently use Var annotations. + it.options.compilerArgs += ["-Xep:Var:OFF"] + + // ImmutableRefactoring suggests using com.google.errorprone.annotations.Immutable, + // but currently uses javax.annotation.concurrent.Immutable + it.options.compilerArgs += ["-Xep:ImmutableRefactoring:OFF"] + + // This check causes a NullPointerException + // (https://github.com/google/error-prone/issues/1138). + it.options.compilerArgs += ["-Xep:NullableDereference:OFF"] + + // ExpectedExceptionRefactoring and TestExceptionRefactoring suggest using + // assertThrows, but assertThrows only works well with lambdas. + it.options.compilerArgs += ["-Xep:ExpectedExceptionRefactoring:OFF"] + it.options.compilerArgs += ["-Xep:TestExceptionRefactoring:OFF"] + it.options.encoding = "UTF-8" + } + + compileTestJava { + // serialVersionUID is basically guaranteed to be useless in tests + options.compilerArgs += ["-Xlint:-serial"] + // It undeprecates DoubleSubject.isEqualTo(Double). + options.compilerArgs += ["-Xlint:-deprecation"] + } + + jar.manifest { + attributes('Implementation-Title': name, + 'Implementation-Version': version, + 'Built-By': System.getProperty('user.name'), + 'Built-JDK': System.getProperty('java.version'), + 'Source-Compatibility': sourceCompatibility, + 'Target-Compatibility': targetCompatibility) + } + + javadoc.options { + encoding = 'UTF-8' + links 'https://docs.oracle.com/javase/8/docs/api/' + } + + ext { + autoValueVersion = '1.4' + findBugsAnnotationsVersion = '3.0.1' + findBugsJsr305Version = '3.0.2' + errorProneVersion = '2.3.2' + grpcVersion = '1.18.0' + guavaVersion = '26.0-android' + + libraries = [ + auto_value: "com.google.auto.value:auto-value:${autoValueVersion}", + auto_service: 'com.google.auto.service:auto-service:1.0-rc3', + config: 'com.typesafe:config:1.2.1', + errorprone: "com.google.errorprone:error_prone_annotations:${errorProneVersion}", + findbugs_annotations: "com.google.code.findbugs:annotations:${findBugsAnnotationsVersion}", + grpc_context: "io.grpc:grpc-context:${grpcVersion}", + guava: "com.google.guava:guava:${guavaVersion}", + jsr305: "com.google.code.findbugs:jsr305:${findBugsJsr305Version}", + + // Test dependencies. + guava_testlib: "com.google.guava:guava-testlib:${guavaVersion}", + junit: 'junit:junit:4.12', + mockito: 'org.mockito:mockito-core:1.9.5', + truth: 'com.google.truth:truth:0.42', + ] + } + + configurations { + compile { + // Detect Maven Enforcer's dependencyConvergence failures. We only + // care for artifacts used as libraries by others. + resolutionStrategy.failOnVersionConflict() + } + } + + dependencies { + compileOnly libraries.errorprone, + libraries.jsr305 + + testCompile libraries.guava_testlib, + libraries.junit, + libraries.mockito, + libraries.truth + + // The ErrorProne plugin defaults to the latest, which would break our + // build if error prone releases a new version with a new check + errorprone "com.google.errorprone:error_prone_core:${errorProneVersion}" + } + + findbugs { + toolVersion = findBugsAnnotationsVersion + ignoreFailures = false // bug free or it doesn't ship! + effort = 'max' + reportLevel = 'low' // low = sensitive to even minor mistakes + omitVisitors = [] // bugs that we want to ignore + excludeFilter = file("$rootDir/findbugs-exclude.xml") + } + // Generate html report for findbugs. + findbugsMain { + reports { + xml.enabled = false + html.enabled = true + } + } + findbugsTest { + reports { + xml.enabled = false + html.enabled = true + } + } + findbugsJmh { + reports { + xml.enabled = false + html.enabled = true + } + } + + checkstyle { + configFile = file("$rootDir/buildscripts/checkstyle.xml") + toolVersion = "8.12" + ignoreFailures = false + if (rootProject.hasProperty("checkstyle.ignoreFailures")) { + ignoreFailures = rootProject.properties["checkstyle.ignoreFailures"].toBoolean() + } + configProperties["rootDir"] = rootDir + } + + googleJavaFormat { + toolVersion '1.7' + } + + afterEvaluate { // Allow subproject to add more source sets. + tasks.googleJavaFormat { + source = sourceSets*.allJava + include '**/*.java' + } + + tasks.verifyGoogleJavaFormat { + source = sourceSets*.allJava + include '**/*.java' + } + } + + signing { + required false + sign configurations.archives + } + + task javadocJar(type: Jar) { + classifier = 'javadoc' + from javadoc + } + + task sourcesJar(type: Jar) { + classifier = 'sources' + from sourceSets.main.allSource + } + + artifacts { + archives javadocJar, sourcesJar + } + + jmh { + jmhVersion = '1.20' + warmupIterations = 10 + iterations = 10 + fork = 1 + failOnError = true + resultFormat = 'JSON' + // Allow to run single benchmark class like: + // ./gradlew -PjmhIncludeSingleClass=StatsTraceContextBenchmark clean :grpc-core:jmh + if (project.hasProperty('jmhIncludeSingleClass')) { + include = [ + project.property('jmhIncludeSingleClass') + ] + } + } + + jmhReport { + jmhResultPath = project.file("${project.buildDir}/reports/jmh/results.json") + jmhReportOutput = project.file("${project.buildDir}/reports/jmh") + } + + tasks.jmh.finalizedBy tasks.jmhReport + + // At a test failure, log the stack trace to the console so that we don't + // have to open the HTML in a browser. + test { + testLogging { + exceptionFormat = 'full' + showExceptions true + showCauses true + showStackTraces true + } + maxHeapSize = '1500m' + } +} diff --git a/buildscripts/checkstyle.xml b/buildscripts/checkstyle.xml new file mode 100644 index 0000000000..09fe7d24e9 --- /dev/null +++ b/buildscripts/checkstyle.xml @@ -0,0 +1,278 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/context/README.md b/context/README.md new file mode 100644 index 0000000000..5065ebd9df --- /dev/null +++ b/context/README.md @@ -0,0 +1,5 @@ +OpenConsensus Context +====================================================== + +* Java 7 and Android 14 compatible. +* Generic Context implementation. diff --git a/context/build.gradle b/context/build.gradle new file mode 100644 index 0000000000..486c1795f0 --- /dev/null +++ b/context/build.gradle @@ -0,0 +1,10 @@ +description = 'OpenConsensus Context' + +dependencies { + compile libraries.grpc_context + + compileOnly libraries.auto_value + + signature "org.codehaus.mojo.signature:java17:1.0@signature" + signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature" +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..87b738cbd0 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..a95009c3b9 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000000..af6708ff22 --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000000..0f8d5937c4 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000000..868d5b5da5 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,7 @@ +rootProject.name = "openconsensus" + +include ":openconsensus-api" +include ":openconsensus-context" + +project(':openconsensus-api').projectDir = "$rootDir/api" as File +project(':openconsensus-context').projectDir = "$rootDir/context" as File