Skip to content

Commit 06e6160

Browse files
committed
Merge branch 'release/0.11'
2 parents ded796d + b17c9ca commit 06e6160

File tree

156 files changed

+13264
-3226
lines changed

Some content is hidden

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

156 files changed

+13264
-3226
lines changed

.idea/codeStyleSettings.xml

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

buildSrc/src/main/groovy/org/stepik/gradle/plugins/clion/CLionPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class CLionPlugin extends BasePlugin {
1010
private static final PRODUCT_NAME = "CLion"
1111
private static final EXTENSION_NAME = "clion"
1212
private static final DEFAULT_REPO =
13-
'http://download.jetbrains.com/cpp/CLion-[version].[archiveType]'
13+
'https://download.jetbrains.com/cpp/CLion-[version].[archiveType]'
1414

1515
CLionPlugin() {
1616
extensionName = EXTENSION_NAME

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

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import java.nio.file.StandardCopyOption
2525
* @author meanmail
2626
*/
2727
class PrepareSandboxTask extends DefaultTask {
28-
private static final Logger LOG = Logging.getLogger(PrepareSandboxTask.class)
28+
private static final Logger logger = Logging.getLogger(PrepareSandboxTask.class)
2929

3030
private ProductPluginExtension extension
3131

@@ -80,12 +80,12 @@ class PrepareSandboxTask extends DefaultTask {
8080
@TaskAction
8181
protected void copy() {
8282
if (pluginJar == null) {
83-
LOG.error("Failed prepare sandbox task: plugin jar is null")
83+
logger.error("Failed prepare sandbox task: plugin jar is null")
8484
return
8585
}
8686

8787
if (destinationDir == null) {
88-
LOG.error("Failed prepare sandbox task: plugins directory is null")
88+
logger.error("Failed prepare sandbox task: plugins directory is null")
8989
return
9090
}
9191
def dependenciesJars = getDependenciesJars(project)
@@ -100,7 +100,7 @@ class PrepareSandboxTask extends DefaultTask {
100100
Files.copy(it, target, StandardCopyOption.REPLACE_EXISTING)
101101
}
102102
} catch (IOException ignored) {
103-
LOG.error("Failed prepare sandbox task: copy from " + dependenciesJars + " to " + libPath)
103+
logger.error("Failed prepare sandbox task: copy from " + dependenciesJars + " to " + libPath)
104104
return
105105
}
106106
disableIdeUpdate()
@@ -145,28 +145,9 @@ class PrepareSandboxTask extends DefaultTask {
145145
return
146146
}
147147

148-
def updatesConfig = new File(optionsDir, "updates.xml")
149-
try {
150-
if (!updatesConfig.exists() && !updatesConfig.createNewFile()) {
151-
return
152-
}
153-
} catch (IOException ignore) {
154-
return
155-
}
156-
157-
def doc = Utils.getXmlDocument(updatesConfig)
158-
159-
if (!doc || !doc.hasRootElement()) {
160-
doc = Utils.createUpdatesXml()
161-
} else {
162-
Utils.repairUpdateXml(doc)
163-
}
164-
165-
try {
166-
Utils.outputXml(doc, updatesConfig)
167-
} catch (IOException ignored) {
168-
LOG.warn("Failed write to " + updatesConfig)
169-
}
148+
Utils.createOrRepairUpdateXml(optionsDir)
149+
Utils.createOrRepairIdeGeneralXml(optionsDir)
150+
Utils.createOrRepairOptionsXml(optionsDir)
170151
}
171152

172153
void setExtension(@NotNull ProductPluginExtension extension) {

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

Lines changed: 100 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.gradle.api.Task
55
import org.gradle.api.file.FileCollection
66
import org.gradle.api.plugins.JavaPluginConvention
77
import org.gradle.api.tasks.SourceSet
8+
import org.gradle.internal.Pair
89
import org.gradle.process.JavaForkOptions
910
import org.jdom2.Attribute
1011
import org.jdom2.Document
@@ -21,22 +22,50 @@ import org.slf4j.Logger
2122
import org.slf4j.LoggerFactory
2223

2324
import java.nio.charset.Charset
24-
import java.nio.file.*
25+
import java.nio.file.DirectoryNotEmptyException
26+
import java.nio.file.FileVisitResult
27+
import java.nio.file.FileVisitor
28+
import java.nio.file.Files
29+
import java.nio.file.Path
2530
import java.nio.file.attribute.BasicFileAttributes
2631

2732
/**
2833
* @author meanmail
2934
*/
3035
class Utils {
3136
private static final Logger logger = LoggerFactory.getLogger(Utils)
32-
private static final String APPLICATION = "application"
33-
private static final String COMPONENT = "component"
34-
private static final String NAME = "name"
35-
private static final String UPDATES_CONFIGURABLE = "UpdatesConfigurable"
36-
private static final String OPTION = "option"
37-
private static final String CHECK_NEEDED = "CHECK_NEEDED"
38-
private static final String VALUE = "value"
39-
private static final String FALSE = "false"
37+
static final String APPLICATION = "application"
38+
static final String COMPONENT = "component"
39+
static final String COMPONENT_NAME = "componentName"
40+
static final String NAME = "name"
41+
static final String OPTIONS = "options"
42+
static final String OPTION_TAG = "optionTag"
43+
static final String VALUE = "value"
44+
static final UPDATE_XML = [
45+
filename : "updates.xml",
46+
componentName: "UpdatesConfigurable",
47+
optionTag : "option",
48+
options : [
49+
Pair.of("CHECK_NEEDED", "false")
50+
]
51+
]
52+
static final IDE_GENERAL_XML = [
53+
filename : "ide.general.xml",
54+
componentName: "GeneralSettings",
55+
optionTag : "option",
56+
options : [
57+
Pair.of("confirmExit", "false"),
58+
Pair.of("showTipsOnStartup", "false")
59+
]
60+
]
61+
static final OPTIONS_XML = [
62+
filename : "options.xml",
63+
componentName: "PropertiesComponent",
64+
optionTag : "property",
65+
options : [
66+
Pair.of("toolwindow.stripes.buttons.info.shown", "true")
67+
]
68+
]
4069

4170
@Nullable
4271
static Document getXmlDocument(@NotNull File file) {
@@ -48,16 +77,6 @@ class Utils {
4877
}
4978
}
5079

51-
@Nullable
52-
static Document getXmlDocument(@NotNull InputStream input) {
53-
try {
54-
def builder = new SAXBuilder()
55-
return builder.build(input)
56-
} catch (JDOMException | IOException ignored) {
57-
return null
58-
}
59-
}
60-
6180
@NotNull
6281
static SourceSet mainSourceSet(@NotNull Project project) {
6382
def javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class)
@@ -119,7 +138,7 @@ class Utils {
119138
node.setAttribute(name, value)
120139
}
121140

122-
static Document createUpdatesXml() {
141+
static Document createXml(Map map) {
123142
def doc = new Document()
124143

125144
def applicationNode = new Element(APPLICATION)
@@ -128,17 +147,19 @@ class Utils {
128147
def component = new Element(COMPONENT)
129148
applicationNode.addContent(component)
130149

131-
setAttributeValue(component, NAME, UPDATES_CONFIGURABLE)
150+
setAttributeValue(component, NAME, map[COMPONENT_NAME] as String)
132151

133-
def option = new Element(OPTION)
134-
component.addContent(option)
135-
setAttributeValue(option, NAME, CHECK_NEEDED)
136-
setAttributeValue(option, VALUE, FALSE)
152+
map[OPTIONS].each { Pair option ->
153+
def optionTag = new Element(map[OPTION_TAG] as String)
154+
component.addContent(optionTag)
155+
setAttributeValue(optionTag, NAME, option.getLeft() as String)
156+
setAttributeValue(optionTag, VALUE, option.getRight() as String)
157+
}
137158

138159
return doc
139160
}
140161

141-
static void repairUpdateXml(Document doc) {
162+
static void repairXml(Document doc, Map map) {
142163
def applicationNode
143164

144165
if (!doc.hasRootElement()) {
@@ -152,9 +173,10 @@ class Utils {
152173
applicationNode.setName(APPLICATION)
153174
}
154175

176+
String componentName = map[COMPONENT_NAME]
155177
def component = applicationNode.getChildren(COMPONENT).find {
156178
Attribute attr = it.getAttribute(NAME)
157-
return attr != null && UPDATES_CONFIGURABLE == attr.getValue()
179+
return attr != null && componentName == attr.getValue()
158180
}
159181

160182
if (component == null) {
@@ -164,22 +186,24 @@ class Utils {
164186

165187
def name = component.getAttribute(NAME)
166188

167-
if (name == null || UPDATES_CONFIGURABLE == name.getValue()) {
168-
setAttributeValue(component, NAME, UPDATES_CONFIGURABLE)
189+
if (name == null || componentName == name.getValue()) {
190+
setAttributeValue(component, NAME, componentName)
169191
}
170192

171-
def option = component.getChildren(OPTION).find {
172-
Attribute attr = it.getAttribute(NAME)
173-
return attr != null && CHECK_NEEDED == attr.getValue()
174-
}
193+
map[OPTIONS].each { Pair option ->
194+
def optionTag = component.getChildren(map[OPTION_TAG] as String).find {
195+
Attribute attr = it.getAttribute(NAME)
196+
return attr != null && option.getLeft() == attr.getValue()
197+
}
175198

176-
if (option == null) {
177-
option = new Element(OPTION)
178-
component.addContent(option)
179-
setAttributeValue(option, NAME, CHECK_NEEDED)
180-
}
199+
if (optionTag == null) {
200+
optionTag = new Element(map[OPTION_TAG] as String)
201+
component.addContent(optionTag)
202+
setAttributeValue(optionTag, NAME, option.getLeft() as String)
203+
}
181204

182-
setAttributeValue(option, VALUE, FALSE)
205+
setAttributeValue(optionTag, VALUE, option.getRight() as String)
206+
}
183207
}
184208

185209
@Nullable
@@ -379,4 +403,41 @@ class Utils {
379403
return "tar.gz"
380404
}
381405
}
406+
407+
static void createOrRepairXml(@NotNull File optionsDir, Map map) {
408+
def updatesConfig = new File(optionsDir, map["filename"] as String)
409+
try {
410+
if (!updatesConfig.exists() && !updatesConfig.createNewFile()) {
411+
return
412+
}
413+
} catch (IOException ignore) {
414+
return
415+
}
416+
417+
def doc = getXmlDocument(updatesConfig)
418+
419+
if (!doc || !doc.hasRootElement()) {
420+
doc = createXml(map)
421+
} else {
422+
repairXml(doc, map)
423+
}
424+
425+
try {
426+
outputXml(doc, updatesConfig)
427+
} catch (IOException ignored) {
428+
logger.warn("Failed write to " + updatesConfig)
429+
}
430+
}
431+
432+
static void createOrRepairUpdateXml(@NotNull File file) {
433+
createOrRepairXml(file, UPDATE_XML)
434+
}
435+
436+
static void createOrRepairIdeGeneralXml(@NotNull File file) {
437+
createOrRepairXml(file, IDE_GENERAL_XML)
438+
}
439+
440+
static void createOrRepairOptionsXml(File file) {
441+
createOrRepairXml(file, OPTIONS_XML)
442+
}
382443
}

0 commit comments

Comments
 (0)