Created
July 29, 2019 17:17
-
-
Save LiewJunTung/05c5aa6de5029eab9b24923a3de4f7b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.liewjuntung.symbolicPlugin | |
import org.gradle.api.DefaultTask | |
import org.gradle.api.tasks.TaskAction | |
import java.io.File | |
abstract class SymbolicLink: DefaultTask() { | |
var actualFilePath: String? = null | |
var symbolicDirPath: String? = null | |
var rename: String? = null | |
@TaskAction | |
fun link() { | |
val aPath = actualFilePath ?: throw Exception("actualPath not set") | |
val sPath = symbolicDirPath ?: throw Exception("symbolicPath not set") | |
val actualFile = File(aPath) | |
if (!actualFile.exists()) { | |
throw Exception("$aPath not found") | |
} | |
val symbolicDirFile = File(sPath) | |
val pb = ProcessBuilder() | |
if (!symbolicDirFile.exists()) { | |
symbolicDirFile.mkdirs() | |
} | |
pb.directory(symbolicDirFile) | |
val symbolicRelativePath = symbolicDirFile.toPath().relativize(actualFile.toPath()) | |
println(symbolicRelativePath.toString()) | |
pb.command("ln", "-s", symbolicRelativePath.toString(), rename ?: ".") | |
pb.directory(symbolicDirFile) | |
pb.start() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment