forked from momosecurity/momo-code-sec-inspector-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
131 lines (108 loc) · 3.66 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
plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.5.0'
}
group 'com.immomo.momosec'
version plugin_version
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
repositories {
mavenCentral()
}
dependencies {
compileOnly group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
implementation group: 'commons-codec', name: 'commons-codec', version: '1.13'
implementation group: 'me.gosimple', name: 'nbvcxz', version: '1.5.0'
testImplementation group: 'junit', name: 'junit', version: '4.12'
}
import groovy.xml.XmlUtil
import groovy.util.XmlSlurper
import org.apache.tools.ant.filters.ReplaceTokens
def plugin_env=project.getProperties().get("MOMO_CODE_SEC_INSPECTOR_ENV", "dev")
println "plugin env: ${plugin_env}"
// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version idea_version
pluginName project.name + "-" + plugin_env
println "pluginName change to: ${pluginName}"
def versionParts = version.replace('IU-', '').split('\\.')
if ((Integer.parseInt(versionParts[0] as String) == 2019 && Integer.parseInt(versionParts[1] as String) >= 2) ||
Integer.parseInt(versionParts[0] as String) > 2019
) {
/* since 2019.2 Java is a separate plugin, hence we have to specify it implicitly */
plugins = [
'java',
'properties',
'yaml'
]
} else {
plugins = [
'properties',
'yaml'
]
}
}
test {
systemProperty "idea.home.path", IDEA_HOME_PATH
}
def htmlFixer = { htmlFile -> file(htmlFile).text.replace('<html>', '').replace('</html>', '') }
def mdToHtml = { mdFile ->
String htmlText = "\n<body>\n"
file(mdFile).eachLine {
if (it.startsWith("# ")) {
htmlText += "<b>" + it.substring(2) + "</b>"
} else if (it.startsWith("## ")) {
htmlText += "<b>> version " + it.substring(3) + "</b>"
} else if (it.startsWith("### ")) {
htmlText += "<b># " + it.substring(4) + "</b>"
} else {
htmlText += it
}
htmlText += "<br/>\n"
}
return htmlText + "</body>\n"
}
patchPluginXml {
sinceBuild = idea_since_build
untilBuild = idea_until_build
pluginDescription = htmlFixer('src/main/resources/META-INF/description.html')
changeNotes = mdToHtml('CHANGELOG.md')
}
task deleteAppProperties(type: Delete) {
delete "${buildDir}/resources/main"
}
task copyProperties(type: Copy, dependsOn: [deleteAppProperties]) {
from("src/main/resources/properties/${plugin_env}.properties") {
filter(ReplaceTokens, tokens: ["plugin_version": plugin_version])
}
rename { _ -> "app.properties" }
into "${buildDir}/resources/main/properties/"
}
processResources.dependsOn(copyProperties)
task addPluginNamePrefix(dependsOn: [processResources]) {
doLast {
if (plugin_env == "prod") {
return
}
def pluginXmlFile = file("${buildDir}/resources/main/META-INF/plugin.xml")
def content = new XmlSlurper().parse(pluginXmlFile)
def oldPluginName = content.name.text()
println "plugin Name replace with: [${oldPluginName} - ${plugin_env}]"
content.name.replaceBody("${oldPluginName} - ${plugin_env}")
pluginXmlFile.write(XmlUtil.serialize(content))
}
}
build.dependsOn(addPluginNamePrefix)
sourceSets {
test {
resources {
srcDir 'src/test/testData'
}
}
}
wrapper {
gradleVersion '6.1.1'
}
test.testLogging.exceptionFormat = 'full'