summaryrefslogtreecommitdiff
path: root/build.gradle
blob: 28451c7e80f1de63b9e24110f500e86f60d74094 (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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// Do it this way so people with older Gradle can hopefully still build.
buildscript {
    repositories {
        jcenter()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }

    dependencies {
        classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
    }
}

import org.apache.tools.ant.filters.ReplaceTokens

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'maven'

group = 'cuchaz'
version = '0.12.2'

def filteredSourceDir = file("${buildDir}/filtered")

def ENV = System.getenv()
if (ENV.BUILD_NUMBER) {
    version = version + "." + "${System.getenv().BUILD_NUMBER}"
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

// Custom source layout
sourceSets {
    main {
        java { srcDir 'src/main/java' }
        resources { srcDir 'conf' }
    }
    test {
        java { srcDir 'src/test/java' }
        resources { srcDir 'test' }
    }
    filtered {
        java { srcDir filteredSourceDir }
    }
}

compileJava.source = sourceSets.filtered.java

task processVersion(type: Copy) {
    from sourceSets.main.java
    into filteredSourceDir

    filter { String line ->
        ("$line".replaceAll('@VERSION@', version))
    }
}

compileJava.dependsOn processVersion

repositories {
    mavenLocal()
    mavenCentral()

    maven {
        name "Cuchaz Custom Repository"
        url 'http://maven.cuchazinteractive.com'
    }

    maven {
        name "Modmuss Repository"
        url 'http://maven.modmuss50.me/'
    }

	ivy {
		name "darcula"
		artifactPattern "https://raw.githubusercontent.com/bulenkov/Darcula/master/build/[module].[ext]"
	}
}

configurations {
    proGuard // used to download ProGuard
    application // used for JSyntaxPane so it's not in the library POM

    compile.extendsFrom application
}

dependencies {
    compile 'com.google.guava:guava:27.0-jre'
    compile 'org.bitbucket.mstrobel:procyon-compilertools:0.5.33.8-enigma'
    compile 'com.google.code.gson:gson:2.8.5'
    compile 'org.ow2.asm:asm:7.0'
    compile 'org.ow2.asm:asm-commons:7.0'
    compile 'org.ow2.asm:asm-tree:7.0'
    compile 'org.ow2.asm:asm-util:7.0'

    application name: "darcula", version: "1.0.0"
    application 'de.sciss:syntaxpane:1.1.+'

    testCompile 'junit:junit:4.+'
    testCompile 'org.hamcrest:hamcrest-all:1.+'

    proGuard 'net.sf.proguard:proguard-base:5.+'
}

// For each set of test inputs, create an output jar and obfuscate it.
file('src/test/java/cuchaz/enigma/inputs').listFiles().each { theFile ->
    if (theFile.directory) {
        task("${theFile.name}TestJar", type: Jar, dependsOn: testClasses) {
            from('build/classes/test') {
                include "cuchaz/enigma/inputs/$theFile.name/**/*.class"
                include 'cuchaz/enigma/inputs/Keep.class'
            }

            archiveName = theFile.name + '.jar'
            destinationDir = file('build/test-inputs')
        }

        task("${theFile.name}TestObf", type: JavaExec,
                dependsOn: "${theFile.name}TestJar") {
            main 'proguard.ProGuard'
            classpath configurations.proGuard

            args '@proguard-test.conf', '-injars', file('build/test-inputs/' +
                    "${theFile.name}.jar"), '-outjars', file('build/test-obf/' +
                    "${theFile.name}.jar")
        }

        test.dependsOn "${theFile.name}TestObf"
    }
}

// We also semi-deobfuscate translation.jar to then test it... yeah... oh well.
task('deobfTranslationInput', type: JavaExec, dependsOn: 'translationTestObf')
        {
            classpath sourceSets.main.runtimeClasspath
            main 'cuchaz.enigma.CommandMain'
            args 'deobfuscate', file('build/test-obf/translation.jar'),
                    file('build/test-deobf/translation.jar')
        }
test.dependsOn 'deobfTranslationInput'

test {
    // Since the Minecraft test is really long (like 10 minutes D:) we turn it
    // off by default.
    if (!System.getProperty('enableExtremelySlowMinecraftTest', '')
            .equalsIgnoreCase('true')) {
        exclude 'cuchaz/enigma/TestSourceIndex.class'
    }

    // Allow people to specify a custom path to their Minecraft directory.
    // (Example: `gradle build -Denigma.test.minecraftdir=./`)
    systemProperties = [
            'enigma.test.minecraftdir': System.getProperty('test.minecraftdir')
    ]
}

// Set the main class.
jar.manifest.attributes 'Main-Class': 'cuchaz.enigma.Main'

// Make the "fat" application jar. This is useful to just throw in a classpath
// for tests, though it includes some slightly useless stuff.
shadowJar {
    append 'license.LGPL3.txt'
    append 'license.APL2.txt'
    append 'readme.txt'

    exclude 'META-INF/maven/**'
}

// Create a library jar, containing only the deobfuscation code, for use at
// runtime. This will be deployed to Maven Local with a POM, and can be uploaded
// to a remote server manually (for now anyway).
task('libJar', type: Jar, dependsOn: classes) {
    classifier = 'lib'

    from("$buildDir/classes/main") {
        exclude 'cuchaz/enigma/gui/**'
        exclude 'cuchaz/enigma/convert/**'

        // Main classes + inner classes (keep CommandMain)
        exclude 'cuchaz/enigma/Main.class'
        exclude 'cuchaz/enigma/Main.class'
    }
}

task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.resources
    from sourceSets.filtered.java
}

artifacts {
   archives shadowJar
   archives libJar
   archives sourcesJar
}

// And finally, make the build generate / install the jars.
build.dependsOn install

apply from: 'https://github.com/FabricMC/fabric-docs/raw/master/gradle/maven.gradle'

uploadArchives.repositories.mavenDeployer.pom.withXml {
	asNode().dependencies.'*'.findAll() { it.artifactId.text() == 'darcula' }
	.each() { it.parent().remove(it) }
}