build.gradle 16.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
  repositories { mavenCentral() }
31
  dependencies { classpath 'org.netbeans.tools:sigtest-maven-plugin:1.1' }
Eric Bruneton's avatar
Eric Bruneton committed
32 33
}

34
plugins { id 'biz.aQute.bnd.builder' version '4.2.0' apply false }
Eric Bruneton's avatar
Eric Bruneton committed
35
plugins { id 'com.github.sherter.google-java-format' version '0.8' apply false }
36
plugins { id 'me.champeau.gradle.jmh' version '0.4.8' apply false }
37
plugins { id 'org.sonarqube' version '2.7.1' 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'
44
  apply plugin: 'jacoco'
45
  def snapshotSuffix = rootProject.hasProperty('release') ? '' : '-SNAPSHOT'
Eric Bruneton's avatar
Eric Bruneton committed
46
  group = 'org.ow2.asm'
47
  version = '8.0-alpha' + snapshotSuffix
48 49
  sourceCompatibility = '1.8'
  targetCompatibility = '1.8'
50
  test { useJUnitPlatform() }
Eric Bruneton's avatar
Eric Bruneton committed
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']
54 55 56 57
  // Some external dependencies (such as Jacoco) depend transitively on ASM, and
  // without this rule Gradle can mix ASM jars of different versions (e.g.
  // asm-6.0.jar with the asm-tree.jar built locally).
  configurations.all { resolutionStrategy { preferProjectModules() } }
Eric Bruneton's avatar
Eric Bruneton committed
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
}

// -----------------------------------------------------------------------------
// 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') }
}

project(':asm-test') {
  description = "Utilities for testing ${parent.description}"
  provides = ['org.objectweb.asm.test']
85 86
  depends = ['org.junit.jupiter:junit-jupiter-api:5.3.2',
      'org.junit.jupiter:junit-jupiter-params:5.3.2']
Eric Bruneton's avatar
Eric Bruneton committed
87 88 89 90 91 92 93 94 95 96 97 98
}

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']
99
  dependencies { testCompile 'org.codehaus.janino:janino:3.0.11' }
Eric Bruneton's avatar
Eric Bruneton committed
100 101
}

102
// Use "gradle benchmarks:jmh [-PjmhInclude='<regex>']" to run the benchmarks.
Eric Bruneton's avatar
Eric Bruneton committed
103
project(':benchmarks') {
104
  description = "Benchmarks for ${rootProject.description}"
105
  apply plugin: 'me.champeau.gradle.jmh'
106 107 108
  dependencies {
    compile files('libs/csg-bytecode-1.0.0.jar', 'libs/jclasslib.jar')
    jmh project(':asm'), project(':asm-tree') 
109
  }
Eric Bruneton's avatar
Eric Bruneton committed
110
  depends = [
111 112
    'kawa:kawa:1.7',
    'net.sf.jiapi:jiapi-reflect:0.5.2',
Eric Bruneton's avatar
Eric Bruneton committed
113 114 115
    'net.sourceforge.serp:serp:1.15.1',
    'org.apache.bcel:bcel:6.0',
    'org.aspectj:aspectjweaver:1.8.10',
116 117 118
    'org.cojen:cojen:2.2.5',
    'org.javassist:javassist:3.21.0-GA',
    'org.mozilla:rhino:1.7.7.1'
Eric Bruneton's avatar
Eric Bruneton committed
119
  ]
Eric Bruneton's avatar
Eric Bruneton committed
120
  ['4.0', '5.0.1', '6.0', '7.0', '7.1'].each { version ->
121 122 123 124 125 126 127 128
    configurations.create("asm${version}")
    dependencies.add("asm${version}", "org.ow2.asm:asm:${version}@jar")
    dependencies.add("asm${version}", "org.ow2.asm:asm-tree:${version}@jar")
    task "asm${version}"(type: Copy) {
      from configurations."asm${version}".collect { zipTree(it) }
      into "${buildDir}/asm${version}"
    }
    classes.dependsOn "asm${version}"
129
  }
130 131 132 133 134 135 136
  configurations.create('input-classes-java8')
  dependencies.add('input-classes-java8', 'io.vavr:vavr:0.10.0@jar')
  task copyInputClasses(type: Copy) {
    from configurations.'input-classes-java8'.collect { zipTree(it) }
    into "${buildDir}/input-classes-java8"
  }
  classes.dependsOn copyInputClasses
137
  jmh {
138
    jvmArgsAppend = "-Duser.dir=${rootDir}"
139
    resultFormat = 'CSV'
140
    profilers = ['org.objectweb.asm.benchmarks.MemoryProfiler']
141 142 143
    if (rootProject.hasProperty('jmhInclude')) {
      include = [jmhInclude]
    }
Eric Bruneton's avatar
Eric Bruneton committed
144 145 146 147 148 149 150 151 152 153 154
  }
}

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
155
  depends = ['biz.aQute.bnd:biz.aQute.bnd:4.0.0']
Eric Bruneton's avatar
Eric Bruneton committed
156 157 158 159 160 161 162 163 164 165 166 167
}

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
// -----------------------------------------------------------------------------

168 169
// All projects are checked with googleJavaFormat, Checkstyle and PMD, 
// and tested with :asm-test and JUnit.
Eric Bruneton's avatar
Eric Bruneton committed
170
subprojects {
171
  apply plugin: 'com.github.sherter.google-java-format'
172
  googleJavaFormat.toolVersion = '1.7'
173
  googleJavaFormat.exclude 'src/resources/java/**/*'
174 175 176
  
  // Check the coding style with Checkstyle. Fail in case of error or warning.
  apply plugin: 'checkstyle'
177
  checkstyle.toolVersion = '8.20'
178 179 180 181
  checkstyle.configFile = file("${rootDir}/tools/checkstyle.xml")
  checkstyle.maxErrors = 0
  checkstyle.maxWarnings = 0
  
Eric Bruneton's avatar
Eric Bruneton committed
182
  // Check the code with PMD.
183 184 185
  apply plugin: 'pmd'
  pmd.ruleSets = []
  pmd.ruleSetFiles = files("${rootDir}/tools/pmd.xml")
186
  pmd.consoleOutput = true
187

Eric Bruneton's avatar
Eric Bruneton committed
188 189 190
  dependencies {
    requires.each { projectName -> compile project(projectName) }
    depends.each { artifactName -> compile artifactName }
191 192 193
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.2',
        'org.junit.jupiter:junit-jupiter-params:5.3.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.2'
194
    testCompile project(':asm-test')
Eric Bruneton's avatar
Eric Bruneton committed
195
  }
196 197 198 199 200 201 202 203

  // Produce byte-for-byte reproducible archives.
  tasks.withType(AbstractArchiveTask).configureEach {
    preserveFileTimestamps = false
    reproducibleFileOrder = true
    dirMode = 0775
    fileMode = 0664
  }
Eric Bruneton's avatar
Eric Bruneton committed
204 205 206 207 208 209 210
}

// 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 }) {
211
  // Code coverage configuration.
212
  jacoco.toolVersion = '0.8.5'
213
  jacocoTestReport {
214
    classDirectories.setFrom(sourceSets.main.output.classesDirs)
215 216
  }
  jacocoTestCoverageVerification {
217 218
    classDirectories.setFrom(sourceSets.main.output.classesDirs)
    violationRules.rule { limit { minimum = 0.95; counter = 'INSTRUCTION' } }
219
  }
220
  check.dependsOn jacocoTestCoverageVerification
Eric Bruneton's avatar
Eric Bruneton committed
221 222

  // Retrofit the code to Java 1.5, in-place, in compileJava.doLast.
Eric Bruneton's avatar
Eric Bruneton committed
223 224
  if (name != 'asm-test') {
    compileJava.dependsOn ':tools:retrofitter:classes'
225 226 227
    compileJava.doLast {
      def path = project(':tools:retrofitter').sourceSets.main.runtimeClasspath
      def loader = new URLClassLoader(path.collect {f -> f.toURL()} as URL[])
228 229 230
      def retrofitter =
          loader.loadClass('org.objectweb.asm.tools.Retrofitter').newInstance()
      retrofitter.retrofit sourceSets.main.output.classesDirs.singleFile
231
    }
Eric Bruneton's avatar
Eric Bruneton committed
232 233 234
  }

  // Create one backward compatibility checking task for each 'sigtest-*' file
235
  // in test/resources, and make the 'check' task depend on all these tasks.
236 237
  if (file('src/test/resources/').exists()) {
    file('src/test/resources/').eachFileMatch(~/sigtest-.*/) { f ->
238
      task "${f.name}"(dependsOn: 'classes') {
Eric Bruneton's avatar
Eric Bruneton committed
239
        inputs.files(f, sourceSets.main.java)
240
        outputs.file("${buildDir}/${f.name}")
241
        doLast {
242 243
          def sigtest = new com.sun.tdk.signaturetest.SignatureTest()
          def args = ['-ApiVersion', version, '-Backward', '-Static',
244 245 246
              '-Mode', 'bin', '-FileName', f, '-Classpath',
              project(':tools').file('jdk8-api.jar').path + File.pathSeparator +
              sourceSets.main.output.classesDirs.asPath, '-Package'] + provides
247 248 249
          outputs.getFiles()[0].withPrintWriter { printWriter -> 
            sigtest.run(args as String[], printWriter, null)
          }
250
          if (!sigtest.isPassed()) throw new GradleException()
Eric Bruneton's avatar
Eric Bruneton committed
251 252
        }
      }
253
      check.dependsOn f.name
Eric Bruneton's avatar
Eric Bruneton committed
254
    }
255
    // Define a task to create a sigtest file for the current version.
256
    task "buildSigtest"(dependsOn: 'classes') {
257
      inputs.files(sourceSets.main.java)
258
      outputs.file("src/test/resources/sigtest-${version}.txt")
259
      doLast {
260 261 262 263 264 265 266 267
        def setup = new com.sun.tdk.signaturetest.Setup()
        def args = ['-ApiVersion', version, '-FileName', outputs.getFiles()[0],
            '-Classpath', project(':tools').file('jdk8-api.jar').path +
            File.pathSeparator + sourceSets.main.output.classesDirs.asPath +
            File.pathSeparator + sourceSets.main.compileClasspath.asPath,
            '-Package'] + provides
        setup.run(args as String[], new PrintWriter(System.err, true), null)
        if (!setup.isPassed()) throw new GradleException()
268 269
      }
    }
Eric Bruneton's avatar
Eric Bruneton committed
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
  }

  // 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',
286
      'Bundle-License': 'BSD-3-Clause;link=https://asm.ow2.io/LICENSE.txt',
Eric Bruneton's avatar
Eric Bruneton committed
287 288 289
      'Bundle-DocURL': 'http://asm.ow2.org',
      'Bundle-RequiredExecutionEnvironment': 'J2SE-1.5',
      'Bundle-SymbolicName': provides[0],
290
      'Export-Package': provides.collect{"${it};version=${version}"}.join(','),
Eric Bruneton's avatar
Eric Bruneton committed
291
      'Implementation-Title': project.description,
292
      'Implementation-Version': "${version}",
Eric Bruneton's avatar
Eric Bruneton committed
293 294 295 296 297
      'Module-Requires': 
          requires
              .collect{"${project(it).provides[0]};transitive=true"}
              .join(',')
    )
298 299 300 301
  } else {
    jar.manifest.attributes(
      'Implementation-Title': project.description,
      'Implementation-Version': "${version}")
Eric Bruneton's avatar
Eric Bruneton committed
302 303
  }

304 305 306
  // 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'
307 308 309
  sonarqube {
    properties { property 'sonar.projectKey', "ASM:${project.name}" }
  }
310

311 312 313 314 315 316 317 318 319 320
  // 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
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
  // 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
  }

336 337 338
  // Add an uploadArchives task, provided by the maven plugin, to generate and
  // sign the project POM and to upload it, with the signed classes, sources
  // and Javadoc jars.
Eric Bruneton's avatar
Eric Bruneton committed
339
  apply plugin: 'maven'
340
  apply plugin: 'signing'
Eric Bruneton's avatar
Eric Bruneton committed
341
  uploadArchives.repositories.mavenDeployer {
342 343 344 345 346 347 348 349
    def nexusUserName = System.env.NEXUS_USER_NAME
    def nexusPassword = System.env.NEXUS_PASSWORD
    if (nexusUserName != null) {
      def baseUrl = 'http://repository.ow2.org/nexus/'
      repository(url: baseUrl + 'service/local/staging/deploy/maven2') {
        authentication(userName: nexusUserName, password: nexusPassword)
      }
      snapshotRepository(url: baseUrl + 'content/repositories/snapshots') {
350 351
        authentication(userName: nexusUserName, password: nexusPassword)
      }
352
      signing {
353
        required rootProject.hasProperty('release')
354 355 356
        sign configurations.archives
      }
      beforeDeployment { MavenDeployment deploy -> signing.signPom(deploy) }
357 358 359
    } else {
      repository url: 'file://localhost/tmp/myRepo/'
    }
Eric Bruneton's avatar
Eric Bruneton committed
360 361 362 363 364 365 366 367 368 369 370 371 372
    pom.project {
      parent {
        artifactId 'ow2'
        groupId 'org.ow2'
        version '1.5'
      }

      name jar.baseName
      description project.description
      packaging 'jar'
      inceptionYear '2000'
      licenses {
        license {
373 374
          name 'BSD-3-Clause'
          url 'https://asm.ow2.io/license.html'
Eric Bruneton's avatar
Eric Bruneton committed
375 376 377
        }
      }

378
      url 'http://asm.ow2.io/'
Eric Bruneton's avatar
Eric Bruneton committed
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
      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/'
      }
    }
  }
}