Skip to content

Commit 52581b1

Browse files
committed
Merge branch 'release/4'
2 parents ddd04d7 + 23fb5e3 commit 52581b1

24 files changed

+456
-305
lines changed

.idea/codeStyleSettings.xml

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

buildSrc/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ plugins {
33
}
44

55
repositories {
6+
maven { url 'http://dl.bintray.com/jetbrains/intellij-plugin-service' }
67
mavenCentral()
78
}
89

910
dependencies {
1011
compile gradleApi()
1112
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'
1215
compile 'org.jdom:jdom2:2.0.6'
1316
compile group: 'org.rauschig', name: 'jarchivelib', version: '0.7.1'
1417

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ abstract class BasePlugin implements Plugin<Project> {
4949
plugin = this
5050
instrumentCode = extensionInstrumentCode
5151
repositoryType = this.repositoryType
52+
publish = new ProductPluginExtensionPublish()
5253
}
5354

5455
configureTasks(project, extension)
@@ -62,6 +63,7 @@ abstract class BasePlugin implements Plugin<Project> {
6263
configurePrepareSandboxTask(project, extension)
6364
configureRunTask(project, extension)
6465
configureBuildPluginTask(project)
66+
configurePublishPluginTask(project, extension)
6567
configureProcessResources(project)
6668
project.afterEvaluate(new Action<Project>() {
6769
@Override
@@ -151,6 +153,17 @@ abstract class BasePlugin implements Plugin<Project> {
151153
}
152154
}
153155

156+
private void configurePublishPluginTask(@NotNull Project project, @NotNull ProductPluginExtension ext) {
157+
logger.info("Configuring publishing {} plugin task", productName)
158+
project.tasks.create("publish$productName", PublishTask).with {
159+
group = tasksGroupName
160+
description = "Publish plugin distribution on plugins.jetbrains.com."
161+
extension = ext
162+
plugin = this
163+
dependsOn(buildPluginTaskName)
164+
}
165+
}
166+
154167
private void configureProcessResources(@NotNull Project project) {
155168
logger.info("Configuring {} resources task", productName)
156169

@@ -240,6 +253,10 @@ abstract class BasePlugin implements Plugin<Project> {
240253
return prepareTestSandboxTaskName
241254
}
242255

256+
String getBuildPluginTaskName() {
257+
return buildPluginTaskName
258+
}
259+
243260
String getProductType() {
244261
return productType
245262
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class ProductPluginExtension {
3434
private Project project
3535
private BasePlugin plugin
3636
boolean instrumentCode
37+
ProductPluginExtensionPublish publish
3738

3839
RepositoryType repositoryType
3940

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.stepik.gradle.plugins.jetbrains
2+
3+
class ProductPluginExtensionPublish {
4+
String username
5+
String password
6+
String[] channels
7+
8+
def username(String username) {
9+
this.username = username
10+
}
11+
12+
def password(String password) {
13+
this.password = password
14+
}
15+
16+
def setChannel(String channel) {
17+
this.channels = [channel]
18+
}
19+
20+
def channel(String channel) {
21+
channels(channel)
22+
}
23+
24+
def channels(String... channels) {
25+
this.channels = channels
26+
}
27+
28+
def setChannels(String... channels) {
29+
this.channels = channels
30+
}
31+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package org.stepik.gradle.plugins.jetbrains
2+
3+
import com.intellij.structure.plugin.PluginManager
4+
import org.gradle.api.internal.ConventionTask
5+
import org.gradle.api.tasks.Input
6+
import org.gradle.api.tasks.InputFile
7+
import org.gradle.api.tasks.Optional
8+
import org.gradle.api.tasks.TaskAction
9+
import org.gradle.api.tasks.TaskExecutionException
10+
import org.gradle.api.tasks.bundling.Zip
11+
import org.gradle.util.CollectionUtils
12+
import org.jetbrains.intellij.pluginRepository.PluginRepositoryInstance
13+
import org.slf4j.Logger
14+
import org.slf4j.LoggerFactory
15+
16+
class PublishTask extends ConventionTask {
17+
private static final Logger logger = LoggerFactory.getLogger(BasePlugin)
18+
19+
private ProductPluginExtension extension
20+
private BasePlugin plugin
21+
private String host = "http://plugins.jetbrains.com"
22+
23+
PublishTask() {
24+
enabled = !project.gradle.startParameter.offline
25+
}
26+
27+
void setExtension(ProductPluginExtension extension) {
28+
this.extension = extension
29+
}
30+
31+
void setPlugin(BasePlugin plugin) {
32+
this.plugin = plugin
33+
}
34+
35+
@Input
36+
String getHost() {
37+
host
38+
}
39+
40+
@InputFile
41+
File getDistributionFile() {
42+
def buildPluginTask = project.tasks.findByName(plugin.buildPluginTaskName) as Zip
43+
def distributionFile = buildPluginTask?.archivePath
44+
distributionFile?.exists() ? distributionFile : null
45+
}
46+
47+
void setDistributionFile(Object distributionFile) {
48+
this.distributionFile = distributionFile
49+
}
50+
51+
@Input
52+
String getUsername() {
53+
Utils.toString(extension.publish.username)
54+
}
55+
56+
@Input
57+
String getPassword() {
58+
Utils.toString(extension.publish.password)
59+
}
60+
61+
@Input
62+
@Optional
63+
String[] getChannels() {
64+
CollectionUtils.stringize(extension.publish.channels.collect {
65+
it instanceof Closure ? (it as Closure).call() : it
66+
}.flatten())
67+
}
68+
69+
@SuppressWarnings("GroovyUnusedDeclaration")
70+
@TaskAction
71+
protected void publishPlugin() {
72+
def channels = getChannels()
73+
if (!channels || channels.length == 0) {
74+
channels = ['default']
75+
}
76+
77+
def host = getHost()
78+
def distributionFile = getDistributionFile()
79+
String pluginId = PluginManager.instance.createPlugin(distributionFile).plugin.pluginId
80+
for (String channel : channels) {
81+
logger.info("Uploading plugin ${pluginId} from $distributionFile.absolutePath to $host, channel: $channel")
82+
try {
83+
def repoClient = new PluginRepositoryInstance(host, getUsername(), getPassword())
84+
repoClient.uploadPlugin(pluginId, distributionFile, channel && 'default' != channel ? channel : '')
85+
logger.info("Uploaded successfully")
86+
} catch (exception) {
87+
throw new TaskExecutionException(this, new RuntimeException("Failed to upload plugin", exception))
88+
}
89+
}
90+
}
91+
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ class Utils {
240240
}
241241

242242
@NotNull
243-
static File getArchivePath(@NotNull Project project,
243+
static File getArchivePath(
244+
@NotNull Project project,
244245
@NotNull BasePlugin plugin,
245246
@NotNull ProductPluginExtension extension) {
246247
def defaultIdePath = getDefaultIdePath(
@@ -440,4 +441,9 @@ class Utils {
440441
static void createOrRepairOptionsXml(File file) {
441442
createOrRepairXml(file, OPTIONS_XML)
442443
}
444+
445+
static String toString(input) {
446+
input = input instanceof Closure ? (input as Closure).call() : input
447+
return input?.toString()
448+
}
443449
}

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
### General options ###
33
javaVersion=1.8
44
gradleVersion=3.5
5-
pluginVersion=3.1
5+
pluginVersion=4
66
# if set the 'idePath' then the version ignoring
77
# if 'sandboxDir' not set then use default sandbox directory (build/${product}-sandbox)
88
# if 'ideVersion' not set then use LATEST-EAP-SNAPSHOT
@@ -12,7 +12,7 @@ ideaVersion=163.7743.44
1212
#ideaSandboxDir=build/idea-sandbox/
1313
#ideaPath=/path/to/idea
1414
### PyCharm ###
15-
pyCharmVersion=163.8233.8
15+
pyCharmVersion=2016.3.3
1616
#pyCharmSandboxDir=build/pycharm-sandbox/
1717
#pyCharmPath=/path/to/pycharm
1818
### CLion ###

0 commit comments

Comments
 (0)