Ben Gruver | 076c606 | 2014-03-15 17:37:29 -0700 | [diff] [blame] | 1 | /* |
| 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 Gruver | df4e74e | 2016-02-14 12:16:24 -0800 | [diff] [blame] | 32 | buildscript { |
| 33 | repositories { |
| 34 | maven { |
| 35 | url "https://plugins.gradle.org/m2/" |
| 36 | } |
Ben Gruver | 458398f | 2016-10-02 18:10:49 -0700 | [diff] [blame] | 37 | maven { |
| 38 | url 'http://dl.bintray.com/jetbrains/intellij-plugin-service' |
| 39 | } |
| 40 | |
Ben Gruver | df4e74e | 2016-02-14 12:16:24 -0800 | [diff] [blame] | 41 | } |
| 42 | dependencies { |
Ben Gruver | 458398f | 2016-10-02 18:10:49 -0700 | [diff] [blame] | 43 | classpath "gradle.plugin.org.jetbrains:gradle-intellij-plugin:0.1.10" |
Ben Gruver | df4e74e | 2016-02-14 12:16:24 -0800 | [diff] [blame] | 44 | } |
Ben Gruver | 076c606 | 2014-03-15 17:37:29 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Ben Gruver | df4e74e | 2016-02-14 12:16:24 -0800 | [diff] [blame] | 47 | apply plugin: 'java' |
| 48 | apply plugin: 'idea' |
| 49 | apply plugin: 'antlr' |
Ben Gruver | 076c606 | 2014-03-15 17:37:29 -0700 | [diff] [blame] | 50 | |
Ben Gruver | 458398f | 2016-10-02 18:10:49 -0700 | [diff] [blame] | 51 | |
Ben Gruver | 76d69c7 | 2017-03-31 16:25:08 -0700 | [diff] [blame] | 52 | version = '0.05' |
Ben Gruver | df4e74e | 2016-02-14 12:16:24 -0800 | [diff] [blame] | 53 | |
| 54 | if (!('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 | |
| 79 | if (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 Gruver | 3bdedd6 | 2016-02-27 12:50:54 -0800 | [diff] [blame] | 92 | def sandboxDir = "${buildDir}/sandbox" |
| 93 | |
Ben Gruver | df4e74e | 2016-02-14 12:16:24 -0800 | [diff] [blame] | 94 | if (!('idea' in gradle.startParameter.taskNames)) { |
Ben Gruver | 458398f | 2016-10-02 18:10:49 -0700 | [diff] [blame] | 95 | |
Ben Gruver | df4e74e | 2016-02-14 12:16:24 -0800 | [diff] [blame] | 96 | apply plugin: 'org.jetbrains.intellij' |
| 97 | |
| 98 | intellij { |
Ben Gruver | fa13b13 | 2017-03-21 21:59:02 -0700 | [diff] [blame] | 99 | version 'IC-2016.3.5' |
Ben Gruver | df4e74e | 2016-02-14 12:16:24 -0800 | [diff] [blame] | 100 | pluginName 'smalidea' |
| 101 | |
Ben Gruver | 81e0309 | 2016-02-27 20:06:20 -0800 | [diff] [blame] | 102 | updateSinceUntilBuild false |
| 103 | |
Ben Gruver | 3bdedd6 | 2016-02-27 12:50:54 -0800 | [diff] [blame] | 104 | sandboxDirectory sandboxDir |
Ben Gruver | df4e74e | 2016-02-14 12:16:24 -0800 | [diff] [blame] | 105 | } |
Ben Gruver | 92f8ec5 | 2016-02-14 12:19:34 -0800 | [diff] [blame] | 106 | |
| 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 Gruver | 458398f | 2016-10-02 18:10:49 -0700 | [diff] [blame] | 112 | println "IDEA Plugin jdk: ${intellij.ideaDependency.classes}" |
| 113 | println "sources: ${intellij.ideaDependency.getSources()}" |
Ben Gruver | 92f8ec5 | 2016-02-14 12:19:34 -0800 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | } |
Ben Gruver | 1df3869 | 2016-02-15 13:13:31 -0800 | [diff] [blame] | 117 | |
| 118 | dependencies { |
| 119 | compile files("${System.properties['java.home']}/../lib/tools.jar") |
| 120 | } |
Ben Gruver | 29d714f | 2016-02-26 22:09:08 -0800 | [diff] [blame] | 121 | |
Ben Gruver | 458398f | 2016-10-02 18:10:49 -0700 | [diff] [blame] | 122 | } else { |
Ben Gruver | 29d714f | 2016-02-26 22:09:08 -0800 | [diff] [blame] | 123 | 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 Gruver | 3bdedd6 | 2016-02-27 12:50:54 -0800 | [diff] [blame] | 144 | <option name="VM_PARAMETERS" value="-Didea.system.path=${sandboxDir}/config -Didea.system.path=${sandboxDir}/system-test -Didea.load.plugins.id=org.jf.smalidea" /> |
Ben Gruver | 29d714f | 2016-02-26 22:09:08 -0800 | [diff] [blame] | 145 | <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 Gruver | df4e74e | 2016-02-14 12:16:24 -0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | repositories { |
| 197 | mavenLocal() |
| 198 | mavenCentral() |
| 199 | } |
Ben Gruver | 076c606 | 2014-03-15 17:37:29 -0700 | [diff] [blame] | 200 | |
| 201 | dependencies { |
Ben Gruver | 29d714f | 2016-02-26 22:09:08 -0800 | [diff] [blame] | 202 | compile project(':smali') |
| 203 | compile depends.antlr_runtime |
| 204 | compile depends.gson |
Ben Gruver | 076c606 | 2014-03-15 17:37:29 -0700 | [diff] [blame] | 205 | |
Ben Gruver | 29d714f | 2016-02-26 22:09:08 -0800 | [diff] [blame] | 206 | antlr depends.antlr |
Ben Gruver | 076c606 | 2014-03-15 17:37:29 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Ben Gruver | 29d714f | 2016-02-26 22:09:08 -0800 | [diff] [blame] | 209 | task extractTokens(type: org.gradle.api.tasks.Copy, dependsOn: ':smali:build') { |
Ben Gruver | 458398f | 2016-10-02 18:10:49 -0700 | [diff] [blame] | 210 | project.afterEvaluate { |
| 211 | def allArtifacts = configurations.default.resolvedConfiguration.resolvedArtifacts |
| 212 | def smaliArtifact = allArtifacts.find { it.moduleVersion.id.name.equals('smali') } |
Ben Gruver | df4e74e | 2016-02-14 12:16:24 -0800 | [diff] [blame] | 213 | |
Ben Gruver | 458398f | 2016-10-02 18:10:49 -0700 | [diff] [blame] | 214 | from(zipTree(smaliArtifact.file)) { |
| 215 | include '**/*.tokens' |
| 216 | } |
| 217 | into "${buildDir}/tokens" |
Ben Gruver | 076c606 | 2014-03-15 17:37:29 -0700 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | |
Ben Gruver | df4e74e | 2016-02-14 12:16:24 -0800 | [diff] [blame] | 221 | generateGrammarSource { |
| 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 | } |
| 227 | generateGrammarSource.dependsOn(extractTokens) |
Ben Gruver | df4e74e | 2016-02-14 12:16:24 -0800 | [diff] [blame] | 228 | ideaModule.dependsOn(generateGrammarSource) |
Ben Gruver | 076c606 | 2014-03-15 17:37:29 -0700 | [diff] [blame] | 229 | |
Ben Gruver | 616a073 | 2016-02-27 20:11:39 -0800 | [diff] [blame] | 230 | task release(dependsOn: 'buildPlugin') { |
Ben Gruver | 29d714f | 2016-02-26 22:09:08 -0800 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | tasks.getByPath('idea').dependsOn(project(':').getTasksByName('idea', true).findAll({ |
| 234 | it.project.name != 'smalidea' |
| 235 | })) |