-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.gradle
257 lines (216 loc) · 9.08 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
Copyright IBM Corporation 2023, 2024
Licensed under the Apache Public License 2.0, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'eclipse'
id 'application'
id 'org.graalvm.buildtools.native' version '0.9.28'
}
// Get the version from the property file first
version = new Properties().with {property ->
file("gradle.properties").withInputStream {property.load(it)}
property.getProperty("version")
}
repositories {
mavenCentral()
mavenLocal()
}
if (project.hasProperty('mainClass')) {
mainClassName = project.getProperty('mainClass')
} else {
// use a default
mainClassName =("com.ibm.cldk.CodeAnalyzer")
}
sourceSets {
main {
java {
srcDirs = ["src/main/java"]
}
resources {
srcDirs = ["src/main/resources"]
}
}
test {
java {
srcDirs = ['src/test/java']
}
resources {
srcDirs= ["src/test/resources"]
}
}
}
// Remove that nagging bin folder vscode seems to generate every single time
clean.doFirst {
delete "${rootDir}/bin"
}
dependencies {
// PICOCLI for handling commandline interface
implementation 'info.picocli:picocli:4.1.0'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
annotationProcessor 'info.picocli:picocli-codegen:4.1.0'
implementation 'org.apache.commons:commons-lang3:3.14.0'
implementation group: 'commons-cli', name: 'commons-cli', version: '1.4'
implementation 'commons-io:commons-io:2.8.0'
implementation 'org.apache.logging.log4j:log4j-api:2.18.0'
implementation 'org.apache.logging.log4j:log4j-core:2.18.0'
def walaVersion = '1.6.7'
compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
implementation "com.ibm.wala:com.ibm.wala.shrike:${walaVersion}"
implementation "com.ibm.wala:com.ibm.wala.util:${walaVersion}"
implementation "com.ibm.wala:com.ibm.wala.core:${walaVersion}"
implementation "com.ibm.wala:com.ibm.wala.cast:${walaVersion}"
implementation "com.ibm.wala:com.ibm.wala.cast.java:${walaVersion}"
implementation "com.ibm.wala:com.ibm.wala.cast.java.ecj:${walaVersion}"
compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
implementation 'com.google.guava:guava:33.0.0-jre'
implementation("commons-io:commons-io:2.15.1")
implementation("org.ow2.asm:asm:9.6")
implementation("org.eclipse.jdt:org.eclipse.jdt.core:3.21.0")
implementation("org.eclipse.platform:org.eclipse.core.commands:3.9.700")
implementation("org.eclipse.platform:org.eclipse.core.contenttype:3.7.1000")
implementation("org.eclipse.platform:org.eclipse.core.expressions:3.7.100")
implementation("org.eclipse.platform:org.eclipse.core.filesystem:1.9.0")
implementation("org.eclipse.platform:org.eclipse.core.jobs:3.11.0")
implementation('org.eclipse.platform:org.eclipse.core.resources:3.20.0')
implementation("org.eclipse.platform:org.eclipse.core.runtime:3.17.100")
implementation("org.eclipse.platform:org.eclipse.equinox.app:1.5.100")
implementation("org.eclipse.platform:org.eclipse.equinox.common:3.14.100")
implementation("org.eclipse.platform:org.eclipse.equinox.preferences:3.8.200")
implementation("org.eclipse.platform:org.eclipse.equinox.registry:3.10.200")
implementation("org.eclipse.platform:org.eclipse.osgi:3.16.300")
implementation("org.eclipse.platform:org.eclipse.text:3.11.0")
implementation('org.json:json:20231013')
implementation('com.google.code.gson:gson:2.10.1')
implementation('org.jgrapht:jgrapht-core:1.5.2')
implementation('org.jgrapht:jgrapht-io:1.5.2')
implementation('org.jgrapht:jgrapht-ext:1.5.2')
implementation('com.github.javaparser:javaparser-symbol-solver-core:3.25.9')
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
}
task fatJar(type: Jar) {
archiveBaseName = 'codeanalyzer'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes(
'Implementation-Title': 'codeanalyzer',
'Implementation-Version': project.version,
'Main-Class': 'com.ibm.cldk.CodeAnalyzer'
)
}
// Collect and include runtime classpath dependencies, excluding signature files
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
with jar
}
run {
if (project.hasProperty('args')) {
args = project.args.split(',')
}
}
graalvmNative {
binaries {
main {
imageName = "codeanalyzer"
mainClass = "com.ibm.cldk.CodeAnalyzer"
buildArgs.add("-Ob")
buildArgs.add("-march=compatibility")
buildArgs.add("--no-fallback")
buildArgs.add("--no-server")
buildArgs.add("-H:ReflectionConfigurationFiles=$projectDir/src/main/resources/META-INF/native-image-config/reflect-config.json")
buildArgs.add("-H:ResourceConfigurationFiles=$projectDir/src/main/resources/META-INF/native-image-config/resource-config.json")
buildArgs.add("-H:JNIConfigurationFiles=$projectDir/src/main/resources/META-INF/native-image-config/jni-config.json")
buildArgs.add("-H:DynamicProxyConfigurationFiles=$projectDir/src/main/resources/META-INF/native-image-config/proxy-config.json")
}
test {
buildArgs.add("-O0")
}
}
binaries.configureEach {
buildArgs.add("--verbose")
}
}
// Define a property for the output directory
def binDir = project.hasProperty('binDir') ? project.property('binDir') : "$projectDir/artifacts/bin"
// Task to copy the native executable to the specified directory
task copyNativeExecutable(type: Copy) {
dependsOn nativeCompile // Ensure this runs after the native image is built
from "${buildDir}/native/nativeCompile/codeanalyzer"
into binDir
fileMode = 0755
}
task createRelease {
doLast {
def releaseTitle = 'latest'
def repo = 'cldk/codeanalyzer'
// Command to create release
def delete = "gh release delete latest --cleanup-tag --yes -R ${hostName}:${repo}"//
// Execute command
def proc = delete.execute()
proc.in.eachLine { line -> println line } // Print output
proc.err.eachLine { line -> println "Error: $line" } // Print error
proc.waitFor() // Wait for process to complete
def command = "gh release create latest $projectDir/build/libs/codeanalyzer.jar -t ${releaseTitle} -R ${hostName}:${repo}"
try {
def release = command.execute()
release.in.eachLine { line -> println line } // Print output
release.err.eachLine { line -> println "Error: $line" } // Print error
release.waitFor() // Wait for process to complete
} catch (Exception e) {
throw new GradleException("Error executing gh command: ${e.message}")
}
}
}
tasks.register('bumpVersion') {
description = 'Bumps the version number (patch, minor, or major)'
group = 'Versioning'
doLast {
def versionFile = file('gradle.properties')
def versionFileText = versionFile.text
def versionPattern = /version\s*=\s*(\d+)\.(\d+)\.(\d+)/
def matcher = (versionFileText =~ versionPattern)
if (matcher.find()) {
def major = matcher.group(1) as int
def minor = matcher.group(2) as int
def patch = matcher.group(3) as int
def bumpType = project.hasProperty('bumpType') ? project.bumpType : 'patch'
switch (bumpType) {
case 'major':
major++
minor = 0
patch = 0
break
case 'minor':
minor++
patch = 0
break
case 'patch':
default:
patch++
break
}
def newVersion = "${major}.${minor}.${patch}"
def updatedContent = versionFileText.replaceFirst(versionPattern, "version=$newVersion")
versionFile.text = updatedContent
println "Version bumped to $newVersion"
} else {
throw new GradleException("Version not found in gradle.properties")
}
}
}
nativeCompile.finalizedBy copyNativeExecutable