blob: 5720976284591964ef61d77a9e391885434a291d [file] [log] [blame]
Ben Gruver076c6062014-03-15 17:37:29 -07001/*
2 * Copyright 2013, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
Ben Gruverdf4e74e2016-02-14 12:16:24 -080032buildscript {
33 repositories {
34 maven {
35 url "https://plugins.gradle.org/m2/"
36 }
Ben Gruver458398f2016-10-02 18:10:49 -070037 maven {
38 url 'http://dl.bintray.com/jetbrains/intellij-plugin-service'
39 }
40
Ben Gruverdf4e74e2016-02-14 12:16:24 -080041 }
42 dependencies {
Ben Gruver458398f2016-10-02 18:10:49 -070043 classpath "gradle.plugin.org.jetbrains:gradle-intellij-plugin:0.1.10"
Ben Gruverdf4e74e2016-02-14 12:16:24 -080044 }
Ben Gruver076c6062014-03-15 17:37:29 -070045}
46
Ben Gruverdf4e74e2016-02-14 12:16:24 -080047apply plugin: 'java'
48apply plugin: 'idea'
49apply plugin: 'antlr'
Ben Gruver076c6062014-03-15 17:37:29 -070050
Ben Gruver458398f2016-10-02 18:10:49 -070051
Ben Gruver76d69c72017-03-31 16:25:08 -070052version = '0.05'
Ben Gruverdf4e74e2016-02-14 12:16:24 -080053
54if (!('release' in gradle.startParameter.taskNames)) {
55 def versionSuffix
56 try {
57 def git = org.eclipse.jgit.api.Git.open(file('..'))
58 def head = git.getRepository().getRef('HEAD')
59 versionSuffix = head.getObjectId().abbreviate(8).name()
60
61 if (!git.status().call().clean) {
62 versionSuffix += '-dirty'
63 }
64 } catch (Exception ex) {
65 // In case we can't get the commit for some reason,
66 // just use -dev
67 versionSuffix = 'dev'
68 }
69
70 def baseVersion = version
71 version = baseVersion + '-' + versionSuffix
72} else {
73 if (System.env.JDK7_HOME == null && !JavaVersion.current().isJava7()) {
74 throw new InvalidUserDataException("bzzzzzzzt. Release builds must be performed with java 7. " +
75 "Either run gradle with java 7, or define the JDK7_HOME environment variable.")
76 }
77}
78
79if (System.env.JDK7_HOME != null) {
80 sourceCompatibility = 1.7
81 targetCompatibility = 1.7
82
83 tasks.withType(JavaCompile) {
84 doFirst {
85 options.fork = true
86 options.bootClasspath = "$System.env.JDK7_HOME/jre/lib/rt.jar"
87 options.bootClasspath += "$File.pathSeparator$System.env.JDK7_HOME/jre/lib/jsse.jar"
88 }
89 }
90}
91
Ben Gruver3bdedd62016-02-27 12:50:54 -080092def sandboxDir = "${buildDir}/sandbox"
93
Ben Gruverdf4e74e2016-02-14 12:16:24 -080094if (!('idea' in gradle.startParameter.taskNames)) {
Ben Gruver458398f2016-10-02 18:10:49 -070095
Ben Gruverdf4e74e2016-02-14 12:16:24 -080096 apply plugin: 'org.jetbrains.intellij'
97
98 intellij {
Ben Gruverfa13b132017-03-21 21:59:02 -070099 version 'IC-2016.3.5'
Ben Gruverdf4e74e2016-02-14 12:16:24 -0800100 pluginName 'smalidea'
101
Ben Gruver81e03092016-02-27 20:06:20 -0800102 updateSinceUntilBuild false
103
Ben Gruver3bdedd62016-02-27 12:50:54 -0800104 sandboxDirectory sandboxDir
Ben Gruverdf4e74e2016-02-14 12:16:24 -0800105 }
Ben Gruver92f8ec52016-02-14 12:19:34 -0800106
107 // This prints out the directories that can be used to configure a plugin sdk in IDEA, using
108 // the copy of IDEA downloaded by the org.jetbrains.intellij plugin
109 task ideaDirs() {
110 project.afterEvaluate {
111 if (intellij != null) {
Ben Gruver458398f2016-10-02 18:10:49 -0700112 println "IDEA Plugin jdk: ${intellij.ideaDependency.classes}"
113 println "sources: ${intellij.ideaDependency.getSources()}"
Ben Gruver92f8ec52016-02-14 12:19:34 -0800114 }
115 }
116 }
Ben Gruver1df38692016-02-15 13:13:31 -0800117
118 dependencies {
119 compile files("${System.properties['java.home']}/../lib/tools.jar")
120 }
Ben Gruver29d714f2016-02-26 22:09:08 -0800121
Ben Gruver458398f2016-10-02 18:10:49 -0700122} else {
Ben Gruver29d714f2016-02-26 22:09:08 -0800123 project(':') {
124 idea {
125 project {
126 ipr {
127 withXml {
128 def node = it.asNode()
129
130 /*node.find { it.@name == 'ProjectRootManager' }
131 .@'project-jdk-type' = 'IDEA JDK'*/
132
133 def componentNode = node.find { it.@name == 'ProjectRunConfigurationManager' }
134 if (componentNode == null) {
135 componentNode = it.node.appendNode 'component', [name: 'ProjectRunConfigurationManager']
136 }
137
138 if (componentNode.find { it.@name == 'All smalidea tests' } == null) {
139 componentNode.append(new XmlParser().parseText("""
140 <configuration default="false" name="All smalidea tests" type="JUnit" factoryName="JUnit">
141 <extension name="coverage" enabled="false" merge="false" runner="idea" />
142 <module name="smalidea" />
143 <option name="TEST_OBJECT" value="directory" />
Ben Gruver3bdedd62016-02-27 12:50:54 -0800144 <option name="VM_PARAMETERS" value="-Didea.system.path=${sandboxDir}/config -Didea.system.path=${sandboxDir}/system-test -Didea.load.plugins.id=org.jf.smalidea" />
Ben Gruver29d714f2016-02-26 22:09:08 -0800145 <option name="WORKING_DIRECTORY" value="file://\$PROJECT_DIR\$/smalidea" />
146 <option name="PASS_PARENT_ENVS" value="true" />
147 <option name="TEST_SEARCH_SCOPE">
148 <value defaultName="moduleWithDependencies" />
149 </option>
150 <dir value="\$PROJECT_DIR\$/smalidea/src/test/java" />
151 </configuration>"""))
152 }
153 }
154 }
155 }
156 }
157 }
158
159 idea {
160 module {
161 jdkName = 'IDEA Plugin jdk'
162
163 excludeDirs -= buildDir
164 if (buildDir.exists()) {
165 excludeDirs.addAll(buildDir.listFiles())
166 }
167
168 for (sourceDir in (sourceDirs + testSourceDirs)) {
169 excludeDirs.remove(sourceDir);
170 while ((sourceDir = sourceDir.getParentFile()) != null) {
171 excludeDirs.remove(sourceDir);
172 }
173 }
174
175 iml {
176 withXml {
177 def node = it.node
178
179 node.@type = 'PLUGIN_MODULE'
180
181 def pluginUrl = 'file://$MODULE_DIR$/src/main/resources/META-INF/plugin.xml'
182
183 def pluginNode = node.find { it.@name == 'DevKit.ModuleBuildProperties' }
184 if (pluginNode == null) {
185 node.appendNode 'component', [name: 'DevKit.ModuleBuildProperties',
186 url : pluginUrl]
187 } else {
188 pluginNode.@url = pluginUrl
189 }
190 }
191 }
192 }
193 }
Ben Gruverdf4e74e2016-02-14 12:16:24 -0800194}
195
196repositories {
197 mavenLocal()
198 mavenCentral()
199}
Ben Gruver076c6062014-03-15 17:37:29 -0700200
201dependencies {
Ben Gruver29d714f2016-02-26 22:09:08 -0800202 compile project(':smali')
203 compile depends.antlr_runtime
204 compile depends.gson
Ben Gruver076c6062014-03-15 17:37:29 -0700205
Ben Gruver29d714f2016-02-26 22:09:08 -0800206 antlr depends.antlr
Ben Gruver076c6062014-03-15 17:37:29 -0700207}
208
Ben Gruver29d714f2016-02-26 22:09:08 -0800209task extractTokens(type: org.gradle.api.tasks.Copy, dependsOn: ':smali:build') {
Ben Gruver458398f2016-10-02 18:10:49 -0700210 project.afterEvaluate {
211 def allArtifacts = configurations.default.resolvedConfiguration.resolvedArtifacts
212 def smaliArtifact = allArtifacts.find { it.moduleVersion.id.name.equals('smali') }
Ben Gruverdf4e74e2016-02-14 12:16:24 -0800213
Ben Gruver458398f2016-10-02 18:10:49 -0700214 from(zipTree(smaliArtifact.file)) {
215 include '**/*.tokens'
216 }
217 into "${buildDir}/tokens"
Ben Gruver076c6062014-03-15 17:37:29 -0700218 }
219}
220
Ben Gruverdf4e74e2016-02-14 12:16:24 -0800221generateGrammarSource {
222 def tokensDir = file("${buildDir}/tokens/org/jf/smali")
223 inputs.file new File(tokensDir, 'smaliParser.tokens')
224 setArguments(['-lib', tokensDir.path])
225 outputDirectory(file("${buildDir}/generated-src/antlr/main/org/jf/smalidea"))
226}
227generateGrammarSource.dependsOn(extractTokens)
Ben Gruverdf4e74e2016-02-14 12:16:24 -0800228ideaModule.dependsOn(generateGrammarSource)
Ben Gruver076c6062014-03-15 17:37:29 -0700229
Ben Gruver616a0732016-02-27 20:11:39 -0800230task release(dependsOn: 'buildPlugin') {
Ben Gruver29d714f2016-02-26 22:09:08 -0800231}
232
233tasks.getByPath('idea').dependsOn(project(':').getTasksByName('idea', true).findAll({
234 it.project.name != 'smalidea'
235}))