-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathnewrelic.gradle
107 lines (87 loc) · 3.17 KB
/
newrelic.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
/**
* Copyright (c) 2022-present New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
/**
*
* New Relic React Native Gradle Plugin
*
**/
def config = project.hasProperty("react") ? project.react : [];
def reactRootDir = file(config.rootDir ?: "../..")
def shell = config.shell ?: ["/bin/sh"] // TODO get from environment
def sourcemapGenPath = "$reactRootDir/node_modules/newrelic-react-native-agent/new-relic/scripts/js-sourcemap/rn-gen-source-map.sh"
def logger = project.logger
dependencies {
implementation group: 'com.google.guava', name: 'guava', version: '27.1-jre'
}
gradle.projectsEvaluated {
try {
projectVariants(project).all { variant ->
def variantNameCap = variant.name.capitalize()
try {
def targetTask = "bundle${variantNameCap}JsAndAssets"
project.tasks.getByName(targetTask) { task ->
if (task.getEnabled()) {
def nameCliTask = "bundle${variantNameCap}SourceMapUpload"
task.finalizedBy {
project.task(nameCliTask, type: Exec) {
description = "New Relic upload js source maps"
group = 'react'
workingDir reactRootDir
def args = [ sourcemapGenPath ]
environment['REACT_ROOTDIR'] = reactRootDir
environment['PLATFORM'] = 'android'
environment['buildType'] = variant.buildType.name.toLowerCase()
commandLine(*shell, *args)
enabled true
}
}
}
}
} catch (UnknownTaskException e) {
// task for this variant not available
}
}
} catch(Exception e) {
logger.warn e as String
}
}
def bundleTasks(Project project) {
def bundleTasks = []
try {
bundleTasks = project.tasks.findAll { it.name ==~ /bundle.*JsAndAssets/ }
} catch (Exception e) {
logger.warn("[NRMA] bundleTasks: " + e)
}
bundleTasks
}
def projectVariants(Project project) {
def variants = []
try {
def android = project.getProperties().get("android")
if (android != null) {
if (android.hasProperty("applicationVariants")) {
variants = android.applicationVariants
} else if (android.hasProperty("libraryVariants")) {
variants = android.libraryVariants
}
}
} catch (MissingPropertyException) {
// has no android closure or variants property
logger.warn("[NRMA] projectVariants: " + e)
}
catch (Exception e) {
logger.warn("[NRMA] projectVariants: " + e)
}
variants
}
task copyNRFiles(type: Copy)
copyNRFiles {
outputs.upToDateWhen { false }
description = 'Copies newrelic.json to asset folder.'
from "$projectDir/../../"
into "$projectDir/src/main/assets/"
include('newrelic.json')
}
preBuild.dependsOn copyNRFiles