summaryrefslogtreecommitdiff
path: root/cli/build.gradle
blob: 397468ded70ab9ebd78b965604622f994fd018b8 (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
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
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'scala'
apply plugin: 'signing'

evaluationDependsOn(':stringmetric-core')

compileScala {
	compileScala.scalaCompileOptions.additionalParameters = ['-optimise', '–Xdisable-assertions']
}

dependencies {
	compile project(':stringmetric-core')
	compile 'org.scala-lang:scala-compiler:2.9.2'
	compile 'org.scala-lang:scala-library:2.9.2'

	scalaTools 'org.scala-lang:scala-compiler:2.9.2'
	scalaTools 'org.scala-lang:scala-library:2.9.2'

	testCompile project(':stringmetric-core').sourceSets.test.output
	testCompile 'junit:junit:4.10'
	testCompile 'org.scalatest:scalatest_2.9.2:1.8'
}

signing {
	sign configurations.archives
}

sourceSets {
	main {
		output.resourcesDir "${project.buildDir}/classes/main"

		java {
			srcDir 'source/core/java'
		}
		resources {
			srcDir 'source/core/resource'
		}
		scala {
			srcDir 'source/core/scala'
		}
	}
	test {
		output.resourcesDir "${project.buildDir}/classes/test"

		java {
			srcDir 'source/test/java'
		}
		resources {
			srcDir 'source/test/resource'
		}
		scala {
			srcDir 'source/test/scala'
		}
	}
}

task scaladocJar(type: Jar, dependsOn: scaladoc) {
	classifier = 'javadoc'
	from "${project.buildDir}/docs/scaladoc"
}

task sourceJar(type: Jar, dependsOn: classes) {
	classifier = 'sources'
	from sourceSets.main.allSource
}

task tar(description: 'Assembles a compressed tar archive of source files.', dependsOn: [':stringmetric-cli:jar', ':stringmetric-core:jar']) {
	ext.sourcePath = "${project.projectDir}/source/core/scala"
	ext.outputPath = "${project.buildDir}"
	ext.workingPath = "${project.buildDir}/${project.name}"

	inputs.dir new File(sourcePath)
	outputs.dir new File(outputPath, 'generated')
	outputs.upToDateWhen {
		new File(workingPath).isDirectory()
	}
	
	doLast {
		// Clean up working directory and tar from last execution, should they exist.
		ant.delete(dir: workingPath, failOnError: false)
		ant.delete(file: "${project.buildDir}/${project.name}.tar.gz", failOnError: false)

		// Create project working directory.
		ant.mkdir(dir: workingPath)

		// Create scalascript header file.
		ant.echo(file: "${workingPath}/scalascript.sh", message: '#!/bin/bash\ndir="`dirname \\"$0\\"`"\ndir="`( cd \\"$dir\\" && pwd )`"\ncp=`echo $dir/*.jar|sed \'s/ /:/g\'`\nexec scala -classpath "$cp" -savecompiled "$0" "$@"\n!#\n//')

		// Copy source files to working directory.
		ant.copy(toDir: workingPath, force: true, overwrite: true) {
			fileset(dir: sourcePath) {
				exclude(name: '**/cli/*.scala')
				exclude(name: '**/package.scala')
			}
			filterchain {
				concatfilter(prepend: "${workingPath}/scalascript.sh")
			}
		}

		// Delete scalascript header file.
		ant.delete(file: "${workingPath}/scalascript.sh")

		// Flatten and remove file extension.
		ant.move(toDir: workingPath) {
			fileset(dir: workingPath)
			chainedmapper {
				mapper(type: 'flatten')
				mapper(from: '*.scala', to: '*', type: 'glob')
			}
		}

		// Clean up emtpy folder(s) from flatten.
		ant.delete(dir: "${workingPath}/org", includeEmptyDirs: true)

		// Copy project jars into place.
		ant.copy(toDir: workingPath, force: true, overwrite: true) {
			fileset(dir: "${project.buildDir}/libs")
		}
		ant.copy(toDir: workingPath, force: true, overwrite: true) {
			fileset(dir: "${project(':stringmetric-core').buildDir}/libs")
		}

		// Assemble compressed tar.
		ant.tar(compression: 'gzip', destFile: "${project.buildDir}/${project.name}.tar.gz") {
			tarfileset(dir: workingPath, fileMode: 755, prefix: project.name)
		}
	}
}

artifacts {
	archives jar
	archives scaladocJar
	archives sourceJar
}

def isDeployable = hasProperty('sonatypeRepositoryUrl') && hasProperty('sonatypeUsername') && hasProperty('sonatypePassword')

uploadArchives {
	repositories {
		if(isDeployable) {
			mavenDeployer {
				beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

				repository(url: sonatypeRepositoryUrl) {
					authentication(userName: sonatypeUsername, password: sonatypePassword)
				}

				pom.project {
					description "${parent.project.description}"
					groupId "${parent.project.group}"
					name "${project.name}"
					packaging 'jar'
					url "${parent.project.url}"
					version "${parent.project.version}"

					developers {
						developer {
							id 'rockymadden'
							name 'Rocky Madden'
						}
					}
	 
					licenses {
						license {
							name 'Apache License v2.0'
							url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
							distribution 'repo'
						}
					}

					scm {
						url "${parent.project.scm}"
						connection "${parent.project.scm}"
					}
				}
			}
		} else { mavenLocal() }
	}
}