forked from allaboutjst/airbnb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
94 lines (74 loc) · 2.18 KB
/
build.gradle
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
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
eclipse {
classpath {
downloadSources = true
downloadJavadoc = false
}
}
group = 'allaboutjst'
archivesBaseName = 'airbnb-java-coding'
version = '1.0'
description = 'AirBnB java coding exercise'
repositories {
mavenCentral()
}
dependencies {
compile 'junit:junit:4.12'
compile 'org.apache.commons:commons-lang3:3.4'
testCompile 'junit:junit:4.12'
}
sourceSets.test.java.srcDir 'src/main/java'
task wrapper(type: Wrapper) {
gradleVersion = '4.1'
}
task question {
doLast {
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} {
/*
*/
public class Solution {
}
public static class UnitTest {
@Test
public void test1() {
Solution sol = new ${className}().new Solution();
assertEquals(1, 1);
}
}
}
""")
}
}
}
}