Skip to content

Commit

Permalink
Merge pull request #3 from newrelic-experimental/enhancements-scg
Browse files Browse the repository at this point in the history
Enhancements Spring Cloud Gateway
  • Loading branch information
gsidhwani-nr authored Jan 31, 2024
2 parents f3853c3 + 730720d commit 3b5ec94
Show file tree
Hide file tree
Showing 16 changed files with 418 additions and 158 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ If you believe you have found a security vulnerability in this project or any of

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


203 changes: 203 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
// 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'
javaAgentVersion = '6.4.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'
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 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')
}
jar {
manifest {
attributes 'Implementation-Title': 'PROJECT_GROUP.PROJECT_NAME'
attributes 'Implementation-Vendor': 'New Relic'
attributes 'Implementation-Vendor-Id': 'com.newrelic'
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'

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.")
}
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; 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
Expand Down
21 changes: 18 additions & 3 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

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

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

if exist "%JAVA_EXE%" goto execute
if exist "%JAVA_EXE%" goto init

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
Expand All @@ -64,14 +64,29 @@ 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 %*
"%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
Expand Down
Loading

0 comments on commit 3b5ec94

Please sign in to comment.