Skip to content

Commit 3b5ec94

Browse files
authored
Merge pull request #3 from newrelic-experimental/enhancements-scg
Enhancements Spring Cloud Gateway
2 parents f3853c3 + 730720d commit 3b5ec94

File tree

16 files changed

+418
-158
lines changed

16 files changed

+418
-158
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ If you believe you have found a security vulnerability in this project or any of
6060

6161
newrelic-java-spring-cloud-gateway is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.
6262

63+

build.gradle

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

gradle/wrapper/gradle-wrapper.jar

-293 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

gradlew

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fi
130130
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131131
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132132
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133-
133+
134134
JAVACMD=`cygpath --unix "$JAVACMD"`
135135

136136
# We build the pattern for arguments to be converted via cygpath

gradlew.bat

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
4040

4141
set JAVA_EXE=java.exe
4242
%JAVA_EXE% -version >NUL 2>&1
43-
if "%ERRORLEVEL%" == "0" goto execute
43+
if "%ERRORLEVEL%" == "0" goto init
4444

4545
echo.
4646
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -54,7 +54,7 @@ goto fail
5454
set JAVA_HOME=%JAVA_HOME:"=%
5555
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
5656

57-
if exist "%JAVA_EXE%" goto execute
57+
if exist "%JAVA_EXE%" goto init
5858

5959
echo.
6060
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@@ -64,14 +64,29 @@ echo location of your Java installation.
6464

6565
goto fail
6666

67+
:init
68+
@rem Get command-line arguments, handling Windows variants
69+
70+
if not "%OS%" == "Windows_NT" goto win9xME_args
71+
72+
:win9xME_args
73+
@rem Slurp the command line arguments.
74+
set CMD_LINE_ARGS=
75+
set _SKIP=2
76+
77+
:win9xME_args_slurp
78+
if "x%~1" == "x" goto execute
79+
80+
set CMD_LINE_ARGS=%*
81+
6782
:execute
6883
@rem Setup the command line
6984

7085
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
7186

7287

7388
@rem Execute Gradle
74-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
89+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
7590

7691
:end
7792
@rem End local scope for the variables with windows NT shell

0 commit comments

Comments
 (0)