aboutsummaryrefslogtreecommitdiff
path: root/build.gradle
blob: ffb11109e58dc3edf434837a9daaceb3d9291707 (plain) (blame)
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
/*
 buildfile for gradle (http://gradle.org/)
*/

apply plugin: 'java'

buildDir = "$projectDir/build-gradle"

// specify where to get jars
repositories {
  flatDir {
    dirs 'lib'
  }
  mavenCentral()
}

dependencies {
  compile group: 'com.google.guava', name: 'guava', version: '14.0.1'
  compile group: 'junit', name: 'junit', version: '4.11'
  compile name: 'log4j', version: '1.2.16'
  compile name: 'slf4j-api', version: '1.6.4'
  compile name: 'slf4j-log4j12', version: '1.6.4'
}


task showClasspath << {
  System.out.println(configurations.compile.asPath);
}

task showDeps << {
  configurations.compile.each { File file -> println file.getPath() }
}


compileJava.options.debugOptions.debugLevel = "source,lines,vars"

project.ext.instrumentDir = "$buildDir/classes_instrumented"
project.ext.coberturaDir = "$projectDir/cobertura"
project.ext.coverageData = "$projectDir/coverage.data"
project.ext.coverageReportDir = "$projectDir/coverage-report"

task instrument (dependsOn: ['compileJava', 'compileTestJava'], type: JavaExec) {
  inputs.dir compileJava.destinationDir
  outputs.dir fileTree(dir: instrumentDir)

  classpath = files("$coberturaDir/cobertura.jar", "$coberturaDir/lib/*")
  main = 'net.sourceforge.cobertura.instrument.Main'

  args "--datafile", "$coverageData"
  args "--destination", "$instrumentDir"

  doFirst {
    FileTree tree = fileTree(dir: "$buildDir/classes/main/")
    tree.visit { element ->
      args "$buildDir/classes/main/$element.path"
    }
  }
}


task testCoverage (dependsOn: ['instrument'], type: Test) {
  classpath = files("$instrumentDir",
                    "$coberturaDir/cobertura.jar",
                    project.sourceSets.test.runtimeClasspath)
  //testClassesDir = new File("$instrumentDir")
  systemProperties = ["net.sourceforge.cobertura.datafile":"$coverageData"]
}


testCoverage.outputs.file("$coverageData")

task reportCoverage (type: JavaExec) {
  description = "Reports code coverage."
  doFirst {
    classpath = files("$projectDir/cobertura/cobertura.jar",
                      "$projectDir/cobertura/lib/*")
    main = 'net.sourceforge.cobertura.reporting.Main'
    args "--datafile", "$coverageData"
    args "--destination", "$coverageReportDir"
    args "$projectDir/src/"
  }
}

reportCoverage.inputs.file("$coverageData")
reportCoverage.outputs.dir("$coverageReportDir")

reportCoverage.dependsOn testCoverage


task createResourcesDir << {
  def myDir = new File('src/main/resources')  
  myDir.mkdirs()
}

/*
TODO: should we really use the compile task for this?
*/
task msgtypes (type: JavaCompile, dependsOn: 'createResourcesDir') {
  description = "Updates the index of GNUnet message types known to gnunet-java."
  classpath = project.sourceSets.main.runtimeClasspath
  source = files(project.sourceSets.main.allJava)
  options.setCompilerArgs(["-processor", "org.gnunet.construct.MessageIdAnnotationProcessor",
                           "-proc:only",
                           // generated "source" files should resources, tell the annotation processor!
                           "-s", "src/main/resources"])
  destinationDir = file("$buildDir/classes/main/")
}

project.ext.installerFile = "$projectDir/gnunet-java-installer.jar"

task installer (type: Exec) {
  description "build an IZPack installer for gnunet-java"
  workingDir "$projectDir"

  outputs.file("$installerFile")
}

installer.dependsOn "build","javadoc"

installer.outputs.upToDateWhen { false }

installer.doFirst {
  def izpack = System.getenv("IZPACK_COMPILER")
  if (izpack == null) {
    throw new RuntimeException("environment variable IZPACK_COMPILER not defined")
  }
  installer.commandLine "$izpack", "$projectDir/izpack-installer.xml", "-o", "$installerFile"
}


task wrapper(type: Wrapper) {
  gradleVersion = '1.7'
}

if (hasProperty("xlint")) {
  tasks.withType(Compile) {
    options.compilerArgs << "-Xlint:unchecked"
  }
}