Merge pull request #114 from DataDog/tyler/version

Report version from main
This commit is contained in:
Tyler Benson 2017-08-28 14:06:49 -07:00 committed by GitHub
commit 1808e38fd9
9 changed files with 74 additions and 49 deletions

View File

@ -15,6 +15,7 @@ import org.eclipse.aether.spi.connector.RepositoryConnectorFactory
import org.eclipse.aether.spi.connector.transport.TransporterFactory
import org.eclipse.aether.transport.http.HttpTransporterFactory
import org.eclipse.aether.version.Version
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.objectweb.asm.ClassReader
@ -138,41 +139,41 @@ class VersionScanPlugin implements Plugin<Project> {
if (!verifyPresent.isEmpty() || !verifyMissing.isEmpty()) {
def verifyVersionScan = project.task('verifyVersionScan') {
description = "Validates that the configured classes and methods are only present where expected."
doLast {
// This may already be done by the report task, but repeating for good measure.
keyPresent.get().removeAll(allExclude)
keyMissing.get().removeAll(allInclude)
}
verifyVersionScan.doLast {
// This may already be done by the report task, but repeating for good measure.
keyPresent.get().removeAll(allExclude)
keyMissing.get().removeAll(allInclude)
assert keyPresent.get() != [] || keyMissing.get() != []
assert keyPresent.get() != [] || keyMissing.get() != []
def errors = []
for (String className : verifyPresent.keySet()) {
if (project.versionScan.scanMethods && verifyPresent.get(className) == null) {
throw new AssertionError("When 'scanMethods' is enabled, a method must be configured for '$className'")
} else if (!project.versionScan.scanMethods && verifyPresent.get(className) != null) {
throw new AssertionError("When 'scanMethods' is not enabled, configured method must be null for '$className'")
}
def errors = []
for (String className : verifyPresent.keySet()) {
if (project.versionScan.scanMethods && verifyPresent.get(className) == null) {
throw new AssertionError("When 'scanMethods' is enabled, a method must be configured for '$className'")
} else if (!project.versionScan.scanMethods && verifyPresent.get(className) != null) {
throw new AssertionError("When 'scanMethods' is not enabled, configured method must be null for '$className'")
}
String identifier = project.versionScan.scanMethods ? "$className|${verifyPresent.get(className)}" : className
if (!keyPresent.get().contains(identifier)) {
errors << "not a 'keyPresent' identifier: $identifier"
}
String identifier = project.versionScan.scanMethods ? "$className|${verifyPresent.get(className)}" : className
if (!keyPresent.get().contains(identifier)) {
errors << "not a 'keyPresent' identifier: $identifier"
}
for (String className : verifyMissing) {
if (!keyMissing.get().contains(className)) {
errors << "not a 'keyMissing' identifier: $className"
}
}
errors.each {
System.err.println "Error for $group:$module - $it"
}
if (!errors.isEmpty()) {
throw new AssertionError("Version scan verification failed.\n" +
"Errors listed above are likely the result of a new module " +
"being published to Maven, not a code change in this repo.\n" +
"This does mean a fix should be made though to 'dd-trace-supported-framework.yaml'.")
}
for (String className : verifyMissing) {
if (!keyMissing.get().contains(className)) {
errors << "not a 'keyMissing' identifier: $className"
}
}
errors.each {
logger.error "Error for $group:$module - $it"
}
if (!errors.isEmpty()) {
throw new GradleException("Version scan verification failed.\n" +
"Errors listed above are likely the result of a new module " +
"being published to Maven, not a code change in this repo.\n" +
"This does mean a fix should be made though to 'dd-trace-supported-framework.yaml'.")
}
}
if (project.gradle.startParameter.taskNames.contains('scanVersions')) {

View File

@ -78,6 +78,7 @@ jar {
manifest {
attributes(
"Main-Class": "com.datadoghq.trace.agent.DDJavaAgentInfo",
// I don't think we want to define this since we can't really load after startup:
//"Agent-Class": "com.datadoghq.trace.agent.AnnotationsTracingAgent",
"Premain-Class": "com.datadoghq.trace.agent.AnnotationsTracingAgent",

View File

@ -16,14 +16,19 @@ public class DDJavaAgentInfo {
final BufferedReader br =
new BufferedReader(
new InputStreamReader(
DDJavaAgentInfo.class.getResourceAsStream("dd-java-agent.version"), "UTF-8"));
DDJavaAgentInfo.class.getResourceAsStream("/dd-java-agent.version"), "UTF-8"));
for (int c = br.read(); c != -1; c = br.read()) sb.append((char) c);
v = sb.toString().trim();
} catch (final Exception e) {
e.printStackTrace();
v = "unknown";
}
VERSION = v;
log.info("dd-java-agent - version: {}", v);
}
public static void main(String... args) {
System.out.println(VERSION);
}
}

View File

@ -16,7 +16,7 @@ public class DDTraceAnnotationsInfo {
final BufferedReader br =
new BufferedReader(
new InputStreamReader(
DDTraceAnnotationsInfo.class.getResourceAsStream("dd-trace-annotations.version"),
DDTraceAnnotationsInfo.class.getResourceAsStream("/dd-trace-annotations.version"),
"UTF-8"));
for (int c = br.read(); c != -1; c = br.read()) sb.append((char) c);
@ -27,4 +27,8 @@ public class DDTraceAnnotationsInfo {
VERSION = v;
log.info("dd-trace-annotations - version: {}", v);
}
public static void main(String... args) {
System.out.println(VERSION);
}
}

View File

@ -1,3 +1,7 @@
plugins {
id "com.github.johnrengelman.shadow" version "2.0.1"
}
apply plugin: 'application'
apply from: "${rootDir}/gradle/java.gradle"
apply from: "${rootDir}/gradle/jacoco.gradle"
@ -23,6 +27,16 @@ dependencies {
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
}
jar {
manifest {
attributes 'Main-Class': 'com.datadoghq.example.restspark.SparkApplication'
}
}
shadowJar {
mergeServiceFiles()
}
task wrapper(type: Wrapper) {
gradleVersion = '4.0'
}

View File

@ -30,25 +30,20 @@ apply from: "${rootDir}/gradle/publish.gradle"
// Source: https://github.com/ratpack/ratpack/blob/master/ratpack.gradle#L101
task bintrayPublish() {
doLast {
if (!project.hasProperty("bintrayApiKey")) {
throw new InvalidUserDataException("You must provide bintrayApiKey")
if (!project.hasProperty("bintrayApiKey") || bintrayApiKey.length() < 20) {
throw new InvalidUserDataException("You must provide a valid bintrayApiKey")
}
if (!project.hasProperty('buildNumber')) {
throw new GradleException("Must provide buildNumber of a release from https://oss.jfrog.org/artifactory/webapp/#/builds/dd-trace-java")
if (!project.hasProperty('buildNumber') || !"$buildNumber".isInteger()) {
throw new TaskExecutionException("Must provide buildNumber of a release from https://oss.jfrog.org/artifactory/webapp/#/builds/dd-trace-java")
}
def curl = ['curl',
'-X', 'POST',
"-u", "${bintrayUser}:${bintrayApiKey}",
"-H", "Content-Type: application/json",
"-d", """{
"dryRun": "true",
"targetRepo": "datadog-maven",
"sourceRepos": ["oss-release-local"]
}
""",
"https://oss.jfrog.org/api/build/distribute/dd-trace-java/$project.buildNumber"
def curl = [
'curl',
'-X', 'POST',
'-u', "${bintrayUser}:${bintrayApiKey}",
'-d', '',
"http://oss.jfrog.org/api/plugins/build/promote/snapshotsToBintray/dd-trace-java/$project.buildNumber"
].execute()
logger.info("Received response: ${curl.text}")
}

View File

@ -20,7 +20,7 @@ public class DDTraceInfo {
final BufferedReader br =
new BufferedReader(
new InputStreamReader(
DDTraceInfo.class.getResourceAsStream("dd-trace.version"), "UTF-8"));
DDTraceInfo.class.getResourceAsStream("/dd-trace.version"), "UTF-8"));
for (int c = br.read(); c != -1; c = br.read()) sb.append((char) c);
v = sb.toString().trim();
@ -30,4 +30,8 @@ public class DDTraceInfo {
VERSION = v;
log.info("dd-trace - version: {}", v);
}
public static void main(String... args) {
System.out.println(VERSION);
}
}

View File

@ -76,7 +76,7 @@ class DDApiTest extends Specification {
requestContentType.get().type == "application/msgpack"
requestHeaders.get().get("Datadog-Meta-Lang") == "java"
requestHeaders.get().get("Datadog-Meta-Lang-Version") == System.getProperty("java.version", "unknown")
requestHeaders.get().get("Datadog-Meta-Tracer-Version") == "unknown"
requestHeaders.get().get("Datadog-Meta-Tracer-Version") == "Stubbed-Test-Version"
convertList(requestBody.get()) == expectedRequestBody
cleanup:
@ -175,7 +175,7 @@ class DDApiTest extends Specification {
requestContentType.get().type == "application/msgpack"
requestHeaders.get().get("Datadog-Meta-Lang") == "java"
requestHeaders.get().get("Datadog-Meta-Lang-Version") == System.getProperty("java.version", "unknown")
requestHeaders.get().get("Datadog-Meta-Tracer-Version") == "unknown"
requestHeaders.get().get("Datadog-Meta-Tracer-Version") == "Stubbed-Test-Version"
convertMap(requestBody.get()) == expectedRequestBody
cleanup:

View File

@ -0,0 +1 @@
Stubbed-Test-Version