build.gradle 15.2 KB
Newer Older
Eric Bruneton's avatar
Eric Bruneton committed
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
// ASM: a very small and fast Java bytecode manipulation framework
// Copyright (c) 2000-2011 INRIA, France Telecom
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
// 3. Neither the name of the copyright holders nor the names of its
//    contributors may be used to endorse or promote products derived from
//    this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE.

Eric Bruneton's avatar
Eric Bruneton committed
29
buildscript {
30
31
  repositories { mavenCentral() }
  dependencies { classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.1' }
Eric Bruneton's avatar
Eric Bruneton committed
32
33
}

Eric Bruneton's avatar
Eric Bruneton committed
34
plugins { id 'biz.aQute.bnd.builder' version '3.3.0' apply false }
35
plugins { id 'com.github.sherter.google-java-format' version '0.6' apply false }
36
plugins { id 'me.champeau.gradle.jmh' version '0.4.4' apply false }
37
plugins { id 'org.sonarqube' version '2.6' apply false }
Eric Bruneton's avatar
Eric Bruneton committed
38
39
40
41
42
43

description = 'ASM, a very small and fast Java bytecode manipulation framework'

subprojects {
  repositories { mavenCentral() }
  apply plugin: 'java'
Eric Bruneton's avatar
Eric Bruneton committed
44
45
  apply plugin: 'org.junit.platform.gradle.plugin'
  junitPlatform { filters { engines { 'junit-jupiter' } } }
Eric Bruneton's avatar
Eric Bruneton committed
46
47
  group = 'org.ow2.asm'
  version = 6.1
Eric Bruneton's avatar
Eric Bruneton committed
48
49
  sourceCompatibility = '1.5'
  targetCompatibility = '1.5'
Eric Bruneton's avatar
Eric Bruneton committed
50
51
52
53
  ext.provides = []  // The provided java packages, e.g. ['org.objectweb.asm']
  ext.requires = []  // The required Gradle projects, e.g. [':asm-test']
  ext.depends = []   // The external dependencies, e.g. ['junit:junit:4.12']
  ext.runWith = []   // The command line to run this project, if applicable.
54
  ext.minCodeCoverage = 0.95 // The minimum code coverage fraction.
Eric Bruneton's avatar
Eric Bruneton committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
}

// -----------------------------------------------------------------------------
// Project descriptions
// -----------------------------------------------------------------------------

project(':asm') {
  description = parent.description
  provides = ['org.objectweb.asm', 'org.objectweb.asm.signature']
}

project(':asm-analysis') {
  description = "Static code analysis API of ${parent.description}"
  provides = ['org.objectweb.asm.tree.analysis']
  requires = [':asm-tree']
}

project(':asm-commons') {
  description = "Usefull class adapters based on ${parent.description}"
  provides = ['org.objectweb.asm.commons']
  requires = [':asm', ':asm-tree', ':asm-analysis']
  dependencies { testCompile project(':asm-util') }
77
  minCodeCoverage = 0.5  // TODO: improve the code coverage of this project.
Eric Bruneton's avatar
Eric Bruneton committed
78
79
80
81
82
}

project(':asm-test') {
  description = "Utilities for testing ${parent.description}"
  provides = ['org.objectweb.asm.test']
Eric Bruneton's avatar
Eric Bruneton committed
83
84
85
86
  depends = ['org.junit.jupiter:junit-jupiter-api:5.0.1',
      'org.junit.jupiter:junit-jupiter-params:5.0.1']
  sourceCompatibility = '1.8'
  targetCompatibility = '1.8'
Eric Bruneton's avatar
Eric Bruneton committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
}

project(':asm-tree') {
  description = "Tree API of ${parent.description}"
  provides = ['org.objectweb.asm.tree']
  requires = [':asm']
}

project(':asm-util') {
  description = "Utilities for ${parent.description}"
  provides = ['org.objectweb.asm.util']
  requires = [':asm', ':asm-tree', ':asm-analysis']
  dependencies { testCompile 'org.codehaus.janino:janino:3.0.7' }
}

project(':asm-xml') {
  description = "XML API of ${parent.description}"
  provides = ['org.objectweb.asm.xml']
  requires = [':asm', ':asm-util']
106
  minCodeCoverage = 0.8
Eric Bruneton's avatar
Eric Bruneton committed
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
}

project(':benchmarks') {
  description = "Benchmarks for ${parent.description}"
}

project(':benchmarks:memory') {
  description = "Memory benchmark for ${rootProject.description}"
  requires = [':asm', ':asm-tree']
  runWith = ['org.objectweb.asm.ASMMemTest', 
      "${System.env.JAVA_HOME}/jre/lib/rt.jar", '2000']
}

project(':benchmarks:read-write') {
  description = "Read-Write benchmark for ${rootProject.description}"
  requires = [':asm', ':asm-analysis', ':asm-commons', ':asm-tree']
  depends = [
    'net.sourceforge.serp:serp:1.15.1',
    'org.apache.bcel:bcel:6.0',
    'org.aspectj:aspectjweaver:1.8.10',
    'org.javassist:javassist:3.21.0-GA'
  ]
  runWith = ['org.objectweb.asm.ALLPerfTest']
}

project(':benchmarks:write') {
  description = "Write benchmark for ${rootProject.description}"
134
135
136
137
138
139
140
141
142
143
144
  apply plugin: 'me.champeau.gradle.jmh'
  ['4', '5', '6'].each { version -> 
    configurations.create("asm${version}")
    dependencies.add("asm${version}", "org.ow2.asm:asm:${version}.0@jar")
    task "asm${version}"(type: Copy) {
      from configurations."asm${version}".collect { zipTree(it) }
      into "${buildDir}/asm${version}"
    }
    classes.dependsOn "asm${version}"
  }
  classes.dependsOn project(':asm').classes
Eric Bruneton's avatar
Eric Bruneton committed
145
146
  dependencies { 
    compile files('libs/csg-bytecode-1.0.0.jar', 'libs/jclasslib.jar') 
147
    jmhCompileOnly project(':asm')
Eric Bruneton's avatar
Eric Bruneton committed
148
149
150
151
152
153
154
155
156
  }
  depends = [
    'kawa:kawa:1.7',
    'net.sf.jiapi:jiapi-reflect:0.5.2',
    'org.apache.bcel:bcel:6.0',
    'org.aspectj:aspectjweaver:1.8.10',
    'org.cojen:cojen:2.2.5',
    'org.mozilla:rhino:1.7.7.1'
  ]
157
  jmh { fork = 1; warmupIterations = 5; iterations = 20 }
Eric Bruneton's avatar
Eric Bruneton committed
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
}

project(':tools') {
  description = "Tools used to build ${parent.description}"
}

project(':tools:bnd-module-plugin') {
  description = "bnd plugin to build moduleinfo with ${rootProject.description}"
  // TODO: this compiles asm twice (here and in :asm), find a way to avoid this.
  sourceSets.main.java.srcDirs += project(':asm').sourceSets.main.java.srcDirs
  depends = ['biz.aQute.bnd:biz.aQute.bnd:3.4.0']
}

project(':tools:retrofitter') {
  description = "JDK 1.5 class retrofitter based on ${rootProject.description}"
  // TODO: this compiles asm thrice (here, above and in :asm).
  sourceSets.main.java.srcDirs += project(':asm').sourceSets.main.java.srcDirs
}

// -----------------------------------------------------------------------------
// Project tasks creation and configuration
// -----------------------------------------------------------------------------

// All projects use Java 1.5 and are tested with :asm-test and JUnit.
subprojects {
183
184
  apply plugin: 'com.github.sherter.google-java-format'
  googleJavaFormat.toolVersion = '1.4'
Eric Bruneton's avatar
Eric Bruneton committed
185
186
187
188
  compileTestJava {
    sourceCompatibility = '1.8'
    targetCompatibility = '1.8'
  }
Eric Bruneton's avatar
Eric Bruneton committed
189
190
191
  dependencies {
    requires.each { projectName -> compile project(projectName) }
    depends.each { artifactName -> compile artifactName }
Eric Bruneton's avatar
Eric Bruneton committed
192
193
    testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.1', 
        'org.junit.jupiter:junit-jupiter-params:5.0.1', project(':asm-test')
194
195
    // Workaround for https://github.com/junit-team/junit5-samples/issues/45
    testCompileOnly 'org.apiguardian:apiguardian-api:1.0.0'
Eric Bruneton's avatar
Eric Bruneton committed
196
  	testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.0.1'
Eric Bruneton's avatar
Eric Bruneton committed
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
  }
}

// Add a run task to all the projects having a non-empty 'runWidth' property.
configure(subprojects.findAll { it.runWith }) {
  task run(type: JavaExec) {
    classpath sourceSets.main.runtimeClasspath
    main runWith[0]
    args runWith.drop(1)
  }
}

// Configures the projects with a non-empty 'provides' property. These are the
// ones which are published in Maven. They must be checked for code coverage and
// backward compatibility, retrofited to Java 1.5, packaged with biz.aQute.bnd
// and uploaded to Maven with a POM, sources and Javadoc.
configure(subprojects.findAll { it.provides }) {
214
215
  // Code coverage configuration (JUnit5 is not yet supported by default, we 
  // need to override the default tasks to make this work).
Eric Bruneton's avatar
Eric Bruneton committed
216
  apply plugin: 'jacoco'
217
218
219
220
221
222
223
  afterEvaluate {
    jacoco { applyTo junitPlatformTest }
    task jacocoTestReport(type: JacocoReport, overwrite: true) {
      executionData junitPlatformTest
      sourceSets sourceSets.main
      sourceDirectories = files(project.sourceSets.main.allSource.srcDirs)
      classDirectories = files(project.sourceSets.main.output.collect {
224
225
226
        fileTree(dir: it, include: 'org/objectweb/asm/**')
      })
    }
227
228
229
230
231
232
233
234
235
236
237
    task jacocoTestCoverageVerification(
        type: JacocoCoverageVerification, overwrite: true) {
      executionData junitPlatformTest
      sourceSets sourceSets.main
      sourceDirectories = files(project.sourceSets.main.allSource.srcDirs)
      classDirectories = files(project.sourceSets.main.output.collect {
        fileTree(dir: it, include: 'org/objectweb/asm/**')
      })
      violationRules.rule {
        limit {
          counter = 'INSTRUCTION'
238
          minimum = minCodeCoverage
239
        }
240
241
242
      }
    }
  }
Eric Bruneton's avatar
Eric Bruneton committed
243
244

  // Retrofit the code to Java 1.5, in-place, in compileJava.doLast.
Eric Bruneton's avatar
Eric Bruneton committed
245
246
247
248
249
250
251
252
  if (name != 'asm-test') {
    task retrofit(type: JavaExec) {
      classpath project(':tools:retrofitter').sourceSets.main.runtimeClasspath
      main 'org.objectweb.asm.tools.Retrofitter'
      args sourceSets.main.output.classesDirs
    }
    compileJava.dependsOn ':tools:retrofitter:classes'
    compileJava.doLast { tasks.retrofit.execute() }
Eric Bruneton's avatar
Eric Bruneton committed
253
254
255
  }

  // Create one backward compatibility checking task for each 'sigtest-*' file
256
  // in test/resources, and make the 'check' task depend on all these tasks.
257
258
259
260
261
  if (file('src/test/resources/').exists()) {
    configurations { sigtest }
    dependencies { sigtest 'org.netbeans.tools:sigtest-maven-plugin:1.0' }
    file('src/test/resources/').eachFileMatch(~/sigtest-.*/) { f ->
      task "${f.name}" (type: JavaExec, dependsOn: 'classes') {
Eric Bruneton's avatar
Eric Bruneton committed
262
        inputs.files(f, sourceSets.main.java)
263
        outputs.file("${buildDir}/${f.name}")
264
265
266
        classpath configurations.sigtest
        main 'com.sun.tdk.signaturetest.Main'
        args 'Test', '-ApiVersion', version, '-Backward', '-Static', '-Mode',
Eric Bruneton's avatar
Eric Bruneton committed
267
268
269
            'bin', '-Classpath', "${System.env.JAVA_HOME}/jre/lib/rt.jar:" +
            sourceSets.main.output.classesDirs.asPath, '-FileName', f,
            '-Out', outputs.getFiles()[0], '-Package'
270
271
272
273
274
275
276
        args provides
        // The exit value is not 0 in case of success, but 95...
        ignoreExitValue true
        doLast {
          if (!outputs.getFiles()[0].readLines().find {it =~ /STATUS:Passed/}) {
            throw new GradleException('Sigtest FAILED')
          }
Eric Bruneton's avatar
Eric Bruneton committed
277
278
        }
      }
279
      check.dependsOn f.name
Eric Bruneton's avatar
Eric Bruneton committed
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
    }
  }

  // Apply the biz.aQute.bnd plugin to package the project as an OSGi bundle, 
  // with a custom plugin to generate and include a module-info class. Exclude
  // the asm-test project (the DefaultPackage class prevents it from being a
  // proper bundle).
  if (name != 'asm-test') {
    apply plugin: 'biz.aQute.bnd.builder'
    jar.dependsOn ':tools:bnd-module-plugin:jar'
    jar.manifest.attributes(
      '-classpath': sourceSets.main.output.classesDirs.asPath,
      '-plugin': 'org.objectweb.asm.tools.ModuleInfoBndPlugin;',
      '-pluginpath': 
          project(':tools:bnd-module-plugin').jar.outputs.files.singleFile,
      '-removeheaders': 'Bnd-LastModified,Build-By,Created-By,Include-Resource,\
          Require-Capability,Tool',
      'Bundle-DocURL': 'http://asm.ow2.org',
      'Bundle-RequiredExecutionEnvironment': 'J2SE-1.5',
      'Bundle-SymbolicName': provides[0],
300
      'Export-Package': provides.collect{"${it};version=${version}"}.join(','),
Eric Bruneton's avatar
Eric Bruneton committed
301
302
303
304
305
306
307
308
      'Implementation-Title': project.description,
      'Module-Requires': 
          requires
              .collect{"${project(it).provides[0]};transitive=true"}
              .join(',')
    )
  }

309
310
311
312
313
314
315
316
317
318
  // Apply the SonarQube plugin to monitor the code quality of the project.
  // Use with 'gradlew sonarqube -Dsonar.host.url=https://sonarqube.ow2.org'.
  apply plugin: 'org.sonarqube'
  sonarqube {
    properties {
      property 'sonar.jacoco.reportPaths',
          "${project.buildDir}/jacoco/junitPlatformTest.exec"
    }
  }

319
320
321
322
323
324
325
326
327
328
  // Add a task to generate a private javadoc and add it as a dependency of the
  // 'check' task.
  task privateJavadoc(type: Javadoc) {    
    source = sourceSets.main.allJava
    classpath = configurations.compile
    destinationDir = file("${javadoc.destinationDir}-private")
    options.memberLevel = JavadocMemberLevel.PRIVATE
  }
  check.dependsOn privateJavadoc

Eric Bruneton's avatar
Eric Bruneton committed
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
  // Add tasks to generate the Javadoc and a source jar, to be uploaded to Maven
  // together with the main jar (containing the compiled code).
  task javadocJar(type: Jar, dependsOn: 'javadoc') {
    from javadoc.destinationDir
    classifier 'javadoc'
  }
  task sourcesJar(type: Jar, dependsOn: 'classes') {
    from sourceSets.main.allSource
    classifier 'sources'
  }
  artifacts {
    archives javadocJar
    archives sourcesJar
  }

  // Add an uploadArchives task, provided by the maven plugin, to generate the
  // project POM and to upload it, with the classes, sources and Javadoc jars.
  apply plugin: 'maven'
  uploadArchives.repositories.mavenDeployer {
    // TODO: replace this with the OW2 Nexus repository.
    repository url: 'file://localhost/tmp/myRepo/'
    pom.project {
      parent {
        artifactId 'ow2'
        groupId 'org.ow2'
        version '1.5'
      }

      name jar.baseName
      description project.description
      packaging 'jar'
      inceptionYear '2000'
      licenses {
        license {
          name 'BSD'
          url 'http://asm.ow2.org/license.html'
        }
      }

      url 'http://asm.ow2.org/'
      mailingLists {
        mailingList {
          name 'ASM Users List'
          subscribe 'https://mail.ow2.org/wws/subscribe/asm'
          post 'asm@objectweb.org'
          archive 'https://mail.ow2.org/wws/arc/asm/'
        }
        mailingList {
          name 'ASM Team List'
          subscribe 'https://mail.ow2.org/wws/subscribe/asm-team'
          post 'asm-team@objectweb.org'
          archive 'https://mail.ow2.org/wws/arc/asm-team/'
        }
      }
      issueManagement {
        url 'https://gitlab.ow2.org/asm/asm/issues'
      }
      scm {
        connection 'scm:git:https://gitlab.ow2.org/asm/asm/'
        developerConnection 'scm:git:https://gitlab.ow2.org/asm/asm/'
        url 'https://gitlab.ow2.org/asm/asm/'
      }

      developers {
        developer {
          name 'Eric Bruneton'
          id 'ebruneton'
          email 'ebruneton@free.fr'
          roles {
            role 'Creator'
            role 'Java Developer'
          }
        }
        developer {
          name 'Eugene Kuleshov'
          id 'eu'
          email 'eu@javatx.org'
          roles {
            role 'Java Developer'
          }
        }
        developer {
          name 'Remi Forax'
          id 'forax'
          email 'forax@univ-mlv.fr'
          roles {
            role 'Java Developer'
          }
        }
      }
      organization {
        name 'OW2'
        url 'http://www.ow2.org/'
      }
    }
  }
}