-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathbuild.gradle
More file actions
80 lines (58 loc) · 1.68 KB
/
build.gradle
File metadata and controls
80 lines (58 loc) · 1.68 KB
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
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
eclipse {
classpath {
downloadSources = true
downloadJavadoc = false
}
}
group = 'me.iamzsx'
archivesBaseName = 'leetcode-java'
version = '1.0'
description = 'java solution for leetcode'
repositories {
mavenCentral()
}
dependencies {
compile 'junit:junit:4.10'
}
sourceSets.test.java.srcDir 'src/main/java'
task(question) << {
def insertUnderlineIfStartsWithDigit = { s ->
if (Character.isDigit(s.charAt(0))) {
s = '_' + s
}
s
}
if (!project.hasProperty('q')) {
throw new InvalidUserDataException('You need to specify a question. E.g., gradle question "-Pq=Some Question"')
}
def question = project.q
def questionPackage = insertUnderlineIfStartsWithDigit(question.replaceAll(' ', '_').toLowerCase())
def className = insertUnderlineIfStartsWithDigit(question.replaceAll(' ', ''))
def questionPackageDir = new File(sourceSets.main.java.srcDirs.iterator().next(), questionPackage)
if(!questionPackageDir.exists()) {
println 'Create ' + questionPackageDir
questionPackageDir.mkdirs()
}
def questionFile = new File(questionPackageDir, className + '.java')
if(!questionFile.exists()) {
println 'Create ' + questionFile
questionFile.withWriter { out ->
out.writeLine("""\
package ${questionPackage};
import java.util.*;
import org.junit.*;
import static org.junit.Assert.*;
public class ${className} {
// Insert your Solution class here
public static class UnitTest {
}
}
""")
}
}
}