forked from jason-lang/jason
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle
652 lines (567 loc) · 20.2 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
/*
Jason Gradle build file
*/
plugins {
id "ca.coglinc.javacc" version "2.3.1"
// see https://github.com/johnmartel/javaccPlugin
}
defaultTasks 'jar'
apply plugin: 'java'
//apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'signing'
version '3.0'
group 'org.jason'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(15)
}
}
/*compileJava {
options.compilerArgs += ['--enable-preview']
}
tasks.withType(Test).all {
jvmArgs += '--enable-preview'
}
tasks.withType(JavaCompile).all {
options.compilerArgs += ['--enable-preview']
}
tasks.withType(JavaExec) {
jvmArgs += '--enable-preview'
}
javadoc.options {
addBooleanOption('-enable-preview', true)
addStringOption('-release', '15')
}
*/
/*compileJava {
sourceCompatibility = JavaVersion.VERSION_1_15
targetCompatibility = JavaVersion.VERSION_1_15
}*/
repositories {
mavenCentral()
maven { url "https://raw.github.com/jacamo-lang/mvn-repo/master" }
//maven { url "http://jacamo.sourceforge.net/maven2" }
//maven { url "http://jade.tilab.com/maven" //}
flatDir {
dirs 'jedit', 'demos/persistent-belief-base/lib'
}
}
/*configurations {
umljavadoc // see http://www.umlgraph.org/doc/indexw.html
}*/
dependencies {
compile group: 'net.sf.ingenias', name: 'jade', version: '4.3'
//compile group: 'com.tilab.jade', name: 'jade', version: '4.4.0'
//compile group: 'org.jacamo', name: 'cartago', version: '2.5'
//compile group: 'org.jacamo', name: 'jaca', version: '2.5'
// from jEdit
compile fileTree(dir: 'jedit', include: '*.jar') // using fileTree, jedit jars are not included as a dependency in the pom file
runtime group: 'org.apache.ant', name: 'ant', version: '1.10.5'
compile group: 'javax.json', name: 'javax.json-api', version: '1.1.4'
compile group: 'org.glassfish', name: 'javax.json', version: '1.1.4'
testImplementation group: 'junit', name: 'junit', version: '4.12'
testImplementation name: 'hsqldb'
//umljavadoc 'org.umlgraph:umlgraph:5.6'
}
// copy dep jars and scritps into build directory
task copyJarsToBuild {
inputs.files configurations.runtime.files
inputs.dir 'scripts'
outputs.dir 'build/libs'
outputs.dir 'build/scripts'
doLast {
copy {
from configurations.runtime
into 'build/libs'
}
copy {
from 'scripts'
into 'build/scripts'
include '**'
filter {
String line -> line.replaceAll("JasonREL=[0-9]+\\.[0-9]+", "JasonREL="+project.version)
}
filter {
String line -> line.replaceAll("JadeJar", file(project.configurations.compile.find { it.name.startsWith("jade-") }).name)
}
}
}
}
jar {
baseName 'jason'
manifest {
attributes 'Main-Class': 'jason.util.ConfigGUI',
'Specification-Title': 'Jason Language',
'Specification-Version': project.version,
'Implementation-Version': new Date().toString()
}
from('src') {
include '/test/jason/inc/**/*.asl'
include '/test/jason/**/*.mas2j'
}
/*doFirst {
Properties props = new Properties()
props.put('version', '')
props.put('release', project.version)
props.store(new File(project.buildDir.absolutePath +'/classes/main/dist.properties').newWriter(), null)
}*/
}
jar.dependsOn(copyJarsToBuild)
task jarCore(type: Jar, dependsOn: 'classes') {
baseName 'jason-core'
from 'build/classes/main'
from 'build/resources/main'
exclude '**/MindInspectorAgArch*'
exclude '**/MindInspectorWebImpl*'
exclude 'jason/environment/grid/**/*'
exclude 'jason/jeditplugin/**/*'
exclude 'jason/runtime/MASConsole*'
exclude 'jason/runtime/OutputStreamAdapter*'
exclude 'jason/util/ConfigGUI*'
exclude 'jason/util/CheckVersion*'
exclude 'jason/control/ExecutionControlGUI*'
exclude 'jason/infra/local/*GUI*'
exclude 'jason/infra/jade/Run*'
exclude 'jason/infra/repl/**/*'
}
clean {
delete 'bin'
delete 'doc/api'
delete 'doc/faq.html'
delete 'doc/index.html'
delete 'doc/readme.html'
delete 'readme.html'
delete 'release-notes.html'
delete fileTree('doc/tutorials') { include '**/*.html' }
delete fileTree('doc/tutorials') { include '**/bin/**/*' }
delete fileTree('.') { include '**/*~' }
delete fileTree('.') { include '**/.stop___MAS' }
delete fileTree('.') { include '**/APDescription.txt' }
delete fileTree('.') { include '**/MTPs-Main-Container.txt' }
delete fileTree('examples') { include '**/bin/**' }
delete fileTree('examples') { include '**/*.log' }
delete fileTree('demos') { include '**/bin/**' }
delete fileTree('demos') { include '**/*.log' }
delete 'demos/persistent-belief-base/a.bb'
def emptyDirs = []
fileTree (dir: 'examples').visit {
def File f = it.file
if (f.isDirectory() ) {
def children = project.fileTree(f).filter { it.isFile() }.files
if (children.size() == 0) {
emptyDirs << f
}
}
}
fileTree (dir: 'demos').visit {
def File f = it.file
if (f.isDirectory() ) {
def children = project.fileTree(f).filter { it.isFile() }.files
if (children.size() == 0) {
emptyDirs << f
}
}
}
emptyDirs.reverseEach { it.delete() }
}
task config (type: JavaExec, dependsOn: ['jar', 'plugin']) {
main = 'jason.util.Config'
classpath project.buildDir.absolutePath + '/libs/jason-' +project.version+'.jar'
workingDir project.buildDir.absolutePath + '/libs'
doFirst {
delete System.getProperty("user.home")+'/.jason'
}
doLast {
println '------'
println ''
println 'you can set the Jason home directory with the following command:'
println ' export JASON_HOME='+project.buildDir.absolutePath
println ''
println 'and also change your PATH with:'
println ' export PATH=$JASON_HOME/scripts:$PATH'
println ''
println '-----'
}
}
/*
eclipse {
classpath {
downloadJavadoc = true
file.whenMerged { cp ->
cp.entries.add( new org.gradle.plugins.ide.eclipse.model.SourceFolder('build/generated/javacc', null) )
}
file.whenMerged { cp ->
logger.lifecycle "Removing duplicate classpath entries from eclipse for project '${project.name}'"
Map entryByPath = cp.entries.groupBy { entry -> entry.path }
entryByPath.each { key, values ->
if (values.size() > 1) {
def entry = values.first()
if (entry.kind == 'src') {
entry.includes = []
entry.excludes = []
}
int index = cp.entries.indexOf entry
logger.lifecycle "Removing ${values.collect { it.path }}"
cp.entries.removeAll values
logger.lifecycle "Adding ${entry.path}"
cp.entries.add index, entry
}
}
}
}
}
*/
javadoc {
options.showAll()
options.encoding('UTF-8')
options.setUse(true)
options.author(true)
options.version(true)
options.windowTitle('Jason API')
options.docTitle('Jason API')
options.footer('<a href=http://jason.sf.net>Jason Site</a>')
destinationDir = file("${buildDir}/../doc/api")
doFirst {
javadoc.title = 'Jason API'
javadoc.options.docTitle = javadoc.title
}
}
// the following lines is used to avoid errors while generating javadoc
if (JavaVersion.current().isJava8Compatible()) {
allprojects {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
}
/*
task javadoc(overwrite: true, dependsOn: compileJava) {
setDescription('Generates Javadoc API documentation with UMLGraph diagrams')
setGroup(JavaBasePlugin.DOCUMENTATION_GROUP)
doLast {
ant.javadoc(classpath: (configurations.runtime + configurations.compile).asPath,
sourcepath: file('src/main/java'),
packagenames: '*',
destdir: "${docsDir}/../../doc/api",
private: 'true' ,
docletpath: configurations.umljavadoc.asPath) {
doclet(name: 'org.umlgraph.doclet.UmlGraphDoc') {
//param(name: '-inferrel')
//param(name: '-inferdep')
param(name: '-qualify')
//param(name: '-T', value: 'svg')
param(name: '-postfixpackage')
param(name: '-hide', value: 'java.*')
//param(name: '-collpackages', value: 'java.util.*')
//param(name: '-nodefontsize', value: '9')
//param(name: '-nodefontpackagesize', value: '7')
//param(name: '-link', value: 'http://java.sun.com/j2se/1.5.0/docs/guide/javadoc/doclet/spec')
//param(name: '-link', value: 'http://java.sun.com/j2se/1.5/docs/api')
}
}
}
}
*/
task javadocJar (type: Jar, dependsOn: javadoc) {
baseName 'jason'
classifier = 'javadoc'
from '${docsDir}/../../doc/api'
}
task sourceJar (type : Jar) {
baseName 'jason'
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourceJar, javadocJar
}
publishing {
publications {
maven(MavenPublication) {
from components.java
artifact sourceJar
artifact javadocJar
artifactId 'jason'
}
}
}
// from http://central.sonatype.org/pages/gradle.html
// see http://central.sonatype.org/pages/releasing-the-deployment.html
// comment cartago and jaca dependencies
// check gradle.properties for
// signing.keyId=
// signing.password=
// signing.secretKeyRingFile=
// ossrhUsername=
// ossrhPassword=
//
// run gradle uploadArchives
// login https://oss.sonatype.org/
// select Staging Repositories
// search jason, close, refresh, release
// uncomment to produce maven jar
/*
signing {
sign configurations.archives
}
uploadArchives {
group = 'net.sf.jason'
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom*.whenConfigured { pom -> pom.dependencies.clear() }
pom.project {
name 'Jason'
packaging 'jar'
groupId 'net.sf.jason'
// optionally artifactId can be defined here
description 'Jason is a fully-fledged interpreter for an extended version of AgentSpeak, a BDI agent-oriented logic programming language.'
url 'http://jason.sf.net'
scm {
connection 'scm:git:https://github.com/jason-lang/jason.git'
developerConnection 'scm:git:https://github.com/jason-lang/jason.git'
url 'https://github.com/jason-lang/jason.git'
}
licenses {
license {
name 'GNU Library or Lesser General Public License version 2.0 (LGPLv2)'
url 'http://www.gnu.org/licenses/gpl-2.0.html'
}
}
developers {
developer {
id 'jomi'
name 'Jomi F. Hubner'
email 'jomifred@gmail.com'
}
developer {
id 'rafael'
name 'Rafael H. Bordini'
email 'rafael.h.bordini@gmail.com'
}
}
}
}
}
}
*/
compileJavacc {
inputDirectory = file('src/main/javacc')
outputDirectory = file(project.buildDir.absolutePath + '/generated/javacc')
}
jjdoc {
outputDirectory = file(project.projectDir.absolutePath + '/doc/tech')
//arguments = [text: 'true']
}
// Builds jEdit plugin
task plugin(type: Jar, dependsOn: 'jar') {
archiveName 'jason-jedit-plugin.jar'
destinationDir file('build/jedit/jars')
from 'build/classes/java/main'
from 'build/resources/main'
from 'build/resources/main/jeditPlugin'
manifest {
attributes 'Main-Class': 'jason.util.ConfigGUI',
'Specification-Title': 'Jason Language',
'Specification-Version': project.version,
'Implementation-Version': new Date().toString()
}
from ( configurations.compile.collect { zipTree(it) } ) {
include 'jade/**/*.class'
}
doFirst {
ant.untar(compression: 'gzip', dest: 'build', src: 'jedit/jedit.tgz')
}
doLast {
copy {
from 'src/main/resources/jeditPlugin'
into 'build/jedit/modes'
include 'agentSpeak.xml', 'jasonProject.xml', 'catalog'
}
copy {
from 'src/main/resources/jeditPlugin'
into 'build/jedit/properties'
include 'jedit-initial.props'
}
}
}
// transfer local maven artifact to our maven2 repository at sourceforge
/*task publishMavenSF(dependsOn: [ 'build', 'publishToMavenLocal']) {
doLast {
def wdir = System.getProperty("user.home")+'/.m2/repository/org/jason/jason'
def tdir = System.getenv('USERSF')+',jacamo@web.sf.net:/home/project-web/jacamo/htdocs/maven2/org/jason/jason'
exec {
commandLine 'scp', '-r', project.version, tdir
workingDir wdir
}
exec {
commandLine 'cp', 'maven-metadata-local.xml', 'maven-metadata.xml'
workingDir wdir
}
exec {
commandLine 'scp', 'maven-metadata.xml', tdir
workingDir wdir
}
}
}*/
task publishMavenGitHub(dependsOn: [ 'build', 'publishToMavenLocal']) {
doLast {
def wdir = System.getProperty("user.home")+'/.m2/repository/org/jason/jason'
def rdir = '../jacamo-mvn-repo'
exec {
commandLine 'git', 'pull'
workingDir rdir
}
copy {
from wdir
into rdir + '/org/jason/jason'
}
exec {
commandLine 'git', 'add', '*'
workingDir rdir
}
exec {
commandLine 'git', 'commit', '-a', '-m', 'new version of jason '+project.version
workingDir rdir
}
exec {
commandLine 'git', 'push'
workingDir rdir
}
}
}
// Builds the distribution, documentation and a new release
task doc(dependsOn: [ 'jjdoc', 'javadoc', 'renderAsciiDocs']) {
}
task renderAsciiDocs(type: Exec) {
commandLine 'find', '.', '-name', '*.adoc', '-exec', 'scripts/asciidoc-docker', '{}', ';'
//commandLine 'find', '.', '-name', '*.adoc', '-exec', 'asciidoctor', '{}', ';'
}
task fixTab {
ant.fixcrlf(eol: 'lf', includes: '**/*.txt,**/*.bat, **/*.adoc', srcdir: '.')
ant.fixcrlf(tab: 'remove', tablength: '4', javafiles: 'true', includes: '**/*.java,**/*.xml,**/*.asl,**/*.mas2j,**/*.txt', srcdir: 'src')
ant.fixcrlf(tab: 'remove', tablength: '4', javafiles: 'true', includes: '**/*.java,**/*.xml,**/*.asl,**/*.mas2j,**/*.txt', srcdir: 'examples')
ant.fixcrlf(tab: 'remove', tablength: '4', javafiles: 'true', includes: '**/*.java,**/*.xml,**/*.asl,**/*.mas2j,**/*.txt', srcdir: 'demos')
ant.fixcrlf(tab: 'remove', tablength: '4', javafiles: 'true', includes: '**/*.java,**/*.xml,**/*.asl,**/*.mas2j,**/*.txt', srcdir: 'doc')
ant.fixcrlf(tab: 'remove', tablength: '4', javafiles: 'true', includes: '*.gradle', srcdir: '.')
}
// Builds the distribution, documentation and a new release
task release(dependsOn: [ 'build', 'doc', 'fixTab', 'plugin', 'zipRel' ]) {
}
// copy files used to build a release
task copyRel (dependsOn: ['plugin', 'jar']) {
doLast {
copy {
from '.'
into 'build/jason-'+project.version
include '*.html'
include 'LICENSE'
include 'doc/**'
}
delete fileTree('build/jason-'+project.version+'/doc') { include '**/*.adoc', '**/Makefile' }
copy {
from 'build/scripts'
into 'build/jason-'+project.version+'/scripts'
}
copy {
from libsDir
from configurations.runtime
into 'build/jason-'+project.version+'/'+libsDirName
include '**/*.jar'
}
copy {
from 'build/jedit'
into 'build/jason-'+project.version+'/jedit'
}
copy {
from 'examples'
into 'build/jason-'+project.version+'/examples'
}
copy {
from 'demos'
into 'build/jason-'+project.version+'/demos'
}
copy {
from 'src'
into 'build/jason-'+project.version+'/src'
}
}
}
// creates a zip file for a release
task zipRel(type: Zip, dependsOn: copyRel) {
from 'build/jason-'+project.version
baseName 'jason'
}
/**
* Gradle task to execute unit tests for Jason agents
* To run this script in a virtual machine to simulate a CI environment type:
* $ docker volume create --name gradle-cache
* $ docker run -ti --rm -u gradle -v gradle-cache:/home/gradle/.gradle -v "$PWD":/home/gradle/project -w /home/gradle/project -p 8000:8000 gradle:6.3.0-jdk11 bash -c "./gradlew config test -i"
*/
task testJason(dependsOn: 'config') {
description 'runs Jason unit tests: tests.mas2j'
def errorOnTests = false
outputs.upToDateWhen { false } // disable cache
doFirst {
try {
javaexec {
jvmArgs += '--enable-preview'
main = 'jason.infra.local.RunLocalMAS'
if (gradle.startParameter.logLevel.toString().equals("DEBUG")) {
args = ['src/test/jason/unit_tests.mas2j', '--log-conf', 'src/main/resources/templates/console-debug-logging.properties']
} else if (gradle.startParameter.logLevel.toString().equals("INFO")) {
args = ['src/test/jason/unit_tests.mas2j', '--log-conf', 'src/main/resources/templates/console-info-logging.properties']
} else {
args = ['src/test/jason/unit_tests.mas2j', '--log-conf', 'src/main/resources/templates/console-lifecycle-logging.properties']
}
classpath sourceSets.main.runtimeClasspath
sourceSets.test.java.srcDirs += ['src/test/jason/jia']
errorOutput = new ByteArrayOutputStream()
standardOutput = new ByteArrayOutputStream()
ext.stdout = {
return standardOutput.toString()
}
ext.errout = {
return errorOutput.toString()
}
}
} catch (Exception e) {
errorOnTests = true
}
}
doLast {
def styler = 'black red green yellow blue magenta cyan white'
.split().toList().withIndex(30)
.collectEntries { key, val -> [(key) : { "\033[${val}m${it}\033[0m" }] }
def std = stdout()
std.splitEachLine('\n') { String line ->
line = line.replace("TESTING","${styler['yellow']('TESTING')}")
line = line.replace("PASSED","${styler['green']('PASSED')}")
line = line.replace("FAILED","${styler['red']('FAILED')}")
line = line.replace("TODO","${styler['magenta']('TODO')}")
line = line.replace("LAUNCHING","${styler['blue']('LAUNCHING')}")
println line
}
def err = errout()
err.splitEachLine('\n') { String line ->
line = line.replace("TESTING","${styler['yellow']('TESTING')}")
line = line.replace("PASSED","${styler['green']('PASSED')}")
line = line.replace("FAILED","${styler['red']('FAILED')}")
line = line.replace("TODO","${styler['magenta']('TODO')}")
line = line.replace("LAUNCHING","${styler['blue']('LAUNCHING')}")
println line
}
if (errorOnTests) {
throw new GradleException('Jason unit tests: ERROR!')
}
}
}
tasks.build.finalizedBy testJason