Skip to content

Commit 8884567

Browse files
committed
Merge branch 'release/5'
2 parents 52581b1 + c7c3424 commit 8884567

File tree

101 files changed

+2424
-1032
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+2424
-1032
lines changed

build.gradle

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
buildscript {
2-
ext.kotlin_version = '1.1.2-2'
2+
ext.kotlin_version = '1.1.3-2'
33

44
repositories {
55
mavenCentral()
@@ -14,6 +14,24 @@ subprojects {
1414
apply plugin: "java"
1515
apply plugin: "kotlin"
1616

17+
def javaVersion = project.getProperties().get('javaVersion') ?: JavaVersion.current()
18+
19+
compileKotlin {
20+
kotlinOptions{
21+
jvmTarget = javaVersion
22+
languageVersion = "1.1"
23+
apiVersion = "1.1"
24+
}
25+
}
26+
27+
compileTestKotlin {
28+
kotlinOptions {
29+
jvmTarget = javaVersion
30+
languageVersion = "1.1"
31+
apiVersion = "1.1"
32+
}
33+
}
34+
1735
repositories {
1836
mavenCentral()
1937
}
@@ -24,17 +42,18 @@ subprojects {
2442
testCompile(group: 'junit', name: 'junit', version: '4+') {
2543
exclude group: 'org.hamcrest'
2644
}
45+
46+
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
2747
}
2848

2949
apply plugin: 'idea'
3050

3151
tasks.withType(JavaCompile) {
32-
def javaVersion = project.getProperties().get('javaVersion') ?: JavaVersion.current()
3352
sourceCompatibility = javaVersion
3453
targetCompatibility = javaVersion
3554
}
3655
}
3756

3857
task wrapper(type: Wrapper) {
39-
gradleVersion = project.getProperties().get('gradleVersion') ?: gradle.gradleVersion
58+
gradleVersion = (project.getProperties().get('gradleVersion') ?: gradle.gradleVersion) as String
4059
}

buildSrc/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ repositories {
1010
dependencies {
1111
compile gradleApi()
1212
compile 'org.jetbrains:annotations:13.0'
13-
compile 'org.jetbrains.intellij:plugin-repository-rest-client:0.3.21'
14-
compile 'org.jetbrains.intellij.plugins:intellij-plugin-structure:2.2'
13+
compile 'org.jetbrains.intellij:plugin-repository-rest-client:0.4.26'
14+
compile 'org.jetbrains.intellij.plugins:intellij-plugin-structure:2.3'
1515
compile 'org.jdom:jdom2:2.0.6'
1616
compile group: 'org.rauschig', name: 'jarchivelib', version: '0.7.1'
1717

buildSrc/src/main/groovy/org/stepik/gradle/plugins/jetbrains/BasePlugin.groovy

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ package org.stepik.gradle.plugins.jetbrains
33
import org.gradle.api.Action
44
import org.gradle.api.Plugin
55
import org.gradle.api.Project
6-
import org.gradle.api.Task
76
import org.gradle.api.file.DuplicatesStrategy
87
import org.gradle.api.plugins.JavaPlugin
8+
import org.gradle.api.tasks.SourceSet
99
import org.gradle.api.tasks.bundling.Zip
10-
import org.gradle.api.tasks.compile.AbstractCompile
1110
import org.gradle.api.tasks.testing.Test
1211
import org.gradle.internal.jvm.Jvm
1312
import org.gradle.language.jvm.tasks.ProcessResources
@@ -107,7 +106,7 @@ abstract class BasePlugin implements Plugin<Project> {
107106

108107
def toolsJar = Jvm.current().getToolsJar()
109108
if (toolsJar) {
110-
project.getDependencies().add(JavaPlugin.RUNTIME_CONFIGURATION_NAME, project.files(toolsJar))
109+
project.getDependencies().add(JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME, project.files(toolsJar))
111110
}
112111
}
113112

@@ -178,18 +177,20 @@ abstract class BasePlugin implements Plugin<Project> {
178177

179178
private void configureInstrumentation(@NotNull Project project, @NotNull ProductPluginExtension extension) {
180179
logger.info("Configuring IntelliJ compile tasks")
181-
def abstractCompileDependencies = { String taskName ->
182-
project.tasks.findByName(taskName).collect {
183-
it.taskDependencies.getDependencies(it).findAll { it instanceof AbstractCompile }
184-
}.flatten() as Collection<AbstractCompile>
185-
}
186-
abstractCompileDependencies(JavaPlugin.CLASSES_TASK_NAME).each {
187-
it.inputs.property("intellijIdeaDependency", extension.dependency.toString())
188-
it.doLast(new InstrumentCodeAction(false, extensionName) as Action<? super Task>)
189-
}
190-
abstractCompileDependencies(JavaPlugin.TEST_CLASSES_TASK_NAME).each {
191-
it.inputs.property("intellijIdeaDependency", extension.dependency.toString())
192-
it.doLast(new InstrumentCodeAction(true, extensionName) as Action<? super Task>)
180+
def instrumentCode = { extension.instrumentCode && extension.type != 'RS' }
181+
project.sourceSets.all { SourceSet sourceSet ->
182+
def instrumentTask = project.tasks.create(sourceSet.getTaskName("${productName}Instrument", 'code'), InstrumentCodeTask)
183+
instrumentTask.sourceSet = sourceSet
184+
instrumentTask.with {
185+
dependsOn sourceSet.classesTaskName
186+
onlyIf instrumentCode
187+
188+
conventionMapping("ideaDependency", { extension.dependency })
189+
conventionMapping('outputDir', { new File(sourceSet.output.classesDirs[0].getParent(), "${sourceSet.name}") })
190+
}
191+
192+
// Ensure that our task is invoked when the source set is built
193+
sourceSet.compiledBy(instrumentTask)
193194
}
194195
}
195196

buildSrc/src/main/groovy/org/stepik/gradle/plugins/jetbrains/BaseRunTask.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.stepik.gradle.plugins.jetbrains
22

33
import org.gradle.api.Project
4+
import org.gradle.api.tasks.Input
45
import org.gradle.api.tasks.InputDirectory
56
import org.gradle.api.tasks.Internal
67
import org.gradle.api.tasks.JavaExec
@@ -80,7 +81,7 @@ abstract class BaseRunTask extends JavaExec {
8081
}
8182
}
8283

83-
@Internal
84+
@Input
8485
protected abstract String getPlatformPrefix()
8586

8687
private void configureSystemProperties() {
@@ -116,6 +117,7 @@ abstract class BaseRunTask extends JavaExec {
116117
this.plugin = plugin
117118
}
118119

120+
@Internal
119121
ProductPluginExtension getExtension() {
120122
return extension
121123
}

buildSrc/src/main/groovy/org/stepik/gradle/plugins/jetbrains/InstrumentCodeAction.groovy

Lines changed: 0 additions & 94 deletions
This file was deleted.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package org.stepik.gradle.plugins.jetbrains
2+
3+
import org.apache.tools.ant.BuildException
4+
import org.gradle.api.file.ConfigurableFileCollection
5+
import org.gradle.api.file.FileCollection
6+
import org.gradle.api.internal.ConventionTask
7+
import org.gradle.api.tasks.Input
8+
import org.gradle.api.tasks.InputFiles
9+
import org.gradle.api.tasks.Internal
10+
import org.gradle.api.tasks.OutputDirectory
11+
import org.gradle.api.tasks.SourceSet
12+
import org.gradle.api.tasks.TaskAction
13+
import org.jetbrains.annotations.NotNull
14+
import org.stepik.gradle.plugins.jetbrains.dependency.ProductDependency
15+
16+
class InstrumentCodeTask extends ConventionTask {
17+
private static final String FILTER_ANNOTATION_REGEXP_CLASS = 'com.intellij.ant.ClassFilterAnnotationRegexp'
18+
private static final LOADER_REF = "java2.loader"
19+
20+
@Internal
21+
SourceSet sourceSet
22+
23+
@Input
24+
ProductDependency ideaDependency
25+
26+
@OutputDirectory
27+
File outputDir
28+
29+
@InputFiles
30+
FileCollection getSourceDirs() {
31+
return project.files(sourceSet.allSource.srcDirs.findAll { !sourceSet.resources.contains(it) && it.exists() })
32+
}
33+
34+
@SuppressWarnings("GroovyUnusedDeclaration")
35+
@TaskAction
36+
void instrumentClasses() {
37+
def outputDir = getOutputDir()
38+
39+
def ideaDependency = getIdeaDependency()
40+
def classpath = project.files(
41+
"$ideaDependency.classes/lib/javac2.jar",
42+
"$ideaDependency.classes/lib/jdom.jar",
43+
"$ideaDependency.classes/lib/asm-all.jar",
44+
"$ideaDependency.classes/lib/jgoodies-forms.jar")
45+
46+
ant.taskdef(name: 'instrumentIdeaExtensions',
47+
classpath: classpath.asPath,
48+
loaderref: LOADER_REF,
49+
classname: 'com.intellij.ant.InstrumentIdeaExtensions')
50+
51+
logger.info("Compiling forms and instrumenting code with nullability preconditions")
52+
boolean instrumentNotNull = prepareNotNullInstrumenting(classpath)
53+
instrumentCode(getSourceDirs(), outputDir, instrumentNotNull)
54+
}
55+
56+
private boolean prepareNotNullInstrumenting(@NotNull ConfigurableFileCollection classpath) {
57+
try {
58+
ant.typedef(name: 'skip', classpath: classpath.asPath, loaderref: LOADER_REF,
59+
classname: FILTER_ANNOTATION_REGEXP_CLASS)
60+
} catch (BuildException e) {
61+
def cause = e.getCause()
62+
if (cause instanceof ClassNotFoundException && FILTER_ANNOTATION_REGEXP_CLASS == cause.getMessage()) {
63+
logger.info("Old version of Javac2 is used, " +
64+
"instrumenting code with nullability will be skipped. Use IDEA >14 SDK (139.*) to fix this")
65+
return false
66+
} else {
67+
throw e
68+
}
69+
}
70+
return true
71+
}
72+
73+
private void instrumentCode(@NotNull FileCollection srcDirs, @NotNull File outputDir, boolean instrumentNotNull) {
74+
def headlessOldValue = System.setProperty('java.awt.headless', 'true')
75+
ant.instrumentIdeaExtensions(srcdir: srcDirs.asPath,
76+
destdir: outputDir, classpath: sourceSet.compileClasspath.asPath,
77+
includeantruntime: false, instrumentNotNull: instrumentNotNull) {
78+
if (instrumentNotNull) {
79+
ant.skip(pattern: 'kotlin/Metadata')
80+
}
81+
}
82+
if (headlessOldValue != null) {
83+
System.setProperty('java.awt.headless', headlessOldValue)
84+
} else {
85+
System.clearProperty('java.awt.headless')
86+
}
87+
}
88+
}

buildSrc/src/main/groovy/org/stepik/gradle/plugins/jetbrains/PatchPluginXmlTask.groovy

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ package org.stepik.gradle.plugins.jetbrains
33
import org.gradle.api.file.FileCollection
44
import org.gradle.api.internal.ConventionTask
55
import org.gradle.api.tasks.*
6+
import org.jdom2.CDATA
7+
import org.jdom2.Content
68
import org.jdom2.Document
79
import org.jdom2.Element
10+
import org.jdom2.Text
811
import org.jetbrains.annotations.NotNull
912
import org.jetbrains.annotations.Nullable
1013

@@ -82,8 +85,8 @@ class PatchPluginXmlTask extends ConventionTask {
8285
}
8386

8487
patchSinceUntilBuild(pluginXml, sinceBuild, untilBuild)
85-
patchElement(pluginXml, "description", pluginDescription)
86-
patchElement(pluginXml, "change-notes", changeNotes)
88+
patchElement(pluginXml, "description", new CDATA(pluginDescription))
89+
patchElement(pluginXml, "change-notes", new CDATA(changeNotes))
8790
patchElement(pluginXml, "version", version)
8891

8992
def destinationFile = new File(destinationDir, it.name)
@@ -111,6 +114,10 @@ class PatchPluginXmlTask extends ConventionTask {
111114
}
112115

113116
static void patchElement(@NotNull Document pluginXml, @NotNull String name, @Nullable String value) {
117+
patchElement(pluginXml, name, new Text(value))
118+
}
119+
120+
static void patchElement(@NotNull Document pluginXml, @NotNull String name, @Nullable Content value) {
114121
if (value != null) {
115122
def result = pluginXml.getRootElement().getChild(name)
116123

@@ -119,7 +126,7 @@ class PatchPluginXmlTask extends ConventionTask {
119126
pluginXml.getRootElement().addContent(result)
120127
}
121128

122-
result.text = value
129+
result.setContent(value)
123130
}
124131
}
125132

buildSrc/src/main/groovy/org/stepik/gradle/plugins/jetbrains/PrepareSandboxTask.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class PrepareSandboxTask extends DefaultTask {
5555
return pluginName != null ? FileUtils.toSafeFileName(pluginName) : null
5656
}
5757

58-
@Input
58+
@OutputDirectory
5959
@Nullable
6060
File getConfigDirectory() {
6161
if (extension == null) {

buildSrc/src/main/groovy/org/stepik/gradle/plugins/jetbrains/ProductPluginExtension.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ class ProductPluginExtension {
246246
this.plugin = plugin
247247
}
248248

249+
BasePlugin getPlugin() {
250+
return plugin
251+
}
252+
249253
@Input
250254
@NotNull
251255
RepositoryType getRepositoryType() {

0 commit comments

Comments
 (0)