generated from newrelic-experimental/java-instrumentation-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
204 lines (162 loc) · 6.2 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// Build.gradle for creating or installing new instrumentation modules
// Global defaults - override here or in individual modules as needed.
buildscript {
repositories {
flatDir dirs: 'template-lib'
mavenLocal()
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath 'gradle-templates:gradle-templates:1.5'
classpath 'com.newrelic.agent.java:gradle-verify-instrumentation-plugin:3.2'
}
}
plugins {
id "de.undercouch.download" version "1.2"
}
project.ext {
group = 'com.newrelic.instrumentation.labs'
javaAgentVersion = '6.0.0'
// Aligned with minimum Java major version supported by latest Java Agent
javaVersion = JavaVersion.VERSION_1_8
}
apply plugin: 'java'
apply plugin: 'de.undercouch.download'
import templates.*
import de.undercouch.gradle.tasks.download.Download
task getAgent(type: Download) {
def rootProject = projectDir.path
src 'https://repo1.maven.org/maven2/com/newrelic/agent/java/newrelic-agent/'+project.javaAgentVersion+'/newrelic-agent-'+project.javaAgentVersion+'.jar'
dest projectDir.path+"/libs/newrelic-agent-"+project.javaAgentVersion+".jar"
}
task extractJars(type: Copy) {
from zipTree(projectDir.path+"/libs/newrelic-agent-"+project.javaAgentVersion+".jar")
into projectDir.path+"/libs"
}
task cleanUp(type: Delete) {
delete projectDir.path+'/libs/META-INF', projectDir.path+'/libs/com', projectDir.path+'/libs/mozilla'
delete projectDir.path+'/libs/LICENSE', projectDir.path+'/libs/Log4j-events.dtd', projectDir.path+'/libs/THIRD_PARTY_NOTICES.md'
delete fileTree(projectDir.path+'/libs') {
include '**/*.xsd'
include '**/*.xml'
include '**/*.yml'
include '**/*.properties'
}
}
task checkForDependencies(type: Exec) {
environment "JAVAAGENTVERSION", javaAgentVersion
def rootProject = projectDir.path
def cmdLine = rootProject+'/newrelic-dependencies.sh'
workingDir rootProject
commandLine cmdLine
}
task buildIfNeeded {
dependsOn checkForDependencies
dependsOn jar
tasks.findByName('jar').mustRunAfter 'checkForDependencies'
}
task createModule {
dependsOn checkForDependencies
description = 'Generate project files for a new instrumentation module'
group = 'New Relic Labs'
doLast {
def rootProject = projectDir.path
String projectGroup = TemplatesPlugin.prompt('Instrumentation Module Group (default: ' + project.ext.group + ') (Hit return to use default):\n')
String projectName = TemplatesPlugin.prompt('Instrumentation Module Name:\n')
if (projectName == null) {
throw new Exception("Please specify a valid module name.")
} else {
projectName = projectName.trim()
}
if (projectGroup == null || projectGroup.trim() == '') {
projectGroup = project.ext.group
} else {
projectGroup = projectGroup.trim()
}
def projectLibDir = new File(rootProject+'/lib')
def projectPath = new File(projectName)
if (projectPath.exists()) {
throw new Exception(projectPath.path + ' already exists.')
}
def projectJava = new File(projectPath, 'src/main/java')
def projectTest = new File(projectPath, 'src/test/java')
mkdir projectJava
mkdir projectTest
ProjectTemplate.fromRoot(projectPath) {
'build.gradle' '''
// Build.gradle generated for instrumentation module PROJECT_NAME
apply plugin: 'java'
dependencies {
// Declare a dependency on each JAR you want to instrument
// Example:
// implementation 'javax.servlet:servlet-api:2.5'
// New Relic Labs Java Agent dependencies
implementation 'com.newrelic.agent.java:newrelic-agent:JAVA_AGENT_VERSION'
implementation 'com.newrelic.agent.java:newrelic-api:JAVA_AGENT_VERSION'
implementation fileTree(include: ['*.jar'], dir: '../libs')
implementation fileTree(include: ['*.jar'], dir: '../test-lib')
}
jar {
manifest {
attributes 'Implementation-Title': 'PROJECT_GROUP.PROJECT_NAME'
attributes 'Implementation-Vendor': 'New Relic Labs'
attributes 'Implementation-Vendor-Id': 'com.newrelic.labs'
attributes 'Implementation-Version': 1.0
}
}
verifyInstrumentation {
// Verifier plugin documentation:
// https://github.com/newrelic/newrelic-gradle-verify-instrumentation
// Example:
// passes 'javax.servlet:servlet-api:[2.2,2.5]'
// exclude 'javax.servlet:servlet-api:2.4.public_draft'
}'''.replace('PROJECT_GROUP', projectGroup)
.replace('PROJECT_NAME', projectName)
.replace('PROJECT_PATH', projectPath.path)
.replace('JAVA_AGENT_VERSION', project.ext.javaAgentVersion)
}
File settings = new File('settings.gradle')
settings.append("include '$projectName'\n")
println "Created module in $projectPath.path."
}
}
subprojects {
repositories {
mavenLocal()
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'com.newrelic.gradle-verify-instrumentation-plugin'
sourceCompatibility = project.javaVersion
targetCompatibility = project.javaVersion
dependencies {
testImplementation fileTree(dir: '../lib', include: "*.jar") // + project.javaAgentVersion
testImplementation 'org.nanohttpd:nanohttpd:2.3.1'
testImplementation 'com.newrelic.agent.java:newrelic-agent:' + project.javaAgentVersion
}
task install(dependsOn: buildIfNeeded, type: Copy) {
description = 'Copies compiled jar to the NEW_RELIC_EXTENSIONS_DIR.'
group = 'New Relic Labs'
def extDir = System.getenv("NEW_RELIC_EXTENSIONS_DIR") ?: " "
from jar
into extDir
}
compileJava.doFirst {
tasks.findByName('checkForDependencies')
}
install.doFirst {
def extDir = System.getenv("NEW_RELIC_EXTENSIONS_DIR")
if (extDir == null) {
throw new Exception("Must set NEW_RELIC_EXTENSIONS_DIR.")
}
if (extDir.startsWith("~" + File.separator)) {
extDir = System.getProperty("user.home") + extDir.substring(1);
}
if (!file(extDir).directory) {
throw new Exception(extDir + "NEW_RELIC_EXTENSIONS_DIR, set as '" + extDir + "'is not a valid directory.")
}
}
}