aboutsummaryrefslogtreecommitdiff
path: root/buildSrc/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'buildSrc/src/main')
-rw-r--r--buildSrc/src/main/groovy/org/jetbrains/CrossPlatformExec.groovy84
-rw-r--r--buildSrc/src/main/kotlin/org/jetbrains/BintrayPublishing.kt6
-rw-r--r--buildSrc/src/main/kotlin/org/jetbrains/CrossPlatformExec.kt67
-rw-r--r--buildSrc/src/main/kotlin/org/jetbrains/DistMavenPublishing.kt10
4 files changed, 73 insertions, 94 deletions
diff --git a/buildSrc/src/main/groovy/org/jetbrains/CrossPlatformExec.groovy b/buildSrc/src/main/groovy/org/jetbrains/CrossPlatformExec.groovy
deleted file mode 100644
index d3973a8a..00000000
--- a/buildSrc/src/main/groovy/org/jetbrains/CrossPlatformExec.groovy
+++ /dev/null
@@ -1,84 +0,0 @@
-package org.jetbrains
-
-import org.gradle.api.tasks.AbstractExecTask
-import org.gradle.api.tasks.TaskAction
-import org.gradle.internal.os.OperatingSystem
-
-import java.nio.file.Files
-import java.nio.file.Path
-import java.nio.file.Paths
-
-class CrossPlatformExec extends AbstractExecTask {
- private static final def windowsExtensions = ['bat', 'cmd', 'exe'];
- private static final def unixExtensions = [null, 'sh'];
-
- private boolean windows;
-
- public CrossPlatformExec() {
- super(CrossPlatformExec.class);
- windows = OperatingSystem.current().windows;
- }
-
- @Override
- @TaskAction
- protected void exec() {
- List<String> commandLine = this.getCommandLine();
-
- if (!commandLine.isEmpty()) {
- commandLine[0] = findCommand(commandLine[0], windows);
- }
-
- if (windows) {
- if (!commandLine.isEmpty() && commandLine[0]) {
- commandLine
- }
- commandLine.add(0, '/c');
- commandLine.add(0, 'cmd');
- }
-
- this.setCommandLine(commandLine);
-
- super.exec();
- }
-
- private static String findCommand(String command, boolean windows) {
- command = normalizeCommandPaths(command);
- def extensions = windows ? windowsExtensions : unixExtensions;
-
- return extensions.findResult(command) { extension ->
- Path commandFile
- if (extension) {
- commandFile = Paths.get(command + '.' + extension);
- } else {
- commandFile = Paths.get(command);
- }
-
- return resolveCommandFromFile(commandFile, windows);
- };
- }
-
- private static String resolveCommandFromFile(Path commandFile, boolean windows) {
- if (!Files.isExecutable(commandFile)) {
- return null;
- }
-
- return commandFile.toAbsolutePath().normalize();
- }
-
- private static String normalizeCommandPaths(String command) {
- // need to escape backslash so it works with regex
- String backslashSeparator = '\\\\';
-
- String forwardSlashSeparator = '/';
-
- // escape separator if it's a backslash
- char backslash = '\\';
- String separator = File.separatorChar == backslash ? backslashSeparator : File.separator
-
- return command
- // first replace all of the backslashes with forward slashes
- .replaceAll(backslashSeparator, forwardSlashSeparator)
- // then replace all forward slashes with whatever the separator actually is
- .replaceAll(forwardSlashSeparator, separator);
- }
-} \ No newline at end of file
diff --git a/buildSrc/src/main/kotlin/org/jetbrains/BintrayPublishing.kt b/buildSrc/src/main/kotlin/org/jetbrains/BintrayPublishing.kt
index 19e032a8..78e4257f 100644
--- a/buildSrc/src/main/kotlin/org/jetbrains/BintrayPublishing.kt
+++ b/buildSrc/src/main/kotlin/org/jetbrains/BintrayPublishing.kt
@@ -4,9 +4,7 @@ import com.jfrog.bintray.gradle.BintrayExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.provideDelegate
-fun Project.configureBintrayPublication(publication: String) = configureBintrayPublication(listOf(publication))
-
-fun Project.configureBintrayPublication(publications: List<String>) {
+fun Project.configureBintrayPublication(vararg publications: String) {
val dokka_version: String by this
val dokka_publication_channel: String by this
extensions.configure<BintrayExtension>("bintray") {
@@ -24,6 +22,6 @@ fun Project.configureBintrayPublication(publications: List<String>) {
name = dokka_version
}
}
- setPublications(*publications.toTypedArray())
+ setPublications(*publications)
}
} \ No newline at end of file
diff --git a/buildSrc/src/main/kotlin/org/jetbrains/CrossPlatformExec.kt b/buildSrc/src/main/kotlin/org/jetbrains/CrossPlatformExec.kt
new file mode 100644
index 00000000..feb32cac
--- /dev/null
+++ b/buildSrc/src/main/kotlin/org/jetbrains/CrossPlatformExec.kt
@@ -0,0 +1,67 @@
+package org.jetbrains
+
+import org.gradle.api.tasks.AbstractExecTask
+import org.gradle.internal.os.OperatingSystem
+import java.io.File
+import java.nio.file.Files
+import java.nio.file.Path
+import java.nio.file.Paths
+
+open class CrossPlatformExec : AbstractExecTask<CrossPlatformExec>(CrossPlatformExec::class.java) {
+ private val windowsExtensions = listOf(".bat", ".cmd", ".exe")
+ private val unixExtensions = listOf("", ".sh")
+
+ private val isWindows = OperatingSystem.current().isWindows
+
+ override fun exec() {
+ val commandLine: MutableList<String> = this.commandLine
+
+ if (commandLine.isNotEmpty()) {
+ commandLine[0] = findCommand(commandLine[0])
+ }
+
+ if (isWindows) {
+ if (commandLine.isNotEmpty() && commandLine[0].isNotBlank()) {
+ commandLine
+ }
+ commandLine.add(0, "/c")
+ commandLine.add(0, "cmd")
+ }
+
+ this.commandLine = commandLine
+
+ super.exec()
+ }
+
+ private fun findCommand(command: String): String {
+ val command = normalizeCommandPaths(command)
+ val extensions = if (isWindows) windowsExtensions else unixExtensions
+
+ return extensions.map { extension ->
+ resolveCommandFromFile(Paths.get("$command$extension"))
+ }.firstOrNull() ?: command
+ }
+
+ private fun resolveCommandFromFile(commandFile: Path) =
+ if (!Files.isExecutable(commandFile)) {
+ ""
+ } else {
+ commandFile.toAbsolutePath().normalize().toString()
+ }
+
+
+ private fun normalizeCommandPaths(command: String): String {
+ // need to escape backslash so it works with regex
+ val backslashSeparator = "\\"
+ val forwardSlashSeparator = "/"
+
+ // get the actual separator
+ val separator = if (File.separatorChar == '\\') backslashSeparator else File.separator
+
+ return command
+ // first replace all of the backslashes with forward slashes
+ .replace(backslashSeparator, forwardSlashSeparator)
+ // then replace all forward slashes with whatever the separator actually is
+ .replace(forwardSlashSeparator, separator)
+ }
+} \ No newline at end of file
diff --git a/buildSrc/src/main/kotlin/org/jetbrains/DistMavenPublishing.kt b/buildSrc/src/main/kotlin/org/jetbrains/DistMavenPublishing.kt
index ec536bd7..175bbd0b 100644
--- a/buildSrc/src/main/kotlin/org/jetbrains/DistMavenPublishing.kt
+++ b/buildSrc/src/main/kotlin/org/jetbrains/DistMavenPublishing.kt
@@ -9,12 +9,10 @@ fun Project.configureDistMaven() { // TODO: This can probably be written cleaner
val repoLocation = uri(file("${rootProject.buildDir}/dist-maven"))
var distMaven: MavenArtifactRepository? = null
pluginManager.withPlugin("maven-publish") {
- this@configureDistMaven.extensions.findByType(PublishingExtension::class.java)?.let {
- it.repositories {
- distMaven = maven {
- name = "distMaven"
- url = repoLocation
- }
+ this@configureDistMaven.extensions.findByType(PublishingExtension::class.java)?.repositories {
+ distMaven = maven {
+ name = "distMaven"
+ url = repoLocation
}
}
}